diff --git a/frameworks/js/napi/crypto/src/napi_utils.cpp b/frameworks/js/napi/crypto/src/napi_utils.cpp index 026447d232e0642438e673ec8633d862339c8b5e..7ad4dc3787abbefcc9e220d49fdd4b516163624c 100644 --- a/frameworks/js/napi/crypto/src/napi_utils.cpp +++ b/frameworks/js/napi/crypto/src/napi_utils.cpp @@ -1108,7 +1108,7 @@ static bool GetRsaAsyKeySpec(napi_env env, napi_value arg, HcfAsyKeyParamsSpec * } } -static bool InitAlg25519CommonAsyKeySpec(HcfAsyKeyParamsSpec *spec, string algName) +static bool InitAlg25519CommonAsyKeySpec(HcfAsyKeyParamsSpec *spec, const string algName) { size_t algNameLen = algName.length(); spec->algName = static_cast(HcfMalloc(algNameLen + 1, 0)); @@ -1120,7 +1120,7 @@ static bool InitAlg25519CommonAsyKeySpec(HcfAsyKeyParamsSpec *spec, string algNa return true; } -static bool GetAlg25519PriKeySpec(napi_env env, napi_value arg, HcfAsyKeyParamsSpec **asyKeySpec, string algName) +static bool GetAlg25519PriKeySpec(napi_env env, napi_value arg, HcfAsyKeyParamsSpec **asyKeySpec, const string algName) { HcfAlg25519PriKeyParamsSpec *spec = reinterpret_cast(HcfMalloc(sizeof(HcfAlg25519PriKeyParamsSpec), 0)); @@ -1146,7 +1146,7 @@ static bool GetAlg25519PriKeySpec(napi_env env, napi_value arg, HcfAsyKeyParamsS return true; } -static bool GetAlg25519PubKeySpec(napi_env env, napi_value arg, HcfAsyKeyParamsSpec **asyKeySpec, string algName) +static bool GetAlg25519PubKeySpec(napi_env env, napi_value arg, HcfAsyKeyParamsSpec **asyKeySpec, const string algName) { HcfAlg25519PubKeyParamsSpec *spec = reinterpret_cast(HcfMalloc(sizeof(HcfAlg25519PubKeyParamsSpec), 0)); @@ -1172,7 +1172,7 @@ static bool GetAlg25519PubKeySpec(napi_env env, napi_value arg, HcfAsyKeyParamsS } static bool GetAlg25519KeyPairAsyKeySpec(napi_env env, napi_value arg, - HcfAsyKeyParamsSpec **asyKeySpec, string algName) + HcfAsyKeyParamsSpec **asyKeySpec, const string algName) { HcfAlg25519KeyPairParamsSpec *spec = reinterpret_cast(HcfMalloc(sizeof(HcfAlg25519KeyPairParamsSpec), 0)); @@ -1204,7 +1204,7 @@ static bool GetAlg25519KeyPairAsyKeySpec(napi_env env, napi_value arg, return true; } -static bool GetAlg25519AsyKeySpec(napi_env env, napi_value arg, HcfAsyKeyParamsSpec **asyKeySpec, string algName) +static bool GetAlg25519AsyKeySpec(napi_env env, napi_value arg, HcfAsyKeyParamsSpec **asyKeySpec, const string algName) { napi_value data = nullptr; napi_valuetype valueType = napi_undefined; 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 48b148953393aa070264a74fc9dfedf07fc99543..c0c0692c219aeeee3bd4061021bf7e61128189de 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 @@ -262,26 +262,16 @@ static void FreeEccCommParamObject(HcfEccCommParamsSpecSpi *spec) HcfFree(spec->paramsSpec.field); spec->paramsSpec.field = NULL; } - if (spec->paramsSpec.a.data != NULL) { - HcfFree(spec->paramsSpec.a.data); - spec->paramsSpec.a.data = NULL; - } - if (spec->paramsSpec.b.data != NULL) { - HcfFree(spec->paramsSpec.b.data); - spec->paramsSpec.b.data = NULL; - } - if (spec->paramsSpec.n.data != NULL) { - HcfFree(spec->paramsSpec.n.data); - spec->paramsSpec.n.data = NULL; - } - if (spec->paramsSpec.g.x.data != NULL) { - HcfFree(spec->paramsSpec.g.x.data); - spec->paramsSpec.g.x.data = NULL; - } - if (spec->paramsSpec.g.y.data != NULL) { - HcfFree(spec->paramsSpec.g.y.data); - spec->paramsSpec.g.y.data = NULL; - } + HcfFree(spec->paramsSpec.a.data); + spec->paramsSpec.a.data = NULL; + HcfFree(spec->paramsSpec.b.data); + spec->paramsSpec.b.data = NULL; + HcfFree(spec->paramsSpec.n.data); + spec->paramsSpec.n.data = NULL; + HcfFree(spec->paramsSpec.g.x.data); + spec->paramsSpec.g.x.data = NULL; + HcfFree(spec->paramsSpec.g.y.data); + spec->paramsSpec.g.y.data = NULL; HcfFree(spec); spec = NULL; } diff --git a/test/fuzztest/key/asykeygenerator_fuzzer/asykeygenerator_fuzzer.cpp b/test/fuzztest/key/asykeygenerator_fuzzer/asykeygenerator_fuzzer.cpp index 29081c24dccda3415c572d334053d4201696cce6..e014e15b863543ca5eae285438e66d32d11428c8 100644 --- a/test/fuzztest/key/asykeygenerator_fuzzer/asykeygenerator_fuzzer.cpp +++ b/test/fuzztest/key/asykeygenerator_fuzzer/asykeygenerator_fuzzer.cpp @@ -14,10 +14,10 @@ */ #include "asykeygenerator_fuzzer.h" - #include #include #include +#include "securec.h" #include "asy_key_generator.h" #include "blob.h" @@ -32,6 +32,7 @@ #include "ecc_key_util.h" #include "dh_key_util.h" #include "key_utils.h" +#include "memory.h" #include "result.h" using namespace std; @@ -47,18 +48,6 @@ static string g_x25519AlgoName = "X25519"; namespace OHOS { constexpr uint32_t PLEN_BITS = 3072; constexpr int32_t SKLEN_BITS = 256; - HcfEccPubKeyParamsSpec g_ecc256PubKeySpec; - HcfEccPriKeyParamsSpec g_ecc256PriKeySpec; - HcfEccKeyPairParamsSpec g_ecc256KeyPairSpec; - HcfAlg25519KeyPairParamsSpec g_ed25519KeyPairSpec; - HcfAlg25519PriKeyParamsSpec g_ed25519PriKeySpec; - HcfAlg25519PubKeyParamsSpec g_ed25519PubKeySpec; - HcfAlg25519KeyPairParamsSpec g_x25519KeyPairSpec; - HcfAlg25519PriKeyParamsSpec g_x25519PriKeySpec; - HcfAlg25519PubKeyParamsSpec g_x25519PubKeySpec; - HcfDhPubKeyParamsSpec g_dhPubKeySpec; - HcfDhPriKeyParamsSpec g_dhPriKeySpec; - HcfDhKeyPairParamsSpec g_dhKeyPairSpec; enum class GenerateType { FUZZ_COMMON = 0, @@ -97,7 +86,7 @@ namespace OHOS { static uint8_t g_mockSm2256PriKey[SM2256_PRI_KEY_LEN] = { 48, 49, 2, 1, 1, 4, 32, 78, 6, 176, 182, 178, 223, 78, 63, 118, 13, 15, 35, 44, 56, 78, 69, 212, 192, 65, 232, 103, 124, 247, 30, 211, 81, 139, 187, 28, 165, 8, 248, 160, 10, 6, 8, 42, 129, 28, 207, 85, 1, 130, 45 }; - + static uint8_t g_mockBrainpoolPubKey[BRAINPOOLP160R1_PUB_KEY_LEN] = { 48, 66, 48, 20, 6, 7, 42, 134, 72, 206, 61, 2, 1, 6, 9, 43, 36, 3, 3, 2, 8, 1, 1, 1, 3, 42, 0, 4, 37, 67, 178, 178, 176, 241, 23, 119, 74, 231, 82, 88, 215, 227, 37, 24, 129, 177, 152, 142, 144, 155, 44, 97, 145, 114, 242, 156, 129, 225, 186, 196, 113, 41, 198, @@ -646,34 +635,16 @@ namespace OHOS { HcfEccCommParamsSpec *eccCommSpec = nullptr; HcfEccKeyUtilCreate(algoName.c_str(), &eccCommSpec); - + if (eccCommSpec == nullptr) { + return HCF_INVALID_PARAMS; + } *spec = eccCommSpec; return HCF_SUCCESS; } - static HcfResult ConstructSm2256PubKeyParams(HcfKeyPair *keyPair, HcfEccCommParamsSpec *eccCommParamsSpec, - HcfAsyKeyParamsSpec **spec) + static HcfResult ConstructSm2256PubKeyBigInt(HcfKeyPair *keyPair, HcfEccPubKeyParamsSpec *eccPubKeySpec) { - HcfEccPubKeyParamsSpec *eccPubKeySpec = &g_ecc256PubKeySpec; HcfBigInteger retBigInt = { .data = nullptr, .len = 0 }; - - eccPubKeySpec->base.base.algName = eccCommParamsSpec->base.algName; - eccPubKeySpec->base.base.specType = HCF_PUBLIC_KEY_SPEC; - eccPubKeySpec->base.field = eccCommParamsSpec->field; - eccPubKeySpec->base.field->fieldType = eccCommParamsSpec->field->fieldType; - ((HcfECFieldFp *)(eccPubKeySpec->base.field))->p.data = ((HcfECFieldFp *)(eccCommParamsSpec->field))->p.data; - ((HcfECFieldFp *)(eccPubKeySpec->base.field))->p.len = ((HcfECFieldFp *)(eccCommParamsSpec->field))->p.len; - eccPubKeySpec->base.a.data = eccCommParamsSpec->a.data; - eccPubKeySpec->base.a.len = eccCommParamsSpec->a.len; - eccPubKeySpec->base.b.data = eccCommParamsSpec->b.data; - eccPubKeySpec->base.b.len = eccCommParamsSpec->b.len; - eccPubKeySpec->base.g.x.data = eccCommParamsSpec->g.x.data; - eccPubKeySpec->base.g.x.len = eccCommParamsSpec->g.x.len; - eccPubKeySpec->base.g.y.data = eccCommParamsSpec->g.y.data; - eccPubKeySpec->base.g.y.len = eccCommParamsSpec->g.y.len; - eccPubKeySpec->base.n.data = eccCommParamsSpec->n.data; - eccPubKeySpec->base.n.len = eccCommParamsSpec->n.len; - eccPubKeySpec->base.h = eccCommParamsSpec->h; HcfResult res = keyPair->pubKey->getAsyKeySpecBigInteger(keyPair->pubKey, ECC_PK_X_BN, &retBigInt); if (res != HCF_SUCCESS) { return res; @@ -683,116 +654,115 @@ namespace OHOS { res = keyPair->pubKey->getAsyKeySpecBigInteger(keyPair->pubKey, ECC_PK_Y_BN, &retBigInt); if (res != HCF_SUCCESS) { + HcfFree(eccPubKeySpec->pk.x.data); + eccPubKeySpec->pk.x.data = nullptr; + eccPubKeySpec->pk.x.len = 0; return res; } - eccPubKeySpec->pk.y.data =retBigInt.data; + eccPubKeySpec->pk.y.data = retBigInt.data; eccPubKeySpec->pk.y.len = retBigInt.len; - - *spec = reinterpret_cast(eccPubKeySpec); return HCF_SUCCESS; } - static HcfResult ConstructSm2256PubKeyParamsSpec(const std::string &algoName, - HcfEccCommParamsSpec *eccCommParamsSpec, HcfAsyKeyParamsSpec **spec) + HcfResult ConstructSm2256PubKeyParamsSpec(const std::string &algoName, HcfEccCommParamsSpec *eccCommSpec, + HcfAsyKeyParamsSpec **spec) { + HcfResult res = HCF_ERR_CRYPTO_OPERATION; HcfAsyKeyGenerator *generator = nullptr; - HcfResult res = HcfAsyKeyGeneratorCreate(algoName.c_str(), &generator); - if (res != HCF_SUCCESS) { + if (HcfAsyKeyGeneratorCreate(algoName.c_str(), &generator) != HCF_SUCCESS) { return res; } - + HcfKeyPair *keyPair = nullptr; - res = generator->generateKeyPair(generator, nullptr, &keyPair); - if (res != HCF_SUCCESS) { + if (generator->generateKeyPair(generator, nullptr, &keyPair) != HCF_SUCCESS) { HcfObjDestroy(generator); return res; } - res = ConstructSm2256PubKeyParams(keyPair, eccCommParamsSpec, spec); - if (res != HCF_SUCCESS) { - HcfObjDestroy(generator); - HcfObjDestroy(keyPair); - return res; + auto eccPubKeySpec = reinterpret_cast(HcfMalloc(sizeof(HcfEccPubKeyParamsSpec), 0)); + if (eccPubKeySpec != nullptr) { + eccPubKeySpec->base.base.algName = eccCommSpec->base.algName; + eccPubKeySpec->base.base.specType = HCF_PUBLIC_KEY_SPEC; + eccPubKeySpec->base.field = eccCommSpec->field; + eccPubKeySpec->base.field->fieldType = eccCommSpec->field->fieldType; + ((HcfECFieldFp *)(eccPubKeySpec->base.field))->p.data = ((HcfECFieldFp *)(eccCommSpec->field))->p.data; + ((HcfECFieldFp *)(eccPubKeySpec->base.field))->p.len = ((HcfECFieldFp *)(eccCommSpec->field))->p.len; + eccPubKeySpec->base.a.data = eccCommSpec->a.data; + eccPubKeySpec->base.a.len = eccCommSpec->a.len; + eccPubKeySpec->base.b.data = eccCommSpec->b.data; + eccPubKeySpec->base.b.len = eccCommSpec->b.len; + eccPubKeySpec->base.g.x.data = eccCommSpec->g.x.data; + eccPubKeySpec->base.g.x.len = eccCommSpec->g.x.len; + eccPubKeySpec->base.g.y.data = eccCommSpec->g.y.data; + eccPubKeySpec->base.g.y.len = eccCommSpec->g.y.len; + eccPubKeySpec->base.n.data = eccCommSpec->n.data; + eccPubKeySpec->base.n.len = eccCommSpec->n.len; + eccPubKeySpec->base.h = eccCommSpec->h; + if (ConstructSm2256PubKeyBigInt(keyPair, eccPubKeySpec) != HCF_SUCCESS) { + HcfFree(eccPubKeySpec); + } else { + *spec = reinterpret_cast(eccPubKeySpec); + res = HCF_SUCCESS; + } } + HcfObjDestroy(generator); HcfObjDestroy(keyPair); - return HCF_SUCCESS; + return res; } - static HcfResult ConstructSm2256PriKeyParamsSpec(const std::string &algoName, - HcfEccCommParamsSpec *eccCommParamsSpec, HcfAsyKeyParamsSpec **spec) + HcfResult ConstructSm2256PriKeyParamsSpec(const std::string &algoName, HcfEccCommParamsSpec *eccCommSpec, + HcfAsyKeyParamsSpec **spec) { + HcfResult res = HCF_ERR_CRYPTO_OPERATION; HcfAsyKeyGenerator *generator = nullptr; - HcfResult res = HcfAsyKeyGeneratorCreate(algoName.c_str(), &generator); - if (res != HCF_SUCCESS) { + if (HcfAsyKeyGeneratorCreate(algoName.c_str(), &generator) != HCF_SUCCESS) { return res; } - + HcfKeyPair *keyPair = nullptr; - res = generator->generateKeyPair(generator, nullptr, &keyPair); - if (res != HCF_SUCCESS) { + if (generator->generateKeyPair(generator, nullptr, &keyPair) != HCF_SUCCESS) { HcfObjDestroy(generator); return res; } - HcfEccPriKeyParamsSpec *eccPriKeySpec = &g_ecc256PriKeySpec; - HcfBigInteger retBigInt = { .data = nullptr, .len = 0 }; - - eccPriKeySpec->base.base.algName = eccCommParamsSpec->base.algName; - eccPriKeySpec->base.base.specType = HCF_PRIVATE_KEY_SPEC; - eccPriKeySpec->base.field = eccCommParamsSpec->field; - eccPriKeySpec->base.field->fieldType = eccCommParamsSpec->field->fieldType; - ((HcfECFieldFp *)(eccPriKeySpec->base.field))->p.data = ((HcfECFieldFp *)(eccCommParamsSpec->field))->p.data; - ((HcfECFieldFp *)(eccPriKeySpec->base.field))->p.len = ((HcfECFieldFp *)(eccCommParamsSpec->field))->p.len; - eccPriKeySpec->base.a.data = eccCommParamsSpec->a.data; - eccPriKeySpec->base.a.len = eccCommParamsSpec->a.len; - eccPriKeySpec->base.b.data = eccCommParamsSpec->b.data; - eccPriKeySpec->base.b.len = eccCommParamsSpec->b.len; - eccPriKeySpec->base.g.x.data = eccCommParamsSpec->g.x.data; - eccPriKeySpec->base.g.x.len = eccCommParamsSpec->g.x.len; - eccPriKeySpec->base.g.y.data = eccCommParamsSpec->g.y.data; - eccPriKeySpec->base.g.y.len = eccCommParamsSpec->g.y.len; - eccPriKeySpec->base.n.data = eccCommParamsSpec->n.data; - eccPriKeySpec->base.n.len = eccCommParamsSpec->n.len; - eccPriKeySpec->base.h = eccCommParamsSpec->h; - res = keyPair->priKey->getAsyKeySpecBigInteger(keyPair->priKey, ECC_SK_BN, &retBigInt); - if (res != HCF_SUCCESS) { - HcfObjDestroy(generator); - HcfObjDestroy(keyPair); - return HCF_ERR_CRYPTO_OPERATION; + auto eccPriKeySpec = reinterpret_cast(HcfMalloc(sizeof(HcfEccPriKeyParamsSpec), 0)); + if (eccPriKeySpec != nullptr) { + eccPriKeySpec->base.base.algName = eccCommSpec->base.algName; + eccPriKeySpec->base.base.specType = HCF_PRIVATE_KEY_SPEC; + eccPriKeySpec->base.field = eccCommSpec->field; + eccPriKeySpec->base.field->fieldType = eccCommSpec->field->fieldType; + ((HcfECFieldFp *)(eccPriKeySpec->base.field))->p.data = ((HcfECFieldFp *)(eccCommSpec->field))->p.data; + ((HcfECFieldFp *)(eccPriKeySpec->base.field))->p.len = ((HcfECFieldFp *)(eccCommSpec->field))->p.len; + eccPriKeySpec->base.a.data = eccCommSpec->a.data; + eccPriKeySpec->base.a.len = eccCommSpec->a.len; + eccPriKeySpec->base.b.data = eccCommSpec->b.data; + eccPriKeySpec->base.b.len = eccCommSpec->b.len; + eccPriKeySpec->base.g.x.data = eccCommSpec->g.x.data; + eccPriKeySpec->base.g.x.len = eccCommSpec->g.x.len; + eccPriKeySpec->base.g.y.data = eccCommSpec->g.y.data; + eccPriKeySpec->base.g.y.len = eccCommSpec->g.y.len; + eccPriKeySpec->base.n.data = eccCommSpec->n.data; + eccPriKeySpec->base.n.len = eccCommSpec->n.len; + eccPriKeySpec->base.h = eccCommSpec->h; + HcfBigInteger retBigInt = { .data = nullptr, .len = 0 }; + if (keyPair->priKey->getAsyKeySpecBigInteger(keyPair->priKey, ECC_SK_BN, &retBigInt) != HCF_SUCCESS) { + HcfFree(eccPriKeySpec); + } else { + eccPriKeySpec->sk.data = retBigInt.data; + eccPriKeySpec->sk.len = retBigInt.len; + *spec = reinterpret_cast(eccPriKeySpec); + res = HCF_SUCCESS; + } } - eccPriKeySpec->sk.data = retBigInt.data; - eccPriKeySpec->sk.len = retBigInt.len; - - *spec = reinterpret_cast(eccPriKeySpec); HcfObjDestroy(generator); HcfObjDestroy(keyPair); - return HCF_SUCCESS; + return res; } - static HcfResult ConstructSm2256KeyPairParams(HcfKeyPair *keyPair, HcfEccCommParamsSpec *eccCommParamsSpec, - HcfAsyKeyParamsSpec **spec) + static HcfResult ConstructSm2256KeyPairBigInt(HcfKeyPair *keyPair, HcfEccKeyPairParamsSpec *eccKeyPairSpec) { - HcfEccKeyPairParamsSpec *eccKeyPairSpec = &g_ecc256KeyPairSpec; - HcfBigInteger retBigInt = { .data = nullptr, .len = 0 }; - - eccKeyPairSpec->base.base.algName = eccCommParamsSpec->base.algName; - eccKeyPairSpec->base.base.specType = HCF_KEY_PAIR_SPEC; - eccKeyPairSpec->base.field = eccCommParamsSpec->field; - eccKeyPairSpec->base.field->fieldType = eccCommParamsSpec->field->fieldType; - ((HcfECFieldFp *)(eccKeyPairSpec->base.field))->p.data = ((HcfECFieldFp *)(eccCommParamsSpec->field))->p.data; - ((HcfECFieldFp *)(eccKeyPairSpec->base.field))->p.len = ((HcfECFieldFp *)(eccCommParamsSpec->field))->p.len; - eccKeyPairSpec->base.a.data = eccCommParamsSpec->a.data; - eccKeyPairSpec->base.a.len = eccCommParamsSpec->a.len; - eccKeyPairSpec->base.b.data = eccCommParamsSpec->b.data; - eccKeyPairSpec->base.b.len = eccCommParamsSpec->b.len; - eccKeyPairSpec->base.g.x.data = eccCommParamsSpec->g.x.data; - eccKeyPairSpec->base.g.x.len = eccCommParamsSpec->g.x.len; - eccKeyPairSpec->base.g.y.data = eccCommParamsSpec->g.y.data; - eccKeyPairSpec->base.g.y.len = eccCommParamsSpec->g.y.len; - eccKeyPairSpec->base.n.data = eccCommParamsSpec->n.data; - eccKeyPairSpec->base.n.len = eccCommParamsSpec->n.len; - eccKeyPairSpec->base.h = eccCommParamsSpec->h; + HcfBigInteger retBigInt = { .data = NULL, .len = 0 }; HcfResult res = keyPair->pubKey->getAsyKeySpecBigInteger(keyPair->pubKey, ECC_PK_X_BN, &retBigInt); if (res != HCF_SUCCESS) { return res; @@ -802,194 +772,284 @@ namespace OHOS { res = keyPair->pubKey->getAsyKeySpecBigInteger(keyPair->pubKey, ECC_PK_Y_BN, &retBigInt); if (res != HCF_SUCCESS) { + HcfFree(eccKeyPairSpec->pk.x.data); + eccKeyPairSpec->pk.x.data = NULL; + eccKeyPairSpec->pk.x.len = 0; return res; } - eccKeyPairSpec->pk.y.data =retBigInt.data; + eccKeyPairSpec->pk.y.data = retBigInt.data; eccKeyPairSpec->pk.y.len = retBigInt.len; res = keyPair->priKey->getAsyKeySpecBigInteger(keyPair->priKey, ECC_SK_BN, &retBigInt); if (res != HCF_SUCCESS) { + HcfFree(eccKeyPairSpec->pk.x.data); + eccKeyPairSpec->pk.x.data = NULL; + eccKeyPairSpec->pk.x.len = 0; + HcfFree(eccKeyPairSpec->pk.y.data); + eccKeyPairSpec->pk.y.data = NULL; + eccKeyPairSpec->pk.y.len = 0; return res; } eccKeyPairSpec->sk.data = retBigInt.data; eccKeyPairSpec->sk.len = retBigInt.len; - - *spec = reinterpret_cast(eccKeyPairSpec); return HCF_SUCCESS; } - static HcfResult ConstructSm2256KeyPairParamsSpec(const std::string &algoName, - HcfEccCommParamsSpec *eccCommParamsSpec, HcfAsyKeyParamsSpec **spec) + + HcfResult ConstructSm2256KeyPairParamsSpec(const std::string &algoName, + HcfEccCommParamsSpec *eccCommSpec, HcfAsyKeyParamsSpec **spec) { HcfAsyKeyGenerator *generator = nullptr; - HcfResult res = HcfAsyKeyGeneratorCreate(algoName.c_str(), &generator); - if (res != HCF_SUCCESS) { + HcfResult res = HCF_ERR_CRYPTO_OPERATION; + if (HcfAsyKeyGeneratorCreate(algoName.c_str(), &generator) != HCF_SUCCESS) { return res; } - HcfKeyPair *keyPair = nullptr; - res = generator->generateKeyPair(generator, nullptr, &keyPair); - if (res != HCF_SUCCESS) { + if (generator->generateKeyPair(generator, nullptr, &keyPair) != HCF_SUCCESS) { HcfObjDestroy(generator); return res; } - res = ConstructSm2256KeyPairParams(keyPair, eccCommParamsSpec, spec); - if (res != HCF_SUCCESS) { - HcfObjDestroy(generator); - HcfObjDestroy(keyPair); - return res; + auto eccKeyPairSpec = + reinterpret_cast(HcfMalloc(sizeof(HcfEccKeyPairParamsSpec), 0)); + if (eccKeyPairSpec != nullptr) { + eccKeyPairSpec->base.base.algName = eccCommSpec->base.algName; + eccKeyPairSpec->base.base.specType = HCF_KEY_PAIR_SPEC; + eccKeyPairSpec->base.field = eccCommSpec->field; + eccKeyPairSpec->base.field->fieldType = eccCommSpec->field->fieldType; + ((HcfECFieldFp *)(eccKeyPairSpec->base.field))->p.data = ((HcfECFieldFp *)(eccCommSpec->field))->p.data; + ((HcfECFieldFp *)(eccKeyPairSpec->base.field))->p.len = ((HcfECFieldFp *)(eccCommSpec->field))->p.len; + eccKeyPairSpec->base.a.data = eccCommSpec->a.data; + eccKeyPairSpec->base.a.len = eccCommSpec->a.len; + eccKeyPairSpec->base.b.data = eccCommSpec->b.data; + eccKeyPairSpec->base.b.len = eccCommSpec->b.len; + eccKeyPairSpec->base.g.x.data = eccCommSpec->g.x.data; + eccKeyPairSpec->base.g.x.len = eccCommSpec->g.x.len; + eccKeyPairSpec->base.g.y.data = eccCommSpec->g.y.data; + eccKeyPairSpec->base.g.y.len = eccCommSpec->g.y.len; + eccKeyPairSpec->base.n.data = eccCommSpec->n.data; + eccKeyPairSpec->base.n.len = eccCommSpec->n.len; + eccKeyPairSpec->base.h = eccCommSpec->h; + if (ConstructSm2256KeyPairBigInt(keyPair, eccKeyPairSpec) != HCF_SUCCESS) { + HcfFree(eccKeyPairSpec); + } else { + *spec = reinterpret_cast(eccKeyPairSpec); + res = HCF_SUCCESS; + } } HcfObjDestroy(generator); HcfObjDestroy(keyPair); + return res; + } + + static HcfResult CreateAlg25519KeyPairSpec(bool choose, HcfAlg25519KeyPairParamsSpec **alg25519KeyPairSpec) + { + *alg25519KeyPairSpec = (HcfAlg25519KeyPairParamsSpec*)HcfMalloc(sizeof(HcfAlg25519KeyPairParamsSpec), 0); + if (*alg25519KeyPairSpec == nullptr) { + return HCF_ERR_MALLOC; + } + if (choose) { + (*alg25519KeyPairSpec)->base.algName = static_cast(HcfMalloc(sizeof(g_ed25519AlgoName), 0)); + if ((*alg25519KeyPairSpec)->base.algName == nullptr) { + HcfFree(*alg25519KeyPairSpec); + *alg25519KeyPairSpec = nullptr; + return HCF_ERR_MALLOC; + } + (void)memcpy_s((*alg25519KeyPairSpec)->base.algName, g_ed25519AlgoName.length(), + g_ed25519AlgoName.data(), g_ed25519AlgoName.length()); + } else { + (*alg25519KeyPairSpec)->base.algName = static_cast(HcfMalloc(sizeof(g_x25519AlgoName), 0)); + if ((*alg25519KeyPairSpec)->base.algName == nullptr) { + HcfFree(*alg25519KeyPairSpec); + *alg25519KeyPairSpec = nullptr; + return HCF_ERR_MALLOC; + } + (void)memcpy_s((*alg25519KeyPairSpec)->base.algName, g_x25519AlgoName.length(), + g_x25519AlgoName.data(), g_x25519AlgoName.length()); + } return HCF_SUCCESS; } static HcfResult ConstructAlg25519KeyPairParamsSpec(const string &algoName, bool choose, HcfAsyKeyParamsSpec **spec) { + HcfResult res = HCF_ERR_CRYPTO_OPERATION; HcfAsyKeyGenerator *generator = nullptr; - HcfResult res = HcfAsyKeyGeneratorCreate(algoName.c_str(), &generator); - if (res != HCF_SUCCESS) { - return HCF_ERR_CRYPTO_OPERATION; + if (HcfAsyKeyGeneratorCreate(algoName.c_str(), &generator) != HCF_SUCCESS) { + return res; } HcfKeyPair *keyPair = nullptr; - res = generator->generateKeyPair(generator, nullptr, &keyPair); - if (res != HCF_SUCCESS) { + if (generator->generateKeyPair(generator, nullptr, &keyPair) != HCF_SUCCESS) { HcfObjDestroy(generator); - HcfObjDestroy(keyPair); - return HCF_ERR_CRYPTO_OPERATION; + return res; } HcfAlg25519KeyPairParamsSpec *alg25519KeyPairSpec = nullptr; - if (choose) { - alg25519KeyPairSpec = &g_ed25519KeyPairSpec; - alg25519KeyPairSpec->base.algName = g_ed25519AlgoName.data(); - } else { - alg25519KeyPairSpec = &g_x25519KeyPairSpec; - alg25519KeyPairSpec->base.algName = g_x25519AlgoName.data(); - } - HcfBigInteger retBigInt = { .data = nullptr, .len = 0 }; - alg25519KeyPairSpec->base.specType = HCF_KEY_PAIR_SPEC; - if (choose) { - res = keyPair->pubKey->getAsyKeySpecBigInteger(keyPair->pubKey, ED25519_PK_BN, &retBigInt); - } else { - res = keyPair->pubKey->getAsyKeySpecBigInteger(keyPair->pubKey, X25519_PK_BN, &retBigInt); - } - if (res != HCF_SUCCESS) { - HcfObjDestroy(generator); - HcfObjDestroy(keyPair); - return HCF_ERR_CRYPTO_OPERATION; + if (CreateAlg25519KeyPairSpec(choose, &alg25519KeyPairSpec) == HCF_SUCCESS) { + HcfBigInteger retBigInt = { .data = nullptr, .len = 0 }; + alg25519KeyPairSpec->base.specType = HCF_KEY_PAIR_SPEC; + if (choose) { + res = keyPair->pubKey->getAsyKeySpecBigInteger(keyPair->pubKey, ED25519_PK_BN, &retBigInt); + } else { + res = keyPair->pubKey->getAsyKeySpecBigInteger(keyPair->pubKey, X25519_PK_BN, &retBigInt); + } + + if (res == HCF_SUCCESS) { + alg25519KeyPairSpec->pk.data = retBigInt.data; + alg25519KeyPairSpec->pk.len = retBigInt.len; + + if (choose) { + res = keyPair->priKey->getAsyKeySpecBigInteger(keyPair->priKey, ED25519_SK_BN, &retBigInt); + } else { + res = keyPair->priKey->getAsyKeySpecBigInteger(keyPair->priKey, X25519_SK_BN, &retBigInt); + } + if (res == HCF_SUCCESS) { + alg25519KeyPairSpec->sk.data = retBigInt.data; + alg25519KeyPairSpec->sk.len = retBigInt.len; + *spec = reinterpret_cast(alg25519KeyPairSpec); + } else { + HcfFree(alg25519KeyPairSpec->pk.data); + alg25519KeyPairSpec->pk.data = NULL; + alg25519KeyPairSpec->pk.len = 0; + } + } + if (res != HCF_SUCCESS) { + DestroyAlg25519KeyPairSpec(reinterpret_cast(alg25519KeyPairSpec)); + } } - alg25519KeyPairSpec->pk.data = retBigInt.data; - alg25519KeyPairSpec->pk.len = retBigInt.len; + HcfObjDestroy(generator); + HcfObjDestroy(keyPair); + return res; + } + static HcfResult CreateAlg25519PubKeySpec(bool choose, HcfAlg25519PubKeyParamsSpec **alg25519PubKeySpec) + { + *alg25519PubKeySpec = (HcfAlg25519PubKeyParamsSpec*)HcfMalloc(sizeof(HcfAlg25519PubKeyParamsSpec), 0); + if (*alg25519PubKeySpec == nullptr) { + return HCF_ERR_MALLOC; + } if (choose) { - res = keyPair->priKey->getAsyKeySpecBigInteger(keyPair->priKey, ED25519_SK_BN, &retBigInt); + (*alg25519PubKeySpec)->base.algName = static_cast(HcfMalloc(sizeof(g_ed25519AlgoName), 0)); + if ((*alg25519PubKeySpec)->base.algName == nullptr) { + HcfFree(*alg25519PubKeySpec); + *alg25519PubKeySpec = nullptr; + return HCF_ERR_MALLOC; + } + (void)memcpy_s((*alg25519PubKeySpec)->base.algName, g_ed25519AlgoName.length(), + g_ed25519AlgoName.data(), g_ed25519AlgoName.length()); } else { - res = keyPair->priKey->getAsyKeySpecBigInteger(keyPair->priKey, X25519_SK_BN, &retBigInt); + (*alg25519PubKeySpec)->base.algName = static_cast(HcfMalloc(sizeof(g_x25519AlgoName), 0)); + if ((*alg25519PubKeySpec)->base.algName == nullptr) { + HcfFree(*alg25519PubKeySpec); + *alg25519PubKeySpec = nullptr; + return HCF_ERR_MALLOC; + } + (void)memcpy_s((*alg25519PubKeySpec)->base.algName, g_x25519AlgoName.length(), + g_x25519AlgoName.data(), g_x25519AlgoName.length()); } - if (res != HCF_SUCCESS) { - HcfObjDestroy(generator); - HcfObjDestroy(keyPair); - return HCF_ERR_CRYPTO_OPERATION; - } - alg25519KeyPairSpec->sk.data = retBigInt.data; - alg25519KeyPairSpec->sk.len = retBigInt.len; - - *spec = reinterpret_cast(alg25519KeyPairSpec); - HcfObjDestroy(generator); - HcfObjDestroy(keyPair); return HCF_SUCCESS; } static HcfResult ConstructAlg25519PubKeyParamsSpec(const string &algoName, bool choose, HcfAsyKeyParamsSpec **spec) { + HcfResult res = HCF_ERR_CRYPTO_OPERATION; HcfAsyKeyGenerator *generator = nullptr; - HcfResult res = HcfAsyKeyGeneratorCreate(algoName.c_str(), &generator); - if (res != HCF_SUCCESS) { - return HCF_ERR_CRYPTO_OPERATION; + if (HcfAsyKeyGeneratorCreate(algoName.c_str(), &generator) != HCF_SUCCESS) { + return res; } HcfKeyPair *keyPair = nullptr; - res = generator->generateKeyPair(generator, nullptr, &keyPair); - if (res != HCF_SUCCESS) { + if (generator->generateKeyPair(generator, nullptr, &keyPair) != HCF_SUCCESS) { HcfObjDestroy(generator); - return HCF_ERR_CRYPTO_OPERATION; + return res; } HcfAlg25519PubKeyParamsSpec *alg25519PubKeySpec = nullptr; - if (choose) { - alg25519PubKeySpec = &g_ed25519PubKeySpec; - alg25519PubKeySpec->base.algName = g_ed25519AlgoName.data(); - } else { - alg25519PubKeySpec = &g_x25519PubKeySpec; - alg25519PubKeySpec->base.algName = g_x25519AlgoName.data(); + if (CreateAlg25519PubKeySpec(choose, &alg25519PubKeySpec) == HCF_SUCCESS) { + HcfBigInteger retBigInt = { .data = nullptr, .len = 0 }; + alg25519PubKeySpec->base.specType = HCF_PUBLIC_KEY_SPEC; + if (choose) { + res = keyPair->pubKey->getAsyKeySpecBigInteger(keyPair->pubKey, ED25519_PK_BN, &retBigInt); + } else { + res = keyPair->pubKey->getAsyKeySpecBigInteger(keyPair->pubKey, X25519_PK_BN, &retBigInt); + } + if (res == HCF_SUCCESS) { + alg25519PubKeySpec->pk.data = retBigInt.data; + alg25519PubKeySpec->pk.len = retBigInt.len; + *spec = reinterpret_cast(alg25519PubKeySpec); + } else { + DestroyAlg25519PubKeySpec(reinterpret_cast(alg25519PubKeySpec)); + } } - HcfBigInteger retBigInt = { .data = nullptr, .len = 0 }; - alg25519PubKeySpec->base.specType = HCF_PUBLIC_KEY_SPEC; - if (choose) { - res = keyPair->pubKey->getAsyKeySpecBigInteger(keyPair->pubKey, ED25519_PK_BN, &retBigInt); - } else { - res = keyPair->pubKey->getAsyKeySpecBigInteger(keyPair->pubKey, X25519_PK_BN, &retBigInt); - } - if (res != HCF_SUCCESS) { - HcfObjDestroy(generator); - HcfObjDestroy(keyPair); - return HCF_ERR_CRYPTO_OPERATION; - } - alg25519PubKeySpec->pk.data = retBigInt.data; - alg25519PubKeySpec->pk.len = retBigInt.len; - *spec = reinterpret_cast(alg25519PubKeySpec); HcfObjDestroy(generator); HcfObjDestroy(keyPair); + return res; + } + + static HcfResult CreateAlg25519PriKeySpec(bool choose, HcfAlg25519PriKeyParamsSpec **alg25519PriKeySpec) + { + *alg25519PriKeySpec = (HcfAlg25519PriKeyParamsSpec*)HcfMalloc(sizeof(HcfAlg25519PriKeyParamsSpec), 0); + if (*alg25519PriKeySpec == nullptr) { + return HCF_ERR_MALLOC; + } + if (choose) { + (*alg25519PriKeySpec)->base.algName = static_cast(HcfMalloc(sizeof(g_ed25519AlgoName), 0)); + if ((*alg25519PriKeySpec)->base.algName == nullptr) { + HcfFree(*alg25519PriKeySpec); + *alg25519PriKeySpec = nullptr; + return HCF_ERR_MALLOC; + } + (void)memcpy_s((*alg25519PriKeySpec)->base.algName, g_ed25519AlgoName.length(), + g_ed25519AlgoName.data(), g_ed25519AlgoName.length()); + } else { + (*alg25519PriKeySpec)->base.algName = static_cast(HcfMalloc(sizeof(g_x25519AlgoName), 0)); + if ((*alg25519PriKeySpec)->base.algName == nullptr) { + HcfFree(*alg25519PriKeySpec); + *alg25519PriKeySpec = nullptr; + return HCF_ERR_MALLOC; + } + (void)memcpy_s((*alg25519PriKeySpec)->base.algName, g_x25519AlgoName.length(), + g_x25519AlgoName.data(), g_x25519AlgoName.length()); + } return HCF_SUCCESS; } static HcfResult ConstructAlg25519PriKeyParamsSpec(const string &algoName, bool choose, HcfAsyKeyParamsSpec **spec) { + HcfResult res = HCF_ERR_CRYPTO_OPERATION; HcfAsyKeyGenerator *generator = nullptr; - HcfResult res = HcfAsyKeyGeneratorCreate(algoName.c_str(), &generator); - if (res != HCF_SUCCESS) { - return HCF_ERR_CRYPTO_OPERATION; + if (HcfAsyKeyGeneratorCreate(algoName.c_str(), &generator) != HCF_SUCCESS) { + return res; } HcfKeyPair *keyPair = nullptr; - res = generator->generateKeyPair(generator, nullptr, &keyPair); - if (res != HCF_SUCCESS) { + if (generator->generateKeyPair(generator, nullptr, &keyPair) != HCF_SUCCESS) { HcfObjDestroy(generator); - return HCF_ERR_CRYPTO_OPERATION; + return res; } HcfAlg25519PriKeyParamsSpec *alg25519PriKeySpec = nullptr; - if (choose) { - alg25519PriKeySpec = &g_ed25519PriKeySpec; - alg25519PriKeySpec->base.algName = g_ed25519AlgoName.data(); - } else { - alg25519PriKeySpec = &g_x25519PriKeySpec; - alg25519PriKeySpec->base.algName = g_x25519AlgoName.data(); - } - HcfBigInteger retBigInt = { .data = nullptr, .len = 0 }; - alg25519PriKeySpec->base.specType = HCF_PRIVATE_KEY_SPEC; - if (choose) { - res = keyPair->priKey->getAsyKeySpecBigInteger(keyPair->priKey, ED25519_SK_BN, &retBigInt); - } else { - res = keyPair->priKey->getAsyKeySpecBigInteger(keyPair->priKey, X25519_SK_BN, &retBigInt); - } - if (res != HCF_SUCCESS) { - HcfObjDestroy(generator); - HcfObjDestroy(keyPair); - return HCF_ERR_CRYPTO_OPERATION; + if (CreateAlg25519PriKeySpec(choose, &alg25519PriKeySpec) == HCF_SUCCESS) { + HcfBigInteger retBigInt = { .data = nullptr, .len = 0 }; + alg25519PriKeySpec->base.specType = HCF_PRIVATE_KEY_SPEC; + if (choose) { + res = keyPair->priKey->getAsyKeySpecBigInteger(keyPair->priKey, ED25519_SK_BN, &retBigInt); + } else { + res = keyPair->priKey->getAsyKeySpecBigInteger(keyPair->priKey, X25519_SK_BN, &retBigInt); + } + if (res == HCF_SUCCESS) { + alg25519PriKeySpec->sk.data = retBigInt.data; + alg25519PriKeySpec->sk.len = retBigInt.len; + *spec = reinterpret_cast(alg25519PriKeySpec); + } else { + DestroyAlg25519PriKeySpec(reinterpret_cast(alg25519PriKeySpec)); + } } - alg25519PriKeySpec->sk.data = retBigInt.data; - alg25519PriKeySpec->sk.len = retBigInt.len; - - *spec = reinterpret_cast(alg25519PriKeySpec); HcfObjDestroy(generator); HcfObjDestroy(keyPair); - return HCF_SUCCESS; + return res; } static HcfResult ConstructDhCommParamsSpec(uint32_t pLen, int32_t skLen, HcfDhCommParamsSpec **spec) @@ -997,6 +1057,9 @@ namespace OHOS { HcfDhCommParamsSpec *dhCommSpec = nullptr; HcfDhKeyUtilCreate(pLen, skLen, &dhCommSpec); + if (dhCommSpec == nullptr) { + return HCF_INVALID_PARAMS; + } *spec = dhCommSpec; return HCF_SUCCESS; } @@ -1007,19 +1070,22 @@ namespace OHOS { HcfAsyKeyGenerator *generator = nullptr; HcfResult res = HcfAsyKeyGeneratorCreate(algoName.c_str(), &generator); if (res != HCF_SUCCESS) { - return HCF_ERR_CRYPTO_OPERATION; + return res; } - + HcfKeyPair *keyPair = nullptr; res = generator->generateKeyPair(generator, nullptr, &keyPair); if (res != HCF_SUCCESS) { HcfObjDestroy(generator); - return HCF_ERR_CRYPTO_OPERATION; + return res; } - HcfDhPubKeyParamsSpec *dhPubKeySpec = &g_dhPubKeySpec; - HcfBigInteger retBigInt = { .data = nullptr, .len = 0 }; - + HcfDhPubKeyParamsSpec *dhPubKeySpec = (HcfDhPubKeyParamsSpec*)HcfMalloc(sizeof(HcfDhPubKeyParamsSpec), 0); + if (dhPubKeySpec == nullptr) { + HcfObjDestroy(generator); + HcfObjDestroy(keyPair); + return HCF_ERR_MALLOC; + } dhPubKeySpec->base.base.algName = dhCommParamsSpec->base.algName; dhPubKeySpec->base.base.specType = HCF_PUBLIC_KEY_SPEC; dhPubKeySpec->base.p.data = dhCommParamsSpec->p.data; @@ -1027,11 +1093,13 @@ namespace OHOS { dhPubKeySpec->base.g.data = dhCommParamsSpec->g.data; dhPubKeySpec->base.g.len = dhCommParamsSpec->g.len; dhPubKeySpec->base.length = dhCommParamsSpec->length; + HcfBigInteger retBigInt = { .data = nullptr, .len = 0 }; res = keyPair->pubKey->getAsyKeySpecBigInteger(keyPair->pubKey, DH_PK_BN, &retBigInt); if (res != HCF_SUCCESS) { HcfObjDestroy(generator); HcfObjDestroy(keyPair); - return HCF_ERR_CRYPTO_OPERATION; + HcfFree(dhPubKeySpec); + return res; } dhPubKeySpec->pk.data = retBigInt.data; dhPubKeySpec->pk.len = retBigInt.len; @@ -1048,18 +1116,21 @@ namespace OHOS { HcfAsyKeyGenerator *generator = nullptr; HcfResult res = HcfAsyKeyGeneratorCreate(algoName.c_str(), &generator); if (res != HCF_SUCCESS) { - return HCF_ERR_CRYPTO_OPERATION; + return res; } HcfKeyPair *keyPair = nullptr; res = generator->generateKeyPair(generator, nullptr, &keyPair); if (res != HCF_SUCCESS) { HcfObjDestroy(generator); - return HCF_ERR_CRYPTO_OPERATION; + return res; } - HcfDhPriKeyParamsSpec *dhPriKeySpec = &g_dhPriKeySpec; - HcfBigInteger retBigInt = { .data = nullptr, .len = 0 }; - + HcfDhPriKeyParamsSpec *dhPriKeySpec = (HcfDhPriKeyParamsSpec*)HcfMalloc(sizeof(HcfDhPriKeyParamsSpec), 0); + if (dhPriKeySpec == nullptr) { + HcfObjDestroy(generator); + HcfObjDestroy(keyPair); + return HCF_ERR_MALLOC; + } dhPriKeySpec->base.base.algName = dhCommParamsSpec->base.algName; dhPriKeySpec->base.base.specType = HCF_PRIVATE_KEY_SPEC; dhPriKeySpec->base.p.data = dhCommParamsSpec->p.data; @@ -1067,11 +1138,13 @@ namespace OHOS { dhPriKeySpec->base.g.data = dhCommParamsSpec->g.data; dhPriKeySpec->base.g.len = dhCommParamsSpec->g.len; dhPriKeySpec->base.length = dhCommParamsSpec->length; + HcfBigInteger retBigInt = { .data = nullptr, .len = 0 }; res = keyPair->priKey->getAsyKeySpecBigInteger(keyPair->priKey, DH_SK_BN, &retBigInt); if (res != HCF_SUCCESS) { HcfObjDestroy(generator); HcfObjDestroy(keyPair); - return HCF_ERR_CRYPTO_OPERATION; + HcfFree(dhPriKeySpec); + return res; } dhPriKeySpec->sk.data = retBigInt.data; dhPriKeySpec->sk.len = retBigInt.len; @@ -1082,51 +1155,64 @@ namespace OHOS { return HCF_SUCCESS; } - static HcfResult ConstructDhKeyPairParamsSpec(const std::string &algoName, - HcfDhCommParamsSpec *dhCommParamsSpec, HcfAsyKeyParamsSpec **spec) + static HcfResult ConstructDhKeyPairBigInt(HcfKeyPair *keyPair, HcfDhKeyPairParamsSpec *dhKeyPairSpec) { - HcfAsyKeyGenerator *generator = nullptr; - HcfResult res = HcfAsyKeyGeneratorCreate(algoName.c_str(), &generator); + HcfBigInteger retBigInt = { .data = NULL, .len = 0 }; + HcfResult res = keyPair->pubKey->getAsyKeySpecBigInteger(keyPair->pubKey, DH_PK_BN, &retBigInt); if (res != HCF_SUCCESS) { - return HCF_ERR_CRYPTO_OPERATION; + return res; } + dhKeyPairSpec->pk.data = retBigInt.data; + dhKeyPairSpec->pk.len = retBigInt.len; - HcfKeyPair *keyPair = nullptr; - res = generator->generateKeyPair(generator, nullptr, &keyPair); + res = keyPair->priKey->getAsyKeySpecBigInteger(keyPair->priKey, DH_SK_BN, &retBigInt); if (res != HCF_SUCCESS) { - HcfObjDestroy(generator); - return HCF_ERR_CRYPTO_OPERATION; + HcfFree(dhKeyPairSpec->pk.data); + dhKeyPairSpec->pk.data = NULL; + dhKeyPairSpec->pk.len = 0; + return res; } + dhKeyPairSpec->sk.data = retBigInt.data; + dhKeyPairSpec->sk.len = retBigInt.len; + return HCF_SUCCESS; + } - HcfDhKeyPairParamsSpec *dhKeyPairSpec = &g_dhKeyPairSpec; - HcfBigInteger retBigInt = { .data = nullptr, .len = 0 }; - - dhKeyPairSpec->base.base.algName = dhCommParamsSpec->base.algName; - dhKeyPairSpec->base.base.specType = HCF_KEY_PAIR_SPEC; - dhKeyPairSpec->base.p.data = dhCommParamsSpec->p.data; - dhKeyPairSpec->base.p.len = dhCommParamsSpec->p.len; - dhKeyPairSpec->base.g.data = dhCommParamsSpec->g.data; - dhKeyPairSpec->base.g.len = dhCommParamsSpec->g.len; - dhKeyPairSpec->base.length = dhCommParamsSpec->length; - res = keyPair->pubKey->getAsyKeySpecBigInteger(keyPair->pubKey, DH_PK_BN, &retBigInt); + static HcfResult ConstructDhKeyPairParamsSpec(const std::string &algoName, + HcfDhCommParamsSpec *dhCommParamsSpec, HcfAsyKeyParamsSpec **spec) + { + HcfAsyKeyGenerator *generator = nullptr; + HcfResult res = HcfAsyKeyGeneratorCreate(algoName.c_str(), &generator); if (res != HCF_SUCCESS) { - HcfObjDestroy(generator); - HcfObjDestroy(keyPair); - return HCF_ERR_CRYPTO_OPERATION; + return res; } - dhKeyPairSpec->pk.data = retBigInt.data; - dhKeyPairSpec->pk.len = retBigInt.len; - res = keyPair->priKey->getAsyKeySpecBigInteger(keyPair->priKey, DH_SK_BN, &retBigInt); + HcfKeyPair *keyPair = nullptr; + res = generator->generateKeyPair(generator, nullptr, &keyPair); if (res != HCF_SUCCESS) { HcfObjDestroy(generator); - HcfObjDestroy(keyPair); - return HCF_ERR_CRYPTO_OPERATION; + return res; } - dhKeyPairSpec->sk.data = retBigInt.data; - dhKeyPairSpec->sk.len = retBigInt.len; - *spec = reinterpret_cast(dhKeyPairSpec); + HcfDhKeyPairParamsSpec *dhKeyPairSpec = + reinterpret_cast(HcfMalloc(sizeof(HcfDhKeyPairParamsSpec), 0)); + if (dhKeyPairSpec != nullptr) { + dhKeyPairSpec->base.base.algName = dhCommParamsSpec->base.algName; + dhKeyPairSpec->base.base.specType = HCF_KEY_PAIR_SPEC; + dhKeyPairSpec->base.p.data = dhCommParamsSpec->p.data; + dhKeyPairSpec->base.p.len = dhCommParamsSpec->p.len; + dhKeyPairSpec->base.g.data = dhCommParamsSpec->g.data; + dhKeyPairSpec->base.g.len = dhCommParamsSpec->g.len; + dhKeyPairSpec->base.length = dhCommParamsSpec->length; + res = ConstructDhKeyPairBigInt(keyPair, dhKeyPairSpec); + if (res != HCF_SUCCESS) { + HcfObjDestroy(generator); + HcfObjDestroy(keyPair); + HcfFree(dhKeyPairSpec); + return res; + } + *spec = reinterpret_cast(dhKeyPairSpec); + } + HcfObjDestroy(generator); HcfObjDestroy(keyPair); return HCF_SUCCESS; @@ -1541,19 +1627,29 @@ namespace OHOS { res = ConstructSm2256KeyPairParamsSpec(algoName, eccCommParamsSpec, ¶mSpec); break; default: - return; + break; } - if (res != HCF_SUCCESS) { - return; - } - res = HcfAsyKeyGeneratorBySpecCreate(paramSpec, &generator); - if (res != HCF_SUCCESS) { + if ((res != HCF_SUCCESS) || (HcfAsyKeyGeneratorBySpecCreate(paramSpec, &generator) != HCF_SUCCESS)) { + FreeEccCommParamsSpec(eccCommParamsSpec); + eccCommParamsSpec = nullptr; return; } (void)generator->generateKeyPair(generator, &keyPair); (void)generator->generatePriKey(generator, &priKey); (void)generator->generatePubKey(generator, &pubKey); - + switch (type) { + case GenerateType::FUZZ_PRIKEY: + DestroyEccPriKeySpec(reinterpret_cast(paramSpec)); + break; + case GenerateType::FUZZ_PUBKEY: + DestroyEccPubKeySpec(reinterpret_cast(paramSpec)); + break; + case GenerateType::FUZZ_KEYPAIR: + DestroyEccKeyPairSpec(reinterpret_cast(paramSpec)); + break; + default: + break; + } HcfObjDestroy(pubKey); HcfObjDestroy(priKey); HcfObjDestroy(keyPair); @@ -1582,24 +1678,36 @@ namespace OHOS { static void TestSm2KeyBySpec(void) { - ConstructSm2256CommParamsSpec("NID_sm2", &g_sm2256CommSpec); + if (ConstructSm2256CommParamsSpec("NID_sm2", &g_sm2256CommSpec) != HCF_SUCCESS) { + return; + } GenSm2KeyCommonBySpec(g_sm2256CommSpec); GenSm2KeyBySpec(GenerateType::FUZZ_PRIKEY, "SM2_256", g_sm2256CommSpec); + if (ConstructSm2256CommParamsSpec("NID_sm2", &g_sm2256CommSpec) != HCF_SUCCESS) { + return; + } GenSm2KeyBySpec(GenerateType::FUZZ_PUBKEY, "SM2_256", g_sm2256CommSpec); + if (ConstructSm2256CommParamsSpec("NID_sm2", &g_sm2256CommSpec) != HCF_SUCCESS) { + return; + } GenSm2KeyBySpec(GenerateType::FUZZ_KEYPAIR, "SM2_256", g_sm2256CommSpec); - FreeEccCommParamsSpec(g_sm2256CommSpec); - g_sm2256CommSpec = nullptr; } static void TestBrainpoolKeyBySpec(void) { - ConstructSm2256CommParamsSpec("NID_brainpoolP160r1", &g_brainpoolP160r1CommSpec); + if (ConstructSm2256CommParamsSpec("NID_brainpoolP160r1", &g_brainpoolP160r1CommSpec) != HCF_SUCCESS) { + return; + } GenSm2KeyCommonBySpec(g_brainpoolP160r1CommSpec); GenSm2KeyBySpec(GenerateType::FUZZ_PRIKEY, "ECC_BrainPoolP160r1", g_brainpoolP160r1CommSpec); + if (ConstructSm2256CommParamsSpec("NID_brainpoolP160r1", &g_brainpoolP160r1CommSpec) != HCF_SUCCESS) { + return; + } GenSm2KeyBySpec(GenerateType::FUZZ_PUBKEY, "ECC_BrainPoolP160r1", g_brainpoolP160r1CommSpec); + if (ConstructSm2256CommParamsSpec("NID_brainpoolP160r1", &g_brainpoolP160r1CommSpec) != HCF_SUCCESS) { + return; + } GenSm2KeyBySpec(GenerateType::FUZZ_KEYPAIR, "ECC_BrainPoolP160r1", g_brainpoolP160r1CommSpec); - FreeEccCommParamsSpec(g_brainpoolP160r1CommSpec); - g_brainpoolP160r1CommSpec = nullptr; } static void GenAlg25519KeyBySpec(GenerateType type, const std::string &algoName, @@ -1622,20 +1730,31 @@ namespace OHOS { res = ConstructAlg25519KeyPairParamsSpec(algoName, choose, ¶mSpec); break; default: - return; + break; } if (res != HCF_SUCCESS) { return; } res = HcfAsyKeyGeneratorBySpecCreate(paramSpec, &generator); if (res != HCF_SUCCESS) { - HcfObjDestroy(paramSpec); return; } (void)generator->generateKeyPair(generator, &keyPair); (void)generator->generatePriKey(generator, &priKey); (void)generator->generatePubKey(generator, &pubKey); - + switch (type) { + case GenerateType::FUZZ_PRIKEY: + DestroyAlg25519PriKeySpec(reinterpret_cast(paramSpec)); + break; + case GenerateType::FUZZ_PUBKEY: + DestroyAlg25519PubKeySpec(reinterpret_cast(paramSpec)); + break; + case GenerateType::FUZZ_KEYPAIR: + DestroyAlg25519KeyPairSpec(reinterpret_cast(paramSpec)); + break; + default: + break; + } HcfObjDestroy(pubKey); HcfObjDestroy(priKey); HcfObjDestroy(keyPair); @@ -1676,20 +1795,29 @@ namespace OHOS { res = ConstructDhKeyPairParamsSpec(algoName, dhCommParamsSpec, ¶mSpec); break; default: - return; - } - if (res != HCF_SUCCESS) { - return; + break; } - res = HcfAsyKeyGeneratorBySpecCreate(paramSpec, &generator); - if (res != HCF_SUCCESS) { - HcfObjDestroy(paramSpec); + if ((res != HCF_SUCCESS) || (HcfAsyKeyGeneratorBySpecCreate(paramSpec, &generator) != HCF_SUCCESS)) { + FreeDhCommParamsSpec(dhCommParamsSpec); + dhCommParamsSpec = nullptr; return; } (void)generator->generateKeyPair(generator, &keyPair); (void)generator->generatePriKey(generator, &priKey); (void)generator->generatePubKey(generator, &pubKey); - + switch (type) { + case GenerateType::FUZZ_PRIKEY: + DestroyDhPriKeySpec(reinterpret_cast(paramSpec)); + break; + case GenerateType::FUZZ_PUBKEY: + DestroyDhPubKeySpec(reinterpret_cast(paramSpec)); + break; + case GenerateType::FUZZ_KEYPAIR: + DestroyDhKeyPairSpec(reinterpret_cast(paramSpec)); + break; + default: + break; + } HcfObjDestroy(pubKey); HcfObjDestroy(priKey); HcfObjDestroy(keyPair); @@ -1718,13 +1846,19 @@ namespace OHOS { static void TestDhKeyBySpec(void) { - ConstructDhCommParamsSpec(PLEN_BITS, SKLEN_BITS, &g_dhCommSpec); + if (ConstructDhCommParamsSpec(PLEN_BITS, SKLEN_BITS, &g_dhCommSpec) != HCF_SUCCESS) { + return; + } GenDhKeyCommonBySpec(g_dhCommSpec); GenDhKeyBySpec(GenerateType::FUZZ_PRIKEY, "DH_ffdhe3072", g_dhCommSpec); + if (ConstructDhCommParamsSpec(PLEN_BITS, SKLEN_BITS, &g_dhCommSpec) != HCF_SUCCESS) { + return; + } GenDhKeyBySpec(GenerateType::FUZZ_PUBKEY, "DH_ffdhe3072", g_dhCommSpec); + if (ConstructDhCommParamsSpec(PLEN_BITS, SKLEN_BITS, &g_dhCommSpec) != HCF_SUCCESS) { + return; + } GenDhKeyBySpec(GenerateType::FUZZ_KEYPAIR, "DH_ffdhe3072", g_dhCommSpec); - FreeDhCommParamsSpec(g_dhCommSpec); - g_dhCommSpec = nullptr; } bool AsyKeyGeneratorFuzzTest(const uint8_t* data, size_t size) diff --git a/test/unittest/BUILD.gn b/test/unittest/BUILD.gn index bdc01396120a69cce6c2b05670eb0420fd0420bd..4f758fd45966e865b2503c215a18682897e6b6ce 100644 --- a/test/unittest/BUILD.gn +++ b/test/unittest/BUILD.gn @@ -102,6 +102,8 @@ ohos_unittest("crypto_framework_test") { "//base/security/crypto_framework/common/src/object_base.c", "//base/security/crypto_framework/common/src/params_parser.c", "//base/security/crypto_framework/common/src/utils.c", + "src/alg_25519_common_param_spec.c", + "src/ecc_common_param_spec.c", "src/memory_mock.c", "src/openssl_adapter_mock.c", ] diff --git a/test/unittest/include/alg_25519_common_param_spec.h b/test/unittest/include/alg_25519_common_param_spec.h new file mode 100644 index 0000000000000000000000000000000000000000..7c0c0f6ea6d0f63f129cf6c0304fe47031af02b9 --- /dev/null +++ b/test/unittest/include/alg_25519_common_param_spec.h @@ -0,0 +1,34 @@ +/* + * Copyright (C) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ALG_25519_COMMON_PARAM_SPEC_H +#define ALG_25519_COMMON_PARAM_SPEC_H + +#include +#include "detailed_alg_25519_key_params.h" +#include "result.h" + +#ifdef __cplusplus +extern "C" { +#endif + +HcfResult ConstructAlg25519KeyPairParamsSpec(const char *algoName, bool choose, HcfAsyKeyParamsSpec **spec); +HcfResult ConstructAlg25519PubKeyParamsSpec(const char *algoName, bool choose, HcfAsyKeyParamsSpec **spec); +HcfResult ConstructAlg25519PriKeyParamsSpec(const char *algoName, bool choose, HcfAsyKeyParamsSpec **spec); + +#ifdef __cplusplus +} +#endif +#endif diff --git a/test/unittest/include/ecc_common_param_spec.h b/test/unittest/include/ecc_common_param_spec.h new file mode 100644 index 0000000000000000000000000000000000000000..aa23ed9a50c665895295fe905378a9c86f32ccda --- /dev/null +++ b/test/unittest/include/ecc_common_param_spec.h @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ECC_COMMON_PARAM_SPEC_H +#define ECC_COMMON_PARAM_SPEC_H + +#include +#include "detailed_ecc_key_params.h" +#include "result.h" + +#ifdef __cplusplus +extern "C" { +#endif + +HcfResult ConstructEccKeyPairCommParamsSpec(const char *algoName, HcfEccCommParamsSpec **spec); +HcfResult ConstructEccKeyPairParamsSpec(const char *algoName, HcfEccCommParamsSpec *eccCommSpec, + HcfAsyKeyParamsSpec **spec); +HcfResult ConstructEccPubKeyParamsSpec(const char *algoName, HcfEccCommParamsSpec *eccCommSpec, + HcfAsyKeyParamsSpec **spec); +HcfResult ConstructEccPriKeyParamsSpec(const char *algoName, HcfEccCommParamsSpec *eccCommSpec, + HcfAsyKeyParamsSpec **spec); + +#ifdef __cplusplus +} +#endif +#endif diff --git a/test/unittest/src/alg_25519_common_param_spec.c b/test/unittest/src/alg_25519_common_param_spec.c new file mode 100644 index 0000000000000000000000000000000000000000..831688d5eda0127dc11d8c8eb7be004c4e11898d --- /dev/null +++ b/test/unittest/src/alg_25519_common_param_spec.c @@ -0,0 +1,227 @@ +/* + * Copyright (C) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "alg_25519_common_param_spec.h" +#include "securec.h" +#include "asy_key_generator.h" +#include "memory.h" +#include "memory_mock.h" + +static HcfResult CreateAlg25519KeyPairSpec(bool choose, HcfAlg25519KeyPairParamsSpec **alg25519KeyPairSpec) +{ + *alg25519KeyPairSpec = (HcfAlg25519KeyPairParamsSpec*)HcfMalloc(sizeof(HcfAlg25519KeyPairParamsSpec), 0); + if (*alg25519KeyPairSpec == NULL) { + return HCF_ERR_MALLOC; + } + if (choose) { + (*alg25519KeyPairSpec)->base.algName = (char*)HcfMalloc(sizeof("Ed25519"), 0); + if ((*alg25519KeyPairSpec)->base.algName == NULL) { + HcfFree(*alg25519KeyPairSpec); + *alg25519KeyPairSpec = NULL; + return HCF_ERR_MALLOC; + } + (void)memcpy_s((*alg25519KeyPairSpec)->base.algName, sizeof("Ed25519"), + "Ed25519", sizeof("Ed25519")); + } else { + (*alg25519KeyPairSpec)->base.algName = (char*)HcfMalloc(sizeof("X25519"), 0); + if ((*alg25519KeyPairSpec)->base.algName == NULL) { + HcfFree(*alg25519KeyPairSpec); + *alg25519KeyPairSpec = NULL; + return HCF_ERR_MALLOC; + } + (void)memcpy_s((*alg25519KeyPairSpec)->base.algName, sizeof("X25519"), + "X25519", sizeof("X25519")); + } + return HCF_SUCCESS; +} + +HcfResult ConstructAlg25519KeyPairParamsSpec(const char *algoName, bool choose, HcfAsyKeyParamsSpec **spec) +{ + HcfResult res = HCF_ERR_CRYPTO_OPERATION; + HcfAsyKeyGenerator *generator = NULL; + if (HcfAsyKeyGeneratorCreate(algoName, &generator) != HCF_SUCCESS) { + return res; + } + + HcfKeyPair *keyPair = NULL; + if (generator->generateKeyPair(generator, NULL, &keyPair) != HCF_SUCCESS) { + HcfObjDestroy(generator); + return res; + } + + HcfAlg25519KeyPairParamsSpec *alg25519KeyPairSpec = NULL; + if (CreateAlg25519KeyPairSpec(choose, &alg25519KeyPairSpec) == HCF_SUCCESS) { + HcfBigInteger retBigInt = { .data = NULL, .len = 0 }; + alg25519KeyPairSpec->base.specType = HCF_KEY_PAIR_SPEC; + if (choose) { + res = keyPair->pubKey->getAsyKeySpecBigInteger(keyPair->pubKey, ED25519_PK_BN, &retBigInt); + } else { + res = keyPair->pubKey->getAsyKeySpecBigInteger(keyPair->pubKey, X25519_PK_BN, &retBigInt); + } + if (res == HCF_SUCCESS) { + alg25519KeyPairSpec->pk.data = retBigInt.data; + alg25519KeyPairSpec->pk.len = retBigInt.len; + if (choose) { + res = keyPair->priKey->getAsyKeySpecBigInteger(keyPair->priKey, ED25519_SK_BN, &retBigInt); + } else { + res = keyPair->priKey->getAsyKeySpecBigInteger(keyPair->priKey, X25519_SK_BN, &retBigInt); + } + if (res == HCF_SUCCESS) { + alg25519KeyPairSpec->sk.data = retBigInt.data; + alg25519KeyPairSpec->sk.len = retBigInt.len; + *spec = (HcfAsyKeyParamsSpec *)alg25519KeyPairSpec; + } else { + HcfFree(alg25519KeyPairSpec->pk.data); + alg25519KeyPairSpec->pk.data = NULL; + alg25519KeyPairSpec->pk.len = 0; + } + } + if (res != HCF_SUCCESS) { + DestroyAlg25519KeyPairSpec((HcfAlg25519KeyPairParamsSpec *)alg25519KeyPairSpec); + } + } + + HcfObjDestroy(generator); + HcfObjDestroy(keyPair); + return res; +} + +static HcfResult CreateAlg25519PubKeySpec(bool choose, HcfAlg25519PubKeyParamsSpec **alg25519PubKeySpec) +{ + *alg25519PubKeySpec = (HcfAlg25519PubKeyParamsSpec*)HcfMalloc(sizeof(HcfAlg25519PubKeyParamsSpec), 0); + if (*alg25519PubKeySpec == NULL) { + return HCF_ERR_MALLOC; + } + if (choose) { + (*alg25519PubKeySpec)->base.algName = (char*)HcfMalloc(sizeof("Ed25519"), 0); + if ((*alg25519PubKeySpec)->base.algName == NULL) { + HcfFree(*alg25519PubKeySpec); + *alg25519PubKeySpec = NULL; + return HCF_ERR_MALLOC; + } + (void)memcpy_s((*alg25519PubKeySpec)->base.algName, sizeof("Ed25519"), + "Ed25519", sizeof("Ed25519")); + } else { + (*alg25519PubKeySpec)->base.algName = (char*)HcfMalloc(sizeof("X25519"), 0); + if ((*alg25519PubKeySpec)->base.algName == NULL) { + HcfFree(*alg25519PubKeySpec); + *alg25519PubKeySpec = NULL; + return HCF_ERR_MALLOC; + } + (void)memcpy_s((*alg25519PubKeySpec)->base.algName, sizeof("X25519"), + "X25519", sizeof("X25519")); + } + return HCF_SUCCESS; +} + +HcfResult ConstructAlg25519PubKeyParamsSpec(const char *algoName, bool choose, HcfAsyKeyParamsSpec **spec) +{ + HcfResult res = HCF_ERR_CRYPTO_OPERATION; + HcfAsyKeyGenerator *generator = NULL; + if (HcfAsyKeyGeneratorCreate(algoName, &generator) != HCF_SUCCESS) { + return res; + } + + HcfKeyPair *keyPair = NULL; + if (generator->generateKeyPair(generator, NULL, &keyPair) != HCF_SUCCESS) { + HcfObjDestroy(generator); + return res; + } + + HcfAlg25519PubKeyParamsSpec *alg25519PubKeySpec = NULL; + if (CreateAlg25519PubKeySpec(choose, &alg25519PubKeySpec) == HCF_SUCCESS) { + HcfBigInteger retBigInt = { .data = NULL, .len = 0 }; + alg25519PubKeySpec->base.specType = HCF_PUBLIC_KEY_SPEC; + if (choose) { + res = keyPair->pubKey->getAsyKeySpecBigInteger(keyPair->pubKey, ED25519_PK_BN, &retBigInt); + } else { + res = keyPair->pubKey->getAsyKeySpecBigInteger(keyPair->pubKey, X25519_PK_BN, &retBigInt); + } + if (res == HCF_SUCCESS) { + alg25519PubKeySpec->pk.data = retBigInt.data; + alg25519PubKeySpec->pk.len = retBigInt.len; + *spec = (HcfAsyKeyParamsSpec *)alg25519PubKeySpec; + } else { + DestroyAlg25519PubKeySpec((HcfAlg25519PubKeyParamsSpec *)alg25519PubKeySpec); + } + } + + HcfObjDestroy(generator); + HcfObjDestroy(keyPair); + return res; +} + +static HcfResult CreateAlg25519PriKeySpec(bool choose, HcfAlg25519PriKeyParamsSpec **alg25519PriKeySpec) +{ + *alg25519PriKeySpec = (HcfAlg25519PriKeyParamsSpec*)HcfMalloc(sizeof(HcfAlg25519PriKeyParamsSpec), 0); + if (*alg25519PriKeySpec == NULL) { + return HCF_ERR_MALLOC; + } + if (choose) { + (*alg25519PriKeySpec)->base.algName = (char*)HcfMalloc(sizeof("Ed25519"), 0); + if ((*alg25519PriKeySpec)->base.algName == NULL) { + HcfFree(*alg25519PriKeySpec); + *alg25519PriKeySpec = NULL; + return HCF_ERR_MALLOC; + } + (void)memcpy_s((*alg25519PriKeySpec)->base.algName, sizeof("Ed25519"), + "Ed25519", sizeof("Ed25519")); + } else { + (*alg25519PriKeySpec)->base.algName = (char*)HcfMalloc(sizeof("X25519"), 0); + if ((*alg25519PriKeySpec)->base.algName == NULL) { + HcfFree(*alg25519PriKeySpec); + *alg25519PriKeySpec = NULL; + return HCF_ERR_MALLOC; + } + (void)memcpy_s((*alg25519PriKeySpec)->base.algName, sizeof("X25519"), + "X25519", sizeof("X25519")); + } + return HCF_SUCCESS; +} + +HcfResult ConstructAlg25519PriKeyParamsSpec(const char *algoName, bool choose, HcfAsyKeyParamsSpec **spec) +{ + HcfResult res = HCF_ERR_CRYPTO_OPERATION; + HcfAsyKeyGenerator *generator = NULL; + if (HcfAsyKeyGeneratorCreate(algoName, &generator) != HCF_SUCCESS) { + return res; + } + + HcfKeyPair *keyPair = NULL; + if (generator->generateKeyPair(generator, NULL, &keyPair) != HCF_SUCCESS) { + HcfObjDestroy(generator); + return res; + } + HcfAlg25519PriKeyParamsSpec *alg25519PriKeySpec = NULL; + if (CreateAlg25519PriKeySpec(choose, &alg25519PriKeySpec) == HCF_SUCCESS) { + HcfBigInteger retBigInt = { .data = NULL, .len = 0 }; + alg25519PriKeySpec->base.specType = HCF_PRIVATE_KEY_SPEC; + if (choose) { + res = keyPair->priKey->getAsyKeySpecBigInteger(keyPair->priKey, ED25519_SK_BN, &retBigInt); + } else { + res = keyPair->priKey->getAsyKeySpecBigInteger(keyPair->priKey, X25519_SK_BN, &retBigInt); + } + if (res == HCF_SUCCESS) { + alg25519PriKeySpec->sk.data = retBigInt.data; + alg25519PriKeySpec->sk.len = retBigInt.len; + *spec = (HcfAsyKeyParamsSpec *)alg25519PriKeySpec; + } else { + DestroyAlg25519PriKeySpec((HcfAlg25519PriKeyParamsSpec *)alg25519PriKeySpec); + } + } + HcfObjDestroy(generator); + HcfObjDestroy(keyPair); + return res; +} diff --git a/test/unittest/src/crypto_brainpool_asy_key_generator_test.cpp b/test/unittest/src/crypto_brainpool_asy_key_generator_test.cpp index cb83f731ab09301fb964a71558a5084b59a95eb1..ee498bfd2ad30475852dc3a7527808390d8bcaa0 100644 --- a/test/unittest/src/crypto_brainpool_asy_key_generator_test.cpp +++ b/test/unittest/src/crypto_brainpool_asy_key_generator_test.cpp @@ -19,6 +19,7 @@ #include "asy_key_generator.h" #include "ecc_asy_key_generator_openssl.h" #include "blob.h" +#include "memory.h" #include "memory_mock.h" #include "openssl_adapter_mock.h" #include "params_parser.h" @@ -622,7 +623,7 @@ HWTEST_F(CryptoBrainPoolAsyKeyGeneratorTest, CryptoBrainPoolAsyKeyGeneratorTest0 ASSERT_NE(blob.data, nullptr); ASSERT_NE(blob.len, 0); - free(blob.data); + HcfFree(blob.data); HcfObjDestroy(keyPair); HcfObjDestroy(generator); } @@ -931,7 +932,7 @@ HWTEST_F(CryptoBrainPoolAsyKeyGeneratorTest, CryptoBrainPoolAsyKeyGeneratorTest0 ASSERT_NE(blob.data, nullptr); ASSERT_NE(blob.len, 0); - free(blob.data); + HcfFree(blob.data); HcfObjDestroy(keyPair); HcfObjDestroy(generator); } @@ -1367,7 +1368,7 @@ HWTEST_F(CryptoBrainPoolAsyKeyGeneratorTest, CryptoBrainPoolAsyKeyGeneratorTest0 ASSERT_NE(blob.data, nullptr); ASSERT_NE(blob.len, 0); - free(blob.data); + HcfFree(blob.data); HcfObjDestroy(keyPair); HcfObjDestroy(generator); } @@ -1693,7 +1694,7 @@ HWTEST_F(CryptoBrainPoolAsyKeyGeneratorTest, CryptoBrainPoolAsyKeyGeneratorTest0 ASSERT_NE(blob.data, nullptr); ASSERT_NE(blob.len, 0); - free(blob.data); + HcfFree(blob.data); HcfObjDestroy(keyPair); HcfObjDestroy(generator); } @@ -1717,7 +1718,7 @@ HWTEST_F(CryptoBrainPoolAsyKeyGeneratorTest, CryptoBrainPoolAsyKeyGeneratorTest0 ASSERT_EQ(blob.data, nullptr); ASSERT_EQ(blob.len, 0); - free(blob.data); + HcfFree(blob.data); HcfObjDestroy(keyPair); HcfObjDestroy(generator); } @@ -1741,7 +1742,7 @@ HWTEST_F(CryptoBrainPoolAsyKeyGeneratorTest, CryptoBrainPoolAsyKeyGeneratorTest0 ASSERT_EQ(blob.data, nullptr); ASSERT_EQ(blob.len, 0); - free(blob.data); + HcfFree(blob.data); HcfObjDestroy(keyPair); HcfObjDestroy(generator); } @@ -1765,7 +1766,7 @@ HWTEST_F(CryptoBrainPoolAsyKeyGeneratorTest, CryptoBrainPoolAsyKeyGeneratorTest0 ASSERT_EQ(blob.data, nullptr); ASSERT_EQ(blob.len, 0); - free(blob.data); + HcfFree(blob.data); HcfObjDestroy(keyPair); HcfObjDestroy(generator); } @@ -1811,10 +1812,10 @@ HWTEST_F(CryptoBrainPoolAsyKeyGeneratorTest, CryptoBrainPoolAsyKeyGeneratorTest0 ASSERT_NE(outPriKeyBlob.data, nullptr); ASSERT_NE(outPriKeyBlob.len, 0); - free(pubKeyBlob.data); - free(priKeyBlob.data); - free(outPubKeyBlob.data); - free(outPriKeyBlob.data); + HcfFree(pubKeyBlob.data); + HcfFree(priKeyBlob.data); + HcfFree(outPubKeyBlob.data); + HcfFree(outPriKeyBlob.data); HcfObjDestroy(outKeyPair); HcfObjDestroy(keyPair); HcfObjDestroy(generator); @@ -1942,15 +1943,15 @@ static void MemoryMallocTestFunc(uint32_t mallocCount) }; res = tmpKeyPair->priKey->base.getEncoded(&(tmpKeyPair->priKey->base), &tmpPriKeyBlob); if (res != HCF_SUCCESS) { - free(tmpPubKeyBlob.data); + HcfFree(tmpPubKeyBlob.data); HcfObjDestroy(tmpKeyPair); HcfObjDestroy(tmpGenerator); continue; } HcfKeyPair *tmpOutKeyPair = nullptr; res = tmpGenerator->convertKey(tmpGenerator, nullptr, &tmpPubKeyBlob, &tmpPriKeyBlob, &tmpOutKeyPair); - free(tmpPubKeyBlob.data); - free(tmpPriKeyBlob.data); + HcfFree(tmpPubKeyBlob.data); + HcfFree(tmpPriKeyBlob.data); HcfObjDestroy(tmpKeyPair); HcfObjDestroy(tmpGenerator); if (res == HCF_SUCCESS) { @@ -1988,8 +1989,8 @@ HWTEST_F(CryptoBrainPoolAsyKeyGeneratorTest, CryptoBrainPoolAsyKeyGeneratorTest0 HcfKeyPair *outKeyPair = nullptr; res = generator->convertKey(generator, nullptr, &pubKeyBlob, &priKeyBlob, &outKeyPair); - free(pubKeyBlob.data); - free(priKeyBlob.data); + HcfFree(pubKeyBlob.data); + HcfFree(priKeyBlob.data); HcfObjDestroy(outKeyPair); HcfObjDestroy(keyPair); HcfObjDestroy(generator); @@ -2031,15 +2032,15 @@ static void OpensslMockTestFunc(uint32_t mallocCount) }; res = tmpKeyPair->priKey->base.getEncoded(&(tmpKeyPair->priKey->base), &tmpPriKeyBlob); if (res != HCF_SUCCESS) { - free(tmpPubKeyBlob.data); + HcfFree(tmpPubKeyBlob.data); HcfObjDestroy(tmpKeyPair); HcfObjDestroy(tmpGenerator); continue; } HcfKeyPair *tmpOutKeyPair = nullptr; res = tmpGenerator->convertKey(tmpGenerator, nullptr, &tmpPubKeyBlob, &tmpPriKeyBlob, &tmpOutKeyPair); - free(tmpPubKeyBlob.data); - free(tmpPriKeyBlob.data); + HcfFree(tmpPubKeyBlob.data); + HcfFree(tmpPriKeyBlob.data); HcfObjDestroy(tmpKeyPair); HcfObjDestroy(tmpGenerator); if (res == HCF_SUCCESS) { @@ -2077,8 +2078,8 @@ HWTEST_F(CryptoBrainPoolAsyKeyGeneratorTest, CryptoBrainPoolAsyKeyGeneratorTest0 HcfKeyPair *outKeyPair = nullptr; res = generator->convertKey(generator, nullptr, &pubKeyBlob, &priKeyBlob, &outKeyPair); - free(pubKeyBlob.data); - free(priKeyBlob.data); + HcfFree(pubKeyBlob.data); + HcfFree(priKeyBlob.data); HcfObjDestroy(outKeyPair); HcfObjDestroy(keyPair); HcfObjDestroy(generator); diff --git a/test/unittest/src/crypto_brainpool_key_agreement_test.cpp b/test/unittest/src/crypto_brainpool_key_agreement_test.cpp index 403aef203ff198e9bc6ff0b0dccf67108ae11137..43cbb3e2c3125f40305b3e131d688e0af022c496 100644 --- a/test/unittest/src/crypto_brainpool_key_agreement_test.cpp +++ b/test/unittest/src/crypto_brainpool_key_agreement_test.cpp @@ -17,10 +17,11 @@ #include "securec.h" #include "asy_key_generator.h" -#include "detailed_ecc_key_params.h" +#include "ecc_common_param_spec.h" #include "ecdh_openssl.h" #include "key_agreement.h" #include "ecc_key_util.h" +#include "memory.h" #include "memory_mock.h" #include "openssl_adapter_mock.h" #include "params_parser.h" @@ -31,8 +32,8 @@ using namespace testing::ext; namespace { class CryptoBrainPoolKeyAgreementTest : public testing::Test { public: - static void SetUpTestCase(); - static void TearDownTestCase(); + static void SetUpTestCase() {}; + static void TearDownTestCase() {}; void SetUp(); void TearDown(); }; @@ -42,7 +43,6 @@ void CryptoBrainPoolKeyAgreementTest::TearDown() {} static string g_brainpool160r1AlgName = "ECC_BrainPoolP160r1"; HcfEccCommParamsSpec *g_eccCommSpec = nullptr; -HcfEccKeyPairParamsSpec g_brainpool160r1KeyPairSpec; static const char *GetMockClass(void) { @@ -54,80 +54,10 @@ static HcfObjectBase obj = { .destroy = nullptr }; -static HcfResult ConstructEccBrainPool160r1KeyPairCommParamsSpec(const string &algoName, HcfEccCommParamsSpec **spec) -{ - HcfEccCommParamsSpec *eccCommSpec = nullptr; - - HcfEccKeyUtilCreate(algoName.c_str(), &eccCommSpec); - if (eccCommSpec == nullptr) { - return HCF_INVALID_PARAMS; - } - - *spec = eccCommSpec; - return HCF_SUCCESS; -} - -static HcfResult Constructbrainpool160r1KeyPairParamsSpec(const string &algoName, HcfAsyKeyParamsSpec **spec) -{ - HcfAsyKeyGenerator *generator = nullptr; - HcfResult res = HcfAsyKeyGeneratorCreate(algoName.c_str(), &generator); - if (res != HCF_SUCCESS) { - return res; - } - HcfKeyPair *keyPair = nullptr; - res = generator->generateKeyPair(generator, nullptr, &keyPair); - if (res != HCF_SUCCESS) { - HcfObjDestroy(generator); - return res; - } - HcfEccKeyPairParamsSpec *eccKeyPairSpec = &g_brainpool160r1KeyPairSpec; - HcfBigInteger retBigInt = { .data = nullptr, .len = 0 }; - eccKeyPairSpec->base.base.algName = g_eccCommSpec->base.algName; - eccKeyPairSpec->base.base.specType = HCF_KEY_PAIR_SPEC; - eccKeyPairSpec->base.field = g_eccCommSpec->field; - eccKeyPairSpec->base.field->fieldType = g_eccCommSpec->field->fieldType; - ((HcfECFieldFp *)(eccKeyPairSpec->base.field))->p.data = ((HcfECFieldFp *)(g_eccCommSpec->field))->p.data; - ((HcfECFieldFp *)(eccKeyPairSpec->base.field))->p.len = ((HcfECFieldFp *)(g_eccCommSpec->field))->p.len; - eccKeyPairSpec->base.a.data = g_eccCommSpec->a.data; - eccKeyPairSpec->base.a.len = g_eccCommSpec->a.len; - eccKeyPairSpec->base.b.data = g_eccCommSpec->b.data; - eccKeyPairSpec->base.b.len = g_eccCommSpec->b.len; - eccKeyPairSpec->base.g.x.data = g_eccCommSpec->g.x.data; - eccKeyPairSpec->base.g.x.len = g_eccCommSpec->g.x.len; - eccKeyPairSpec->base.g.y.data = g_eccCommSpec->g.y.data; - eccKeyPairSpec->base.g.y.len = g_eccCommSpec->g.y.len; - eccKeyPairSpec->base.n.data = g_eccCommSpec->n.data; - eccKeyPairSpec->base.n.len = g_eccCommSpec->n.len; - eccKeyPairSpec->base.h = g_eccCommSpec->h; - res = keyPair->pubKey->getAsyKeySpecBigInteger(keyPair->pubKey, ECC_PK_X_BN, &retBigInt); - eccKeyPairSpec->pk.x.data = retBigInt.data; - eccKeyPairSpec->pk.x.len = retBigInt.len; - res = keyPair->pubKey->getAsyKeySpecBigInteger(keyPair->pubKey, ECC_PK_Y_BN, &retBigInt); - eccKeyPairSpec->pk.y.data =retBigInt.data; - eccKeyPairSpec->pk.y.len = retBigInt.len; - res = keyPair->priKey->getAsyKeySpecBigInteger(keyPair->priKey, ECC_SK_BN, &retBigInt); - eccKeyPairSpec->sk.data = retBigInt.data; - eccKeyPairSpec->sk.len = retBigInt.len; - *spec = (HcfAsyKeyParamsSpec *)eccKeyPairSpec; - HcfObjDestroy(generator); - HcfObjDestroy(keyPair); - return HCF_SUCCESS; -} - -void CryptoBrainPoolKeyAgreementTest::SetUpTestCase() -{ - ConstructEccBrainPool160r1KeyPairCommParamsSpec("NID_brainpoolP160r1", &g_eccCommSpec); -} - -void CryptoBrainPoolKeyAgreementTest::TearDownTestCase() -{ - FreeEccCommParamsSpec(g_eccCommSpec); -} - HWTEST_F(CryptoBrainPoolKeyAgreementTest, CryptoBrainPoolKeyAgreementTest001, TestSize.Level0) { HcfKeyAgreement *keyAgreement = nullptr; - int32_t res = HcfKeyAgreementCreate("ECC_BrainPoolP160r1", &keyAgreement); + HcfResult res = HcfKeyAgreementCreate("ECC_BrainPoolP160r1", &keyAgreement); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(keyAgreement, nullptr); @@ -137,7 +67,7 @@ HWTEST_F(CryptoBrainPoolKeyAgreementTest, CryptoBrainPoolKeyAgreementTest001, Te HWTEST_F(CryptoBrainPoolKeyAgreementTest, CryptoBrainPoolKeyAgreementTest002, TestSize.Level0) { HcfKeyAgreement *keyAgreement = nullptr; - int32_t res = HcfKeyAgreementCreate(nullptr, &keyAgreement); + HcfResult res = HcfKeyAgreementCreate(nullptr, &keyAgreement); ASSERT_NE(res, HCF_SUCCESS); ASSERT_EQ(keyAgreement, nullptr); @@ -147,7 +77,7 @@ HWTEST_F(CryptoBrainPoolKeyAgreementTest, CryptoBrainPoolKeyAgreementTest002, Te HWTEST_F(CryptoBrainPoolKeyAgreementTest, CryptoBrainPoolKeyAgreementTest003, TestSize.Level0) { HcfKeyAgreement *keyAgreement = nullptr; - int32_t res = HcfKeyAgreementCreate("ABCDABCDABCDABCDABCDABCDABCDABCDABCDABCDABCDABCDABCDABCDABCD" + HcfResult res = HcfKeyAgreementCreate("ABCDABCDABCDABCDABCDABCDABCDABCDABCDABCDABCDABCDABCDABCDABCD" "ABCDABCDABCDABCDABCDABCDABCDABCDABCDABCDABCDABCDABCDABCDABCDABCDABCD", &keyAgreement); ASSERT_NE(res, HCF_SUCCESS); @@ -158,7 +88,7 @@ HWTEST_F(CryptoBrainPoolKeyAgreementTest, CryptoBrainPoolKeyAgreementTest003, Te HWTEST_F(CryptoBrainPoolKeyAgreementTest, CryptoBrainPoolKeyAgreementTest004, TestSize.Level0) { HcfKeyAgreement *keyAgreement = nullptr; - int32_t res = HcfKeyAgreementCreate("SM257", &keyAgreement); + HcfResult res = HcfKeyAgreementCreate("SM257", &keyAgreement); ASSERT_NE(res, HCF_SUCCESS); ASSERT_EQ(keyAgreement, nullptr); @@ -167,14 +97,14 @@ HWTEST_F(CryptoBrainPoolKeyAgreementTest, CryptoBrainPoolKeyAgreementTest004, Te HWTEST_F(CryptoBrainPoolKeyAgreementTest, CryptoBrainPoolKeyAgreementTest005, TestSize.Level0) { - int32_t res = HcfKeyAgreementCreate("ECC_BrainPoolP512t1", nullptr); + HcfResult res = HcfKeyAgreementCreate("ECC_BrainPoolP512t1", nullptr); ASSERT_NE(res, HCF_SUCCESS); } HWTEST_F(CryptoBrainPoolKeyAgreementTest, CryptoBrainPoolKeyAgreementTest006, TestSize.Level0) { HcfKeyAgreement *keyAgreement = nullptr; - int32_t res = HcfKeyAgreementCreate("ECC_BrainPoolP160r1", &keyAgreement); + HcfResult res = HcfKeyAgreementCreate("ECC_BrainPoolP160r1", &keyAgreement); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(keyAgreement, nullptr); @@ -187,7 +117,7 @@ HWTEST_F(CryptoBrainPoolKeyAgreementTest, CryptoBrainPoolKeyAgreementTest006, Te HWTEST_F(CryptoBrainPoolKeyAgreementTest, CryptoBrainPoolKeyAgreementTest007, TestSize.Level0) { HcfKeyAgreement *keyAgreement = nullptr; - int32_t res = HcfKeyAgreementCreate("ECC_BrainPoolP160r1", &keyAgreement); + HcfResult res = HcfKeyAgreementCreate("ECC_BrainPoolP160r1", &keyAgreement); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(keyAgreement, nullptr); @@ -197,7 +127,7 @@ HWTEST_F(CryptoBrainPoolKeyAgreementTest, CryptoBrainPoolKeyAgreementTest007, Te HWTEST_F(CryptoBrainPoolKeyAgreementTest, CryptoBrainPoolKeyAgreementTest008, TestSize.Level0) { HcfKeyAgreement *keyAgreement = nullptr; - int32_t res = HcfKeyAgreementCreate("ECC_BrainPoolP160r1", &keyAgreement); + HcfResult res = HcfKeyAgreementCreate("ECC_BrainPoolP160r1", &keyAgreement); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(keyAgreement, nullptr); @@ -209,7 +139,7 @@ HWTEST_F(CryptoBrainPoolKeyAgreementTest, CryptoBrainPoolKeyAgreementTest008, Te HWTEST_F(CryptoBrainPoolKeyAgreementTest, CryptoBrainPoolKeyAgreementTest009, TestSize.Level0) { HcfKeyAgreement *keyAgreement = nullptr; - int32_t res = HcfKeyAgreementCreate("ECC_BrainPoolP160r1", &keyAgreement); + HcfResult res = HcfKeyAgreementCreate("ECC_BrainPoolP160r1", &keyAgreement); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(keyAgreement, nullptr); @@ -221,7 +151,7 @@ HWTEST_F(CryptoBrainPoolKeyAgreementTest, CryptoBrainPoolKeyAgreementTest009, Te HWTEST_F(CryptoBrainPoolKeyAgreementTest, CryptoBrainPoolKeyAgreementTest010, TestSize.Level0) { HcfKeyAgreement *keyAgreement = nullptr; - int32_t res = HcfKeyAgreementCreate("ECC_BrainPoolP160r1", &keyAgreement); + HcfResult res = HcfKeyAgreementCreate("ECC_BrainPoolP160r1", &keyAgreement); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(keyAgreement, nullptr); @@ -234,7 +164,7 @@ HWTEST_F(CryptoBrainPoolKeyAgreementTest, CryptoBrainPoolKeyAgreementTest010, Te HWTEST_F(CryptoBrainPoolKeyAgreementTest, CryptoBrainPoolKeyAgreementTest011, TestSize.Level0) { HcfKeyAgreement *keyAgreement = nullptr; - int32_t res = HcfKeyAgreementCreate("ECC_BrainPoolP160r1", &keyAgreement); + HcfResult res = HcfKeyAgreementCreate("ECC_BrainPoolP160r1", &keyAgreement); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(keyAgreement, nullptr); @@ -247,7 +177,7 @@ HWTEST_F(CryptoBrainPoolKeyAgreementTest, CryptoBrainPoolKeyAgreementTest011, Te HWTEST_F(CryptoBrainPoolKeyAgreementTest, CryptoBrainPoolKeyAgreementTest012, TestSize.Level0) { HcfKeyAgreement *keyAgreement = nullptr; - int32_t res = HcfKeyAgreementCreate("ECC_BrainPoolP160r1", &keyAgreement); + HcfResult res = HcfKeyAgreementCreate("ECC_BrainPoolP160r1", &keyAgreement); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(keyAgreement, nullptr); @@ -260,13 +190,15 @@ HWTEST_F(CryptoBrainPoolKeyAgreementTest, CryptoBrainPoolKeyAgreementTest012, Te HWTEST_F(CryptoBrainPoolKeyAgreementTest, CryptoBrainPoolKeyAgreementTest013, TestSize.Level0) { HcfKeyAgreement *keyAgreement = nullptr; - int32_t res = HcfKeyAgreementCreate("ECC_BrainPoolP160r1", &keyAgreement); + HcfResult res = HcfKeyAgreementCreate("ECC_BrainPoolP160r1", &keyAgreement); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(keyAgreement, nullptr); + ConstructEccKeyPairCommParamsSpec("NID_brainpoolP160r1", &g_eccCommSpec); + ASSERT_NE(g_eccCommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - res = Constructbrainpool160r1KeyPairParamsSpec(g_brainpool160r1AlgName, ¶mSpec); + res = ConstructEccKeyPairParamsSpec(g_brainpool160r1AlgName.c_str(), g_eccCommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); @@ -287,22 +219,25 @@ HWTEST_F(CryptoBrainPoolKeyAgreementTest, CryptoBrainPoolKeyAgreementTest013, Te ASSERT_NE(out.data, nullptr); ASSERT_NE(out.len, (const unsigned int)0); - free(out.data); + HcfFree(out.data); HcfObjDestroy(keyPair); HcfObjDestroy(keyAgreement); HcfObjDestroy(generator); + DestroyEccKeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoBrainPoolKeyAgreementTest, CryptoBrainPoolKeyAgreementTest014, TestSize.Level0) { HcfKeyAgreement *keyAgreement = nullptr; - int32_t res = HcfKeyAgreementCreate("ECC_BrainPoolP160r1", &keyAgreement); + HcfResult res = HcfKeyAgreementCreate("ECC_BrainPoolP160r1", &keyAgreement); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(keyAgreement, nullptr); + ConstructEccKeyPairCommParamsSpec("NID_brainpoolP160r1", &g_eccCommSpec); + ASSERT_NE(g_eccCommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - res = Constructbrainpool160r1KeyPairParamsSpec(g_brainpool160r1AlgName, ¶mSpec); + res = ConstructEccKeyPairParamsSpec(g_brainpool160r1AlgName.c_str(), g_eccCommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); @@ -323,22 +258,25 @@ HWTEST_F(CryptoBrainPoolKeyAgreementTest, CryptoBrainPoolKeyAgreementTest014, Te ASSERT_EQ(out.data, nullptr); ASSERT_EQ(out.len, (const unsigned int)0); - free(out.data); + HcfFree(out.data); HcfObjDestroy(keyPair); HcfObjDestroy(keyAgreement); HcfObjDestroy(generator); + DestroyEccKeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoBrainPoolKeyAgreementTest, CryptoBrainPoolKeyAgreementTest015, TestSize.Level0) { HcfKeyAgreement *keyAgreement = nullptr; - int32_t res = HcfKeyAgreementCreate("ECC_BrainPoolP160r1", &keyAgreement); + HcfResult res = HcfKeyAgreementCreate("ECC_BrainPoolP160r1", &keyAgreement); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(keyAgreement, nullptr); + ConstructEccKeyPairCommParamsSpec("NID_brainpoolP160r1", &g_eccCommSpec); + ASSERT_NE(g_eccCommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - res = Constructbrainpool160r1KeyPairParamsSpec(g_brainpool160r1AlgName, ¶mSpec); + res = ConstructEccKeyPairParamsSpec(g_brainpool160r1AlgName.c_str(), g_eccCommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); @@ -359,22 +297,25 @@ HWTEST_F(CryptoBrainPoolKeyAgreementTest, CryptoBrainPoolKeyAgreementTest015, Te ASSERT_EQ(out.data, nullptr); ASSERT_EQ(out.len, (const unsigned int)0); - free(out.data); + HcfFree(out.data); HcfObjDestroy(keyPair); HcfObjDestroy(keyAgreement); HcfObjDestroy(generator); + DestroyEccKeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoBrainPoolKeyAgreementTest, CryptoBrainPoolKeyAgreementTest016, TestSize.Level0) { HcfKeyAgreement *keyAgreement = nullptr; - int32_t res = HcfKeyAgreementCreate("ECC_BrainPoolP160r1", &keyAgreement); + HcfResult res = HcfKeyAgreementCreate("ECC_BrainPoolP160r1", &keyAgreement); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(keyAgreement, nullptr); + ConstructEccKeyPairCommParamsSpec("NID_brainpoolP160r1", &g_eccCommSpec); + ASSERT_NE(g_eccCommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - res = Constructbrainpool160r1KeyPairParamsSpec(g_brainpool160r1AlgName, ¶mSpec); + res = ConstructEccKeyPairParamsSpec(g_brainpool160r1AlgName.c_str(), g_eccCommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); @@ -395,22 +336,25 @@ HWTEST_F(CryptoBrainPoolKeyAgreementTest, CryptoBrainPoolKeyAgreementTest016, Te ASSERT_EQ(out.data, nullptr); ASSERT_EQ(out.len, (const unsigned int)0); - free(out.data); + HcfFree(out.data); HcfObjDestroy(keyPair); HcfObjDestroy(keyAgreement); HcfObjDestroy(generator); + DestroyEccKeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoBrainPoolKeyAgreementTest, CryptoBrainPoolKeyAgreementTest017, TestSize.Level0) { HcfKeyAgreement *keyAgreement = nullptr; - int32_t res = HcfKeyAgreementCreate("ECC_BrainPoolP160r1", &keyAgreement); + HcfResult res = HcfKeyAgreementCreate("ECC_BrainPoolP160r1", &keyAgreement); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(keyAgreement, nullptr); + ConstructEccKeyPairCommParamsSpec("NID_brainpoolP160r1", &g_eccCommSpec); + ASSERT_NE(g_eccCommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - res = Constructbrainpool160r1KeyPairParamsSpec(g_brainpool160r1AlgName, ¶mSpec); + res = ConstructEccKeyPairParamsSpec(g_brainpool160r1AlgName.c_str(), g_eccCommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); @@ -429,6 +373,7 @@ HWTEST_F(CryptoBrainPoolKeyAgreementTest, CryptoBrainPoolKeyAgreementTest017, Te HcfObjDestroy(keyPair); HcfObjDestroy(keyAgreement); HcfObjDestroy(generator); + DestroyEccKeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoBrainPoolKeyAgreementTest, CryptoBrainPoolKeyAgreementTest018, TestSize.Level0) @@ -476,7 +421,7 @@ HWTEST_F(CryptoBrainPoolKeyAgreementTest, CryptoBrainPoolKeyAgreementTest018, Te HcfObjDestroy(generator); HcfObjDestroy(keyPair1); HcfObjDestroy(keyPair2); - free(outBlob1.data); - free(outBlob2.data); -} + HcfFree(outBlob1.data); + HcfFree(outBlob2.data); } +} \ No newline at end of file diff --git a/test/unittest/src/crypto_brainpool_no_length_sign_test.cpp b/test/unittest/src/crypto_brainpool_no_length_sign_test.cpp index b4e0430fca257fa2ef7e9feacac913b0763d8274..99c71a4419c097edb3ecc2a986e1758246ea14e5 100644 --- a/test/unittest/src/crypto_brainpool_no_length_sign_test.cpp +++ b/test/unittest/src/crypto_brainpool_no_length_sign_test.cpp @@ -17,10 +17,10 @@ #include #include "asy_key_generator.h" +#include "ecc_common_param_spec.h" #include "ecc_key_util.h" #include "key_utils.h" #include "blob.h" -#include "detailed_ecc_key_params.h" #include "ecc_openssl_common.h" #include "ecc_openssl_common_param_spec.h" #include "ecc_common.h" @@ -40,17 +40,16 @@ using namespace testing::ext; namespace { class CryptoBrainPoolNoLengthSignTest : public testing::Test { public: - static void SetUpTestCase(); - static void TearDownTestCase(); + static void SetUpTestCase() {}; + static void TearDownTestCase() {}; void SetUp(); void TearDown(); }; static string g_brainpool160r1AlgName = "ECC_BrainPoolP160r1"; -static string g_brainpool160r1curveName = "NID_brainpoolP160r1"; +static string g_brainpool160r1CurveName = "NID_brainpoolP160r1"; HcfEccCommParamsSpec *g_eccCommSpec = nullptr; -HcfEccKeyPairParamsSpec g_brainpool160r1KeyPairSpec; void CryptoBrainPoolNoLengthSignTest::SetUp() {} void CryptoBrainPoolNoLengthSignTest::TearDown() {} @@ -71,74 +70,10 @@ HcfObjectBase obj = { .destroy = nullptr }; -static HcfResult ConstructEccBrainPool160r1KeyPairCommParamsSpec(const string &algoName, HcfEccCommParamsSpec **spec) -{ - HcfEccCommParamsSpec *eccCommSpec = nullptr; - HcfEccKeyUtilCreate(algoName.c_str(), &eccCommSpec); - *spec = eccCommSpec; - return HCF_SUCCESS; -} - -static HcfResult Constructbrainpool160r1KeyPairParamsSpec(const string &algoName, const string &curveName, - HcfAsyKeyParamsSpec **spec) -{ - HcfAsyKeyGenerator *generator = nullptr; - int32_t res = HcfAsyKeyGeneratorCreate(algoName.c_str(), &generator); - - HcfKeyPair *keyPair = nullptr; - res = generator->generateKeyPair(generator, nullptr, &keyPair); - - HcfEccKeyPairParamsSpec *eccKeyPairSpec = &g_brainpool160r1KeyPairSpec; - HcfBigInteger retBigInt = { .data = nullptr, .len = 0 }; - - eccKeyPairSpec->base.base.algName = g_eccCommSpec->base.algName; - eccKeyPairSpec->base.base.specType = HCF_KEY_PAIR_SPEC; - eccKeyPairSpec->base.field = g_eccCommSpec->field; - eccKeyPairSpec->base.field->fieldType = g_eccCommSpec->field->fieldType; - ((HcfECFieldFp *)(eccKeyPairSpec->base.field))->p.data = ((HcfECFieldFp *)(g_eccCommSpec->field))->p.data; - ((HcfECFieldFp *)(eccKeyPairSpec->base.field))->p.len = ((HcfECFieldFp *)(g_eccCommSpec->field))->p.len; - eccKeyPairSpec->base.a.data = g_eccCommSpec->a.data; - eccKeyPairSpec->base.a.len = g_eccCommSpec->a.len; - eccKeyPairSpec->base.b.data = g_eccCommSpec->b.data; - eccKeyPairSpec->base.b.len = g_eccCommSpec->b.len; - eccKeyPairSpec->base.g.x.data = g_eccCommSpec->g.x.data; - eccKeyPairSpec->base.g.x.len = g_eccCommSpec->g.x.len; - eccKeyPairSpec->base.g.y.data = g_eccCommSpec->g.y.data; - eccKeyPairSpec->base.g.y.len = g_eccCommSpec->g.y.len; - eccKeyPairSpec->base.n.data = g_eccCommSpec->n.data; - eccKeyPairSpec->base.n.len = g_eccCommSpec->n.len; - eccKeyPairSpec->base.h = g_eccCommSpec->h; - res = keyPair->pubKey->getAsyKeySpecBigInteger(keyPair->pubKey, ECC_PK_X_BN, &retBigInt); - eccKeyPairSpec->pk.x.data = retBigInt.data; - eccKeyPairSpec->pk.x.len = retBigInt.len; - - res = keyPair->pubKey->getAsyKeySpecBigInteger(keyPair->pubKey, ECC_PK_Y_BN, &retBigInt); - eccKeyPairSpec->pk.y.data =retBigInt.data; - eccKeyPairSpec->pk.y.len = retBigInt.len; - - res = keyPair->priKey->getAsyKeySpecBigInteger(keyPair->priKey, ECC_SK_BN, &retBigInt); - eccKeyPairSpec->sk.data = retBigInt.data; - eccKeyPairSpec->sk.len = retBigInt.len; - - *spec = (HcfAsyKeyParamsSpec *)eccKeyPairSpec; - HcfObjDestroy(generator); - return HCF_SUCCESS; -} - -void CryptoBrainPoolNoLengthSignTest::SetUpTestCase() -{ - ConstructEccBrainPool160r1KeyPairCommParamsSpec("NID_brainpoolP160r1", &g_eccCommSpec); -} - -void CryptoBrainPoolNoLengthSignTest::TearDownTestCase() -{ - FreeEccCommParamsSpec(g_eccCommSpec); -} - HWTEST_F(CryptoBrainPoolNoLengthSignTest, CryptoBrainPoolNoLengthSignTest001_1, TestSize.Level0) { HcfSign *sign = nullptr; - int32_t res = HcfSignCreate("ECC_BrainPoolP160r1|SHA1", &sign); + HcfResult res = HcfSignCreate("ECC_BrainPoolP160r1|SHA1", &sign); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(sign, nullptr); HcfObjDestroy(sign); @@ -147,7 +82,7 @@ HWTEST_F(CryptoBrainPoolNoLengthSignTest, CryptoBrainPoolNoLengthSignTest001_1, HWTEST_F(CryptoBrainPoolNoLengthSignTest, CryptoBrainPoolNoLengthSignTest001_2, TestSize.Level0) { HcfSign *sign = nullptr; - int32_t res = HcfSignCreate("ECC_BrainPoolP160r1|SHA224", &sign); + HcfResult res = HcfSignCreate("ECC_BrainPoolP160r1|SHA224", &sign); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(sign, nullptr); HcfObjDestroy(sign); @@ -156,7 +91,7 @@ HWTEST_F(CryptoBrainPoolNoLengthSignTest, CryptoBrainPoolNoLengthSignTest001_2, HWTEST_F(CryptoBrainPoolNoLengthSignTest, CryptoBrainPoolNoLengthSignTest001_3, TestSize.Level0) { HcfSign *sign = nullptr; - int32_t res = HcfSignCreate("ECC_BrainPoolP160r1|SHA256", &sign); + HcfResult res = HcfSignCreate("ECC_BrainPoolP160r1|SHA256", &sign); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(sign, nullptr); HcfObjDestroy(sign); @@ -165,7 +100,7 @@ HWTEST_F(CryptoBrainPoolNoLengthSignTest, CryptoBrainPoolNoLengthSignTest001_3, HWTEST_F(CryptoBrainPoolNoLengthSignTest, CryptoBrainPoolNoLengthSignTest001_4, TestSize.Level0) { HcfSign *sign = nullptr; - int32_t res = HcfSignCreate("ECC_BrainPoolP160r1|SHA384", &sign); + HcfResult res = HcfSignCreate("ECC_BrainPoolP160r1|SHA384", &sign); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(sign, nullptr); HcfObjDestroy(sign); @@ -174,7 +109,7 @@ HWTEST_F(CryptoBrainPoolNoLengthSignTest, CryptoBrainPoolNoLengthSignTest001_4, HWTEST_F(CryptoBrainPoolNoLengthSignTest, CryptoBrainPoolNoLengthSignTest001_5, TestSize.Level0) { HcfSign *sign = nullptr; - int32_t res = HcfSignCreate("ECC_BrainPoolP160r1|SHA512", &sign); + HcfResult res = HcfSignCreate("ECC_BrainPoolP160r1|SHA512", &sign); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(sign, nullptr); HcfObjDestroy(sign); @@ -183,7 +118,7 @@ HWTEST_F(CryptoBrainPoolNoLengthSignTest, CryptoBrainPoolNoLengthSignTest001_5, HWTEST_F(CryptoBrainPoolNoLengthSignTest, CryptoBrainPoolNoLengthSignTest001_6, TestSize.Level0) { HcfSign *sign = nullptr; - int32_t res = HcfSignCreate("ECC_BrainPoolP160r1|MD5", &sign); + HcfResult res = HcfSignCreate("ECC_BrainPoolP160r1|MD5", &sign); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(sign, nullptr); HcfObjDestroy(sign); @@ -192,7 +127,7 @@ HWTEST_F(CryptoBrainPoolNoLengthSignTest, CryptoBrainPoolNoLengthSignTest001_6, HWTEST_F(CryptoBrainPoolNoLengthSignTest, CryptoBrainPoolNoLengthSignTest002, TestSize.Level0) { HcfSign *sign = nullptr; - int32_t res = HcfSignCreate("ECC_BrainPoolP160r1|SHA256", &sign); + HcfResult res = HcfSignCreate("ECC_BrainPoolP160r1|SHA256", &sign); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(sign, nullptr); @@ -204,7 +139,7 @@ HWTEST_F(CryptoBrainPoolNoLengthSignTest, CryptoBrainPoolNoLengthSignTest002, Te HWTEST_F(CryptoBrainPoolNoLengthSignTest, CryptoBrainPoolNoLengthSignTest003, TestSize.Level0) { HcfSign *sign = nullptr; - int32_t res = HcfSignCreate("ECC_BrainPoolP160r1|SHA256", &sign); + HcfResult res = HcfSignCreate("ECC_BrainPoolP160r1|SHA256", &sign); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(sign, nullptr); sign->base.destroy((HcfObjectBase *)sign); @@ -213,7 +148,7 @@ HWTEST_F(CryptoBrainPoolNoLengthSignTest, CryptoBrainPoolNoLengthSignTest003, Te HWTEST_F(CryptoBrainPoolNoLengthSignTest, CryptoBrainPoolNoLengthSignTest004, TestSize.Level0) { HcfSign *sign = nullptr; - int32_t res = HcfSignCreate("ECC_BrainPoolP160r1|SHA256", &sign); + HcfResult res = HcfSignCreate("ECC_BrainPoolP160r1|SHA256", &sign); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(sign, nullptr); sign->base.destroy(nullptr); @@ -222,7 +157,7 @@ HWTEST_F(CryptoBrainPoolNoLengthSignTest, CryptoBrainPoolNoLengthSignTest004, Te HWTEST_F(CryptoBrainPoolNoLengthSignTest, CryptoBrainPoolNoLengthSignTest005, TestSize.Level0) { HcfSign *sign = nullptr; - int32_t res = HcfSignCreate("ECC_BrainPoolP160r1|SHA256", &sign); + HcfResult res = HcfSignCreate("ECC_BrainPoolP160r1|SHA256", &sign); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(sign, nullptr); @@ -233,7 +168,7 @@ HWTEST_F(CryptoBrainPoolNoLengthSignTest, CryptoBrainPoolNoLengthSignTest005, Te HWTEST_F(CryptoBrainPoolNoLengthSignTest, CryptoBrainPoolNoLengthSignTest006, TestSize.Level0) { HcfSign *sign = nullptr; - int32_t res = HcfSignCreate("ECC_BrainPoolP160r1|SHA256", &sign); + HcfResult res = HcfSignCreate("ECC_BrainPoolP160r1|SHA256", &sign); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(sign, nullptr); @@ -245,7 +180,7 @@ HWTEST_F(CryptoBrainPoolNoLengthSignTest, CryptoBrainPoolNoLengthSignTest006, Te HWTEST_F(CryptoBrainPoolNoLengthSignTest, CryptoBrainPoolNoLengthSignTest007, TestSize.Level0) { HcfSign *sign = nullptr; - int32_t res = HcfSignCreate("ECC_BrainPoolP160r1|SHA256", &sign); + HcfResult res = HcfSignCreate("ECC_BrainPoolP160r1|SHA256", &sign); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(sign, nullptr); @@ -257,7 +192,7 @@ HWTEST_F(CryptoBrainPoolNoLengthSignTest, CryptoBrainPoolNoLengthSignTest007, Te HWTEST_F(CryptoBrainPoolNoLengthSignTest, CryptoBrainPoolNoLengthSignTest008, TestSize.Level0) { HcfSign *sign = nullptr; - int32_t res = HcfSignCreate("ECC_BrainPoolP160r1|SHA256", &sign); + HcfResult res = HcfSignCreate("ECC_BrainPoolP160r1|SHA256", &sign); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(sign, nullptr); @@ -269,12 +204,14 @@ HWTEST_F(CryptoBrainPoolNoLengthSignTest, CryptoBrainPoolNoLengthSignTest008, Te HWTEST_F(CryptoBrainPoolNoLengthSignTest, CryptoBrainPoolNoLengthSignTest009, TestSize.Level0) { HcfSign *sign = nullptr; - int32_t res = HcfSignCreate("ECC_BrainPoolP160r1|SHA256", &sign); + HcfResult res = HcfSignCreate("ECC_BrainPoolP160r1|SHA256", &sign); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(sign, nullptr); + ConstructEccKeyPairCommParamsSpec("NID_brainpoolP160r1", &g_eccCommSpec); + ASSERT_NE(g_eccCommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - res = Constructbrainpool160r1KeyPairParamsSpec(g_brainpool160r1AlgName, g_brainpool160r1curveName, ¶mSpec); + res = ConstructEccKeyPairParamsSpec(g_brainpool160r1AlgName.c_str(), g_eccCommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); @@ -294,17 +231,20 @@ HWTEST_F(CryptoBrainPoolNoLengthSignTest, CryptoBrainPoolNoLengthSignTest009, Te HcfObjDestroy(sign); HcfObjDestroy(keyPair); HcfObjDestroy(generator); + DestroyEccKeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoBrainPoolNoLengthSignTest, CryptoBrainPoolNoLengthSignTest010, TestSize.Level0) { HcfSign *sign = nullptr; - int32_t res = HcfSignCreate("ECC_BrainPoolP160r1|SHA256", &sign); + HcfResult res = HcfSignCreate("ECC_BrainPoolP160r1|SHA256", &sign); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(sign, nullptr); + ConstructEccKeyPairCommParamsSpec("NID_brainpoolP160r1", &g_eccCommSpec); + ASSERT_NE(g_eccCommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - res = Constructbrainpool160r1KeyPairParamsSpec(g_brainpool160r1AlgName, g_brainpool160r1curveName, ¶mSpec); + res = ConstructEccKeyPairParamsSpec(g_brainpool160r1AlgName.c_str(), g_eccCommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); @@ -324,17 +264,20 @@ HWTEST_F(CryptoBrainPoolNoLengthSignTest, CryptoBrainPoolNoLengthSignTest010, Te HcfObjDestroy(sign); HcfObjDestroy(keyPair); HcfObjDestroy(generator); + DestroyEccKeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoBrainPoolNoLengthSignTest, CryptoBrainPoolNoLengthSignTest011, TestSize.Level0) { HcfSign *sign = nullptr; - int32_t res = HcfSignCreate("ECC_BrainPoolP160r1|SHA256", &sign); + HcfResult res = HcfSignCreate("ECC_BrainPoolP160r1|SHA256", &sign); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(sign, nullptr); + ConstructEccKeyPairCommParamsSpec("NID_brainpoolP160r1", &g_eccCommSpec); + ASSERT_NE(g_eccCommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - res = Constructbrainpool160r1KeyPairParamsSpec(g_brainpool160r1AlgName, g_brainpool160r1curveName, ¶mSpec); + res = ConstructEccKeyPairParamsSpec(g_brainpool160r1AlgName.c_str(), g_eccCommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); @@ -354,17 +297,20 @@ HWTEST_F(CryptoBrainPoolNoLengthSignTest, CryptoBrainPoolNoLengthSignTest011, Te HcfObjDestroy(sign); HcfObjDestroy(keyPair); HcfObjDestroy(generator); + DestroyEccKeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoBrainPoolNoLengthSignTest, CryptoBrainPoolNoLengthSignTest012, TestSize.Level0) { HcfSign *sign = nullptr; - int32_t res = HcfSignCreate("ECC_BrainPoolP160r1|SHA256", &sign); + HcfResult res = HcfSignCreate("ECC_BrainPoolP160r1|SHA256", &sign); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(sign, nullptr); + ConstructEccKeyPairCommParamsSpec("NID_brainpoolP160r1", &g_eccCommSpec); + ASSERT_NE(g_eccCommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - res = Constructbrainpool160r1KeyPairParamsSpec(g_brainpool160r1AlgName, g_brainpool160r1curveName, ¶mSpec); + res = ConstructEccKeyPairParamsSpec(g_brainpool160r1AlgName.c_str(), g_eccCommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); @@ -387,12 +333,13 @@ HWTEST_F(CryptoBrainPoolNoLengthSignTest, CryptoBrainPoolNoLengthSignTest012, Te HcfObjDestroy(sign); HcfObjDestroy(keyPair); HcfObjDestroy(generator); + DestroyEccKeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoBrainPoolNoLengthSignTest, CryptoBrainPoolNoLengthSignTest013, TestSize.Level0) { HcfSign *sign = nullptr; - int32_t res = HcfSignCreate("ECC_BrainPoolP160r1|SHA256", &sign); + HcfResult res = HcfSignCreate("ECC_BrainPoolP160r1|SHA256", &sign); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(sign, nullptr); @@ -404,7 +351,7 @@ HWTEST_F(CryptoBrainPoolNoLengthSignTest, CryptoBrainPoolNoLengthSignTest013, Te HWTEST_F(CryptoBrainPoolNoLengthSignTest, CryptoBrainPoolNoLengthSignTest014, TestSize.Level0) { HcfSign *sign = nullptr; - int32_t res = HcfSignCreate("ECC_BrainPoolP160r1|SHA256", &sign); + HcfResult res = HcfSignCreate("ECC_BrainPoolP160r1|SHA256", &sign); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(sign, nullptr); @@ -416,18 +363,18 @@ HWTEST_F(CryptoBrainPoolNoLengthSignTest, CryptoBrainPoolNoLengthSignTest014, Te HWTEST_F(CryptoBrainPoolNoLengthSignTest, CryptoBrainPoolNoLengthSignTest015, TestSize.Level0) { HcfSign *sign = nullptr; - int32_t res = HcfSignCreate("ECC_BrainPoolP160r1|SHA256", &sign); + HcfResult res = HcfSignCreate("ECC_BrainPoolP160r1|SHA256", &sign); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(sign, nullptr); res = sign->init(sign, nullptr, (HcfPriKey *)(&obj)); ASSERT_EQ(res, HCF_INVALID_PARAMS); - HcfBlob g_mockInput = { + HcfBlob mockInput = { .data = (uint8_t *)g_mockMessage, .len = 1 }; - res = sign->update(sign, &g_mockInput); + res = sign->update(sign, &mockInput); ASSERT_EQ(res, HCF_INVALID_PARAMS); HcfObjDestroy(sign); } @@ -435,18 +382,18 @@ HWTEST_F(CryptoBrainPoolNoLengthSignTest, CryptoBrainPoolNoLengthSignTest015, Te HWTEST_F(CryptoBrainPoolNoLengthSignTest, CryptoBrainPoolNoLengthSignTest016, TestSize.Level0) { HcfSign *sign = nullptr; - int32_t res = HcfSignCreate("ECC_BrainPoolP160r1|SHA256", &sign); + HcfResult res = HcfSignCreate("ECC_BrainPoolP160r1|SHA256", &sign); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(sign, nullptr); res = sign->init(sign, nullptr, (HcfPriKey *)(&obj)); ASSERT_EQ(res, HCF_INVALID_PARAMS); - HcfBlob g_mockInput = { + HcfBlob mockInput = { .data = (uint8_t *)g_mockMessage, .len = 1 }; - res = sign->update(nullptr, &g_mockInput); + res = sign->update(nullptr, &mockInput); ASSERT_EQ(res, HCF_INVALID_PARAMS); HcfObjDestroy(sign); } @@ -454,18 +401,18 @@ HWTEST_F(CryptoBrainPoolNoLengthSignTest, CryptoBrainPoolNoLengthSignTest016, Te HWTEST_F(CryptoBrainPoolNoLengthSignTest, CryptoBrainPoolNoLengthSignTest017, TestSize.Level0) { HcfSign *sign = nullptr; - int32_t res = HcfSignCreate("ECC_BrainPoolP160r1|SHA256", &sign); + HcfResult res = HcfSignCreate("ECC_BrainPoolP160r1|SHA256", &sign); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(sign, nullptr); res = sign->init(sign, nullptr, (HcfPriKey *)(&obj)); ASSERT_EQ(res, HCF_INVALID_PARAMS); - HcfBlob g_mockInput = { + HcfBlob mockInput = { .data = (uint8_t *)g_mockMessage, .len = 1 }; - res = sign->update((HcfSign *)(&obj), &g_mockInput); + res = sign->update((HcfSign *)(&obj), &mockInput); ASSERT_EQ(res, HCF_INVALID_PARAMS); HcfObjDestroy(sign); } @@ -473,17 +420,17 @@ HWTEST_F(CryptoBrainPoolNoLengthSignTest, CryptoBrainPoolNoLengthSignTest017, Te HWTEST_F(CryptoBrainPoolNoLengthSignTest, CryptoBrainPoolNoLengthSignTest018, TestSize.Level0) { HcfSign *sign = nullptr; - int32_t res = HcfSignCreate("ECC_BrainPoolP160r1|SHA256", &sign); + HcfResult res = HcfSignCreate("ECC_BrainPoolP160r1|SHA256", &sign); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(sign, nullptr); - HcfBlob g_mockInput = { + HcfBlob mockInput = { .data = (uint8_t *)g_mockMessage, .len = 1 }; - res = sign->update(sign, &g_mockInput); + res = sign->update(sign, &mockInput); ASSERT_EQ(res, HCF_INVALID_PARAMS); HcfObjDestroy(sign); } @@ -492,12 +439,14 @@ HWTEST_F(CryptoBrainPoolNoLengthSignTest, CryptoBrainPoolNoLengthSignTest018, Te HWTEST_F(CryptoBrainPoolNoLengthSignTest, CryptoBrainPoolNoLengthSignTest019, TestSize.Level0) { HcfSign *sign = nullptr; - int32_t res = HcfSignCreate("ECC_BrainPoolP160r1|SHA256", &sign); + HcfResult res = HcfSignCreate("ECC_BrainPoolP160r1|SHA256", &sign); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(sign, nullptr); + ConstructEccKeyPairCommParamsSpec("NID_brainpoolP160r1", &g_eccCommSpec); + ASSERT_NE(g_eccCommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - res = Constructbrainpool160r1KeyPairParamsSpec(g_brainpool160r1AlgName, g_brainpool160r1curveName, ¶mSpec); + res = ConstructEccKeyPairParamsSpec(g_brainpool160r1AlgName.c_str(), g_eccCommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); @@ -520,17 +469,20 @@ HWTEST_F(CryptoBrainPoolNoLengthSignTest, CryptoBrainPoolNoLengthSignTest019, Te HcfObjDestroy(sign); HcfObjDestroy(keyPair); HcfObjDestroy(generator); + DestroyEccKeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoBrainPoolNoLengthSignTest, CryptoBrainPoolNoLengthSignTest020, TestSize.Level0) { HcfSign *sign = nullptr; - int32_t res = HcfSignCreate("ECC_BrainPoolP160r1|SHA256", &sign); + HcfResult res = HcfSignCreate("ECC_BrainPoolP160r1|SHA256", &sign); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(sign, nullptr); + ConstructEccKeyPairCommParamsSpec("NID_brainpoolP160r1", &g_eccCommSpec); + ASSERT_NE(g_eccCommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - res = Constructbrainpool160r1KeyPairParamsSpec(g_brainpool160r1AlgName, g_brainpool160r1curveName, ¶mSpec); + res = ConstructEccKeyPairParamsSpec(g_brainpool160r1AlgName.c_str(), g_eccCommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); @@ -558,18 +510,22 @@ HWTEST_F(CryptoBrainPoolNoLengthSignTest, CryptoBrainPoolNoLengthSignTest020, Te HcfObjDestroy(sign); HcfObjDestroy(keyPair); HcfObjDestroy(generator); + HcfBlobDataFree(&input); + DestroyEccKeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoBrainPoolNoLengthSignTest, CryptoBrainPoolNoLengthSignTest021, TestSize.Level0) { HcfSign *sign = nullptr; - int32_t res = HcfSignCreate("ECC_BrainPoolP160r1|SHA256", &sign); + HcfResult res = HcfSignCreate("ECC_BrainPoolP160r1|SHA256", &sign); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(sign, nullptr); + ConstructEccKeyPairCommParamsSpec("NID_brainpoolP160r1", &g_eccCommSpec); + ASSERT_NE(g_eccCommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - res = Constructbrainpool160r1KeyPairParamsSpec(g_brainpool160r1AlgName, g_brainpool160r1curveName, ¶mSpec); + res = ConstructEccKeyPairParamsSpec(g_brainpool160r1AlgName.c_str(), g_eccCommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); @@ -597,17 +553,20 @@ HWTEST_F(CryptoBrainPoolNoLengthSignTest, CryptoBrainPoolNoLengthSignTest021, Te HcfObjDestroy(sign); HcfObjDestroy(keyPair); HcfObjDestroy(generator); + DestroyEccKeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoBrainPoolNoLengthSignTest, CryptoBrainPoolNoLengthSignTest022, TestSize.Level0) { HcfSign *sign = nullptr; - int32_t res = HcfSignCreate("ECC_BrainPoolP160r1|SHA256", &sign); + HcfResult res = HcfSignCreate("ECC_BrainPoolP160r1|SHA256", &sign); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(sign, nullptr); + ConstructEccKeyPairCommParamsSpec("NID_brainpoolP160r1", &g_eccCommSpec); + ASSERT_NE(g_eccCommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - res = Constructbrainpool160r1KeyPairParamsSpec(g_brainpool160r1AlgName, g_brainpool160r1curveName, ¶mSpec); + res = ConstructEccKeyPairParamsSpec(g_brainpool160r1AlgName.c_str(), g_eccCommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); @@ -633,21 +592,24 @@ HWTEST_F(CryptoBrainPoolNoLengthSignTest, CryptoBrainPoolNoLengthSignTest022, Te ASSERT_NE(out.data, nullptr); ASSERT_NE(out.len, (const unsigned int)0); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); HcfObjDestroy(keyPair); HcfObjDestroy(generator); + DestroyEccKeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoBrainPoolNoLengthSignTest, CryptoBrainPoolNoLengthSignTest023, TestSize.Level0) { HcfSign *sign = nullptr; - int32_t res = HcfSignCreate("ECC_BrainPoolP160r1|SHA256", &sign); + HcfResult res = HcfSignCreate("ECC_BrainPoolP160r1|SHA256", &sign); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(sign, nullptr); + ConstructEccKeyPairCommParamsSpec("NID_brainpoolP160r1", &g_eccCommSpec); + ASSERT_NE(g_eccCommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - res = Constructbrainpool160r1KeyPairParamsSpec(g_brainpool160r1AlgName, g_brainpool160r1curveName, ¶mSpec); + res = ConstructEccKeyPairParamsSpec(g_brainpool160r1AlgName.c_str(), g_eccCommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); @@ -670,21 +632,24 @@ HWTEST_F(CryptoBrainPoolNoLengthSignTest, CryptoBrainPoolNoLengthSignTest023, Te ASSERT_NE(out.data, nullptr); ASSERT_NE(out.len, (const unsigned int)0); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); HcfObjDestroy(keyPair); HcfObjDestroy(generator); + DestroyEccKeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoBrainPoolNoLengthSignTest, CryptoBrainPoolNoLengthSignTest024, TestSize.Level0) { HcfSign *sign = nullptr; - int32_t res = HcfSignCreate("ECC_BrainPoolP160r1|SHA256", &sign); + HcfResult res = HcfSignCreate("ECC_BrainPoolP160r1|SHA256", &sign); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(sign, nullptr); + ConstructEccKeyPairCommParamsSpec("NID_brainpoolP160r1", &g_eccCommSpec); + ASSERT_NE(g_eccCommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - res = Constructbrainpool160r1KeyPairParamsSpec(g_brainpool160r1AlgName, g_brainpool160r1curveName, ¶mSpec); + res = ConstructEccKeyPairParamsSpec(g_brainpool160r1AlgName.c_str(), g_eccCommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); @@ -713,17 +678,20 @@ HWTEST_F(CryptoBrainPoolNoLengthSignTest, CryptoBrainPoolNoLengthSignTest024, Te HcfObjDestroy(sign); HcfObjDestroy(keyPair); HcfObjDestroy(generator); + DestroyEccKeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoBrainPoolNoLengthSignTest, CryptoBrainPoolNoLengthSignTest025, TestSize.Level0) { HcfSign *sign = nullptr; - int32_t res = HcfSignCreate("ECC_BrainPoolP160r1|SHA256", &sign); + HcfResult res = HcfSignCreate("ECC_BrainPoolP160r1|SHA256", &sign); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(sign, nullptr); + ConstructEccKeyPairCommParamsSpec("NID_brainpoolP160r1", &g_eccCommSpec); + ASSERT_NE(g_eccCommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - res = Constructbrainpool160r1KeyPairParamsSpec(g_brainpool160r1AlgName, g_brainpool160r1curveName, ¶mSpec); + res = ConstructEccKeyPairParamsSpec(g_brainpool160r1AlgName.c_str(), g_eccCommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); @@ -749,17 +717,20 @@ HWTEST_F(CryptoBrainPoolNoLengthSignTest, CryptoBrainPoolNoLengthSignTest025, Te HcfObjDestroy(sign); HcfObjDestroy(keyPair); HcfObjDestroy(generator); + DestroyEccKeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoBrainPoolNoLengthSignTest, CryptoBrainPoolNoLengthSignTest026, TestSize.Level0) { HcfSign *sign = nullptr; - int32_t res = HcfSignCreate("ECC_BrainPoolP160r1|SHA256", &sign); + HcfResult res = HcfSignCreate("ECC_BrainPoolP160r1|SHA256", &sign); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(sign, nullptr); + ConstructEccKeyPairCommParamsSpec("NID_brainpoolP160r1", &g_eccCommSpec); + ASSERT_NE(g_eccCommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - res = Constructbrainpool160r1KeyPairParamsSpec(g_brainpool160r1AlgName, g_brainpool160r1curveName, ¶mSpec); + res = ConstructEccKeyPairParamsSpec(g_brainpool160r1AlgName.c_str(), g_eccCommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); @@ -788,17 +759,20 @@ HWTEST_F(CryptoBrainPoolNoLengthSignTest, CryptoBrainPoolNoLengthSignTest026, Te HcfObjDestroy(sign); HcfObjDestroy(keyPair); HcfObjDestroy(generator); + DestroyEccKeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoBrainPoolNoLengthSignTest, CryptoBrainPoolNoLengthSignTest027, TestSize.Level0) { HcfSign *sign = nullptr; - int32_t res = HcfSignCreate("ECC_BrainPoolP160r1|SHA256", &sign); + HcfResult res = HcfSignCreate("ECC_BrainPoolP160r1|SHA256", &sign); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(sign, nullptr); + ConstructEccKeyPairCommParamsSpec("NID_brainpoolP160r1", &g_eccCommSpec); + ASSERT_NE(g_eccCommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - res = Constructbrainpool160r1KeyPairParamsSpec(g_brainpool160r1AlgName, g_brainpool160r1curveName, ¶mSpec); + res = ConstructEccKeyPairParamsSpec(g_brainpool160r1AlgName.c_str(), g_eccCommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); @@ -831,17 +805,20 @@ HWTEST_F(CryptoBrainPoolNoLengthSignTest, CryptoBrainPoolNoLengthSignTest027, Te HcfObjDestroy(sign); HcfObjDestroy(keyPair); HcfObjDestroy(generator); + DestroyEccKeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoBrainPoolNoLengthSignTest, CryptoBrainPoolNoLengthSignTest028, TestSize.Level0) { HcfSign *sign = nullptr; - int32_t res = HcfSignCreate("ECC_BrainPoolP160r1|SHA256", &sign); + HcfResult res = HcfSignCreate("ECC_BrainPoolP160r1|SHA256", &sign); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(sign, nullptr); + ConstructEccKeyPairCommParamsSpec("NID_brainpoolP160r1", &g_eccCommSpec); + ASSERT_NE(g_eccCommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - res = Constructbrainpool160r1KeyPairParamsSpec(g_brainpool160r1AlgName, g_brainpool160r1curveName, ¶mSpec); + res = ConstructEccKeyPairParamsSpec(g_brainpool160r1AlgName.c_str(), g_eccCommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); @@ -874,6 +851,7 @@ HWTEST_F(CryptoBrainPoolNoLengthSignTest, CryptoBrainPoolNoLengthSignTest028, Te HcfObjDestroy(sign); HcfObjDestroy(keyPair); HcfObjDestroy(generator); + DestroyEccKeyPairSpec(reinterpret_cast(paramSpec)); } HcfSignatureParams g_params = { @@ -885,20 +863,22 @@ HcfSignatureParams g_params = { HWTEST_F(CryptoBrainPoolNoLengthSignTest, CryptoBrainPoolNoLengthSignTest029, TestSize.Level0) { - int32_t res = HcfSignSpiEcdsaCreate(&g_params, nullptr); + HcfResult res = HcfSignSpiEcdsaCreate(&g_params, nullptr); ASSERT_EQ(res, HCF_INVALID_PARAMS); } HWTEST_F(CryptoBrainPoolNoLengthSignTest, CryptoBrainPoolNoLengthSignTest030, TestSize.Level0) { HcfSignSpi *spiObj = nullptr; - int32_t res = HcfSignSpiEcdsaCreate(&g_params, &spiObj); + HcfResult res = HcfSignSpiEcdsaCreate(&g_params, &spiObj); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(spiObj, nullptr); + ConstructEccKeyPairCommParamsSpec("NID_brainpoolP160r1", &g_eccCommSpec); + ASSERT_NE(g_eccCommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - res = Constructbrainpool160r1KeyPairParamsSpec(g_brainpool160r1AlgName, g_brainpool160r1curveName, ¶mSpec); + res = ConstructEccKeyPairParamsSpec(g_brainpool160r1AlgName.c_str(), g_eccCommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); @@ -918,12 +898,13 @@ HWTEST_F(CryptoBrainPoolNoLengthSignTest, CryptoBrainPoolNoLengthSignTest030, Te HcfObjDestroy(spiObj); HcfObjDestroy(keyPair); HcfObjDestroy(generator); + DestroyEccKeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoBrainPoolNoLengthSignTest, CryptoBrainPoolNoLengthSignTest031, TestSize.Level0) { HcfSignSpi *spiObj = nullptr; - int32_t res = HcfSignSpiEcdsaCreate(&g_params, &spiObj); + HcfResult res = HcfSignSpiEcdsaCreate(&g_params, &spiObj); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(spiObj, nullptr); @@ -936,7 +917,7 @@ HWTEST_F(CryptoBrainPoolNoLengthSignTest, CryptoBrainPoolNoLengthSignTest031, Te HWTEST_F(CryptoBrainPoolNoLengthSignTest, CryptoBrainPoolNoLengthSignTest032, TestSize.Level0) { HcfSignSpi *spiObj = nullptr; - int32_t res = HcfSignSpiEcdsaCreate(&g_params, &spiObj); + HcfResult res = HcfSignSpiEcdsaCreate(&g_params, &spiObj); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(spiObj, nullptr); @@ -953,7 +934,7 @@ HWTEST_F(CryptoBrainPoolNoLengthSignTest, CryptoBrainPoolNoLengthSignTest032, Te HWTEST_F(CryptoBrainPoolNoLengthSignTest, CryptoBrainPoolNoLengthSignTest033, TestSize.Level0) { HcfSignSpi *spiObj = nullptr; - int32_t res = HcfSignSpiEcdsaCreate(&g_params, &spiObj); + HcfResult res = HcfSignSpiEcdsaCreate(&g_params, &spiObj); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(spiObj, nullptr); @@ -970,7 +951,7 @@ HWTEST_F(CryptoBrainPoolNoLengthSignTest, CryptoBrainPoolNoLengthSignTest033, Te HWTEST_F(CryptoBrainPoolNoLengthSignTest, CryptoBrainPoolNoLengthSignTest034, TestSize.Level0) { HcfSignSpi *spiObj = nullptr; - int32_t res = HcfSignSpiEcdsaCreate(&g_params, &spiObj); + HcfResult res = HcfSignSpiEcdsaCreate(&g_params, &spiObj); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(spiObj, nullptr); @@ -982,7 +963,7 @@ HWTEST_F(CryptoBrainPoolNoLengthSignTest, CryptoBrainPoolNoLengthSignTest034, Te HWTEST_F(CryptoBrainPoolNoLengthSignTest, CryptoBrainPoolNoLengthSignTest035, TestSize.Level0) { HcfSignSpi *spiObj = nullptr; - int32_t res = HcfSignSpiEcdsaCreate(&g_params, &spiObj); + HcfResult res = HcfSignSpiEcdsaCreate(&g_params, &spiObj); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(spiObj, nullptr); @@ -996,4 +977,26 @@ HWTEST_F(CryptoBrainPoolNoLengthSignTest, CryptoBrainPoolNoLengthSignTest035, Te ASSERT_EQ(res, HCF_INVALID_PARAMS); HcfObjDestroy(spiObj); } + +HWTEST_F(CryptoBrainPoolNoLengthSignTest, CryptoBrainPoolNoLengthSignTest036, TestSize.Level0) +{ + HcfSign *sign = nullptr; + HcfResult ret = HcfSignCreate("ECC_BrainPoolP160r1|SHA1", &sign); + ASSERT_EQ(ret, HCF_SUCCESS); + ASSERT_NE(sign, nullptr); + + int32_t returnInt = 0; + ret = sign->setSignSpecInt(sign, SM2_USER_ID_UINT8ARR, returnInt); + ASSERT_EQ(ret, HCF_NOT_SUPPORT); + ret = sign->getSignSpecInt(sign, SM2_USER_ID_UINT8ARR, &returnInt); + ASSERT_EQ(ret, HCF_NOT_SUPPORT); + HcfBlob returnBlob = { .data = nullptr, .len = 0}; + ret = sign->setSignSpecUint8Array(sign, SM2_USER_ID_UINT8ARR, returnBlob); + ASSERT_EQ(ret, HCF_NOT_SUPPORT); + char *itemName = nullptr; + ret = sign->getSignSpecString(sign, SM2_USER_ID_UINT8ARR, &itemName); + ASSERT_EQ(ret, HCF_NOT_SUPPORT); + + HcfObjDestroy(sign); } +} \ No newline at end of file diff --git a/test/unittest/src/crypto_brainpool_no_length_verify_test.cpp b/test/unittest/src/crypto_brainpool_no_length_verify_test.cpp index cec7dbeee789162b17756fff9287f112e6198a17..8e6d7ad505bcd41a3c913b80fd08b7cf41dda7d4 100644 --- a/test/unittest/src/crypto_brainpool_no_length_verify_test.cpp +++ b/test/unittest/src/crypto_brainpool_no_length_verify_test.cpp @@ -17,10 +17,10 @@ #include #include "asy_key_generator.h" +#include "ecc_common_param_spec.h" #include "ecc_key_util.h" #include "key_utils.h" #include "blob.h" -#include "detailed_ecc_key_params.h" #include "ecc_openssl_common.h" #include "ecc_openssl_common_param_spec.h" #include "ecc_common.h" @@ -39,19 +39,16 @@ using namespace testing::ext; namespace { class CryptoBrainPoolNoLengthVerifyTest : public testing::Test { public: - static void SetUpTestCase(); - static void TearDownTestCase(); + static void SetUpTestCase() {}; + static void TearDownTestCase() {}; void SetUp(); void TearDown(); }; static string g_brainpool160r1AlgName = "ECC_BrainPoolP160r1"; static string g_brainpool160r1CurveName = "NID_brainpoolP160r1"; - HcfEccCommParamsSpec *g_eccCommSpec = nullptr; -HcfEccKeyPairParamsSpec g_brainpool160r1KeyPairSpec; - void CryptoBrainPoolNoLengthVerifyTest::SetUp() {} void CryptoBrainPoolNoLengthVerifyTest::TearDown() {} @@ -71,83 +68,10 @@ HcfObjectBase obj = { .destroy = nullptr }; -static HcfResult ConstructEccBrainPool160r1KeyPairCommParamsSpec(const string &algoName, HcfEccCommParamsSpec **spec) -{ - HcfEccCommParamsSpec *eccCommSpec = nullptr; - HcfEccKeyUtilCreate(algoName.c_str(), &eccCommSpec); - if (eccCommSpec == nullptr) { - return HCF_INVALID_PARAMS; - } - *spec = eccCommSpec; - return HCF_SUCCESS; -} - -static HcfResult Constructbrainpool160r1KeyPairParamsSpec(const string &algoName, const string &curveName, - HcfAsyKeyParamsSpec **spec) -{ - HcfAsyKeyGenerator *generator = nullptr; - HcfResult res = HcfAsyKeyGeneratorCreate(algoName.c_str(), &generator); - if (res != HCF_SUCCESS) { - return res; - } - HcfKeyPair *keyPair = nullptr; - res = generator->generateKeyPair(generator, nullptr, &keyPair); - if (res != HCF_SUCCESS) { - HcfObjDestroy(keyPair); - return res; - } - HcfEccKeyPairParamsSpec *eccKeyPairSpec = &g_brainpool160r1KeyPairSpec; - HcfBigInteger retBigInt = { .data = nullptr, .len = 0 }; - - eccKeyPairSpec->base.base.algName = g_eccCommSpec->base.algName; - eccKeyPairSpec->base.base.specType = HCF_KEY_PAIR_SPEC; - eccKeyPairSpec->base.field = g_eccCommSpec->field; - eccKeyPairSpec->base.field->fieldType = g_eccCommSpec->field->fieldType; - ((HcfECFieldFp *)(eccKeyPairSpec->base.field))->p.data = ((HcfECFieldFp *)(g_eccCommSpec->field))->p.data; - ((HcfECFieldFp *)(eccKeyPairSpec->base.field))->p.len = ((HcfECFieldFp *)(g_eccCommSpec->field))->p.len; - eccKeyPairSpec->base.a.data = g_eccCommSpec->a.data; - eccKeyPairSpec->base.a.len = g_eccCommSpec->a.len; - eccKeyPairSpec->base.b.data = g_eccCommSpec->b.data; - eccKeyPairSpec->base.b.len = g_eccCommSpec->b.len; - eccKeyPairSpec->base.g.x.data = g_eccCommSpec->g.x.data; - eccKeyPairSpec->base.g.x.len = g_eccCommSpec->g.x.len; - eccKeyPairSpec->base.g.y.data = g_eccCommSpec->g.y.data; - eccKeyPairSpec->base.g.y.len = g_eccCommSpec->g.y.len; - eccKeyPairSpec->base.n.data = g_eccCommSpec->n.data; - eccKeyPairSpec->base.n.len = g_eccCommSpec->n.len; - eccKeyPairSpec->base.h = g_eccCommSpec->h; - res = keyPair->pubKey->getAsyKeySpecBigInteger(keyPair->pubKey, ECC_PK_X_BN, &retBigInt); - eccKeyPairSpec->pk.x.data = retBigInt.data; - eccKeyPairSpec->pk.x.len = retBigInt.len; - - res = keyPair->pubKey->getAsyKeySpecBigInteger(keyPair->pubKey, ECC_PK_Y_BN, &retBigInt); - eccKeyPairSpec->pk.y.data =retBigInt.data; - eccKeyPairSpec->pk.y.len = retBigInt.len; - - res = keyPair->priKey->getAsyKeySpecBigInteger(keyPair->priKey, ECC_SK_BN, &retBigInt); - eccKeyPairSpec->sk.data = retBigInt.data; - eccKeyPairSpec->sk.len = retBigInt.len; - - *spec = (HcfAsyKeyParamsSpec *)eccKeyPairSpec; - HcfObjDestroy(generator); - HcfObjDestroy(keyPair); - return HCF_SUCCESS; -} - -void CryptoBrainPoolNoLengthVerifyTest::SetUpTestCase() -{ - ConstructEccBrainPool160r1KeyPairCommParamsSpec("NID_brainpoolP160r1", &g_eccCommSpec); -} - -void CryptoBrainPoolNoLengthVerifyTest::TearDownTestCase() -{ - FreeEccCommParamsSpec(g_eccCommSpec); -} - HWTEST_F(CryptoBrainPoolNoLengthVerifyTest, CryptoBrainPoolNoLengthVerifyTest001_1, TestSize.Level0) { HcfVerify *verify = nullptr; - int32_t res = HcfVerifyCreate("ECC_BrainPoolP160r1|SHA1", &verify); + HcfResult res = HcfVerifyCreate("ECC_BrainPoolP160r1|SHA1", &verify); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(verify, nullptr); HcfObjDestroy(verify); @@ -156,7 +80,7 @@ HWTEST_F(CryptoBrainPoolNoLengthVerifyTest, CryptoBrainPoolNoLengthVerifyTest001 HWTEST_F(CryptoBrainPoolNoLengthVerifyTest, CryptoBrainPoolNoLengthVerifyTest001_2, TestSize.Level0) { HcfVerify *verify = nullptr; - int32_t res = HcfVerifyCreate("ECC_BrainPoolP160r1|SHA224", &verify); + HcfResult res = HcfVerifyCreate("ECC_BrainPoolP160r1|SHA224", &verify); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(verify, nullptr); HcfObjDestroy(verify); @@ -165,7 +89,7 @@ HWTEST_F(CryptoBrainPoolNoLengthVerifyTest, CryptoBrainPoolNoLengthVerifyTest001 HWTEST_F(CryptoBrainPoolNoLengthVerifyTest, CryptoBrainPoolNoLengthVerifyTest001_3, TestSize.Level0) { HcfVerify *verify = nullptr; - int32_t res = HcfVerifyCreate("ECC_BrainPoolP160r1|SHA256", &verify); + HcfResult res = HcfVerifyCreate("ECC_BrainPoolP160r1|SHA256", &verify); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(verify, nullptr); HcfObjDestroy(verify); @@ -174,7 +98,7 @@ HWTEST_F(CryptoBrainPoolNoLengthVerifyTest, CryptoBrainPoolNoLengthVerifyTest001 HWTEST_F(CryptoBrainPoolNoLengthVerifyTest, CryptoBrainPoolNoLengthVerifyTest001_4, TestSize.Level0) { HcfVerify *verify = nullptr; - int32_t res = HcfVerifyCreate("ECC_BrainPoolP160r1|SHA384", &verify); + HcfResult res = HcfVerifyCreate("ECC_BrainPoolP160r1|SHA384", &verify); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(verify, nullptr); @@ -184,7 +108,7 @@ HWTEST_F(CryptoBrainPoolNoLengthVerifyTest, CryptoBrainPoolNoLengthVerifyTest001 HWTEST_F(CryptoBrainPoolNoLengthVerifyTest, CryptoBrainPoolNoLengthVerifyTest001_5, TestSize.Level0) { HcfVerify *verify = nullptr; - int32_t res = HcfVerifyCreate("ECC_BrainPoolP160r1|SHA512", &verify); + HcfResult res = HcfVerifyCreate("ECC_BrainPoolP160r1|SHA512", &verify); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(verify, nullptr); @@ -194,7 +118,7 @@ HWTEST_F(CryptoBrainPoolNoLengthVerifyTest, CryptoBrainPoolNoLengthVerifyTest001 HWTEST_F(CryptoBrainPoolNoLengthVerifyTest, CryptoBrainPoolNoLengthVerifyTest001_6, TestSize.Level0) { HcfVerify *verify = nullptr; - int32_t res = HcfVerifyCreate("ECC_BrainPoolP160r1|MD5", &verify); + HcfResult res = HcfVerifyCreate("ECC_BrainPoolP160r1|MD5", &verify); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(verify, nullptr); @@ -204,7 +128,7 @@ HWTEST_F(CryptoBrainPoolNoLengthVerifyTest, CryptoBrainPoolNoLengthVerifyTest001 HWTEST_F(CryptoBrainPoolNoLengthVerifyTest, CryptoBrainPoolNoLengthVerifyTest002, TestSize.Level0) { HcfVerify *verify = nullptr; - int32_t res = HcfVerifyCreate("ECC_BrainPoolP160r1|SHA224", &verify); + HcfResult res = HcfVerifyCreate("ECC_BrainPoolP160r1|SHA224", &verify); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(verify, nullptr); @@ -217,7 +141,7 @@ HWTEST_F(CryptoBrainPoolNoLengthVerifyTest, CryptoBrainPoolNoLengthVerifyTest002 HWTEST_F(CryptoBrainPoolNoLengthVerifyTest, CryptoBrainPoolNoLengthVerifyTest003, TestSize.Level0) { HcfVerify *verify = nullptr; - int32_t res = HcfVerifyCreate("ECC_BrainPoolP160r1|SHA224", &verify); + HcfResult res = HcfVerifyCreate("ECC_BrainPoolP160r1|SHA224", &verify); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(verify, nullptr); @@ -227,7 +151,7 @@ HWTEST_F(CryptoBrainPoolNoLengthVerifyTest, CryptoBrainPoolNoLengthVerifyTest003 HWTEST_F(CryptoBrainPoolNoLengthVerifyTest, CryptoBrainPoolNoLengthVerifyTest004, TestSize.Level0) { HcfVerify *verify = nullptr; - int32_t res = HcfVerifyCreate("ECC_BrainPoolP160r1|SHA224", &verify); + HcfResult res = HcfVerifyCreate("ECC_BrainPoolP160r1|SHA224", &verify); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(verify, nullptr); @@ -238,7 +162,7 @@ HWTEST_F(CryptoBrainPoolNoLengthVerifyTest, CryptoBrainPoolNoLengthVerifyTest004 HWTEST_F(CryptoBrainPoolNoLengthVerifyTest, CryptoBrainPoolNoLengthVerifyTest005, TestSize.Level0) { HcfVerify *verify = nullptr; - int32_t res = HcfVerifyCreate("ECC_BrainPoolP160r1|SHA224", &verify); + HcfResult res = HcfVerifyCreate("ECC_BrainPoolP160r1|SHA224", &verify); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(verify, nullptr); @@ -249,7 +173,7 @@ HWTEST_F(CryptoBrainPoolNoLengthVerifyTest, CryptoBrainPoolNoLengthVerifyTest005 HWTEST_F(CryptoBrainPoolNoLengthVerifyTest, CryptoBrainPoolNoLengthVerifyTest006, TestSize.Level0) { HcfVerify *verify = nullptr; - int32_t res = HcfVerifyCreate("ECC_BrainPoolP160r1|SHA224", &verify); + HcfResult res = HcfVerifyCreate("ECC_BrainPoolP160r1|SHA224", &verify); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(verify, nullptr); @@ -262,7 +186,7 @@ HWTEST_F(CryptoBrainPoolNoLengthVerifyTest, CryptoBrainPoolNoLengthVerifyTest006 HWTEST_F(CryptoBrainPoolNoLengthVerifyTest, CryptoBrainPoolNoLengthVerifyTest007, TestSize.Level0) { HcfVerify *verify = nullptr; - int32_t res = HcfVerifyCreate("ECC_BrainPoolP160r1|SHA224", &verify); + HcfResult res = HcfVerifyCreate("ECC_BrainPoolP160r1|SHA224", &verify); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(verify, nullptr); @@ -275,7 +199,7 @@ HWTEST_F(CryptoBrainPoolNoLengthVerifyTest, CryptoBrainPoolNoLengthVerifyTest007 HWTEST_F(CryptoBrainPoolNoLengthVerifyTest, CryptoBrainPoolNoLengthVerifyTest008, TestSize.Level0) { HcfVerify *verify = nullptr; - int32_t res = HcfVerifyCreate("ECC_BrainPoolP160r1|SHA224", &verify); + HcfResult res = HcfVerifyCreate("ECC_BrainPoolP160r1|SHA224", &verify); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(verify, nullptr); @@ -288,13 +212,15 @@ HWTEST_F(CryptoBrainPoolNoLengthVerifyTest, CryptoBrainPoolNoLengthVerifyTest008 HWTEST_F(CryptoBrainPoolNoLengthVerifyTest, CryptoBrainPoolNoLengthVerifyTest009, TestSize.Level0) { HcfVerify *verify = nullptr; - int32_t res = HcfVerifyCreate("ECC_BrainPoolP160r1|SHA224", &verify); + HcfResult res = HcfVerifyCreate("ECC_BrainPoolP160r1|SHA224", &verify); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(verify, nullptr); - + + ConstructEccKeyPairCommParamsSpec("NID_brainpoolP160r1", &g_eccCommSpec); + ASSERT_NE(g_eccCommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - res = Constructbrainpool160r1KeyPairParamsSpec(g_brainpool160r1AlgName, g_brainpool160r1CurveName, ¶mSpec); + res = ConstructEccKeyPairParamsSpec(g_brainpool160r1AlgName.c_str(), g_eccCommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); @@ -313,18 +239,21 @@ HWTEST_F(CryptoBrainPoolNoLengthVerifyTest, CryptoBrainPoolNoLengthVerifyTest009 HcfObjDestroy(generator); HcfObjDestroy(keyPair); HcfObjDestroy(verify); + DestroyEccKeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoBrainPoolNoLengthVerifyTest, CryptoBrainPoolNoLengthVerifyTest010, TestSize.Level0) { HcfVerify *verify = nullptr; - int32_t res = HcfVerifyCreate("ECC_BrainPoolP160r1|SHA224", &verify); + HcfResult res = HcfVerifyCreate("ECC_BrainPoolP160r1|SHA224", &verify); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(verify, nullptr); + ConstructEccKeyPairCommParamsSpec("NID_brainpoolP160r1", &g_eccCommSpec); + ASSERT_NE(g_eccCommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - res = Constructbrainpool160r1KeyPairParamsSpec(g_brainpool160r1AlgName, g_brainpool160r1CurveName, ¶mSpec); + res = ConstructEccKeyPairParamsSpec(g_brainpool160r1AlgName.c_str(), g_eccCommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); @@ -343,18 +272,21 @@ HWTEST_F(CryptoBrainPoolNoLengthVerifyTest, CryptoBrainPoolNoLengthVerifyTest010 HcfObjDestroy(verify); HcfObjDestroy(keyPair); HcfObjDestroy(generator); + DestroyEccKeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoBrainPoolNoLengthVerifyTest, CryptoBrainPoolNoLengthVerifyTest011, TestSize.Level0) { HcfVerify *verify = nullptr; - int32_t res = HcfVerifyCreate("ECC_BrainPoolP160r1|SHA224", &verify); + HcfResult res = HcfVerifyCreate("ECC_BrainPoolP160r1|SHA224", &verify); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(verify, nullptr); + ConstructEccKeyPairCommParamsSpec("NID_brainpoolP160r1", &g_eccCommSpec); + ASSERT_NE(g_eccCommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - res = Constructbrainpool160r1KeyPairParamsSpec(g_brainpool160r1AlgName, g_brainpool160r1CurveName, ¶mSpec); + res = ConstructEccKeyPairParamsSpec(g_brainpool160r1AlgName.c_str(), g_eccCommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); @@ -373,18 +305,21 @@ HWTEST_F(CryptoBrainPoolNoLengthVerifyTest, CryptoBrainPoolNoLengthVerifyTest011 HcfObjDestroy(verify); HcfObjDestroy(keyPair); HcfObjDestroy(generator); + DestroyEccKeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoBrainPoolNoLengthVerifyTest, CryptoBrainPoolNoLengthVerifyTest012, TestSize.Level0) { HcfVerify *verify = nullptr; - int32_t res = HcfVerifyCreate("ECC_BrainPoolP160r1|SHA224", &verify); + HcfResult res = HcfVerifyCreate("ECC_BrainPoolP160r1|SHA224", &verify); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(verify, nullptr); + ConstructEccKeyPairCommParamsSpec("NID_brainpoolP160r1", &g_eccCommSpec); + ASSERT_NE(g_eccCommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - res = Constructbrainpool160r1KeyPairParamsSpec(g_brainpool160r1AlgName, g_brainpool160r1CurveName, ¶mSpec); + res = ConstructEccKeyPairParamsSpec(g_brainpool160r1AlgName.c_str(), g_eccCommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); @@ -407,18 +342,21 @@ HWTEST_F(CryptoBrainPoolNoLengthVerifyTest, CryptoBrainPoolNoLengthVerifyTest012 HcfObjDestroy(verify); HcfObjDestroy(keyPair); HcfObjDestroy(generator); + DestroyEccKeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoBrainPoolNoLengthVerifyTest, CryptoBrainPoolNoLengthVerifyTest013, TestSize.Level0) { HcfVerify *verify = nullptr; - int32_t res = HcfVerifyCreate("ECC_BrainPoolP160r1|SHA224", &verify); + HcfResult res = HcfVerifyCreate("ECC_BrainPoolP160r1|SHA224", &verify); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(verify, nullptr); + ConstructEccKeyPairCommParamsSpec("NID_brainpoolP160r1", &g_eccCommSpec); + ASSERT_NE(g_eccCommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - res = Constructbrainpool160r1KeyPairParamsSpec(g_brainpool160r1AlgName, g_brainpool160r1CurveName, ¶mSpec); + res = ConstructEccKeyPairParamsSpec(g_brainpool160r1AlgName.c_str(), g_eccCommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); @@ -438,18 +376,21 @@ HWTEST_F(CryptoBrainPoolNoLengthVerifyTest, CryptoBrainPoolNoLengthVerifyTest013 HcfObjDestroy(verify); HcfObjDestroy(keyPair); HcfObjDestroy(generator); + DestroyEccKeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoBrainPoolNoLengthVerifyTest, CryptoBrainPoolNoLengthVerifyTest014, TestSize.Level0) { HcfVerify *verify = nullptr; - int32_t res = HcfVerifyCreate("ECC_BrainPoolP160r1|SHA224", &verify); + HcfResult res = HcfVerifyCreate("ECC_BrainPoolP160r1|SHA224", &verify); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(verify, nullptr); + ConstructEccKeyPairCommParamsSpec("NID_brainpoolP160r1", &g_eccCommSpec); + ASSERT_NE(g_eccCommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - res = Constructbrainpool160r1KeyPairParamsSpec(g_brainpool160r1AlgName, g_brainpool160r1CurveName, ¶mSpec); + res = ConstructEccKeyPairParamsSpec(g_brainpool160r1AlgName.c_str(), g_eccCommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); @@ -469,18 +410,21 @@ HWTEST_F(CryptoBrainPoolNoLengthVerifyTest, CryptoBrainPoolNoLengthVerifyTest014 HcfObjDestroy(verify); HcfObjDestroy(keyPair); HcfObjDestroy(generator); + DestroyEccKeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoBrainPoolNoLengthVerifyTest, CryptoBrainPoolNoLengthVerifyTest015, TestSize.Level0) { HcfVerify *verify = nullptr; - int32_t res = HcfVerifyCreate("ECC_BrainPoolP160r1|SHA224", &verify); + HcfResult res = HcfVerifyCreate("ECC_BrainPoolP160r1|SHA224", &verify); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(verify, nullptr); + ConstructEccKeyPairCommParamsSpec("NID_brainpoolP160r1", &g_eccCommSpec); + ASSERT_NE(g_eccCommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - res = Constructbrainpool160r1KeyPairParamsSpec(g_brainpool160r1AlgName, g_brainpool160r1CurveName, ¶mSpec); + res = ConstructEccKeyPairParamsSpec(g_brainpool160r1AlgName.c_str(), g_eccCommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); @@ -503,18 +447,21 @@ HWTEST_F(CryptoBrainPoolNoLengthVerifyTest, CryptoBrainPoolNoLengthVerifyTest015 HcfObjDestroy(verify); HcfObjDestroy(keyPair); HcfObjDestroy(generator); + DestroyEccKeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoBrainPoolNoLengthVerifyTest, CryptoBrainPoolNoLengthVerifyTest016, TestSize.Level0) { HcfVerify *verify = nullptr; - int32_t res = HcfVerifyCreate("ECC_BrainPoolP160r1|SHA224", &verify); + HcfResult res = HcfVerifyCreate("ECC_BrainPoolP160r1|SHA224", &verify); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(verify, nullptr); + ConstructEccKeyPairCommParamsSpec("NID_brainpoolP160r1", &g_eccCommSpec); + ASSERT_NE(g_eccCommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - res = Constructbrainpool160r1KeyPairParamsSpec(g_brainpool160r1AlgName, g_brainpool160r1CurveName, ¶mSpec); + res = ConstructEccKeyPairParamsSpec(g_brainpool160r1AlgName.c_str(), g_eccCommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); @@ -537,18 +484,21 @@ HWTEST_F(CryptoBrainPoolNoLengthVerifyTest, CryptoBrainPoolNoLengthVerifyTest016 HcfObjDestroy(verify); HcfObjDestroy(keyPair); HcfObjDestroy(generator); + DestroyEccKeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoBrainPoolNoLengthVerifyTest, CryptoBrainPoolNoLengthVerifyTest017, TestSize.Level0) { HcfVerify *verify = nullptr; - int32_t res = HcfVerifyCreate("ECC_BrainPoolP160r1|SHA224", &verify); + HcfResult res = HcfVerifyCreate("ECC_BrainPoolP160r1|SHA224", &verify); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(verify, nullptr); + ConstructEccKeyPairCommParamsSpec("NID_brainpoolP160r1", &g_eccCommSpec); + ASSERT_NE(g_eccCommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - res = Constructbrainpool160r1KeyPairParamsSpec(g_brainpool160r1AlgName, g_brainpool160r1CurveName, ¶mSpec); + res = ConstructEccKeyPairParamsSpec(g_brainpool160r1AlgName.c_str(), g_eccCommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); @@ -571,18 +521,21 @@ HWTEST_F(CryptoBrainPoolNoLengthVerifyTest, CryptoBrainPoolNoLengthVerifyTest017 HcfObjDestroy(verify); HcfObjDestroy(keyPair); HcfObjDestroy(generator); + DestroyEccKeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoBrainPoolNoLengthVerifyTest, CryptoBrainPoolNoLengthVerifyTest018, TestSize.Level0) { HcfVerify *verify = nullptr; - int32_t res = HcfVerifyCreate("ECC_BrainPoolP160r1|SHA224", &verify); + HcfResult res = HcfVerifyCreate("ECC_BrainPoolP160r1|SHA224", &verify); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(verify, nullptr); + ConstructEccKeyPairCommParamsSpec("NID_brainpoolP160r1", &g_eccCommSpec); + ASSERT_NE(g_eccCommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - res = Constructbrainpool160r1KeyPairParamsSpec(g_brainpool160r1AlgName, g_brainpool160r1CurveName, ¶mSpec); + res = ConstructEccKeyPairParamsSpec(g_brainpool160r1AlgName.c_str(), g_eccCommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); @@ -605,18 +558,21 @@ HWTEST_F(CryptoBrainPoolNoLengthVerifyTest, CryptoBrainPoolNoLengthVerifyTest018 HcfObjDestroy(verify); HcfObjDestroy(keyPair); HcfObjDestroy(generator); + DestroyEccKeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoBrainPoolNoLengthVerifyTest, CryptoBrainPoolNoLengthVerifyTest019, TestSize.Level0) { HcfVerify *verify = nullptr; - int32_t res = HcfVerifyCreate("ECC_BrainPoolP160r1|SHA224", &verify); + HcfResult res = HcfVerifyCreate("ECC_BrainPoolP160r1|SHA224", &verify); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(verify, nullptr); + ConstructEccKeyPairCommParamsSpec("NID_brainpoolP160r1", &g_eccCommSpec); + ASSERT_NE(g_eccCommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - res = Constructbrainpool160r1KeyPairParamsSpec(g_brainpool160r1AlgName, g_brainpool160r1CurveName, ¶mSpec); + res = ConstructEccKeyPairParamsSpec(g_brainpool160r1AlgName.c_str(), g_eccCommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); @@ -642,18 +598,21 @@ HWTEST_F(CryptoBrainPoolNoLengthVerifyTest, CryptoBrainPoolNoLengthVerifyTest019 HcfObjDestroy(verify); HcfObjDestroy(keyPair); HcfObjDestroy(generator); + DestroyEccKeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoBrainPoolNoLengthVerifyTest, CryptoBrainPoolNoLengthVerifyTest020, TestSize.Level0) { HcfVerify *verify = nullptr; - int32_t res = HcfVerifyCreate("ECC_BrainPoolP160r1|SHA224", &verify); + HcfResult res = HcfVerifyCreate("ECC_BrainPoolP160r1|SHA224", &verify); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(verify, nullptr); + ConstructEccKeyPairCommParamsSpec("NID_brainpoolP160r1", &g_eccCommSpec); + ASSERT_NE(g_eccCommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - res = Constructbrainpool160r1KeyPairParamsSpec(g_brainpool160r1AlgName, g_brainpool160r1CurveName, ¶mSpec); + res = ConstructEccKeyPairParamsSpec(g_brainpool160r1AlgName.c_str(), g_eccCommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); @@ -680,18 +639,21 @@ HWTEST_F(CryptoBrainPoolNoLengthVerifyTest, CryptoBrainPoolNoLengthVerifyTest020 HcfObjDestroy(verify); HcfObjDestroy(keyPair); HcfObjDestroy(generator); + DestroyEccKeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoBrainPoolNoLengthVerifyTest, CryptoBrainPoolNoLengthVerifyTest021, TestSize.Level0) { HcfSign *sign = nullptr; - int32_t res = HcfSignCreate("ECC_BrainPoolP160r1|SHA224", &sign); + HcfResult res = HcfSignCreate("ECC_BrainPoolP160r1|SHA224", &sign); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(sign, nullptr); + ConstructEccKeyPairCommParamsSpec("NID_brainpoolP160r1", &g_eccCommSpec); + ASSERT_NE(g_eccCommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - res = Constructbrainpool160r1KeyPairParamsSpec(g_brainpool160r1AlgName, g_brainpool160r1CurveName, ¶mSpec); + res = ConstructEccKeyPairParamsSpec(g_brainpool160r1AlgName.c_str(), g_eccCommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); @@ -733,23 +695,26 @@ HWTEST_F(CryptoBrainPoolNoLengthVerifyTest, CryptoBrainPoolNoLengthVerifyTest021 bool flag = verify->verify(verify, nullptr, &out); ASSERT_EQ(flag, true); - free(out.data); + HcfFree(out.data); HcfObjDestroy(keyPair); HcfObjDestroy(sign); HcfObjDestroy(verify); HcfObjDestroy(generator); + DestroyEccKeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoBrainPoolNoLengthVerifyTest, CryptoBrainPoolNoLengthVerifyTest022, TestSize.Level0) { HcfSign *sign = nullptr; - int32_t res = HcfSignCreate("ECC_BrainPoolP160r1|SHA224", &sign); + HcfResult res = HcfSignCreate("ECC_BrainPoolP160r1|SHA224", &sign); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(sign, nullptr); + ConstructEccKeyPairCommParamsSpec("NID_brainpoolP160r1", &g_eccCommSpec); + ASSERT_NE(g_eccCommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - res = Constructbrainpool160r1KeyPairParamsSpec(g_brainpool160r1AlgName, g_brainpool160r1CurveName, ¶mSpec); + res = ConstructEccKeyPairParamsSpec(g_brainpool160r1AlgName.c_str(), g_eccCommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); @@ -783,23 +748,26 @@ HWTEST_F(CryptoBrainPoolNoLengthVerifyTest, CryptoBrainPoolNoLengthVerifyTest022 bool flag = verify->verify(verify, &g_mockInput, &out); ASSERT_EQ(flag, true); - free(out.data); + HcfFree(out.data); HcfObjDestroy(keyPair); HcfObjDestroy(sign); HcfObjDestroy(verify); HcfObjDestroy(generator); + DestroyEccKeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoBrainPoolNoLengthVerifyTest, CryptoBrainPoolNoLengthVerifyTest023, TestSize.Level0) { HcfSign *sign = nullptr; - int32_t res = HcfSignCreate("ECC_BrainPoolP160r1|SHA224", &sign); + HcfResult res = HcfSignCreate("ECC_BrainPoolP160r1|SHA224", &sign); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(sign, nullptr); + ConstructEccKeyPairCommParamsSpec("NID_brainpoolP160r1", &g_eccCommSpec); + ASSERT_NE(g_eccCommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - res = Constructbrainpool160r1KeyPairParamsSpec(g_brainpool160r1AlgName, g_brainpool160r1CurveName, ¶mSpec); + res = ConstructEccKeyPairParamsSpec(g_brainpool160r1AlgName.c_str(), g_eccCommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); @@ -841,23 +809,26 @@ HWTEST_F(CryptoBrainPoolNoLengthVerifyTest, CryptoBrainPoolNoLengthVerifyTest023 bool flag = verify->verify(nullptr, nullptr, &out); ASSERT_NE(flag, true); - free(out.data); + HcfFree(out.data); HcfObjDestroy(keyPair); HcfObjDestroy(sign); HcfObjDestroy(verify); HcfObjDestroy(generator); + DestroyEccKeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoBrainPoolNoLengthVerifyTest, CryptoBrainPoolNoLengthVerifyTest024, TestSize.Level0) { HcfSign *sign = nullptr; - int32_t res = HcfSignCreate("ECC_BrainPoolP160r1|SHA224", &sign); + HcfResult res = HcfSignCreate("ECC_BrainPoolP160r1|SHA224", &sign); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(sign, nullptr); + ConstructEccKeyPairCommParamsSpec("NID_brainpoolP160r1", &g_eccCommSpec); + ASSERT_NE(g_eccCommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - res = Constructbrainpool160r1KeyPairParamsSpec(g_brainpool160r1AlgName, g_brainpool160r1CurveName, ¶mSpec); + res = ConstructEccKeyPairParamsSpec(g_brainpool160r1AlgName.c_str(), g_eccCommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); @@ -899,23 +870,26 @@ HWTEST_F(CryptoBrainPoolNoLengthVerifyTest, CryptoBrainPoolNoLengthVerifyTest024 bool flag = verify->verify((HcfVerify *)&obj, nullptr, &out); ASSERT_NE(flag, true); - free(out.data); + HcfFree(out.data); HcfObjDestroy(keyPair); HcfObjDestroy(sign); HcfObjDestroy(verify); HcfObjDestroy(generator); + DestroyEccKeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoBrainPoolNoLengthVerifyTest, CryptoBrainPoolNoLengthVerifyTest025, TestSize.Level0) { HcfSign *sign = nullptr; - int32_t res = HcfSignCreate("ECC_BrainPoolP160r1|SHA224", &sign); + HcfResult res = HcfSignCreate("ECC_BrainPoolP160r1|SHA224", &sign); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(sign, nullptr); + ConstructEccKeyPairCommParamsSpec("NID_brainpoolP160r1", &g_eccCommSpec); + ASSERT_NE(g_eccCommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - res = Constructbrainpool160r1KeyPairParamsSpec(g_brainpool160r1AlgName, g_brainpool160r1CurveName, ¶mSpec); + res = ConstructEccKeyPairParamsSpec(g_brainpool160r1AlgName.c_str(), g_eccCommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); @@ -954,23 +928,26 @@ HWTEST_F(CryptoBrainPoolNoLengthVerifyTest, CryptoBrainPoolNoLengthVerifyTest025 bool flag = verify->verify((HcfVerify *)(&obj), nullptr, &out); ASSERT_NE(flag, true); - free(out.data); + HcfFree(out.data); HcfObjDestroy(keyPair); HcfObjDestroy(sign); HcfObjDestroy(generator); HcfObjDestroy(verify); + DestroyEccKeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoBrainPoolNoLengthVerifyTest, CryptoBrainPoolNoLengthVerifyTest026, TestSize.Level0) { HcfSign *sign = nullptr; - int32_t res = HcfSignCreate("ECC_BrainPoolP160r1|SHA224", &sign); + HcfResult res = HcfSignCreate("ECC_BrainPoolP160r1|SHA224", &sign); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(sign, nullptr); + ConstructEccKeyPairCommParamsSpec("NID_brainpoolP160r1", &g_eccCommSpec); + ASSERT_NE(g_eccCommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - res = Constructbrainpool160r1KeyPairParamsSpec(g_brainpool160r1AlgName, g_brainpool160r1CurveName, ¶mSpec); + res = ConstructEccKeyPairParamsSpec(g_brainpool160r1AlgName.c_str(), g_eccCommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); @@ -1014,11 +991,12 @@ HWTEST_F(CryptoBrainPoolNoLengthVerifyTest, CryptoBrainPoolNoLengthVerifyTest026 bool flag = verify->verify((HcfVerify *)(&obj), &input, &out); ASSERT_NE(flag, true); - free(out.data); + HcfFree(out.data); HcfObjDestroy(keyPair); HcfObjDestroy(sign); HcfObjDestroy(verify); HcfObjDestroy(generator); + DestroyEccKeyPairSpec(reinterpret_cast(paramSpec)); } HcfSignatureParams g_params = { @@ -1030,20 +1008,21 @@ HcfSignatureParams g_params = { HWTEST_F(CryptoBrainPoolNoLengthVerifyTest, CryptoBrainPoolNoLengthVerifyTest027, TestSize.Level0) { - int32_t res = HcfVerifySpiEcdsaCreate(&g_params, nullptr); + HcfResult res = HcfVerifySpiEcdsaCreate(&g_params, nullptr); ASSERT_EQ(res, HCF_INVALID_PARAMS); } HWTEST_F(CryptoBrainPoolNoLengthVerifyTest, CryptoBrainPoolNoLengthVerifyTest028, TestSize.Level0) { HcfVerifySpi *spiObj = nullptr; - int32_t res = HcfVerifySpiEcdsaCreate(&g_params, &spiObj); - + HcfResult res = HcfVerifySpiEcdsaCreate(&g_params, &spiObj); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(spiObj, nullptr); + ConstructEccKeyPairCommParamsSpec("NID_brainpoolP160r1", &g_eccCommSpec); + ASSERT_NE(g_eccCommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - res = Constructbrainpool160r1KeyPairParamsSpec(g_brainpool160r1AlgName, g_brainpool160r1CurveName, ¶mSpec); + res = ConstructEccKeyPairParamsSpec(g_brainpool160r1AlgName.c_str(), g_eccCommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); @@ -1063,18 +1042,20 @@ HWTEST_F(CryptoBrainPoolNoLengthVerifyTest, CryptoBrainPoolNoLengthVerifyTest028 HcfObjDestroy(spiObj); HcfObjDestroy(keyPair); HcfObjDestroy(generator); + DestroyEccKeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoBrainPoolNoLengthVerifyTest, CryptoBrainPoolNoLengthVerifyTest029, TestSize.Level0) { HcfVerifySpi *spiObj = nullptr; - int32_t res = HcfVerifySpiEcdsaCreate(&g_params, &spiObj); - + HcfResult res = HcfVerifySpiEcdsaCreate(&g_params, &spiObj); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(spiObj, nullptr); + ConstructEccKeyPairCommParamsSpec("NID_brainpoolP160r1", &g_eccCommSpec); + ASSERT_NE(g_eccCommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - res = Constructbrainpool160r1KeyPairParamsSpec(g_brainpool160r1AlgName, g_brainpool160r1CurveName, ¶mSpec); + res = ConstructEccKeyPairParamsSpec(g_brainpool160r1AlgName.c_str(), g_eccCommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); @@ -1094,12 +1075,13 @@ HWTEST_F(CryptoBrainPoolNoLengthVerifyTest, CryptoBrainPoolNoLengthVerifyTest029 HcfObjDestroy(spiObj); HcfObjDestroy(keyPair); HcfObjDestroy(generator); + DestroyEccKeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoBrainPoolNoLengthVerifyTest, CryptoBrainPoolNoLengthVerifyTest030, TestSize.Level0) { HcfVerifySpi *spiObj = nullptr; - int32_t res = HcfVerifySpiEcdsaCreate(&g_params, &spiObj); + HcfResult res = HcfVerifySpiEcdsaCreate(&g_params, &spiObj); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(spiObj, nullptr); @@ -1117,7 +1099,7 @@ HWTEST_F(CryptoBrainPoolNoLengthVerifyTest, CryptoBrainPoolNoLengthVerifyTest030 HWTEST_F(CryptoBrainPoolNoLengthVerifyTest, CryptoBrainPoolNoLengthVerifyTest031, TestSize.Level0) { HcfVerifySpi *spiObj = nullptr; - int32_t res = HcfVerifySpiEcdsaCreate(&g_params, &spiObj); + HcfResult res = HcfVerifySpiEcdsaCreate(&g_params, &spiObj); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(spiObj, nullptr); @@ -1135,7 +1117,7 @@ HWTEST_F(CryptoBrainPoolNoLengthVerifyTest, CryptoBrainPoolNoLengthVerifyTest031 HWTEST_F(CryptoBrainPoolNoLengthVerifyTest, CryptoBrainPoolNoLengthVerifyTest032, TestSize.Level0) { HcfVerifySpi *spiObj = nullptr; - int32_t res = HcfVerifySpiEcdsaCreate(&g_params, &spiObj); + HcfResult res = HcfVerifySpiEcdsaCreate(&g_params, &spiObj); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(spiObj, nullptr); @@ -1148,7 +1130,7 @@ HWTEST_F(CryptoBrainPoolNoLengthVerifyTest, CryptoBrainPoolNoLengthVerifyTest032 HWTEST_F(CryptoBrainPoolNoLengthVerifyTest, CryptoBrainPoolNoLengthVerifyTest033, TestSize.Level0) { HcfVerifySpi *spiObj = nullptr; - int32_t res = HcfVerifySpiEcdsaCreate(&g_params, &spiObj); + HcfResult res = HcfVerifySpiEcdsaCreate(&g_params, &spiObj); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(spiObj, nullptr); @@ -1167,7 +1149,7 @@ HWTEST_F(CryptoBrainPoolNoLengthVerifyTest, CryptoBrainPoolNoLengthVerifyTest033 HWTEST_F(CryptoBrainPoolNoLengthVerifyTest, CryptoBrainPoolNoLengthVerifyTest034, TestSize.Level0) { HcfVerifySpi *spiObj = nullptr; - int32_t res = HcfVerifySpiEcdsaCreate(&g_params, &spiObj); + HcfResult res = HcfVerifySpiEcdsaCreate(&g_params, &spiObj); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(spiObj, nullptr); @@ -1185,7 +1167,7 @@ HWTEST_F(CryptoBrainPoolNoLengthVerifyTest, CryptoBrainPoolNoLengthVerifyTest034 HWTEST_F(CryptoBrainPoolNoLengthVerifyTest, CryptoBrainPoolNoLengthVerifyTest035, TestSize.Level0) { HcfVerifySpi *spiObj = nullptr; - int32_t res = HcfVerifySpiEcdsaCreate(&g_params, &spiObj); + HcfResult res = HcfVerifySpiEcdsaCreate(&g_params, &spiObj); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(spiObj, nullptr); @@ -1197,7 +1179,7 @@ HWTEST_F(CryptoBrainPoolNoLengthVerifyTest, CryptoBrainPoolNoLengthVerifyTest035 HWTEST_F(CryptoBrainPoolNoLengthVerifyTest, CryptoBrainPoolNoLengthVerifyTest036, TestSize.Level0) { HcfVerifySpi *spiObj = nullptr; - int32_t res = HcfVerifySpiEcdsaCreate(&g_params, &spiObj); + HcfResult res = HcfVerifySpiEcdsaCreate(&g_params, &spiObj); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(spiObj, nullptr); @@ -1210,7 +1192,7 @@ static bool GetSignTestData(HcfBlob *out, HcfPriKey *priKey) { HcfSign *sign = nullptr; - int32_t res = HcfSignCreate("ECC_BrainPoolP160r1|SHA224", &sign); + HcfResult res = HcfSignCreate("ECC_BrainPoolP160r1|SHA224", &sign); if (res != HCF_SUCCESS) { return false; } @@ -1235,7 +1217,7 @@ static void MemoryMockTestFunc(uint32_t mallocCount, HcfBlob *out, HcfPubKey *pu ResetRecordMallocNum(); SetMockMallocIndex(i); HcfVerify *verify = nullptr; - int32_t res = HcfVerifyCreate("ECC_BrainPoolP160r1|SHA224", &verify); + HcfResult res = HcfVerifyCreate("ECC_BrainPoolP160r1|SHA224", &verify); if (res != HCF_SUCCESS) { continue; } @@ -1259,13 +1241,15 @@ HWTEST_F(CryptoBrainPoolNoLengthVerifyTest, CryptoBrainPoolNoLengthVerifyTest037 StartRecordMallocNum(); HcfVerify *verify = nullptr; - int32_t res = HcfVerifyCreate("ECC_BrainPoolP160r1|SHA224", &verify); + HcfResult res = HcfVerifyCreate("ECC_BrainPoolP160r1|SHA224", &verify); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(verify, nullptr); + ConstructEccKeyPairCommParamsSpec("NID_brainpoolP160r1", &g_eccCommSpec); + ASSERT_NE(g_eccCommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - res = Constructbrainpool160r1KeyPairParamsSpec(g_brainpool160r1AlgName, g_brainpool160r1CurveName, ¶mSpec); + res = ConstructEccKeyPairParamsSpec(g_brainpool160r1AlgName.c_str(), g_eccCommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); @@ -1294,9 +1278,10 @@ HWTEST_F(CryptoBrainPoolNoLengthVerifyTest, CryptoBrainPoolNoLengthVerifyTest037 uint32_t mallocCount = GetMallocNum(); MemoryMockTestFunc(mallocCount, &out, keyPair->pubKey); EndRecordMallocNum(); - free(out.data); + HcfFree(out.data); HcfObjDestroy(generator); HcfObjDestroy(keyPair); + DestroyEccKeyPairSpec(reinterpret_cast(paramSpec)); } static void OpensslMockTestFunc(uint32_t mallocCount, HcfBlob *out, HcfPubKey *pubKey) @@ -1305,7 +1290,7 @@ static void OpensslMockTestFunc(uint32_t mallocCount, HcfBlob *out, HcfPubKey *p ResetOpensslCallNum(); SetOpensslCallMockIndex(i); HcfVerify *verify = nullptr; - int32_t res = HcfVerifyCreate("ECC_BrainPoolP160r1|SHA224", &verify); + HcfResult res = HcfVerifyCreate("ECC_BrainPoolP160r1|SHA224", &verify); if (res != HCF_SUCCESS) { continue; } @@ -1328,13 +1313,15 @@ HWTEST_F(CryptoBrainPoolNoLengthVerifyTest, CryptoBrainPoolNoLengthVerifyTest038 { StartRecordOpensslCallNum(); HcfVerify *verify = nullptr; - int32_t res = HcfVerifyCreate("ECC_BrainPoolP160r1|SHA224", &verify); + HcfResult res = HcfVerifyCreate("ECC_BrainPoolP160r1|SHA224", &verify); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(verify, nullptr); + ConstructEccKeyPairCommParamsSpec("NID_brainpoolP160r1", &g_eccCommSpec); + ASSERT_NE(g_eccCommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - res = Constructbrainpool160r1KeyPairParamsSpec(g_brainpool160r1AlgName, g_brainpool160r1CurveName, ¶mSpec); + res = ConstructEccKeyPairParamsSpec(g_brainpool160r1AlgName.c_str(), g_eccCommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); @@ -1364,8 +1351,32 @@ HWTEST_F(CryptoBrainPoolNoLengthVerifyTest, CryptoBrainPoolNoLengthVerifyTest038 uint32_t mallocCount = GetOpensslCallNum(); OpensslMockTestFunc(mallocCount, &out, keyPair->pubKey); EndRecordOpensslCallNum(); - free(out.data); + HcfFree(out.data); HcfObjDestroy(generator); HcfObjDestroy(keyPair); + DestroyEccKeyPairSpec(reinterpret_cast(paramSpec)); } + +HWTEST_F(CryptoBrainPoolNoLengthVerifyTest, CryptoBrainPoolNoLengthVerifyTest039, TestSize.Level0) +{ + HcfVerify *verify = nullptr; + HcfResult res = HcfVerifyCreate("ECC_BrainPoolP160r1|SHA224", &verify); + + ASSERT_EQ(res, HCF_SUCCESS); + ASSERT_NE(verify, nullptr); + + int32_t returnInt = 0; + res = verify->setVerifySpecInt(verify, SM2_USER_ID_UINT8ARR, returnInt); + ASSERT_EQ(res, HCF_NOT_SUPPORT); + res = verify->getVerifySpecInt(verify, SM2_USER_ID_UINT8ARR, &returnInt); + ASSERT_EQ(res, HCF_NOT_SUPPORT); + HcfBlob returnBlob = { .data = nullptr, .len = 0}; + res = verify->setVerifySpecUint8Array(verify, SM2_USER_ID_UINT8ARR, returnBlob); + ASSERT_EQ(res, HCF_NOT_SUPPORT); + char *itemName = nullptr; + res = verify->getVerifySpecString(verify, SM2_USER_ID_UINT8ARR, &itemName); + ASSERT_EQ(res, HCF_NOT_SUPPORT); + + HcfObjDestroy(verify); } +} \ No newline at end of file diff --git a/test/unittest/src/crypto_dh_asy_key_generator_by_spec_test.cpp b/test/unittest/src/crypto_dh_asy_key_generator_by_spec_test.cpp index 3f3687d73d877ff2e41e3ca657bec8c32256782b..e31f967aa45e460c0c20f4ef5eb824fab850fb67 100644 --- a/test/unittest/src/crypto_dh_asy_key_generator_by_spec_test.cpp +++ b/test/unittest/src/crypto_dh_asy_key_generator_by_spec_test.cpp @@ -16,6 +16,7 @@ #include #include +#include "alg_25519_common_param_spec.h" #include "asy_key_generator.h" #include "blob.h" #include "dh_key_util.h" @@ -28,7 +29,6 @@ #include "dh_asy_key_generator_openssl.h" #include "detailed_dh_key_params.h" #include "alg_25519_asy_key_generator_openssl.h" -#include "detailed_alg_25519_key_params.h" #include "dh_common_param_spec_generator_openssl.h" #include "memory_mock.h" #include "openssl_adapter_mock.h" @@ -71,7 +71,6 @@ static string g_dh3072AlgoName = "DH_modp3072"; static string g_dh4096AlgoName = "DH_modp4096"; static string g_dh6144AlgoName = "DH_modp6144"; static string g_dh8192AlgoName = "DH_modp8192"; -static string g_ed25519AlgoName = "Ed25519"; static string g_dhAlgoName = "DH"; static string g_dhpubkeyformatName = "X.509"; @@ -84,14 +83,6 @@ HcfDhCommParamsSpec *g_dh4096CommSpec = nullptr; HcfDhCommParamsSpec *g_dh6144CommSpec = nullptr; HcfDhCommParamsSpec *g_dh8192CommSpec = nullptr; -HcfDhKeyPairParamsSpec g_dhKeyPairSpec; -HcfDhPriKeyParamsSpec g_dhPriKeySpec; -HcfDhPubKeyParamsSpec g_dhPubKeySpec; - -HcfAlg25519KeyPairParamsSpec g_ed25519KeyPairSpec; -HcfAlg25519PriKeyParamsSpec g_ed25519PriKeySpec; -HcfAlg25519PubKeyParamsSpec g_ed25519PubKeySpec; - void CryptoDHAsyKeyGeneratorBySpecTest::SetUp() {} void CryptoDHAsyKeyGeneratorBySpecTest::TearDown() {} @@ -104,6 +95,44 @@ HcfObjectBase g_obj = { .destroy = nullptr }; +static void DestroyTestDhPriKeySpec(HcfDhPriKeyParamsSpec *spec) +{ + if (spec == NULL) { + return; + } + if (spec->sk.data != NULL) { + (void)memset_s(spec->sk.data, spec->sk.len, 0, spec->sk.len); + HcfFree(spec->sk.data); + spec->sk.data = NULL; + } + HcfFree(spec); +} + +static void DestroyTestDhPubKeySpec(HcfDhPubKeyParamsSpec *spec) +{ + if (spec == NULL) { + return; + } + HcfFree(spec->pk.data); + spec->pk.data = NULL; + HcfFree(spec); +} + +static void DestroyTestDhKeyPairSpec(HcfDhKeyPairParamsSpec *spec) +{ + if (spec == NULL) { + return; + } + HcfFree(spec->pk.data); + spec->pk.data = NULL; + if (spec->sk.data != NULL) { + (void)memset_s(spec->sk.data, spec->sk.len, 0, spec->sk.len); + HcfFree(spec->sk.data); + spec->sk.data = NULL; + } + HcfFree(spec); +} + static HcfResult ConstructDHKeyCommParamsSpec(int32_t pLen, int32_t skLen, HcfDhCommParamsSpec **spec) { HcfDhCommParamsSpec *dhCommSpec = nullptr; @@ -115,51 +144,30 @@ static HcfResult ConstructDHKeyCommParamsSpec(int32_t pLen, int32_t skLen, HcfDh return HCF_SUCCESS; } -static HcfResult ConstructDHKeyPairParamsCommonSpec(const string &algoName, HcfDhCommParamsSpec *comSpec, - HcfAsyKeyParamsSpec **spec) +static HcfResult ConstructDhKeyPairBigInt(HcfKeyPair *keyPair, HcfDhKeyPairParamsSpec *dhKeyPairSpec) { - HcfAsyKeyGenerator *generator = nullptr; - HcfResult res = HcfAsyKeyGeneratorCreate(algoName.c_str(), &generator); + HcfBigInteger retBigInt = { .data = NULL, .len = 0 }; + HcfResult res = keyPair->pubKey->getAsyKeySpecBigInteger(keyPair->pubKey, DH_PK_BN, &retBigInt); if (res != HCF_SUCCESS) { return res; } - HcfKeyPair *keyPair = nullptr; - res = generator->generateKeyPair(generator, nullptr, &keyPair); - if (res != HCF_SUCCESS) { - HcfObjDestroy(generator); - return res; - } - HcfDhKeyPairParamsSpec *dhKeyPairSpec = &g_dhKeyPairSpec; - HcfBigInteger retBigInt = { .data = nullptr, .len = 0 }; - dhKeyPairSpec->base.base.algName = comSpec->base.algName; - dhKeyPairSpec->base.base.specType = HCF_COMMON_PARAMS_SPEC; - dhKeyPairSpec->base.g = comSpec->g; - dhKeyPairSpec->base.p = comSpec->p; - dhKeyPairSpec->base.length = comSpec->length; - res = keyPair->pubKey->getAsyKeySpecBigInteger(keyPair->pubKey, DH_PK_BN, &retBigInt); - if (res != HCF_SUCCESS) { - HcfObjDestroy(generator); - HcfObjDestroy(keyPair); - return res; - } dhKeyPairSpec->pk.data = retBigInt.data; dhKeyPairSpec->pk.len = retBigInt.len; + res = keyPair->priKey->getAsyKeySpecBigInteger(keyPair->priKey, DH_SK_BN, &retBigInt); if (res != HCF_SUCCESS) { - HcfObjDestroy(generator); - HcfObjDestroy(keyPair); + HcfFree(dhKeyPairSpec->pk.data); + dhKeyPairSpec->pk.data = NULL; + dhKeyPairSpec->pk.len = 0; return res; } dhKeyPairSpec->sk.data = retBigInt.data; dhKeyPairSpec->sk.len = retBigInt.len; - *spec = (HcfAsyKeyParamsSpec *)dhKeyPairSpec; - HcfObjDestroy(generator); - HcfObjDestroy(keyPair); return HCF_SUCCESS; } -static HcfResult ConstructDHKeyPairParamsSpec(const string &algoName, HcfDhCommParamsSpec *comSpec, - HcfAsyKeyParamsSpec **spec) +static HcfResult ConstructDHKeyPairParamsCommonSpec(const std::string &algoName, + HcfDhCommParamsSpec *dhCommParamsSpec, HcfAsyKeyParamsSpec **spec) { HcfAsyKeyGenerator *generator = nullptr; HcfResult res = HcfAsyKeyGeneratorCreate(algoName.c_str(), &generator); @@ -173,30 +181,68 @@ static HcfResult ConstructDHKeyPairParamsSpec(const string &algoName, HcfDhCommP HcfObjDestroy(generator); return res; } - HcfDhKeyPairParamsSpec *dhKeyPairSpec = &g_dhKeyPairSpec; - HcfBigInteger retBigInt = { .data = nullptr, .len = 0 }; - dhKeyPairSpec->base.base.algName = comSpec->base.algName; - dhKeyPairSpec->base.base.specType = HCF_KEY_PAIR_SPEC; - dhKeyPairSpec->base.g = comSpec->g; - dhKeyPairSpec->base.p = comSpec->p; - dhKeyPairSpec->base.length = comSpec->length; - res = keyPair->pubKey->getAsyKeySpecBigInteger(keyPair->pubKey, DH_PK_BN, &retBigInt); + + HcfDhKeyPairParamsSpec *dhKeyPairSpec = + reinterpret_cast(HcfMalloc(sizeof(HcfDhKeyPairParamsSpec), 0)); + if (dhKeyPairSpec != nullptr) { + dhKeyPairSpec->base.base.algName = dhCommParamsSpec->base.algName; + dhKeyPairSpec->base.base.specType = HCF_COMMON_PARAMS_SPEC; + dhKeyPairSpec->base.p.data = dhCommParamsSpec->p.data; + dhKeyPairSpec->base.p.len = dhCommParamsSpec->p.len; + dhKeyPairSpec->base.g.data = dhCommParamsSpec->g.data; + dhKeyPairSpec->base.g.len = dhCommParamsSpec->g.len; + dhKeyPairSpec->base.length = dhCommParamsSpec->length; + res = ConstructDhKeyPairBigInt(keyPair, dhKeyPairSpec); + if (res != HCF_SUCCESS) { + HcfObjDestroy(generator); + HcfObjDestroy(keyPair); + HcfFree(dhKeyPairSpec); + return res; + } + *spec = reinterpret_cast(dhKeyPairSpec); + } + + HcfObjDestroy(generator); + HcfObjDestroy(keyPair); + return HCF_SUCCESS; +} + +static HcfResult ConstructDHKeyPairParamsSpec(const std::string &algoName, + HcfDhCommParamsSpec *dhCommParamsSpec, HcfAsyKeyParamsSpec **spec) +{ + HcfAsyKeyGenerator *generator = nullptr; + HcfResult res = HcfAsyKeyGeneratorCreate(algoName.c_str(), &generator); if (res != HCF_SUCCESS) { - HcfObjDestroy(generator); - HcfObjDestroy(keyPair); return res; } - dhKeyPairSpec->pk.data = retBigInt.data; - dhKeyPairSpec->pk.len = retBigInt.len; - res = keyPair->priKey->getAsyKeySpecBigInteger(keyPair->priKey, DH_SK_BN, &retBigInt); + + HcfKeyPair *keyPair = nullptr; + res = generator->generateKeyPair(generator, nullptr, &keyPair); if (res != HCF_SUCCESS) { HcfObjDestroy(generator); - HcfObjDestroy(keyPair); return res; } - dhKeyPairSpec->sk.data = retBigInt.data; - dhKeyPairSpec->sk.len = retBigInt.len; - *spec = (HcfAsyKeyParamsSpec *)dhKeyPairSpec; + + HcfDhKeyPairParamsSpec *dhKeyPairSpec = + reinterpret_cast(HcfMalloc(sizeof(HcfDhKeyPairParamsSpec), 0)); + if (dhKeyPairSpec != nullptr) { + dhKeyPairSpec->base.base.algName = dhCommParamsSpec->base.algName; + dhKeyPairSpec->base.base.specType = HCF_KEY_PAIR_SPEC; + dhKeyPairSpec->base.p.data = dhCommParamsSpec->p.data; + dhKeyPairSpec->base.p.len = dhCommParamsSpec->p.len; + dhKeyPairSpec->base.g.data = dhCommParamsSpec->g.data; + dhKeyPairSpec->base.g.len = dhCommParamsSpec->g.len; + dhKeyPairSpec->base.length = dhCommParamsSpec->length; + res = ConstructDhKeyPairBigInt(keyPair, dhKeyPairSpec); + if (res != HCF_SUCCESS) { + HcfObjDestroy(generator); + HcfObjDestroy(keyPair); + HcfFree(dhKeyPairSpec); + return res; + } + *spec = reinterpret_cast(dhKeyPairSpec); + } + HcfObjDestroy(generator); HcfObjDestroy(keyPair); return HCF_SUCCESS; @@ -205,18 +251,26 @@ static HcfResult ConstructDHKeyPairParamsSpec(const string &algoName, HcfDhCommP static HcfResult ConstructDHPubKeyParamsSpec(const string &algoName, HcfDhCommParamsSpec *comSpec, HcfAsyKeyParamsSpec **spec) { + if (comSpec == nullptr) { + return HCF_INVALID_PARAMS; + } + HcfDhPubKeyParamsSpec *dhPubKeySpec = (HcfDhPubKeyParamsSpec*)HcfMalloc(sizeof(HcfDhPubKeyParamsSpec), 0); + if (dhPubKeySpec == nullptr) { + return HCF_ERR_MALLOC; + } HcfAsyKeyGenerator *generator = nullptr; HcfResult res = HcfAsyKeyGeneratorCreate(algoName.c_str(), &generator); if (res != HCF_SUCCESS) { + HcfFree(dhPubKeySpec); return res; } HcfKeyPair *keyPair = nullptr; res = generator->generateKeyPair(generator, nullptr, &keyPair); if (res != HCF_SUCCESS) { HcfObjDestroy(generator); + HcfFree(dhPubKeySpec); return res; } - HcfDhPubKeyParamsSpec *dhPubKeySpec = &g_dhPubKeySpec; HcfBigInteger retBigInt = { .data = nullptr, .len = 0 }; dhPubKeySpec->base.base.algName = comSpec->base.algName; dhPubKeySpec->base.base.specType = HCF_PUBLIC_KEY_SPEC; @@ -227,12 +281,13 @@ static HcfResult ConstructDHPubKeyParamsSpec(const string &algoName, HcfDhCommPa if (res != HCF_SUCCESS) { HcfObjDestroy(generator); HcfObjDestroy(keyPair); + HcfFree(dhPubKeySpec); return res; } dhPubKeySpec->pk.data = retBigInt.data; dhPubKeySpec->pk.len = retBigInt.len; - *spec = (HcfAsyKeyParamsSpec *)dhPubKeySpec; + *spec = reinterpret_cast(dhPubKeySpec); HcfObjDestroy(generator); HcfObjDestroy(keyPair); return HCF_SUCCESS; @@ -241,9 +296,17 @@ static HcfResult ConstructDHPubKeyParamsSpec(const string &algoName, HcfDhCommPa static HcfResult ConstructDHPriKeyParamsSpec(const string &algoName, HcfDhCommParamsSpec *comSpec, HcfAsyKeyParamsSpec **spec) { + if (comSpec == nullptr) { + return HCF_INVALID_PARAMS; + } + HcfDhPriKeyParamsSpec *dhPriKeySpec = (HcfDhPriKeyParamsSpec*)HcfMalloc(sizeof(HcfDhPriKeyParamsSpec), 0); + if (dhPriKeySpec == nullptr) { + return HCF_ERR_MALLOC; + } HcfAsyKeyGenerator *generator = nullptr; HcfResult res = HcfAsyKeyGeneratorCreate(algoName.c_str(), &generator); if (res != HCF_SUCCESS) { + HcfFree(dhPriKeySpec); return res; } @@ -251,9 +314,9 @@ static HcfResult ConstructDHPriKeyParamsSpec(const string &algoName, HcfDhCommPa res = generator->generateKeyPair(generator, nullptr, &keyPair); if (res != HCF_SUCCESS) { HcfObjDestroy(generator); + HcfFree(dhPriKeySpec); return res; } - HcfDhPriKeyParamsSpec *dhPriKeySpec = &g_dhPriKeySpec; HcfBigInteger retBigInt = { .data = nullptr, .len = 0 }; dhPriKeySpec->base.base.algName = comSpec->base.algName; dhPriKeySpec->base.base.specType = HCF_PRIVATE_KEY_SPEC; @@ -264,125 +327,18 @@ static HcfResult ConstructDHPriKeyParamsSpec(const string &algoName, HcfDhCommPa if (res != HCF_SUCCESS) { HcfObjDestroy(generator); HcfObjDestroy(keyPair); + HcfFree(dhPriKeySpec); return res; } dhPriKeySpec->sk.data = retBigInt.data; dhPriKeySpec->sk.len = retBigInt.len; - *spec = (HcfAsyKeyParamsSpec *)dhPriKeySpec; + *spec = reinterpret_cast(dhPriKeySpec); HcfObjDestroy(generator); HcfObjDestroy(keyPair); return HCF_SUCCESS; } -static HcfResult ConstructEd25519KeyPairParamsSpec(const string &algoName, HcfAsyKeyParamsSpec **spec) -{ - HcfAsyKeyGenerator *generator = nullptr; - HcfResult res = HcfAsyKeyGeneratorCreate(algoName.c_str(), &generator); - if (res != HCF_SUCCESS) { - return res; - } - HcfKeyPair *keyPair = nullptr; - res = generator->generateKeyPair(generator, nullptr, &keyPair); - if (res != HCF_SUCCESS) { - HcfObjDestroy(generator); - return res; - } - HcfAlg25519KeyPairParamsSpec *ed25519KeyPairSpec = &g_ed25519KeyPairSpec; - HcfBigInteger retBigInt = { .data = nullptr, .len = 0 }; - ed25519KeyPairSpec->base.algName = g_ed25519AlgoName.data(); - ed25519KeyPairSpec->base.specType = HCF_KEY_PAIR_SPEC; - res = keyPair->pubKey->getAsyKeySpecBigInteger(keyPair->pubKey, ED25519_PK_BN, &retBigInt); - if (res != HCF_SUCCESS) { - HcfObjDestroy(generator); - HcfObjDestroy(keyPair); - return res; - } - ed25519KeyPairSpec->pk.data = retBigInt.data; - ed25519KeyPairSpec->pk.len = retBigInt.len; - res = keyPair->priKey->getAsyKeySpecBigInteger(keyPair->priKey, ED25519_SK_BN, &retBigInt); - if (res != HCF_SUCCESS) { - HcfObjDestroy(generator); - HcfObjDestroy(keyPair); - return res; - } - ed25519KeyPairSpec->sk.data = retBigInt.data; - ed25519KeyPairSpec->sk.len = retBigInt.len; - - *spec = (HcfAsyKeyParamsSpec *)ed25519KeyPairSpec; - HcfObjDestroy(generator); - HcfObjDestroy(keyPair); - return HCF_SUCCESS; -} - -static HcfResult ConstructEd25519PubKeyParamsSpec(const string &algoName, HcfAsyKeyParamsSpec **spec) -{ - HcfAsyKeyGenerator *generator = nullptr; - HcfResult res = HcfAsyKeyGeneratorCreate(algoName.c_str(), &generator); - if (res != HCF_SUCCESS) { - return res; - } - HcfKeyPair *keyPair = nullptr; - res = generator->generateKeyPair(generator, nullptr, &keyPair); - if (res != HCF_SUCCESS) { - HcfObjDestroy(generator); - return res; - } - - HcfAlg25519PubKeyParamsSpec *ed25519PubKeySpec = &g_ed25519PubKeySpec; - HcfBigInteger retBigInt = { .data = nullptr, .len = 0 }; - ed25519PubKeySpec->base.algName = g_ed25519AlgoName.data(); - ed25519PubKeySpec->base.specType = HCF_PUBLIC_KEY_SPEC; - res = keyPair->pubKey->getAsyKeySpecBigInteger(keyPair->pubKey, ED25519_PK_BN, &retBigInt); - if (res != HCF_SUCCESS) { - HcfObjDestroy(generator); - HcfObjDestroy(keyPair); - return res; - } - ed25519PubKeySpec->pk.data = retBigInt.data; - ed25519PubKeySpec->pk.len = retBigInt.len; - - *spec = (HcfAsyKeyParamsSpec *)ed25519PubKeySpec; - HcfObjDestroy(generator); - HcfObjDestroy(keyPair); - return HCF_SUCCESS; -} - -static HcfResult ConstructEd25519PriKeyParamsSpec(const string &algoName, HcfAsyKeyParamsSpec **spec) -{ - HcfAsyKeyGenerator *generator = nullptr; - HcfResult res = HcfAsyKeyGeneratorCreate(algoName.c_str(), &generator); - if (res != HCF_SUCCESS) { - return HCF_INVALID_PARAMS; - } - HcfKeyPair *keyPair = nullptr; - res = generator->generateKeyPair(generator, nullptr, &keyPair); - if (res != HCF_SUCCESS) { - HcfObjDestroy(generator); - return HCF_INVALID_PARAMS; - } - - HcfAlg25519PriKeyParamsSpec *ed25519PriKeySpec = &g_ed25519PriKeySpec; - HcfBigInteger retBigInt = { .data = nullptr, .len = 0 }; - - ed25519PriKeySpec->base.algName = g_ed25519AlgoName.data(); - ed25519PriKeySpec->base.specType = HCF_PRIVATE_KEY_SPEC; - res = keyPair->priKey->getAsyKeySpecBigInteger(keyPair->priKey, ED25519_SK_BN, &retBigInt); - if (res != HCF_SUCCESS) { - HcfObjDestroy(generator); - HcfObjDestroy(keyPair); - return res; - } - ed25519PriKeySpec->sk.data = retBigInt.data; - ed25519PriKeySpec->sk.len = retBigInt.len; - - *spec = (HcfAsyKeyParamsSpec *)ed25519PriKeySpec; - HcfObjDestroy(generator); - HcfObjDestroy(keyPair); - - return HCF_SUCCESS; -} - void CryptoDHAsyKeyGeneratorBySpecTest::SetUpTestCase() { HcfResult res = ConstructDHKeyCommParamsSpec(PLEN_DH1536, SKLEN_DH1024, &g_dh1536CommSpec); @@ -476,6 +432,7 @@ HWTEST_F(CryptoDHAsyKeyGeneratorBySpecTest, CryptoDHAsyKeyGeneratorBySpecTest002 ASSERT_NE(returnObj, nullptr); HcfObjDestroy(returnObj); + DestroyTestDhKeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoDHAsyKeyGeneratorBySpecTest, CryptoDHAsyKeyGeneratorBySpecTest002_2, TestSize.Level0) @@ -491,6 +448,7 @@ HWTEST_F(CryptoDHAsyKeyGeneratorBySpecTest, CryptoDHAsyKeyGeneratorBySpecTest002 ASSERT_NE(returnObj, nullptr); HcfObjDestroy(returnObj); + DestroyTestDhKeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoDHAsyKeyGeneratorBySpecTest, CryptoDHAsyKeyGeneratorBySpecTest002_3, TestSize.Level0) @@ -506,6 +464,7 @@ HWTEST_F(CryptoDHAsyKeyGeneratorBySpecTest, CryptoDHAsyKeyGeneratorBySpecTest002 ASSERT_NE(returnObj, nullptr); HcfObjDestroy(returnObj); + DestroyTestDhKeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoDHAsyKeyGeneratorBySpecTest, CryptoDHAsyKeyGeneratorBySpecTest002_4, TestSize.Level0) @@ -521,6 +480,7 @@ HWTEST_F(CryptoDHAsyKeyGeneratorBySpecTest, CryptoDHAsyKeyGeneratorBySpecTest002 ASSERT_NE(returnObj, nullptr); HcfObjDestroy(returnObj); + DestroyTestDhKeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoDHAsyKeyGeneratorBySpecTest, CryptoDHAsyKeyGeneratorBySpecTest002_5, TestSize.Level0) @@ -536,6 +496,7 @@ HWTEST_F(CryptoDHAsyKeyGeneratorBySpecTest, CryptoDHAsyKeyGeneratorBySpecTest002 ASSERT_NE(returnObj, nullptr); HcfObjDestroy(returnObj); + DestroyTestDhKeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoDHAsyKeyGeneratorBySpecTest, CryptoDHAsyKeyGeneratorBySpecTest002_6, TestSize.Level0) @@ -551,6 +512,7 @@ HWTEST_F(CryptoDHAsyKeyGeneratorBySpecTest, CryptoDHAsyKeyGeneratorBySpecTest002 ASSERT_NE(returnObj, nullptr); HcfObjDestroy(returnObj); + DestroyTestDhKeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoDHAsyKeyGeneratorBySpecTest, CryptoDHAsyKeyGeneratorBySpecTest003, TestSize.Level0) @@ -569,6 +531,7 @@ HWTEST_F(CryptoDHAsyKeyGeneratorBySpecTest, CryptoDHAsyKeyGeneratorBySpecTest003 ASSERT_NE(className, NULL); HcfObjDestroy(returnObj); + DestroyTestDhKeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoDHAsyKeyGeneratorBySpecTest, CryptoDHAsyKeyGeneratorBySpecTest004, TestSize.Level0) @@ -584,6 +547,7 @@ HWTEST_F(CryptoDHAsyKeyGeneratorBySpecTest, CryptoDHAsyKeyGeneratorBySpecTest004 ASSERT_NE(returnObj, nullptr); returnObj->base.destroy(&(returnObj->base)); + DestroyTestDhKeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoDHAsyKeyGeneratorBySpecTest, CryptoDHAsyKeyGeneratorBySpecTest005, TestSize.Level0) @@ -602,6 +566,7 @@ HWTEST_F(CryptoDHAsyKeyGeneratorBySpecTest, CryptoDHAsyKeyGeneratorBySpecTest005 ASSERT_EQ(algName, g_dhAlgoName); HcfObjDestroy(returnObj); + DestroyTestDhKeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoDHAsyKeyGeneratorBySpecTest, CryptoDHAsyKeyGeneratorBySpecTest006, TestSize.Level0) @@ -622,6 +587,7 @@ HWTEST_F(CryptoDHAsyKeyGeneratorBySpecTest, CryptoDHAsyKeyGeneratorBySpecTest006 HcfObjDestroy(returnObj); HcfObjDestroy(keyPair); + DestroyTestDhKeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoDHAsyKeyGeneratorBySpecTest, CryptoDHAsyKeyGeneratorBySpecTest007, TestSize.Level0) @@ -646,6 +612,7 @@ HWTEST_F(CryptoDHAsyKeyGeneratorBySpecTest, CryptoDHAsyKeyGeneratorBySpecTest007 HcfObjDestroy(returnObj); HcfObjDestroy(keyPair); + DestroyTestDhKeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoDHAsyKeyGeneratorBySpecTest, CryptoDHAsyKeyGeneratorBySpecTest008, TestSize.Level0) @@ -667,6 +634,7 @@ HWTEST_F(CryptoDHAsyKeyGeneratorBySpecTest, CryptoDHAsyKeyGeneratorBySpecTest008 keyPair->base.destroy(&(keyPair->base)); HcfObjDestroy(returnObj); + DestroyTestDhKeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoDHAsyKeyGeneratorBySpecTest, CryptoDHAsyKeyGeneratorBySpecTest009, TestSize.Level0) @@ -691,6 +659,7 @@ HWTEST_F(CryptoDHAsyKeyGeneratorBySpecTest, CryptoDHAsyKeyGeneratorBySpecTest009 HcfObjDestroy(returnObj); HcfObjDestroy(keyPair); + DestroyTestDhKeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoDHAsyKeyGeneratorBySpecTest, CryptoDHAsyKeyGeneratorBySpecTest010, TestSize.Level0) @@ -715,6 +684,7 @@ HWTEST_F(CryptoDHAsyKeyGeneratorBySpecTest, CryptoDHAsyKeyGeneratorBySpecTest010 HcfObjDestroy(returnObj); HcfObjDestroy(keyPair); + DestroyTestDhKeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoDHAsyKeyGeneratorBySpecTest, CryptoDHAsyKeyGeneratorBySpecTest011, TestSize.Level0) @@ -749,6 +719,7 @@ HWTEST_F(CryptoDHAsyKeyGeneratorBySpecTest, CryptoDHAsyKeyGeneratorBySpecTest011 HcfObjDestroy(returnObj); HcfObjDestroy(keyPair); + DestroyTestDhKeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoDHAsyKeyGeneratorBySpecTest, CryptoDHAsyKeyGeneratorBySpecTest012, TestSize.Level0) @@ -773,6 +744,7 @@ HWTEST_F(CryptoDHAsyKeyGeneratorBySpecTest, CryptoDHAsyKeyGeneratorBySpecTest012 HcfObjDestroy(keyPair); HcfObjDestroy(returnObj); + DestroyTestDhKeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoDHAsyKeyGeneratorBySpecTest, CryptoDHAsyKeyGeneratorBySpecTest013, TestSize.Level0) @@ -797,6 +769,7 @@ HWTEST_F(CryptoDHAsyKeyGeneratorBySpecTest, CryptoDHAsyKeyGeneratorBySpecTest013 HcfObjDestroy(returnObj); HcfObjDestroy(keyPair); + DestroyTestDhKeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoDHAsyKeyGeneratorBySpecTest, CryptoDHAsyKeyGeneratorBySpecTest014, TestSize.Level0) @@ -830,6 +803,7 @@ HWTEST_F(CryptoDHAsyKeyGeneratorBySpecTest, CryptoDHAsyKeyGeneratorBySpecTest014 HcfObjDestroy(keyPair); HcfObjDestroy(returnObj); + DestroyTestDhKeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoDHAsyKeyGeneratorBySpecTest, CryptoDHAsyKeyGeneratorBySpecTest015, TestSize.Level0) @@ -858,6 +832,7 @@ HWTEST_F(CryptoDHAsyKeyGeneratorBySpecTest, CryptoDHAsyKeyGeneratorBySpecTest015 HcfFree(blob.data); HcfObjDestroy(keyPair); HcfObjDestroy(returnObj); + DestroyTestDhKeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoDHAsyKeyGeneratorBySpecTest, CryptoDHAsyKeyGeneratorBySpecTest016, TestSize.Level0) @@ -900,6 +875,7 @@ HWTEST_F(CryptoDHAsyKeyGeneratorBySpecTest, CryptoDHAsyKeyGeneratorBySpecTest016 HcfObjDestroy(pubKey); HcfObjDestroy(returnObj); + DestroyTestDhPubKeySpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoDHAsyKeyGeneratorBySpecTest, CryptoDHAsyKeyGeneratorBySpecTest017, TestSize.Level0) @@ -942,6 +918,7 @@ HWTEST_F(CryptoDHAsyKeyGeneratorBySpecTest, CryptoDHAsyKeyGeneratorBySpecTest017 HcfObjDestroy(priKey); HcfObjDestroy(returnObj); + DestroyTestDhPriKeySpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoDHAsyKeyGeneratorBySpecTest, CryptoDHAsyKeyGeneratorBySpecTest018, TestSize.Level0) @@ -971,7 +948,6 @@ HWTEST_F(CryptoDHAsyKeyGeneratorBySpecTest, CryptoDHAsyKeyGeneratorBySpecTest019 HcfAsyKeyGeneratorSpi *returnSpi = nullptr; HcfResult res = HcfAsyKeyGeneratorSpiDhCreate(¶ms, &returnSpi); - ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(returnSpi, nullptr); @@ -987,6 +963,7 @@ HWTEST_F(CryptoDHAsyKeyGeneratorBySpecTest, CryptoDHAsyKeyGeneratorBySpecTest019 HcfObjDestroy(returnSpi); HcfObjDestroy(keyPair); + DestroyTestDhKeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoDHAsyKeyGeneratorBySpecTest, CryptoDHAsyKeyGeneratorBySpecTest020, TestSize.Level0) @@ -999,7 +976,6 @@ HWTEST_F(CryptoDHAsyKeyGeneratorBySpecTest, CryptoDHAsyKeyGeneratorBySpecTest020 HcfAsyKeyGeneratorSpi *returnSpi = nullptr; HcfResult res = HcfAsyKeyGeneratorSpiDhCreate(¶ms, &returnSpi); - ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(returnSpi, nullptr); @@ -1015,6 +991,7 @@ HWTEST_F(CryptoDHAsyKeyGeneratorBySpecTest, CryptoDHAsyKeyGeneratorBySpecTest020 HcfObjDestroy(returnSpi); HcfObjDestroy(pubKey); + DestroyTestDhPubKeySpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoDHAsyKeyGeneratorBySpecTest, CryptoDHAsyKeyGeneratorBySpecTest021, TestSize.Level0) @@ -1027,7 +1004,6 @@ HWTEST_F(CryptoDHAsyKeyGeneratorBySpecTest, CryptoDHAsyKeyGeneratorBySpecTest021 HcfAsyKeyGeneratorSpi *returnSpi = nullptr; HcfResult res = HcfAsyKeyGeneratorSpiDhCreate(¶ms, &returnSpi); - ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(returnSpi, nullptr); @@ -1043,6 +1019,7 @@ HWTEST_F(CryptoDHAsyKeyGeneratorBySpecTest, CryptoDHAsyKeyGeneratorBySpecTest021 HcfObjDestroy(returnSpi); HcfObjDestroy(priKey); + DestroyTestDhPriKeySpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoDHAsyKeyGeneratorBySpecTest, CryptoDHAsyKeyGeneratorBySpecTest022, TestSize.Level0) @@ -1064,6 +1041,7 @@ HWTEST_F(CryptoDHAsyKeyGeneratorBySpecTest, CryptoDHAsyKeyGeneratorBySpecTest022 ASSERT_NE(algName2, g_dhAlgoName.data()); HcfObjDestroy(returnObj); + DestroyTestDhKeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoDHAsyKeyGeneratorBySpecTest, CryptoDHAsyKeyGeneratorBySpecTest023, TestSize.Level0) @@ -1089,6 +1067,7 @@ HWTEST_F(CryptoDHAsyKeyGeneratorBySpecTest, CryptoDHAsyKeyGeneratorBySpecTest023 HcfObjDestroy(returnObj); HcfObjDestroy(keyPair); + DestroyTestDhKeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoDHAsyKeyGeneratorBySpecTest, CryptoDHAsyKeyGeneratorBySpecTest024, TestSize.Level0) @@ -1115,6 +1094,7 @@ HWTEST_F(CryptoDHAsyKeyGeneratorBySpecTest, CryptoDHAsyKeyGeneratorBySpecTest024 ASSERT_EQ(algorithmName1, NULL); HcfObjDestroy(keyPair); HcfObjDestroy(returnObj); + DestroyTestDhKeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoDHAsyKeyGeneratorBySpecTest, CryptoDHAsyKeyGeneratorBySpecTest025, TestSize.Level0) @@ -1150,6 +1130,7 @@ HWTEST_F(CryptoDHAsyKeyGeneratorBySpecTest, CryptoDHAsyKeyGeneratorBySpecTest025 HcfFree(blob.data); HcfObjDestroy(keyPair); HcfObjDestroy(returnObj); + DestroyTestDhKeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoDHAsyKeyGeneratorBySpecTest, CryptoDHAsyKeyGeneratorBySpecTest026, TestSize.Level0) @@ -1177,6 +1158,7 @@ HWTEST_F(CryptoDHAsyKeyGeneratorBySpecTest, CryptoDHAsyKeyGeneratorBySpecTest026 HcfObjDestroy(keyPair); HcfObjDestroy(returnObj); + DestroyTestDhKeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoDHAsyKeyGeneratorBySpecTest, CryptoDHAsyKeyGeneratorBySpecTest027, TestSize.Level0) @@ -1204,6 +1186,7 @@ HWTEST_F(CryptoDHAsyKeyGeneratorBySpecTest, CryptoDHAsyKeyGeneratorBySpecTest027 HcfObjDestroy(keyPair); HcfObjDestroy(returnObj); + DestroyTestDhKeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoDHAsyKeyGeneratorBySpecTest, CryptoDHAsyKeyGeneratorBySpecTest028, TestSize.Level0) @@ -1239,6 +1222,7 @@ HWTEST_F(CryptoDHAsyKeyGeneratorBySpecTest, CryptoDHAsyKeyGeneratorBySpecTest028 HcfFree(blob.data); HcfObjDestroy(keyPair); HcfObjDestroy(returnObj); + DestroyTestDhKeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoDHAsyKeyGeneratorBySpecTest, CryptoDHAsyKeyGeneratorBySpecTest029, TestSize.Level0) @@ -1266,6 +1250,7 @@ HWTEST_F(CryptoDHAsyKeyGeneratorBySpecTest, CryptoDHAsyKeyGeneratorBySpecTest029 HcfObjDestroy(keyPair); HcfObjDestroy(returnObj); + DestroyTestDhKeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoDHAsyKeyGeneratorBySpecTest, CryptoDHAsyKeyGeneratorBySpecTest030, TestSize.Level0) @@ -1322,6 +1307,7 @@ HWTEST_F(CryptoDHAsyKeyGeneratorBySpecTest, CryptoDHAsyKeyGeneratorBySpecTest030 HcfObjDestroy(pubKey); HcfObjDestroy(returnObj); + DestroyTestDhPubKeySpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoDHAsyKeyGeneratorBySpecTest, CryptoDHAsyKeyGeneratorBySpecTest031, TestSize.Level0) @@ -1378,6 +1364,7 @@ HWTEST_F(CryptoDHAsyKeyGeneratorBySpecTest, CryptoDHAsyKeyGeneratorBySpecTest031 HcfObjDestroy(priKey); HcfObjDestroy(returnObj); + DestroyTestDhPriKeySpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoDHAsyKeyGeneratorBySpecTest, CryptoDHAsyKeyGeneratorBySpecTest032, TestSize.Level0) @@ -1414,6 +1401,7 @@ HWTEST_F(CryptoDHAsyKeyGeneratorBySpecTest, CryptoDHAsyKeyGeneratorBySpecTest033 HcfObjDestroy(returnObj); HcfObjDestroy(keyPair); + DestroyTestDhPubKeySpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoDHAsyKeyGeneratorBySpecTest, CryptoDHAsyKeyGeneratorBySpecTest034, TestSize.Level0) @@ -1440,6 +1428,7 @@ HWTEST_F(CryptoDHAsyKeyGeneratorBySpecTest, CryptoDHAsyKeyGeneratorBySpecTest034 HcfObjDestroy(returnObj); HcfObjDestroy(keyPair); + DestroyTestDhPriKeySpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoDHAsyKeyGeneratorBySpecTest, CryptoDHAsyKeyGeneratorBySpecTest035, TestSize.Level0) @@ -1452,7 +1441,6 @@ HWTEST_F(CryptoDHAsyKeyGeneratorBySpecTest, CryptoDHAsyKeyGeneratorBySpecTest035 HcfAsyKeyGeneratorSpi *returnSpi = nullptr; HcfResult res = HcfAsyKeyGeneratorSpiDhCreate(¶ms, &returnSpi); - ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(returnSpi, nullptr); @@ -1468,6 +1456,7 @@ HWTEST_F(CryptoDHAsyKeyGeneratorBySpecTest, CryptoDHAsyKeyGeneratorBySpecTest035 HcfObjDestroy(returnSpi); HcfObjDestroy(keyPair); + DestroyTestDhKeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoDHAsyKeyGeneratorBySpecTest, CryptoDHAsyKeyGeneratorBySpecTest036, TestSize.Level0) @@ -1499,7 +1488,6 @@ HWTEST_F(CryptoDHAsyKeyGeneratorBySpecTest, CryptoDHAsyKeyGeneratorBySpecTest037 HcfAsyKeyGeneratorSpi *returnSpi = nullptr; HcfResult res = HcfAsyKeyGeneratorSpiDhCreate(¶ms, &returnSpi); - ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(returnSpi, nullptr); @@ -1517,7 +1505,7 @@ HWTEST_F(CryptoDHAsyKeyGeneratorBySpecTest, CryptoDHAsyKeyGeneratorBySpecTest037 ASSERT_EQ(keyPair, nullptr); HcfAsyKeyParamsSpec *paramSpec1 = nullptr; - res = ConstructEd25519KeyPairParamsSpec(g_ed25519AlgoName, ¶mSpec1); + res = ConstructAlg25519KeyPairParamsSpec("Ed25519", true, ¶mSpec1); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec1, nullptr); @@ -1529,6 +1517,8 @@ HWTEST_F(CryptoDHAsyKeyGeneratorBySpecTest, CryptoDHAsyKeyGeneratorBySpecTest037 HcfObjDestroy(returnSpi); HcfObjDestroy(keyPair); HcfObjDestroy(keyPair1); + DestroyAlg25519KeyPairSpec(reinterpret_cast(paramSpec1)); + DestroyTestDhKeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoDHAsyKeyGeneratorBySpecTest, CryptoDHAsyKeyGeneratorBySpecTest038, TestSize.Level0) @@ -1541,7 +1531,6 @@ HWTEST_F(CryptoDHAsyKeyGeneratorBySpecTest, CryptoDHAsyKeyGeneratorBySpecTest038 HcfAsyKeyGeneratorSpi *returnSpi = nullptr; HcfResult res = HcfAsyKeyGeneratorSpiDhCreate(¶ms, &returnSpi); - ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(returnSpi, nullptr); @@ -1559,7 +1548,7 @@ HWTEST_F(CryptoDHAsyKeyGeneratorBySpecTest, CryptoDHAsyKeyGeneratorBySpecTest038 ASSERT_EQ(pubKey, nullptr); HcfAsyKeyParamsSpec *paramSpec1 = nullptr; - res = ConstructEd25519PubKeyParamsSpec(g_ed25519AlgoName, ¶mSpec1); + res = ConstructAlg25519PubKeyParamsSpec("Ed25519", true, ¶mSpec1); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec1, nullptr); @@ -1571,6 +1560,8 @@ HWTEST_F(CryptoDHAsyKeyGeneratorBySpecTest, CryptoDHAsyKeyGeneratorBySpecTest038 HcfObjDestroy(returnSpi); HcfObjDestroy(pubKey); HcfObjDestroy(pubKey1); + DestroyTestDhPubKeySpec(reinterpret_cast(paramSpec)); + DestroyAlg25519PubKeySpec(reinterpret_cast(paramSpec1)); } HWTEST_F(CryptoDHAsyKeyGeneratorBySpecTest, CryptoDHAsyKeyGeneratorBySpecTest039, TestSize.Level0) @@ -1583,7 +1574,6 @@ HWTEST_F(CryptoDHAsyKeyGeneratorBySpecTest, CryptoDHAsyKeyGeneratorBySpecTest039 HcfAsyKeyGeneratorSpi *returnSpi = nullptr; HcfResult res = HcfAsyKeyGeneratorSpiDhCreate(¶ms, &returnSpi); - ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(returnSpi, nullptr); @@ -1601,7 +1591,7 @@ HWTEST_F(CryptoDHAsyKeyGeneratorBySpecTest, CryptoDHAsyKeyGeneratorBySpecTest039 ASSERT_EQ(priKey, nullptr); HcfAsyKeyParamsSpec *paramSpec1 = nullptr; - res = ConstructEd25519PriKeyParamsSpec(g_ed25519AlgoName, ¶mSpec1); + res = ConstructAlg25519PriKeyParamsSpec("Ed25519", true, ¶mSpec1); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec1, nullptr); @@ -1613,6 +1603,8 @@ HWTEST_F(CryptoDHAsyKeyGeneratorBySpecTest, CryptoDHAsyKeyGeneratorBySpecTest039 HcfObjDestroy(returnSpi); HcfObjDestroy(priKey); HcfObjDestroy(priKey1); + DestroyTestDhPriKeySpec(reinterpret_cast(paramSpec)); + DestroyAlg25519PriKeySpec(reinterpret_cast(paramSpec1)); } HWTEST_F(CryptoDHAsyKeyGeneratorBySpecTest, CryptoDHAsyKeyGeneratorBySpecTest040, TestSize.Level0) @@ -1673,6 +1665,7 @@ HWTEST_F(CryptoDHAsyKeyGeneratorBySpecTest, CryptoDHAsyKeyGeneratorBySpecTest041 OpensslMockTestFunc(mallocCount, paramSpec); EndRecordOpensslCallNum(); + DestroyTestDhKeyPairSpec(reinterpret_cast(paramSpec)); } static void OpensslMockTestFunc1(uint32_t mallocCount, HcfDhCommParamsSpec *returnCommonParamSpec) @@ -1799,6 +1792,7 @@ HWTEST_F(CryptoDHAsyKeyGeneratorBySpecTest, CryptoDHAsyKeyGeneratorBySpecTest046 HcfObjDestroy(generator); HcfObjDestroy(priKey); HcfObjDestroy(keyPair); + DestroyTestDhPriKeySpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoDHAsyKeyGeneratorBySpecTest, CryptoDHAsyKeyGeneratorBySpecTest047, TestSize.Level0) diff --git a/test/unittest/src/crypto_dh_key_agreement_test.cpp b/test/unittest/src/crypto_dh_key_agreement_test.cpp index 4eff5a89c424d53740fa754912c8e6d22f684030..0456bf560da169cd2ed32283d50ed94c2eb9cb7f 100644 --- a/test/unittest/src/crypto_dh_key_agreement_test.cpp +++ b/test/unittest/src/crypto_dh_key_agreement_test.cpp @@ -34,6 +34,12 @@ using namespace std; using namespace testing::ext; namespace { +constexpr int SKLEN_DH128 = 128; +constexpr int SKLEN_DH512 = 512; +constexpr int SKLEN_DH1024 = 1024; +constexpr int PLEN_DH512 = 512; +constexpr int PLEN_DH2048 = 2048; + class CryptoDHKeyAgreementTest : public testing::Test { public: static void SetUpTestCase(); @@ -548,4 +554,240 @@ HWTEST_F(CryptoDHKeyAgreementTest, CryptoDHKeyAgreementTest016, TestSize.Level0) HcfFree(outBlob1.data); HcfFree(outBlob2.data); } + +HWTEST_F(CryptoDHKeyAgreementTest, CryptoDHKeyAgreementTest017, TestSize.Level0) +{ + HcfDhCommParamsSpec *returnCommonParamSpec = nullptr; + HcfResult res = HcfDhKeyUtilCreate(PLEN_DH512, SKLEN_DH128, &returnCommonParamSpec); + ASSERT_EQ(res, HCF_SUCCESS); + + HcfAsyKeyGeneratorBySpec *generator = nullptr; + res = HcfAsyKeyGeneratorBySpecCreate(reinterpret_cast(returnCommonParamSpec), &generator); + ASSERT_EQ(res, HCF_SUCCESS); + ASSERT_NE(generator, nullptr); + + HcfKeyPair *dh512KeyPair = nullptr; + res = generator->generateKeyPair(generator, &dh512KeyPair); + ASSERT_EQ(res, HCF_SUCCESS); + ASSERT_NE(dh512KeyPair, nullptr); + + HcfKeyAgreement *keyAgreement = nullptr; + res = HcfKeyAgreementCreate("DH", &keyAgreement); + ASSERT_EQ(res, HCF_SUCCESS); + ASSERT_NE(keyAgreement, nullptr); + + HcfBlob out = { .data = nullptr, .len = 0 }; + res = keyAgreement->generateSecret(keyAgreement, dh512KeyPair->priKey, dh512KeyPair->pubKey, &out); + ASSERT_EQ(res, HCF_SUCCESS); + ASSERT_NE(out.data, nullptr); + ASSERT_NE(out.len, 0); + + HcfObjDestroy(keyAgreement); + HcfObjDestroy(generator); + HcfObjDestroy(dh512KeyPair); + HcfFree(out.data); +} + +HWTEST_F(CryptoDHKeyAgreementTest, CryptoDHKeyAgreementTest018, TestSize.Level0) +{ + HcfDhCommParamsSpec *paramSpec = nullptr; + HcfResult res = HcfDhKeyUtilCreate(PLEN_DH512, SKLEN_DH128, ¶mSpec); + ASSERT_EQ(res, HCF_SUCCESS); + ASSERT_NE(paramSpec, nullptr); + + HcfAsyKeyGeneratorBySpec *generator = nullptr; + res = HcfAsyKeyGeneratorBySpecCreate(reinterpret_cast(paramSpec), &generator); + ASSERT_EQ(res, HCF_SUCCESS); + ASSERT_NE(generator, nullptr); + + HcfKeyPair *dh512KeyPair = nullptr; + res = generator->generateKeyPair(generator, &dh512KeyPair); + ASSERT_EQ(res, HCF_SUCCESS); + ASSERT_NE(dh512KeyPair, nullptr); + + HcfDhCommParamsSpec *paramSpec1 = nullptr; + res = HcfDhKeyUtilCreate(PLEN_DH512, 0, ¶mSpec1); + ASSERT_EQ(res, HCF_SUCCESS); + ASSERT_NE(paramSpec1, nullptr); + + HcfAsyKeyGeneratorBySpec *generator1 = nullptr; + res = HcfAsyKeyGeneratorBySpecCreate(reinterpret_cast(paramSpec1), &generator1); + ASSERT_EQ(res, HCF_SUCCESS); + ASSERT_NE(generator1, nullptr); + + HcfKeyPair *dh512KeyPair1 = nullptr; + res = generator1->generateKeyPair(generator1, &dh512KeyPair1); + ASSERT_EQ(res, HCF_SUCCESS); + ASSERT_NE(dh512KeyPair1, nullptr); + + HcfKeyAgreement *keyAgreement = nullptr; + res = HcfKeyAgreementCreate("DH", &keyAgreement); + ASSERT_EQ(res, HCF_SUCCESS); + ASSERT_NE(keyAgreement, nullptr); + + HcfBlob out = { .data = nullptr, .len = 0 }; + res = keyAgreement->generateSecret(keyAgreement, dh512KeyPair->priKey, dh512KeyPair1->pubKey, &out); + ASSERT_EQ(res, HCF_ERR_CRYPTO_OPERATION); + ASSERT_EQ(out.data, nullptr); + ASSERT_EQ(out.len, 0); + + HcfBlob out1 = { .data = nullptr, .len = 0 }; + res = keyAgreement->generateSecret(keyAgreement, dh512KeyPair1->priKey, dh512KeyPair->pubKey, &out1); + ASSERT_EQ(res, HCF_ERR_CRYPTO_OPERATION); + ASSERT_EQ(out1.data, nullptr); + ASSERT_EQ(out1.len, 0); + + HcfFree(out.data); + HcfFree(out1.data); + HcfObjDestroy(keyAgreement); + HcfObjDestroy(generator); + HcfObjDestroy(generator1); + HcfObjDestroy(dh512KeyPair); + HcfObjDestroy(dh512KeyPair1); +} + +HWTEST_F(CryptoDHKeyAgreementTest, CryptoDHKeyAgreementTest019, TestSize.Level0) +{ + HcfDhCommParamsSpec *returnCommonParamSpec = nullptr; + HcfResult res = HcfDhKeyUtilCreate(PLEN_DH2048, 0, &returnCommonParamSpec); + ASSERT_EQ(res, HCF_SUCCESS); + + HcfAsyKeyGeneratorBySpec *generator = nullptr; + res = HcfAsyKeyGeneratorBySpecCreate(reinterpret_cast(returnCommonParamSpec), &generator); + ASSERT_EQ(res, HCF_SUCCESS); + ASSERT_NE(generator, nullptr); + + HcfKeyPair *dh2048KeyPair = nullptr; + res = generator->generateKeyPair(generator, &dh2048KeyPair); + ASSERT_EQ(res, HCF_SUCCESS); + ASSERT_NE(dh2048KeyPair, nullptr); + + HcfKeyAgreement *keyAgreement = nullptr; + res = HcfKeyAgreementCreate("DH", &keyAgreement); + ASSERT_EQ(res, HCF_SUCCESS); + ASSERT_NE(keyAgreement, nullptr); + + HcfBlob out = { .data = nullptr, .len = 0 }; + res = keyAgreement->generateSecret(keyAgreement, dh2048KeyPair->priKey, dh2048KeyPair->pubKey, &out); + ASSERT_EQ(res, HCF_SUCCESS); + ASSERT_NE(out.data, nullptr); + ASSERT_NE(out.len, 0); + + HcfFree(out.data); + HcfObjDestroy(keyAgreement); + HcfObjDestroy(generator); + HcfObjDestroy(dh2048KeyPair); +} + +HWTEST_F(CryptoDHKeyAgreementTest, CryptoDHKeyAgreementTest020, TestSize.Level0) +{ + HcfDhCommParamsSpec *paramSpec = nullptr; + HcfResult res = HcfDhKeyUtilCreate(PLEN_DH2048, SKLEN_DH1024, ¶mSpec); + ASSERT_EQ(res, HCF_SUCCESS); + ASSERT_NE(paramSpec, nullptr); + + HcfAsyKeyGeneratorBySpec *generator = nullptr; + res = HcfAsyKeyGeneratorBySpecCreate(reinterpret_cast(paramSpec), &generator); + ASSERT_EQ(res, HCF_SUCCESS); + ASSERT_NE(generator, nullptr); + + HcfKeyPair *dh2048KeyPair = nullptr; + res = generator->generateKeyPair(generator, &dh2048KeyPair); + ASSERT_EQ(res, HCF_SUCCESS); + ASSERT_NE(dh2048KeyPair, nullptr); + + HcfDhCommParamsSpec *paramSpec1 = nullptr; + res = HcfDhKeyUtilCreate(PLEN_DH2048, SKLEN_DH512, ¶mSpec1); + ASSERT_EQ(res, HCF_SUCCESS); + ASSERT_NE(paramSpec1, nullptr); + + HcfAsyKeyGeneratorBySpec *generator1 = nullptr; + res = HcfAsyKeyGeneratorBySpecCreate(reinterpret_cast(paramSpec1), &generator1); + ASSERT_EQ(res, HCF_SUCCESS); + ASSERT_NE(generator1, nullptr); + + HcfKeyPair *dh2048KeyPair1 = nullptr; + res = generator1->generateKeyPair(generator1, &dh2048KeyPair1); + ASSERT_EQ(res, HCF_SUCCESS); + ASSERT_NE(dh2048KeyPair1, nullptr); + + HcfKeyAgreement *keyAgreement = nullptr; + res = HcfKeyAgreementCreate("DH", &keyAgreement); + ASSERT_EQ(res, HCF_SUCCESS); + ASSERT_NE(keyAgreement, nullptr); + + HcfBlob out = { .data = nullptr, .len = 0 }; + res = keyAgreement->generateSecret(keyAgreement, dh2048KeyPair->priKey, dh2048KeyPair1->pubKey, &out); + ASSERT_EQ(res, HCF_SUCCESS); + ASSERT_NE(out.data, nullptr); + ASSERT_NE(out.len, 0); + + HcfBlob out1 = { .data = nullptr, .len = 0 }; + res = keyAgreement->generateSecret(keyAgreement, dh2048KeyPair1->priKey, dh2048KeyPair->pubKey, &out1); + ASSERT_EQ(res, HCF_SUCCESS); + ASSERT_NE(out1.data, nullptr); + ASSERT_NE(out1.len, 0); + + HcfObjDestroy(keyAgreement); + HcfObjDestroy(generator); + HcfObjDestroy(generator1); + HcfObjDestroy(dh2048KeyPair); + HcfObjDestroy(dh2048KeyPair1); + HcfFree(out.data); + HcfFree(out1.data); +} + +HWTEST_F(CryptoDHKeyAgreementTest, CryptoDHKeyAgreementTest021, TestSize.Level0) +{ + HcfDhCommParamsSpec *paramSpec = nullptr; + HcfResult res = HcfDhKeyUtilCreate(PLEN_DH512, 0, ¶mSpec); + ASSERT_EQ(res, HCF_SUCCESS); + ASSERT_NE(paramSpec, nullptr); + + HcfAsyKeyGeneratorBySpec *generator = nullptr; + res = HcfAsyKeyGeneratorBySpecCreate(reinterpret_cast(paramSpec), &generator); + ASSERT_EQ(res, HCF_SUCCESS); + ASSERT_NE(generator, nullptr); + + HcfKeyPair *dh512KeyPair = nullptr; + res = generator->generateKeyPair(generator, &dh512KeyPair); + ASSERT_EQ(res, HCF_SUCCESS); + ASSERT_NE(dh512KeyPair, nullptr); + + paramSpec->length = SKLEN_DH128; + HcfAsyKeyGeneratorBySpec *generator1 = nullptr; + res = HcfAsyKeyGeneratorBySpecCreate(reinterpret_cast(paramSpec), &generator1); + ASSERT_EQ(res, HCF_SUCCESS); + ASSERT_NE(generator1, nullptr); + + HcfKeyPair *dh512KeyPair1 = nullptr; + res = generator1->generateKeyPair(generator1, &dh512KeyPair1); + ASSERT_EQ(res, HCF_SUCCESS); + ASSERT_NE(dh512KeyPair1, nullptr); + + HcfKeyAgreement *keyAgreement = nullptr; + res = HcfKeyAgreementCreate("DH", &keyAgreement); + ASSERT_EQ(res, HCF_SUCCESS); + ASSERT_NE(keyAgreement, nullptr); + + HcfBlob out = { .data = nullptr, .len = 0 }; + res = keyAgreement->generateSecret(keyAgreement, dh512KeyPair->priKey, dh512KeyPair1->pubKey, &out); + ASSERT_EQ(res, HCF_SUCCESS); + ASSERT_NE(out.data, nullptr); + ASSERT_NE(out.len, 0); + + HcfBlob out1 = { .data = nullptr, .len = 0 }; + res = keyAgreement->generateSecret(keyAgreement, dh512KeyPair1->priKey, dh512KeyPair->pubKey, &out1); + ASSERT_EQ(res, HCF_SUCCESS); + ASSERT_NE(out1.data, nullptr); + ASSERT_NE(out1.len, 0); + + HcfFree(out.data); + HcfFree(out1.data); + HcfObjDestroy(keyAgreement); + HcfObjDestroy(generator); + HcfObjDestroy(generator1); + HcfObjDestroy(dh512KeyPair); + HcfObjDestroy(dh512KeyPair1); +} } diff --git a/test/unittest/src/crypto_ecc_asy_key_generator_test.cpp b/test/unittest/src/crypto_ecc_asy_key_generator_test.cpp index a8a1ccad9f1f865fa5993d592a902ec8e9056b36..48a7b78712bb3c1e821c1f030c0b58ec7507ad7f 100644 --- a/test/unittest/src/crypto_ecc_asy_key_generator_test.cpp +++ b/test/unittest/src/crypto_ecc_asy_key_generator_test.cpp @@ -19,6 +19,7 @@ #include "asy_key_generator.h" #include "ecc_asy_key_generator_openssl.h" #include "blob.h" +#include "memory.h" #include "memory_mock.h" #include "openssl_adapter_mock.h" #include "params_parser.h" @@ -716,7 +717,7 @@ HWTEST_F(CryptoEccAsyKeyGeneratorTest, CryptoEccAsyKeyGeneratorTest315, TestSize ASSERT_NE(blob.data, nullptr); ASSERT_NE(blob.len, 0); - free(blob.data); + HcfFree(blob.data); HcfObjDestroy(keyPair); HcfObjDestroy(generator); @@ -1039,7 +1040,7 @@ HWTEST_F(CryptoEccAsyKeyGeneratorTest, CryptoEccAsyKeyGeneratorTest332, TestSize ASSERT_NE(blob.data, nullptr); ASSERT_NE(blob.len, 0); - free(blob.data); + HcfFree(blob.data); HcfObjDestroy(keyPair); HcfObjDestroy(generator); @@ -1524,7 +1525,7 @@ HWTEST_F(CryptoEccAsyKeyGeneratorTest, CryptoEccAsyKeyGeneratorTest515, TestSize ASSERT_NE(blob.data, nullptr); ASSERT_NE(blob.len, 0); - free(blob.data); + HcfFree(blob.data); HcfObjDestroy(keyPair); HcfObjDestroy(generator); @@ -1847,7 +1848,7 @@ HWTEST_F(CryptoEccAsyKeyGeneratorTest, CryptoEccAsyKeyGeneratorTest532, TestSize ASSERT_NE(blob.data, nullptr); ASSERT_NE(blob.len, 0); - free(blob.data); + HcfFree(blob.data); HcfObjDestroy(keyPair); HcfObjDestroy(generator); @@ -1957,10 +1958,10 @@ HWTEST_F(CryptoEccAsyKeyGeneratorTest, CryptoEccAsyKeyGeneratorTest536, TestSize ASSERT_NE(outPriKeyBlob.data, nullptr); ASSERT_NE(outPriKeyBlob.len, 0); - free(pubKeyBlob.data); - free(priKeyBlob.data); - free(outPubKeyBlob.data); - free(outPriKeyBlob.data); + HcfFree(pubKeyBlob.data); + HcfFree(priKeyBlob.data); + HcfFree(outPubKeyBlob.data); + HcfFree(outPriKeyBlob.data); HcfObjDestroy(outKeyPair); HcfObjDestroy(keyPair); HcfObjDestroy(generator); @@ -1999,8 +2000,8 @@ HWTEST_F(CryptoEccAsyKeyGeneratorTest, CryptoEccAsyKeyGeneratorTest537, TestSize ASSERT_NE(outPubKeyBlob.data, nullptr); ASSERT_NE(outPubKeyBlob.len, 0); - free(pubKeyBlob.data); - free(outPubKeyBlob.data); + HcfFree(pubKeyBlob.data); + HcfFree(outPubKeyBlob.data); HcfObjDestroy(outKeyPair); HcfObjDestroy(keyPair); HcfObjDestroy(generator); @@ -2039,8 +2040,8 @@ HWTEST_F(CryptoEccAsyKeyGeneratorTest, CryptoEccAsyKeyGeneratorTest538, TestSize ASSERT_NE(outPriKeyBlob.data, nullptr); ASSERT_NE(outPriKeyBlob.len, 0); - free(priKeyBlob.data); - free(outPriKeyBlob.data); + HcfFree(priKeyBlob.data); + HcfFree(outPriKeyBlob.data); HcfObjDestroy(outKeyPair); HcfObjDestroy(keyPair); HcfObjDestroy(generator); @@ -2195,15 +2196,15 @@ static void MemoryMallocTestFunc(uint32_t mallocCount) }; res = tmpKeyPair->priKey->base.getEncoded(&(tmpKeyPair->priKey->base), &tmpPriKeyBlob); if (res != HCF_SUCCESS) { - free(tmpPubKeyBlob.data); + HcfFree(tmpPubKeyBlob.data); HcfObjDestroy(tmpKeyPair); HcfObjDestroy(tmpGenerator); continue; } HcfKeyPair *tmpOutKeyPair = nullptr; res = tmpGenerator->convertKey(tmpGenerator, nullptr, &tmpPubKeyBlob, &tmpPriKeyBlob, &tmpOutKeyPair); - free(tmpPubKeyBlob.data); - free(tmpPriKeyBlob.data); + HcfFree(tmpPubKeyBlob.data); + HcfFree(tmpPriKeyBlob.data); HcfObjDestroy(tmpKeyPair); HcfObjDestroy(tmpGenerator); if (res == HCF_SUCCESS) { @@ -2241,8 +2242,8 @@ HWTEST_F(CryptoEccAsyKeyGeneratorTest, CryptoEccAsyKeyGeneratorTest701, TestSize HcfKeyPair *outKeyPair = nullptr; res = generator->convertKey(generator, nullptr, &pubKeyBlob, &priKeyBlob, &outKeyPair); - free(pubKeyBlob.data); - free(priKeyBlob.data); + HcfFree(pubKeyBlob.data); + HcfFree(priKeyBlob.data); HcfObjDestroy(outKeyPair); HcfObjDestroy(keyPair); HcfObjDestroy(generator); @@ -2285,15 +2286,15 @@ static void OpensslMockTestFunc(uint32_t mallocCount) }; res = tmpKeyPair->priKey->base.getEncoded(&(tmpKeyPair->priKey->base), &tmpPriKeyBlob); if (res != HCF_SUCCESS) { - free(tmpPubKeyBlob.data); + HcfFree(tmpPubKeyBlob.data); HcfObjDestroy(tmpKeyPair); HcfObjDestroy(tmpGenerator); continue; } HcfKeyPair *tmpOutKeyPair = nullptr; res = tmpGenerator->convertKey(tmpGenerator, nullptr, &tmpPubKeyBlob, &tmpPriKeyBlob, &tmpOutKeyPair); - free(tmpPubKeyBlob.data); - free(tmpPriKeyBlob.data); + HcfFree(tmpPubKeyBlob.data); + HcfFree(tmpPriKeyBlob.data); HcfObjDestroy(tmpKeyPair); HcfObjDestroy(tmpGenerator); if (res == HCF_SUCCESS) { @@ -2331,8 +2332,8 @@ HWTEST_F(CryptoEccAsyKeyGeneratorTest, CryptoEccAsyKeyGeneratorTest702, TestSize HcfKeyPair *outKeyPair = nullptr; res = generator->convertKey(generator, nullptr, &pubKeyBlob, &priKeyBlob, &outKeyPair); - free(pubKeyBlob.data); - free(priKeyBlob.data); + HcfFree(pubKeyBlob.data); + HcfFree(priKeyBlob.data); HcfObjDestroy(outKeyPair); HcfObjDestroy(keyPair); HcfObjDestroy(generator); diff --git a/test/unittest/src/crypto_ecc_key_agreement_by_spec_test.cpp b/test/unittest/src/crypto_ecc_key_agreement_by_spec_test.cpp index 6eb5b82f60a5c07458fc28d42e941a6973dffa10..6ec738b209f6a4fe335b0ba20487c70905fd4938 100644 --- a/test/unittest/src/crypto_ecc_key_agreement_by_spec_test.cpp +++ b/test/unittest/src/crypto_ecc_key_agreement_by_spec_test.cpp @@ -23,6 +23,7 @@ #include "ecc_common.h" #include "ecdh_openssl.h" #include "key_agreement.h" +#include "memory.h" #include "memory_mock.h" #include "openssl_adapter_mock.h" #include "openssl_common.h" @@ -436,7 +437,7 @@ HWTEST_F(CryptoEccKeyAgreementBySpecTest, CryptoEccKeyAgreementBySpecTest701, Te ASSERT_NE(out.data, nullptr); ASSERT_NE(out.len, (const unsigned int)0); - free(out.data); + HcfFree(out.data); HcfObjDestroy(keyAgreement); } @@ -455,7 +456,7 @@ HWTEST_F(CryptoEccKeyAgreementBySpecTest, CryptoEccKeyAgreementBySpecTest702, Te ASSERT_NE(out.data, nullptr); ASSERT_NE(out.len, (const unsigned int)0); - free(out.data); + HcfFree(out.data); HcfObjDestroy(keyAgreement); } @@ -474,7 +475,7 @@ HWTEST_F(CryptoEccKeyAgreementBySpecTest, CryptoEccKeyAgreementBySpecTest703, Te ASSERT_NE(out.data, nullptr); ASSERT_NE(out.len, (const unsigned int)0); - free(out.data); + HcfFree(out.data); HcfObjDestroy(keyAgreement); } @@ -493,7 +494,7 @@ HWTEST_F(CryptoEccKeyAgreementBySpecTest, CryptoEccKeyAgreementBySpecTest704, Te ASSERT_NE(out.data, nullptr); ASSERT_NE(out.len, (const unsigned int)0); - free(out.data); + HcfFree(out.data); HcfObjDestroy(keyAgreement); } @@ -728,7 +729,7 @@ HWTEST_F(CryptoEccKeyAgreementBySpecTest, CryptoEccKeyAgreementBySpecTest901, Te } HcfObjDestroy(keyAgreement); - free(out.data); + HcfFree(out.data); } EndRecordMallocNum(); } @@ -773,7 +774,7 @@ HWTEST_F(CryptoEccKeyAgreementBySpecTest, CryptoEccKeyAgreementBySpecTest902, Te } HcfObjDestroy(keyAgreement); - free(out.data); + HcfFree(out.data); } EndRecordOpensslCallNum(); } diff --git a/test/unittest/src/crypto_ecc_key_agreement_test.cpp b/test/unittest/src/crypto_ecc_key_agreement_test.cpp index 20a38366be8384d152a622a0f7d388b69a00b3b4..5f9a8e15698faa6dbf1ba22dac1027a1798c1b67 100644 --- a/test/unittest/src/crypto_ecc_key_agreement_test.cpp +++ b/test/unittest/src/crypto_ecc_key_agreement_test.cpp @@ -19,6 +19,7 @@ #include "asy_key_generator.h" #include "ecdh_openssl.h" #include "key_agreement.h" +#include "memory.h" #include "memory_mock.h" #include "openssl_adapter_mock.h" #include "params_parser.h" @@ -316,7 +317,7 @@ HWTEST_F(CryptoEccKeyAgreementTest, CryptoEccKeyAgreementTest201, TestSize.Level ASSERT_NE(out.data, nullptr); ASSERT_NE(out.len, (const unsigned int)0); - free(out.data); + HcfFree(out.data); HcfObjDestroy(keyAgreement); } @@ -335,7 +336,7 @@ HWTEST_F(CryptoEccKeyAgreementTest, CryptoEccKeyAgreementTest202, TestSize.Level ASSERT_NE(out.data, nullptr); ASSERT_NE(out.len, (const unsigned int)0); - free(out.data); + HcfFree(out.data); HcfObjDestroy(keyAgreement); } @@ -354,7 +355,7 @@ HWTEST_F(CryptoEccKeyAgreementTest, CryptoEccKeyAgreementTest203, TestSize.Level ASSERT_NE(out.data, nullptr); ASSERT_NE(out.len, (const unsigned int)0); - free(out.data); + HcfFree(out.data); HcfObjDestroy(keyAgreement); } @@ -373,7 +374,7 @@ HWTEST_F(CryptoEccKeyAgreementTest, CryptoEccKeyAgreementTest204, TestSize.Level ASSERT_NE(out.data, nullptr); ASSERT_NE(out.len, (const unsigned int)0); - free(out.data); + HcfFree(out.data); HcfObjDestroy(keyAgreement); } @@ -672,7 +673,7 @@ HWTEST_F(CryptoEccKeyAgreementTest, CryptoEccKeyAgreementTest401, TestSize.Level } HcfObjDestroy(keyAgreement); - free(out.data); + HcfFree(out.data); } EndRecordMallocNum(); } @@ -717,7 +718,7 @@ HWTEST_F(CryptoEccKeyAgreementTest, CryptoEccKeyAgreementTest402, TestSize.Level } HcfObjDestroy(keyAgreement); - free(out.data); + HcfFree(out.data); } EndRecordOpensslCallNum(); } diff --git a/test/unittest/src/crypto_ecc_key_util_test.cpp b/test/unittest/src/crypto_ecc_key_util_test.cpp index 20dedfaf98e43ea5345591a407a7bc7656b66955..efed76ce67d700a1fb4ee95e90d4042aa77912e6 100644 --- a/test/unittest/src/crypto_ecc_key_util_test.cpp +++ b/test/unittest/src/crypto_ecc_key_util_test.cpp @@ -17,8 +17,8 @@ #include #include "asy_key_generator.h" +#include "ecc_common_param_spec.h" #include "blob.h" -#include "detailed_ecc_key_params.h" #include "ecc_key_util.h" #include "ecc_openssl_common.h" #include "ecc_openssl_common_param_spec.h" @@ -39,8 +39,8 @@ using namespace testing::ext; namespace { class CryptoEccKeyUtilTest : public testing::Test { public: - static void SetUpTestCase(); - static void TearDownTestCase(); + static void SetUpTestCase() {}; + static void TearDownTestCase() {}; void SetUp(); void TearDown(); }; @@ -75,10 +75,6 @@ HcfEccCommParamsSpec *g_brainpool384t1CommSpec = nullptr; HcfEccCommParamsSpec *g_brainpool512r1CommSpec = nullptr; HcfEccCommParamsSpec *g_brainpool512t1CommSpec = nullptr; -HcfEccKeyPairParamsSpec g_brainpoolKeyPairSpec; -HcfEccPriKeyParamsSpec g_brainpool160r1PriKeySpec; -HcfEccPubKeyParamsSpec g_brainpool160r1PubKeySpec; - void CryptoEccKeyUtilTest::SetUp() {} void CryptoEccKeyUtilTest::TearDown() {} @@ -95,186 +91,13 @@ static const char *GetMockClass(void) HcfObjectBase g_obj = { .getClass = GetMockClass, - .destroy = nullptr}; - - -static HcfResult ConstructEccBrainPoolKeyPairCommParamsSpec(const string &algoName, HcfEccCommParamsSpec **spec) -{ - HcfEccCommParamsSpec *eccCommSpec = nullptr; - HcfEccKeyUtilCreate(algoName.c_str(), &eccCommSpec); - - *spec = eccCommSpec; - return HCF_SUCCESS; -} - -static HcfResult ConstructbrainpoolKeyPairParamsSpec(const string &algoName, - HcfEccCommParamsSpec *brainpoolCommSpec, HcfAsyKeyParamsSpec **spec) -{ - HcfAsyKeyGenerator *generator = nullptr; - int32_t res = HcfAsyKeyGeneratorCreate(algoName.c_str(), &generator); - - HcfKeyPair *keyPair = nullptr; - res = generator->generateKeyPair(generator, nullptr, &keyPair); - - HcfEccKeyPairParamsSpec *eccKeyPairSpec = &g_brainpoolKeyPairSpec; - HcfBigInteger retBigInt = { .data = nullptr, .len = 0 }; - - eccKeyPairSpec->base.base.algName = brainpoolCommSpec->base.algName; - eccKeyPairSpec->base.base.specType = HCF_KEY_PAIR_SPEC; - eccKeyPairSpec->base.field = brainpoolCommSpec->field; - eccKeyPairSpec->base.field->fieldType = brainpoolCommSpec->field->fieldType; - ((HcfECFieldFp *)(eccKeyPairSpec->base.field))->p.data = ((HcfECFieldFp *)(brainpoolCommSpec->field))->p.data; - ((HcfECFieldFp *)(eccKeyPairSpec->base.field))->p.len = ((HcfECFieldFp *)(brainpoolCommSpec->field))->p.len; - eccKeyPairSpec->base.a.data = brainpoolCommSpec->a.data; - eccKeyPairSpec->base.a.len = brainpoolCommSpec->a.len; - eccKeyPairSpec->base.b.data = brainpoolCommSpec->b.data; - eccKeyPairSpec->base.b.len = brainpoolCommSpec->b.len; - eccKeyPairSpec->base.g.x.data = brainpoolCommSpec->g.x.data; - eccKeyPairSpec->base.g.x.len = brainpoolCommSpec->g.x.len; - eccKeyPairSpec->base.g.y.data = brainpoolCommSpec->g.y.data; - eccKeyPairSpec->base.g.y.len = brainpoolCommSpec->g.y.len; - eccKeyPairSpec->base.n.data = brainpoolCommSpec->n.data; - eccKeyPairSpec->base.n.len = brainpoolCommSpec->n.len; - eccKeyPairSpec->base.h = brainpoolCommSpec->h; - res = keyPair->pubKey->getAsyKeySpecBigInteger(keyPair->pubKey, ECC_PK_X_BN, &retBigInt); - eccKeyPairSpec->pk.x.data = retBigInt.data; - eccKeyPairSpec->pk.x.len = retBigInt.len; - - res = keyPair->pubKey->getAsyKeySpecBigInteger(keyPair->pubKey, ECC_PK_Y_BN, &retBigInt); - eccKeyPairSpec->pk.y.data =retBigInt.data; - eccKeyPairSpec->pk.y.len = retBigInt.len; - - res = keyPair->priKey->getAsyKeySpecBigInteger(keyPair->priKey, ECC_SK_BN, &retBigInt); - eccKeyPairSpec->sk.data = retBigInt.data; - eccKeyPairSpec->sk.len = retBigInt.len; - - *spec = (HcfAsyKeyParamsSpec *)eccKeyPairSpec; - HcfObjDestroy(generator); - return HCF_SUCCESS; -} - -static HcfResult Constructbrainpool160r1PubKeyParamsSpec(const string &algoName, - HcfEccCommParamsSpec *brainpoolCommSpec, HcfAsyKeyParamsSpec **spec) -{ - HcfAsyKeyGenerator *generator = nullptr; - int32_t res = HcfAsyKeyGeneratorCreate(algoName.c_str(), &generator); - - HcfKeyPair *keyPair = nullptr; - res = generator->generateKeyPair(generator, nullptr, &keyPair); - - HcfEccPubKeyParamsSpec *eccPubKeySpec = &g_brainpool160r1PubKeySpec; - HcfBigInteger retBigInt = { .data = nullptr, .len = 0 }; - - eccPubKeySpec->base.base.algName = brainpoolCommSpec->base.algName; - eccPubKeySpec->base.base.specType = HCF_PUBLIC_KEY_SPEC; - eccPubKeySpec->base.field = brainpoolCommSpec->field; - eccPubKeySpec->base.field->fieldType = brainpoolCommSpec->field->fieldType; - ((HcfECFieldFp *)(eccPubKeySpec->base.field))->p.data = ((HcfECFieldFp *)(brainpoolCommSpec->field))->p.data; - ((HcfECFieldFp *)(eccPubKeySpec->base.field))->p.len = ((HcfECFieldFp *)(brainpoolCommSpec->field))->p.len; - eccPubKeySpec->base.a.data = brainpoolCommSpec->a.data; - eccPubKeySpec->base.a.len = brainpoolCommSpec->a.len; - eccPubKeySpec->base.b.data = brainpoolCommSpec->b.data; - eccPubKeySpec->base.b.len = brainpoolCommSpec->b.len; - eccPubKeySpec->base.g.x.data = brainpoolCommSpec->g.x.data; - eccPubKeySpec->base.g.x.len = brainpoolCommSpec->g.x.len; - eccPubKeySpec->base.g.y.data = brainpoolCommSpec->g.y.data; - eccPubKeySpec->base.g.y.len = brainpoolCommSpec->g.y.len; - eccPubKeySpec->base.n.data = brainpoolCommSpec->n.data; - eccPubKeySpec->base.n.len = brainpoolCommSpec->n.len; - eccPubKeySpec->base.h = brainpoolCommSpec->h; - res = keyPair->pubKey->getAsyKeySpecBigInteger(keyPair->pubKey, ECC_PK_X_BN, &retBigInt); - eccPubKeySpec->pk.x.data = retBigInt.data; - eccPubKeySpec->pk.x.len = retBigInt.len; - - res = keyPair->pubKey->getAsyKeySpecBigInteger(keyPair->pubKey, ECC_PK_Y_BN, &retBigInt); - eccPubKeySpec->pk.y.data =retBigInt.data; - eccPubKeySpec->pk.y.len = retBigInt.len; - - *spec = (HcfAsyKeyParamsSpec *)eccPubKeySpec; - HcfObjDestroy(generator); - return HCF_SUCCESS; -} - -static HcfResult Constructbrainpool160r1PriKeyParamsSpec(const string &algoName, - HcfEccCommParamsSpec *brainpoolCommSpec, HcfAsyKeyParamsSpec **spec) -{ - HcfAsyKeyGenerator *generator = nullptr; - int32_t res = HcfAsyKeyGeneratorCreate(algoName.c_str(), &generator); - - HcfKeyPair *keyPair = nullptr; - res = generator->generateKeyPair(generator, nullptr, &keyPair); - - HcfEccPriKeyParamsSpec *eccPriKeySpec = &g_brainpool160r1PriKeySpec; - HcfBigInteger retBigInt = { .data = nullptr, .len = 0 }; - - eccPriKeySpec->base.base.algName = brainpoolCommSpec->base.algName; - eccPriKeySpec->base.base.specType = HCF_PRIVATE_KEY_SPEC; - eccPriKeySpec->base.field = brainpoolCommSpec->field; - eccPriKeySpec->base.field->fieldType = brainpoolCommSpec->field->fieldType; - ((HcfECFieldFp *)(eccPriKeySpec->base.field))->p.data = ((HcfECFieldFp *)(brainpoolCommSpec->field))->p.data; - ((HcfECFieldFp *)(eccPriKeySpec->base.field))->p.len = ((HcfECFieldFp *)(brainpoolCommSpec->field))->p.len; - eccPriKeySpec->base.a.data = brainpoolCommSpec->a.data; - eccPriKeySpec->base.a.len = brainpoolCommSpec->a.len; - eccPriKeySpec->base.b.data = brainpoolCommSpec->b.data; - eccPriKeySpec->base.b.len = brainpoolCommSpec->b.len; - eccPriKeySpec->base.g.x.data = brainpoolCommSpec->g.x.data; - eccPriKeySpec->base.g.x.len = brainpoolCommSpec->g.x.len; - eccPriKeySpec->base.g.y.data = brainpoolCommSpec->g.y.data; - eccPriKeySpec->base.g.y.len = brainpoolCommSpec->g.y.len; - eccPriKeySpec->base.n.data = brainpoolCommSpec->n.data; - eccPriKeySpec->base.n.len = brainpoolCommSpec->n.len; - eccPriKeySpec->base.h = brainpoolCommSpec->h; - - res = keyPair->priKey->getAsyKeySpecBigInteger(keyPair->priKey, ECC_SK_BN, &retBigInt); - eccPriKeySpec->sk.data = retBigInt.data; - eccPriKeySpec->sk.len = retBigInt.len; - - *spec = (HcfAsyKeyParamsSpec *)eccPriKeySpec; - HcfObjDestroy(generator); - - return HCF_SUCCESS; -} - -void CryptoEccKeyUtilTest::SetUpTestCase() -{ - ConstructEccBrainPoolKeyPairCommParamsSpec("NID_brainpoolP160r1", &g_brainpool160r1CommSpec); - ConstructEccBrainPoolKeyPairCommParamsSpec("NID_brainpoolP160t1", &g_brainpool160t1CommSpec); - ConstructEccBrainPoolKeyPairCommParamsSpec("NID_brainpoolP192r1", &g_brainpool192r1CommSpec); - ConstructEccBrainPoolKeyPairCommParamsSpec("NID_brainpoolP192t1", &g_brainpool192t1CommSpec); - ConstructEccBrainPoolKeyPairCommParamsSpec("NID_brainpoolP224r1", &g_brainpool224r1CommSpec); - ConstructEccBrainPoolKeyPairCommParamsSpec("NID_brainpoolP224t1", &g_brainpool224t1CommSpec); - ConstructEccBrainPoolKeyPairCommParamsSpec("NID_brainpoolP256r1", &g_brainpool256r1CommSpec); - ConstructEccBrainPoolKeyPairCommParamsSpec("NID_brainpoolP256t1", &g_brainpool256t1CommSpec); - ConstructEccBrainPoolKeyPairCommParamsSpec("NID_brainpoolP320r1", &g_brainpool320r1CommSpec); - ConstructEccBrainPoolKeyPairCommParamsSpec("NID_brainpoolP320t1", &g_brainpool320t1CommSpec); - ConstructEccBrainPoolKeyPairCommParamsSpec("NID_brainpoolP384r1", &g_brainpool384r1CommSpec); - ConstructEccBrainPoolKeyPairCommParamsSpec("NID_brainpoolP384t1", &g_brainpool384t1CommSpec); - ConstructEccBrainPoolKeyPairCommParamsSpec("NID_brainpoolP512r1", &g_brainpool512r1CommSpec); - ConstructEccBrainPoolKeyPairCommParamsSpec("NID_brainpoolP512t1", &g_brainpool512t1CommSpec); -} - -void CryptoEccKeyUtilTest::TearDownTestCase() -{ - FreeEccCommParamsSpec(g_brainpool160r1CommSpec); - FreeEccCommParamsSpec(g_brainpool160t1CommSpec); - FreeEccCommParamsSpec(g_brainpool192r1CommSpec); - FreeEccCommParamsSpec(g_brainpool192t1CommSpec); - FreeEccCommParamsSpec(g_brainpool224r1CommSpec); - FreeEccCommParamsSpec(g_brainpool224t1CommSpec); - FreeEccCommParamsSpec(g_brainpool256r1CommSpec); - FreeEccCommParamsSpec(g_brainpool256t1CommSpec); - FreeEccCommParamsSpec(g_brainpool320r1CommSpec); - FreeEccCommParamsSpec(g_brainpool320t1CommSpec); - FreeEccCommParamsSpec(g_brainpool384r1CommSpec); - FreeEccCommParamsSpec(g_brainpool384t1CommSpec); - FreeEccCommParamsSpec(g_brainpool512r1CommSpec); - FreeEccCommParamsSpec(g_brainpool512t1CommSpec); -} + .destroy = nullptr +}; HWTEST_F(CryptoEccKeyUtilTest, CryptoEccKeyUtilTest001_1, TestSize.Level0) { HcfEccCommParamsSpec *returnCommonParamSpec; - int32_t res = HcfEccKeyUtilCreate("NID_brainpoolP160r1", &returnCommonParamSpec); + HcfResult res = HcfEccKeyUtilCreate("NID_brainpoolP160r1", &returnCommonParamSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(returnCommonParamSpec, nullptr); @@ -284,7 +107,7 @@ HWTEST_F(CryptoEccKeyUtilTest, CryptoEccKeyUtilTest001_1, TestSize.Level0) HWTEST_F(CryptoEccKeyUtilTest, CryptoEccKeyUtilTest001_2, TestSize.Level0) { HcfEccCommParamsSpec *returnCommonParamSpec; - int32_t res = HcfEccKeyUtilCreate("NID_brainpoolP160t1", &returnCommonParamSpec); + HcfResult res = HcfEccKeyUtilCreate("NID_brainpoolP160t1", &returnCommonParamSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(returnCommonParamSpec, nullptr); @@ -294,7 +117,7 @@ HWTEST_F(CryptoEccKeyUtilTest, CryptoEccKeyUtilTest001_2, TestSize.Level0) HWTEST_F(CryptoEccKeyUtilTest, CryptoEccKeyUtilTest001_3, TestSize.Level0) { HcfEccCommParamsSpec *returnCommonParamSpec; - int32_t res = HcfEccKeyUtilCreate("NID_brainpoolP192r1", &returnCommonParamSpec); + HcfResult res = HcfEccKeyUtilCreate("NID_brainpoolP192r1", &returnCommonParamSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(returnCommonParamSpec, nullptr); @@ -304,7 +127,7 @@ HWTEST_F(CryptoEccKeyUtilTest, CryptoEccKeyUtilTest001_3, TestSize.Level0) HWTEST_F(CryptoEccKeyUtilTest, CryptoEccKeyUtilTest001_4, TestSize.Level0) { HcfEccCommParamsSpec *returnCommonParamSpec; - int32_t res = HcfEccKeyUtilCreate("NID_brainpoolP192t1", &returnCommonParamSpec); + HcfResult res = HcfEccKeyUtilCreate("NID_brainpoolP192t1", &returnCommonParamSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(returnCommonParamSpec, nullptr); @@ -314,7 +137,7 @@ HWTEST_F(CryptoEccKeyUtilTest, CryptoEccKeyUtilTest001_4, TestSize.Level0) HWTEST_F(CryptoEccKeyUtilTest, CryptoEccKeyUtilTest001_5, TestSize.Level0) { HcfEccCommParamsSpec *returnCommonParamSpec; - int32_t res = HcfEccKeyUtilCreate("NID_brainpoolP224r1", &returnCommonParamSpec); + HcfResult res = HcfEccKeyUtilCreate("NID_brainpoolP224r1", &returnCommonParamSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(returnCommonParamSpec, nullptr); @@ -324,7 +147,7 @@ HWTEST_F(CryptoEccKeyUtilTest, CryptoEccKeyUtilTest001_5, TestSize.Level0) HWTEST_F(CryptoEccKeyUtilTest, CryptoEccKeyUtilTest001_6, TestSize.Level0) { HcfEccCommParamsSpec *returnCommonParamSpec; - int32_t res = HcfEccKeyUtilCreate("NID_brainpoolP224t1", &returnCommonParamSpec); + HcfResult res = HcfEccKeyUtilCreate("NID_brainpoolP224t1", &returnCommonParamSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(returnCommonParamSpec, nullptr); @@ -334,7 +157,7 @@ HWTEST_F(CryptoEccKeyUtilTest, CryptoEccKeyUtilTest001_6, TestSize.Level0) HWTEST_F(CryptoEccKeyUtilTest, CryptoEccKeyUtilTest001_7, TestSize.Level0) { HcfEccCommParamsSpec *returnCommonParamSpec; - int32_t res = HcfEccKeyUtilCreate("NID_brainpoolP256r1", &returnCommonParamSpec); + HcfResult res = HcfEccKeyUtilCreate("NID_brainpoolP256r1", &returnCommonParamSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(returnCommonParamSpec, nullptr); @@ -344,7 +167,7 @@ HWTEST_F(CryptoEccKeyUtilTest, CryptoEccKeyUtilTest001_7, TestSize.Level0) HWTEST_F(CryptoEccKeyUtilTest, CryptoEccKeyUtilTest001_8, TestSize.Level0) { HcfEccCommParamsSpec *returnCommonParamSpec; - int32_t res = HcfEccKeyUtilCreate("NID_brainpoolP256t1", &returnCommonParamSpec); + HcfResult res = HcfEccKeyUtilCreate("NID_brainpoolP256t1", &returnCommonParamSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(returnCommonParamSpec, nullptr); @@ -354,7 +177,7 @@ HWTEST_F(CryptoEccKeyUtilTest, CryptoEccKeyUtilTest001_8, TestSize.Level0) HWTEST_F(CryptoEccKeyUtilTest, CryptoEccKeyUtilTest001_9, TestSize.Level0) { HcfEccCommParamsSpec *returnCommonParamSpec; - int32_t res = HcfEccKeyUtilCreate("NID_brainpoolP320r1", &returnCommonParamSpec); + HcfResult res = HcfEccKeyUtilCreate("NID_brainpoolP320r1", &returnCommonParamSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(returnCommonParamSpec, nullptr); @@ -364,7 +187,7 @@ HWTEST_F(CryptoEccKeyUtilTest, CryptoEccKeyUtilTest001_9, TestSize.Level0) HWTEST_F(CryptoEccKeyUtilTest, CryptoEccKeyUtilTest001_10, TestSize.Level0) { HcfEccCommParamsSpec *returnCommonParamSpec; - int32_t res = HcfEccKeyUtilCreate("NID_brainpoolP320t1", &returnCommonParamSpec); + HcfResult res = HcfEccKeyUtilCreate("NID_brainpoolP320t1", &returnCommonParamSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(returnCommonParamSpec, nullptr); @@ -374,7 +197,7 @@ HWTEST_F(CryptoEccKeyUtilTest, CryptoEccKeyUtilTest001_10, TestSize.Level0) HWTEST_F(CryptoEccKeyUtilTest, CryptoEccKeyUtilTest001_11, TestSize.Level0) { HcfEccCommParamsSpec *returnCommonParamSpec; - int32_t res = HcfEccKeyUtilCreate("NID_brainpoolP384r1", &returnCommonParamSpec); + HcfResult res = HcfEccKeyUtilCreate("NID_brainpoolP384r1", &returnCommonParamSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(returnCommonParamSpec, nullptr); @@ -384,7 +207,7 @@ HWTEST_F(CryptoEccKeyUtilTest, CryptoEccKeyUtilTest001_11, TestSize.Level0) HWTEST_F(CryptoEccKeyUtilTest, CryptoEccKeyUtilTest001_12, TestSize.Level0) { HcfEccCommParamsSpec *returnCommonParamSpec; - int32_t res = HcfEccKeyUtilCreate("NID_brainpoolP384t1", &returnCommonParamSpec); + HcfResult res = HcfEccKeyUtilCreate("NID_brainpoolP384t1", &returnCommonParamSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(returnCommonParamSpec, nullptr); @@ -394,7 +217,7 @@ HWTEST_F(CryptoEccKeyUtilTest, CryptoEccKeyUtilTest001_12, TestSize.Level0) HWTEST_F(CryptoEccKeyUtilTest, CryptoEccKeyUtilTest001_13, TestSize.Level0) { HcfEccCommParamsSpec *returnCommonParamSpec; - int32_t res = HcfEccKeyUtilCreate("NID_brainpoolP512r1", &returnCommonParamSpec); + HcfResult res = HcfEccKeyUtilCreate("NID_brainpoolP512r1", &returnCommonParamSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(returnCommonParamSpec, nullptr); @@ -404,7 +227,7 @@ HWTEST_F(CryptoEccKeyUtilTest, CryptoEccKeyUtilTest001_13, TestSize.Level0) HWTEST_F(CryptoEccKeyUtilTest, CryptoEccKeyUtilTest001_14, TestSize.Level0) { HcfEccCommParamsSpec *returnCommonParamSpec; - int32_t res = HcfEccKeyUtilCreate("NID_brainpoolP512t1", &returnCommonParamSpec); + HcfResult res = HcfEccKeyUtilCreate("NID_brainpoolP512t1", &returnCommonParamSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(returnCommonParamSpec, nullptr); @@ -414,7 +237,7 @@ HWTEST_F(CryptoEccKeyUtilTest, CryptoEccKeyUtilTest001_14, TestSize.Level0) HWTEST_F(CryptoEccKeyUtilTest, CryptoEccKeyUtilTest001_15, TestSize.Level0) { HcfEccCommParamsSpec *returnCommonParamSpec; - int32_t res = HcfEccKeyUtilCreate("NID_secp224r1", &returnCommonParamSpec); + HcfResult res = HcfEccKeyUtilCreate("NID_secp224r1", &returnCommonParamSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(returnCommonParamSpec, nullptr); @@ -424,7 +247,7 @@ HWTEST_F(CryptoEccKeyUtilTest, CryptoEccKeyUtilTest001_15, TestSize.Level0) HWTEST_F(CryptoEccKeyUtilTest, CryptoEccKeyUtilTest001_16, TestSize.Level0) { HcfEccCommParamsSpec *returnCommonParamSpec; - int32_t res = HcfEccKeyUtilCreate("NID_X9_62_prime256v1", &returnCommonParamSpec); + HcfResult res = HcfEccKeyUtilCreate("NID_X9_62_prime256v1", &returnCommonParamSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(returnCommonParamSpec, nullptr); @@ -434,7 +257,7 @@ HWTEST_F(CryptoEccKeyUtilTest, CryptoEccKeyUtilTest001_16, TestSize.Level0) HWTEST_F(CryptoEccKeyUtilTest, CryptoEccKeyUtilTest001_17, TestSize.Level0) { HcfEccCommParamsSpec *returnCommonParamSpec; - int32_t res = HcfEccKeyUtilCreate("NID_secp384r1", &returnCommonParamSpec); + HcfResult res = HcfEccKeyUtilCreate("NID_secp384r1", &returnCommonParamSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(returnCommonParamSpec, nullptr); @@ -444,7 +267,7 @@ HWTEST_F(CryptoEccKeyUtilTest, CryptoEccKeyUtilTest001_17, TestSize.Level0) HWTEST_F(CryptoEccKeyUtilTest, CryptoEccKeyUtilTest001_18, TestSize.Level0) { HcfEccCommParamsSpec *returnCommonParamSpec; - int32_t res = HcfEccKeyUtilCreate("NID_secp521r1", &returnCommonParamSpec); + HcfResult res = HcfEccKeyUtilCreate("NID_secp521r1", &returnCommonParamSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(returnCommonParamSpec, nullptr); @@ -454,7 +277,7 @@ HWTEST_F(CryptoEccKeyUtilTest, CryptoEccKeyUtilTest001_18, TestSize.Level0) HWTEST_F(CryptoEccKeyUtilTest, CryptoEccKeyUtilTest001_19, TestSize.Level0) { HcfEccCommParamsSpec *returnCommonParamSpec; - int32_t res = HcfEccKeyUtilCreate("NID_sm2", &returnCommonParamSpec); + HcfResult res = HcfEccKeyUtilCreate("NID_sm2", &returnCommonParamSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(returnCommonParamSpec, nullptr); @@ -464,7 +287,7 @@ HWTEST_F(CryptoEccKeyUtilTest, CryptoEccKeyUtilTest001_19, TestSize.Level0) HWTEST_F(CryptoEccKeyUtilTest, CryptoEccKeyUtilTest002, TestSize.Level0) { HcfEccCommParamsSpec *returnCommonParamSpec; - int32_t res = HcfEccKeyUtilCreate(nullptr, &returnCommonParamSpec); + HcfResult res = HcfEccKeyUtilCreate(nullptr, &returnCommonParamSpec); ASSERT_NE(res, HCF_SUCCESS); ASSERT_EQ(returnCommonParamSpec, nullptr); @@ -473,14 +296,14 @@ HWTEST_F(CryptoEccKeyUtilTest, CryptoEccKeyUtilTest002, TestSize.Level0) HWTEST_F(CryptoEccKeyUtilTest, CryptoEccKeyUtilTest003, TestSize.Level0) { - int32_t res = HcfEccKeyUtilCreate("ECC_BrainPoolP160r1", nullptr); + HcfResult res = HcfEccKeyUtilCreate("ECC_BrainPoolP160r1", nullptr); ASSERT_NE(res, HCF_SUCCESS); } HWTEST_F(CryptoEccKeyUtilTest, CryptoEccKeyUtilTest004, TestSize.Level0) { HcfEccCommParamsSpec *returnCommonParamSpec; - int32_t res = HcfEccKeyUtilCreate("BrainPoolP999", &returnCommonParamSpec); + HcfResult res = HcfEccKeyUtilCreate("BrainPoolP999", &returnCommonParamSpec); ASSERT_NE(res, HCF_SUCCESS); ASSERT_EQ(returnCommonParamSpec, nullptr); @@ -489,8 +312,11 @@ HWTEST_F(CryptoEccKeyUtilTest, CryptoEccKeyUtilTest004, TestSize.Level0) HWTEST_F(CryptoEccKeyUtilTest, CryptoEccKeyUtilTest005, TestSize.Level0) { + ConstructEccKeyPairCommParamsSpec("NID_brainpoolP160r1", &g_brainpool160r1CommSpec); + ASSERT_NE(g_brainpool160r1CommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - int32_t res = ConstructbrainpoolKeyPairParamsSpec(g_brainpool160r1AlgName, g_brainpool160r1CommSpec, ¶mSpec); + HcfResult res = ConstructEccKeyPairParamsSpec(g_brainpool160r1AlgName.c_str(), + g_brainpool160r1CommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); @@ -504,12 +330,16 @@ HWTEST_F(CryptoEccKeyUtilTest, CryptoEccKeyUtilTest005, TestSize.Level0) ASSERT_NE(classname, nullptr); HcfObjDestroy(returnObj); + DestroyEccKeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoEccKeyUtilTest, CryptoEccKeyUtilTest006, TestSize.Level0) { + ConstructEccKeyPairCommParamsSpec("NID_brainpoolP160r1", &g_brainpool160r1CommSpec); + ASSERT_NE(g_brainpool160r1CommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - int32_t res = ConstructbrainpoolKeyPairParamsSpec(g_brainpool160r1AlgName, g_brainpool160r1CommSpec, ¶mSpec); + HcfResult res = ConstructEccKeyPairParamsSpec(g_brainpool160r1AlgName.c_str(), + g_brainpool160r1CommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); @@ -519,14 +349,17 @@ HWTEST_F(CryptoEccKeyUtilTest, CryptoEccKeyUtilTest006, TestSize.Level0) ASSERT_NE(returnObj, nullptr); returnObj->base.destroy(&g_obj); - HcfObjDestroy(returnObj); + DestroyEccKeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoEccKeyUtilTest, CryptoEccKeyUtilTest007, TestSize.Level0) { + ConstructEccKeyPairCommParamsSpec("NID_brainpoolP160r1", &g_brainpool160r1CommSpec); + ASSERT_NE(g_brainpool160r1CommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - int32_t res = ConstructbrainpoolKeyPairParamsSpec(g_brainpool160r1AlgName, g_brainpool160r1CommSpec, ¶mSpec); + HcfResult res = ConstructEccKeyPairParamsSpec(g_brainpool160r1AlgName.c_str(), + g_brainpool160r1CommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); @@ -537,14 +370,17 @@ HWTEST_F(CryptoEccKeyUtilTest, CryptoEccKeyUtilTest007, TestSize.Level0) const char *algName = returnObj->getAlgName(returnObj); ASSERT_NE(algName, nullptr); - HcfObjDestroy(returnObj); + DestroyEccKeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoEccKeyUtilTest, CryptoEccKeyUtilTest008, TestSize.Level0) { + ConstructEccKeyPairCommParamsSpec("NID_brainpoolP160r1", &g_brainpool160r1CommSpec); + ASSERT_NE(g_brainpool160r1CommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - int32_t res = ConstructbrainpoolKeyPairParamsSpec(g_brainpool160r1AlgName, g_brainpool160r1CommSpec, ¶mSpec); + HcfResult res = ConstructEccKeyPairParamsSpec(g_brainpool160r1AlgName.c_str(), + g_brainpool160r1CommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); @@ -559,12 +395,17 @@ HWTEST_F(CryptoEccKeyUtilTest, CryptoEccKeyUtilTest008, TestSize.Level0) ASSERT_NE(returnKeyPair, nullptr); HcfObjDestroy(returnObj); + HcfObjDestroy(returnKeyPair); + DestroyEccKeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoEccKeyUtilTest, CryptoEccKeyUtilTest009, TestSize.Level0) { + ConstructEccKeyPairCommParamsSpec("NID_brainpoolP160r1", &g_brainpool160r1CommSpec); + ASSERT_NE(g_brainpool160r1CommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - int32_t res = ConstructbrainpoolKeyPairParamsSpec(g_brainpool160r1AlgName, g_brainpool160r1CommSpec, ¶mSpec); + HcfResult res = ConstructEccKeyPairParamsSpec(g_brainpool160r1AlgName.c_str(), + g_brainpool160r1CommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); @@ -582,12 +423,16 @@ HWTEST_F(CryptoEccKeyUtilTest, CryptoEccKeyUtilTest009, TestSize.Level0) HcfObjDestroy(returnKeyPair); HcfObjDestroy(returnObj); + DestroyEccKeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoEccKeyUtilTest, CryptoEccKeyUtilTest010, TestSize.Level0) { + ConstructEccKeyPairCommParamsSpec("NID_brainpoolP160r1", &g_brainpool160r1CommSpec); + ASSERT_NE(g_brainpool160r1CommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - int32_t res = ConstructbrainpoolKeyPairParamsSpec(g_brainpool160r1AlgName, g_brainpool160r1CommSpec, ¶mSpec); + HcfResult res = ConstructEccKeyPairParamsSpec(g_brainpool160r1AlgName.c_str(), + g_brainpool160r1CommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); @@ -603,12 +448,16 @@ HWTEST_F(CryptoEccKeyUtilTest, CryptoEccKeyUtilTest010, TestSize.Level0) returnKeyPair->base.destroy(&(returnKeyPair->base)); HcfObjDestroy(returnObj); + DestroyEccKeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoEccKeyUtilTest, CryptoEccKeyUtilTest011, TestSize.Level0) { + ConstructEccKeyPairCommParamsSpec("NID_brainpoolP160r1", &g_brainpool160r1CommSpec); + ASSERT_NE(g_brainpool160r1CommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - int32_t res = ConstructbrainpoolKeyPairParamsSpec(g_brainpool160r1AlgName, g_brainpool160r1CommSpec, ¶mSpec); + HcfResult res = ConstructEccKeyPairParamsSpec(g_brainpool160r1AlgName.c_str(), + g_brainpool160r1CommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); @@ -625,12 +474,16 @@ HWTEST_F(CryptoEccKeyUtilTest, CryptoEccKeyUtilTest011, TestSize.Level0) returnKeyPair->base.destroy(nullptr); HcfObjDestroy(returnKeyPair); HcfObjDestroy(returnObj); + DestroyEccKeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoEccKeyUtilTest, CryptoEccKeyUtilTest012, TestSize.Level0) { + ConstructEccKeyPairCommParamsSpec("NID_brainpoolP160r1", &g_brainpool160r1CommSpec); + ASSERT_NE(g_brainpool160r1CommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - int32_t res = ConstructbrainpoolKeyPairParamsSpec(g_brainpool160r1AlgName, g_brainpool160r1CommSpec, ¶mSpec); + HcfResult res = ConstructEccKeyPairParamsSpec(g_brainpool160r1AlgName.c_str(), + g_brainpool160r1CommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); @@ -647,12 +500,16 @@ HWTEST_F(CryptoEccKeyUtilTest, CryptoEccKeyUtilTest012, TestSize.Level0) returnKeyPair->base.destroy(&g_obj); HcfObjDestroy(returnKeyPair); HcfObjDestroy(returnObj); + DestroyEccKeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoEccKeyUtilTest, CryptoEccKeyUtilTest013, TestSize.Level0) { + ConstructEccKeyPairCommParamsSpec("NID_brainpoolP160r1", &g_brainpool160r1CommSpec); + ASSERT_NE(g_brainpool160r1CommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - int32_t res = ConstructbrainpoolKeyPairParamsSpec(g_brainpool160r1AlgName, g_brainpool160r1CommSpec, ¶mSpec); + HcfResult res = ConstructEccKeyPairParamsSpec(g_brainpool160r1AlgName.c_str(), + g_brainpool160r1CommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); @@ -670,12 +527,16 @@ HWTEST_F(CryptoEccKeyUtilTest, CryptoEccKeyUtilTest013, TestSize.Level0) HcfObjDestroy(returnKeyPair); HcfObjDestroy(returnObj); + DestroyEccKeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoEccKeyUtilTest, CryptoEccKeyUtilTest014, TestSize.Level0) { + ConstructEccKeyPairCommParamsSpec("NID_brainpoolP160r1", &g_brainpool160r1CommSpec); + ASSERT_NE(g_brainpool160r1CommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - int32_t res = ConstructbrainpoolKeyPairParamsSpec(g_brainpool160r1AlgName, g_brainpool160r1CommSpec, ¶mSpec); + HcfResult res = ConstructEccKeyPairParamsSpec(g_brainpool160r1AlgName.c_str(), + g_brainpool160r1CommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); @@ -693,12 +554,16 @@ HWTEST_F(CryptoEccKeyUtilTest, CryptoEccKeyUtilTest014, TestSize.Level0) returnKeyPair->pubKey = nullptr; HcfObjDestroy(returnKeyPair); HcfObjDestroy(returnObj); + DestroyEccKeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoEccKeyUtilTest, CryptoEccKeyUtilTest015, TestSize.Level0) { + ConstructEccKeyPairCommParamsSpec("NID_brainpoolP160r1", &g_brainpool160r1CommSpec); + ASSERT_NE(g_brainpool160r1CommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - int32_t res = ConstructbrainpoolKeyPairParamsSpec(g_brainpool160r1AlgName, g_brainpool160r1CommSpec, ¶mSpec); + HcfResult res = ConstructEccKeyPairParamsSpec(g_brainpool160r1AlgName.c_str(), + g_brainpool160r1CommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); @@ -716,12 +581,16 @@ HWTEST_F(CryptoEccKeyUtilTest, CryptoEccKeyUtilTest015, TestSize.Level0) returnKeyPair->pubKey = nullptr; HcfObjDestroy(returnKeyPair); HcfObjDestroy(returnObj); + DestroyEccKeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoEccKeyUtilTest, CryptoEccKeyUtilTest016, TestSize.Level0) { + ConstructEccKeyPairCommParamsSpec("NID_brainpoolP160r1", &g_brainpool160r1CommSpec); + ASSERT_NE(g_brainpool160r1CommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - int32_t res = ConstructbrainpoolKeyPairParamsSpec(g_brainpool160r1AlgName, g_brainpool160r1CommSpec, ¶mSpec); + HcfResult res = ConstructEccKeyPairParamsSpec(g_brainpool160r1AlgName.c_str(), + g_brainpool160r1CommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); @@ -738,12 +607,16 @@ HWTEST_F(CryptoEccKeyUtilTest, CryptoEccKeyUtilTest016, TestSize.Level0) returnKeyPair->pubKey->base.base.destroy(&g_obj); HcfObjDestroy(returnKeyPair); HcfObjDestroy(returnObj); + DestroyEccKeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoEccKeyUtilTest, CryptoEccKeyUtilTest017, TestSize.Level0) { + ConstructEccKeyPairCommParamsSpec("NID_brainpoolP160r1", &g_brainpool160r1CommSpec); + ASSERT_NE(g_brainpool160r1CommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - int32_t res = ConstructbrainpoolKeyPairParamsSpec(g_brainpool160r1AlgName, g_brainpool160r1CommSpec, ¶mSpec); + HcfResult res = ConstructEccKeyPairParamsSpec(g_brainpool160r1AlgName.c_str(), + g_brainpool160r1CommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); @@ -761,12 +634,16 @@ HWTEST_F(CryptoEccKeyUtilTest, CryptoEccKeyUtilTest017, TestSize.Level0) HcfObjDestroy(returnKeyPair); HcfObjDestroy(returnObj); + DestroyEccKeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoEccKeyUtilTest, CryptoEccKeyUtilTest018, TestSize.Level0) { + ConstructEccKeyPairCommParamsSpec("NID_brainpoolP160r1", &g_brainpool160r1CommSpec); + ASSERT_NE(g_brainpool160r1CommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - int32_t res = ConstructbrainpoolKeyPairParamsSpec(g_brainpool160r1AlgName, g_brainpool160r1CommSpec, ¶mSpec); + HcfResult res = ConstructEccKeyPairParamsSpec(g_brainpool160r1AlgName.c_str(), + g_brainpool160r1CommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); @@ -784,12 +661,16 @@ HWTEST_F(CryptoEccKeyUtilTest, CryptoEccKeyUtilTest018, TestSize.Level0) HcfObjDestroy(returnKeyPair); HcfObjDestroy(returnObj); + DestroyEccKeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoEccKeyUtilTest, CryptoEccKeyUtilTest019, TestSize.Level0) { + ConstructEccKeyPairCommParamsSpec("NID_brainpoolP160r1", &g_brainpool160r1CommSpec); + ASSERT_NE(g_brainpool160r1CommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - int32_t res = ConstructbrainpoolKeyPairParamsSpec(g_brainpool160r1AlgName, g_brainpool160r1CommSpec, ¶mSpec); + HcfResult res = ConstructEccKeyPairParamsSpec(g_brainpool160r1AlgName.c_str(), + g_brainpool160r1CommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); @@ -807,12 +688,17 @@ HWTEST_F(CryptoEccKeyUtilTest, CryptoEccKeyUtilTest019, TestSize.Level0) HcfObjDestroy(returnKeyPair); HcfObjDestroy(returnObj); + HcfBlobDataFree(&pubKeyBlob); + DestroyEccKeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoEccKeyUtilTest, CryptoEccKeyUtilTest020, TestSize.Level0) { + ConstructEccKeyPairCommParamsSpec("NID_brainpoolP160r1", &g_brainpool160r1CommSpec); + ASSERT_NE(g_brainpool160r1CommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - int32_t res = ConstructbrainpoolKeyPairParamsSpec(g_brainpool160r1AlgName, g_brainpool160r1CommSpec, ¶mSpec); + HcfResult res = ConstructEccKeyPairParamsSpec(g_brainpool160r1AlgName.c_str(), + g_brainpool160r1CommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); @@ -829,12 +715,16 @@ HWTEST_F(CryptoEccKeyUtilTest, CryptoEccKeyUtilTest020, TestSize.Level0) HcfObjDestroy(returnKeyPair); HcfObjDestroy(returnObj); + DestroyEccKeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoEccKeyUtilTest, CryptoEccKeyUtilTest021, TestSize.Level0) { + ConstructEccKeyPairCommParamsSpec("NID_brainpoolP160r1", &g_brainpool160r1CommSpec); + ASSERT_NE(g_brainpool160r1CommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - int32_t res = ConstructbrainpoolKeyPairParamsSpec(g_brainpool160r1AlgName, g_brainpool160r1CommSpec, ¶mSpec); + HcfResult res = ConstructEccKeyPairParamsSpec(g_brainpool160r1AlgName.c_str(), + g_brainpool160r1CommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); @@ -851,12 +741,16 @@ HWTEST_F(CryptoEccKeyUtilTest, CryptoEccKeyUtilTest021, TestSize.Level0) HcfObjDestroy(returnKeyPair); HcfObjDestroy(returnObj); + DestroyEccKeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoEccKeyUtilTest, CryptoEccKeyUtilTest022, TestSize.Level0) { + ConstructEccKeyPairCommParamsSpec("NID_brainpoolP160r1", &g_brainpool160r1CommSpec); + ASSERT_NE(g_brainpool160r1CommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - int32_t res = ConstructbrainpoolKeyPairParamsSpec(g_brainpool160r1AlgName, g_brainpool160r1CommSpec, ¶mSpec); + HcfResult res = ConstructEccKeyPairParamsSpec(g_brainpool160r1AlgName.c_str(), + g_brainpool160r1CommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); @@ -873,12 +767,16 @@ HWTEST_F(CryptoEccKeyUtilTest, CryptoEccKeyUtilTest022, TestSize.Level0) HcfObjDestroy(returnKeyPair); HcfObjDestroy(returnObj); + DestroyEccKeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoEccKeyUtilTest, CryptoEccKeyUtilTest023, TestSize.Level0) { + ConstructEccKeyPairCommParamsSpec("NID_brainpoolP160r1", &g_brainpool160r1CommSpec); + ASSERT_NE(g_brainpool160r1CommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - int32_t res = ConstructbrainpoolKeyPairParamsSpec(g_brainpool160r1AlgName, g_brainpool160r1CommSpec, ¶mSpec); + HcfResult res = ConstructEccKeyPairParamsSpec(g_brainpool160r1AlgName.c_str(), + g_brainpool160r1CommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); @@ -896,12 +794,16 @@ HWTEST_F(CryptoEccKeyUtilTest, CryptoEccKeyUtilTest023, TestSize.Level0) HcfObjDestroy(returnKeyPair); HcfObjDestroy(returnObj); + DestroyEccKeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoEccKeyUtilTest, CryptoEccKeyUtilTest024, TestSize.Level0) { + ConstructEccKeyPairCommParamsSpec("NID_brainpoolP160r1", &g_brainpool160r1CommSpec); + ASSERT_NE(g_brainpool160r1CommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - int32_t res = ConstructbrainpoolKeyPairParamsSpec(g_brainpool160r1AlgName, g_brainpool160r1CommSpec, ¶mSpec); + HcfResult res = ConstructEccKeyPairParamsSpec(g_brainpool160r1AlgName.c_str(), + g_brainpool160r1CommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); @@ -919,12 +821,16 @@ HWTEST_F(CryptoEccKeyUtilTest, CryptoEccKeyUtilTest024, TestSize.Level0) returnKeyPair->priKey = nullptr; HcfObjDestroy(returnKeyPair); HcfObjDestroy(returnObj); + DestroyEccKeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoEccKeyUtilTest, CryptoEccKeyUtilTest025, TestSize.Level0) { + ConstructEccKeyPairCommParamsSpec("NID_brainpoolP160r1", &g_brainpool160r1CommSpec); + ASSERT_NE(g_brainpool160r1CommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - int32_t res = ConstructbrainpoolKeyPairParamsSpec(g_brainpool160r1AlgName, g_brainpool160r1CommSpec, ¶mSpec); + HcfResult res = ConstructEccKeyPairParamsSpec(g_brainpool160r1AlgName.c_str(), + g_brainpool160r1CommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); @@ -942,12 +848,16 @@ HWTEST_F(CryptoEccKeyUtilTest, CryptoEccKeyUtilTest025, TestSize.Level0) returnKeyPair->priKey = nullptr; HcfObjDestroy(returnKeyPair); HcfObjDestroy(returnObj); + DestroyEccKeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoEccKeyUtilTest, CryptoEccKeyUtilTest026, TestSize.Level0) { + ConstructEccKeyPairCommParamsSpec("NID_brainpoolP160r1", &g_brainpool160r1CommSpec); + ASSERT_NE(g_brainpool160r1CommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - int32_t res = ConstructbrainpoolKeyPairParamsSpec(g_brainpool160r1AlgName, g_brainpool160r1CommSpec, ¶mSpec); + HcfResult res = ConstructEccKeyPairParamsSpec(g_brainpool160r1AlgName.c_str(), + g_brainpool160r1CommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); @@ -965,12 +875,16 @@ HWTEST_F(CryptoEccKeyUtilTest, CryptoEccKeyUtilTest026, TestSize.Level0) returnKeyPair->priKey = nullptr; HcfObjDestroy(returnKeyPair); HcfObjDestroy(returnObj); + DestroyEccKeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoEccKeyUtilTest, CryptoEccKeyUtilTest027, TestSize.Level0) { + ConstructEccKeyPairCommParamsSpec("NID_brainpoolP160r1", &g_brainpool160r1CommSpec); + ASSERT_NE(g_brainpool160r1CommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - int32_t res = ConstructbrainpoolKeyPairParamsSpec(g_brainpool160r1AlgName, g_brainpool160r1CommSpec, ¶mSpec); + HcfResult res = ConstructEccKeyPairParamsSpec(g_brainpool160r1AlgName.c_str(), + g_brainpool160r1CommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); @@ -988,12 +902,16 @@ HWTEST_F(CryptoEccKeyUtilTest, CryptoEccKeyUtilTest027, TestSize.Level0) HcfObjDestroy(returnKeyPair); HcfObjDestroy(returnObj); + DestroyEccKeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoEccKeyUtilTest, CryptoEccKeyUtilTest028, TestSize.Level0) { + ConstructEccKeyPairCommParamsSpec("NID_brainpoolP160r1", &g_brainpool160r1CommSpec); + ASSERT_NE(g_brainpool160r1CommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - int32_t res = ConstructbrainpoolKeyPairParamsSpec(g_brainpool160r1AlgName, g_brainpool160r1CommSpec, ¶mSpec); + HcfResult res = ConstructEccKeyPairParamsSpec(g_brainpool160r1AlgName.c_str(), + g_brainpool160r1CommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); @@ -1011,12 +929,16 @@ HWTEST_F(CryptoEccKeyUtilTest, CryptoEccKeyUtilTest028, TestSize.Level0) HcfObjDestroy(returnKeyPair); HcfObjDestroy(returnObj); + DestroyEccKeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoEccKeyUtilTest, CryptoEccKeyUtilTest029, TestSize.Level0) { + ConstructEccKeyPairCommParamsSpec("NID_brainpoolP160r1", &g_brainpool160r1CommSpec); + ASSERT_NE(g_brainpool160r1CommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - int32_t res = ConstructbrainpoolKeyPairParamsSpec(g_brainpool160r1AlgName, g_brainpool160r1CommSpec, ¶mSpec); + HcfResult res = ConstructEccKeyPairParamsSpec(g_brainpool160r1AlgName.c_str(), + g_brainpool160r1CommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); @@ -1034,12 +956,16 @@ HWTEST_F(CryptoEccKeyUtilTest, CryptoEccKeyUtilTest029, TestSize.Level0) HcfObjDestroy(returnKeyPair); HcfObjDestroy(returnObj); + HcfBlobDataFree(&priKeyBlob); + DestroyEccKeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoEccKeyUtilTest, CryptoEccKeyUtilTest030, TestSize.Level0) { + ConstructEccKeyPairCommParamsSpec("NID_brainpoolP160r1", &g_brainpool160r1CommSpec); + ASSERT_NE(g_brainpool160r1CommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - int32_t res = Constructbrainpool160r1PubKeyParamsSpec(g_brainpool160r1AlgName, g_brainpool160r1CommSpec, + HcfResult res = ConstructEccPubKeyParamsSpec(g_brainpool160r1AlgName.c_str(), g_brainpool160r1CommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); @@ -1056,12 +982,15 @@ HWTEST_F(CryptoEccKeyUtilTest, CryptoEccKeyUtilTest030, TestSize.Level0) HcfObjDestroy(returnPubKey); HcfObjDestroy(returnObj); + DestroyEccPubKeySpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoEccKeyUtilTest, CryptoEccKeyUtilTest031, TestSize.Level0) { + ConstructEccKeyPairCommParamsSpec("NID_brainpoolP160r1", &g_brainpool160r1CommSpec); + ASSERT_NE(g_brainpool160r1CommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - int32_t res = Constructbrainpool160r1PubKeyParamsSpec(g_brainpool160r1AlgName, g_brainpool160r1CommSpec, + HcfResult res = ConstructEccPubKeyParamsSpec(g_brainpool160r1AlgName.c_str(), g_brainpool160r1CommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); @@ -1078,12 +1007,15 @@ HWTEST_F(CryptoEccKeyUtilTest, CryptoEccKeyUtilTest031, TestSize.Level0) returnPubKey->base.base.destroy(&(returnPubKey->base.base)); HcfObjDestroy(returnObj); + DestroyEccPubKeySpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoEccKeyUtilTest, CryptoEccKeyUtilTest032, TestSize.Level0) { + ConstructEccKeyPairCommParamsSpec("NID_brainpoolP160r1", &g_brainpool160r1CommSpec); + ASSERT_NE(g_brainpool160r1CommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - int32_t res = Constructbrainpool160r1PubKeyParamsSpec(g_brainpool160r1AlgName, g_brainpool160r1CommSpec, + HcfResult res = ConstructEccPubKeyParamsSpec(g_brainpool160r1AlgName.c_str(), g_brainpool160r1CommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); @@ -1101,12 +1033,15 @@ HWTEST_F(CryptoEccKeyUtilTest, CryptoEccKeyUtilTest032, TestSize.Level0) HcfObjDestroy(returnPubKey); HcfObjDestroy(returnObj); + DestroyEccPubKeySpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoEccKeyUtilTest, CryptoEccKeyUtilTest033, TestSize.Level0) { + ConstructEccKeyPairCommParamsSpec("NID_brainpoolP160r1", &g_brainpool160r1CommSpec); + ASSERT_NE(g_brainpool160r1CommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - int32_t res = Constructbrainpool160r1PubKeyParamsSpec(g_brainpool160r1AlgName, g_brainpool160r1CommSpec, + HcfResult res = ConstructEccPubKeyParamsSpec(g_brainpool160r1AlgName.c_str(), g_brainpool160r1CommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); @@ -1124,12 +1059,15 @@ HWTEST_F(CryptoEccKeyUtilTest, CryptoEccKeyUtilTest033, TestSize.Level0) HcfObjDestroy(returnPubKey); HcfObjDestroy(returnObj); + DestroyEccPubKeySpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoEccKeyUtilTest, CryptoEccKeyUtilTest034, TestSize.Level0) { + ConstructEccKeyPairCommParamsSpec("NID_brainpoolP160r1", &g_brainpool160r1CommSpec); + ASSERT_NE(g_brainpool160r1CommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - int32_t res = Constructbrainpool160r1PubKeyParamsSpec(g_brainpool160r1AlgName, g_brainpool160r1CommSpec, + HcfResult res = ConstructEccPubKeyParamsSpec(g_brainpool160r1AlgName.c_str(), g_brainpool160r1CommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); @@ -1150,12 +1088,15 @@ HWTEST_F(CryptoEccKeyUtilTest, CryptoEccKeyUtilTest034, TestSize.Level0) HcfFree(blob.data); HcfObjDestroy(returnPubKey); HcfObjDestroy(returnObj); + DestroyEccPubKeySpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoEccKeyUtilTest, CryptoEccKeyUtilTest035, TestSize.Level0) { + ConstructEccKeyPairCommParamsSpec("NID_brainpoolP160r1", &g_brainpool160r1CommSpec); + ASSERT_NE(g_brainpool160r1CommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - int32_t res = Constructbrainpool160r1PriKeyParamsSpec(g_brainpool160r1AlgName, g_brainpool160r1CommSpec, + HcfResult res = ConstructEccPriKeyParamsSpec(g_brainpool160r1AlgName.c_str(), g_brainpool160r1CommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); @@ -1172,12 +1113,15 @@ HWTEST_F(CryptoEccKeyUtilTest, CryptoEccKeyUtilTest035, TestSize.Level0) HcfObjDestroy(returnPriKey); HcfObjDestroy(returnObj); + DestroyEccPriKeySpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoEccKeyUtilTest, CryptoEccKeyUtilTest036, TestSize.Level0) { + ConstructEccKeyPairCommParamsSpec("NID_brainpoolP160r1", &g_brainpool160r1CommSpec); + ASSERT_NE(g_brainpool160r1CommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - int32_t res = Constructbrainpool160r1PriKeyParamsSpec(g_brainpool160r1AlgName, g_brainpool160r1CommSpec, + HcfResult res = ConstructEccPriKeyParamsSpec(g_brainpool160r1AlgName.c_str(), g_brainpool160r1CommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); @@ -1194,12 +1138,15 @@ HWTEST_F(CryptoEccKeyUtilTest, CryptoEccKeyUtilTest036, TestSize.Level0) returnPriKey->base.base.destroy(&(returnPriKey->base.base)); HcfObjDestroy(returnObj); + DestroyEccPriKeySpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoEccKeyUtilTest, CryptoEccKeyUtilTest037, TestSize.Level0) { + ConstructEccKeyPairCommParamsSpec("NID_brainpoolP160r1", &g_brainpool160r1CommSpec); + ASSERT_NE(g_brainpool160r1CommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - int32_t res = Constructbrainpool160r1PriKeyParamsSpec(g_brainpool160r1AlgName, g_brainpool160r1CommSpec, + HcfResult res = ConstructEccPriKeyParamsSpec(g_brainpool160r1AlgName.c_str(), g_brainpool160r1CommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); @@ -1217,12 +1164,15 @@ HWTEST_F(CryptoEccKeyUtilTest, CryptoEccKeyUtilTest037, TestSize.Level0) HcfObjDestroy(returnPriKey); HcfObjDestroy(returnObj); + DestroyEccPriKeySpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoEccKeyUtilTest, CryptoEccKeyUtilTest038, TestSize.Level0) { + ConstructEccKeyPairCommParamsSpec("NID_brainpoolP160r1", &g_brainpool160r1CommSpec); + ASSERT_NE(g_brainpool160r1CommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - int32_t res = Constructbrainpool160r1PriKeyParamsSpec(g_brainpool160r1AlgName, g_brainpool160r1CommSpec, + HcfResult res = ConstructEccPriKeyParamsSpec(g_brainpool160r1AlgName.c_str(), g_brainpool160r1CommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); @@ -1241,12 +1191,16 @@ HWTEST_F(CryptoEccKeyUtilTest, CryptoEccKeyUtilTest038, TestSize.Level0) HcfObjDestroy(returnPriKey); HcfObjDestroy(returnObj); + DestroyEccPriKeySpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoEccKeyUtilTest, CryptoEccKeyUtilTest039_1, TestSize.Level0) { + ConstructEccKeyPairCommParamsSpec("NID_brainpoolP160r1", &g_brainpool160r1CommSpec); + ASSERT_NE(g_brainpool160r1CommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - int32_t res = ConstructbrainpoolKeyPairParamsSpec(g_brainpool160r1AlgName, g_brainpool160r1CommSpec, ¶mSpec); + int32_t res = ConstructEccKeyPairParamsSpec(g_brainpool160r1AlgName.c_str(), + g_brainpool160r1CommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); @@ -1288,12 +1242,16 @@ HWTEST_F(CryptoEccKeyUtilTest, CryptoEccKeyUtilTest039_1, TestSize.Level0) HcfObjDestroy(returnObj); HcfObjDestroy(sign); HcfObjDestroy(verify); + DestroyEccKeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoEccKeyUtilTest, CryptoEccKeyUtilTest039_2, TestSize.Level0) { + ConstructEccKeyPairCommParamsSpec("NID_brainpoolP160t1", &g_brainpool160t1CommSpec); + ASSERT_NE(g_brainpool160t1CommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - int32_t res = ConstructbrainpoolKeyPairParamsSpec(g_brainpool160t1AlgName, g_brainpool160t1CommSpec, ¶mSpec); + int32_t res = ConstructEccKeyPairParamsSpec(g_brainpool160t1AlgName.c_str(), + g_brainpool160t1CommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); @@ -1327,12 +1285,16 @@ HWTEST_F(CryptoEccKeyUtilTest, CryptoEccKeyUtilTest039_2, TestSize.Level0) HcfObjDestroy(returnObj); HcfObjDestroy(sign); HcfObjDestroy(verify); + DestroyEccKeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoEccKeyUtilTest, CryptoEccKeyUtilTest039_3, TestSize.Level0) { + ConstructEccKeyPairCommParamsSpec("NID_brainpoolP192r1", &g_brainpool192r1CommSpec); + ASSERT_NE(g_brainpool192r1CommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - int32_t res = ConstructbrainpoolKeyPairParamsSpec(g_brainpool192r1AlgName, g_brainpool192r1CommSpec, ¶mSpec); + int32_t res = ConstructEccKeyPairParamsSpec(g_brainpool192r1AlgName.c_str(), + g_brainpool192r1CommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); @@ -1366,12 +1328,16 @@ HWTEST_F(CryptoEccKeyUtilTest, CryptoEccKeyUtilTest039_3, TestSize.Level0) HcfObjDestroy(returnObj); HcfObjDestroy(sign); HcfObjDestroy(verify); + DestroyEccKeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoEccKeyUtilTest, CryptoEccKeyUtilTest039_4, TestSize.Level0) { + ConstructEccKeyPairCommParamsSpec("NID_brainpoolP192t1", &g_brainpool192t1CommSpec); + ASSERT_NE(g_brainpool192t1CommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - int32_t res = ConstructbrainpoolKeyPairParamsSpec(g_brainpool192t1AlgName, g_brainpool192t1CommSpec, ¶mSpec); + int32_t res = ConstructEccKeyPairParamsSpec(g_brainpool192t1AlgName.c_str(), + g_brainpool192t1CommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); @@ -1406,12 +1372,16 @@ HWTEST_F(CryptoEccKeyUtilTest, CryptoEccKeyUtilTest039_4, TestSize.Level0) HcfObjDestroy(returnObj); HcfObjDestroy(sign); HcfObjDestroy(verify); + DestroyEccKeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoEccKeyUtilTest, CryptoEccKeyUtilTest039_5, TestSize.Level0) { + ConstructEccKeyPairCommParamsSpec("NID_brainpoolP224r1", &g_brainpool224r1CommSpec); + ASSERT_NE(g_brainpool224r1CommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - int32_t res = ConstructbrainpoolKeyPairParamsSpec(g_brainpool224r1AlgName, g_brainpool224r1CommSpec, ¶mSpec); + int32_t res = ConstructEccKeyPairParamsSpec(g_brainpool224r1AlgName.c_str(), + g_brainpool224r1CommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); @@ -1445,12 +1415,16 @@ HWTEST_F(CryptoEccKeyUtilTest, CryptoEccKeyUtilTest039_5, TestSize.Level0) HcfObjDestroy(returnObj); HcfObjDestroy(sign); HcfObjDestroy(verify); + DestroyEccKeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoEccKeyUtilTest, CryptoEccKeyUtilTest039_6, TestSize.Level0) { + ConstructEccKeyPairCommParamsSpec("NID_brainpoolP224t1", &g_brainpool224t1CommSpec); + ASSERT_NE(g_brainpool224t1CommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - int32_t res = ConstructbrainpoolKeyPairParamsSpec(g_brainpool224t1AlgName, g_brainpool224t1CommSpec, ¶mSpec); + int32_t res = ConstructEccKeyPairParamsSpec(g_brainpool224t1AlgName.c_str(), + g_brainpool224t1CommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); @@ -1484,12 +1458,16 @@ HWTEST_F(CryptoEccKeyUtilTest, CryptoEccKeyUtilTest039_6, TestSize.Level0) HcfObjDestroy(returnObj); HcfObjDestroy(sign); HcfObjDestroy(verify); + DestroyEccKeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoEccKeyUtilTest, CryptoEccKeyUtilTest039_7, TestSize.Level0) { + ConstructEccKeyPairCommParamsSpec("NID_brainpoolP256r1", &g_brainpool256r1CommSpec); + ASSERT_NE(g_brainpool256r1CommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - int32_t res = ConstructbrainpoolKeyPairParamsSpec(g_brainpool256r1AlgName, g_brainpool256r1CommSpec, ¶mSpec); + int32_t res = ConstructEccKeyPairParamsSpec(g_brainpool256r1AlgName.c_str(), + g_brainpool256r1CommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); @@ -1522,12 +1500,16 @@ HWTEST_F(CryptoEccKeyUtilTest, CryptoEccKeyUtilTest039_7, TestSize.Level0) HcfObjDestroy(returnObj); HcfObjDestroy(sign); HcfObjDestroy(verify); + DestroyEccKeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoEccKeyUtilTest, CryptoEccKeyUtilTest039_8, TestSize.Level0) { + ConstructEccKeyPairCommParamsSpec("NID_brainpoolP256t1", &g_brainpool256t1CommSpec); + ASSERT_NE(g_brainpool256t1CommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - int32_t res = ConstructbrainpoolKeyPairParamsSpec(g_brainpool256t1AlgName, g_brainpool256t1CommSpec, ¶mSpec); + int32_t res = ConstructEccKeyPairParamsSpec(g_brainpool256t1AlgName.c_str(), + g_brainpool256t1CommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); @@ -1561,12 +1543,16 @@ HWTEST_F(CryptoEccKeyUtilTest, CryptoEccKeyUtilTest039_8, TestSize.Level0) HcfObjDestroy(returnObj); HcfObjDestroy(sign); HcfObjDestroy(verify); + DestroyEccKeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoEccKeyUtilTest, CryptoEccKeyUtilTest039_9, TestSize.Level0) { + ConstructEccKeyPairCommParamsSpec("NID_brainpoolP320r1", &g_brainpool320r1CommSpec); + ASSERT_NE(g_brainpool320r1CommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - int32_t res = ConstructbrainpoolKeyPairParamsSpec(g_brainpool320r1AlgName, g_brainpool320r1CommSpec, ¶mSpec); + int32_t res = ConstructEccKeyPairParamsSpec(g_brainpool320r1AlgName.c_str(), + g_brainpool320r1CommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); @@ -1600,12 +1586,16 @@ HWTEST_F(CryptoEccKeyUtilTest, CryptoEccKeyUtilTest039_9, TestSize.Level0) HcfObjDestroy(returnObj); HcfObjDestroy(sign); HcfObjDestroy(verify); + DestroyEccKeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoEccKeyUtilTest, CryptoEccKeyUtilTest039_10, TestSize.Level0) { + ConstructEccKeyPairCommParamsSpec("NID_brainpoolP320t1", &g_brainpool320t1CommSpec); + ASSERT_NE(g_brainpool320t1CommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - int32_t res = ConstructbrainpoolKeyPairParamsSpec(g_brainpool320t1AlgName, g_brainpool320t1CommSpec, ¶mSpec); + int32_t res = ConstructEccKeyPairParamsSpec(g_brainpool320t1AlgName.c_str(), + g_brainpool320t1CommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); @@ -1639,12 +1629,16 @@ HWTEST_F(CryptoEccKeyUtilTest, CryptoEccKeyUtilTest039_10, TestSize.Level0) HcfObjDestroy(returnObj); HcfObjDestroy(sign); HcfObjDestroy(verify); + DestroyEccKeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoEccKeyUtilTest, CryptoEccKeyUtilTest039_11, TestSize.Level0) { + ConstructEccKeyPairCommParamsSpec("NID_brainpoolP384r1", &g_brainpool384r1CommSpec); + ASSERT_NE(g_brainpool384r1CommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - int32_t res = ConstructbrainpoolKeyPairParamsSpec(g_brainpool384r1AlgName, g_brainpool384r1CommSpec, ¶mSpec); + int32_t res = ConstructEccKeyPairParamsSpec(g_brainpool384r1AlgName.c_str(), + g_brainpool384r1CommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); @@ -1678,12 +1672,16 @@ HWTEST_F(CryptoEccKeyUtilTest, CryptoEccKeyUtilTest039_11, TestSize.Level0) HcfObjDestroy(returnObj); HcfObjDestroy(sign); HcfObjDestroy(verify); + DestroyEccKeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoEccKeyUtilTest, CryptoEccKeyUtilTest039_12, TestSize.Level0) { + ConstructEccKeyPairCommParamsSpec("NID_brainpoolP384t1", &g_brainpool384t1CommSpec); + ASSERT_NE(g_brainpool384t1CommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - int32_t res = ConstructbrainpoolKeyPairParamsSpec(g_brainpool384t1AlgName, g_brainpool384t1CommSpec, ¶mSpec); + int32_t res = ConstructEccKeyPairParamsSpec(g_brainpool384t1AlgName.c_str(), + g_brainpool384t1CommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); @@ -1717,12 +1715,16 @@ HWTEST_F(CryptoEccKeyUtilTest, CryptoEccKeyUtilTest039_12, TestSize.Level0) HcfObjDestroy(returnObj); HcfObjDestroy(sign); HcfObjDestroy(verify); + DestroyEccKeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoEccKeyUtilTest, CryptoEccKeyUtilTest039_13, TestSize.Level0) { + ConstructEccKeyPairCommParamsSpec("NID_brainpoolP512r1", &g_brainpool512r1CommSpec); + ASSERT_NE(g_brainpool512r1CommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - int32_t res = ConstructbrainpoolKeyPairParamsSpec(g_brainpool512r1AlgName, g_brainpool512r1CommSpec, ¶mSpec); + int32_t res = ConstructEccKeyPairParamsSpec(g_brainpool512r1AlgName.c_str(), + g_brainpool512r1CommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); @@ -1756,12 +1758,16 @@ HWTEST_F(CryptoEccKeyUtilTest, CryptoEccKeyUtilTest039_13, TestSize.Level0) HcfObjDestroy(returnObj); HcfObjDestroy(sign); HcfObjDestroy(verify); + DestroyEccKeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoEccKeyUtilTest, CryptoEccKeyUtilTest039_14, TestSize.Level0) { + ConstructEccKeyPairCommParamsSpec("NID_brainpoolP512t1", &g_brainpool512t1CommSpec); + ASSERT_NE(g_brainpool512t1CommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - int32_t res = ConstructbrainpoolKeyPairParamsSpec(g_brainpool512t1AlgName, g_brainpool512t1CommSpec, ¶mSpec); + int32_t res = ConstructEccKeyPairParamsSpec(g_brainpool512t1AlgName.c_str(), + g_brainpool512t1CommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); @@ -1794,12 +1800,16 @@ HWTEST_F(CryptoEccKeyUtilTest, CryptoEccKeyUtilTest039_14, TestSize.Level0) HcfObjDestroy(returnObj); HcfObjDestroy(sign); HcfObjDestroy(verify); + DestroyEccKeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoEccKeyUtilTest, CryptoEccKeyUtilTest040, TestSize.Level0) { + ConstructEccKeyPairCommParamsSpec("NID_brainpoolP160r1", &g_brainpool160r1CommSpec); + ASSERT_NE(g_brainpool160r1CommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - int32_t res = ConstructbrainpoolKeyPairParamsSpec(g_brainpool160r1AlgName, g_brainpool160r1CommSpec, ¶mSpec); + HcfResult res = ConstructEccKeyPairParamsSpec(g_brainpool160r1AlgName.c_str(), + g_brainpool160r1CommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); @@ -1815,12 +1825,15 @@ HWTEST_F(CryptoEccKeyUtilTest, CryptoEccKeyUtilTest040, TestSize.Level0) HcfObjDestroy(returnKeyPair); HcfObjDestroy(returnObj); + DestroyEccKeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoEccKeyUtilTest, CryptoEccKeyUtilTest041, TestSize.Level0) { + ConstructEccKeyPairCommParamsSpec("NID_brainpoolP160r1", &g_brainpool160r1CommSpec); + ASSERT_NE(g_brainpool160r1CommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - int32_t res = Constructbrainpool160r1PubKeyParamsSpec(g_brainpool160r1AlgName, g_brainpool160r1CommSpec, + HcfResult res = ConstructEccPubKeyParamsSpec(g_brainpool160r1AlgName.c_str(), g_brainpool160r1CommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); @@ -1837,12 +1850,15 @@ HWTEST_F(CryptoEccKeyUtilTest, CryptoEccKeyUtilTest041, TestSize.Level0) HcfObjDestroy(returnPubKey); HcfObjDestroy(returnObj); + DestroyEccPubKeySpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoEccKeyUtilTest, CryptoEccKeyUtilTest042, TestSize.Level0) { + ConstructEccKeyPairCommParamsSpec("NID_brainpoolP160r1", &g_brainpool160r1CommSpec); + ASSERT_NE(g_brainpool160r1CommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - int32_t res = Constructbrainpool160r1PriKeyParamsSpec(g_brainpool160r1AlgName, g_brainpool160r1CommSpec, + HcfResult res = ConstructEccPriKeyParamsSpec(g_brainpool160r1AlgName.c_str(), g_brainpool160r1CommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); @@ -1859,12 +1875,15 @@ HWTEST_F(CryptoEccKeyUtilTest, CryptoEccKeyUtilTest042, TestSize.Level0) HcfObjDestroy(returnPriKey); HcfObjDestroy(returnObj); + DestroyEccPriKeySpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoEccKeyUtilTest, CryptoEccKeyUtilTest043, TestSize.Level0) { + ConstructEccKeyPairCommParamsSpec("NID_brainpoolP160r1", &g_brainpool160r1CommSpec); + ASSERT_NE(g_brainpool160r1CommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - int32_t res = Constructbrainpool160r1PriKeyParamsSpec(g_brainpool160r1AlgName, g_brainpool160r1CommSpec, + HcfResult res = ConstructEccPriKeyParamsSpec(g_brainpool160r1AlgName.c_str(), g_brainpool160r1CommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); @@ -1881,12 +1900,16 @@ HWTEST_F(CryptoEccKeyUtilTest, CryptoEccKeyUtilTest043, TestSize.Level0) HcfObjDestroy(returnPriKey); HcfObjDestroy(returnObj); + DestroyEccPriKeySpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoEccKeyUtilTest, CryptoEccKeyUtilTest044, TestSize.Level0) { + ConstructEccKeyPairCommParamsSpec("NID_brainpoolP160r1", &g_brainpool160r1CommSpec); + ASSERT_NE(g_brainpool160r1CommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - int32_t res = ConstructbrainpoolKeyPairParamsSpec(g_brainpool160r1AlgName, g_brainpool160r1CommSpec, ¶mSpec); + HcfResult res = ConstructEccKeyPairParamsSpec(g_brainpool160r1AlgName.c_str(), + g_brainpool160r1CommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); @@ -1902,12 +1925,15 @@ HWTEST_F(CryptoEccKeyUtilTest, CryptoEccKeyUtilTest044, TestSize.Level0) HcfObjDestroy(returnPriKey); HcfObjDestroy(returnObj); + DestroyEccKeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoEccKeyUtilTest, CryptoEccKeyUtilTest045, TestSize.Level0) { + ConstructEccKeyPairCommParamsSpec("NID_brainpoolP160r1", &g_brainpool160r1CommSpec); + ASSERT_NE(g_brainpool160r1CommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - int32_t res = Constructbrainpool160r1PriKeyParamsSpec(g_brainpool160r1AlgName, g_brainpool160r1CommSpec, + HcfResult res = ConstructEccPriKeyParamsSpec(g_brainpool160r1AlgName.c_str(), g_brainpool160r1CommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); @@ -1924,6 +1950,7 @@ HWTEST_F(CryptoEccKeyUtilTest, CryptoEccKeyUtilTest045, TestSize.Level0) HcfObjDestroy(returnPriKey); HcfObjDestroy(returnObj); + DestroyEccPriKeySpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoEccKeyUtilTest, CryptoEccKeyUtilTest046, TestSize.Level0) @@ -1934,7 +1961,7 @@ HWTEST_F(CryptoEccKeyUtilTest, CryptoEccKeyUtilTest046, TestSize.Level0) .primes = HCF_OPENSSL_PRIMES_2 }; HcfEccCommParamsSpecSpi *returnCommonParamSpec = nullptr; - int32_t res = HcfECCCommonParamSpecCreate(¶ms, &returnCommonParamSpec); + HcfResult res = HcfECCCommonParamSpecCreate(¶ms, &returnCommonParamSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(returnCommonParamSpec, nullptr); } @@ -1942,7 +1969,7 @@ HWTEST_F(CryptoEccKeyUtilTest, CryptoEccKeyUtilTest046, TestSize.Level0) HWTEST_F(CryptoEccKeyUtilTest, CryptoEccKeyUtilTest047, TestSize.Level0) { HcfEccCommParamsSpecSpi *returnCommonParamSpec = nullptr; - int32_t res = HcfECCCommonParamSpecCreate(nullptr, &returnCommonParamSpec); + HcfResult res = HcfECCCommonParamSpecCreate(nullptr, &returnCommonParamSpec); ASSERT_NE(res, HCF_SUCCESS); } @@ -1953,7 +1980,7 @@ HWTEST_F(CryptoEccKeyUtilTest, CryptoEccKeyUtilTest048, TestSize.Level0) .bits = HCF_ALG_ECC_BP160R1, .primes = HCF_OPENSSL_PRIMES_2 }; - int32_t res = HcfECCCommonParamSpecCreate(¶ms, nullptr); + HcfResult res = HcfECCCommonParamSpecCreate(¶ms, nullptr); ASSERT_NE(res, HCF_SUCCESS); } @@ -1965,7 +1992,7 @@ HWTEST_F(CryptoEccKeyUtilTest, CryptoEccKeyUtilTest049, TestSize.Level0) .primes = HCF_OPENSSL_PRIMES_2 }; HcfEccCommParamsSpecSpi *returnCommonParamSpec = nullptr; - int32_t res = HcfECCCommonParamSpecCreate(&obj, &returnCommonParamSpec); + HcfResult res = HcfECCCommonParamSpecCreate(&obj, &returnCommonParamSpec); ASSERT_NE(res, HCF_SUCCESS); ASSERT_EQ(returnCommonParamSpec, nullptr); @@ -1980,7 +2007,7 @@ HWTEST_F(CryptoEccKeyUtilTest, CryptoEccKeyUtilTest050, TestSize.Level0) .primes = HCF_OPENSSL_PRIMES_2 }; HcfEccCommParamsSpecSpi *returnCommonParamSpec = nullptr; - int32_t res = HcfECCCommonParamSpecCreate(&obj, &returnCommonParamSpec); + HcfResult res = HcfECCCommonParamSpecCreate(&obj, &returnCommonParamSpec); ASSERT_NE(res, HCF_SUCCESS); ASSERT_EQ(returnCommonParamSpec, nullptr); @@ -1989,7 +2016,7 @@ HWTEST_F(CryptoEccKeyUtilTest, CryptoEccKeyUtilTest050, TestSize.Level0) HWTEST_F(CryptoEccKeyUtilTest, CryptoEccKeyUtilTest051, TestSize.Level0) { - int32_t res = HcfEccKeyUtilCreate("NID_brainpoolP160r1", nullptr); + HcfResult res = HcfEccKeyUtilCreate("NID_brainpoolP160r1", nullptr); ASSERT_EQ(res, HCF_INVALID_PARAMS); } @@ -1999,7 +2026,7 @@ static void OpensslMockTestFunc(uint32_t mallocCount, HcfEccCommParamsSpec *retu ResetOpensslCallNum(); SetOpensslCallMockIndex(i); - int32_t res = HcfEccKeyUtilCreate("NID_brainpoolP160r1", &returnCommonParamSpec); + HcfResult res = HcfEccKeyUtilCreate("NID_brainpoolP160r1", &returnCommonParamSpec); if (res != HCF_SUCCESS) { continue; } @@ -2012,7 +2039,7 @@ HWTEST_F(CryptoEccKeyUtilTest, CryptoEccKeyUtilTest052, TestSize.Level0) { StartRecordOpensslCallNum(); HcfEccCommParamsSpec *returnCommonParamSpec = NULL; - int32_t res = HcfEccKeyUtilCreate("NID_brainpoolP160r1", &returnCommonParamSpec); + HcfResult res = HcfEccKeyUtilCreate("NID_brainpoolP160r1", &returnCommonParamSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(returnCommonParamSpec, nullptr); diff --git a/test/unittest/src/crypto_ecc_no_length_sign_test.cpp b/test/unittest/src/crypto_ecc_no_length_sign_test.cpp index e133790bf29a2b9e7af5990a960ab52fc75d20df..796e3e7259a7519f1493af0c34d7ea89da50926c 100644 --- a/test/unittest/src/crypto_ecc_no_length_sign_test.cpp +++ b/test/unittest/src/crypto_ecc_no_length_sign_test.cpp @@ -1389,7 +1389,7 @@ HWTEST_F(CryptoEccNoLengthSignTest, CryptoEccNoLengthSignTest401, TestSize.Level ASSERT_NE(out.data, nullptr); ASSERT_NE(out.len, (const unsigned int)0); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); } @@ -1416,7 +1416,7 @@ HWTEST_F(CryptoEccNoLengthSignTest, CryptoEccNoLengthSignTest402, TestSize.Level ASSERT_NE(out.data, nullptr); ASSERT_NE(out.len, (const unsigned int)0); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); } @@ -1443,7 +1443,7 @@ HWTEST_F(CryptoEccNoLengthSignTest, CryptoEccNoLengthSignTest403, TestSize.Level ASSERT_NE(out.data, nullptr); ASSERT_NE(out.len, (const unsigned int)0); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); } @@ -1470,7 +1470,7 @@ HWTEST_F(CryptoEccNoLengthSignTest, CryptoEccNoLengthSignTest404, TestSize.Level ASSERT_NE(out.data, nullptr); ASSERT_NE(out.len, (const unsigned int)0); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); } @@ -1497,7 +1497,7 @@ HWTEST_F(CryptoEccNoLengthSignTest, CryptoEccNoLengthSignTest405, TestSize.Level ASSERT_NE(out.data, nullptr); ASSERT_NE(out.len, (const unsigned int)0); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); } @@ -1524,7 +1524,7 @@ HWTEST_F(CryptoEccNoLengthSignTest, CryptoEccNoLengthSignTest406, TestSize.Level ASSERT_NE(out.data, nullptr); ASSERT_NE(out.len, (const unsigned int)0); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); } @@ -1551,7 +1551,7 @@ HWTEST_F(CryptoEccNoLengthSignTest, CryptoEccNoLengthSignTest407, TestSize.Level ASSERT_NE(out.data, nullptr); ASSERT_NE(out.len, (const unsigned int)0); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); } @@ -1578,7 +1578,7 @@ HWTEST_F(CryptoEccNoLengthSignTest, CryptoEccNoLengthSignTest408, TestSize.Level ASSERT_NE(out.data, nullptr); ASSERT_NE(out.len, (const unsigned int)0); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); } @@ -1605,7 +1605,7 @@ HWTEST_F(CryptoEccNoLengthSignTest, CryptoEccNoLengthSignTest409, TestSize.Level ASSERT_NE(out.data, nullptr); ASSERT_NE(out.len, (const unsigned int)0); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); } @@ -1632,7 +1632,7 @@ HWTEST_F(CryptoEccNoLengthSignTest, CryptoEccNoLengthSignTest410, TestSize.Level ASSERT_NE(out.data, nullptr); ASSERT_NE(out.len, (const unsigned int)0); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); } @@ -1659,7 +1659,7 @@ HWTEST_F(CryptoEccNoLengthSignTest, CryptoEccNoLengthSignTest411, TestSize.Level ASSERT_NE(out.data, nullptr); ASSERT_NE(out.len, (const unsigned int)0); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); } @@ -1686,7 +1686,7 @@ HWTEST_F(CryptoEccNoLengthSignTest, CryptoEccNoLengthSignTest412, TestSize.Level ASSERT_NE(out.data, nullptr); ASSERT_NE(out.len, (const unsigned int)0); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); } @@ -1713,7 +1713,7 @@ HWTEST_F(CryptoEccNoLengthSignTest, CryptoEccNoLengthSignTest413, TestSize.Level ASSERT_NE(out.data, nullptr); ASSERT_NE(out.len, (const unsigned int)0); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); } @@ -1740,7 +1740,7 @@ HWTEST_F(CryptoEccNoLengthSignTest, CryptoEccNoLengthSignTest414, TestSize.Level ASSERT_NE(out.data, nullptr); ASSERT_NE(out.len, (const unsigned int)0); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); } @@ -1767,7 +1767,7 @@ HWTEST_F(CryptoEccNoLengthSignTest, CryptoEccNoLengthSignTest415, TestSize.Level ASSERT_NE(out.data, nullptr); ASSERT_NE(out.len, (const unsigned int)0); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); } @@ -1794,7 +1794,7 @@ HWTEST_F(CryptoEccNoLengthSignTest, CryptoEccNoLengthSignTest416, TestSize.Level ASSERT_NE(out.data, nullptr); ASSERT_NE(out.len, (const unsigned int)0); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); } @@ -1821,7 +1821,7 @@ HWTEST_F(CryptoEccNoLengthSignTest, CryptoEccNoLengthSignTest417, TestSize.Level ASSERT_NE(out.data, nullptr); ASSERT_NE(out.len, (const unsigned int)0); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); } @@ -1848,7 +1848,7 @@ HWTEST_F(CryptoEccNoLengthSignTest, CryptoEccNoLengthSignTest418, TestSize.Level ASSERT_NE(out.data, nullptr); ASSERT_NE(out.len, (const unsigned int)0); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); } @@ -1875,7 +1875,7 @@ HWTEST_F(CryptoEccNoLengthSignTest, CryptoEccNoLengthSignTest419, TestSize.Level ASSERT_NE(out.data, nullptr); ASSERT_NE(out.len, (const unsigned int)0); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); } @@ -1902,7 +1902,7 @@ HWTEST_F(CryptoEccNoLengthSignTest, CryptoEccNoLengthSignTest420, TestSize.Level ASSERT_NE(out.data, nullptr); ASSERT_NE(out.len, (const unsigned int)0); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); } @@ -1925,7 +1925,7 @@ HWTEST_F(CryptoEccNoLengthSignTest, CryptoEccNoLengthSignTest421, TestSize.Level ASSERT_NE(out.data, nullptr); ASSERT_NE(out.len, (const unsigned int)0); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); } @@ -1948,7 +1948,7 @@ HWTEST_F(CryptoEccNoLengthSignTest, CryptoEccNoLengthSignTest422, TestSize.Level ASSERT_NE(out.data, nullptr); ASSERT_NE(out.len, (const unsigned int)0); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); } @@ -1971,7 +1971,7 @@ HWTEST_F(CryptoEccNoLengthSignTest, CryptoEccNoLengthSignTest423, TestSize.Level ASSERT_NE(out.data, nullptr); ASSERT_NE(out.len, (const unsigned int)0); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); } @@ -1994,7 +1994,7 @@ HWTEST_F(CryptoEccNoLengthSignTest, CryptoEccNoLengthSignTest424, TestSize.Level ASSERT_NE(out.data, nullptr); ASSERT_NE(out.len, (const unsigned int)0); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); } @@ -2017,7 +2017,7 @@ HWTEST_F(CryptoEccNoLengthSignTest, CryptoEccNoLengthSignTest425, TestSize.Level ASSERT_NE(out.data, nullptr); ASSERT_NE(out.len, (const unsigned int)0); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); } @@ -2040,7 +2040,7 @@ HWTEST_F(CryptoEccNoLengthSignTest, CryptoEccNoLengthSignTest426, TestSize.Level ASSERT_NE(out.data, nullptr); ASSERT_NE(out.len, (const unsigned int)0); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); } @@ -2063,7 +2063,7 @@ HWTEST_F(CryptoEccNoLengthSignTest, CryptoEccNoLengthSignTest427, TestSize.Level ASSERT_NE(out.data, nullptr); ASSERT_NE(out.len, (const unsigned int)0); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); } @@ -2086,7 +2086,7 @@ HWTEST_F(CryptoEccNoLengthSignTest, CryptoEccNoLengthSignTest428, TestSize.Level ASSERT_NE(out.data, nullptr); ASSERT_NE(out.len, (const unsigned int)0); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); } @@ -2109,7 +2109,7 @@ HWTEST_F(CryptoEccNoLengthSignTest, CryptoEccNoLengthSignTest429, TestSize.Level ASSERT_NE(out.data, nullptr); ASSERT_NE(out.len, (const unsigned int)0); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); } @@ -2132,7 +2132,7 @@ HWTEST_F(CryptoEccNoLengthSignTest, CryptoEccNoLengthSignTest430, TestSize.Level ASSERT_NE(out.data, nullptr); ASSERT_NE(out.len, (const unsigned int)0); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); } @@ -2155,7 +2155,7 @@ HWTEST_F(CryptoEccNoLengthSignTest, CryptoEccNoLengthSignTest431, TestSize.Level ASSERT_NE(out.data, nullptr); ASSERT_NE(out.len, (const unsigned int)0); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); } @@ -2178,7 +2178,7 @@ HWTEST_F(CryptoEccNoLengthSignTest, CryptoEccNoLengthSignTest432, TestSize.Level ASSERT_NE(out.data, nullptr); ASSERT_NE(out.len, (const unsigned int)0); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); } @@ -2201,7 +2201,7 @@ HWTEST_F(CryptoEccNoLengthSignTest, CryptoEccNoLengthSignTest433, TestSize.Level ASSERT_NE(out.data, nullptr); ASSERT_NE(out.len, (const unsigned int)0); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); } @@ -2224,7 +2224,7 @@ HWTEST_F(CryptoEccNoLengthSignTest, CryptoEccNoLengthSignTest434, TestSize.Level ASSERT_NE(out.data, nullptr); ASSERT_NE(out.len, (const unsigned int)0); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); } @@ -2247,7 +2247,7 @@ HWTEST_F(CryptoEccNoLengthSignTest, CryptoEccNoLengthSignTest435, TestSize.Level ASSERT_NE(out.data, nullptr); ASSERT_NE(out.len, (const unsigned int)0); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); } @@ -2270,7 +2270,7 @@ HWTEST_F(CryptoEccNoLengthSignTest, CryptoEccNoLengthSignTest436, TestSize.Level ASSERT_NE(out.data, nullptr); ASSERT_NE(out.len, (const unsigned int)0); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); } @@ -2293,7 +2293,7 @@ HWTEST_F(CryptoEccNoLengthSignTest, CryptoEccNoLengthSignTest437, TestSize.Level ASSERT_NE(out.data, nullptr); ASSERT_NE(out.len, (const unsigned int)0); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); } @@ -2316,7 +2316,7 @@ HWTEST_F(CryptoEccNoLengthSignTest, CryptoEccNoLengthSignTest438, TestSize.Level ASSERT_NE(out.data, nullptr); ASSERT_NE(out.len, (const unsigned int)0); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); } @@ -2339,7 +2339,7 @@ HWTEST_F(CryptoEccNoLengthSignTest, CryptoEccNoLengthSignTest439, TestSize.Level ASSERT_NE(out.data, nullptr); ASSERT_NE(out.len, (const unsigned int)0); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); } @@ -2362,7 +2362,7 @@ HWTEST_F(CryptoEccNoLengthSignTest, CryptoEccNoLengthSignTest440, TestSize.Level ASSERT_NE(out.data, nullptr); ASSERT_NE(out.len, (const unsigned int)0); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); } @@ -2560,8 +2560,8 @@ HWTEST_F(CryptoEccNoLengthSignTest, CryptoEccNoLengthSignTest447, TestSize.Level flag = verify->verify(verify, nullptr, &out2); ASSERT_EQ(flag, true); - free(out.data); - free(out2.data); + HcfFree(out.data); + HcfFree(out2.data); HcfObjDestroy(sign); HcfObjDestroy(verify); } @@ -2594,7 +2594,7 @@ HWTEST_F(CryptoEccNoLengthSignTest, CryptoEccNoLengthSignTest448, TestSize.Level HcfBlob out2 = { .data = nullptr, .len = 0 }; res = sign->sign(sign, nullptr, &out2); - free(out2.data); + HcfFree(out2.data); HcfObjDestroy(sign); } @@ -2633,7 +2633,7 @@ HWTEST_F(CryptoEccNoLengthSignTest, CryptoEccNoLengthSignTest927, TestSize.Level ASSERT_NE(out.data, nullptr); ASSERT_NE(out.len, (const unsigned int)0); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); } @@ -2674,7 +2674,7 @@ HWTEST_F(CryptoEccNoLengthSignTest, CryptoEccNoLengthSignTest928, TestSize.Level ASSERT_NE(out.data, nullptr); ASSERT_NE(out.len, (const unsigned int)0); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); } @@ -2860,7 +2860,7 @@ static void MemoryMallocTestFunc(uint32_t mallocCount, HcfBlob *input) HcfObjDestroy(sign); HcfObjDestroy(keyPair); if (res == HCF_SUCCESS) { - free(out.data); + HcfFree(out.data); } } } @@ -2903,7 +2903,7 @@ HWTEST_F(CryptoEccNoLengthSignTest, CryptoEccNoLengthSignTest1101, TestSize.Leve ASSERT_NE(out.data, nullptr); ASSERT_NE(out.len, (const unsigned int)0); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); uint32_t mallocCount = GetMallocNum(); @@ -2954,7 +2954,7 @@ static void OpensslMockTestFunc(uint32_t mallocCount, HcfBlob *input) HcfObjDestroy(sign); HcfObjDestroy(keyPair); if (res == HCF_SUCCESS) { - free(out.data); + HcfFree(out.data); } } } @@ -2997,7 +2997,7 @@ HWTEST_F(CryptoEccNoLengthSignTest, CryptoEccNoLengthSignTest1102, TestSize.Leve ASSERT_NE(out.data, nullptr); ASSERT_NE(out.len, (const unsigned int)0); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); uint32_t mallocCount = GetOpensslCallNum(); diff --git a/test/unittest/src/crypto_ecc_no_length_verify_test.cpp b/test/unittest/src/crypto_ecc_no_length_verify_test.cpp index ed93887992a7a743239308f275b52416a1675619..113658359f41f99b8398e24d184acadf7de81acc 100644 --- a/test/unittest/src/crypto_ecc_no_length_verify_test.cpp +++ b/test/unittest/src/crypto_ecc_no_length_verify_test.cpp @@ -1418,7 +1418,7 @@ HWTEST_F(CryptoEccNoLengthVerifyTest, CryptoEccNoLengthVerifyTest401, TestSize.L ASSERT_EQ(flag, true); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); HcfObjDestroy(verify); } @@ -1464,7 +1464,7 @@ HWTEST_F(CryptoEccNoLengthVerifyTest, CryptoEccNoLengthVerifyTest402, TestSize.L ASSERT_EQ(flag, true); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); HcfObjDestroy(verify); } @@ -1510,7 +1510,7 @@ HWTEST_F(CryptoEccNoLengthVerifyTest, CryptoEccNoLengthVerifyTest403, TestSize.L ASSERT_EQ(flag, true); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); HcfObjDestroy(verify); } @@ -1556,7 +1556,7 @@ HWTEST_F(CryptoEccNoLengthVerifyTest, CryptoEccNoLengthVerifyTest404, TestSize.L ASSERT_EQ(flag, true); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); HcfObjDestroy(verify); } @@ -1602,7 +1602,7 @@ HWTEST_F(CryptoEccNoLengthVerifyTest, CryptoEccNoLengthVerifyTest405, TestSize.L ASSERT_EQ(flag, true); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); HcfObjDestroy(verify); } @@ -1648,7 +1648,7 @@ HWTEST_F(CryptoEccNoLengthVerifyTest, CryptoEccNoLengthVerifyTest406, TestSize.L ASSERT_EQ(flag, true); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); HcfObjDestroy(verify); } @@ -1694,7 +1694,7 @@ HWTEST_F(CryptoEccNoLengthVerifyTest, CryptoEccNoLengthVerifyTest407, TestSize.L ASSERT_EQ(flag, true); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); HcfObjDestroy(verify); } @@ -1740,7 +1740,7 @@ HWTEST_F(CryptoEccNoLengthVerifyTest, CryptoEccNoLengthVerifyTest408, TestSize.L ASSERT_EQ(flag, true); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); HcfObjDestroy(verify); } @@ -1786,7 +1786,7 @@ HWTEST_F(CryptoEccNoLengthVerifyTest, CryptoEccNoLengthVerifyTest409, TestSize.L ASSERT_EQ(flag, true); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); HcfObjDestroy(verify); } @@ -1832,7 +1832,7 @@ HWTEST_F(CryptoEccNoLengthVerifyTest, CryptoEccNoLengthVerifyTest410, TestSize.L ASSERT_EQ(flag, true); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); HcfObjDestroy(verify); } @@ -1878,7 +1878,7 @@ HWTEST_F(CryptoEccNoLengthVerifyTest, CryptoEccNoLengthVerifyTest411, TestSize.L ASSERT_EQ(flag, true); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); HcfObjDestroy(verify); } @@ -1924,7 +1924,7 @@ HWTEST_F(CryptoEccNoLengthVerifyTest, CryptoEccNoLengthVerifyTest412, TestSize.L ASSERT_EQ(flag, true); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); HcfObjDestroy(verify); } @@ -1970,7 +1970,7 @@ HWTEST_F(CryptoEccNoLengthVerifyTest, CryptoEccNoLengthVerifyTest413, TestSize.L ASSERT_EQ(flag, true); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); HcfObjDestroy(verify); } @@ -2016,7 +2016,7 @@ HWTEST_F(CryptoEccNoLengthVerifyTest, CryptoEccNoLengthVerifyTest414, TestSize.L ASSERT_EQ(flag, true); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); HcfObjDestroy(verify); } @@ -2062,7 +2062,7 @@ HWTEST_F(CryptoEccNoLengthVerifyTest, CryptoEccNoLengthVerifyTest415, TestSize.L ASSERT_EQ(flag, true); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); HcfObjDestroy(verify); } @@ -2108,7 +2108,7 @@ HWTEST_F(CryptoEccNoLengthVerifyTest, CryptoEccNoLengthVerifyTest416, TestSize.L ASSERT_EQ(flag, true); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); HcfObjDestroy(verify); } @@ -2154,7 +2154,7 @@ HWTEST_F(CryptoEccNoLengthVerifyTest, CryptoEccNoLengthVerifyTest417, TestSize.L ASSERT_EQ(flag, true); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); HcfObjDestroy(verify); } @@ -2200,7 +2200,7 @@ HWTEST_F(CryptoEccNoLengthVerifyTest, CryptoEccNoLengthVerifyTest418, TestSize.L ASSERT_EQ(flag, true); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); HcfObjDestroy(verify); } @@ -2246,7 +2246,7 @@ HWTEST_F(CryptoEccNoLengthVerifyTest, CryptoEccNoLengthVerifyTest419, TestSize.L ASSERT_EQ(flag, true); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); HcfObjDestroy(verify); } @@ -2292,7 +2292,7 @@ HWTEST_F(CryptoEccNoLengthVerifyTest, CryptoEccNoLengthVerifyTest420, TestSize.L ASSERT_EQ(flag, true); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); HcfObjDestroy(verify); } @@ -2330,7 +2330,7 @@ HWTEST_F(CryptoEccNoLengthVerifyTest, CryptoEccNoLengthVerifyTest421, TestSize.L ASSERT_EQ(flag, true); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); HcfObjDestroy(verify); } @@ -2368,7 +2368,7 @@ HWTEST_F(CryptoEccNoLengthVerifyTest, CryptoEccNoLengthVerifyTest422, TestSize.L ASSERT_EQ(flag, true); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); HcfObjDestroy(verify); } @@ -2406,7 +2406,7 @@ HWTEST_F(CryptoEccNoLengthVerifyTest, CryptoEccNoLengthVerifyTest423, TestSize.L ASSERT_EQ(flag, true); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); HcfObjDestroy(verify); } @@ -2444,7 +2444,7 @@ HWTEST_F(CryptoEccNoLengthVerifyTest, CryptoEccNoLengthVerifyTest424, TestSize.L ASSERT_EQ(flag, true); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); HcfObjDestroy(verify); } @@ -2482,7 +2482,7 @@ HWTEST_F(CryptoEccNoLengthVerifyTest, CryptoEccNoLengthVerifyTest425, TestSize.L ASSERT_EQ(flag, true); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); HcfObjDestroy(verify); } @@ -2520,7 +2520,7 @@ HWTEST_F(CryptoEccNoLengthVerifyTest, CryptoEccNoLengthVerifyTest426, TestSize.L ASSERT_EQ(flag, true); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); HcfObjDestroy(verify); } @@ -2558,7 +2558,7 @@ HWTEST_F(CryptoEccNoLengthVerifyTest, CryptoEccNoLengthVerifyTest427, TestSize.L ASSERT_EQ(flag, true); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); HcfObjDestroy(verify); } @@ -2596,7 +2596,7 @@ HWTEST_F(CryptoEccNoLengthVerifyTest, CryptoEccNoLengthVerifyTest428, TestSize.L ASSERT_EQ(flag, true); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); HcfObjDestroy(verify); } @@ -2634,7 +2634,7 @@ HWTEST_F(CryptoEccNoLengthVerifyTest, CryptoEccNoLengthVerifyTest429, TestSize.L ASSERT_EQ(flag, true); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); HcfObjDestroy(verify); } @@ -2672,7 +2672,7 @@ HWTEST_F(CryptoEccNoLengthVerifyTest, CryptoEccNoLengthVerifyTest430, TestSize.L ASSERT_EQ(flag, true); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); HcfObjDestroy(verify); } @@ -2710,7 +2710,7 @@ HWTEST_F(CryptoEccNoLengthVerifyTest, CryptoEccNoLengthVerifyTest431, TestSize.L ASSERT_EQ(flag, true); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); HcfObjDestroy(verify); } @@ -2748,7 +2748,7 @@ HWTEST_F(CryptoEccNoLengthVerifyTest, CryptoEccNoLengthVerifyTest432, TestSize.L ASSERT_EQ(flag, true); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); HcfObjDestroy(verify); } @@ -2786,7 +2786,7 @@ HWTEST_F(CryptoEccNoLengthVerifyTest, CryptoEccNoLengthVerifyTest433, TestSize.L ASSERT_EQ(flag, true); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); HcfObjDestroy(verify); } @@ -2824,7 +2824,7 @@ HWTEST_F(CryptoEccNoLengthVerifyTest, CryptoEccNoLengthVerifyTest434, TestSize.L ASSERT_EQ(flag, true); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); HcfObjDestroy(verify); } @@ -2862,7 +2862,7 @@ HWTEST_F(CryptoEccNoLengthVerifyTest, CryptoEccNoLengthVerifyTest435, TestSize.L ASSERT_EQ(flag, true); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); HcfObjDestroy(verify); } @@ -2900,7 +2900,7 @@ HWTEST_F(CryptoEccNoLengthVerifyTest, CryptoEccNoLengthVerifyTest436, TestSize.L ASSERT_EQ(flag, true); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); HcfObjDestroy(verify); } @@ -2938,7 +2938,7 @@ HWTEST_F(CryptoEccNoLengthVerifyTest, CryptoEccNoLengthVerifyTest437, TestSize.L ASSERT_EQ(flag, true); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); HcfObjDestroy(verify); } @@ -2976,7 +2976,7 @@ HWTEST_F(CryptoEccNoLengthVerifyTest, CryptoEccNoLengthVerifyTest438, TestSize.L ASSERT_EQ(flag, true); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); HcfObjDestroy(verify); } @@ -3014,7 +3014,7 @@ HWTEST_F(CryptoEccNoLengthVerifyTest, CryptoEccNoLengthVerifyTest439, TestSize.L ASSERT_EQ(flag, true); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); HcfObjDestroy(verify); } @@ -3052,7 +3052,7 @@ HWTEST_F(CryptoEccNoLengthVerifyTest, CryptoEccNoLengthVerifyTest440, TestSize.L ASSERT_EQ(flag, true); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); HcfObjDestroy(verify); } @@ -3098,7 +3098,7 @@ HWTEST_F(CryptoEccNoLengthVerifyTest, CryptoEccNoLengthVerifyTest441, TestSize.L ASSERT_EQ(flag, false); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); HcfObjDestroy(verify); } @@ -3144,7 +3144,7 @@ HWTEST_F(CryptoEccNoLengthVerifyTest, CryptoEccNoLengthVerifyTest442, TestSize.L ASSERT_EQ(flag, false); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); HcfObjDestroy(verify); } @@ -3186,7 +3186,7 @@ HWTEST_F(CryptoEccNoLengthVerifyTest, CryptoEccNoLengthVerifyTest443, TestSize.L ASSERT_EQ(flag, false); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); HcfObjDestroy(verify); } @@ -3232,7 +3232,7 @@ HWTEST_F(CryptoEccNoLengthVerifyTest, CryptoEccNoLengthVerifyTest444, TestSize.L ASSERT_EQ(flag, false); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); HcfObjDestroy(verify); } @@ -3278,7 +3278,7 @@ HWTEST_F(CryptoEccNoLengthVerifyTest, CryptoEccNoLengthVerifyTest445, TestSize.L ASSERT_EQ(flag, false); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); HcfObjDestroy(verify); } diff --git a/test/unittest/src/crypto_ecc_sign_test.cpp b/test/unittest/src/crypto_ecc_sign_test.cpp index aa756a15f15d9f33bea015cf30cbad65a05481d4..86e4ecd18bbb8fd3924b2cff8760b126f6b74dd4 100644 --- a/test/unittest/src/crypto_ecc_sign_test.cpp +++ b/test/unittest/src/crypto_ecc_sign_test.cpp @@ -1412,7 +1412,7 @@ HWTEST_F(CryptoEccSignTest, CryptoEccSignTest401, TestSize.Level0) ASSERT_NE(out.data, nullptr); ASSERT_NE(out.len, (const unsigned int)0); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); } @@ -1439,7 +1439,7 @@ HWTEST_F(CryptoEccSignTest, CryptoEccSignTest402, TestSize.Level0) ASSERT_NE(out.data, nullptr); ASSERT_NE(out.len, (const unsigned int)0); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); } @@ -1466,7 +1466,7 @@ HWTEST_F(CryptoEccSignTest, CryptoEccSignTest403, TestSize.Level0) ASSERT_NE(out.data, nullptr); ASSERT_NE(out.len, (const unsigned int)0); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); } @@ -1493,7 +1493,7 @@ HWTEST_F(CryptoEccSignTest, CryptoEccSignTest404, TestSize.Level0) ASSERT_NE(out.data, nullptr); ASSERT_NE(out.len, (const unsigned int)0); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); } @@ -1520,7 +1520,7 @@ HWTEST_F(CryptoEccSignTest, CryptoEccSignTest405, TestSize.Level0) ASSERT_NE(out.data, nullptr); ASSERT_NE(out.len, (const unsigned int)0); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); } @@ -1547,7 +1547,7 @@ HWTEST_F(CryptoEccSignTest, CryptoEccSignTest406, TestSize.Level0) ASSERT_NE(out.data, nullptr); ASSERT_NE(out.len, (const unsigned int)0); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); } @@ -1574,7 +1574,7 @@ HWTEST_F(CryptoEccSignTest, CryptoEccSignTest407, TestSize.Level0) ASSERT_NE(out.data, nullptr); ASSERT_NE(out.len, (const unsigned int)0); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); } @@ -1601,7 +1601,7 @@ HWTEST_F(CryptoEccSignTest, CryptoEccSignTest408, TestSize.Level0) ASSERT_NE(out.data, nullptr); ASSERT_NE(out.len, (const unsigned int)0); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); } @@ -1628,7 +1628,7 @@ HWTEST_F(CryptoEccSignTest, CryptoEccSignTest409, TestSize.Level0) ASSERT_NE(out.data, nullptr); ASSERT_NE(out.len, (const unsigned int)0); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); } @@ -1655,7 +1655,7 @@ HWTEST_F(CryptoEccSignTest, CryptoEccSignTest410, TestSize.Level0) ASSERT_NE(out.data, nullptr); ASSERT_NE(out.len, (const unsigned int)0); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); } @@ -1682,7 +1682,7 @@ HWTEST_F(CryptoEccSignTest, CryptoEccSignTest411, TestSize.Level0) ASSERT_NE(out.data, nullptr); ASSERT_NE(out.len, (const unsigned int)0); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); } @@ -1709,7 +1709,7 @@ HWTEST_F(CryptoEccSignTest, CryptoEccSignTest412, TestSize.Level0) ASSERT_NE(out.data, nullptr); ASSERT_NE(out.len, (const unsigned int)0); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); } @@ -1736,7 +1736,7 @@ HWTEST_F(CryptoEccSignTest, CryptoEccSignTest413, TestSize.Level0) ASSERT_NE(out.data, nullptr); ASSERT_NE(out.len, (const unsigned int)0); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); } @@ -1763,7 +1763,7 @@ HWTEST_F(CryptoEccSignTest, CryptoEccSignTest414, TestSize.Level0) ASSERT_NE(out.data, nullptr); ASSERT_NE(out.len, (const unsigned int)0); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); } @@ -1790,7 +1790,7 @@ HWTEST_F(CryptoEccSignTest, CryptoEccSignTest415, TestSize.Level0) ASSERT_NE(out.data, nullptr); ASSERT_NE(out.len, (const unsigned int)0); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); } @@ -1817,7 +1817,7 @@ HWTEST_F(CryptoEccSignTest, CryptoEccSignTest416, TestSize.Level0) ASSERT_NE(out.data, nullptr); ASSERT_NE(out.len, (const unsigned int)0); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); } @@ -1844,7 +1844,7 @@ HWTEST_F(CryptoEccSignTest, CryptoEccSignTest417, TestSize.Level0) ASSERT_NE(out.data, nullptr); ASSERT_NE(out.len, (const unsigned int)0); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); } @@ -1871,7 +1871,7 @@ HWTEST_F(CryptoEccSignTest, CryptoEccSignTest418, TestSize.Level0) ASSERT_NE(out.data, nullptr); ASSERT_NE(out.len, (const unsigned int)0); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); } @@ -1898,7 +1898,7 @@ HWTEST_F(CryptoEccSignTest, CryptoEccSignTest419, TestSize.Level0) ASSERT_NE(out.data, nullptr); ASSERT_NE(out.len, (const unsigned int)0); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); } @@ -1925,7 +1925,7 @@ HWTEST_F(CryptoEccSignTest, CryptoEccSignTest420, TestSize.Level0) ASSERT_NE(out.data, nullptr); ASSERT_NE(out.len, (const unsigned int)0); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); } @@ -1948,7 +1948,7 @@ HWTEST_F(CryptoEccSignTest, CryptoEccSignTest421, TestSize.Level0) ASSERT_NE(out.data, nullptr); ASSERT_NE(out.len, (const unsigned int)0); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); } @@ -1971,7 +1971,7 @@ HWTEST_F(CryptoEccSignTest, CryptoEccSignTest422, TestSize.Level0) ASSERT_NE(out.data, nullptr); ASSERT_NE(out.len, (const unsigned int)0); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); } @@ -1994,7 +1994,7 @@ HWTEST_F(CryptoEccSignTest, CryptoEccSignTest423, TestSize.Level0) ASSERT_NE(out.data, nullptr); ASSERT_NE(out.len, (const unsigned int)0); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); } @@ -2017,7 +2017,7 @@ HWTEST_F(CryptoEccSignTest, CryptoEccSignTest424, TestSize.Level0) ASSERT_NE(out.data, nullptr); ASSERT_NE(out.len, (const unsigned int)0); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); } @@ -2040,7 +2040,7 @@ HWTEST_F(CryptoEccSignTest, CryptoEccSignTest425, TestSize.Level0) ASSERT_NE(out.data, nullptr); ASSERT_NE(out.len, (const unsigned int)0); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); } @@ -2063,7 +2063,7 @@ HWTEST_F(CryptoEccSignTest, CryptoEccSignTest426, TestSize.Level0) ASSERT_NE(out.data, nullptr); ASSERT_NE(out.len, (const unsigned int)0); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); } @@ -2086,7 +2086,7 @@ HWTEST_F(CryptoEccSignTest, CryptoEccSignTest427, TestSize.Level0) ASSERT_NE(out.data, nullptr); ASSERT_NE(out.len, (const unsigned int)0); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); } @@ -2109,7 +2109,7 @@ HWTEST_F(CryptoEccSignTest, CryptoEccSignTest428, TestSize.Level0) ASSERT_NE(out.data, nullptr); ASSERT_NE(out.len, (const unsigned int)0); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); } @@ -2132,7 +2132,7 @@ HWTEST_F(CryptoEccSignTest, CryptoEccSignTest429, TestSize.Level0) ASSERT_NE(out.data, nullptr); ASSERT_NE(out.len, (const unsigned int)0); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); } @@ -2155,7 +2155,7 @@ HWTEST_F(CryptoEccSignTest, CryptoEccSignTest430, TestSize.Level0) ASSERT_NE(out.data, nullptr); ASSERT_NE(out.len, (const unsigned int)0); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); } @@ -2178,7 +2178,7 @@ HWTEST_F(CryptoEccSignTest, CryptoEccSignTest431, TestSize.Level0) ASSERT_NE(out.data, nullptr); ASSERT_NE(out.len, (const unsigned int)0); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); } @@ -2201,7 +2201,7 @@ HWTEST_F(CryptoEccSignTest, CryptoEccSignTest432, TestSize.Level0) ASSERT_NE(out.data, nullptr); ASSERT_NE(out.len, (const unsigned int)0); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); } @@ -2224,7 +2224,7 @@ HWTEST_F(CryptoEccSignTest, CryptoEccSignTest433, TestSize.Level0) ASSERT_NE(out.data, nullptr); ASSERT_NE(out.len, (const unsigned int)0); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); } @@ -2247,7 +2247,7 @@ HWTEST_F(CryptoEccSignTest, CryptoEccSignTest434, TestSize.Level0) ASSERT_NE(out.data, nullptr); ASSERT_NE(out.len, (const unsigned int)0); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); } @@ -2270,7 +2270,7 @@ HWTEST_F(CryptoEccSignTest, CryptoEccSignTest435, TestSize.Level0) ASSERT_NE(out.data, nullptr); ASSERT_NE(out.len, (const unsigned int)0); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); } @@ -2293,7 +2293,7 @@ HWTEST_F(CryptoEccSignTest, CryptoEccSignTest436, TestSize.Level0) ASSERT_NE(out.data, nullptr); ASSERT_NE(out.len, (const unsigned int)0); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); } @@ -2316,7 +2316,7 @@ HWTEST_F(CryptoEccSignTest, CryptoEccSignTest437, TestSize.Level0) ASSERT_NE(out.data, nullptr); ASSERT_NE(out.len, (const unsigned int)0); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); } @@ -2339,7 +2339,7 @@ HWTEST_F(CryptoEccSignTest, CryptoEccSignTest438, TestSize.Level0) ASSERT_NE(out.data, nullptr); ASSERT_NE(out.len, (const unsigned int)0); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); } @@ -2362,7 +2362,7 @@ HWTEST_F(CryptoEccSignTest, CryptoEccSignTest439, TestSize.Level0) ASSERT_NE(out.data, nullptr); ASSERT_NE(out.len, (const unsigned int)0); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); } @@ -2385,7 +2385,7 @@ HWTEST_F(CryptoEccSignTest, CryptoEccSignTest440, TestSize.Level0) ASSERT_NE(out.data, nullptr); ASSERT_NE(out.len, (const unsigned int)0); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); } @@ -2583,8 +2583,8 @@ HWTEST_F(CryptoEccSignTest, CryptoEccSignTest447, TestSize.Level0) flag = verify->verify(verify, nullptr, &out2); ASSERT_EQ(flag, true); - free(out.data); - free(out2.data); + HcfFree(out.data); + HcfFree(out2.data); HcfObjDestroy(sign); HcfObjDestroy(verify); } @@ -2617,7 +2617,7 @@ HWTEST_F(CryptoEccSignTest, CryptoEccSignTest448, TestSize.Level0) HcfBlob out2 = { .data = nullptr, .len = 0 }; res = sign->sign(sign, nullptr, &out2); - free(out2.data); + HcfFree(out2.data); HcfObjDestroy(sign); } @@ -2656,7 +2656,7 @@ HWTEST_F(CryptoEccSignTest, CryptoEccSignTest927, TestSize.Level0) ASSERT_NE(out.data, nullptr); ASSERT_NE(out.len, (const unsigned int)0); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); } @@ -2697,7 +2697,7 @@ HWTEST_F(CryptoEccSignTest, CryptoEccSignTest928, TestSize.Level0) ASSERT_NE(out.data, nullptr); ASSERT_NE(out.len, (const unsigned int)0); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); } @@ -2939,7 +2939,7 @@ static void MemoryMallocTestFunc(uint32_t mallocCount, HcfBlob *input) HcfObjDestroy(sign); HcfObjDestroy(keyPair); if (res == HCF_SUCCESS) { - free(out.data); + HcfFree(out.data); } } } @@ -2982,7 +2982,7 @@ HWTEST_F(CryptoEccSignTest, CryptoEccSignTest1101, TestSize.Level0) ASSERT_NE(out.data, nullptr); ASSERT_NE(out.len, (const unsigned int)0); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); uint32_t mallocCount = GetMallocNum(); @@ -3033,7 +3033,7 @@ static void OpensslMockTestFunc(uint32_t mallocCount, HcfBlob *input) HcfObjDestroy(sign); HcfObjDestroy(keyPair); if (res == HCF_SUCCESS) { - free(out.data); + HcfFree(out.data); } } } @@ -3076,7 +3076,7 @@ HWTEST_F(CryptoEccSignTest, CryptoEccSignTest1102, TestSize.Level0) ASSERT_NE(out.data, nullptr); ASSERT_NE(out.len, (const unsigned int)0); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); uint32_t mallocCount = GetOpensslCallNum(); diff --git a/test/unittest/src/crypto_ecc_verify_test.cpp b/test/unittest/src/crypto_ecc_verify_test.cpp index 73e5ef844463145da0a509211fd331bd6707892b..21e3da2900dfcf40aa597941ba9f7eb83869cc10 100644 --- a/test/unittest/src/crypto_ecc_verify_test.cpp +++ b/test/unittest/src/crypto_ecc_verify_test.cpp @@ -1430,7 +1430,7 @@ HWTEST_F(CryptoEccVerifyTest, CryptoEccVerifyTest401, TestSize.Level0) ASSERT_EQ(flag, true); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); HcfObjDestroy(verify); } @@ -1476,7 +1476,7 @@ HWTEST_F(CryptoEccVerifyTest, CryptoEccVerifyTest402, TestSize.Level0) ASSERT_EQ(flag, true); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); HcfObjDestroy(verify); } @@ -1522,7 +1522,7 @@ HWTEST_F(CryptoEccVerifyTest, CryptoEccVerifyTest403, TestSize.Level0) ASSERT_EQ(flag, true); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); HcfObjDestroy(verify); } @@ -1568,7 +1568,7 @@ HWTEST_F(CryptoEccVerifyTest, CryptoEccVerifyTest404, TestSize.Level0) ASSERT_EQ(flag, true); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); HcfObjDestroy(verify); } @@ -1614,7 +1614,7 @@ HWTEST_F(CryptoEccVerifyTest, CryptoEccVerifyTest405, TestSize.Level0) ASSERT_EQ(flag, true); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); HcfObjDestroy(verify); } @@ -1660,7 +1660,7 @@ HWTEST_F(CryptoEccVerifyTest, CryptoEccVerifyTest406, TestSize.Level0) ASSERT_EQ(flag, true); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); HcfObjDestroy(verify); } @@ -1706,7 +1706,7 @@ HWTEST_F(CryptoEccVerifyTest, CryptoEccVerifyTest407, TestSize.Level0) ASSERT_EQ(flag, true); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); HcfObjDestroy(verify); } @@ -1752,7 +1752,7 @@ HWTEST_F(CryptoEccVerifyTest, CryptoEccVerifyTest408, TestSize.Level0) ASSERT_EQ(flag, true); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); HcfObjDestroy(verify); } @@ -1798,7 +1798,7 @@ HWTEST_F(CryptoEccVerifyTest, CryptoEccVerifyTest409, TestSize.Level0) ASSERT_EQ(flag, true); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); HcfObjDestroy(verify); } @@ -1844,7 +1844,7 @@ HWTEST_F(CryptoEccVerifyTest, CryptoEccVerifyTest410, TestSize.Level0) ASSERT_EQ(flag, true); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); HcfObjDestroy(verify); } @@ -1890,7 +1890,7 @@ HWTEST_F(CryptoEccVerifyTest, CryptoEccVerifyTest411, TestSize.Level0) ASSERT_EQ(flag, true); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); HcfObjDestroy(verify); } @@ -1936,7 +1936,7 @@ HWTEST_F(CryptoEccVerifyTest, CryptoEccVerifyTest412, TestSize.Level0) ASSERT_EQ(flag, true); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); HcfObjDestroy(verify); } @@ -1982,7 +1982,7 @@ HWTEST_F(CryptoEccVerifyTest, CryptoEccVerifyTest413, TestSize.Level0) ASSERT_EQ(flag, true); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); HcfObjDestroy(verify); } @@ -2028,7 +2028,7 @@ HWTEST_F(CryptoEccVerifyTest, CryptoEccVerifyTest414, TestSize.Level0) ASSERT_EQ(flag, true); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); HcfObjDestroy(verify); } @@ -2074,7 +2074,7 @@ HWTEST_F(CryptoEccVerifyTest, CryptoEccVerifyTest415, TestSize.Level0) ASSERT_EQ(flag, true); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); HcfObjDestroy(verify); } @@ -2120,7 +2120,7 @@ HWTEST_F(CryptoEccVerifyTest, CryptoEccVerifyTest416, TestSize.Level0) ASSERT_EQ(flag, true); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); HcfObjDestroy(verify); } @@ -2166,7 +2166,7 @@ HWTEST_F(CryptoEccVerifyTest, CryptoEccVerifyTest417, TestSize.Level0) ASSERT_EQ(flag, true); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); HcfObjDestroy(verify); } @@ -2212,7 +2212,7 @@ HWTEST_F(CryptoEccVerifyTest, CryptoEccVerifyTest418, TestSize.Level0) ASSERT_EQ(flag, true); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); HcfObjDestroy(verify); } @@ -2258,7 +2258,7 @@ HWTEST_F(CryptoEccVerifyTest, CryptoEccVerifyTest419, TestSize.Level0) ASSERT_EQ(flag, true); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); HcfObjDestroy(verify); } @@ -2304,7 +2304,7 @@ HWTEST_F(CryptoEccVerifyTest, CryptoEccVerifyTest420, TestSize.Level0) ASSERT_EQ(flag, true); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); HcfObjDestroy(verify); } @@ -2342,7 +2342,7 @@ HWTEST_F(CryptoEccVerifyTest, CryptoEccVerifyTest421, TestSize.Level0) ASSERT_EQ(flag, true); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); HcfObjDestroy(verify); } @@ -2380,7 +2380,7 @@ HWTEST_F(CryptoEccVerifyTest, CryptoEccVerifyTest422, TestSize.Level0) ASSERT_EQ(flag, true); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); HcfObjDestroy(verify); } @@ -2418,7 +2418,7 @@ HWTEST_F(CryptoEccVerifyTest, CryptoEccVerifyTest423, TestSize.Level0) ASSERT_EQ(flag, true); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); HcfObjDestroy(verify); } @@ -2456,7 +2456,7 @@ HWTEST_F(CryptoEccVerifyTest, CryptoEccVerifyTest424, TestSize.Level0) ASSERT_EQ(flag, true); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); HcfObjDestroy(verify); } @@ -2494,7 +2494,7 @@ HWTEST_F(CryptoEccVerifyTest, CryptoEccVerifyTest425, TestSize.Level0) ASSERT_EQ(flag, true); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); HcfObjDestroy(verify); } @@ -2532,7 +2532,7 @@ HWTEST_F(CryptoEccVerifyTest, CryptoEccVerifyTest426, TestSize.Level0) ASSERT_EQ(flag, true); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); HcfObjDestroy(verify); } @@ -2570,7 +2570,7 @@ HWTEST_F(CryptoEccVerifyTest, CryptoEccVerifyTest427, TestSize.Level0) ASSERT_EQ(flag, true); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); HcfObjDestroy(verify); } @@ -2608,7 +2608,7 @@ HWTEST_F(CryptoEccVerifyTest, CryptoEccVerifyTest428, TestSize.Level0) ASSERT_EQ(flag, true); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); HcfObjDestroy(verify); } @@ -2646,7 +2646,7 @@ HWTEST_F(CryptoEccVerifyTest, CryptoEccVerifyTest429, TestSize.Level0) ASSERT_EQ(flag, true); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); HcfObjDestroy(verify); } @@ -2684,7 +2684,7 @@ HWTEST_F(CryptoEccVerifyTest, CryptoEccVerifyTest430, TestSize.Level0) ASSERT_EQ(flag, true); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); HcfObjDestroy(verify); } @@ -2722,7 +2722,7 @@ HWTEST_F(CryptoEccVerifyTest, CryptoEccVerifyTest431, TestSize.Level0) ASSERT_EQ(flag, true); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); HcfObjDestroy(verify); } @@ -2760,7 +2760,7 @@ HWTEST_F(CryptoEccVerifyTest, CryptoEccVerifyTest432, TestSize.Level0) ASSERT_EQ(flag, true); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); HcfObjDestroy(verify); } @@ -2798,7 +2798,7 @@ HWTEST_F(CryptoEccVerifyTest, CryptoEccVerifyTest433, TestSize.Level0) ASSERT_EQ(flag, true); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); HcfObjDestroy(verify); } @@ -2836,7 +2836,7 @@ HWTEST_F(CryptoEccVerifyTest, CryptoEccVerifyTest434, TestSize.Level0) ASSERT_EQ(flag, true); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); HcfObjDestroy(verify); } @@ -2874,7 +2874,7 @@ HWTEST_F(CryptoEccVerifyTest, CryptoEccVerifyTest435, TestSize.Level0) ASSERT_EQ(flag, true); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); HcfObjDestroy(verify); } @@ -2912,7 +2912,7 @@ HWTEST_F(CryptoEccVerifyTest, CryptoEccVerifyTest436, TestSize.Level0) ASSERT_EQ(flag, true); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); HcfObjDestroy(verify); } @@ -2950,7 +2950,7 @@ HWTEST_F(CryptoEccVerifyTest, CryptoEccVerifyTest437, TestSize.Level0) ASSERT_EQ(flag, true); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); HcfObjDestroy(verify); } @@ -2988,7 +2988,7 @@ HWTEST_F(CryptoEccVerifyTest, CryptoEccVerifyTest438, TestSize.Level0) ASSERT_EQ(flag, true); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); HcfObjDestroy(verify); } @@ -3026,7 +3026,7 @@ HWTEST_F(CryptoEccVerifyTest, CryptoEccVerifyTest439, TestSize.Level0) ASSERT_EQ(flag, true); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); HcfObjDestroy(verify); } @@ -3064,7 +3064,7 @@ HWTEST_F(CryptoEccVerifyTest, CryptoEccVerifyTest440, TestSize.Level0) ASSERT_EQ(flag, true); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); HcfObjDestroy(verify); } @@ -3110,7 +3110,7 @@ HWTEST_F(CryptoEccVerifyTest, CryptoEccVerifyTest441, TestSize.Level0) ASSERT_EQ(flag, false); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); HcfObjDestroy(verify); } @@ -3156,7 +3156,7 @@ HWTEST_F(CryptoEccVerifyTest, CryptoEccVerifyTest442, TestSize.Level0) ASSERT_EQ(flag, false); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); HcfObjDestroy(verify); } @@ -3198,7 +3198,7 @@ HWTEST_F(CryptoEccVerifyTest, CryptoEccVerifyTest443, TestSize.Level0) ASSERT_EQ(flag, false); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); HcfObjDestroy(verify); } @@ -3244,7 +3244,7 @@ HWTEST_F(CryptoEccVerifyTest, CryptoEccVerifyTest444, TestSize.Level0) ASSERT_EQ(flag, false); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); HcfObjDestroy(verify); } @@ -3290,7 +3290,7 @@ HWTEST_F(CryptoEccVerifyTest, CryptoEccVerifyTest445, TestSize.Level0) ASSERT_EQ(flag, false); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); HcfObjDestroy(verify); } diff --git a/test/unittest/src/crypto_ed25519_asy_key_generator_by_spec_test.cpp b/test/unittest/src/crypto_ed25519_asy_key_generator_by_spec_test.cpp index 0ef9ad87734d16a1272e795f2d20c0310e384a2c..a8fa229c83c286cdce755f0a28541aa56fde80dc 100644 --- a/test/unittest/src/crypto_ed25519_asy_key_generator_by_spec_test.cpp +++ b/test/unittest/src/crypto_ed25519_asy_key_generator_by_spec_test.cpp @@ -16,6 +16,7 @@ #include #include +#include "alg_25519_common_param_spec.h" #include "asy_key_generator.h" #include "blob.h" #include "ecdsa_openssl.h" @@ -25,7 +26,6 @@ #include "asy_key_params.h" #include "params_parser.h" #include "alg_25519_asy_key_generator_openssl.h" -#include "detailed_alg_25519_key_params.h" #include "memory_mock.h" #include "openssl_adapter_mock.h" @@ -35,8 +35,8 @@ using namespace testing::ext; namespace { class CryptoEd25519AsyKeyGeneratorBySpecTest : public testing::Test { public: - static void SetUpTestCase(); - static void TearDownTestCase(); + static void SetUpTestCase() {}; + static void TearDownTestCase() {}; void SetUp(); void TearDown(); }; @@ -46,14 +46,8 @@ static string g_pubkeyformatName = "X.509"; static string g_prikeyformatName = "PKCS#8"; static string g_algorithmName = "Alg25519"; -HcfAlg25519KeyPairParamsSpec g_ed25519KeyPairSpec; -HcfAlg25519PriKeyParamsSpec g_ed25519PriKeySpec; -HcfAlg25519PubKeyParamsSpec g_ed25519PubKeySpec; - void CryptoEd25519AsyKeyGeneratorBySpecTest::SetUp() {} void CryptoEd25519AsyKeyGeneratorBySpecTest::TearDown() {} -void CryptoEd25519AsyKeyGeneratorBySpecTest::SetUpTestCase() {} -void CryptoEd25519AsyKeyGeneratorBySpecTest::TearDownTestCase() {} static const char *g_mockMessage = "hello world"; static HcfBlob g_mockInput = { @@ -70,114 +64,10 @@ HcfObjectBase g_obj = { .destroy = nullptr }; -static HcfResult ConstructEd25519KeyPairParamsSpec(const string &algoName, HcfAsyKeyParamsSpec **spec) -{ - HcfAsyKeyGenerator *generator = nullptr; - HcfResult res = HcfAsyKeyGeneratorCreate(algoName.c_str(), &generator); - if (res != HCF_SUCCESS) { - return res; - } - HcfKeyPair *keyPair = nullptr; - res = generator->generateKeyPair(generator, nullptr, &keyPair); - if (res != HCF_SUCCESS) { - HcfObjDestroy(generator); - return res; - } - HcfAlg25519KeyPairParamsSpec *ed25519KeyPairSpec = &g_ed25519KeyPairSpec; - HcfBigInteger retBigInt = { .data = nullptr, .len = 0 }; - ed25519KeyPairSpec->base.algName = g_ed25519AlgoName.data(); - ed25519KeyPairSpec->base.specType = HCF_KEY_PAIR_SPEC; - res = keyPair->pubKey->getAsyKeySpecBigInteger(keyPair->pubKey, ED25519_PK_BN, &retBigInt); - if (res != HCF_SUCCESS) { - HcfObjDestroy(generator); - HcfObjDestroy(keyPair); - return res; - } - ed25519KeyPairSpec->pk.data = retBigInt.data; - ed25519KeyPairSpec->pk.len = retBigInt.len; - res = keyPair->priKey->getAsyKeySpecBigInteger(keyPair->priKey, ED25519_SK_BN, &retBigInt); - if (res != HCF_SUCCESS) { - HcfObjDestroy(generator); - HcfObjDestroy(keyPair); - return res; - } - ed25519KeyPairSpec->sk.data = retBigInt.data; - ed25519KeyPairSpec->sk.len = retBigInt.len; - *spec = (HcfAsyKeyParamsSpec *)ed25519KeyPairSpec; - HcfObjDestroy(generator); - HcfObjDestroy(keyPair); - return HCF_SUCCESS; -} - -static HcfResult ConstructEd25519PubKeyParamsSpec(const string &algoName, HcfAsyKeyParamsSpec **spec) -{ - HcfAsyKeyGenerator *generator = nullptr; - HcfResult res = HcfAsyKeyGeneratorCreate(algoName.c_str(), &generator); - if (res != HCF_SUCCESS) { - return res; - } - HcfKeyPair *keyPair = nullptr; - res = generator->generateKeyPair(generator, nullptr, &keyPair); - if (res != HCF_SUCCESS) { - return res; - } - HcfAlg25519PubKeyParamsSpec *ed25519PubKeySpec = &g_ed25519PubKeySpec; - HcfBigInteger retBigInt = { .data = nullptr, .len = 0 }; - ed25519PubKeySpec->base.algName = g_ed25519AlgoName.data(); - ed25519PubKeySpec->base.specType = HCF_PUBLIC_KEY_SPEC; - res = keyPair->pubKey->getAsyKeySpecBigInteger(keyPair->pubKey, ED25519_PK_BN, &retBigInt); - if (res != HCF_SUCCESS) { - HcfObjDestroy(generator); - HcfObjDestroy(keyPair); - return res; - } - ed25519PubKeySpec->pk.data = retBigInt.data; - ed25519PubKeySpec->pk.len = retBigInt.len; - *spec = (HcfAsyKeyParamsSpec *)ed25519PubKeySpec; - HcfObjDestroy(generator); - HcfObjDestroy(keyPair); - return HCF_SUCCESS; -} - -static HcfResult ConstructEd25519PriKeyParamsSpec(const string &algoName, HcfAsyKeyParamsSpec **spec) -{ - HcfAsyKeyGenerator *generator = nullptr; - HcfResult res = HcfAsyKeyGeneratorCreate(algoName.c_str(), &generator); - if (res != HCF_SUCCESS) { - return res; - } - - HcfKeyPair *keyPair = nullptr; - res = generator->generateKeyPair(generator, nullptr, &keyPair); - if (res != HCF_SUCCESS) { - HcfObjDestroy(generator); - return res; - } - - HcfAlg25519PriKeyParamsSpec *ed25519PriKeySpec = &g_ed25519PriKeySpec; - HcfBigInteger retBigInt = { .data = nullptr, .len = 0 }; - - ed25519PriKeySpec->base.algName = g_ed25519AlgoName.data(); - ed25519PriKeySpec->base.specType = HCF_PRIVATE_KEY_SPEC; - res = keyPair->priKey->getAsyKeySpecBigInteger(keyPair->priKey, ED25519_SK_BN, &retBigInt); - if (res != HCF_SUCCESS) { - HcfObjDestroy(generator); - HcfObjDestroy(keyPair); - return res; - } - ed25519PriKeySpec->sk.data = retBigInt.data; - ed25519PriKeySpec->sk.len = retBigInt.len; - - *spec = (HcfAsyKeyParamsSpec *)ed25519PriKeySpec; - HcfObjDestroy(generator); - HcfObjDestroy(keyPair); - return HCF_SUCCESS; -} - HWTEST_F(CryptoEd25519AsyKeyGeneratorBySpecTest, CryptoEd25519AsyKeyGeneratorBySpecTest001_1, TestSize.Level0) { HcfAsyKeyParamsSpec *paramSpec = nullptr; - HcfResult res = ConstructEd25519KeyPairParamsSpec(g_ed25519AlgoName, ¶mSpec); + HcfResult res = ConstructAlg25519KeyPairParamsSpec(g_ed25519AlgoName.c_str(), true, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); @@ -185,12 +75,13 @@ HWTEST_F(CryptoEd25519AsyKeyGeneratorBySpecTest, CryptoEd25519AsyKeyGeneratorByS res = HcfAsyKeyGeneratorBySpecCreate(paramSpec, &returnObj); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(returnObj, nullptr); + DestroyAlg25519KeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoEd25519AsyKeyGeneratorBySpecTest, CryptoEd25519AsyKeyGeneratorBySpecTest001_2, TestSize.Level0) { HcfAsyKeyParamsSpec *paramSpec = nullptr; - HcfResult res = ConstructEd25519PubKeyParamsSpec(g_ed25519AlgoName, ¶mSpec); + HcfResult res = ConstructAlg25519PubKeyParamsSpec(g_ed25519AlgoName.c_str(), true, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); @@ -198,12 +89,13 @@ HWTEST_F(CryptoEd25519AsyKeyGeneratorBySpecTest, CryptoEd25519AsyKeyGeneratorByS res = HcfAsyKeyGeneratorBySpecCreate(paramSpec, &returnObj); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(returnObj, nullptr); + DestroyAlg25519PubKeySpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoEd25519AsyKeyGeneratorBySpecTest, CryptoEd25519AsyKeyGeneratorBySpecTest001_3, TestSize.Level0) { HcfAsyKeyParamsSpec *paramSpec = nullptr; - HcfResult res = ConstructEd25519PriKeyParamsSpec(g_ed25519AlgoName, ¶mSpec); + HcfResult res = ConstructAlg25519PriKeyParamsSpec(g_ed25519AlgoName.c_str(), true, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); @@ -211,12 +103,13 @@ HWTEST_F(CryptoEd25519AsyKeyGeneratorBySpecTest, CryptoEd25519AsyKeyGeneratorByS res = HcfAsyKeyGeneratorBySpecCreate(paramSpec, &returnObj); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(returnObj, nullptr); + DestroyAlg25519PriKeySpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoEd25519AsyKeyGeneratorBySpecTest, CryptoEd25519AsyKeyGeneratorBySpecTest002, TestSize.Level0) { HcfAsyKeyParamsSpec *paramSpec = nullptr; - HcfResult res = ConstructEd25519KeyPairParamsSpec(g_ed25519AlgoName, ¶mSpec); + HcfResult res = ConstructAlg25519KeyPairParamsSpec(g_ed25519AlgoName.c_str(), true, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); @@ -228,12 +121,13 @@ HWTEST_F(CryptoEd25519AsyKeyGeneratorBySpecTest, CryptoEd25519AsyKeyGeneratorByS const char *className = returnObj->base.getClass(); ASSERT_NE(className, NULL); ASSERT_NE(returnObj, nullptr); + DestroyAlg25519KeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoEd25519AsyKeyGeneratorBySpecTest, CryptoEd25519AsyKeyGeneratorBySpecTest003, TestSize.Level0) { HcfAsyKeyParamsSpec *paramSpec = nullptr; - HcfResult res = ConstructEd25519KeyPairParamsSpec(g_ed25519AlgoName, ¶mSpec); + HcfResult res = ConstructAlg25519KeyPairParamsSpec(g_ed25519AlgoName.c_str(), true, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); @@ -243,14 +137,14 @@ HWTEST_F(CryptoEd25519AsyKeyGeneratorBySpecTest, CryptoEd25519AsyKeyGeneratorByS ASSERT_NE(returnObj, nullptr); returnObj->base.destroy(&g_obj); - HcfObjDestroy(returnObj); + DestroyAlg25519KeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoEd25519AsyKeyGeneratorBySpecTest, CryptoEd25519AsyKeyGeneratorBySpecTest004, TestSize.Level0) { HcfAsyKeyParamsSpec *paramSpec = nullptr; - HcfResult res = ConstructEd25519KeyPairParamsSpec(g_ed25519AlgoName, ¶mSpec); + HcfResult res = ConstructAlg25519KeyPairParamsSpec(g_ed25519AlgoName.c_str(), true, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); @@ -260,17 +154,17 @@ HWTEST_F(CryptoEd25519AsyKeyGeneratorBySpecTest, CryptoEd25519AsyKeyGeneratorByS ASSERT_NE(returnObj, nullptr); const char *algoName = returnObj->getAlgName(returnObj); - ASSERT_EQ(res, HCF_SUCCESS); ASSERT_EQ(algoName, g_ed25519AlgoName); HcfObjDestroy(returnObj); + DestroyAlg25519KeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoEd25519AsyKeyGeneratorBySpecTest, CryptoEd25519AsyKeyGeneratorBySpecTest005, TestSize.Level0) { HcfAsyKeyParamsSpec *paramSpec = nullptr; - HcfResult res = ConstructEd25519KeyPairParamsSpec(g_ed25519AlgoName, ¶mSpec); + HcfResult res = ConstructAlg25519KeyPairParamsSpec(g_ed25519AlgoName.c_str(), true, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); @@ -287,12 +181,13 @@ HWTEST_F(CryptoEd25519AsyKeyGeneratorBySpecTest, CryptoEd25519AsyKeyGeneratorByS HcfObjDestroy(keyPair); HcfObjDestroy(returnObj); + DestroyAlg25519KeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoEd25519AsyKeyGeneratorBySpecTest, CryptoEd25519AsyKeyGeneratorBySpecTest006, TestSize.Level0) { HcfAsyKeyParamsSpec *paramSpec = nullptr; - HcfResult res = ConstructEd25519KeyPairParamsSpec(g_ed25519AlgoName, ¶mSpec); + HcfResult res = ConstructAlg25519KeyPairParamsSpec(g_ed25519AlgoName.c_str(), true, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); @@ -312,12 +207,13 @@ HWTEST_F(CryptoEd25519AsyKeyGeneratorBySpecTest, CryptoEd25519AsyKeyGeneratorByS HcfObjDestroy(keyPair); HcfObjDestroy(returnObj); + DestroyAlg25519KeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoEd25519AsyKeyGeneratorBySpecTest, CryptoEd25519AsyKeyGeneratorBySpecTest007, TestSize.Level0) { HcfAsyKeyParamsSpec *paramSpec = nullptr; - HcfResult res = ConstructEd25519KeyPairParamsSpec(g_ed25519AlgoName, ¶mSpec); + HcfResult res = ConstructAlg25519KeyPairParamsSpec(g_ed25519AlgoName.c_str(), true, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); @@ -333,14 +229,14 @@ HWTEST_F(CryptoEd25519AsyKeyGeneratorBySpecTest, CryptoEd25519AsyKeyGeneratorByS ASSERT_NE(keyPair, nullptr); keyPair->base.destroy(&(keyPair->base)); - HcfObjDestroy(returnObj); + DestroyAlg25519KeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoEd25519AsyKeyGeneratorBySpecTest, CryptoEd25519AsyKeyGeneratorBySpecTest008, TestSize.Level0) { HcfAsyKeyParamsSpec *paramSpec = nullptr; - HcfResult res = ConstructEd25519KeyPairParamsSpec(g_ed25519AlgoName, ¶mSpec); + HcfResult res = ConstructAlg25519KeyPairParamsSpec(g_ed25519AlgoName.c_str(), true, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); @@ -359,12 +255,13 @@ HWTEST_F(CryptoEd25519AsyKeyGeneratorBySpecTest, CryptoEd25519AsyKeyGeneratorByS HcfObjDestroy(keyPair); HcfObjDestroy(returnObj); + DestroyAlg25519KeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoEd25519AsyKeyGeneratorBySpecTest, CryptoEd25519AsyKeyGeneratorBySpecTest009, TestSize.Level0) { HcfAsyKeyParamsSpec *paramSpec = nullptr; - HcfResult res = ConstructEd25519KeyPairParamsSpec(g_ed25519AlgoName, ¶mSpec); + HcfResult res = ConstructAlg25519KeyPairParamsSpec(g_ed25519AlgoName.c_str(), true, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); @@ -382,12 +279,13 @@ HWTEST_F(CryptoEd25519AsyKeyGeneratorBySpecTest, CryptoEd25519AsyKeyGeneratorByS keyPair->pubKey = nullptr; HcfObjDestroy(keyPair); HcfObjDestroy(returnObj); + DestroyAlg25519KeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoEd25519AsyKeyGeneratorBySpecTest, CryptoEd25519AsyKeyGeneratorBySpecTest010, TestSize.Level0) { HcfAsyKeyParamsSpec *paramSpec = nullptr; - HcfResult res = ConstructEd25519KeyPairParamsSpec(g_ed25519AlgoName, ¶mSpec); + HcfResult res = ConstructAlg25519KeyPairParamsSpec(g_ed25519AlgoName.c_str(), true, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); @@ -415,12 +313,13 @@ HWTEST_F(CryptoEd25519AsyKeyGeneratorBySpecTest, CryptoEd25519AsyKeyGeneratorByS HcfObjDestroy(keyPair); HcfObjDestroy(returnObj); + DestroyAlg25519KeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoEd25519AsyKeyGeneratorBySpecTest, CryptoEd25519AsyKeyGeneratorBySpecTest011, TestSize.Level0) { HcfAsyKeyParamsSpec *paramSpec = nullptr; - HcfResult res = ConstructEd25519KeyPairParamsSpec(g_ed25519AlgoName, ¶mSpec); + HcfResult res = ConstructAlg25519KeyPairParamsSpec(g_ed25519AlgoName.c_str(), true, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); @@ -439,12 +338,13 @@ HWTEST_F(CryptoEd25519AsyKeyGeneratorBySpecTest, CryptoEd25519AsyKeyGeneratorByS HcfObjDestroy(keyPair); HcfObjDestroy(returnObj); + DestroyAlg25519KeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoEd25519AsyKeyGeneratorBySpecTest, CryptoEd25519AsyKeyGeneratorBySpecTest012, TestSize.Level0) { HcfAsyKeyParamsSpec *paramSpec = nullptr; - HcfResult res = ConstructEd25519KeyPairParamsSpec(g_ed25519AlgoName, ¶mSpec); + HcfResult res = ConstructAlg25519KeyPairParamsSpec(g_ed25519AlgoName.c_str(), true, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); @@ -462,12 +362,13 @@ HWTEST_F(CryptoEd25519AsyKeyGeneratorBySpecTest, CryptoEd25519AsyKeyGeneratorByS keyPair->priKey = nullptr; HcfObjDestroy(keyPair); HcfObjDestroy(returnObj); + DestroyAlg25519KeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoEd25519AsyKeyGeneratorBySpecTest, CryptoEd25519AsyKeyGeneratorBySpecTest013, TestSize.Level0) { HcfAsyKeyParamsSpec *paramSpec = nullptr; - HcfResult res = ConstructEd25519KeyPairParamsSpec(g_ed25519AlgoName, ¶mSpec); + HcfResult res = ConstructAlg25519KeyPairParamsSpec(g_ed25519AlgoName.c_str(), true, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); @@ -495,12 +396,13 @@ HWTEST_F(CryptoEd25519AsyKeyGeneratorBySpecTest, CryptoEd25519AsyKeyGeneratorByS HcfObjDestroy(keyPair); HcfObjDestroy(returnObj); + DestroyAlg25519KeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoEd25519AsyKeyGeneratorBySpecTest, CryptoEd25519AsyKeyGeneratorBySpecTest014, TestSize.Level0) { HcfAsyKeyParamsSpec *paramSpec = nullptr; - HcfResult res = ConstructEd25519KeyPairParamsSpec(g_ed25519AlgoName, ¶mSpec); + HcfResult res = ConstructAlg25519KeyPairParamsSpec(g_ed25519AlgoName.c_str(), true, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); @@ -523,17 +425,18 @@ HWTEST_F(CryptoEd25519AsyKeyGeneratorBySpecTest, CryptoEd25519AsyKeyGeneratorByS HcfFree(blob.data); HcfObjDestroy(keyPair); HcfObjDestroy(returnObj); + DestroyAlg25519KeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoEd25519AsyKeyGeneratorBySpecTest, CryptoEd25519AsyKeyGeneratorBySpecTest015, TestSize.Level0) { HcfAsyKeyParamsSpec *pubparamSpec = nullptr; - HcfResult res = ConstructEd25519PubKeyParamsSpec(g_ed25519AlgoName, &pubparamSpec); + HcfResult res = ConstructAlg25519PubKeyParamsSpec(g_ed25519AlgoName.c_str(), true, &pubparamSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(pubparamSpec, nullptr); HcfAsyKeyParamsSpec *priparamSpec = nullptr; - res = ConstructEd25519PriKeyParamsSpec(g_ed25519AlgoName, &priparamSpec); + res = ConstructAlg25519PriKeyParamsSpec(g_ed25519AlgoName.c_str(), true, &priparamSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(priparamSpec, nullptr); @@ -572,12 +475,14 @@ HWTEST_F(CryptoEd25519AsyKeyGeneratorBySpecTest, CryptoEd25519AsyKeyGeneratorByS HcfObjDestroy(priKey); HcfObjDestroy(returnpubObj); HcfObjDestroy(returnpriObj); + DestroyAlg25519PubKeySpec(reinterpret_cast(pubparamSpec)); + DestroyAlg25519PriKeySpec(reinterpret_cast(priparamSpec)); } HWTEST_F(CryptoEd25519AsyKeyGeneratorBySpecTest, CryptoEd25519AsyKeyGeneratorBySpecTest016, TestSize.Level0) { HcfAsyKeyParamsSpec *paramSpec = nullptr; - HcfResult res = ConstructEd25519KeyPairParamsSpec(g_ed25519AlgoName, ¶mSpec); + HcfResult res = ConstructAlg25519KeyPairParamsSpec(g_ed25519AlgoName.c_str(), true, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); @@ -618,6 +523,7 @@ HWTEST_F(CryptoEd25519AsyKeyGeneratorBySpecTest, CryptoEd25519AsyKeyGeneratorByS HcfObjDestroy(verify); HcfObjDestroy(keyPair); HcfObjDestroy(returnObj); + DestroyAlg25519KeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoEd25519AsyKeyGeneratorBySpecTest, CryptoEd25519AsyKeyGeneratorBySpecTest017, TestSize.Level0) @@ -651,7 +557,7 @@ HWTEST_F(CryptoEd25519AsyKeyGeneratorBySpecTest, CryptoEd25519AsyKeyGeneratorByS ASSERT_NE(returnSpi, nullptr); HcfAsyKeyParamsSpec *paramsSpec = nullptr; - res = ConstructEd25519KeyPairParamsSpec("Ed25519", ¶msSpec); + res = ConstructAlg25519KeyPairParamsSpec(g_ed25519AlgoName.c_str(), true, ¶msSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(returnSpi, nullptr); @@ -662,6 +568,7 @@ HWTEST_F(CryptoEd25519AsyKeyGeneratorBySpecTest, CryptoEd25519AsyKeyGeneratorByS HcfObjDestroy(returnSpi); HcfObjDestroy(keyPair); + DestroyAlg25519KeyPairSpec(reinterpret_cast(paramsSpec)); } HWTEST_F(CryptoEd25519AsyKeyGeneratorBySpecTest, CryptoEd25519AsyKeyGeneratorBySpecTest019, TestSize.Level0) @@ -679,7 +586,7 @@ HWTEST_F(CryptoEd25519AsyKeyGeneratorBySpecTest, CryptoEd25519AsyKeyGeneratorByS ASSERT_NE(returnSpi, nullptr); HcfAsyKeyParamsSpec *paramsSpec = nullptr; - res = ConstructEd25519PubKeyParamsSpec("Ed25519", ¶msSpec); + res = ConstructAlg25519PubKeyParamsSpec(g_ed25519AlgoName.c_str(), true, ¶msSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(returnSpi, nullptr); @@ -690,6 +597,7 @@ HWTEST_F(CryptoEd25519AsyKeyGeneratorBySpecTest, CryptoEd25519AsyKeyGeneratorByS HcfObjDestroy(returnSpi); HcfObjDestroy(pubKey); + DestroyAlg25519PubKeySpec(reinterpret_cast(paramsSpec)); } HWTEST_F(CryptoEd25519AsyKeyGeneratorBySpecTest, CryptoEd25519AsyKeyGeneratorBySpecTest020, TestSize.Level0) @@ -707,7 +615,7 @@ HWTEST_F(CryptoEd25519AsyKeyGeneratorBySpecTest, CryptoEd25519AsyKeyGeneratorByS ASSERT_NE(returnSpi, nullptr); HcfAsyKeyParamsSpec *paramsSpec = nullptr; - res = ConstructEd25519PriKeyParamsSpec("Ed25519", ¶msSpec); + res = ConstructAlg25519PriKeyParamsSpec(g_ed25519AlgoName.c_str(), true, ¶msSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(returnSpi, nullptr); @@ -718,12 +626,13 @@ HWTEST_F(CryptoEd25519AsyKeyGeneratorBySpecTest, CryptoEd25519AsyKeyGeneratorByS HcfObjDestroy(returnSpi); HcfObjDestroy(priKey); + DestroyAlg25519PriKeySpec(reinterpret_cast(paramsSpec)); } HWTEST_F(CryptoEd25519AsyKeyGeneratorBySpecTest, CryptoEd25519AsyKeyGeneratorBySpecTest021, TestSize.Level0) { HcfAsyKeyParamsSpec *paramSpec = nullptr; - HcfResult res = ConstructEd25519PubKeyParamsSpec(g_ed25519AlgoName, ¶mSpec); + HcfResult res = ConstructAlg25519PubKeyParamsSpec(g_ed25519AlgoName.c_str(), true, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); @@ -745,12 +654,13 @@ HWTEST_F(CryptoEd25519AsyKeyGeneratorBySpecTest, CryptoEd25519AsyKeyGeneratorByS HcfObjDestroy(returnObj); HcfObjDestroy(priKey); HcfObjDestroy(keyPair); + DestroyAlg25519PubKeySpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoEd25519AsyKeyGeneratorBySpecTest, CryptoEd25519AsyKeyGeneratorBySpecTest022, TestSize.Level0) { HcfAsyKeyParamsSpec *paramSpec = nullptr; - HcfResult res = ConstructEd25519PriKeyParamsSpec(g_ed25519AlgoName, ¶mSpec); + HcfResult res = ConstructAlg25519PriKeyParamsSpec(g_ed25519AlgoName.c_str(), true, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); @@ -772,6 +682,7 @@ HWTEST_F(CryptoEd25519AsyKeyGeneratorBySpecTest, CryptoEd25519AsyKeyGeneratorByS HcfObjDestroy(returnObj); HcfObjDestroy(keyPair); HcfObjDestroy(pubKey); + DestroyAlg25519PriKeySpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoEd25519AsyKeyGeneratorBySpecTest, CryptoEd25519AsyKeyGeneratorBySpecTest023, TestSize.Level0) @@ -793,7 +704,7 @@ HWTEST_F(CryptoEd25519AsyKeyGeneratorBySpecTest, CryptoEd25519AsyKeyGeneratorByS ASSERT_NE(blob1.len, 0); HcfAsyKeyParamsSpec *paramSpec = nullptr; - res = ConstructEd25519PubKeyParamsSpec(g_ed25519AlgoName, ¶mSpec); + res = ConstructAlg25519PubKeyParamsSpec(g_ed25519AlgoName.c_str(), true, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); @@ -821,6 +732,7 @@ HWTEST_F(CryptoEd25519AsyKeyGeneratorBySpecTest, CryptoEd25519AsyKeyGeneratorByS HcfObjDestroy(returnObj); HcfObjDestroy(pubKey); HcfObjDestroy(keyPair); + DestroyAlg25519PubKeySpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoEd25519AsyKeyGeneratorBySpecTest, CryptoEd25519AsyKeyGeneratorBySpecTest024, TestSize.Level0) @@ -842,7 +754,7 @@ HWTEST_F(CryptoEd25519AsyKeyGeneratorBySpecTest, CryptoEd25519AsyKeyGeneratorByS ASSERT_NE(blob1.len, 0); HcfAsyKeyParamsSpec *paramSpec = nullptr; - res = ConstructEd25519PriKeyParamsSpec(g_ed25519AlgoName, ¶mSpec); + res = ConstructAlg25519PriKeyParamsSpec(g_ed25519AlgoName.c_str(), true, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); @@ -870,12 +782,13 @@ HWTEST_F(CryptoEd25519AsyKeyGeneratorBySpecTest, CryptoEd25519AsyKeyGeneratorByS HcfObjDestroy(returnObj); HcfObjDestroy(priKey); HcfObjDestroy(keyPair); + DestroyAlg25519PriKeySpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoEd25519AsyKeyGeneratorBySpecTest, CryptoEd25519AsyKeyGeneratorBySpecTest025, TestSize.Level0) { HcfAsyKeyParamsSpec *paramSpec = nullptr; - HcfResult res = ConstructEd25519PriKeyParamsSpec(g_ed25519AlgoName, ¶mSpec); + HcfResult res = ConstructAlg25519PriKeyParamsSpec(g_ed25519AlgoName.c_str(), true, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); @@ -906,12 +819,13 @@ HWTEST_F(CryptoEd25519AsyKeyGeneratorBySpecTest, CryptoEd25519AsyKeyGeneratorByS HcfObjDestroy(returnObj); HcfObjDestroy(priKey); HcfObjDestroy(keyPair); + DestroyAlg25519PriKeySpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoEd25519AsyKeyGeneratorBySpecTest, CryptoEd25519AsyKeyGeneratorBySpecTest026, TestSize.Level0) { HcfAsyKeyParamsSpec *paramSpec = nullptr; - HcfResult res = ConstructEd25519PubKeyParamsSpec(g_ed25519AlgoName, ¶mSpec); + HcfResult res = ConstructAlg25519PubKeyParamsSpec(g_ed25519AlgoName.c_str(), true, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); @@ -941,5 +855,6 @@ HWTEST_F(CryptoEd25519AsyKeyGeneratorBySpecTest, CryptoEd25519AsyKeyGeneratorByS HcfObjDestroy(returnObj); HcfObjDestroy(pubKey); HcfObjDestroy(keyPair); + DestroyAlg25519PubKeySpec(reinterpret_cast(paramSpec)); } } \ No newline at end of file diff --git a/test/unittest/src/crypto_ed25519_sign_test.cpp b/test/unittest/src/crypto_ed25519_sign_test.cpp index a3d51e73f98aa4a8cda75c428df361188d25db67..a63d9c7c2212a880f19da9fc1ac648738560d10e 100644 --- a/test/unittest/src/crypto_ed25519_sign_test.cpp +++ b/test/unittest/src/crypto_ed25519_sign_test.cpp @@ -464,7 +464,7 @@ HWTEST_F(CryptoEd25519SignTest, CryptoEd25519SignTest014, TestSize.Level0) ASSERT_EQ(ret, HCF_SUCCESS); ASSERT_NE(sign, nullptr); - int32_t returnInt = 1; + int32_t returnInt = 0; ret = sign->setSignSpecInt(sign, SM2_USER_ID_UINT8ARR, returnInt); ASSERT_EQ(ret, HCF_NOT_SUPPORT); ret = sign->getSignSpecInt(sign, SM2_USER_ID_UINT8ARR, &returnInt); @@ -475,6 +475,8 @@ HWTEST_F(CryptoEd25519SignTest, CryptoEd25519SignTest014, TestSize.Level0) char *itemName = nullptr; ret = sign->getSignSpecString(sign, SM2_USER_ID_UINT8ARR, &itemName); ASSERT_EQ(ret, HCF_NOT_SUPPORT); + + HcfObjDestroy(sign); } HWTEST_F(CryptoEd25519SignTest, CryptoEd25519SignTest015, TestSize.Level0) diff --git a/test/unittest/src/crypto_ed25519_verify_test.cpp b/test/unittest/src/crypto_ed25519_verify_test.cpp index 493921d84c2d9c386d68fe2b8529c40ab2c65920..fdb261dfa32a361e28af659849b9b90a08853e15 100644 --- a/test/unittest/src/crypto_ed25519_verify_test.cpp +++ b/test/unittest/src/crypto_ed25519_verify_test.cpp @@ -355,7 +355,7 @@ HWTEST_F(CryptoEd25519VerifyTest, CryptoEd25519VerifyTest013, TestSize.Level0) ASSERT_EQ(ret, HCF_SUCCESS); ASSERT_NE(verify, nullptr); - int32_t returnInt = 1; + int32_t returnInt = 0; ret = verify->setVerifySpecInt(verify, SM2_USER_ID_UINT8ARR, returnInt); ASSERT_EQ(ret, HCF_NOT_SUPPORT); ret = verify->getVerifySpecInt(verify, SM2_USER_ID_UINT8ARR, &returnInt); @@ -368,6 +368,8 @@ HWTEST_F(CryptoEd25519VerifyTest, CryptoEd25519VerifyTest013, TestSize.Level0) ASSERT_EQ(ret, HCF_NOT_SUPPORT); ret = verify->update(verify, &g_mockInput); ASSERT_EQ(ret, HCF_INVALID_PARAMS); + + HcfObjDestroy(verify); } HWTEST_F(CryptoEd25519VerifyTest, CryptoEd25519VerifyTest014, TestSize.Level0) diff --git a/test/unittest/src/crypto_sm2_asy_key_generator_by_spec_test.cpp b/test/unittest/src/crypto_sm2_asy_key_generator_by_spec_test.cpp index 427af9b60d571d770fea1307cc30c31816de5a17..7b91448d696b9ab59055dd7e0987e6f036e2f8e5 100644 --- a/test/unittest/src/crypto_sm2_asy_key_generator_by_spec_test.cpp +++ b/test/unittest/src/crypto_sm2_asy_key_generator_by_spec_test.cpp @@ -19,10 +19,10 @@ #include "asy_key_generator.h" #include "sm2_asy_key_generator_openssl.h" -#include "detailed_ecc_key_params.h" #include "ecc_openssl_common.h" #include "ecc_openssl_common_param_spec.h" #include "ecc_common.h" +#include "ecc_common_param_spec.h" #include "ecc_key_util.h" #include "key_utils.h" #include "blob.h" @@ -42,8 +42,6 @@ using namespace std; using namespace testing::ext; namespace { -constexpr int ZERO = 0; -constexpr int ONE = 1; constexpr int TWO = 2; constexpr int THREE = 3; constexpr int FOUR = 4; @@ -54,8 +52,8 @@ constexpr int EIGHT = 8; class CryptoSm2AsyKeyGeneratorBySpecTest : public testing::Test { public: - static void SetUpTestCase(); - static void TearDownTestCase(); + static void SetUpTestCase() {}; + static void TearDownTestCase() {}; void SetUp(); void TearDown(); }; @@ -82,165 +80,19 @@ static HcfBlob g_mockInput = { static string g_sm2AlgName = "SM2_256"; static string g_sm2CurveName = "NID_sm2"; -HcfEccPubKeyParamsSpec g_sm2256PubKeySpec; -HcfEccPriKeyParamsSpec g_sm2256PriKeySpec; -HcfEccKeyPairParamsSpec g_sm2256KeyPairSpec; -HcfEccCommParamsSpec g_sm2256CommSpec; HcfEccCommParamsSpec *g_eccCommSpec = nullptr; static HcfResult ConstructSm2256CommParamsSpec(HcfAsyKeyParamsSpec **spec) { - HcfEccCommParamsSpec *eccCommSpec = &g_sm2256CommSpec; + HcfEccCommParamsSpec *eccCommSpec = nullptr; HcfEccKeyUtilCreate(g_sm2CurveName.c_str(), &eccCommSpec); - + if (eccCommSpec == nullptr) { + return HCF_INVALID_PARAMS; + } *spec = (HcfAsyKeyParamsSpec *)eccCommSpec; return HCF_SUCCESS; } -static HcfResult ConstructSm2256KeyPairCommParamsSpec(const string &algoName, HcfEccCommParamsSpec **spec) -{ - HcfEccCommParamsSpec *eccCommSpec = nullptr; - - HcfEccKeyUtilCreate(algoName.c_str(), &eccCommSpec); - - *spec = eccCommSpec; - return HCF_SUCCESS; -} - -static HcfResult ConstructSm2256KeyPairParamsSpec(const string &algoName, HcfAsyKeyParamsSpec **spec) -{ - HcfAsyKeyGenerator *generator = nullptr; - int32_t res = HcfAsyKeyGeneratorCreate(algoName.c_str(), &generator); - - HcfKeyPair *keyPair = nullptr; - res = generator->generateKeyPair(generator, nullptr, &keyPair); - - HcfEccKeyPairParamsSpec *eccKeyPairSpec = &g_sm2256KeyPairSpec; - HcfBigInteger retBigInt = { .data = nullptr, .len = 0 }; - - eccKeyPairSpec->base.base.algName = g_eccCommSpec->base.algName; - eccKeyPairSpec->base.base.specType = HCF_KEY_PAIR_SPEC; - eccKeyPairSpec->base.field = g_eccCommSpec->field; - eccKeyPairSpec->base.field->fieldType = g_eccCommSpec->field->fieldType; - ((HcfECFieldFp *)(eccKeyPairSpec->base.field))->p.data = ((HcfECFieldFp *)(g_eccCommSpec->field))->p.data; - ((HcfECFieldFp *)(eccKeyPairSpec->base.field))->p.len = ((HcfECFieldFp *)(g_eccCommSpec->field))->p.len; - eccKeyPairSpec->base.a.data = g_eccCommSpec->a.data; - eccKeyPairSpec->base.a.len = g_eccCommSpec->a.len; - eccKeyPairSpec->base.b.data = g_eccCommSpec->b.data; - eccKeyPairSpec->base.b.len = g_eccCommSpec->b.len; - eccKeyPairSpec->base.g.x.data = g_eccCommSpec->g.x.data; - eccKeyPairSpec->base.g.x.len = g_eccCommSpec->g.x.len; - eccKeyPairSpec->base.g.y.data = g_eccCommSpec->g.y.data; - eccKeyPairSpec->base.g.y.len = g_eccCommSpec->g.y.len; - eccKeyPairSpec->base.n.data = g_eccCommSpec->n.data; - eccKeyPairSpec->base.n.len = g_eccCommSpec->n.len; - eccKeyPairSpec->base.h = g_eccCommSpec->h; - res = keyPair->pubKey->getAsyKeySpecBigInteger(keyPair->pubKey, ECC_PK_X_BN, &retBigInt); - eccKeyPairSpec->pk.x.data = retBigInt.data; - eccKeyPairSpec->pk.x.len = retBigInt.len; - - res = keyPair->pubKey->getAsyKeySpecBigInteger(keyPair->pubKey, ECC_PK_Y_BN, &retBigInt); - eccKeyPairSpec->pk.y.data =retBigInt.data; - eccKeyPairSpec->pk.y.len = retBigInt.len; - - res = keyPair->priKey->getAsyKeySpecBigInteger(keyPair->priKey, ECC_SK_BN, &retBigInt); - eccKeyPairSpec->sk.data = retBigInt.data; - eccKeyPairSpec->sk.len = retBigInt.len; - - *spec = (HcfAsyKeyParamsSpec *)eccKeyPairSpec; - HcfObjDestroy(generator); - return HCF_SUCCESS; -} - -static HcfResult ConstructSm2256PriKeyParamsSpec(const string &algoName, HcfAsyKeyParamsSpec **spec) -{ - HcfAsyKeyGenerator *generator = nullptr; - int32_t res = HcfAsyKeyGeneratorCreate(algoName.c_str(), &generator); - - HcfKeyPair *keyPair = nullptr; - res = generator->generateKeyPair(generator, nullptr, &keyPair); - - HcfEccPriKeyParamsSpec *eccPriKeySpec = &g_sm2256PriKeySpec; - HcfBigInteger retBigInt = { .data = nullptr, .len = 0 }; - - eccPriKeySpec->base.base.algName = g_eccCommSpec->base.algName; - eccPriKeySpec->base.base.specType = HCF_PRIVATE_KEY_SPEC; - eccPriKeySpec->base.field = g_eccCommSpec->field; - eccPriKeySpec->base.field->fieldType = g_eccCommSpec->field->fieldType; - ((HcfECFieldFp *)(eccPriKeySpec->base.field))->p.data = ((HcfECFieldFp *)(g_eccCommSpec->field))->p.data; - ((HcfECFieldFp *)(eccPriKeySpec->base.field))->p.len = ((HcfECFieldFp *)(g_eccCommSpec->field))->p.len; - eccPriKeySpec->base.a.data = g_eccCommSpec->a.data; - eccPriKeySpec->base.a.len = g_eccCommSpec->a.len; - eccPriKeySpec->base.b.data = g_eccCommSpec->b.data; - eccPriKeySpec->base.b.len = g_eccCommSpec->b.len; - eccPriKeySpec->base.g.x.data = g_eccCommSpec->g.x.data; - eccPriKeySpec->base.g.x.len = g_eccCommSpec->g.x.len; - eccPriKeySpec->base.g.y.data = g_eccCommSpec->g.y.data; - eccPriKeySpec->base.g.y.len = g_eccCommSpec->g.y.len; - eccPriKeySpec->base.n.data = g_eccCommSpec->n.data; - eccPriKeySpec->base.n.len = g_eccCommSpec->n.len; - eccPriKeySpec->base.h = g_eccCommSpec->h; - - res = keyPair->priKey->getAsyKeySpecBigInteger(keyPair->priKey, ECC_SK_BN, &retBigInt); - eccPriKeySpec->sk.data = retBigInt.data; - eccPriKeySpec->sk.len = retBigInt.len; - - *spec = (HcfAsyKeyParamsSpec *)eccPriKeySpec; - HcfObjDestroy(generator); - return HCF_SUCCESS; -} - -static HcfResult ConstructSm2256PubKeyParamsSpec(const string &algoName, HcfAsyKeyParamsSpec **spec) -{ - HcfAsyKeyGenerator *generator = nullptr; - int32_t res = HcfAsyKeyGeneratorCreate(algoName.c_str(), &generator); - - HcfKeyPair *keyPair = nullptr; - res = generator->generateKeyPair(generator, nullptr, &keyPair); - - HcfEccPubKeyParamsSpec *eccPubKeySpec = &g_sm2256PubKeySpec; - HcfBigInteger retBigInt = { .data = nullptr, .len = 0 }; - - eccPubKeySpec->base.base.algName = g_eccCommSpec->base.algName; - eccPubKeySpec->base.base.specType = HCF_PUBLIC_KEY_SPEC; - eccPubKeySpec->base.field = g_eccCommSpec->field; - eccPubKeySpec->base.field->fieldType = g_eccCommSpec->field->fieldType; - ((HcfECFieldFp *)(eccPubKeySpec->base.field))->p.data = ((HcfECFieldFp *)(g_eccCommSpec->field))->p.data; - ((HcfECFieldFp *)(eccPubKeySpec->base.field))->p.len = ((HcfECFieldFp *)(g_eccCommSpec->field))->p.len; - eccPubKeySpec->base.a.data = g_eccCommSpec->a.data; - eccPubKeySpec->base.a.len = g_eccCommSpec->a.len; - eccPubKeySpec->base.b.data = g_eccCommSpec->b.data; - eccPubKeySpec->base.b.len = g_eccCommSpec->b.len; - eccPubKeySpec->base.g.x.data = g_eccCommSpec->g.x.data; - eccPubKeySpec->base.g.x.len = g_eccCommSpec->g.x.len; - eccPubKeySpec->base.g.y.data = g_eccCommSpec->g.y.data; - eccPubKeySpec->base.g.y.len = g_eccCommSpec->g.y.len; - eccPubKeySpec->base.n.data = g_eccCommSpec->n.data; - eccPubKeySpec->base.n.len = g_eccCommSpec->n.len; - eccPubKeySpec->base.h = g_eccCommSpec->h; - res = keyPair->pubKey->getAsyKeySpecBigInteger(keyPair->pubKey, ECC_PK_X_BN, &retBigInt); - eccPubKeySpec->pk.x.data = retBigInt.data; - eccPubKeySpec->pk.x.len = retBigInt.len; - - res = keyPair->pubKey->getAsyKeySpecBigInteger(keyPair->pubKey, ECC_PK_Y_BN, &retBigInt); - eccPubKeySpec->pk.y.data =retBigInt.data; - eccPubKeySpec->pk.y.len = retBigInt.len; - - *spec = (HcfAsyKeyParamsSpec *)eccPubKeySpec; - HcfObjDestroy(generator); - return HCF_SUCCESS; -} - -void CryptoSm2AsyKeyGeneratorBySpecTest::SetUpTestCase() -{ - ConstructSm2256KeyPairCommParamsSpec("NID_sm2", &g_eccCommSpec); -} - -void CryptoSm2AsyKeyGeneratorBySpecTest::TearDownTestCase() -{ - FreeEccCommParamsSpec(g_eccCommSpec); -} - /** * @tc.name: CryptoEccAsyKeyGeneratorBySpecTest.CryptoSm2AsyKeyGeneratorBySpecTest001 * @tc.desc: Verify that the creation of the sm2 key pair generator is normal. @@ -250,7 +102,7 @@ void CryptoSm2AsyKeyGeneratorBySpecTest::TearDownTestCase() HWTEST_F(CryptoSm2AsyKeyGeneratorBySpecTest, CryptoSm2AsyKeyGeneratorBySpecTest001, TestSize.Level0) { HcfAsyKeyParamsSpec *paramSpec = nullptr; - int32_t res = ConstructSm2256CommParamsSpec(¶mSpec); + HcfResult res = ConstructSm2256CommParamsSpec(¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); @@ -262,13 +114,14 @@ HWTEST_F(CryptoSm2AsyKeyGeneratorBySpecTest, CryptoSm2AsyKeyGeneratorBySpecTest0 ASSERT_NE(generator, nullptr); HcfObjDestroy(generator); + FreeEccCommParamsSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoSm2AsyKeyGeneratorBySpecTest, CryptoSm2AsyKeyGeneratorBySpecTest002, TestSize.Level0) { HcfAsyKeyGeneratorBySpec *generator = nullptr; - int32_t res = HcfAsyKeyGeneratorBySpecCreate(nullptr, &generator); + HcfResult res = HcfAsyKeyGeneratorBySpecCreate(nullptr, &generator); ASSERT_NE(res, HCF_SUCCESS); ASSERT_EQ(generator, nullptr); @@ -279,20 +132,20 @@ HWTEST_F(CryptoSm2AsyKeyGeneratorBySpecTest, CryptoSm2AsyKeyGeneratorBySpecTest0 HWTEST_F(CryptoSm2AsyKeyGeneratorBySpecTest, CryptoSm2AsyKeyGeneratorBySpecTest003, TestSize.Level0) { HcfAsyKeyParamsSpec *paramSpec = nullptr; - int32_t res = ConstructSm2256CommParamsSpec(¶mSpec); + HcfResult res = ConstructSm2256CommParamsSpec(¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); res = HcfAsyKeyGeneratorBySpecCreate(paramSpec, nullptr); - ASSERT_NE(res, HCF_SUCCESS); + FreeEccCommParamsSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoSm2AsyKeyGeneratorBySpecTest, CryptoSm2AsyKeyGeneratorBySpecTest004, TestSize.Level0) { HcfAsyKeyParamsSpec *paramSpec = nullptr; - int32_t res = ConstructSm2256CommParamsSpec(¶mSpec); + HcfResult res = ConstructSm2256CommParamsSpec(¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); @@ -307,12 +160,13 @@ HWTEST_F(CryptoSm2AsyKeyGeneratorBySpecTest, CryptoSm2AsyKeyGeneratorBySpecTest0 ASSERT_NE(className, nullptr); HcfObjDestroy(generator); + FreeEccCommParamsSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoSm2AsyKeyGeneratorBySpecTest, CryptoSm2AsyKeyGeneratorBySpecTest005, TestSize.Level0) { HcfAsyKeyParamsSpec *paramSpec = nullptr; - int32_t res = ConstructSm2256CommParamsSpec(¶mSpec); + HcfResult res = ConstructSm2256CommParamsSpec(¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); @@ -324,12 +178,13 @@ HWTEST_F(CryptoSm2AsyKeyGeneratorBySpecTest, CryptoSm2AsyKeyGeneratorBySpecTest0 ASSERT_NE(generator, nullptr); generator->base.destroy((HcfObjectBase *)generator); + FreeEccCommParamsSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoSm2AsyKeyGeneratorBySpecTest, CryptoSm2AsyKeyGeneratorBySpecTest006, TestSize.Level0) { HcfAsyKeyParamsSpec *paramSpec = nullptr; - int32_t res = ConstructSm2256CommParamsSpec(¶mSpec); + HcfResult res = ConstructSm2256CommParamsSpec(¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); @@ -342,12 +197,13 @@ HWTEST_F(CryptoSm2AsyKeyGeneratorBySpecTest, CryptoSm2AsyKeyGeneratorBySpecTest0 generator->base.destroy(nullptr); HcfObjDestroy(generator); + FreeEccCommParamsSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoSm2AsyKeyGeneratorBySpecTest, CryptoSm2AsyKeyGeneratorBySpecTest007, TestSize.Level0) { HcfAsyKeyParamsSpec *paramSpec = nullptr; - int32_t res = ConstructSm2256CommParamsSpec(¶mSpec); + HcfResult res = ConstructSm2256CommParamsSpec(¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); @@ -365,7 +221,7 @@ HWTEST_F(CryptoSm2AsyKeyGeneratorBySpecTest, CryptoSm2AsyKeyGeneratorBySpecTest0 HWTEST_F(CryptoSm2AsyKeyGeneratorBySpecTest, CryptoSm2AsyKeyGeneratorBySpecTest008, TestSize.Level0) { HcfAsyKeyParamsSpec *paramSpec = nullptr; - int32_t res = ConstructSm2256CommParamsSpec(¶mSpec); + HcfResult res = ConstructSm2256CommParamsSpec(¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); @@ -376,16 +232,16 @@ HWTEST_F(CryptoSm2AsyKeyGeneratorBySpecTest, CryptoSm2AsyKeyGeneratorBySpecTest0 ASSERT_NE(generator, nullptr); const char *algName = generator->getAlgName(generator); - ASSERT_NE(algName, nullptr); HcfObjDestroy(generator); + FreeEccCommParamsSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoSm2AsyKeyGeneratorBySpecTest, CryptoSm2AsyKeyGeneratorBySpecTest009, TestSize.Level0) { HcfAsyKeyParamsSpec *paramSpec = nullptr; - int32_t res = ConstructSm2256CommParamsSpec(¶mSpec); + HcfResult res = ConstructSm2256CommParamsSpec(¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); @@ -397,7 +253,6 @@ HWTEST_F(CryptoSm2AsyKeyGeneratorBySpecTest, CryptoSm2AsyKeyGeneratorBySpecTest0 ASSERT_NE(generator, nullptr); const char *algName = generator->getAlgName(nullptr); - ASSERT_EQ(algName, nullptr); HcfObjDestroy(generator); @@ -407,7 +262,7 @@ HWTEST_F(CryptoSm2AsyKeyGeneratorBySpecTest, CryptoSm2AsyKeyGeneratorBySpecTest0 HWTEST_F(CryptoSm2AsyKeyGeneratorBySpecTest, CryptoSm2AsyKeyGeneratorBySpecTest010, TestSize.Level0) { HcfAsyKeyParamsSpec *paramSpec = nullptr; - int32_t res = ConstructSm2256CommParamsSpec(¶mSpec); + HcfResult res = ConstructSm2256CommParamsSpec(¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); @@ -418,17 +273,18 @@ HWTEST_F(CryptoSm2AsyKeyGeneratorBySpecTest, CryptoSm2AsyKeyGeneratorBySpecTest0 ASSERT_NE(generator, nullptr); const char *algName = generator->getAlgName((HcfAsyKeyGeneratorBySpec *)&g_obj); - ASSERT_EQ(algName, nullptr); HcfObjDestroy(generator); + FreeEccCommParamsSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoSm2AsyKeyGeneratorBySpecTest, CryptoSm2AsyKeyGeneratorBySpecTest011, TestSize.Level0) { + ConstructEccKeyPairCommParamsSpec("NID_sm2", &g_eccCommSpec); + ASSERT_NE(g_eccCommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - int32_t res = ConstructSm2256KeyPairParamsSpec(g_sm2AlgName, ¶mSpec); - + HcfResult res = ConstructEccKeyPairParamsSpec(g_sm2AlgName.c_str(), g_eccCommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); @@ -444,12 +300,15 @@ HWTEST_F(CryptoSm2AsyKeyGeneratorBySpecTest, CryptoSm2AsyKeyGeneratorBySpecTest0 HcfObjDestroy(keyPair); HcfObjDestroy(generator); + DestroyEccKeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoSm2AsyKeyGeneratorBySpecTest, CryptoSm2AsyKeyGeneratorBySpecTest012, TestSize.Level0) { + ConstructEccKeyPairCommParamsSpec("NID_sm2", &g_eccCommSpec); + ASSERT_NE(g_eccCommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - int32_t res = ConstructSm2256KeyPairParamsSpec(g_sm2AlgName, ¶mSpec); + HcfResult res = ConstructEccKeyPairParamsSpec(g_sm2AlgName.c_str(), g_eccCommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); @@ -472,63 +331,62 @@ HWTEST_F(CryptoSm2AsyKeyGeneratorBySpecTest, CryptoSm2AsyKeyGeneratorBySpecTest0 HWTEST_F(CryptoSm2AsyKeyGeneratorBySpecTest, CryptoSm2AsyKeyGeneratorBySpecTest013, TestSize.Level0) { + ConstructEccKeyPairCommParamsSpec("NID_sm2", &g_eccCommSpec); + ASSERT_NE(g_eccCommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - int32_t res = ConstructSm2256KeyPairParamsSpec(g_sm2AlgName, ¶mSpec); - + HcfResult res = ConstructEccKeyPairParamsSpec(g_sm2AlgName.c_str(), g_eccCommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); HcfAsyKeyGeneratorBySpec *generator = nullptr; res = HcfAsyKeyGeneratorBySpecCreate(paramSpec, &generator); - ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(generator, nullptr); res = generator->generateKeyPair(generator, nullptr); - ASSERT_NE(res, HCF_SUCCESS); HcfObjDestroy(generator); + DestroyEccKeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoSm2AsyKeyGeneratorBySpecTest, CryptoSm2AsyKeyGeneratorBySpecTest014, TestSize.Level0) { + ConstructEccKeyPairCommParamsSpec("NID_sm2", &g_eccCommSpec); + ASSERT_NE(g_eccCommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - int32_t res = ConstructSm2256KeyPairParamsSpec(g_sm2AlgName, ¶mSpec); - + HcfResult res = ConstructEccKeyPairParamsSpec(g_sm2AlgName.c_str(), g_eccCommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); HcfAsyKeyGeneratorBySpec *generator = nullptr; res = HcfAsyKeyGeneratorBySpecCreate(paramSpec, &generator); - ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(generator, nullptr); res = generator->generateKeyPair(nullptr, nullptr); - ASSERT_NE(res, HCF_SUCCESS); HcfObjDestroy(generator); + DestroyEccKeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoSm2AsyKeyGeneratorBySpecTest, CryptoSm2AsyKeyGeneratorBySpecTest015, TestSize.Level0) { + ConstructEccKeyPairCommParamsSpec("NID_sm2", &g_eccCommSpec); + ASSERT_NE(g_eccCommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - int32_t res = ConstructSm2256KeyPairParamsSpec(g_sm2AlgName, ¶mSpec); - + HcfResult res = ConstructEccKeyPairParamsSpec(g_sm2AlgName.c_str(), g_eccCommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); HcfAsyKeyGeneratorBySpec *generator = nullptr; res = HcfAsyKeyGeneratorBySpecCreate(paramSpec, &generator); - ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(generator, nullptr); HcfKeyPair *keyPair = nullptr; res = generator->generateKeyPair(generator, &keyPair); - ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(keyPair, nullptr); @@ -537,102 +395,99 @@ HWTEST_F(CryptoSm2AsyKeyGeneratorBySpecTest, CryptoSm2AsyKeyGeneratorBySpecTest0 HcfObjDestroy(keyPair); HcfObjDestroy(generator); + DestroyEccKeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoSm2AsyKeyGeneratorBySpecTest, CryptoSm2AsyKeyGeneratorBySpecTest016, TestSize.Level0) { + ConstructEccKeyPairCommParamsSpec("NID_sm2", &g_eccCommSpec); + ASSERT_NE(g_eccCommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - int32_t res = ConstructSm2256KeyPairParamsSpec(g_sm2AlgName, ¶mSpec); - + HcfResult res = ConstructEccKeyPairParamsSpec(g_sm2AlgName.c_str(), g_eccCommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); HcfAsyKeyGeneratorBySpec *generator = nullptr; res = HcfAsyKeyGeneratorBySpecCreate(paramSpec, &generator); - ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(generator, nullptr); HcfKeyPair *keyPair = nullptr; res = generator->generateKeyPair(generator, &keyPair); - ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(keyPair, nullptr); keyPair->base.destroy((HcfObjectBase *)(&(keyPair->base))); - HcfObjDestroy(generator); + DestroyEccKeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoSm2AsyKeyGeneratorBySpecTest, CryptoSm2AsyKeyGeneratorBySpecTest017, TestSize.Level0) { + ConstructEccKeyPairCommParamsSpec("NID_sm2", &g_eccCommSpec); + ASSERT_NE(g_eccCommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - int32_t res = ConstructSm2256KeyPairParamsSpec(g_sm2AlgName, ¶mSpec); - + HcfResult res = ConstructEccKeyPairParamsSpec(g_sm2AlgName.c_str(), g_eccCommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); HcfAsyKeyGeneratorBySpec *generator = nullptr; res = HcfAsyKeyGeneratorBySpecCreate(paramSpec, &generator); - ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(generator, nullptr); HcfKeyPair *keyPair = nullptr; res = generator->generateKeyPair(generator, &keyPair); - ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(keyPair, nullptr); keyPair->base.destroy(nullptr); - HcfObjDestroy(keyPair); HcfObjDestroy(generator); + DestroyEccKeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoSm2AsyKeyGeneratorBySpecTest, CryptoSm2AsyKeyGeneratorBySpecTest018, TestSize.Level0) { + ConstructEccKeyPairCommParamsSpec("NID_sm2", &g_eccCommSpec); + ASSERT_NE(g_eccCommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - int32_t res = ConstructSm2256KeyPairParamsSpec(g_sm2AlgName, ¶mSpec); - + HcfResult res = ConstructEccKeyPairParamsSpec(g_sm2AlgName.c_str(), g_eccCommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); HcfAsyKeyGeneratorBySpec *generator = nullptr; res = HcfAsyKeyGeneratorBySpecCreate(paramSpec, &generator); - ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(generator, nullptr); HcfKeyPair *keyPair = nullptr; res = generator->generateKeyPair(generator, &keyPair); - ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(keyPair, nullptr); keyPair->base.destroy(&g_obj); - HcfObjDestroy(keyPair); HcfObjDestroy(generator); + DestroyEccKeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoSm2AsyKeyGeneratorBySpecTest, CryptoSm2AsyKeyGeneratorBySpecTest019, TestSize.Level0) { + ConstructEccKeyPairCommParamsSpec("NID_sm2", &g_eccCommSpec); + ASSERT_NE(g_eccCommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - int32_t res = ConstructSm2256KeyPairParamsSpec(g_sm2AlgName, ¶mSpec); - + HcfResult res = ConstructEccKeyPairParamsSpec(g_sm2AlgName.c_str(), g_eccCommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); HcfAsyKeyGeneratorBySpec *generator = nullptr; res = HcfAsyKeyGeneratorBySpecCreate(paramSpec, &generator); - ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(generator, nullptr); HcfKeyPair *keyPair = nullptr; res = generator->generateKeyPair(generator, &keyPair); - ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(keyPair, nullptr); @@ -641,25 +496,25 @@ HWTEST_F(CryptoSm2AsyKeyGeneratorBySpecTest, CryptoSm2AsyKeyGeneratorBySpecTest0 HcfObjDestroy(keyPair); HcfObjDestroy(generator); + DestroyEccKeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoSm2AsyKeyGeneratorBySpecTest, CryptoSm2AsyKeyGeneratorBySpecTest020, TestSize.Level0) { + ConstructEccKeyPairCommParamsSpec("NID_sm2", &g_eccCommSpec); + ASSERT_NE(g_eccCommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - int32_t res = ConstructSm2256KeyPairParamsSpec(g_sm2AlgName, ¶mSpec); - + HcfResult res = ConstructEccKeyPairParamsSpec(g_sm2AlgName.c_str(), g_eccCommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); HcfAsyKeyGeneratorBySpec *generator = nullptr; res = HcfAsyKeyGeneratorBySpecCreate(paramSpec, &generator); - ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(generator, nullptr); HcfKeyPair *keyPair = nullptr; res = generator->generateKeyPair(generator, &keyPair); - ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(keyPair, nullptr); @@ -668,364 +523,351 @@ HWTEST_F(CryptoSm2AsyKeyGeneratorBySpecTest, CryptoSm2AsyKeyGeneratorBySpecTest0 HcfObjDestroy(keyPair); HcfObjDestroy(generator); + DestroyEccKeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoSm2AsyKeyGeneratorBySpecTest, CryptoSm2AsyKeyGeneratorBySpecTest021, TestSize.Level0) { + ConstructEccKeyPairCommParamsSpec("NID_sm2", &g_eccCommSpec); + ASSERT_NE(g_eccCommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - int32_t res = ConstructSm2256KeyPairParamsSpec(g_sm2AlgName, ¶mSpec); - + HcfResult res = ConstructEccKeyPairParamsSpec(g_sm2AlgName.c_str(), g_eccCommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); HcfAsyKeyGeneratorBySpec *generator = nullptr; res = HcfAsyKeyGeneratorBySpecCreate(paramSpec, &generator); - ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(generator, nullptr); HcfKeyPair *keyPair = nullptr; res = generator->generateKeyPair(generator, &keyPair); - ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(keyPair, nullptr); keyPair->pubKey->base.base.destroy(nullptr); - HcfObjDestroy(keyPair); HcfObjDestroy(generator); + DestroyEccKeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoSm2AsyKeyGeneratorBySpecTest, CryptoSm2AsyKeyGeneratorBySpecTest022, TestSize.Level0) { + ConstructEccKeyPairCommParamsSpec("NID_sm2", &g_eccCommSpec); + ASSERT_NE(g_eccCommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - int32_t res = ConstructSm2256KeyPairParamsSpec(g_sm2AlgName, ¶mSpec); - + HcfResult res = ConstructEccKeyPairParamsSpec(g_sm2AlgName.c_str(), g_eccCommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); HcfAsyKeyGeneratorBySpec *generator = nullptr; res = HcfAsyKeyGeneratorBySpecCreate(paramSpec, &generator); - ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(generator, nullptr); HcfKeyPair *keyPair = nullptr; res = generator->generateKeyPair(generator, &keyPair); - ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(keyPair, nullptr); keyPair->pubKey->base.base.destroy(&g_obj); - HcfObjDestroy(keyPair); HcfObjDestroy(generator); + DestroyEccKeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoSm2AsyKeyGeneratorBySpecTest, CryptoSm2AsyKeyGeneratorBySpecTest023, TestSize.Level0) { + ConstructEccKeyPairCommParamsSpec("NID_sm2", &g_eccCommSpec); + ASSERT_NE(g_eccCommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - int32_t res = ConstructSm2256KeyPairParamsSpec(g_sm2AlgName, ¶mSpec); - + HcfResult res = ConstructEccKeyPairParamsSpec(g_sm2AlgName.c_str(), g_eccCommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); HcfAsyKeyGeneratorBySpec *generator = nullptr; res = HcfAsyKeyGeneratorBySpecCreate(paramSpec, &generator); - ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(generator, nullptr); HcfKeyPair *keyPair = nullptr; res = generator->generateKeyPair(generator, &keyPair); - ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(keyPair, nullptr); const char *format = keyPair->pubKey->base.getFormat(&(keyPair->pubKey->base)); - ASSERT_NE(format, nullptr); HcfObjDestroy(keyPair); HcfObjDestroy(generator); + DestroyEccKeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoSm2AsyKeyGeneratorBySpecTest, CryptoSm2AsyKeyGeneratorBySpecTest024, TestSize.Level0) { + ConstructEccKeyPairCommParamsSpec("NID_sm2", &g_eccCommSpec); + ASSERT_NE(g_eccCommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - int32_t res = ConstructSm2256KeyPairParamsSpec(g_sm2AlgName, ¶mSpec); - + HcfResult res = ConstructEccKeyPairParamsSpec(g_sm2AlgName.c_str(), g_eccCommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); HcfAsyKeyGeneratorBySpec *generator = nullptr; res = HcfAsyKeyGeneratorBySpecCreate(paramSpec, &generator); - ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(generator, nullptr); HcfKeyPair *keyPair = nullptr; res = generator->generateKeyPair(generator, &keyPair); - ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(keyPair, nullptr); const char *format = keyPair->pubKey->base.getFormat(nullptr); - ASSERT_EQ(format, nullptr); HcfObjDestroy(keyPair); HcfObjDestroy(generator); + DestroyEccKeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoSm2AsyKeyGeneratorBySpecTest, CryptoSm2AsyKeyGeneratorBySpecTest025, TestSize.Level0) { + ConstructEccKeyPairCommParamsSpec("NID_sm2", &g_eccCommSpec); + ASSERT_NE(g_eccCommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - int32_t res = ConstructSm2256KeyPairParamsSpec(g_sm2AlgName, ¶mSpec); - + HcfResult res = ConstructEccKeyPairParamsSpec(g_sm2AlgName.c_str(), g_eccCommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); HcfAsyKeyGeneratorBySpec *generator = nullptr; res = HcfAsyKeyGeneratorBySpecCreate(paramSpec, &generator); - ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(generator, nullptr); HcfKeyPair *keyPair = nullptr; res = generator->generateKeyPair(generator, &keyPair); - ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(keyPair, nullptr); const char *format = keyPair->pubKey->base.getFormat((HcfKey *)&g_obj); - ASSERT_EQ(format, nullptr); HcfObjDestroy(keyPair); HcfObjDestroy(generator); + DestroyEccKeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoSm2AsyKeyGeneratorBySpecTest, CryptoSm2AsyKeyGeneratorBySpecTest026, TestSize.Level0) { + ConstructEccKeyPairCommParamsSpec("NID_sm2", &g_eccCommSpec); + ASSERT_NE(g_eccCommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - int32_t res = ConstructSm2256KeyPairParamsSpec(g_sm2AlgName, ¶mSpec); - + HcfResult res = ConstructEccKeyPairParamsSpec(g_sm2AlgName.c_str(), g_eccCommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); HcfAsyKeyGeneratorBySpec *generator = nullptr; res = HcfAsyKeyGeneratorBySpecCreate(paramSpec, &generator); - ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(generator, nullptr); HcfKeyPair *keyPair = nullptr; res = generator->generateKeyPair(generator, &keyPair); - ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(keyPair, nullptr); const char *algName = keyPair->pubKey->base.getAlgorithm(&(keyPair->pubKey->base)); - ASSERT_NE(algName, nullptr); HcfObjDestroy(keyPair); HcfObjDestroy(generator); + DestroyEccKeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoSm2AsyKeyGeneratorBySpecTest, CryptoSm2AsyKeyGeneratorBySpecTest027, TestSize.Level0) { + ConstructEccKeyPairCommParamsSpec("NID_sm2", &g_eccCommSpec); + ASSERT_NE(g_eccCommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - int32_t res = ConstructSm2256KeyPairParamsSpec(g_sm2AlgName, ¶mSpec); - + HcfResult res = ConstructEccKeyPairParamsSpec(g_sm2AlgName.c_str(), g_eccCommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); HcfAsyKeyGeneratorBySpec *generator = nullptr; res = HcfAsyKeyGeneratorBySpecCreate(paramSpec, &generator); - ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(generator, nullptr); HcfKeyPair *keyPair = nullptr; res = generator->generateKeyPair(generator, &keyPair); - ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(keyPair, nullptr); const char *algName = keyPair->pubKey->base.getAlgorithm(nullptr); - ASSERT_EQ(algName, nullptr); HcfObjDestroy(keyPair); HcfObjDestroy(generator); + DestroyEccKeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoSm2AsyKeyGeneratorBySpecTest, CryptoSm2AsyKeyGeneratorBySpecTest028, TestSize.Level0) { + ConstructEccKeyPairCommParamsSpec("NID_sm2", &g_eccCommSpec); + ASSERT_NE(g_eccCommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - int32_t res = ConstructSm2256KeyPairParamsSpec(g_sm2AlgName, ¶mSpec); - + HcfResult res = ConstructEccKeyPairParamsSpec(g_sm2AlgName.c_str(), g_eccCommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); HcfAsyKeyGeneratorBySpec *generator = nullptr; res = HcfAsyKeyGeneratorBySpecCreate(paramSpec, &generator); - ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(generator, nullptr); HcfKeyPair *keyPair = nullptr; res = generator->generateKeyPair(generator, &keyPair); - ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(keyPair, nullptr); const char *algName = keyPair->pubKey->base.getAlgorithm((HcfKey *)&g_obj); - ASSERT_EQ(algName, nullptr); HcfObjDestroy(keyPair); HcfObjDestroy(generator); + DestroyEccKeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoSm2AsyKeyGeneratorBySpecTest, CryptoSm2AsyKeyGeneratorBySpecTest029, TestSize.Level0) { + ConstructEccKeyPairCommParamsSpec("NID_sm2", &g_eccCommSpec); + ASSERT_NE(g_eccCommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - int32_t res = ConstructSm2256KeyPairParamsSpec(g_sm2AlgName, ¶mSpec); - + HcfResult res = ConstructEccKeyPairParamsSpec(g_sm2AlgName.c_str(), g_eccCommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); HcfAsyKeyGeneratorBySpec *generator = nullptr; res = HcfAsyKeyGeneratorBySpecCreate(paramSpec, &generator); - ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(generator, nullptr); HcfKeyPair *keyPair = nullptr; res = generator->generateKeyPair(generator, &keyPair); - ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(keyPair, nullptr); HcfBlob blob = { .data = nullptr, .len = 0 }; res = keyPair->pubKey->base.getEncoded(&(keyPair->pubKey->base), &blob); - ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(blob.data, nullptr); ASSERT_NE(blob.len, 0); - free(blob.data); - + HcfFree(blob.data); HcfObjDestroy(keyPair); HcfObjDestroy(generator); + DestroyEccKeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoSm2AsyKeyGeneratorBySpecTest, CryptoSm2AsyKeyGeneratorBySpecTest030, TestSize.Level0) { + ConstructEccKeyPairCommParamsSpec("NID_sm2", &g_eccCommSpec); + ASSERT_NE(g_eccCommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - int32_t res = ConstructSm2256KeyPairParamsSpec(g_sm2AlgName, ¶mSpec); - + HcfResult res = ConstructEccKeyPairParamsSpec(g_sm2AlgName.c_str(), g_eccCommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); HcfAsyKeyGeneratorBySpec *generator = nullptr; res = HcfAsyKeyGeneratorBySpecCreate(paramSpec, &generator); - ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(generator, nullptr); HcfKeyPair *keyPair = nullptr; res = generator->generateKeyPair(generator, &keyPair); - ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(keyPair, nullptr); HcfBlob blob = { .data = nullptr, .len = 0 }; res = keyPair->pubKey->base.getEncoded(nullptr, &blob); - ASSERT_NE(res, HCF_SUCCESS); ASSERT_EQ(blob.data, nullptr); ASSERT_EQ(blob.len, 0); - free(blob.data); - + HcfFree(blob.data); HcfObjDestroy(keyPair); HcfObjDestroy(generator); + DestroyEccKeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoSm2AsyKeyGeneratorBySpecTest, CryptoSm2AsyKeyGeneratorBySpecTest031, TestSize.Level0) { + ConstructEccKeyPairCommParamsSpec("NID_sm2", &g_eccCommSpec); + ASSERT_NE(g_eccCommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - int32_t res = ConstructSm2256KeyPairParamsSpec(g_sm2AlgName, ¶mSpec); - + HcfResult res = ConstructEccKeyPairParamsSpec(g_sm2AlgName.c_str(), g_eccCommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); HcfAsyKeyGeneratorBySpec *generator = nullptr; res = HcfAsyKeyGeneratorBySpecCreate(paramSpec, &generator); - ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(generator, nullptr); HcfKeyPair *keyPair = nullptr; res = generator->generateKeyPair(generator, &keyPair); - ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(keyPair, nullptr); HcfBlob blob = { .data = nullptr, .len = 0 }; res = keyPair->pubKey->base.getEncoded((HcfKey *)&g_obj, &blob); - ASSERT_NE(res, HCF_SUCCESS); ASSERT_EQ(blob.data, nullptr); ASSERT_EQ(blob.len, 0); - free(blob.data); - + HcfFree(blob.data); HcfObjDestroy(keyPair); HcfObjDestroy(generator); + DestroyEccKeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoSm2AsyKeyGeneratorBySpecTest, CryptoSm2AsyKeyGeneratorBySpecTest032, TestSize.Level0) { + ConstructEccKeyPairCommParamsSpec("NID_sm2", &g_eccCommSpec); + ASSERT_NE(g_eccCommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - int32_t res = ConstructSm2256KeyPairParamsSpec(g_sm2AlgName, ¶mSpec); - + HcfResult res = ConstructEccKeyPairParamsSpec(g_sm2AlgName.c_str(), g_eccCommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); HcfAsyKeyGeneratorBySpec *generator = nullptr; res = HcfAsyKeyGeneratorBySpecCreate(paramSpec, &generator); - ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(generator, nullptr); HcfKeyPair *keyPair = nullptr; res = generator->generateKeyPair(generator, &keyPair); - ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(keyPair, nullptr); res = keyPair->pubKey->base.getEncoded(&(keyPair->pubKey->base), nullptr); - ASSERT_NE(res, HCF_SUCCESS); HcfObjDestroy(keyPair); HcfObjDestroy(generator); + DestroyEccKeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoSm2AsyKeyGeneratorBySpecTest, CryptoSm2AsyKeyGeneratorBySpecTest033, TestSize.Level0) { + ConstructEccKeyPairCommParamsSpec("NID_sm2", &g_eccCommSpec); + ASSERT_NE(g_eccCommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - int32_t res = ConstructSm2256KeyPairParamsSpec(g_sm2AlgName, ¶mSpec); - + HcfResult res = ConstructEccKeyPairParamsSpec(g_sm2AlgName.c_str(), g_eccCommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); @@ -1036,83 +878,80 @@ HWTEST_F(CryptoSm2AsyKeyGeneratorBySpecTest, CryptoSm2AsyKeyGeneratorBySpecTest0 HcfKeyPair *keyPair = nullptr; res = generator->generateKeyPair(generator, &keyPair); - ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(keyPair, nullptr); keyPair->priKey->clearMem(keyPair->priKey); - HcfObjDestroy(keyPair); HcfObjDestroy(generator); + DestroyEccKeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoSm2AsyKeyGeneratorBySpecTest, CryptoSm2AsyKeyGeneratorBySpecTest034, TestSize.Level0) { + ConstructEccKeyPairCommParamsSpec("NID_sm2", &g_eccCommSpec); + ASSERT_NE(g_eccCommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - int32_t res = ConstructSm2256KeyPairParamsSpec(g_sm2AlgName, ¶mSpec); - + HcfResult res = ConstructEccKeyPairParamsSpec(g_sm2AlgName.c_str(), g_eccCommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); HcfAsyKeyGeneratorBySpec *generator = nullptr; res = HcfAsyKeyGeneratorBySpecCreate(paramSpec, &generator); - ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(generator, nullptr); HcfKeyPair *keyPair = nullptr; res = generator->generateKeyPair(generator, &keyPair); - ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(keyPair, nullptr); keyPair->priKey->clearMem(nullptr); - HcfObjDestroy(keyPair); HcfObjDestroy(generator); + DestroyEccKeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoSm2AsyKeyGeneratorBySpecTest, CryptoSm2AsyKeyGeneratorBySpecTest035, TestSize.Level0) { + ConstructEccKeyPairCommParamsSpec("NID_sm2", &g_eccCommSpec); + ASSERT_NE(g_eccCommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - int32_t res = ConstructSm2256KeyPairParamsSpec(g_sm2AlgName, ¶mSpec); - + HcfResult res = ConstructEccKeyPairParamsSpec(g_sm2AlgName.c_str(), g_eccCommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); HcfAsyKeyGeneratorBySpec *generator = nullptr; res = HcfAsyKeyGeneratorBySpecCreate(paramSpec, &generator); - ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(generator, nullptr); HcfKeyPair *keyPair = nullptr; res = generator->generateKeyPair(generator, &keyPair); - ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(keyPair, nullptr); HcfObjDestroy(keyPair); HcfObjDestroy(generator); + DestroyEccKeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoSm2AsyKeyGeneratorBySpecTest, CryptoSm2AsyKeyGeneratorBySpecTest036, TestSize.Level0) { + ConstructEccKeyPairCommParamsSpec("NID_sm2", &g_eccCommSpec); + ASSERT_NE(g_eccCommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - int32_t res = ConstructSm2256KeyPairParamsSpec(g_sm2AlgName, ¶mSpec); - + HcfResult res = ConstructEccKeyPairParamsSpec(g_sm2AlgName.c_str(), g_eccCommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); HcfAsyKeyGeneratorBySpec *generator = nullptr; res = HcfAsyKeyGeneratorBySpecCreate(paramSpec, &generator); - ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(generator, nullptr); HcfKeyPair *keyPair = nullptr; res = generator->generateKeyPair(generator, &keyPair); - ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(keyPair, nullptr); @@ -1121,514 +960,497 @@ HWTEST_F(CryptoSm2AsyKeyGeneratorBySpecTest, CryptoSm2AsyKeyGeneratorBySpecTest0 HcfObjDestroy(keyPair); HcfObjDestroy(generator); + DestroyEccKeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoSm2AsyKeyGeneratorBySpecTest, CryptoSm2AsyKeyGeneratorBySpecTest037, TestSize.Level0) { + ConstructEccKeyPairCommParamsSpec("NID_sm2", &g_eccCommSpec); + ASSERT_NE(g_eccCommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - int32_t res = ConstructSm2256KeyPairParamsSpec(g_sm2AlgName, ¶mSpec); - + HcfResult res = ConstructEccKeyPairParamsSpec(g_sm2AlgName.c_str(), g_eccCommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); HcfAsyKeyGeneratorBySpec *generator = nullptr; res = HcfAsyKeyGeneratorBySpecCreate(paramSpec, &generator); - ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(generator, nullptr); HcfKeyPair *keyPair = nullptr; res = generator->generateKeyPair(generator, &keyPair); - ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(keyPair, nullptr); keyPair->priKey->base.base.destroy((HcfObjectBase *)(&(keyPair->priKey->base.base))); keyPair->priKey = nullptr; - HcfObjDestroy(keyPair); HcfObjDestroy(generator); + DestroyEccKeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoSm2AsyKeyGeneratorBySpecTest, CryptoSm2AsyKeyGeneratorBySpecTest038, TestSize.Level0) { + ConstructEccKeyPairCommParamsSpec("NID_sm2", &g_eccCommSpec); + ASSERT_NE(g_eccCommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - int32_t res = ConstructSm2256KeyPairParamsSpec(g_sm2AlgName, ¶mSpec); - + HcfResult res = ConstructEccKeyPairParamsSpec(g_sm2AlgName.c_str(), g_eccCommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); HcfAsyKeyGeneratorBySpec *generator = nullptr; res = HcfAsyKeyGeneratorBySpecCreate(paramSpec, &generator); - ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(generator, nullptr); HcfKeyPair *keyPair = nullptr; res = generator->generateKeyPair(generator, &keyPair); - ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(keyPair, nullptr); keyPair->priKey->base.base.destroy(nullptr); - HcfObjDestroy(keyPair); HcfObjDestroy(generator); + DestroyEccKeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoSm2AsyKeyGeneratorBySpecTest, CryptoSm2AsyKeyGeneratorBySpecTest039, TestSize.Level0) { + ConstructEccKeyPairCommParamsSpec("NID_sm2", &g_eccCommSpec); + ASSERT_NE(g_eccCommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - int32_t res = ConstructSm2256KeyPairParamsSpec(g_sm2AlgName, ¶mSpec); - + HcfResult res = ConstructEccKeyPairParamsSpec(g_sm2AlgName.c_str(), g_eccCommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); HcfAsyKeyGeneratorBySpec *generator = nullptr; res = HcfAsyKeyGeneratorBySpecCreate(paramSpec, &generator); - ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(generator, nullptr); HcfKeyPair *keyPair = nullptr; res = generator->generateKeyPair(generator, &keyPair); - ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(keyPair, nullptr); keyPair->priKey->base.base.destroy(&g_obj); - HcfObjDestroy(keyPair); HcfObjDestroy(generator); + DestroyEccKeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoSm2AsyKeyGeneratorBySpecTest, CryptoSm2AsyKeyGeneratorBySpecTest040, TestSize.Level0) { + ConstructEccKeyPairCommParamsSpec("NID_sm2", &g_eccCommSpec); + ASSERT_NE(g_eccCommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - int32_t res = ConstructSm2256KeyPairParamsSpec(g_sm2AlgName, ¶mSpec); - + HcfResult res = ConstructEccKeyPairParamsSpec(g_sm2AlgName.c_str(), g_eccCommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); HcfAsyKeyGeneratorBySpec *generator = nullptr; res = HcfAsyKeyGeneratorBySpecCreate(paramSpec, &generator); - ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(generator, nullptr); HcfKeyPair *keyPair = nullptr; res = generator->generateKeyPair(generator, &keyPair); - ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(keyPair, nullptr); const char *format = keyPair->priKey->base.getFormat(&(keyPair->priKey->base)); - ASSERT_NE(format, nullptr); HcfObjDestroy(keyPair); HcfObjDestroy(generator); + DestroyEccKeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoSm2AsyKeyGeneratorBySpecTest, CryptoSm2AsyKeyGeneratorBySpecTest041, TestSize.Level0) { + ConstructEccKeyPairCommParamsSpec("NID_sm2", &g_eccCommSpec); + ASSERT_NE(g_eccCommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - int32_t res = ConstructSm2256KeyPairParamsSpec(g_sm2AlgName, ¶mSpec); - + HcfResult res = ConstructEccKeyPairParamsSpec(g_sm2AlgName.c_str(), g_eccCommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); HcfAsyKeyGeneratorBySpec *generator = nullptr; res = HcfAsyKeyGeneratorBySpecCreate(paramSpec, &generator); - ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(generator, nullptr); HcfKeyPair *keyPair = nullptr; res = generator->generateKeyPair(generator, &keyPair); - ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(keyPair, nullptr); const char *format = keyPair->priKey->base.getFormat(nullptr); - ASSERT_EQ(format, nullptr); HcfObjDestroy(keyPair); HcfObjDestroy(generator); + DestroyEccKeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoSm2AsyKeyGeneratorBySpecTest, CryptoSm2AsyKeyGeneratorBySpecTest042, TestSize.Level0) { + ConstructEccKeyPairCommParamsSpec("NID_sm2", &g_eccCommSpec); + ASSERT_NE(g_eccCommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - int32_t res = ConstructSm2256KeyPairParamsSpec(g_sm2AlgName, ¶mSpec); - + HcfResult res = ConstructEccKeyPairParamsSpec(g_sm2AlgName.c_str(), g_eccCommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); HcfAsyKeyGeneratorBySpec *generator = nullptr; res = HcfAsyKeyGeneratorBySpecCreate(paramSpec, &generator); - ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(generator, nullptr); HcfKeyPair *keyPair = nullptr; res = generator->generateKeyPair(generator, &keyPair); - ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(keyPair, nullptr); const char *format = keyPair->priKey->base.getFormat((HcfKey *)&g_obj); - ASSERT_EQ(format, nullptr); HcfObjDestroy(keyPair); HcfObjDestroy(generator); + DestroyEccKeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoSm2AsyKeyGeneratorBySpecTest, CryptoSm2AsyKeyGeneratorBySpecTest043, TestSize.Level0) { + ConstructEccKeyPairCommParamsSpec("NID_sm2", &g_eccCommSpec); + ASSERT_NE(g_eccCommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - int32_t res = ConstructSm2256KeyPairParamsSpec(g_sm2AlgName, ¶mSpec); - + HcfResult res = ConstructEccKeyPairParamsSpec(g_sm2AlgName.c_str(), g_eccCommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); HcfAsyKeyGeneratorBySpec *generator = nullptr; res = HcfAsyKeyGeneratorBySpecCreate(paramSpec, &generator); - ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(generator, nullptr); HcfKeyPair *keyPair = nullptr; res = generator->generateKeyPair(generator, &keyPair); - ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(keyPair, nullptr); const char *algName = keyPair->priKey->base.getAlgorithm(&(keyPair->priKey->base)); - ASSERT_NE(algName, nullptr); HcfObjDestroy(keyPair); HcfObjDestroy(generator); + DestroyEccKeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoSm2AsyKeyGeneratorBySpecTest, CryptoSm2AsyKeyGeneratorBySpecTest044, TestSize.Level0) { + ConstructEccKeyPairCommParamsSpec("NID_sm2", &g_eccCommSpec); + ASSERT_NE(g_eccCommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - int32_t res = ConstructSm2256KeyPairParamsSpec(g_sm2AlgName, ¶mSpec); - + HcfResult res = ConstructEccKeyPairParamsSpec(g_sm2AlgName.c_str(), g_eccCommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); HcfAsyKeyGeneratorBySpec *generator = nullptr; res = HcfAsyKeyGeneratorBySpecCreate(paramSpec, &generator); - ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(generator, nullptr); HcfKeyPair *keyPair = nullptr; res = generator->generateKeyPair(generator, &keyPair); - ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(keyPair, nullptr); const char *algName = keyPair->priKey->base.getAlgorithm(nullptr); - ASSERT_EQ(algName, nullptr); HcfObjDestroy(keyPair); HcfObjDestroy(generator); + DestroyEccKeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoSm2AsyKeyGeneratorBySpecTest, CryptoSm2AsyKeyGeneratorBySpecTest045, TestSize.Level0) { + ConstructEccKeyPairCommParamsSpec("NID_sm2", &g_eccCommSpec); + ASSERT_NE(g_eccCommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - int32_t res = ConstructSm2256KeyPairParamsSpec(g_sm2AlgName, ¶mSpec); - + HcfResult res = ConstructEccKeyPairParamsSpec(g_sm2AlgName.c_str(), g_eccCommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); HcfAsyKeyGeneratorBySpec *generator = nullptr; res = HcfAsyKeyGeneratorBySpecCreate(paramSpec, &generator); - ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(generator, nullptr); HcfKeyPair *keyPair = nullptr; res = generator->generateKeyPair(generator, &keyPair); - ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(keyPair, nullptr); const char *algName = keyPair->priKey->base.getAlgorithm((HcfKey *)&g_obj); - ASSERT_EQ(algName, nullptr); HcfObjDestroy(keyPair); HcfObjDestroy(generator); + DestroyEccKeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoSm2AsyKeyGeneratorBySpecTest, CryptoSm2AsyKeyGeneratorBySpecTest046, TestSize.Level0) { + ConstructEccKeyPairCommParamsSpec("NID_sm2", &g_eccCommSpec); + ASSERT_NE(g_eccCommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - int32_t res = ConstructSm2256KeyPairParamsSpec(g_sm2AlgName, ¶mSpec); - + HcfResult res = ConstructEccKeyPairParamsSpec(g_sm2AlgName.c_str(), g_eccCommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); HcfAsyKeyGeneratorBySpec *generator = nullptr; res = HcfAsyKeyGeneratorBySpecCreate(paramSpec, &generator); - ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(generator, nullptr); HcfKeyPair *keyPair = nullptr; res = generator->generateKeyPair(generator, &keyPair); - ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(keyPair, nullptr); HcfBlob blob = { .data = nullptr, .len = 0 }; res = keyPair->priKey->base.getEncoded(&(keyPair->priKey->base), &blob); - ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(blob.data, nullptr); ASSERT_NE(blob.len, 0); - free(blob.data); - + HcfFree(blob.data); HcfObjDestroy(keyPair); HcfObjDestroy(generator); + DestroyEccKeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoSm2AsyKeyGeneratorBySpecTest, CryptoSm2AsyKeyGeneratorBySpecTest047, TestSize.Level0) { + ConstructEccKeyPairCommParamsSpec("NID_sm2", &g_eccCommSpec); + ASSERT_NE(g_eccCommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - int32_t res = ConstructSm2256KeyPairParamsSpec(g_sm2AlgName, ¶mSpec); - + HcfResult res = ConstructEccKeyPairParamsSpec(g_sm2AlgName.c_str(), g_eccCommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); HcfAsyKeyGeneratorBySpec *generator = nullptr; res = HcfAsyKeyGeneratorBySpecCreate(paramSpec, &generator); - ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(generator, nullptr); HcfKeyPair *keyPair = nullptr; res = generator->generateKeyPair(generator, &keyPair); - ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(keyPair, nullptr); HcfBlob blob = { .data = nullptr, .len = 0 }; res = keyPair->priKey->base.getEncoded(nullptr, &blob); - ASSERT_NE(res, HCF_SUCCESS); ASSERT_EQ(blob.data, nullptr); ASSERT_EQ(blob.len, 0); - free(blob.data); - + HcfFree(blob.data); HcfObjDestroy(keyPair); HcfObjDestroy(generator); + DestroyEccKeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoSm2AsyKeyGeneratorBySpecTest, CryptoSm2AsyKeyGeneratorBySpecTest048, TestSize.Level0) { + ConstructEccKeyPairCommParamsSpec("NID_sm2", &g_eccCommSpec); + ASSERT_NE(g_eccCommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - int32_t res = ConstructSm2256KeyPairParamsSpec(g_sm2AlgName, ¶mSpec); - + HcfResult res = ConstructEccKeyPairParamsSpec(g_sm2AlgName.c_str(), g_eccCommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); HcfAsyKeyGeneratorBySpec *generator = nullptr; res = HcfAsyKeyGeneratorBySpecCreate(paramSpec, &generator); - ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(generator, nullptr); HcfKeyPair *keyPair = nullptr; res = generator->generateKeyPair(generator, &keyPair); - ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(keyPair, nullptr); HcfBlob blob = { .data = nullptr, .len = 0 }; res = keyPair->priKey->base.getEncoded((HcfKey *)&g_obj, &blob); - ASSERT_NE(res, HCF_SUCCESS); ASSERT_EQ(blob.data, nullptr); ASSERT_EQ(blob.len, 0); - free(blob.data); - + HcfFree(blob.data); HcfObjDestroy(keyPair); HcfObjDestroy(generator); + DestroyEccKeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoSm2AsyKeyGeneratorBySpecTest, CryptoSm2AsyKeyGeneratorBySpecTest049, TestSize.Level0) { + ConstructEccKeyPairCommParamsSpec("NID_sm2", &g_eccCommSpec); + ASSERT_NE(g_eccCommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - int32_t res = ConstructSm2256KeyPairParamsSpec(g_sm2AlgName, ¶mSpec); - + HcfResult res = ConstructEccKeyPairParamsSpec(g_sm2AlgName.c_str(), g_eccCommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); HcfAsyKeyGeneratorBySpec *generator = nullptr; res = HcfAsyKeyGeneratorBySpecCreate(paramSpec, &generator); - ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(generator, nullptr); - HcfKeyPair *keyPair = nullptr; res = generator->generateKeyPair(generator, &keyPair); - ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(keyPair, nullptr); res = keyPair->priKey->base.getEncoded(&(keyPair->priKey->base), nullptr); - ASSERT_NE(res, HCF_SUCCESS); HcfObjDestroy(keyPair); HcfObjDestroy(generator); + DestroyEccKeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoSm2AsyKeyGeneratorBySpecTest, CryptoSm2AsyKeyGeneratorBySpecTest050, TestSize.Level0) { + ConstructEccKeyPairCommParamsSpec("NID_sm2", &g_eccCommSpec); + ASSERT_NE(g_eccCommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - int32_t res = ConstructSm2256PubKeyParamsSpec(g_sm2AlgName, ¶mSpec); - + HcfResult res = ConstructEccPubKeyParamsSpec(g_sm2AlgName.c_str(), g_eccCommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); HcfAsyKeyGeneratorBySpec *generator = nullptr; res = HcfAsyKeyGeneratorBySpecCreate(paramSpec, &generator); - ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(generator, nullptr); HcfPubKey *pubKey = nullptr; res = generator->generatePubKey(generator, &pubKey); - ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(pubKey, nullptr); HcfObjDestroy(pubKey); HcfObjDestroy(generator); + DestroyEccPubKeySpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoSm2AsyKeyGeneratorBySpecTest, CryptoSm2AsyKeyGeneratorBySpecTest051, TestSize.Level0) { + ConstructEccKeyPairCommParamsSpec("NID_sm2", &g_eccCommSpec); + ASSERT_NE(g_eccCommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - int32_t res = ConstructSm2256PubKeyParamsSpec(g_sm2AlgName, ¶mSpec); - + HcfResult res = ConstructEccPubKeyParamsSpec(g_sm2AlgName.c_str(), g_eccCommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); HcfAsyKeyGeneratorBySpec *generator = nullptr; res = HcfAsyKeyGeneratorBySpecCreate(paramSpec, &generator); - ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(generator, nullptr); HcfPubKey *pubKey = nullptr; res = generator->generatePubKey(nullptr, &pubKey); - ASSERT_NE(res, HCF_SUCCESS); ASSERT_EQ(pubKey, nullptr); HcfObjDestroy(pubKey); HcfObjDestroy(generator); + DestroyEccPubKeySpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoSm2AsyKeyGeneratorBySpecTest, CryptoSm2AsyKeyGeneratorBySpecTest052, TestSize.Level0) { + ConstructEccKeyPairCommParamsSpec("NID_sm2", &g_eccCommSpec); + ASSERT_NE(g_eccCommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - int32_t res = ConstructSm2256PubKeyParamsSpec(g_sm2AlgName, ¶mSpec); - + HcfResult res = ConstructEccPubKeyParamsSpec(g_sm2AlgName.c_str(), g_eccCommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); HcfAsyKeyGeneratorBySpec *generator = nullptr; res = HcfAsyKeyGeneratorBySpecCreate(paramSpec, &generator); - ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(generator, nullptr); res = generator->generatePubKey(generator, nullptr); - ASSERT_NE(res, HCF_SUCCESS); HcfObjDestroy(generator); + DestroyEccPubKeySpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoSm2AsyKeyGeneratorBySpecTest, CryptoSm2AsyKeyGeneratorBySpecTest053, TestSize.Level0) { + ConstructEccKeyPairCommParamsSpec("NID_sm2", &g_eccCommSpec); + ASSERT_NE(g_eccCommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - int32_t res = ConstructSm2256PubKeyParamsSpec(g_sm2AlgName, ¶mSpec); - + HcfResult res = ConstructEccPubKeyParamsSpec(g_sm2AlgName.c_str(), g_eccCommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); HcfAsyKeyGeneratorBySpec *generator = nullptr; res = HcfAsyKeyGeneratorBySpecCreate(paramSpec, &generator); - ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(generator, nullptr); res = generator->generatePubKey(nullptr, nullptr); - ASSERT_NE(res, HCF_SUCCESS); HcfObjDestroy(generator); + DestroyEccPubKeySpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoSm2AsyKeyGeneratorBySpecTest, CryptoSm2AsyKeyGeneratorBySpecTest054, TestSize.Level0) { + ConstructEccKeyPairCommParamsSpec("NID_sm2", &g_eccCommSpec); + ASSERT_NE(g_eccCommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - int32_t res = ConstructSm2256PubKeyParamsSpec(g_sm2AlgName, ¶mSpec); - + HcfResult res = ConstructEccPubKeyParamsSpec(g_sm2AlgName.c_str(), g_eccCommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); HcfAsyKeyGeneratorBySpec *generator = nullptr; res = HcfAsyKeyGeneratorBySpecCreate(paramSpec, &generator); - ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(generator, nullptr); HcfPubKey *pubKey = nullptr; res = generator->generatePubKey(generator, &pubKey); - ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(pubKey, nullptr); const char *className = pubKey->base.base.getClass(); - ASSERT_NE(className, nullptr); HcfObjDestroy(pubKey); HcfObjDestroy(generator); + DestroyEccPubKeySpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoSm2AsyKeyGeneratorBySpecTest, CryptoSm2AsyKeyGeneratorBySpecTest055, TestSize.Level0) { + ConstructEccKeyPairCommParamsSpec("NID_sm2", &g_eccCommSpec); + ASSERT_NE(g_eccCommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - int32_t res = ConstructSm2256PubKeyParamsSpec(g_sm2AlgName, ¶mSpec); - + HcfResult res = ConstructEccPubKeyParamsSpec(g_sm2AlgName.c_str(), g_eccCommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); HcfAsyKeyGeneratorBySpec *generator = nullptr; res = HcfAsyKeyGeneratorBySpecCreate(paramSpec, &generator); - ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(generator, nullptr); @@ -1639,247 +1461,238 @@ HWTEST_F(CryptoSm2AsyKeyGeneratorBySpecTest, CryptoSm2AsyKeyGeneratorBySpecTest0 ASSERT_NE(pubKey, nullptr); pubKey->base.base.destroy((HcfObjectBase *)(&(pubKey->base.base))); - HcfObjDestroy(generator); + DestroyEccPubKeySpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoSm2AsyKeyGeneratorBySpecTest, CryptoSm2AsyKeyGeneratorBySpecTest056, TestSize.Level0) { + ConstructEccKeyPairCommParamsSpec("NID_sm2", &g_eccCommSpec); + ASSERT_NE(g_eccCommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - int32_t res = ConstructSm2256PubKeyParamsSpec(g_sm2AlgName, ¶mSpec); - + HcfResult res = ConstructEccPubKeyParamsSpec(g_sm2AlgName.c_str(), g_eccCommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); HcfAsyKeyGeneratorBySpec *generator = nullptr; res = HcfAsyKeyGeneratorBySpecCreate(paramSpec, &generator); - ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(generator, nullptr); HcfPubKey *pubKey = nullptr; res = generator->generatePubKey(generator, &pubKey); - ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(pubKey, nullptr); pubKey->base.base.destroy(nullptr); - HcfObjDestroy(pubKey); HcfObjDestroy(generator); + DestroyEccPubKeySpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoSm2AsyKeyGeneratorBySpecTest, CryptoSm2AsyKeyGeneratorBySpecTest057, TestSize.Level0) { + ConstructEccKeyPairCommParamsSpec("NID_sm2", &g_eccCommSpec); + ASSERT_NE(g_eccCommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - int32_t res = ConstructSm2256PubKeyParamsSpec(g_sm2AlgName, ¶mSpec); - + HcfResult res = ConstructEccPubKeyParamsSpec(g_sm2AlgName.c_str(), g_eccCommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); HcfAsyKeyGeneratorBySpec *generator = nullptr; res = HcfAsyKeyGeneratorBySpecCreate(paramSpec, &generator); - ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(generator, nullptr); HcfPubKey *pubKey = nullptr; res = generator->generatePubKey(generator, &pubKey); - ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(pubKey, nullptr); pubKey->base.base.destroy(&g_obj); - HcfObjDestroy(pubKey); HcfObjDestroy(generator); + DestroyEccPubKeySpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoSm2AsyKeyGeneratorBySpecTest, CryptoSm2AsyKeyGeneratorBySpecTest058, TestSize.Level0) { + ConstructEccKeyPairCommParamsSpec("NID_sm2", &g_eccCommSpec); + ASSERT_NE(g_eccCommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - int32_t res = ConstructSm2256PubKeyParamsSpec(g_sm2AlgName, ¶mSpec); - + HcfResult res = ConstructEccPubKeyParamsSpec(g_sm2AlgName.c_str(), g_eccCommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); HcfAsyKeyGeneratorBySpec *generator = nullptr; res = HcfAsyKeyGeneratorBySpecCreate(paramSpec, &generator); - ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(generator, nullptr); HcfPubKey *pubKey = nullptr; res = generator->generatePubKey(generator, &pubKey); - ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(pubKey, nullptr); const char *format = pubKey->base.getFormat(&(pubKey->base)); - ASSERT_NE(format, nullptr); HcfObjDestroy(pubKey); HcfObjDestroy(generator); + DestroyEccPubKeySpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoSm2AsyKeyGeneratorBySpecTest, CryptoSm2AsyKeyGeneratorBySpecTest059, TestSize.Level0) { + ConstructEccKeyPairCommParamsSpec("NID_sm2", &g_eccCommSpec); + ASSERT_NE(g_eccCommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - int32_t res = ConstructSm2256PubKeyParamsSpec(g_sm2AlgName, ¶mSpec); - + HcfResult res = ConstructEccPubKeyParamsSpec(g_sm2AlgName.c_str(), g_eccCommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); HcfAsyKeyGeneratorBySpec *generator = nullptr; res = HcfAsyKeyGeneratorBySpecCreate(paramSpec, &generator); - ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(generator, nullptr); HcfPubKey *pubKey = nullptr; res = generator->generatePubKey(generator, &pubKey); - ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(pubKey, nullptr); const char *format = pubKey->base.getFormat(nullptr); - ASSERT_EQ(format, nullptr); HcfObjDestroy(pubKey); HcfObjDestroy(generator); + DestroyEccPubKeySpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoSm2AsyKeyGeneratorBySpecTest, CryptoSm2AsyKeyGeneratorBySpecTest060, TestSize.Level0) { + ConstructEccKeyPairCommParamsSpec("NID_sm2", &g_eccCommSpec); + ASSERT_NE(g_eccCommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - int32_t res = ConstructSm2256PubKeyParamsSpec(g_sm2AlgName, ¶mSpec); - + HcfResult res = ConstructEccPubKeyParamsSpec(g_sm2AlgName.c_str(), g_eccCommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); HcfAsyKeyGeneratorBySpec *generator = nullptr; res = HcfAsyKeyGeneratorBySpecCreate(paramSpec, &generator); - ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(generator, nullptr); HcfPubKey *pubKey = nullptr; res = generator->generatePubKey(generator, &pubKey); - ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(pubKey, nullptr); const char *format = pubKey->base.getFormat((HcfKey *)&g_obj); - ASSERT_EQ(format, nullptr); HcfObjDestroy(pubKey); HcfObjDestroy(generator); + DestroyEccPubKeySpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoSm2AsyKeyGeneratorBySpecTest, CryptoSm2AsyKeyGeneratorBySpecTest061, TestSize.Level0) { + ConstructEccKeyPairCommParamsSpec("NID_sm2", &g_eccCommSpec); + ASSERT_NE(g_eccCommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - int32_t res = ConstructSm2256PubKeyParamsSpec(g_sm2AlgName, ¶mSpec); - + HcfResult res = ConstructEccPubKeyParamsSpec(g_sm2AlgName.c_str(), g_eccCommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); HcfAsyKeyGeneratorBySpec *generator = nullptr; res = HcfAsyKeyGeneratorBySpecCreate(paramSpec, &generator); - ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(generator, nullptr); HcfPubKey *pubKey = nullptr; res = generator->generatePubKey(generator, &pubKey); - ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(pubKey, nullptr); const char *algName = pubKey->base.getAlgorithm(&(pubKey->base)); - ASSERT_NE(algName, nullptr); HcfObjDestroy(pubKey); HcfObjDestroy(generator); + DestroyEccPubKeySpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoSm2AsyKeyGeneratorBySpecTest, CryptoSm2AsyKeyGeneratorBySpecTest062, TestSize.Level0) { + ConstructEccKeyPairCommParamsSpec("NID_sm2", &g_eccCommSpec); + ASSERT_NE(g_eccCommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - int32_t res = ConstructSm2256PubKeyParamsSpec(g_sm2AlgName, ¶mSpec); - + HcfResult res = ConstructEccPubKeyParamsSpec(g_sm2AlgName.c_str(), g_eccCommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); HcfAsyKeyGeneratorBySpec *generator = nullptr; res = HcfAsyKeyGeneratorBySpecCreate(paramSpec, &generator); - ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(generator, nullptr); HcfPubKey *pubKey = nullptr; res = generator->generatePubKey(generator, &pubKey); - ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(pubKey, nullptr); const char *algName = pubKey->base.getAlgorithm(nullptr); - ASSERT_EQ(algName, nullptr); HcfObjDestroy(pubKey); HcfObjDestroy(generator); + DestroyEccPubKeySpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoSm2AsyKeyGeneratorBySpecTest, CryptoSm2AsyKeyGeneratorBySpecTest063, TestSize.Level0) { + ConstructEccKeyPairCommParamsSpec("NID_sm2", &g_eccCommSpec); + ASSERT_NE(g_eccCommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - int32_t res = ConstructSm2256PubKeyParamsSpec(g_sm2AlgName, ¶mSpec); - + HcfResult res = ConstructEccPubKeyParamsSpec(g_sm2AlgName.c_str(), g_eccCommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); HcfAsyKeyGeneratorBySpec *generator = nullptr; res = HcfAsyKeyGeneratorBySpecCreate(paramSpec, &generator); - ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(generator, nullptr); HcfPubKey *pubKey = nullptr; res = generator->generatePubKey(generator, &pubKey); - ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(pubKey, nullptr); const char *algName = pubKey->base.getAlgorithm((HcfKey *)&g_obj); - ASSERT_EQ(algName, nullptr); HcfObjDestroy(pubKey); HcfObjDestroy(generator); + DestroyEccPubKeySpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoSm2AsyKeyGeneratorBySpecTest, CryptoSm2AsyKeyGeneratorBySpecTest064, TestSize.Level0) { + ConstructEccKeyPairCommParamsSpec("NID_sm2", &g_eccCommSpec); + ASSERT_NE(g_eccCommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - int32_t res = ConstructSm2256PubKeyParamsSpec(g_sm2AlgName, ¶mSpec); - + HcfResult res = ConstructEccPubKeyParamsSpec(g_sm2AlgName.c_str(), g_eccCommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); HcfAsyKeyGeneratorBySpec *generator = nullptr; res = HcfAsyKeyGeneratorBySpecCreate(paramSpec, &generator); - ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(generator, nullptr); HcfPubKey *pubKey = nullptr; res = generator->generatePubKey(generator, &pubKey); - ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(pubKey, nullptr); @@ -1889,30 +1702,29 @@ HWTEST_F(CryptoSm2AsyKeyGeneratorBySpecTest, CryptoSm2AsyKeyGeneratorBySpecTest0 ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(blob.data, nullptr); ASSERT_NE(blob.len, 0); - - free(blob.data); + HcfFree(blob.data); HcfObjDestroy(pubKey); HcfObjDestroy(generator); + DestroyEccPubKeySpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoSm2AsyKeyGeneratorBySpecTest, CryptoSm2AsyKeyGeneratorBySpecTest065, TestSize.Level0) { + ConstructEccKeyPairCommParamsSpec("NID_sm2", &g_eccCommSpec); + ASSERT_NE(g_eccCommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - int32_t res = ConstructSm2256PubKeyParamsSpec(g_sm2AlgName, ¶mSpec); - + HcfResult res = ConstructEccPubKeyParamsSpec(g_sm2AlgName.c_str(), g_eccCommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); HcfAsyKeyGeneratorBySpec *generator = nullptr; res = HcfAsyKeyGeneratorBySpecCreate(paramSpec, &generator); - ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(generator, nullptr); HcfPubKey *pubKey = nullptr; res = generator->generatePubKey(generator, &pubKey); - ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(pubKey, nullptr); @@ -1923,565 +1735,546 @@ HWTEST_F(CryptoSm2AsyKeyGeneratorBySpecTest, CryptoSm2AsyKeyGeneratorBySpecTest0 ASSERT_EQ(blob.data, nullptr); ASSERT_EQ(blob.len, 0); - free(blob.data); - + HcfFree(blob.data); HcfObjDestroy(pubKey); HcfObjDestroy(generator); + DestroyEccPubKeySpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoSm2AsyKeyGeneratorBySpecTest, CryptoSm2AsyKeyGeneratorBySpecTest066, TestSize.Level0) { + ConstructEccKeyPairCommParamsSpec("NID_sm2", &g_eccCommSpec); + ASSERT_NE(g_eccCommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - int32_t res = ConstructSm2256PubKeyParamsSpec(g_sm2AlgName, ¶mSpec); - + HcfResult res = ConstructEccPubKeyParamsSpec(g_sm2AlgName.c_str(), g_eccCommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); HcfAsyKeyGeneratorBySpec *generator = nullptr; res = HcfAsyKeyGeneratorBySpecCreate(paramSpec, &generator); - ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(generator, nullptr); HcfPubKey *pubKey = nullptr; res = generator->generatePubKey(generator, &pubKey); - ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(pubKey, nullptr); HcfBlob blob = { .data = nullptr, .len = 0 }; res = pubKey->base.getEncoded((HcfKey *)&g_obj, &blob); - ASSERT_NE(res, HCF_SUCCESS); ASSERT_EQ(blob.data, nullptr); ASSERT_EQ(blob.len, 0); - free(blob.data); - + HcfFree(blob.data); HcfObjDestroy(pubKey); HcfObjDestroy(generator); + DestroyEccPubKeySpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoSm2AsyKeyGeneratorBySpecTest, CryptoSm2AsyKeyGeneratorBySpecTest067, TestSize.Level0) { + ConstructEccKeyPairCommParamsSpec("NID_sm2", &g_eccCommSpec); + ASSERT_NE(g_eccCommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - int32_t res = ConstructSm2256PubKeyParamsSpec(g_sm2AlgName, ¶mSpec); - + HcfResult res = ConstructEccPubKeyParamsSpec(g_sm2AlgName.c_str(), g_eccCommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); HcfAsyKeyGeneratorBySpec *generator = nullptr; res = HcfAsyKeyGeneratorBySpecCreate(paramSpec, &generator); - ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(generator, nullptr); HcfPubKey *pubKey = nullptr; res = generator->generatePubKey(generator, &pubKey); - ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(pubKey, nullptr); res = pubKey->base.getEncoded(&(pubKey->base), nullptr); - ASSERT_NE(res, HCF_SUCCESS); HcfObjDestroy(pubKey); HcfObjDestroy(generator); + DestroyEccPubKeySpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoSm2AsyKeyGeneratorBySpecTest, CryptoSm2AsyKeyGeneratorBySpecTest068, TestSize.Level0) { + ConstructEccKeyPairCommParamsSpec("NID_sm2", &g_eccCommSpec); + ASSERT_NE(g_eccCommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - int32_t res = ConstructSm2256PriKeyParamsSpec(g_sm2AlgName, ¶mSpec); - + HcfResult res = ConstructEccPriKeyParamsSpec(g_sm2AlgName.c_str(), g_eccCommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); HcfAsyKeyGeneratorBySpec *generator = nullptr; res = HcfAsyKeyGeneratorBySpecCreate(paramSpec, &generator); - ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(generator, nullptr); HcfPriKey *priKey = nullptr; res = generator->generatePriKey(generator, &priKey); - ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(priKey, nullptr); HcfObjDestroy(priKey); HcfObjDestroy(generator); + DestroyEccPriKeySpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoSm2AsyKeyGeneratorBySpecTest, CryptoSm2AsyKeyGeneratorBySpecTest069, TestSize.Level0) { + ConstructEccKeyPairCommParamsSpec("NID_sm2", &g_eccCommSpec); + ASSERT_NE(g_eccCommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - int32_t res = ConstructSm2256PriKeyParamsSpec(g_sm2AlgName, ¶mSpec); - + HcfResult res = ConstructEccPriKeyParamsSpec(g_sm2AlgName.c_str(), g_eccCommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); HcfAsyKeyGeneratorBySpec *generator = nullptr; res = HcfAsyKeyGeneratorBySpecCreate(paramSpec, &generator); - ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(generator, nullptr); HcfPriKey *priKey = nullptr; res = generator->generatePriKey(nullptr, &priKey); - ASSERT_NE(res, HCF_SUCCESS); ASSERT_EQ(priKey, nullptr); HcfObjDestroy(priKey); HcfObjDestroy(generator); + DestroyEccPriKeySpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoSm2AsyKeyGeneratorBySpecTest, CryptoSm2AsyKeyGeneratorBySpecTest070, TestSize.Level0) { + ConstructEccKeyPairCommParamsSpec("NID_sm2", &g_eccCommSpec); + ASSERT_NE(g_eccCommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - int32_t res = ConstructSm2256PriKeyParamsSpec(g_sm2AlgName, ¶mSpec); - + HcfResult res = ConstructEccPriKeyParamsSpec(g_sm2AlgName.c_str(), g_eccCommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); HcfAsyKeyGeneratorBySpec *generator = nullptr; res = HcfAsyKeyGeneratorBySpecCreate(paramSpec, &generator); - ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(generator, nullptr); res = generator->generatePriKey(generator, nullptr); - ASSERT_NE(res, HCF_SUCCESS); HcfObjDestroy(generator); + DestroyEccPriKeySpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoSm2AsyKeyGeneratorBySpecTest, CryptoSm2AsyKeyGeneratorBySpecTest071, TestSize.Level0) { + ConstructEccKeyPairCommParamsSpec("NID_sm2", &g_eccCommSpec); + ASSERT_NE(g_eccCommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - int32_t res = ConstructSm2256PriKeyParamsSpec(g_sm2AlgName, ¶mSpec); - + HcfResult res = ConstructEccPriKeyParamsSpec(g_sm2AlgName.c_str(), g_eccCommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); HcfAsyKeyGeneratorBySpec *generator = nullptr; res = HcfAsyKeyGeneratorBySpecCreate(paramSpec, &generator); - ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(generator, nullptr); res = generator->generatePriKey(nullptr, nullptr); - ASSERT_NE(res, HCF_SUCCESS); HcfObjDestroy(generator); + DestroyEccPriKeySpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoSm2AsyKeyGeneratorBySpecTest, CryptoSm2AsyKeyGeneratorBySpecTest072, TestSize.Level0) { + ConstructEccKeyPairCommParamsSpec("NID_sm2", &g_eccCommSpec); + ASSERT_NE(g_eccCommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - int32_t res = ConstructSm2256PriKeyParamsSpec(g_sm2AlgName, ¶mSpec); - + HcfResult res = ConstructEccPriKeyParamsSpec(g_sm2AlgName.c_str(), g_eccCommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); HcfAsyKeyGeneratorBySpec *generator = nullptr; res = HcfAsyKeyGeneratorBySpecCreate(paramSpec, &generator); - ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(generator, nullptr); HcfPriKey *priKey = nullptr; res = generator->generatePriKey(generator, &priKey); - ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(priKey, nullptr); const char *className = priKey->base.base.getClass(); - ASSERT_NE(className, nullptr); HcfObjDestroy(priKey); HcfObjDestroy(generator); + DestroyEccPriKeySpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoSm2AsyKeyGeneratorBySpecTest, CryptoSm2AsyKeyGeneratorBySpecTest073, TestSize.Level0) { + ConstructEccKeyPairCommParamsSpec("NID_sm2", &g_eccCommSpec); + ASSERT_NE(g_eccCommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - int32_t res = ConstructSm2256PriKeyParamsSpec(g_sm2AlgName, ¶mSpec); - + HcfResult res = ConstructEccPriKeyParamsSpec(g_sm2AlgName.c_str(), g_eccCommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); HcfAsyKeyGeneratorBySpec *generator = nullptr; res = HcfAsyKeyGeneratorBySpecCreate(paramSpec, &generator); - ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(generator, nullptr); HcfPriKey *priKey = nullptr; res = generator->generatePriKey(generator, &priKey); - ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(priKey, nullptr); priKey->base.base.destroy((HcfObjectBase *)(&(priKey->base.base))); - HcfObjDestroy(generator); + DestroyEccPriKeySpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoSm2AsyKeyGeneratorBySpecTest, CryptoSm2AsyKeyGeneratorBySpecTest074, TestSize.Level0) { + ConstructEccKeyPairCommParamsSpec("NID_sm2", &g_eccCommSpec); + ASSERT_NE(g_eccCommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - int32_t res = ConstructSm2256PriKeyParamsSpec(g_sm2AlgName, ¶mSpec); - + HcfResult res = ConstructEccPriKeyParamsSpec(g_sm2AlgName.c_str(), g_eccCommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); HcfAsyKeyGeneratorBySpec *generator = nullptr; res = HcfAsyKeyGeneratorBySpecCreate(paramSpec, &generator); - ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(generator, nullptr); HcfPriKey *priKey = nullptr; res = generator->generatePriKey(generator, &priKey); - ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(priKey, nullptr); priKey->base.base.destroy(nullptr); - HcfObjDestroy(priKey); HcfObjDestroy(generator); + DestroyEccPriKeySpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoSm2AsyKeyGeneratorBySpecTest, CryptoSm2AsyKeyGeneratorBySpecTest075, TestSize.Level0) { + ConstructEccKeyPairCommParamsSpec("NID_sm2", &g_eccCommSpec); + ASSERT_NE(g_eccCommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - int32_t res = ConstructSm2256PriKeyParamsSpec(g_sm2AlgName, ¶mSpec); - + HcfResult res = ConstructEccPriKeyParamsSpec(g_sm2AlgName.c_str(), g_eccCommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); HcfAsyKeyGeneratorBySpec *generator = nullptr; res = HcfAsyKeyGeneratorBySpecCreate(paramSpec, &generator); - ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(generator, nullptr); HcfPriKey *priKey = nullptr; res = generator->generatePriKey(generator, &priKey); - ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(priKey, nullptr); priKey->base.base.destroy(&g_obj); - HcfObjDestroy(priKey); HcfObjDestroy(generator); + DestroyEccPriKeySpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoSm2AsyKeyGeneratorBySpecTest, CryptoSm2AsyKeyGeneratorBySpecTest076, TestSize.Level0) { + ConstructEccKeyPairCommParamsSpec("NID_sm2", &g_eccCommSpec); + ASSERT_NE(g_eccCommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - int32_t res = ConstructSm2256PriKeyParamsSpec(g_sm2AlgName, ¶mSpec); - + HcfResult res = ConstructEccPriKeyParamsSpec(g_sm2AlgName.c_str(), g_eccCommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); HcfAsyKeyGeneratorBySpec *generator = nullptr; res = HcfAsyKeyGeneratorBySpecCreate(paramSpec, &generator); - ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(generator, nullptr); HcfPriKey *priKey = nullptr; res = generator->generatePriKey(generator, &priKey); - ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(priKey, nullptr); res = priKey->base.getEncoded(&(priKey->base), nullptr); - ASSERT_NE(res, HCF_SUCCESS); HcfObjDestroy(priKey); HcfObjDestroy(generator); + DestroyEccPriKeySpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoSm2AsyKeyGeneratorBySpecTest, CryptoSm2AsyKeyGeneratorBySpecTest077, TestSize.Level0) { + ConstructEccKeyPairCommParamsSpec("NID_sm2", &g_eccCommSpec); + ASSERT_NE(g_eccCommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - int32_t res = ConstructSm2256PriKeyParamsSpec(g_sm2AlgName, ¶mSpec); - + HcfResult res = ConstructEccPriKeyParamsSpec(g_sm2AlgName.c_str(), g_eccCommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); HcfAsyKeyGeneratorBySpec *generator = nullptr; res = HcfAsyKeyGeneratorBySpecCreate(paramSpec, &generator); - ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(generator, nullptr); HcfPriKey *priKey = nullptr; res = generator->generatePriKey(generator, &priKey); - ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(priKey, nullptr); priKey->clearMem(priKey); - HcfObjDestroy(priKey); HcfObjDestroy(generator); + DestroyEccPriKeySpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoSm2AsyKeyGeneratorBySpecTest, CryptoSm2AsyKeyGeneratorBySpecTest078, TestSize.Level0) { + ConstructEccKeyPairCommParamsSpec("NID_sm2", &g_eccCommSpec); + ASSERT_NE(g_eccCommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - int32_t res = ConstructSm2256PriKeyParamsSpec(g_sm2AlgName, ¶mSpec); - + HcfResult res = ConstructEccPriKeyParamsSpec(g_sm2AlgName.c_str(), g_eccCommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); HcfAsyKeyGeneratorBySpec *generator = nullptr; res = HcfAsyKeyGeneratorBySpecCreate(paramSpec, &generator); - ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(generator, nullptr); HcfPriKey *priKey = nullptr; res = generator->generatePriKey(generator, &priKey); - ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(priKey, nullptr); priKey->clearMem(nullptr); - HcfObjDestroy(priKey); HcfObjDestroy(generator); + DestroyEccPriKeySpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoSm2AsyKeyGeneratorBySpecTest, CryptoSm2AsyKeyGeneratorBySpecTest079, TestSize.Level0) { + ConstructEccKeyPairCommParamsSpec("NID_sm2", &g_eccCommSpec); + ASSERT_NE(g_eccCommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - int32_t res = ConstructSm2256PriKeyParamsSpec(g_sm2AlgName, ¶mSpec); - + HcfResult res = ConstructEccPriKeyParamsSpec(g_sm2AlgName.c_str(), g_eccCommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); HcfAsyKeyGeneratorBySpec *generator = nullptr; res = HcfAsyKeyGeneratorBySpecCreate(paramSpec, &generator); - ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(generator, nullptr); HcfPriKey *priKey = nullptr; res = generator->generatePriKey(generator, &priKey); - ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(priKey, nullptr); const char *format = priKey->base.getFormat(&priKey->base); - ASSERT_NE(format, nullptr); HcfObjDestroy(priKey); HcfObjDestroy(generator); + DestroyEccPriKeySpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoSm2AsyKeyGeneratorBySpecTest, CryptoSm2AsyKeyGeneratorBySpecTest080, TestSize.Level0) { + ConstructEccKeyPairCommParamsSpec("NID_sm2", &g_eccCommSpec); + ASSERT_NE(g_eccCommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - int32_t res = ConstructSm2256PriKeyParamsSpec(g_sm2AlgName, ¶mSpec); - + HcfResult res = ConstructEccPriKeyParamsSpec(g_sm2AlgName.c_str(), g_eccCommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); HcfAsyKeyGeneratorBySpec *generator = nullptr; res = HcfAsyKeyGeneratorBySpecCreate(paramSpec, &generator); - ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(generator, nullptr); HcfPriKey *priKey = nullptr; res = generator->generatePriKey(generator, &priKey); - ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(priKey, nullptr); const char *format = priKey->base.getFormat(nullptr); - ASSERT_EQ(format, nullptr); HcfObjDestroy(priKey); HcfObjDestroy(generator); + DestroyEccPriKeySpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoSm2AsyKeyGeneratorBySpecTest, CryptoSm2AsyKeyGeneratorBySpecTest081, TestSize.Level0) { + ConstructEccKeyPairCommParamsSpec("NID_sm2", &g_eccCommSpec); + ASSERT_NE(g_eccCommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - int32_t res = ConstructSm2256PriKeyParamsSpec(g_sm2AlgName, ¶mSpec); - + HcfResult res = ConstructEccPriKeyParamsSpec(g_sm2AlgName.c_str(), g_eccCommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); HcfAsyKeyGeneratorBySpec *generator = nullptr; res = HcfAsyKeyGeneratorBySpecCreate(paramSpec, &generator); - ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(generator, nullptr); HcfPriKey *priKey = nullptr; res = generator->generatePriKey(generator, &priKey); - ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(priKey, nullptr); const char *format = priKey->base.getFormat((HcfKey *)&g_obj); - ASSERT_EQ(format, nullptr); HcfObjDestroy(priKey); HcfObjDestroy(generator); + DestroyEccPriKeySpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoSm2AsyKeyGeneratorBySpecTest, CryptoSm2AsyKeyGeneratorBySpecTest082, TestSize.Level0) { + ConstructEccKeyPairCommParamsSpec("NID_sm2", &g_eccCommSpec); + ASSERT_NE(g_eccCommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - int32_t res = ConstructSm2256PriKeyParamsSpec(g_sm2AlgName, ¶mSpec); - + HcfResult res = ConstructEccPriKeyParamsSpec(g_sm2AlgName.c_str(), g_eccCommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); HcfAsyKeyGeneratorBySpec *generator = nullptr; res = HcfAsyKeyGeneratorBySpecCreate(paramSpec, &generator); - ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(generator, nullptr); HcfPriKey *priKey = nullptr; res = generator->generatePriKey(generator, &priKey); - ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(priKey, nullptr); const char *algName = priKey->base.getAlgorithm(&priKey->base); - ASSERT_NE(algName, nullptr); HcfObjDestroy(priKey); HcfObjDestroy(generator); + DestroyEccPriKeySpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoSm2AsyKeyGeneratorBySpecTest, CryptoSm2AsyKeyGeneratorBySpecTest083, TestSize.Level0) { + ConstructEccKeyPairCommParamsSpec("NID_sm2", &g_eccCommSpec); + ASSERT_NE(g_eccCommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - int32_t res = ConstructSm2256PriKeyParamsSpec(g_sm2AlgName, ¶mSpec); - + HcfResult res = ConstructEccPriKeyParamsSpec(g_sm2AlgName.c_str(), g_eccCommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); HcfAsyKeyGeneratorBySpec *generator = nullptr; res = HcfAsyKeyGeneratorBySpecCreate(paramSpec, &generator); - ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(generator, nullptr); HcfPriKey *priKey = nullptr; res = generator->generatePriKey(generator, &priKey); - ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(priKey, nullptr); const char *algName = priKey->base.getAlgorithm(nullptr); - ASSERT_EQ(algName, nullptr); HcfObjDestroy(priKey); HcfObjDestroy(generator); + DestroyEccPriKeySpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoSm2AsyKeyGeneratorBySpecTest, CryptoSm2AsyKeyGeneratorBySpecTest084, TestSize.Level0) { + ConstructEccKeyPairCommParamsSpec("NID_sm2", &g_eccCommSpec); + ASSERT_NE(g_eccCommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - int32_t res = ConstructSm2256PriKeyParamsSpec(g_sm2AlgName, ¶mSpec); - + HcfResult res = ConstructEccPriKeyParamsSpec(g_sm2AlgName.c_str(), g_eccCommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); HcfAsyKeyGeneratorBySpec *generator = nullptr; res = HcfAsyKeyGeneratorBySpecCreate(paramSpec, &generator); - ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(generator, nullptr); HcfPriKey *priKey = nullptr; res = generator->generatePriKey(generator, &priKey); - ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(priKey, nullptr); const char *algName = priKey->base.getAlgorithm((HcfKey *)&g_obj); - ASSERT_EQ(algName, nullptr); HcfObjDestroy(priKey); HcfObjDestroy(generator); + DestroyEccPriKeySpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoSm2AsyKeyGeneratorBySpecTest, CryptoSm2AsyKeyGeneratorBySpecTest085, TestSize.Level0) { + ConstructEccKeyPairCommParamsSpec("NID_sm2", &g_eccCommSpec); + ASSERT_NE(g_eccCommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - int32_t res = ConstructSm2256PriKeyParamsSpec(g_sm2AlgName, ¶mSpec); - + HcfResult res = ConstructEccPriKeyParamsSpec(g_sm2AlgName.c_str(), g_eccCommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); HcfAsyKeyGeneratorBySpec *generator = nullptr; res = HcfAsyKeyGeneratorBySpecCreate(paramSpec, &generator); - ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(generator, nullptr); HcfPriKey *priKey = nullptr; res = generator->generatePriKey(generator, &priKey); - ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(priKey, nullptr); HcfBlob blob = {.data = nullptr, .len = 0}; res = priKey->base.getEncoded(&(priKey->base), &blob); - ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(blob.data, nullptr); ASSERT_NE(blob.len, 0); - free(blob.data); - + HcfFree(blob.data); HcfObjDestroy(priKey); HcfObjDestroy(generator); + DestroyEccPriKeySpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoSm2AsyKeyGeneratorBySpecTest, CryptoSm2AsyKeyGeneratorBySpecTest086, TestSize.Level0) { + ConstructEccKeyPairCommParamsSpec("NID_sm2", &g_eccCommSpec); + ASSERT_NE(g_eccCommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - int32_t res = ConstructSm2256PriKeyParamsSpec(g_sm2AlgName, ¶mSpec); - + HcfResult res = ConstructEccPriKeyParamsSpec(g_sm2AlgName.c_str(), g_eccCommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); HcfAsyKeyGeneratorBySpec *generator = nullptr; res = HcfAsyKeyGeneratorBySpecCreate(paramSpec, &generator); - ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(generator, nullptr); HcfPriKey *priKey = nullptr; res = generator->generatePriKey(generator, &priKey); - ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(priKey, nullptr); @@ -2492,90 +2285,86 @@ HWTEST_F(CryptoSm2AsyKeyGeneratorBySpecTest, CryptoSm2AsyKeyGeneratorBySpecTest0 ASSERT_EQ(blob.data, nullptr); ASSERT_EQ(blob.len, 0); - free(blob.data); - + HcfFree(blob.data); HcfObjDestroy(priKey); HcfObjDestroy(generator); + DestroyEccPriKeySpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoSm2AsyKeyGeneratorBySpecTest, CryptoSm2AsyKeyGeneratorBySpecTest087, TestSize.Level0) { + ConstructEccKeyPairCommParamsSpec("NID_sm2", &g_eccCommSpec); + ASSERT_NE(g_eccCommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - int32_t res = ConstructSm2256PriKeyParamsSpec(g_sm2AlgName, ¶mSpec); - + HcfResult res = ConstructEccPriKeyParamsSpec(g_sm2AlgName.c_str(), g_eccCommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); HcfAsyKeyGeneratorBySpec *generator = nullptr; res = HcfAsyKeyGeneratorBySpecCreate(paramSpec, &generator); - ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(generator, nullptr); HcfPriKey *priKey = nullptr; res = generator->generatePriKey(generator, &priKey); - ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(priKey, nullptr); HcfBlob blob = {.data = nullptr, .len = 0}; res = priKey->base.getEncoded((HcfKey *)&g_obj, &blob); - ASSERT_NE(res, HCF_SUCCESS); ASSERT_EQ(blob.data, nullptr); ASSERT_EQ(blob.len, 0); - free(blob.data); - + HcfFree(blob.data); HcfObjDestroy(priKey); HcfObjDestroy(generator); + DestroyEccPriKeySpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoSm2AsyKeyGeneratorBySpecTest, CryptoSm2AsyKeyGeneratorBySpecTest088, TestSize.Level0) { + ConstructEccKeyPairCommParamsSpec("NID_sm2", &g_eccCommSpec); + ASSERT_NE(g_eccCommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - int32_t res = ConstructSm2256PriKeyParamsSpec(g_sm2AlgName, ¶mSpec); - + HcfResult res = ConstructEccPriKeyParamsSpec(g_sm2AlgName.c_str(), g_eccCommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); HcfAsyKeyGeneratorBySpec *generator = nullptr; res = HcfAsyKeyGeneratorBySpecCreate(paramSpec, &generator); - ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(generator, nullptr); HcfPriKey *priKey = nullptr; res = generator->generatePriKey(generator, &priKey); - ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(priKey, nullptr); res = priKey->base.getEncoded(&(priKey->base), nullptr); - ASSERT_NE(res, HCF_SUCCESS); HcfObjDestroy(priKey); HcfObjDestroy(generator); + DestroyEccPriKeySpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoSm2AsyKeyGeneratorBySpecTest, CryptoSm2AsyKeyGeneratorBySpecTest089, TestSize.Level0) { + ConstructEccKeyPairCommParamsSpec("NID_sm2", &g_eccCommSpec); + ASSERT_NE(g_eccCommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - int32_t res = ConstructSm2256KeyPairParamsSpec(g_sm2AlgName, ¶mSpec); - + HcfResult res = ConstructEccKeyPairParamsSpec(g_sm2AlgName.c_str(), g_eccCommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); HcfAsyKeyGeneratorBySpec *generatorBySpec = nullptr; res = HcfAsyKeyGeneratorBySpecCreate(paramSpec, &generatorBySpec); - ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(generatorBySpec, nullptr); HcfKeyPair *keyPair = nullptr; res = generatorBySpec->generateKeyPair(generatorBySpec, &keyPair); - ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(keyPair, nullptr); @@ -2602,20 +2391,23 @@ HWTEST_F(CryptoSm2AsyKeyGeneratorBySpecTest, CryptoSm2AsyKeyGeneratorBySpecTest0 ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(outPriKeyBlob.data, nullptr); ASSERT_NE(outPriKeyBlob.len, 0); - free(pubKeyBlob.data); - free(priKeyBlob.data); - free(outPubKeyBlob.data); - free(outPriKeyBlob.data); + HcfFree(pubKeyBlob.data); + HcfFree(priKeyBlob.data); + HcfFree(outPubKeyBlob.data); + HcfFree(outPriKeyBlob.data); HcfObjDestroy(keyPair); HcfObjDestroy(outKeyPair); HcfObjDestroy(generator); HcfObjDestroy(generatorBySpec); + DestroyEccKeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoSm2AsyKeyGeneratorBySpecTest, CryptoSm2AsyKeyGeneratorBySpecTest090, TestSize.Level0) { + ConstructEccKeyPairCommParamsSpec("NID_sm2", &g_eccCommSpec); + ASSERT_NE(g_eccCommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - int32_t res = ConstructSm2256KeyPairParamsSpec(g_sm2AlgName, ¶mSpec); + HcfResult res = ConstructEccKeyPairParamsSpec(g_sm2AlgName.c_str(), g_eccCommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); HcfAsyKeyGeneratorBySpec *generator = nullptr; @@ -2656,12 +2448,15 @@ HWTEST_F(CryptoSm2AsyKeyGeneratorBySpecTest, CryptoSm2AsyKeyGeneratorBySpecTest0 HcfObjDestroy(keyPair); HcfObjDestroy(generator); + DestroyEccKeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoSm2AsyKeyGeneratorBySpecTest, CryptoSm2AsyKeyGeneratorBySpecTest091, TestSize.Level0) { + ConstructEccKeyPairCommParamsSpec("NID_sm2", &g_eccCommSpec); + ASSERT_NE(g_eccCommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - int32_t res = ConstructSm2256KeyPairParamsSpec(g_sm2AlgName, ¶mSpec); + HcfResult res = ConstructEccKeyPairParamsSpec(g_sm2AlgName.c_str(), g_eccCommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); HcfAsyKeyGeneratorBySpec *generator = nullptr; @@ -2701,19 +2496,18 @@ HWTEST_F(CryptoSm2AsyKeyGeneratorBySpecTest, CryptoSm2AsyKeyGeneratorBySpecTest0 ASSERT_NE(verify, nullptr); res = verify->init(verify, nullptr, keyPair->pubKey); - ASSERT_EQ(res, HCF_SUCCESS); bool flag = verify->verify(verify, &g_mockInput, &out); - ASSERT_EQ(flag, true); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); HcfObjDestroy(verify); HcfObjDestroy(keyPair); HcfObjDestroy(generator); + DestroyEccKeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoSm2AsyKeyGeneratorBySpecTest, CryptoSm2AsyKeyGeneratorBySpecTest092, TestSize.Level0) @@ -2725,13 +2519,14 @@ HWTEST_F(CryptoSm2AsyKeyGeneratorBySpecTest, CryptoSm2AsyKeyGeneratorBySpecTest0 }; HcfAsyKeyGeneratorSpi *spiObj = nullptr; - int32_t res = HcfAsyKeyGeneratorSpiSm2Create(¶ms, &spiObj); - + HcfResult res = HcfAsyKeyGeneratorSpiSm2Create(¶ms, &spiObj); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(spiObj, nullptr); + ConstructEccKeyPairCommParamsSpec("NID_sm2", &g_eccCommSpec); + ASSERT_NE(g_eccCommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - res = ConstructSm2256KeyPairParamsSpec(g_sm2AlgName, ¶mSpec); + res = ConstructEccKeyPairParamsSpec(g_sm2AlgName.c_str(), g_eccCommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); @@ -2740,6 +2535,7 @@ HWTEST_F(CryptoSm2AsyKeyGeneratorBySpecTest, CryptoSm2AsyKeyGeneratorBySpecTest0 ASSERT_EQ(res, HCF_SUCCESS); HcfObjDestroy(spiObj); + DestroyEccKeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoSm2AsyKeyGeneratorBySpecTest, CryptoSm2AsyKeyGeneratorBySpecTest093, TestSize.Level0) @@ -2751,13 +2547,14 @@ HWTEST_F(CryptoSm2AsyKeyGeneratorBySpecTest, CryptoSm2AsyKeyGeneratorBySpecTest0 }; HcfAsyKeyGeneratorSpi *spiObj = nullptr; - int32_t res = HcfAsyKeyGeneratorSpiSm2Create(¶ms, &spiObj); - + HcfResult res = HcfAsyKeyGeneratorSpiSm2Create(¶ms, &spiObj); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(spiObj, nullptr); + ConstructEccKeyPairCommParamsSpec("NID_sm2", &g_eccCommSpec); + ASSERT_NE(g_eccCommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - res = ConstructSm2256KeyPairParamsSpec(g_sm2AlgName, ¶mSpec); + res = ConstructEccKeyPairParamsSpec(g_sm2AlgName.c_str(), g_eccCommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); @@ -2766,6 +2563,7 @@ HWTEST_F(CryptoSm2AsyKeyGeneratorBySpecTest, CryptoSm2AsyKeyGeneratorBySpecTest0 ASSERT_EQ(res, HCF_SUCCESS); HcfObjDestroy(spiObj); + DestroyEccKeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoSm2AsyKeyGeneratorBySpecTest, CryptoSm2AsyKeyGeneratorBySpecTest094, TestSize.Level0) @@ -2777,13 +2575,14 @@ HWTEST_F(CryptoSm2AsyKeyGeneratorBySpecTest, CryptoSm2AsyKeyGeneratorBySpecTest0 }; HcfAsyKeyGeneratorSpi *spiObj = nullptr; - int32_t res = HcfAsyKeyGeneratorSpiSm2Create(¶ms, &spiObj); - + HcfResult res = HcfAsyKeyGeneratorSpiSm2Create(¶ms, &spiObj); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(spiObj, nullptr); + ConstructEccKeyPairCommParamsSpec("NID_sm2", &g_eccCommSpec); + ASSERT_NE(g_eccCommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - res = ConstructSm2256KeyPairParamsSpec(g_sm2AlgName, ¶mSpec); + res = ConstructEccKeyPairParamsSpec(g_sm2AlgName.c_str(), g_eccCommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); @@ -2792,6 +2591,7 @@ HWTEST_F(CryptoSm2AsyKeyGeneratorBySpecTest, CryptoSm2AsyKeyGeneratorBySpecTest0 ASSERT_EQ(res, HCF_SUCCESS); HcfObjDestroy(spiObj); + DestroyEccKeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoSm2AsyKeyGeneratorBySpecTest, CryptoSm2AsyKeyGeneratorBySpecTest095, TestSize.Level0) @@ -2803,7 +2603,7 @@ HWTEST_F(CryptoSm2AsyKeyGeneratorBySpecTest, CryptoSm2AsyKeyGeneratorBySpecTest0 }; HcfAsyKeyGeneratorSpi *spiObj = nullptr; - int32_t res = HcfAsyKeyGeneratorSpiSm2Create(¶ms, &spiObj); + HcfResult res = HcfAsyKeyGeneratorSpiSm2Create(¶ms, &spiObj); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(spiObj, nullptr); @@ -2818,12 +2618,15 @@ HWTEST_F(CryptoSm2AsyKeyGeneratorBySpecTest, CryptoSm2AsyKeyGeneratorBySpecTest0 ASSERT_EQ(res, HCF_SUCCESS); HcfObjDestroy(spiObj); + FreeEccCommParamsSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoSm2AsyKeyGeneratorBySpecTest, CryptoSm2AsyKeyGeneratorBySpecTest096, TestSize.Level0) { + ConstructEccKeyPairCommParamsSpec("NID_sm2", &g_eccCommSpec); + ASSERT_NE(g_eccCommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - int32_t res = ConstructSm2256KeyPairParamsSpec(g_sm2AlgName, ¶mSpec); + HcfResult res = ConstructEccKeyPairParamsSpec(g_sm2AlgName.c_str(), g_eccCommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); @@ -2844,16 +2647,18 @@ HWTEST_F(CryptoSm2AsyKeyGeneratorBySpecTest, CryptoSm2AsyKeyGeneratorBySpecTest0 ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(retStr, nullptr); - free(retStr); - + HcfFree(retStr); HcfObjDestroy(priKey); HcfObjDestroy(generator); + DestroyEccKeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoSm2AsyKeyGeneratorBySpecTest, CryptoSm2AsyKeyGeneratorBySpecTest097, TestSize.Level0) { + ConstructEccKeyPairCommParamsSpec("NID_sm2", &g_eccCommSpec); + ASSERT_NE(g_eccCommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - int32_t res = ConstructSm2256KeyPairParamsSpec(g_sm2AlgName, ¶mSpec); + HcfResult res = ConstructEccKeyPairParamsSpec(g_sm2AlgName.c_str(), g_eccCommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); @@ -2874,13 +2679,13 @@ HWTEST_F(CryptoSm2AsyKeyGeneratorBySpecTest, CryptoSm2AsyKeyGeneratorBySpecTest0 HcfObjDestroy(pubKey); HcfObjDestroy(generator); + DestroyEccKeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoSm2AsyKeyGeneratorBySpecTest, CryptoSm2AsyKeyGeneratorBySpecTest098, TestSize.Level0) { HcfAsyKeyParamsSpec *paramSpec = nullptr; - int32_t res = ConstructSm2256CommParamsSpec(¶mSpec); - + HcfResult res = ConstructSm2256CommParamsSpec(¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); HcfAsyKeyGeneratorBySpec *generator = nullptr; @@ -2888,7 +2693,6 @@ HWTEST_F(CryptoSm2AsyKeyGeneratorBySpecTest, CryptoSm2AsyKeyGeneratorBySpecTest0 HcfKeyPair *keyPair = nullptr; res = generator->generateKeyPair(generator, &keyPair); - ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(keyPair, nullptr); @@ -2902,18 +2706,16 @@ HWTEST_F(CryptoSm2AsyKeyGeneratorBySpecTest, CryptoSm2AsyKeyGeneratorBySpecTest0 res = keyPair->pubKey->getAsyKeySpecString(keyPair->pubKey, item, &retStr); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(retStr, nullptr); - - free(retStr); - + HcfFree(retStr); HcfObjDestroy(keyPair); HcfObjDestroy(generator); + FreeEccCommParamsSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoSm2AsyKeyGeneratorBySpecTest, CryptoSm2AsyKeyGeneratorBySpecTest099, TestSize.Level0) { HcfAsyKeyParamsSpec *paramSpec = nullptr; - int32_t res = ConstructSm2256CommParamsSpec(¶mSpec); - + HcfResult res = ConstructSm2256CommParamsSpec(¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); HcfAsyKeyGeneratorBySpec *generator = nullptr; @@ -2921,24 +2723,25 @@ HWTEST_F(CryptoSm2AsyKeyGeneratorBySpecTest, CryptoSm2AsyKeyGeneratorBySpecTest0 HcfKeyPair *keyPair = nullptr; res = generator->generateKeyPair(generator, &keyPair); - ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(keyPair, nullptr); AsyKeySpecItem item = ECC_FIELD_TYPE_STR; res = keyPair->pubKey->getAsyKeySpecString(keyPair->pubKey, item, nullptr); - ASSERT_EQ(res, HCF_INVALID_PARAMS); HcfObjDestroy(keyPair); HcfObjDestroy(generator); + FreeEccCommParamsSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoSm2AsyKeyGeneratorBySpecTest, CryptoSm2AsyKeyGeneratorBySpecTest100, TestSize.Level0) { + ConstructEccKeyPairCommParamsSpec("NID_sm2", &g_eccCommSpec); + ASSERT_NE(g_eccCommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - int32_t res = ConstructSm2256KeyPairParamsSpec(g_sm2AlgName, ¶mSpec); + HcfResult res = ConstructEccKeyPairParamsSpec(g_sm2AlgName.c_str(), g_eccCommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); @@ -2964,12 +2767,15 @@ HWTEST_F(CryptoSm2AsyKeyGeneratorBySpecTest, CryptoSm2AsyKeyGeneratorBySpecTest1 HcfObjDestroy(keyPair); HcfObjDestroy(generator); + DestroyEccKeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoSm2AsyKeyGeneratorBySpecTest, CryptoSm2AsyKeyGeneratorBySpecTest101, TestSize.Level0) { + ConstructEccKeyPairCommParamsSpec("NID_sm2", &g_eccCommSpec); + ASSERT_NE(g_eccCommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - int32_t res = ConstructSm2256KeyPairParamsSpec(g_sm2AlgName, ¶mSpec); + HcfResult res = ConstructEccKeyPairParamsSpec(g_sm2AlgName.c_str(), g_eccCommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); @@ -2994,6 +2800,7 @@ HWTEST_F(CryptoSm2AsyKeyGeneratorBySpecTest, CryptoSm2AsyKeyGeneratorBySpecTest1 ASSERT_EQ(res, HCF_INVALID_PARAMS); HcfObjDestroy(keyPair); HcfObjDestroy(generator); + DestroyEccKeyPairSpec(reinterpret_cast(paramSpec)); } static HcfResult ConstructSm2256KeyPairParamsSpecByGet(HcfEccKeyPairParamsSpec *eccKeyPairSpec, @@ -3003,10 +2810,10 @@ static HcfResult ConstructSm2256KeyPairParamsSpecByGet(HcfEccKeyPairParamsSpec * eccKeyPairSpec->base.base.specType = HCF_KEY_PAIR_SPEC; eccKeyPairSpec->base.field = g_eccCommSpec->field; eccKeyPairSpec->base.field->fieldType = g_eccCommSpec->field->fieldType; - ((HcfECFieldFp *)(eccKeyPairSpec->base.field))->p.data = params[ZERO].data; - ((HcfECFieldFp *)(eccKeyPairSpec->base.field))->p.len = params[ZERO].len; - eccKeyPairSpec->base.a.data = params[ONE].data; - eccKeyPairSpec->base.a.len = params[ONE].len; + ((HcfECFieldFp *)(eccKeyPairSpec->base.field))->p.data = params[0].data; + ((HcfECFieldFp *)(eccKeyPairSpec->base.field))->p.len = params[0].len; + eccKeyPairSpec->base.a.data = params[1].data; + eccKeyPairSpec->base.a.len = params[1].len; eccKeyPairSpec->base.b.data = params[TWO].data; eccKeyPairSpec->base.b.len = params[TWO].len; eccKeyPairSpec->base.g.x.data = params[THREE].data; @@ -3030,7 +2837,7 @@ static HcfResult ConstructSm2256KeyPairParamsSpecByGet(HcfEccKeyPairParamsSpec * HWTEST_F(CryptoSm2AsyKeyGeneratorBySpecTest, CryptoSm2AsyKeyGeneratorBySpecTest102, TestSize.Level0) { HcfAsyKeyGenerator *generator = nullptr; - int32_t res = HcfAsyKeyGeneratorCreate(g_sm2AlgName.c_str(), &generator); + HcfResult res = HcfAsyKeyGeneratorCreate(g_sm2AlgName.c_str(), &generator); HcfKeyPair *keyPair = nullptr; res = generator->generateKeyPair(generator, nullptr, &keyPair); @@ -3074,21 +2881,23 @@ HWTEST_F(CryptoSm2AsyKeyGeneratorBySpecTest, CryptoSm2AsyKeyGeneratorBySpecTest1 params[0].len = retFp.len; params[1].data = retA.data; params[1].len = retA.len; - params[2].data = retB.data; - params[2].len = retB.len; - params[3].data = retGX.data; - params[3].len = retGX.len; - params[4].data = retGY.data; - params[4].len = retGY.len; - params[5].data = retN.data; - params[5].len = retN.len; - params[6].data = retPkX.data; - params[6].len = retPkX.len; - params[7].data = retPkY.data; - params[7].len = retPkY.len; - params[8].data = retSk.data; - params[8].len = retSk.len; - + params[TWO].data = retB.data; + params[TWO].len = retB.len; + params[THREE].data = retGX.data; + params[THREE].len = retGX.len; + params[FOUR].data = retGY.data; + params[FOUR].len = retGY.len; + params[FIVE].data = retN.data; + params[FIVE].len = retN.len; + params[SIX].data = retPkX.data; + params[SIX].len = retPkX.len; + params[SEVEN].data = retPkY.data; + params[SEVEN].len = retPkY.len; + params[EIGHT].data = retSk.data; + params[EIGHT].len = retSk.len; + + ConstructEccKeyPairCommParamsSpec("NID_sm2", &g_eccCommSpec); + ASSERT_NE(g_eccCommSpec, nullptr); HcfEccKeyPairParamsSpec eccKeyPairSpec = {}; res = ConstructSm2256KeyPairParamsSpecByGet(&eccKeyPairSpec, params, retH); HcfAsyKeyGeneratorBySpec *generatorSpec = nullptr; @@ -3105,16 +2914,17 @@ HWTEST_F(CryptoSm2AsyKeyGeneratorBySpecTest, CryptoSm2AsyKeyGeneratorBySpecTest1 HcfObjDestroy(keyPair); HcfObjDestroy(generator); HcfObjDestroy(generatorSpec); + FreeEccCommParamsSpec(reinterpret_cast(g_eccCommSpec)); } static void OpensslMockTestFunc(uint32_t mallocCount, HcfAsyKeyParamsSpec *paramSpec) { - for (int i = 0; i < mallocCount - THREE; i++) { + for (uint32_t i = 0; i < mallocCount - THREE; i++) { ResetOpensslCallNum(); SetOpensslCallMockIndex(i); HcfAsyKeyGeneratorBySpec *generatorBySpec = nullptr; - int32_t res = HcfAsyKeyGeneratorBySpecCreate(paramSpec, &generatorBySpec); + HcfResult res = HcfAsyKeyGeneratorBySpecCreate(paramSpec, &generatorBySpec); if (res != HCF_SUCCESS) { continue; } @@ -3136,8 +2946,8 @@ static void OpensslMockTestFunc(uint32_t mallocCount, HcfAsyKeyParamsSpec *param HcfObjDestroy(generatorBySpec); continue; } - free(pubKeyBlob.data); - free(priKeyBlob.data); + HcfFree(pubKeyBlob.data); + HcfFree(priKeyBlob.data); HcfObjDestroy(keyPair); HcfObjDestroy(generatorBySpec); } @@ -3145,8 +2955,10 @@ static void OpensslMockTestFunc(uint32_t mallocCount, HcfAsyKeyParamsSpec *param HWTEST_F(CryptoSm2AsyKeyGeneratorBySpecTest, CryptoSm2AsyKeyGeneratorBySpecTest103, TestSize.Level0) { + ConstructEccKeyPairCommParamsSpec("NID_sm2", &g_eccCommSpec); + ASSERT_NE(g_eccCommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - int32_t res = ConstructSm2256KeyPairParamsSpec(g_sm2AlgName, ¶mSpec); + HcfResult res = ConstructEccKeyPairParamsSpec(g_sm2AlgName.c_str(), g_eccCommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); @@ -3178,25 +2990,26 @@ HWTEST_F(CryptoSm2AsyKeyGeneratorBySpecTest, CryptoSm2AsyKeyGeneratorBySpecTest1 ASSERT_NE(priKeyBlob.data, nullptr); ASSERT_NE(priKeyBlob.len, 0); - free(pubKeyBlob.data); - free(priKeyBlob.data); + HcfFree(pubKeyBlob.data); + HcfFree(priKeyBlob.data); HcfObjDestroy(keyPair); HcfObjDestroy(generatorBySpec); uint32_t mallocCount = GetOpensslCallNum(); OpensslMockTestFunc(mallocCount, paramSpec); + DestroyEccKeyPairSpec(reinterpret_cast(paramSpec)); EndRecordOpensslCallNum(); } static void OpensslMockTestFunc1(uint32_t mallocCount, HcfAsyKeyParamsSpec *paramSpec) { - for (int i = 0; i < mallocCount - 1; i++) { + for (uint32_t i = 0; i < mallocCount - 1; i++) { ResetOpensslCallNum(); SetOpensslCallMockIndex(i); HcfAsyKeyGeneratorBySpec *generatorBySpec = nullptr; - int32_t res = HcfAsyKeyGeneratorBySpecCreate(paramSpec, &generatorBySpec); + HcfResult res = HcfAsyKeyGeneratorBySpecCreate(paramSpec, &generatorBySpec); if (res != HCF_SUCCESS) { continue; } @@ -3214,15 +3027,13 @@ static void OpensslMockTestFunc1(uint32_t mallocCount, HcfAsyKeyParamsSpec *para HWTEST_F(CryptoSm2AsyKeyGeneratorBySpecTest, CryptoSm2AsyKeyGeneratorBySpecTest104, TestSize.Level0) { HcfAsyKeyParamsSpec *paramSpec = nullptr; - int32_t res = ConstructSm2256CommParamsSpec(¶mSpec); - + HcfResult res = ConstructSm2256CommParamsSpec(¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); StartRecordOpensslCallNum(); HcfAsyKeyGeneratorBySpec *generatorBySpec = nullptr; res = HcfAsyKeyGeneratorBySpecCreate(paramSpec, &generatorBySpec); - ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(generatorBySpec, nullptr); @@ -3237,18 +3048,19 @@ HWTEST_F(CryptoSm2AsyKeyGeneratorBySpecTest, CryptoSm2AsyKeyGeneratorBySpecTest1 uint32_t mallocCount = GetOpensslCallNum(); OpensslMockTestFunc1(mallocCount, paramSpec); + FreeEccCommParamsSpec(reinterpret_cast(paramSpec)); EndRecordOpensslCallNum(); } static void OpensslMockTestFunc2(uint32_t mallocCount, HcfAsyKeyParamsSpec *paramSpec) { - for (int i = 0; i < mallocCount - FIVE; i++) { + for (uint32_t i = 0; i < mallocCount - FIVE; i++) { ResetOpensslCallNum(); SetOpensslCallMockIndex(i); HcfAsyKeyGeneratorBySpec *generatorBySpec = nullptr; - int32_t res = HcfAsyKeyGeneratorBySpecCreate(paramSpec, &generatorBySpec); + HcfResult res = HcfAsyKeyGeneratorBySpecCreate(paramSpec, &generatorBySpec); if (res != HCF_SUCCESS) { continue; } @@ -3265,22 +3077,21 @@ static void OpensslMockTestFunc2(uint32_t mallocCount, HcfAsyKeyParamsSpec *para HWTEST_F(CryptoSm2AsyKeyGeneratorBySpecTest, CryptoSm2AsyKeyGeneratorBySpecTest105, TestSize.Level0) { + ConstructEccKeyPairCommParamsSpec("NID_sm2", &g_eccCommSpec); + ASSERT_NE(g_eccCommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - int32_t res = ConstructSm2256PriKeyParamsSpec(g_sm2AlgName, ¶mSpec); - + HcfResult res = ConstructEccPriKeyParamsSpec(g_sm2AlgName.c_str(), g_eccCommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); StartRecordOpensslCallNum(); HcfAsyKeyGeneratorBySpec *generatorBySpec = nullptr; res = HcfAsyKeyGeneratorBySpecCreate(paramSpec, &generatorBySpec); - ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(generatorBySpec, nullptr); HcfPriKey *priKey = nullptr; res = generatorBySpec->generatePriKey(generatorBySpec, &priKey); - ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(priKey, nullptr); @@ -3289,18 +3100,19 @@ HWTEST_F(CryptoSm2AsyKeyGeneratorBySpecTest, CryptoSm2AsyKeyGeneratorBySpecTest1 uint32_t mallocCount = GetOpensslCallNum(); OpensslMockTestFunc2(mallocCount, paramSpec); + DestroyEccPriKeySpec(reinterpret_cast(paramSpec)); EndRecordOpensslCallNum(); } static void OpensslMockTestFunc3(uint32_t mallocCount, HcfAsyKeyParamsSpec *paramSpec) { - for (int i = 0; i < mallocCount - 1; i++) { + for (uint32_t i = 0; i < mallocCount - 1; i++) { ResetOpensslCallNum(); SetOpensslCallMockIndex(i); HcfAsyKeyGeneratorBySpec *generatorBySpec = nullptr; - int32_t res = HcfAsyKeyGeneratorBySpecCreate(paramSpec, &generatorBySpec); + HcfResult res = HcfAsyKeyGeneratorBySpecCreate(paramSpec, &generatorBySpec); if (res != HCF_SUCCESS) { continue; } @@ -3317,8 +3129,10 @@ static void OpensslMockTestFunc3(uint32_t mallocCount, HcfAsyKeyParamsSpec *para HWTEST_F(CryptoSm2AsyKeyGeneratorBySpecTest, CryptoSm2AsyKeyGeneratorBySpecTest106, TestSize.Level0) { + ConstructEccKeyPairCommParamsSpec("NID_sm2", &g_eccCommSpec); + ASSERT_NE(g_eccCommSpec, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - int32_t res = ConstructSm2256PubKeyParamsSpec(g_sm2AlgName, ¶mSpec); + HcfResult res = ConstructEccPubKeyParamsSpec(g_sm2AlgName.c_str(), g_eccCommSpec, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); @@ -3341,6 +3155,7 @@ HWTEST_F(CryptoSm2AsyKeyGeneratorBySpecTest, CryptoSm2AsyKeyGeneratorBySpecTest1 uint32_t mallocCount = GetOpensslCallNum(); OpensslMockTestFunc3(mallocCount, paramSpec); + DestroyEccPubKeySpec(reinterpret_cast(paramSpec)); EndRecordOpensslCallNum(); } diff --git a/test/unittest/src/crypto_sm2_asy_key_generator_test.cpp b/test/unittest/src/crypto_sm2_asy_key_generator_test.cpp index 14be064b8ad22f78e334154054c9a110b807ef1c..ebe18b1b61f4b5dc5a2f1ddaad804690f95e9de8 100644 --- a/test/unittest/src/crypto_sm2_asy_key_generator_test.cpp +++ b/test/unittest/src/crypto_sm2_asy_key_generator_test.cpp @@ -19,6 +19,7 @@ #include "asy_key_generator.h" #include "sm2_asy_key_generator_openssl.h" #include "blob.h" +#include "memory.h" #include "memory_mock.h" #include "openssl_adapter_mock.h" #include "params_parser.h" @@ -487,7 +488,7 @@ HWTEST_F(CryptoSm2AsyKeyGeneratorTest, CryptoSm2AsyKeyGeneratorTest031, TestSize ASSERT_NE(blob.data, nullptr); ASSERT_NE(blob.len, 0); - free(blob.data); + HcfFree(blob.data); HcfObjDestroy(keyPair); HcfObjDestroy(generator); @@ -716,7 +717,7 @@ HWTEST_F(CryptoSm2AsyKeyGeneratorTest, CryptoSm2AsyKeyGeneratorTest048, TestSize ASSERT_NE(blob.data, nullptr); ASSERT_NE(blob.len, 0); - free(blob.data); + HcfFree(blob.data); HcfObjDestroy(keyPair); HcfObjDestroy(generator); @@ -1047,7 +1048,7 @@ HWTEST_F(CryptoSm2AsyKeyGeneratorTest, CryptoSm2AsyKeyGeneratorTest073, TestSize ASSERT_NE(blob.data, nullptr); ASSERT_NE(blob.len, 0); - free(blob.data); + HcfFree(blob.data); HcfObjDestroy(keyPair); HcfObjDestroy(generator); @@ -1276,7 +1277,7 @@ HWTEST_F(CryptoSm2AsyKeyGeneratorTest, CryptoSm2AsyKeyGeneratorTest090, TestSize ASSERT_NE(blob.data, nullptr); ASSERT_NE(blob.len, 0); - free(blob.data); + HcfFree(blob.data); HcfObjDestroy(keyPair); HcfObjDestroy(generator); @@ -1364,10 +1365,10 @@ HWTEST_F(CryptoSm2AsyKeyGeneratorTest, CryptoSm2AsyKeyGeneratorTest094, TestSize ASSERT_NE(outPriKeyBlob.data, nullptr); ASSERT_NE(outPriKeyBlob.len, 0); - free(pubKeyBlob.data); - free(priKeyBlob.data); - free(outPubKeyBlob.data); - free(outPriKeyBlob.data); + HcfFree(pubKeyBlob.data); + HcfFree(priKeyBlob.data); + HcfFree(outPubKeyBlob.data); + HcfFree(outPriKeyBlob.data); HcfObjDestroy(outKeyPair); HcfObjDestroy(keyPair); HcfObjDestroy(generator); @@ -1406,8 +1407,8 @@ HWTEST_F(CryptoSm2AsyKeyGeneratorTest, CryptoSm2AsyKeyGeneratorTest095, TestSize ASSERT_NE(outPubKeyBlob.data, nullptr); ASSERT_NE(outPubKeyBlob.len, 0); - free(pubKeyBlob.data); - free(outPubKeyBlob.data); + HcfFree(pubKeyBlob.data); + HcfFree(outPubKeyBlob.data); HcfObjDestroy(outKeyPair); HcfObjDestroy(keyPair); HcfObjDestroy(generator); @@ -1446,8 +1447,8 @@ HWTEST_F(CryptoSm2AsyKeyGeneratorTest, CryptoSm2AsyKeyGeneratorTest096, TestSize ASSERT_NE(outPriKeyBlob.data, nullptr); ASSERT_NE(outPriKeyBlob.len, 0); - free(priKeyBlob.data); - free(outPriKeyBlob.data); + HcfFree(priKeyBlob.data); + HcfFree(outPriKeyBlob.data); HcfObjDestroy(outKeyPair); HcfObjDestroy(keyPair); HcfObjDestroy(generator); @@ -1562,15 +1563,15 @@ static void MemoryMallocTestFunc(uint32_t mallocCount) }; res = tmpKeyPair->priKey->base.getEncoded(&(tmpKeyPair->priKey->base), &tmpPriKeyBlob); if (res != HCF_SUCCESS) { - free(tmpPubKeyBlob.data); + HcfFree(tmpPubKeyBlob.data); HcfObjDestroy(tmpKeyPair); HcfObjDestroy(tmpGenerator); continue; } HcfKeyPair *tmpOutKeyPair = nullptr; res = tmpGenerator->convertKey(tmpGenerator, nullptr, &tmpPubKeyBlob, &tmpPriKeyBlob, &tmpOutKeyPair); - free(tmpPubKeyBlob.data); - free(tmpPriKeyBlob.data); + HcfFree(tmpPubKeyBlob.data); + HcfFree(tmpPriKeyBlob.data); HcfObjDestroy(tmpKeyPair); HcfObjDestroy(tmpGenerator); if (res == HCF_SUCCESS) { @@ -1608,8 +1609,8 @@ HWTEST_F(CryptoSm2AsyKeyGeneratorTest, CryptoSm2AsyKeyGeneratorTest104, TestSize HcfKeyPair *outKeyPair = nullptr; res = generator->convertKey(generator, nullptr, &pubKeyBlob, &priKeyBlob, &outKeyPair); - free(pubKeyBlob.data); - free(priKeyBlob.data); + HcfFree(pubKeyBlob.data); + HcfFree(priKeyBlob.data); HcfObjDestroy(outKeyPair); HcfObjDestroy(keyPair); HcfObjDestroy(generator); @@ -1652,15 +1653,15 @@ static void OpensslMockTestFunc(uint32_t mallocCount) }; res = tmpKeyPair->priKey->base.getEncoded(&(tmpKeyPair->priKey->base), &tmpPriKeyBlob); if (res != HCF_SUCCESS) { - free(tmpPubKeyBlob.data); + HcfFree(tmpPubKeyBlob.data); HcfObjDestroy(tmpKeyPair); HcfObjDestroy(tmpGenerator); continue; } HcfKeyPair *tmpOutKeyPair = nullptr; res = tmpGenerator->convertKey(tmpGenerator, nullptr, &tmpPubKeyBlob, &tmpPriKeyBlob, &tmpOutKeyPair); - free(tmpPubKeyBlob.data); - free(tmpPriKeyBlob.data); + HcfFree(tmpPubKeyBlob.data); + HcfFree(tmpPriKeyBlob.data); HcfObjDestroy(tmpKeyPair); HcfObjDestroy(tmpGenerator); if (res == HCF_SUCCESS) { @@ -1698,8 +1699,8 @@ HWTEST_F(CryptoSm2AsyKeyGeneratorTest, CryptoSm2AsyKeyGeneratorTest105, TestSize HcfKeyPair *outKeyPair = nullptr; res = generator->convertKey(generator, nullptr, &pubKeyBlob, &priKeyBlob, &outKeyPair); - free(pubKeyBlob.data); - free(priKeyBlob.data); + HcfFree(pubKeyBlob.data); + HcfFree(priKeyBlob.data); HcfObjDestroy(outKeyPair); HcfObjDestroy(keyPair); HcfObjDestroy(generator); diff --git a/test/unittest/src/crypto_sm2_sign_test.cpp b/test/unittest/src/crypto_sm2_sign_test.cpp index 944c68d48a4d2fb2d0628f09c953265e7a2721a8..0573dfc388003dca88b538a9d050b93e277f093f 100644 --- a/test/unittest/src/crypto_sm2_sign_test.cpp +++ b/test/unittest/src/crypto_sm2_sign_test.cpp @@ -442,7 +442,7 @@ HWTEST_F(CryptoSm2SignTest, CryptoSm2SignTest025, TestSize.Level0) ASSERT_NE(out.data, nullptr); ASSERT_NE(out.len, (const unsigned int)0); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); } @@ -465,7 +465,7 @@ HWTEST_F(CryptoSm2SignTest, CryptoSm2SignTest026, TestSize.Level0) ASSERT_NE(out.data, nullptr); ASSERT_NE(out.len, (const unsigned int)0); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); } @@ -639,8 +639,8 @@ HWTEST_F(CryptoSm2SignTest, CryptoSm2SignTest032, TestSize.Level0) flag = verify->verify(verify, nullptr, &out2); ASSERT_EQ(flag, true); - free(out.data); - free(out2.data); + HcfFree(out.data); + HcfFree(out2.data); HcfObjDestroy(sign); HcfObjDestroy(verify); } @@ -673,7 +673,7 @@ HWTEST_F(CryptoSm2SignTest, CryptoSm2SignTest033, TestSize.Level0) HcfBlob out2 = { .data = nullptr, .len = 0 }; res = sign->sign(sign, nullptr, &out2); - free(out2.data); + HcfFree(out2.data); HcfObjDestroy(sign); } @@ -712,7 +712,7 @@ HWTEST_F(CryptoSm2SignTest, CryptoSm2SignTest034, TestSize.Level0) ASSERT_NE(out.data, nullptr); ASSERT_NE(out.len, (const unsigned int)0); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); } @@ -753,7 +753,7 @@ HWTEST_F(CryptoSm2SignTest, CryptoSm2SignTest035, TestSize.Level0) ASSERT_NE(out.data, nullptr); ASSERT_NE(out.len, (const unsigned int)0); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); } @@ -895,7 +895,7 @@ static void MemoryMallocTestFunc(uint32_t mallocCount, HcfBlob *input) HcfObjDestroy(sign); HcfObjDestroy(keyPair); if (res == HCF_SUCCESS) { - free(out.data); + HcfFree(out.data); } } } @@ -938,7 +938,7 @@ HWTEST_F(CryptoSm2SignTest, CryptoSm2SignTest042, TestSize.Level0) ASSERT_NE(out.data, nullptr); ASSERT_NE(out.len, (const unsigned int)0); - free(out.data); + HcfFree(out.data); HcfObjDestroy(keyPair); HcfObjDestroy(sign); @@ -997,7 +997,7 @@ static void OpensslMockTestFunc(uint32_t mallocCount, HcfBlob *input) HcfObjDestroy(sign); HcfObjDestroy(keyPair); if (res == HCF_SUCCESS) { - free(out.data); + HcfFree(out.data); } } } @@ -1044,7 +1044,7 @@ HWTEST_F(CryptoSm2SignTest, CryptoSm2SignTest043, TestSize.Level0) ASSERT_NE(out.data, nullptr); ASSERT_NE(out.len, (const unsigned int)0); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); HcfObjDestroy(keyPair); @@ -1387,7 +1387,7 @@ HWTEST_F(CryptoSm2SignTest, CryptoSm2SignTest060, TestSize.Level0) ASSERT_EQ(flag, true); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); HcfObjDestroy(verify); } diff --git a/test/unittest/src/crypto_sm2_verify_test.cpp b/test/unittest/src/crypto_sm2_verify_test.cpp index 8dc43628cc556690dd6507da1587f34533472f6b..27fa1fe75cdb8ec4c2707166d8c239d2ba2b4576 100644 --- a/test/unittest/src/crypto_sm2_verify_test.cpp +++ b/test/unittest/src/crypto_sm2_verify_test.cpp @@ -460,7 +460,7 @@ HWTEST_F(CryptoSm2VerifyTest, CryptoSm2VerifyTest025, TestSize.Level0) ASSERT_EQ(flag, true); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); HcfObjDestroy(verify); } @@ -498,7 +498,7 @@ HWTEST_F(CryptoSm2VerifyTest, CryptoSm2VerifyTest026, TestSize.Level0) ASSERT_EQ(flag, true); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); HcfObjDestroy(verify); } @@ -544,7 +544,7 @@ HWTEST_F(CryptoSm2VerifyTest, CryptoSm2VerifyTest027, TestSize.Level0) ASSERT_EQ(flag, false); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); HcfObjDestroy(verify); } @@ -590,7 +590,7 @@ HWTEST_F(CryptoSm2VerifyTest, CryptoSm2VerifyTest028, TestSize.Level0) ASSERT_EQ(flag, false); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); HcfObjDestroy(verify); } @@ -632,7 +632,7 @@ HWTEST_F(CryptoSm2VerifyTest, CryptoSm2VerifyTest029, TestSize.Level0) ASSERT_EQ(flag, false); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); HcfObjDestroy(verify); } @@ -678,7 +678,7 @@ HWTEST_F(CryptoSm2VerifyTest, CryptoSm2VerifyTest030, TestSize.Level0) ASSERT_EQ(flag, false); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); HcfObjDestroy(verify); } @@ -724,7 +724,7 @@ HWTEST_F(CryptoSm2VerifyTest, CryptoSm2VerifyTest031, TestSize.Level0) ASSERT_EQ(flag, false); - free(out.data); + HcfFree(out.data); HcfObjDestroy(sign); HcfObjDestroy(verify); } diff --git a/test/unittest/src/crypto_x25519_asy_key_generator_by_spec_test.cpp b/test/unittest/src/crypto_x25519_asy_key_generator_by_spec_test.cpp index f982ac881d8fcb1412189046b9679c1b229db0ec..1bccd9369ef371f2cfca86c70a340e14401a2926 100644 --- a/test/unittest/src/crypto_x25519_asy_key_generator_by_spec_test.cpp +++ b/test/unittest/src/crypto_x25519_asy_key_generator_by_spec_test.cpp @@ -16,6 +16,7 @@ #include #include "securec.h" +#include "alg_25519_common_param_spec.h" #include "asy_key_generator.h" #include "asy_key_generator_spi.h" #include "blob.h" @@ -28,7 +29,6 @@ #include "key_pair.h" #include "object_base.h" #include "alg_25519_asy_key_generator_openssl.h" -#include "detailed_alg_25519_key_params.h" using namespace std; using namespace testing::ext; @@ -47,133 +47,15 @@ static string g_pubkeyformatName = "X.509"; static string g_prikeyformatName = "PKCS#8"; static string g_algorithmName = "Alg25519"; -HcfAlg25519KeyPairParamsSpec g_x25519KeyPairSpec; -HcfAlg25519PriKeyParamsSpec g_x25519PriKeySpec; -HcfAlg25519PubKeyParamsSpec g_x25519PubKeySpec; - void CryptoX25519AsyKeyGeneratorBySpecTest::SetUp() {} void CryptoX25519AsyKeyGeneratorBySpecTest::TearDown() {} void CryptoX25519AsyKeyGeneratorBySpecTest::SetUpTestCase() {} void CryptoX25519AsyKeyGeneratorBySpecTest::TearDownTestCase() {} -static HcfResult ConstructX25519KeyPairParamsSpec(const string &algoName, HcfAsyKeyParamsSpec **spec) -{ - HcfAsyKeyGenerator *generator = nullptr; - HcfResult res = HcfAsyKeyGeneratorCreate(algoName.c_str(), &generator); - if (res != HCF_SUCCESS) { - return res; - } - - HcfKeyPair *keyPair = nullptr; - res = generator->generateKeyPair(generator, nullptr, &keyPair); - if (res != HCF_SUCCESS) { - HcfObjDestroy(generator); - return res; - } - - HcfAlg25519KeyPairParamsSpec *x25519KeyPairSpec = &g_x25519KeyPairSpec; - HcfBigInteger retBigInt = { .data = nullptr, .len = 0 }; - - x25519KeyPairSpec->base.algName = g_x25519AlgoName.data(); - x25519KeyPairSpec->base.specType = HCF_KEY_PAIR_SPEC; - res = keyPair->pubKey->getAsyKeySpecBigInteger(keyPair->pubKey, X25519_PK_BN, &retBigInt); - if (res != HCF_SUCCESS) { - HcfObjDestroy(generator); - HcfObjDestroy(keyPair); - return res; - } - x25519KeyPairSpec->pk.data = retBigInt.data; - x25519KeyPairSpec->pk.len = retBigInt.len; - - res = keyPair->priKey->getAsyKeySpecBigInteger(keyPair->priKey, X25519_SK_BN, &retBigInt); - if (res != HCF_SUCCESS) { - HcfObjDestroy(generator); - HcfObjDestroy(keyPair); - return res; - } - x25519KeyPairSpec->sk.data = retBigInt.data; - x25519KeyPairSpec->sk.len = retBigInt.len; - - *spec = (HcfAsyKeyParamsSpec *)x25519KeyPairSpec; - HcfObjDestroy(generator); - HcfObjDestroy(keyPair); - return HCF_SUCCESS; -} - -static HcfResult ConstructX25519PubKeyParamsSpec(const string &algoName, HcfAsyKeyParamsSpec **spec) -{ - HcfAsyKeyGenerator *generator = nullptr; - HcfResult res = HcfAsyKeyGeneratorCreate(algoName.c_str(), &generator); - if (res != HCF_SUCCESS) { - return HCF_INVALID_PARAMS; - } - - HcfKeyPair *keyPair = nullptr; - res = generator->generateKeyPair(generator, nullptr, &keyPair); - if (res != HCF_SUCCESS) { - HcfObjDestroy(generator); - return HCF_INVALID_PARAMS; - } - - HcfAlg25519PubKeyParamsSpec *x25519PubKeySpec = &g_x25519PubKeySpec; - HcfBigInteger retBigInt = { .data = nullptr, .len = 0 }; - x25519PubKeySpec->base.algName = g_x25519AlgoName.data(); - x25519PubKeySpec->base.specType = HCF_PUBLIC_KEY_SPEC; - res = keyPair->pubKey->getAsyKeySpecBigInteger(keyPair->pubKey, X25519_PK_BN, &retBigInt); - if (res != HCF_SUCCESS) { - HcfObjDestroy(generator); - HcfObjDestroy(keyPair); - return res; - } - x25519PubKeySpec->pk.data = retBigInt.data; - x25519PubKeySpec->pk.len = retBigInt.len; - - *spec = (HcfAsyKeyParamsSpec *)x25519PubKeySpec; - HcfObjDestroy(generator); - HcfObjDestroy(keyPair); - return HCF_SUCCESS; -} - -static HcfResult ConstructX25519PriKeyParamsSpec(const string &algoName, HcfAsyKeyParamsSpec **spec) -{ - HcfAsyKeyGenerator *generator = nullptr; - HcfResult res = HcfAsyKeyGeneratorCreate(algoName.c_str(), &generator); - if (res != HCF_SUCCESS) { - return res; - } - - HcfKeyPair *keyPair = nullptr; - res = generator->generateKeyPair(generator, nullptr, &keyPair); - if (res != HCF_SUCCESS) { - HcfObjDestroy(generator); - return res; - } - - HcfAlg25519PriKeyParamsSpec *x25519PriKeySpec = &g_x25519PriKeySpec; - HcfBigInteger retBigInt = { .data = nullptr, .len = 0 }; - - x25519PriKeySpec->base.algName = g_x25519AlgoName.data(); - x25519PriKeySpec->base.specType = HCF_PRIVATE_KEY_SPEC; - res = keyPair->priKey->getAsyKeySpecBigInteger(keyPair->priKey, X25519_SK_BN, &retBigInt); - if (res != HCF_SUCCESS) { - HcfObjDestroy(generator); - HcfObjDestroy(keyPair); - return res; - } - x25519PriKeySpec->sk.data = retBigInt.data; - x25519PriKeySpec->sk.len = retBigInt.len; - - *spec = (HcfAsyKeyParamsSpec *)x25519PriKeySpec; - HcfObjDestroy(generator); - HcfObjDestroy(keyPair); - - return HCF_SUCCESS; -} - HWTEST_F(CryptoX25519AsyKeyGeneratorBySpecTest, CryptoX25519AsyKeyGeneratorBySpecTest001_1, TestSize.Level0) { HcfAsyKeyParamsSpec *paramSpec = nullptr; - HcfResult res = ConstructX25519KeyPairParamsSpec(g_x25519AlgoName, ¶mSpec); + HcfResult res = ConstructAlg25519KeyPairParamsSpec(g_x25519AlgoName.c_str(), false, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); @@ -181,12 +63,13 @@ HWTEST_F(CryptoX25519AsyKeyGeneratorBySpecTest, CryptoX25519AsyKeyGeneratorBySpe res = HcfAsyKeyGeneratorBySpecCreate(paramSpec, &returnObj); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(returnObj, nullptr); + DestroyAlg25519KeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoX25519AsyKeyGeneratorBySpecTest, CryptoX25519AsyKeyGeneratorBySpecTest001_2, TestSize.Level0) { HcfAsyKeyParamsSpec *paramSpec = nullptr; - HcfResult res = ConstructX25519PubKeyParamsSpec(g_x25519AlgoName, ¶mSpec); + HcfResult res = ConstructAlg25519PubKeyParamsSpec(g_x25519AlgoName.c_str(), false, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); @@ -194,12 +77,13 @@ HWTEST_F(CryptoX25519AsyKeyGeneratorBySpecTest, CryptoX25519AsyKeyGeneratorBySpe res = HcfAsyKeyGeneratorBySpecCreate(paramSpec, &returnObj); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(returnObj, nullptr); + DestroyAlg25519PubKeySpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoX25519AsyKeyGeneratorBySpecTest, CryptoX25519AsyKeyGeneratorBySpecTest001_3, TestSize.Level0) { HcfAsyKeyParamsSpec *paramSpec = nullptr; - HcfResult res = ConstructX25519PriKeyParamsSpec(g_x25519AlgoName, ¶mSpec); + HcfResult res = ConstructAlg25519PriKeyParamsSpec(g_x25519AlgoName.c_str(), false, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); @@ -207,12 +91,13 @@ HWTEST_F(CryptoX25519AsyKeyGeneratorBySpecTest, CryptoX25519AsyKeyGeneratorBySpe res = HcfAsyKeyGeneratorBySpecCreate(paramSpec, &returnObj); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(returnObj, nullptr); + DestroyAlg25519PriKeySpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoX25519AsyKeyGeneratorBySpecTest, CryptoX25519AsyKeyGeneratorBySpecTest002, TestSize.Level0) { HcfAsyKeyParamsSpec *paramSpec = nullptr; - HcfResult res = ConstructX25519KeyPairParamsSpec(g_x25519AlgoName, ¶mSpec); + HcfResult res = ConstructAlg25519KeyPairParamsSpec(g_x25519AlgoName.c_str(), false, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); @@ -224,12 +109,13 @@ HWTEST_F(CryptoX25519AsyKeyGeneratorBySpecTest, CryptoX25519AsyKeyGeneratorBySpe const char *className = returnObj->base.getClass(); ASSERT_NE(className, NULL); ASSERT_NE(returnObj, nullptr); + DestroyAlg25519KeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoX25519AsyKeyGeneratorBySpecTest, CryptoX25519AsyKeyGeneratorBySpecTest003, TestSize.Level0) { HcfAsyKeyParamsSpec *paramSpec = nullptr; - HcfResult res = ConstructX25519KeyPairParamsSpec(g_x25519AlgoName, ¶mSpec); + HcfResult res = ConstructAlg25519KeyPairParamsSpec(g_x25519AlgoName.c_str(), false, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); @@ -239,12 +125,13 @@ HWTEST_F(CryptoX25519AsyKeyGeneratorBySpecTest, CryptoX25519AsyKeyGeneratorBySpe ASSERT_NE(returnObj, nullptr); returnObj->base.destroy((HcfObjectBase *)returnObj); + DestroyAlg25519KeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoX25519AsyKeyGeneratorBySpecTest, CryptoX25519AsyKeyGeneratorBySpecTest004, TestSize.Level0) { HcfAsyKeyParamsSpec *paramSpec = nullptr; - HcfResult res = ConstructX25519KeyPairParamsSpec(g_x25519AlgoName, ¶mSpec); + HcfResult res = ConstructAlg25519KeyPairParamsSpec(g_x25519AlgoName.c_str(), false, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); @@ -254,17 +141,17 @@ HWTEST_F(CryptoX25519AsyKeyGeneratorBySpecTest, CryptoX25519AsyKeyGeneratorBySpe ASSERT_NE(returnObj, nullptr); const char *algoName = returnObj->getAlgName(returnObj); - ASSERT_EQ(res, HCF_SUCCESS); ASSERT_EQ(algoName, g_x25519AlgoName); HcfObjDestroy(returnObj); + DestroyAlg25519KeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoX25519AsyKeyGeneratorBySpecTest, CryptoX25519AsyKeyGeneratorBySpecTest005, TestSize.Level0) { HcfAsyKeyParamsSpec *paramSpec = nullptr; - HcfResult res = ConstructX25519KeyPairParamsSpec(g_x25519AlgoName, ¶mSpec); + HcfResult res = ConstructAlg25519KeyPairParamsSpec(g_x25519AlgoName.c_str(), false, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); @@ -281,12 +168,13 @@ HWTEST_F(CryptoX25519AsyKeyGeneratorBySpecTest, CryptoX25519AsyKeyGeneratorBySpe HcfObjDestroy(keyPair); HcfObjDestroy(returnObj); + DestroyAlg25519KeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoX25519AsyKeyGeneratorBySpecTest, CryptoX25519AsyKeyGeneratorBySpecTest006, TestSize.Level0) { HcfAsyKeyParamsSpec *paramSpec = nullptr; - HcfResult res = ConstructX25519KeyPairParamsSpec(g_x25519AlgoName, ¶mSpec); + HcfResult res = ConstructAlg25519KeyPairParamsSpec(g_x25519AlgoName.c_str(), false, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); @@ -306,12 +194,13 @@ HWTEST_F(CryptoX25519AsyKeyGeneratorBySpecTest, CryptoX25519AsyKeyGeneratorBySpe HcfObjDestroy(keyPair); HcfObjDestroy(returnObj); + DestroyAlg25519KeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoX25519AsyKeyGeneratorBySpecTest, CryptoX25519AsyKeyGeneratorBySpecTest007, TestSize.Level0) { HcfAsyKeyParamsSpec *paramSpec = nullptr; - HcfResult res = ConstructX25519KeyPairParamsSpec(g_x25519AlgoName, ¶mSpec); + HcfResult res = ConstructAlg25519KeyPairParamsSpec(g_x25519AlgoName.c_str(), false, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); @@ -322,19 +211,18 @@ HWTEST_F(CryptoX25519AsyKeyGeneratorBySpecTest, CryptoX25519AsyKeyGeneratorBySpe HcfKeyPair *keyPair = nullptr; res = returnObj->generateKeyPair(returnObj, &keyPair); - ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(keyPair, nullptr); keyPair->base.destroy(&(keyPair->base)); - ASSERT_NE(returnObj, nullptr); + DestroyAlg25519KeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoX25519AsyKeyGeneratorBySpecTest, CryptoX25519AsyKeyGeneratorBySpecTest008, TestSize.Level0) { HcfAsyKeyParamsSpec *paramSpec = nullptr; - HcfResult res = ConstructX25519KeyPairParamsSpec(g_x25519AlgoName, ¶mSpec); + HcfResult res = ConstructAlg25519KeyPairParamsSpec(g_x25519AlgoName.c_str(), false, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); @@ -353,12 +241,13 @@ HWTEST_F(CryptoX25519AsyKeyGeneratorBySpecTest, CryptoX25519AsyKeyGeneratorBySpe HcfObjDestroy(keyPair); HcfObjDestroy(returnObj); + DestroyAlg25519KeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoX25519AsyKeyGeneratorBySpecTest, CryptoX25519AsyKeyGeneratorBySpecTest009, TestSize.Level0) { HcfAsyKeyParamsSpec *paramSpec = nullptr; - HcfResult res = ConstructX25519KeyPairParamsSpec(g_x25519AlgoName, ¶mSpec); + HcfResult res = ConstructAlg25519KeyPairParamsSpec(g_x25519AlgoName.c_str(), false, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); @@ -376,12 +265,13 @@ HWTEST_F(CryptoX25519AsyKeyGeneratorBySpecTest, CryptoX25519AsyKeyGeneratorBySpe keyPair->pubKey = nullptr; HcfObjDestroy(keyPair); HcfObjDestroy(returnObj); + DestroyAlg25519KeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoX25519AsyKeyGeneratorBySpecTest, CryptoX25519AsyKeyGeneratorBySpecTest010, TestSize.Level0) { HcfAsyKeyParamsSpec *paramSpec = nullptr; - HcfResult res = ConstructX25519KeyPairParamsSpec(g_x25519AlgoName, ¶mSpec); + HcfResult res = ConstructAlg25519KeyPairParamsSpec(g_x25519AlgoName.c_str(), false, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); @@ -409,12 +299,13 @@ HWTEST_F(CryptoX25519AsyKeyGeneratorBySpecTest, CryptoX25519AsyKeyGeneratorBySpe HcfObjDestroy(keyPair); HcfObjDestroy(returnObj); + DestroyAlg25519KeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoX25519AsyKeyGeneratorBySpecTest, CryptoX25519AsyKeyGeneratorBySpecTest011, TestSize.Level0) { HcfAsyKeyParamsSpec *paramSpec = nullptr; - HcfResult res = ConstructX25519KeyPairParamsSpec(g_x25519AlgoName, ¶mSpec); + HcfResult res = ConstructAlg25519KeyPairParamsSpec(g_x25519AlgoName.c_str(), false, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); @@ -433,12 +324,13 @@ HWTEST_F(CryptoX25519AsyKeyGeneratorBySpecTest, CryptoX25519AsyKeyGeneratorBySpe HcfObjDestroy(keyPair); HcfObjDestroy(returnObj); + DestroyAlg25519KeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoX25519AsyKeyGeneratorBySpecTest, CryptoX25519AsyKeyGeneratorBySpecTest012, TestSize.Level0) { HcfAsyKeyParamsSpec *paramSpec = nullptr; - HcfResult res = ConstructX25519KeyPairParamsSpec(g_x25519AlgoName, ¶mSpec); + HcfResult res = ConstructAlg25519KeyPairParamsSpec(g_x25519AlgoName.c_str(), false, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); @@ -457,12 +349,13 @@ HWTEST_F(CryptoX25519AsyKeyGeneratorBySpecTest, CryptoX25519AsyKeyGeneratorBySpe HcfObjDestroy(keyPair); HcfObjDestroy(returnObj); + DestroyAlg25519KeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoX25519AsyKeyGeneratorBySpecTest, CryptoX25519AsyKeyGeneratorBySpecTest013, TestSize.Level0) { HcfAsyKeyParamsSpec *paramSpec = nullptr; - HcfResult res = ConstructX25519KeyPairParamsSpec(g_x25519AlgoName, ¶mSpec); + HcfResult res = ConstructAlg25519KeyPairParamsSpec(g_x25519AlgoName.c_str(), false, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); @@ -490,12 +383,13 @@ HWTEST_F(CryptoX25519AsyKeyGeneratorBySpecTest, CryptoX25519AsyKeyGeneratorBySpe HcfObjDestroy(keyPair); HcfObjDestroy(returnObj); + DestroyAlg25519KeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoX25519AsyKeyGeneratorBySpecTest, CryptoX25519AsyKeyGeneratorBySpecTest014, TestSize.Level0) { HcfAsyKeyParamsSpec *paramSpec = nullptr; - HcfResult res = ConstructX25519KeyPairParamsSpec(g_x25519AlgoName, ¶mSpec); + HcfResult res = ConstructAlg25519KeyPairParamsSpec(g_x25519AlgoName.c_str(), false, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); @@ -518,17 +412,18 @@ HWTEST_F(CryptoX25519AsyKeyGeneratorBySpecTest, CryptoX25519AsyKeyGeneratorBySpe HcfFree(blob.data); HcfObjDestroy(keyPair); HcfObjDestroy(returnObj); + DestroyAlg25519KeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoX25519AsyKeyGeneratorBySpecTest, CryptoX25519AsyKeyGeneratorBySpecTest015, TestSize.Level0) { HcfAsyKeyParamsSpec *pubparamSpec = nullptr; - HcfResult res = ConstructX25519PubKeyParamsSpec(g_x25519AlgoName, &pubparamSpec); + HcfResult res = ConstructAlg25519PubKeyParamsSpec(g_x25519AlgoName.c_str(), false, &pubparamSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(pubparamSpec, nullptr); HcfAsyKeyParamsSpec *priparamSpec = nullptr; - res = ConstructX25519PriKeyParamsSpec(g_x25519AlgoName, &priparamSpec); + res = ConstructAlg25519PriKeyParamsSpec(g_x25519AlgoName.c_str(), false, &priparamSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(priparamSpec, nullptr); @@ -569,6 +464,8 @@ HWTEST_F(CryptoX25519AsyKeyGeneratorBySpecTest, CryptoX25519AsyKeyGeneratorBySpe HcfObjDestroy(priKey); HcfObjDestroy(returnpubObj); HcfObjDestroy(returnpriObj); + DestroyAlg25519PubKeySpec(reinterpret_cast(pubparamSpec)); + DestroyAlg25519PriKeySpec(reinterpret_cast(priparamSpec)); } HWTEST_F(CryptoX25519AsyKeyGeneratorBySpecTest, CryptoX25519AsyKeyGeneratorBySpecTest016, TestSize.Level0) @@ -602,7 +499,7 @@ HWTEST_F(CryptoX25519AsyKeyGeneratorBySpecTest, CryptoX25519AsyKeyGeneratorBySpe ASSERT_NE(returnSpi, nullptr); HcfAsyKeyParamsSpec *paramsSpec = nullptr; - res = ConstructX25519KeyPairParamsSpec("X25519", ¶msSpec); + res = ConstructAlg25519KeyPairParamsSpec(g_x25519AlgoName.c_str(), false, ¶msSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(returnSpi, nullptr); @@ -613,6 +510,7 @@ HWTEST_F(CryptoX25519AsyKeyGeneratorBySpecTest, CryptoX25519AsyKeyGeneratorBySpe HcfObjDestroy(returnSpi); HcfObjDestroy(keyPair); + DestroyAlg25519KeyPairSpec(reinterpret_cast(paramsSpec)); } HWTEST_F(CryptoX25519AsyKeyGeneratorBySpecTest, CryptoX25519AsyKeyGeneratorBySpecTest018, TestSize.Level0) @@ -630,7 +528,7 @@ HWTEST_F(CryptoX25519AsyKeyGeneratorBySpecTest, CryptoX25519AsyKeyGeneratorBySpe ASSERT_NE(returnSpi, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - res = ConstructX25519PubKeyParamsSpec("X25519", ¶mSpec); + res = ConstructAlg25519PubKeyParamsSpec("X25519", false, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(returnSpi, nullptr); @@ -641,6 +539,7 @@ HWTEST_F(CryptoX25519AsyKeyGeneratorBySpecTest, CryptoX25519AsyKeyGeneratorBySpe HcfObjDestroy(returnSpi); HcfObjDestroy(pubKey); + DestroyAlg25519PubKeySpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoX25519AsyKeyGeneratorBySpecTest, CryptoX25519AsyKeyGeneratorBySpecTest019, TestSize.Level0) @@ -658,7 +557,7 @@ HWTEST_F(CryptoX25519AsyKeyGeneratorBySpecTest, CryptoX25519AsyKeyGeneratorBySpe ASSERT_NE(returnSpi, nullptr); HcfAsyKeyParamsSpec *paramSpec = nullptr; - res = ConstructX25519PriKeyParamsSpec("X25519", ¶mSpec); + res = ConstructAlg25519PriKeyParamsSpec("X25519", false, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(returnSpi, nullptr); @@ -669,6 +568,7 @@ HWTEST_F(CryptoX25519AsyKeyGeneratorBySpecTest, CryptoX25519AsyKeyGeneratorBySpe HcfObjDestroy(returnSpi); HcfObjDestroy(priKey); + DestroyAlg25519PriKeySpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoX25519AsyKeyGeneratorBySpecTest, CryptoX25519AsyKeyGeneratorBySpecTest020, TestSize.Level0) @@ -690,7 +590,7 @@ HWTEST_F(CryptoX25519AsyKeyGeneratorBySpecTest, CryptoX25519AsyKeyGeneratorBySpe ASSERT_NE(blob1.len, 0); HcfAsyKeyParamsSpec *paramSpec = nullptr; - res = ConstructX25519PubKeyParamsSpec("X25519", ¶mSpec); + res = ConstructAlg25519PubKeyParamsSpec("X25519", false, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); @@ -718,6 +618,7 @@ HWTEST_F(CryptoX25519AsyKeyGeneratorBySpecTest, CryptoX25519AsyKeyGeneratorBySpe HcfObjDestroy(returnObj); HcfObjDestroy(pubKey); HcfObjDestroy(keyPair); + DestroyAlg25519PubKeySpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoX25519AsyKeyGeneratorBySpecTest, CryptoX25519AsyKeyGeneratorBySpecTest021, TestSize.Level0) @@ -739,7 +640,7 @@ HWTEST_F(CryptoX25519AsyKeyGeneratorBySpecTest, CryptoX25519AsyKeyGeneratorBySpe ASSERT_NE(blob1.len, 0); HcfAsyKeyParamsSpec *paramSpec = nullptr; - res = ConstructX25519PriKeyParamsSpec("X25519", ¶mSpec); + res = ConstructAlg25519PriKeyParamsSpec("X25519", false, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); @@ -767,12 +668,13 @@ HWTEST_F(CryptoX25519AsyKeyGeneratorBySpecTest, CryptoX25519AsyKeyGeneratorBySpe HcfObjDestroy(returnObj); HcfObjDestroy(priKey); HcfObjDestroy(keyPair); + DestroyAlg25519PriKeySpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoX25519AsyKeyGeneratorBySpecTest, CryptoX25519AsyKeyGeneratorBySpecTest022, TestSize.Level0) { HcfAsyKeyParamsSpec *paramSpec = nullptr; - HcfResult res = ConstructX25519PriKeyParamsSpec("X25519", ¶mSpec); + HcfResult res = ConstructAlg25519PriKeyParamsSpec("X25519", false, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); @@ -803,12 +705,13 @@ HWTEST_F(CryptoX25519AsyKeyGeneratorBySpecTest, CryptoX25519AsyKeyGeneratorBySpe HcfObjDestroy(returnObj); HcfObjDestroy(priKey); HcfObjDestroy(keyPair); + DestroyAlg25519PriKeySpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoX25519AsyKeyGeneratorBySpecTest, CryptoX25519AsyKeyGeneratorBySpecTest023, TestSize.Level0) { HcfAsyKeyParamsSpec *paramSpec = nullptr; - HcfResult res = ConstructX25519PubKeyParamsSpec("X25519", ¶mSpec); + HcfResult res = ConstructAlg25519PubKeyParamsSpec("X25519", false, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); @@ -839,5 +742,6 @@ HWTEST_F(CryptoX25519AsyKeyGeneratorBySpecTest, CryptoX25519AsyKeyGeneratorBySpe HcfObjDestroy(returnObj); HcfObjDestroy(pubKey); HcfObjDestroy(keyPair); + DestroyAlg25519PubKeySpec(reinterpret_cast(paramSpec)); } } \ No newline at end of file diff --git a/test/unittest/src/crypto_x25519_key_agreement_test.cpp b/test/unittest/src/crypto_x25519_key_agreement_test.cpp index 2697f9b9609edc2af37aff7a4c4173b136e87df5..414b7ace77f7b1683f21270f75c84522fc6445e8 100644 --- a/test/unittest/src/crypto_x25519_key_agreement_test.cpp +++ b/test/unittest/src/crypto_x25519_key_agreement_test.cpp @@ -18,7 +18,7 @@ #include "asy_key_generator.h" #include "alg_25519_asy_key_generator_openssl.h" -#include "detailed_alg_25519_key_params.h" +#include "alg_25519_common_param_spec.h" #include "key_agreement.h" #include "params_parser.h" #include "x25519_openssl.h" @@ -47,8 +47,6 @@ HcfKeyPair *CryptoX25519KeyAgreementTest::x25519KeyPair_ = nullptr; static string g_ed25519AlgoName = "Ed25519"; static string g_x25519AlgoName = "X25519"; -HcfAlg25519KeyPairParamsSpec g_x25519KeyPairSpec; - void CryptoX25519KeyAgreementTest::SetUp() {} void CryptoX25519KeyAgreementTest::TearDown() {} @@ -62,45 +60,6 @@ static HcfObjectBase g_obj = { .destroy = nullptr }; -static HcfResult ConstructX25519KeyPairParamsSpec(const string &algoName, HcfAsyKeyParamsSpec **spec) -{ - HcfAsyKeyGenerator *generator = nullptr; - HcfResult res = HcfAsyKeyGeneratorCreate(algoName.c_str(), &generator); - if (res != HCF_SUCCESS) { - return res; - } - HcfKeyPair *keyPair = nullptr; - res = generator->generateKeyPair(generator, nullptr, &keyPair); - if (res != HCF_SUCCESS) { - return res; - } - HcfAlg25519KeyPairParamsSpec *x25519KeyPairSpec = &g_x25519KeyPairSpec; - HcfBigInteger retBigInt = { .data = nullptr, .len = 0 }; - x25519KeyPairSpec->base.algName = const_cast(g_x25519AlgoName.c_str()); - x25519KeyPairSpec->base.specType = HCF_KEY_PAIR_SPEC; - res = keyPair->pubKey->getAsyKeySpecBigInteger(keyPair->pubKey, X25519_PK_BN, &retBigInt); - if (res != HCF_SUCCESS) { - HcfObjDestroy(generator); - HcfObjDestroy(keyPair); - return res; - } - x25519KeyPairSpec->pk.data = retBigInt.data; - x25519KeyPairSpec->pk.len = retBigInt.len; - res = keyPair->priKey->getAsyKeySpecBigInteger(keyPair->priKey, X25519_SK_BN, &retBigInt); - if (res != HCF_SUCCESS) { - HcfObjDestroy(generator); - HcfObjDestroy(keyPair); - return res; - } - x25519KeyPairSpec->sk.data = retBigInt.data; - x25519KeyPairSpec->sk.len = retBigInt.len; - - *spec = (HcfAsyKeyParamsSpec *)x25519KeyPairSpec; - HcfObjDestroy(generator); - HcfObjDestroy(keyPair); - return HCF_SUCCESS; -} - void CryptoX25519KeyAgreementTest::SetUpTestCase() { HcfAsyKeyGenerator *generator = nullptr; @@ -177,7 +136,7 @@ HWTEST_F(CryptoX25519KeyAgreementTest, CryptoX25519KeyAgreementTest004, TestSize ASSERT_EQ(algName, g_x25519AlgoName); HcfAsyKeyParamsSpec *paramSpec = nullptr; - res = ConstructX25519KeyPairParamsSpec(g_x25519AlgoName, ¶mSpec); + res = ConstructAlg25519KeyPairParamsSpec(g_x25519AlgoName.c_str(), false, ¶mSpec); ASSERT_EQ(res, HCF_SUCCESS); ASSERT_NE(paramSpec, nullptr); @@ -202,6 +161,7 @@ HWTEST_F(CryptoX25519KeyAgreementTest, CryptoX25519KeyAgreementTest004, TestSize HcfObjDestroy(keyAgreement); HcfObjDestroy(generator); HcfObjDestroy(keyPair); + DestroyAlg25519KeyPairSpec(reinterpret_cast(paramSpec)); } HWTEST_F(CryptoX25519KeyAgreementTest, CryptoX25519KeyAgreementTest005, TestSize.Level0) diff --git a/test/unittest/src/ecc_common_param_spec.c b/test/unittest/src/ecc_common_param_spec.c new file mode 100644 index 0000000000000000000000000000000000000000..292aa587d04dd43e119dcb80ce42c478282b9b9f --- /dev/null +++ b/test/unittest/src/ecc_common_param_spec.c @@ -0,0 +1,241 @@ +/* + * Copyright (C) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecc_common_param_spec.h" +#include "securec.h" +#include "asy_key_generator.h" +#include "ecc_key_util.h" +#include "memory.h" +#include "memory_mock.h" + +HcfResult ConstructEccKeyPairCommParamsSpec(const char *algoName, HcfEccCommParamsSpec **spec) +{ + HcfEccCommParamsSpec *eccCommSpec = NULL; + HcfEccKeyUtilCreate(algoName, &eccCommSpec); + if (eccCommSpec == NULL) { + return HCF_INVALID_PARAMS; + } + *spec = eccCommSpec; + return HCF_SUCCESS; +} + +static HcfResult ConstructEccKeyPairBigInt(HcfKeyPair *keyPair, HcfEccKeyPairParamsSpec *eccKeyPairSpec) +{ + HcfBigInteger retBigInt = { .data = NULL, .len = 0 }; + HcfResult res = keyPair->pubKey->getAsyKeySpecBigInteger(keyPair->pubKey, ECC_PK_X_BN, &retBigInt); + if (res != HCF_SUCCESS) { + return res; + } + eccKeyPairSpec->pk.x.data = retBigInt.data; + eccKeyPairSpec->pk.x.len = retBigInt.len; + + res = keyPair->pubKey->getAsyKeySpecBigInteger(keyPair->pubKey, ECC_PK_Y_BN, &retBigInt); + if (res != HCF_SUCCESS) { + HcfFree(eccKeyPairSpec->pk.x.data); + eccKeyPairSpec->pk.x.data = NULL; + eccKeyPairSpec->pk.x.len = 0; + return res; + } + eccKeyPairSpec->pk.y.data = retBigInt.data; + eccKeyPairSpec->pk.y.len = retBigInt.len; + + res = keyPair->priKey->getAsyKeySpecBigInteger(keyPair->priKey, ECC_SK_BN, &retBigInt); + if (res != HCF_SUCCESS) { + HcfFree(eccKeyPairSpec->pk.x.data); + eccKeyPairSpec->pk.x.data = NULL; + eccKeyPairSpec->pk.x.len = 0; + HcfFree(eccKeyPairSpec->pk.y.data); + eccKeyPairSpec->pk.y.data = NULL; + eccKeyPairSpec->pk.y.len = 0; + return res; + } + eccKeyPairSpec->sk.data = retBigInt.data; + eccKeyPairSpec->sk.len = retBigInt.len; + return HCF_SUCCESS; +} + +HcfResult ConstructEccKeyPairParamsSpec(const char *algoName, HcfEccCommParamsSpec *eccCommSpec, + HcfAsyKeyParamsSpec **spec) +{ + if (eccCommSpec == NULL) { + return HCF_INVALID_PARAMS; + } + HcfAsyKeyGenerator *generator = NULL; + HcfResult res = HCF_ERR_CRYPTO_OPERATION; + if (HcfAsyKeyGeneratorCreate(algoName, &generator) != HCF_SUCCESS) { + return res; + } + HcfKeyPair *keyPair = NULL; + if (generator->generateKeyPair(generator, NULL, &keyPair) != HCF_SUCCESS) { + HcfObjDestroy(generator); + return res; + } + + HcfEccKeyPairParamsSpec *eccKeyPairSpec = (HcfEccKeyPairParamsSpec*)HcfMalloc(sizeof(HcfEccKeyPairParamsSpec), 0); + if (eccKeyPairSpec != NULL) { + eccKeyPairSpec->base.base.algName = eccCommSpec->base.algName; + eccKeyPairSpec->base.base.specType = HCF_KEY_PAIR_SPEC; + eccKeyPairSpec->base.field = eccCommSpec->field; + eccKeyPairSpec->base.field->fieldType = eccCommSpec->field->fieldType; + ((HcfECFieldFp *)(eccKeyPairSpec->base.field))->p.data = ((HcfECFieldFp *)(eccCommSpec->field))->p.data; + ((HcfECFieldFp *)(eccKeyPairSpec->base.field))->p.len = ((HcfECFieldFp *)(eccCommSpec->field))->p.len; + eccKeyPairSpec->base.a.data = eccCommSpec->a.data; + eccKeyPairSpec->base.a.len = eccCommSpec->a.len; + eccKeyPairSpec->base.b.data = eccCommSpec->b.data; + eccKeyPairSpec->base.b.len = eccCommSpec->b.len; + eccKeyPairSpec->base.g.x.data = eccCommSpec->g.x.data; + eccKeyPairSpec->base.g.x.len = eccCommSpec->g.x.len; + eccKeyPairSpec->base.g.y.data = eccCommSpec->g.y.data; + eccKeyPairSpec->base.g.y.len = eccCommSpec->g.y.len; + eccKeyPairSpec->base.n.data = eccCommSpec->n.data; + eccKeyPairSpec->base.n.len = eccCommSpec->n.len; + eccKeyPairSpec->base.h = eccCommSpec->h; + if (ConstructEccKeyPairBigInt(keyPair, eccKeyPairSpec) != HCF_SUCCESS) { + HcfFree(eccKeyPairSpec); + } else { + *spec = (HcfAsyKeyParamsSpec *)eccKeyPairSpec; + res = HCF_SUCCESS; + } + } + HcfObjDestroy(generator); + HcfObjDestroy(keyPair); + return res; +} + +static HcfResult ConstructEccPubKeyBigInt(HcfKeyPair *keyPair, HcfEccPubKeyParamsSpec *eccPubKeySpec) +{ + HcfBigInteger retBigInt = { .data = NULL, .len = 0 }; + HcfResult res = keyPair->pubKey->getAsyKeySpecBigInteger(keyPair->pubKey, ECC_PK_X_BN, &retBigInt); + if (res != HCF_SUCCESS) { + return res; + } + eccPubKeySpec->pk.x.data = retBigInt.data; + eccPubKeySpec->pk.x.len = retBigInt.len; + + res = keyPair->pubKey->getAsyKeySpecBigInteger(keyPair->pubKey, ECC_PK_Y_BN, &retBigInt); + if (res != HCF_SUCCESS) { + HcfFree(eccPubKeySpec->pk.x.data); + eccPubKeySpec->pk.x.data = NULL; + eccPubKeySpec->pk.x.len = 0; + return res; + } + eccPubKeySpec->pk.y.data = retBigInt.data; + eccPubKeySpec->pk.y.len = retBigInt.len; + return HCF_SUCCESS; +} + +HcfResult ConstructEccPubKeyParamsSpec(const char *algoName, HcfEccCommParamsSpec *eccCommSpec, + HcfAsyKeyParamsSpec **spec) +{ + if (eccCommSpec == NULL) { + return HCF_INVALID_PARAMS; + } + + HcfResult res = HCF_ERR_CRYPTO_OPERATION; + HcfAsyKeyGenerator *generator = NULL; + if (HcfAsyKeyGeneratorCreate(algoName, &generator) != HCF_SUCCESS) { + return res; + } + + HcfKeyPair *keyPair = NULL; + if (generator->generateKeyPair(generator, NULL, &keyPair) != HCF_SUCCESS) { + HcfObjDestroy(generator); + return res; + } + + HcfEccPubKeyParamsSpec *eccPubKeySpec = (HcfEccPubKeyParamsSpec*)HcfMalloc(sizeof(HcfEccPubKeyParamsSpec), 0); + if (eccPubKeySpec != NULL) { + eccPubKeySpec->base.base.algName = eccCommSpec->base.algName; + eccPubKeySpec->base.base.specType = HCF_PUBLIC_KEY_SPEC; + eccPubKeySpec->base.field = eccCommSpec->field; + eccPubKeySpec->base.field->fieldType = eccCommSpec->field->fieldType; + ((HcfECFieldFp *)(eccPubKeySpec->base.field))->p.data = ((HcfECFieldFp *)(eccCommSpec->field))->p.data; + ((HcfECFieldFp *)(eccPubKeySpec->base.field))->p.len = ((HcfECFieldFp *)(eccCommSpec->field))->p.len; + eccPubKeySpec->base.a.data = eccCommSpec->a.data; + eccPubKeySpec->base.a.len = eccCommSpec->a.len; + eccPubKeySpec->base.b.data = eccCommSpec->b.data; + eccPubKeySpec->base.b.len = eccCommSpec->b.len; + eccPubKeySpec->base.g.x.data = eccCommSpec->g.x.data; + eccPubKeySpec->base.g.x.len = eccCommSpec->g.x.len; + eccPubKeySpec->base.g.y.data = eccCommSpec->g.y.data; + eccPubKeySpec->base.g.y.len = eccCommSpec->g.y.len; + eccPubKeySpec->base.n.data = eccCommSpec->n.data; + eccPubKeySpec->base.n.len = eccCommSpec->n.len; + eccPubKeySpec->base.h = eccCommSpec->h; + if (ConstructEccPubKeyBigInt(keyPair, eccPubKeySpec) != HCF_SUCCESS) { + HcfFree(eccPubKeySpec); + } else { + *spec = (HcfAsyKeyParamsSpec *)eccPubKeySpec; + res = HCF_SUCCESS; + } + } + + HcfObjDestroy(generator); + HcfObjDestroy(keyPair); + return res; +} + +HcfResult ConstructEccPriKeyParamsSpec(const char *algoName, HcfEccCommParamsSpec *eccCommSpec, + HcfAsyKeyParamsSpec **spec) +{ + if (eccCommSpec == NULL) { + return HCF_INVALID_PARAMS; + } + + HcfResult res = HCF_ERR_CRYPTO_OPERATION; + HcfAsyKeyGenerator *generator = NULL; + if (HcfAsyKeyGeneratorCreate(algoName, &generator) != HCF_SUCCESS) { + return res; + } + + HcfKeyPair *keyPair = NULL; + if (generator->generateKeyPair(generator, NULL, &keyPair) != HCF_SUCCESS) { + HcfObjDestroy(generator); + return res; + } + + HcfEccPriKeyParamsSpec *eccPriKeySpec = (HcfEccPriKeyParamsSpec*)HcfMalloc(sizeof(HcfEccPriKeyParamsSpec), 0); + if (eccPriKeySpec != NULL) { + eccPriKeySpec->base.base.algName = eccCommSpec->base.algName; + eccPriKeySpec->base.base.specType = HCF_PRIVATE_KEY_SPEC; + eccPriKeySpec->base.field = eccCommSpec->field; + eccPriKeySpec->base.field->fieldType = eccCommSpec->field->fieldType; + ((HcfECFieldFp *)(eccPriKeySpec->base.field))->p.data = ((HcfECFieldFp *)(eccCommSpec->field))->p.data; + ((HcfECFieldFp *)(eccPriKeySpec->base.field))->p.len = ((HcfECFieldFp *)(eccCommSpec->field))->p.len; + eccPriKeySpec->base.a.data = eccCommSpec->a.data; + eccPriKeySpec->base.a.len = eccCommSpec->a.len; + eccPriKeySpec->base.b.data = eccCommSpec->b.data; + eccPriKeySpec->base.b.len = eccCommSpec->b.len; + eccPriKeySpec->base.g.x.data = eccCommSpec->g.x.data; + eccPriKeySpec->base.g.x.len = eccCommSpec->g.x.len; + eccPriKeySpec->base.g.y.data = eccCommSpec->g.y.data; + eccPriKeySpec->base.g.y.len = eccCommSpec->g.y.len; + eccPriKeySpec->base.n.data = eccCommSpec->n.data; + eccPriKeySpec->base.n.len = eccCommSpec->n.len; + eccPriKeySpec->base.h = eccCommSpec->h; + HcfBigInteger retBigInt = { .data = NULL, .len = 0 }; + if (keyPair->priKey->getAsyKeySpecBigInteger(keyPair->priKey, ECC_SK_BN, &retBigInt) != HCF_SUCCESS) { + HcfFree(eccPriKeySpec); + } else { + eccPriKeySpec->sk.data = retBigInt.data; + eccPriKeySpec->sk.len = retBigInt.len; + *spec = (HcfAsyKeyParamsSpec *)eccPriKeySpec; + res = HCF_SUCCESS; + } + } + HcfObjDestroy(generator); + HcfObjDestroy(keyPair); + return res; +} \ No newline at end of file