diff --git a/common/inc/log.h b/common/inc/log.h index ded862155449711d8d984ad87c33d3f60b32c27c..d3b3c2982f36798a06dc54345f34b1245a3e097d 100644 --- a/common/inc/log.h +++ b/common/inc/log.h @@ -18,6 +18,7 @@ #include #include +#include "hilog/log.h" #if defined(MINI_HILOG_ENABLE) @@ -41,7 +42,7 @@ enum HcfLogLevel { extern "C" { #endif -void HcfLogPrint(uint32_t hcfLogLevel, const char *funcName, uint32_t lineNo, const char *format, ...); +void HcfLogPrint(uint32_t hcfLogLevel, const char *funcName, uint32_t lineNo, const char *str); #ifdef __cplusplus } @@ -53,10 +54,15 @@ void HcfLogPrint(uint32_t hcfLogLevel, const char *funcName, uint32_t lineNo, co #undef LOG_DOMAIN #define LOG_DOMAIN 0xD002F0A /* Security subsystem's domain id */ -#define LOGI(...) HcfLogPrint(HCF_LOG_LEVEL_I, __func__, __LINE__, __VA_ARGS__) -#define LOGW(...) HcfLogPrint(HCF_LOG_LEVEL_W, __func__, __LINE__, __VA_ARGS__) -#define LOGE(...) HcfLogPrint(HCF_LOG_LEVEL_E, __func__, __LINE__, __VA_ARGS__) -#define LOGD(...) HcfLogPrint(HCF_LOG_LEVEL_D, __func__, __LINE__, __VA_ARGS__) +#define LOGI(fmt, ...) HILOG_INFO(LOG_CORE, "%{public}s[%{public}u]: " fmt "\n", __func__, __LINE__, ##__VA_ARGS__) +#define LOGW(fmt, ...) HILOG_WARN(LOG_CORE, "%{public}s[%{public}u]: " fmt "\n", __func__, __LINE__, ##__VA_ARGS__) +#define LOGE(fmt, ...) HILOG_ERROR(LOG_CORE, "%{public}s[%{public}u]: " fmt "\n", __func__, __LINE__, ##__VA_ARGS__) +#define LOGD(fmt, ...) HILOG_DEBUG(LOG_CORE, "%{public}s[%{public}u]: " fmt "\n", __func__, __LINE__, ##__VA_ARGS__) + +#define LOGI_ONE_STR(str) HcfLogPrint(HCF_LOG_LEVEL_I, __func__, __LINE__, str) +#define LOGW_ONE_STR(str) HcfLogPrint(HCF_LOG_LEVEL_W, __func__, __LINE__, str) +#define LOGE_ONE_STR(str) HcfLogPrint(HCF_LOG_LEVEL_E, __func__, __LINE__, str) +#define LOGD_ONE_STR(str) HcfLogPrint(HCF_LOG_LEVEL_D, __func__, __LINE__, str) #else #include diff --git a/common/src/asy_key_params.c b/common/src/asy_key_params.c index 415ab5aca1521d04efe2d9ee12e91ab6f0874b7d..9c5937c293da38edde8d9f21093e770677aa4cb8 100644 --- a/common/src/asy_key_params.c +++ b/common/src/asy_key_params.c @@ -294,7 +294,7 @@ static void DestroyDsaParamsSpec(HcfAsyKeyParamsSpec *spec) DestroyDsaKeyPairSpec((HcfDsaKeyPairParamsSpec *)spec); break; default: - LOGE("No matching DSA key params spec type."); + LOGE_ONE_STR("No matching DSA key params spec type."); break; } } @@ -315,7 +315,7 @@ static void DestroyDhParamsSpec(HcfAsyKeyParamsSpec *spec) DestroyDhKeyPairSpec((HcfDhKeyPairParamsSpec *)spec); break; default: - LOGE("No matching DH key params spec type."); + LOGE_ONE_STR("No matching DH key params spec type."); break; } } @@ -336,7 +336,7 @@ static void DestroyEccParamsSpec(HcfAsyKeyParamsSpec *spec) DestroyEccKeyPairSpec((HcfEccKeyPairParamsSpec *)spec); break; default: - LOGE("No matching ECC key params spec type."); + LOGE_ONE_STR("No matching ECC key params spec type."); break; } } @@ -354,7 +354,7 @@ static void DestroyRsaParamsSpec(HcfAsyKeyParamsSpec *spec) DestroyRsaKeyPairSpec((HcfRsaKeyPairParamsSpec *)spec); break; default: - LOGE("No matching RSA key params spec type."); + LOGE_ONE_STR("No matching RSA key params spec type."); break; } } @@ -428,7 +428,7 @@ static void DestroyAlg25519ParamsSpec(HcfAsyKeyParamsSpec *spec) DestroyAlg25519KeyPairSpec((HcfAlg25519KeyPairParamsSpec *)spec); break; default: - LOGE("No matching alg25519 key params spec type."); + LOGE_ONE_STR("No matching alg25519 key params spec type."); break; } } @@ -457,14 +457,14 @@ static HcfFreeParamsAsyKeySpec FindAsyKeySpecFreeAbility(HcfAsyKeyParamsSpec *sp void FreeAsyKeySpec(HcfAsyKeyParamsSpec *spec) { if (spec == NULL || spec->algName == NULL) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return; } HcfFreeParamsAsyKeySpec createFreeFunc = FindAsyKeySpecFreeAbility(spec); if (createFreeFunc != NULL) { createFreeFunc(spec); } else { - LOGE("create freeFunc failed."); + LOGE_ONE_STR("create freeFunc failed."); } } diff --git a/common/src/blob.c b/common/src/blob.c index 4befeb06e3d95108d5f04118a353b5aedb00ba96..09014fc802c21a8eaf51cf2f473c4ccf1969cd02 100644 --- a/common/src/blob.c +++ b/common/src/blob.c @@ -32,7 +32,7 @@ void HcfBlobDataFree(HcfBlob *blob) void HcfBlobDataClearAndFree(HcfBlob *blob) { if ((blob == NULL) || (blob->data == NULL)) { - LOGD("The input blob is null, no need to free."); + LOGD_ONE_STR("The input blob is null, no need to free."); return; } (void)memset_s(blob->data, blob->len, 0, blob->len); diff --git a/common/src/log.c b/common/src/log.c index 02bace19ce751a6dc794c2e2ac1ddbb7914b234a..d9c6b6a997e3d7831d3149428598c477a2b0001a 100644 --- a/common/src/log.c +++ b/common/src/log.c @@ -19,33 +19,21 @@ #ifdef HILOG_ENABLE #include "hilog/log.h" -#define HCF_MAX_LOG_BUFF_LEN 512 -void HcfLogPrint(uint32_t hcfLogLevel, const char *funcName, uint32_t lineNo, const char *format, ...) +void HcfLogPrint(uint32_t hcfLogLevel, const char *funcName, uint32_t lineNo, const char *str) { - char logBuf[HCF_MAX_LOG_BUFF_LEN] = {0}; - - va_list arg; - va_start(arg, format); - int32_t ret = vsnprintf_s(logBuf, HCF_MAX_LOG_BUFF_LEN, HCF_MAX_LOG_BUFF_LEN - 1, format, arg); - va_end(arg); - if (ret < 0) { - HILOG_ERROR(LOG_CORE, "crypto framework log concatenate error."); - return; - } - switch (hcfLogLevel) { case HCF_LOG_LEVEL_I: - HILOG_INFO(LOG_CORE, "%{public}s[%{public}u]: %{public}s\n", funcName, lineNo, logBuf); + HILOG_INFO(LOG_CORE, "%{public}s[%{public}u]: %{public}s\n", funcName, lineNo, str); break; case HCF_LOG_LEVEL_E: - HILOG_ERROR(LOG_CORE, "%{public}s[%{public}u]: %{public}s\n", funcName, lineNo, logBuf); + HILOG_ERROR(LOG_CORE, "%{public}s[%{public}u]: %{public}s\n", funcName, lineNo, str); break; case HCF_LOG_LEVEL_W: - HILOG_WARN(LOG_CORE, "%{public}s[%{public}u]: %{public}s\n", funcName, lineNo, logBuf); + HILOG_WARN(LOG_CORE, "%{public}s[%{public}u]: %{public}s\n", funcName, lineNo, str); break; case HCF_LOG_LEVEL_D: - HILOG_DEBUG(LOG_CORE, "%{public}s[%{public}u]: %{private}s\n", funcName, lineNo, logBuf); + HILOG_DEBUG(LOG_CORE, "%{public}s[%{public}u]: %{private}s\n", funcName, lineNo, str); break; default: return; diff --git a/common/src/memory.c b/common/src/memory.c index aec37366e85fc88f4c0be8d1b61add7a3a85b446..1304110a61e3996218fee584f9842f17bb629e20 100644 --- a/common/src/memory.c +++ b/common/src/memory.c @@ -21,7 +21,7 @@ void *HcfMalloc(uint32_t size, char val) { if (size == 0) { - LOGE("malloc size is invalid"); + LOGE_ONE_STR("malloc size is invalid"); return NULL; } void *addr = malloc(size); diff --git a/common/src/params_parser.c b/common/src/params_parser.c index 856a828be7213c7c4da0577b6abc12520127c2f5..347ee0f4d2c46deeacabac4825a1e75fc719133e 100644 --- a/common/src/params_parser.c +++ b/common/src/params_parser.c @@ -215,7 +215,7 @@ HcfResult ParseAndSetParameter(const char *paramsStr, void *params, SetParameter int findPos = StringFind(&str, '|', pos); if (findPos >= 0) { if (!StringSubString(&str, pos, findPos - pos, &subStr)) { - LOGE("StringSubString failed!"); + LOGE_ONE_STR("StringSubString failed!"); break; } ret = (*setFunc)(FindConfig(&subStr), params); @@ -229,7 +229,7 @@ HcfResult ParseAndSetParameter(const char *paramsStr, void *params, SetParameter break; } if (!StringSubString(&str, pos, strLen - pos, &subStr)) { - LOGE("get last string failed!"); + LOGE_ONE_STR("get last string failed!"); break; } ret = (*setFunc)(FindConfig(&subStr), params); @@ -261,7 +261,7 @@ HcfResult ParseAlgNameToParams(const char *algNameStr, HcfAsyKeyGenParams *param HcfResult ParseCurveNameToParams(const char *curveNameStr, HcfAsyKeyGenParams *params) { if (curveNameStr == NULL || params == NULL) { - LOGE("curveName to Params failed!"); + LOGE_ONE_STR("curveName to Params failed!"); return HCF_INVALID_PARAMS; } for (uint32_t i = 0; i < sizeof(CURVE_MAP) / sizeof(HcfCurveMap); ++i) { @@ -278,7 +278,7 @@ HcfResult ParseCurveNameToParams(const char *curveNameStr, HcfAsyKeyGenParams *p HcfResult GetAlgValueByCurveName(const char *curveNameStr, HcfAlgParaValue *algValue) { if (curveNameStr == NULL || algValue == NULL) { - LOGE("Invalid parameter!"); + LOGE_ONE_STR("Invalid parameter!"); return HCF_INVALID_PARAMS; } for (uint32_t i = 0; i < sizeof(CURVE_MAP) / sizeof(CURVE_MAP[0]); i++) { @@ -294,7 +294,7 @@ HcfResult GetAlgValueByCurveName(const char *curveNameStr, HcfAlgParaValue *algV HcfResult GetFormatValueByFormatName(const char *formatName, HcfFormatValue *formatValue) { if (formatName == NULL || formatValue == NULL) { - LOGE("Invalid parameter!"); + LOGE_ONE_STR("Invalid parameter!"); return HCF_INVALID_PARAMS; } diff --git a/common/src/utils.c b/common/src/utils.c index d42b49957ad56b35465e31df4370b227bfea9fc0..ceea92d49f16882259c89dfc52e552602a4c8426 100644 --- a/common/src/utils.c +++ b/common/src/utils.c @@ -23,12 +23,12 @@ bool HcfIsStrValid(const char *str, uint32_t maxLen) { if (str == NULL) { - LOGE("input string is NULL ptr"); + LOGE_ONE_STR("input string is NULL ptr"); return false; } // One byte must be reserved for the terminator. if (strnlen(str, maxLen) >= maxLen) { - LOGE("input string is beyond max length"); + LOGE_ONE_STR("input string is beyond max length"); return false; } return true; @@ -55,7 +55,7 @@ bool HcfIsClassMatch(const HcfObjectBase *obj, const char *className) size_t HcfStrlen(const char *str) { if (str == NULL) { - LOGE("str is null"); + LOGE_ONE_STR("str is null"); return ERROR_STR_LENGTH; } return strlen(str); diff --git a/frameworks/crypto_operation/cipher.c b/frameworks/crypto_operation/cipher.c index aab445a791b7be7be4b682692e59543343f30b2c..aff85cba7e0216596e561c7c1eec16b1a818b6d9 100644 --- a/frameworks/crypto_operation/cipher.c +++ b/frameworks/crypto_operation/cipher.c @@ -140,7 +140,7 @@ static void SetMgf1Digest(HcfAlgParaValue value, CipherAttr *cipher) static HcfResult OnSetParameter(const HcfParaConfig *config, void *cipher) { if ((config == NULL) || (cipher == NULL)) { - LOGE("Invalid cipher params"); + LOGE_ONE_STR("Invalid cipher params"); return HCF_INVALID_PARAMS; } HcfResult ret = HCF_SUCCESS; @@ -166,7 +166,7 @@ static HcfResult OnSetParameter(const HcfParaConfig *config, void *cipher) break; case HCF_ALG_TEXT_FORMAT: if (config->paraValue == HCF_ALG_TEXT_FORMAT_C1C2C3) { - LOGE("Not Support C1C2C3 Format"); + LOGE_ONE_STR("Not Support C1C2C3 Format"); ret = HCF_INVALID_PARAMS; } break; @@ -185,11 +185,11 @@ static const char *GetCipherGeneratorClass(void) static const char *GetAlgorithm(HcfCipher *self) { if (self == NULL) { - LOGE("The input self ptr is NULL!"); + LOGE_ONE_STR("The input self ptr is NULL!"); return NULL; } if (!HcfIsClassMatch((HcfObjectBase *)self, GetCipherGeneratorClass())) { - LOGE("Class is not match."); + LOGE_ONE_STR("Class is not match."); return NULL; } return ((CipherGenImpl *)self)->algoName; @@ -201,7 +201,7 @@ static void CipherDestroy(HcfObjectBase *self) return; } if (!HcfIsClassMatch(self, GetCipherGeneratorClass())) { - LOGE("Class not match."); + LOGE_ONE_STR("Class not match."); return; } CipherGenImpl *impl = (CipherGenImpl *)self; @@ -215,15 +215,15 @@ static HcfResult SetCipherSpecUint8Array(HcfCipher *self, CipherSpecItem item, H // only implemented for OAEP_MGF1_PSRC_UINT8ARR // if pSource == NULL or len == 0, it means cleaning the pSource if (self == NULL) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return HCF_INVALID_PARAMS; } if (item != OAEP_MGF1_PSRC_UINT8ARR) { - LOGE("Spec item not support."); + LOGE_ONE_STR("Spec item not support."); return HCF_INVALID_PARAMS; } if (!HcfIsClassMatch((HcfObjectBase *)self, GetCipherGeneratorClass())) { - LOGE("Class not match."); + LOGE_ONE_STR("Class not match."); return HCF_INVALID_PARAMS; } CipherGenImpl *impl = (CipherGenImpl *)self; @@ -239,15 +239,15 @@ static bool CheckCipherSpecString(CipherSpecItem item) static HcfResult GetCipherSpecString(HcfCipher *self, CipherSpecItem item, char **returnString) { if (self == NULL || returnString == NULL) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return HCF_INVALID_PARAMS; } if (!CheckCipherSpecString(item)) { - LOGE("Spec item not support."); + LOGE_ONE_STR("Spec item not support."); return HCF_INVALID_PARAMS; } if (!HcfIsClassMatch((HcfObjectBase *)self, GetCipherGeneratorClass())) { - LOGE("Class not match."); + LOGE_ONE_STR("Class not match."); return HCF_INVALID_PARAMS; } CipherGenImpl *impl = (CipherGenImpl *)self; @@ -257,15 +257,15 @@ static HcfResult GetCipherSpecString(HcfCipher *self, CipherSpecItem item, char static HcfResult GetCipherSpecUint8Array(HcfCipher *self, CipherSpecItem item, HcfBlob *returnUint8Array) { if (self == NULL || returnUint8Array == NULL) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return HCF_INVALID_PARAMS; } if (item != OAEP_MGF1_PSRC_UINT8ARR) { - LOGE("Spec item not support."); + LOGE_ONE_STR("Spec item not support."); return HCF_INVALID_PARAMS; } if (!HcfIsClassMatch((HcfObjectBase *)self, GetCipherGeneratorClass())) { - LOGE("Class not match."); + LOGE_ONE_STR("Class not match."); return HCF_INVALID_PARAMS; } CipherGenImpl *impl = (CipherGenImpl *)self; @@ -276,11 +276,11 @@ static HcfResult CipherInit(HcfCipher *self, enum HcfCryptoMode opMode, HcfKey *key, HcfParamsSpec *params) { if (self == NULL || key == NULL) { /* params maybe is NULL */ - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return HCF_INVALID_PARAMS; } if (!HcfIsClassMatch((HcfObjectBase *)self, GetCipherGeneratorClass())) { - LOGE("Class is not match."); + LOGE_ONE_STR("Class is not match."); return HCF_INVALID_PARAMS; } CipherGenImpl *impl = (CipherGenImpl *)self; @@ -290,11 +290,11 @@ static HcfResult CipherInit(HcfCipher *self, enum HcfCryptoMode opMode, static HcfResult CipherUpdate(HcfCipher *self, HcfBlob *input, HcfBlob *output) { if ((self == NULL) || (input == NULL) || (output == NULL)) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return HCF_INVALID_PARAMS; } if (!HcfIsClassMatch((HcfObjectBase *)self, GetCipherGeneratorClass())) { - LOGE("Class is not match."); + LOGE_ONE_STR("Class is not match."); return HCF_INVALID_PARAMS; } CipherGenImpl *impl = (CipherGenImpl *)self; @@ -304,11 +304,11 @@ static HcfResult CipherUpdate(HcfCipher *self, HcfBlob *input, HcfBlob *output) static HcfResult CipherFinal(HcfCipher *self, HcfBlob *input, HcfBlob *output) { if ((self == NULL) || (output == NULL)) { - LOGE("Invalid input parameter!"); + LOGE_ONE_STR("Invalid input parameter!"); return HCF_INVALID_PARAMS; } if (!HcfIsClassMatch((HcfObjectBase *)self, GetCipherGeneratorClass())) { - LOGE("Class is not match."); + LOGE_ONE_STR("Class is not match."); return HCF_INVALID_PARAMS; } CipherGenImpl *impl = (CipherGenImpl *)self; @@ -346,33 +346,33 @@ HcfResult HcfCipherCreate(const char *transformation, HcfCipher **returnObj) { CipherAttr attr = {0}; if (!HcfIsStrValid(transformation, HCF_MAX_ALGO_NAME_LEN) || (returnObj == NULL)) { - LOGE("Invalid input params while creating cipher!"); + LOGE_ONE_STR("Invalid input params while creating cipher!"); return HCF_INVALID_PARAMS; } if (ParseAndSetParameter(transformation, (void *)&attr, OnSetParameter) != HCF_SUCCESS) { - LOGE("ParseAndSetParameter failed!"); + LOGE_ONE_STR("ParseAndSetParameter failed!"); return HCF_NOT_SUPPORT; } const HcfCipherGenFuncSet *funcSet = FindAbility(&attr); if (funcSet == NULL) { - LOGE("FindAbility failed!"); + LOGE_ONE_STR("FindAbility failed!"); return HCF_NOT_SUPPORT; } CipherGenImpl *returnGenerator = (CipherGenImpl *)HcfMalloc(sizeof(CipherGenImpl), 0); if (returnGenerator == NULL) { - LOGE("failed to allocate returnGenerator memory!"); + LOGE_ONE_STR("failed to allocate returnGenerator memory!"); return HCF_ERR_MALLOC; } if (strcpy_s(returnGenerator->algoName, HCF_MAX_ALGO_NAME_LEN, transformation) != EOK) { - LOGE("Failed to copy algoName!"); + LOGE_ONE_STR("Failed to copy algoName!"); HcfFree(returnGenerator); return HCF_INVALID_PARAMS; } HcfCipherGeneratorSpi *spiObj = NULL; HcfResult res = funcSet->createFunc(&attr, &spiObj); if (res != HCF_SUCCESS) { - LOGE("Failed to create spi object!"); + LOGE_ONE_STR("Failed to create spi object!"); HcfFree(returnGenerator); return res; } diff --git a/frameworks/crypto_operation/kdf.c b/frameworks/crypto_operation/kdf.c index a404af57c2ac0f9bf80ab150597a1d62cfad88fd..8acb374b3e2e9d3577ce7fe11eb118aab89d920a 100644 --- a/frameworks/crypto_operation/kdf.c +++ b/frameworks/crypto_operation/kdf.c @@ -71,7 +71,7 @@ static void SetMode(HcfAlgParaValue value, HcfKdfDeriveParams *kdf) static HcfResult ParseKdfParams(const HcfParaConfig *config, void *params) { if (config == NULL || params == NULL) { - LOGE("Invalid Kdf params"); + LOGE_ONE_STR("Invalid Kdf params"); return HCF_INVALID_PARAMS; } HcfResult ret = HCF_SUCCESS; @@ -120,7 +120,7 @@ static const char *GetKdfGeneratorClass(void) static const char *GetAlgoName(HcfKdf *self) { if (self == NULL) { - LOGE("The input self ptr is NULL!"); + LOGE_ONE_STR("The input self ptr is NULL!"); return NULL; } if (!HcfIsClassMatch((HcfObjectBase *)self, GetKdfGeneratorClass())) { @@ -132,7 +132,7 @@ static const char *GetAlgoName(HcfKdf *self) static HcfResult GenerateSecret(HcfKdf *self, HcfKdfParamsSpec *paramsSpec) { if (self == NULL || paramsSpec == NULL) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return HCF_INVALID_PARAMS; } if (!HcfIsClassMatch((HcfObjectBase *)self, GetKdfGeneratorClass())) { @@ -160,35 +160,35 @@ static void DestroyKdf(HcfObjectBase *self) HcfResult HcfKdfCreate(const char *transformation, HcfKdf **returnObj) { if ((!HcfIsStrValid(transformation, HCF_MAX_ALGO_NAME_LEN)) || (returnObj == NULL)) { - LOGE("Invalid input params while creating kdf!"); + LOGE_ONE_STR("Invalid input params while creating kdf!"); return HCF_INVALID_PARAMS; } HcfKdfDeriveParams params = { 0 }; if (ParseAndSetParameter(transformation, ¶ms, ParseKdfParams) != HCF_SUCCESS) { - LOGE("Failed to parse params!"); + LOGE_ONE_STR("Failed to parse params!"); return HCF_INVALID_PARAMS; } HcfKdfSpiCreateFunc createSpiFunc = FindAbility(¶ms); if (createSpiFunc == NULL) { - LOGE("Not support this KDF func"); + LOGE_ONE_STR("Not support this KDF func"); return HCF_NOT_SUPPORT; } HcfKdfImpl *returnGenerator = (HcfKdfImpl *)HcfMalloc(sizeof(HcfKdfImpl), 0); if (returnGenerator == NULL) { - LOGE("Failed to allocate returnGenerator memory!"); + LOGE_ONE_STR("Failed to allocate returnGenerator memory!"); return HCF_ERR_MALLOC; } if (strcpy_s(returnGenerator->algoName, HCF_MAX_ALGO_NAME_LEN, transformation) != EOK) { - LOGE("Failed to copy algoName!"); + LOGE_ONE_STR("Failed to copy algoName!"); HcfFree(returnGenerator); return HCF_INVALID_PARAMS; } HcfKdfSpi *spiObj = NULL; HcfResult res = createSpiFunc(¶ms, &spiObj); if (res != HCF_SUCCESS) { - LOGE("Failed to create spi object!"); + LOGE_ONE_STR("Failed to create spi object!"); HcfFree(returnGenerator); return res; } diff --git a/frameworks/crypto_operation/key_agreement.c b/frameworks/crypto_operation/key_agreement.c index 45e65989bc1bb0a940d21c2cb646ff232ac8c91c..d1c4e731f1518be16ed41f6e81d1110e8c15d9a7 100644 --- a/frameworks/crypto_operation/key_agreement.c +++ b/frameworks/crypto_operation/key_agreement.c @@ -127,7 +127,7 @@ static void SetKeyTypeDefault(HcfAlgParaValue value, HcfKeyAgreementParams *par static HcfResult ParseKeyAgreementParams(const HcfParaConfig *config, void *params) { if (config == NULL || params == NULL) { - LOGE("Invalid key agreement params"); + LOGE_ONE_STR("Invalid key agreement params"); return HCF_INVALID_PARAMS; } HcfResult ret = HCF_SUCCESS; @@ -156,7 +156,7 @@ static const char *GetKeyAgreementClass(void) static const char *GetAlgoName(HcfKeyAgreement *self) { if (self == NULL) { - LOGE("The input self ptr is NULL!"); + LOGE_ONE_STR("The input self ptr is NULL!"); return NULL; } if (!HcfIsClassMatch((HcfObjectBase *)self, GetKeyAgreementClass())) { @@ -169,7 +169,7 @@ static HcfResult GenerateSecret(HcfKeyAgreement *self, HcfPriKey *priKey, HcfPubKey *pubKey, HcfBlob *returnSecret) { if (self == NULL) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return HCF_INVALID_PARAMS; } if (!HcfIsClassMatch((HcfObjectBase *)self, GetKeyAgreementClass())) { @@ -202,7 +202,7 @@ HcfResult HcfKeyAgreementCreate(const char *algoName, HcfKeyAgreement **returnOb HcfKeyAgreementParams params = { 0 }; if (ParseAndSetParameter(algoName, ¶ms, ParseKeyAgreementParams) != HCF_SUCCESS) { - LOGE("Failed to parse params!"); + LOGE_ONE_STR("Failed to parse params!"); return HCF_INVALID_PARAMS; } @@ -213,18 +213,18 @@ HcfResult HcfKeyAgreementCreate(const char *algoName, HcfKeyAgreement **returnOb HcfKeyAgreementImpl *returnGenerator = (HcfKeyAgreementImpl *)HcfMalloc(sizeof(HcfKeyAgreementImpl), 0); if (returnGenerator == NULL) { - LOGE("Failed to allocate returnGenerator memory!"); + LOGE_ONE_STR("Failed to allocate returnGenerator memory!"); return HCF_ERR_MALLOC; } if (strcpy_s(returnGenerator->algoName, HCF_MAX_ALGO_NAME_LEN, algoName) != EOK) { - LOGE("Failed to copy algoName!"); + LOGE_ONE_STR("Failed to copy algoName!"); HcfFree(returnGenerator); return HCF_INVALID_PARAMS; } HcfKeyAgreementSpi *spiObj = NULL; HcfResult res = createSpiFunc(¶ms, &spiObj); if (res != HCF_SUCCESS) { - LOGE("Failed to create spi object!"); + LOGE_ONE_STR("Failed to create spi object!"); HcfFree(returnGenerator); return res; } diff --git a/frameworks/crypto_operation/mac.c b/frameworks/crypto_operation/mac.c index 07afa7ece98e07d45b91ad40581d0e205d3169c2..f5ce3a5ea5060de789ebf50378468725f8c0344c 100644 --- a/frameworks/crypto_operation/mac.c +++ b/frameworks/crypto_operation/mac.c @@ -61,7 +61,7 @@ static const char *GetMacClass(void) static HcfMacSpiCreateFunc FindAbility(const char *mdName) { if (mdName == NULL) { - LOGE("Invalid mdName: null pointer."); + LOGE_ONE_STR("Invalid mdName: null pointer."); return NULL; } for (uint32_t i = 0; i < (sizeof(HMAC_ABILITY_SET) / sizeof(HMAC_ABILITY_SET[0])); i++) { @@ -76,11 +76,11 @@ static HcfMacSpiCreateFunc FindAbility(const char *mdName) static HcfResult Init(HcfMac *self, const HcfSymKey *key) { if ((self == NULL) || (key == NULL)) { - LOGE("The input self ptr or key is NULL!"); + LOGE_ONE_STR("The input self ptr or key is NULL!"); return HCF_INVALID_PARAMS; } if (!HcfIsClassMatch((HcfObjectBase *)self, GetMacClass())) { - LOGE("Class is not match."); + LOGE_ONE_STR("Class is not match."); return HCF_INVALID_PARAMS; } return ((HcfMacImpl *)self)->spiObj->engineInitMac( @@ -90,11 +90,11 @@ static HcfResult Init(HcfMac *self, const HcfSymKey *key) static HcfResult Update(HcfMac *self, HcfBlob *input) { if ((self == NULL) || (!HcfIsBlobValid(input))) { - LOGE("The input self ptr or dataBlob is NULL!"); + LOGE_ONE_STR("The input self ptr or dataBlob is NULL!"); return HCF_INVALID_PARAMS; } if (!HcfIsClassMatch((HcfObjectBase *)self, GetMacClass())) { - LOGE("Class is not match."); + LOGE_ONE_STR("Class is not match."); return HCF_INVALID_PARAMS; } return ((HcfMacImpl *)self)->spiObj->engineUpdateMac( @@ -104,11 +104,11 @@ static HcfResult Update(HcfMac *self, HcfBlob *input) static HcfResult DoFinal(HcfMac *self, HcfBlob *output) { if ((self == NULL) || (output == NULL)) { - LOGE("The input self ptr or dataBlob is NULL!"); + LOGE_ONE_STR("The input self ptr or dataBlob is NULL!"); return HCF_INVALID_PARAMS; } if (!HcfIsClassMatch((HcfObjectBase *)self, GetMacClass())) { - LOGE("Class is not match."); + LOGE_ONE_STR("Class is not match."); return HCF_INVALID_PARAMS; } return ((HcfMacImpl *)self)->spiObj->engineDoFinalMac( @@ -118,11 +118,11 @@ static HcfResult DoFinal(HcfMac *self, HcfBlob *output) static uint32_t GetMacLength(HcfMac *self) { if (self == NULL) { - LOGE("The input self ptr is NULL!"); + LOGE_ONE_STR("The input self ptr is NULL!"); return 0; } if (!HcfIsClassMatch((HcfObjectBase *)self, GetMacClass())) { - LOGE("Class is not match."); + LOGE_ONE_STR("Class is not match."); return 0; } return ((HcfMacImpl *)self)->spiObj->engineGetMacLength( @@ -132,11 +132,11 @@ static uint32_t GetMacLength(HcfMac *self) static const char *GetAlgoName(HcfMac *self) { if (self == NULL) { - LOGE("The input self ptr is NULL!"); + LOGE_ONE_STR("The input self ptr is NULL!"); return NULL; } if (!HcfIsClassMatch((HcfObjectBase *)self, GetMacClass())) { - LOGE("Class is not match."); + LOGE_ONE_STR("Class is not match."); return NULL; } return ((HcfMacImpl *)self)->algoName; @@ -145,11 +145,11 @@ static const char *GetAlgoName(HcfMac *self) static void MacDestroy(HcfObjectBase *self) { if (self == NULL) { - LOGE("The input self ptr is NULL!"); + LOGE_ONE_STR("The input self ptr is NULL!"); return; } if (!HcfIsClassMatch((HcfObjectBase *)self, GetMacClass())) { - LOGE("Class is not match."); + LOGE_ONE_STR("Class is not match."); return; } HcfMacImpl *impl = (HcfMacImpl *)self; @@ -160,7 +160,7 @@ static void MacDestroy(HcfObjectBase *self) static HcfResult SetMacAlgoName(HcfMacImpl *macImpl, const char *algoName) { if (strcpy_s(macImpl->algoName, HCF_MAX_ALGO_NAME_LEN, algoName) != EOK) { - LOGE("Failed to copy algoName!"); + LOGE_ONE_STR("Failed to copy algoName!"); return HCF_INVALID_PARAMS; } return HCF_SUCCESS; @@ -171,7 +171,7 @@ static HcfResult HandleCmacAlgo(HcfMacImpl *macImpl, const HcfMacParamsSpec *par { const char *cipherName = ((HcfCmacParamsSpec *)paramsSpec)->cipherName; if (cipherName == NULL) { - LOGE("Invalid cipher name: null pointer."); + LOGE_ONE_STR("Invalid cipher name: null pointer."); return HCF_INVALID_PARAMS; } @@ -198,13 +198,13 @@ static HcfResult HandleHmacAlgo(HcfMacImpl *macImpl, const HcfMacParamsSpec *par HcfResult HcfMacCreate(HcfMacParamsSpec *paramsSpec, HcfMac **mac) { if (paramsSpec == NULL || !HcfIsStrValid(paramsSpec->algName, HCF_MAX_ALGO_NAME_LEN) || (mac == NULL)) { - LOGE("Invalid input params while creating mac!"); + LOGE_ONE_STR("Invalid input params while creating mac!"); return HCF_INVALID_PARAMS; } HcfMacSpiCreateFunc createSpiFunc = NULL; HcfMacImpl *returnMacApi = (HcfMacImpl *)HcfMalloc(sizeof(HcfMacImpl), 0); if (returnMacApi == NULL) { - LOGE("Failed to allocate Mac Obj memory!"); + LOGE_ONE_STR("Failed to allocate Mac Obj memory!"); return HCF_ERR_MALLOC; } @@ -224,13 +224,13 @@ HcfResult HcfMacCreate(HcfMacParamsSpec *paramsSpec, HcfMac **mac) return res; } if (createSpiFunc == NULL) { - LOGE("Algo name is error!"); + LOGE_ONE_STR("Algo name is error!"); return HCF_INVALID_PARAMS; } HcfMacSpi *spiObj = NULL; res = createSpiFunc(paramsSpec, &spiObj); if (res != HCF_SUCCESS) { - LOGE("Failed to create spi object!"); + LOGE_ONE_STR("Failed to create spi object!"); HcfFree(returnMacApi); return res; } diff --git a/frameworks/crypto_operation/md.c b/frameworks/crypto_operation/md.c index 888f3bebaf0eef31ab88b9de75068b8eb21c790f..97aab22d74d7121b821d20f9a33b825f3c57747b 100644 --- a/frameworks/crypto_operation/md.c +++ b/frameworks/crypto_operation/md.c @@ -82,11 +82,11 @@ static HcfMdSpiCreateFunc FindAbility(const char *algoName) static HcfResult Update(HcfMd *self, HcfBlob *input) { if ((self == NULL) || (!HcfIsBlobValid(input))) { - LOGE("The input self ptr or dataBlob is NULL!"); + LOGE_ONE_STR("The input self ptr or dataBlob is NULL!"); return HCF_INVALID_PARAMS; } if (!HcfIsClassMatch((HcfObjectBase *)self, GetMdClass())) { - LOGE("Class is not match."); + LOGE_ONE_STR("Class is not match."); return HCF_INVALID_PARAMS; } return ((HcfMdImpl *)self)->spiObj->engineUpdateMd( @@ -96,11 +96,11 @@ static HcfResult Update(HcfMd *self, HcfBlob *input) static HcfResult DoFinal(HcfMd *self, HcfBlob *output) { if ((self == NULL) || (output == NULL)) { - LOGE("The input self ptr or dataBlob is NULL!"); + LOGE_ONE_STR("The input self ptr or dataBlob is NULL!"); return HCF_INVALID_PARAMS; } if (!HcfIsClassMatch((HcfObjectBase *)self, GetMdClass())) { - LOGE("Class is not match."); + LOGE_ONE_STR("Class is not match."); return HCF_INVALID_PARAMS; } return ((HcfMdImpl *)self)->spiObj->engineDoFinalMd( @@ -110,11 +110,11 @@ static HcfResult DoFinal(HcfMd *self, HcfBlob *output) static uint32_t GetMdLength(HcfMd *self) { if (self == NULL) { - LOGE("The input self ptr is NULL!"); + LOGE_ONE_STR("The input self ptr is NULL!"); return 0; } if (!HcfIsClassMatch((HcfObjectBase *)self, GetMdClass())) { - LOGE("Class is not match."); + LOGE_ONE_STR("Class is not match."); return 0; } return ((HcfMdImpl *)self)->spiObj->engineGetMdLength( @@ -124,11 +124,11 @@ static uint32_t GetMdLength(HcfMd *self) static const char *GetAlgoName(HcfMd *self) { if (self == NULL) { - LOGE("The input self ptr is NULL!"); + LOGE_ONE_STR("The input self ptr is NULL!"); return NULL; } if (!HcfIsClassMatch((HcfObjectBase *)self, GetMdClass())) { - LOGE("Class is not match."); + LOGE_ONE_STR("Class is not match."); return NULL; } return ((HcfMdImpl *)self)->algoName; @@ -137,11 +137,11 @@ static const char *GetAlgoName(HcfMd *self) static void MdDestroy(HcfObjectBase *self) { if (self == NULL) { - LOGE("The input self ptr is NULL!"); + LOGE_ONE_STR("The input self ptr is NULL!"); return; } if (!HcfIsClassMatch((HcfObjectBase *)self, GetMdClass())) { - LOGE("Class is not match."); + LOGE_ONE_STR("Class is not match."); return; } HcfMdImpl *impl = (HcfMdImpl *)self; @@ -152,28 +152,28 @@ static void MdDestroy(HcfObjectBase *self) HcfResult HcfMdCreate(const char *algoName, HcfMd **md) { if (!HcfIsStrValid(algoName, HCF_MAX_ALGO_NAME_LEN) || (md == NULL)) { - LOGE("Invalid input params while creating md!"); + LOGE_ONE_STR("Invalid input params while creating md!"); return HCF_INVALID_PARAMS; } HcfMdSpiCreateFunc createSpiFunc = FindAbility(algoName); if (createSpiFunc == NULL) { - LOGE("Algo name is error!"); + LOGE_ONE_STR("Algo name is error!"); return HCF_INVALID_PARAMS; } HcfMdImpl *returnMdApi = (HcfMdImpl *)HcfMalloc(sizeof(HcfMdImpl), 0); if (returnMdApi == NULL) { - LOGE("Failed to allocate Md Obj memory!"); + LOGE_ONE_STR("Failed to allocate Md Obj memory!"); return HCF_ERR_MALLOC; } if (strcpy_s(returnMdApi->algoName, HCF_MAX_ALGO_NAME_LEN, algoName) != EOK) { - LOGE("Failed to copy algoName!"); + LOGE_ONE_STR("Failed to copy algoName!"); HcfFree(returnMdApi); return HCF_INVALID_PARAMS; } HcfMdSpi *spiObj = NULL; HcfResult res = createSpiFunc(algoName, &spiObj); if (res != HCF_SUCCESS) { - LOGE("Failed to create spi object!"); + LOGE_ONE_STR("Failed to create spi object!"); HcfFree(returnMdApi); return res; } diff --git a/frameworks/crypto_operation/rand.c b/frameworks/crypto_operation/rand.c index 0f4227d8fa857204ce3396263d2d8a6ec4dec8c2..9f6f0679ac104436c44d9a31bff9e68b9bc28e5c 100644 --- a/frameworks/crypto_operation/rand.c +++ b/frameworks/crypto_operation/rand.c @@ -71,15 +71,15 @@ static HcfRandSpiCreateFunc FindAbility(const char *algoName) static HcfResult GenerateRandom(HcfRand *self, int32_t numBytes, HcfBlob *random) { if ((self == NULL) || (random == NULL)) { - LOGE("Invalid params!"); + LOGE_ONE_STR("Invalid params!"); return HCF_INVALID_PARAMS; } if (numBytes <= 0) { - LOGE("Invalid numBytes!"); + LOGE_ONE_STR("Invalid numBytes!"); return HCF_INVALID_PARAMS; } if (!HcfIsClassMatch((HcfObjectBase *)self, GetRandClass())) { - LOGE("Class is not match."); + LOGE_ONE_STR("Class is not match."); return HCF_INVALID_PARAMS; } return ((HcfRandImpl *)self)->spiObj->engineGenerateRandom( @@ -89,11 +89,11 @@ static HcfResult GenerateRandom(HcfRand *self, int32_t numBytes, HcfBlob *random static const char *GetAlgoName(HcfRand *self) { if (self == NULL) { - LOGE("The input self ptr is NULL!"); + LOGE_ONE_STR("The input self ptr is NULL!"); return NULL; } if (!HcfIsClassMatch((HcfObjectBase *)self, GetRandClass())) { - LOGE("Class is not match!"); + LOGE_ONE_STR("Class is not match!"); return NULL; } return ((HcfRandImpl *)self)->spiObj->engineGetAlgoName(((HcfRandImpl *)self)->spiObj); @@ -102,11 +102,11 @@ static const char *GetAlgoName(HcfRand *self) static HcfResult SetSeed(HcfRand *self, HcfBlob *seed) { if ((self == NULL) || (!HcfIsBlobValid(seed)) || (seed->len > INT_MAX)) { - LOGE("The input self ptr is NULL!"); + LOGE_ONE_STR("The input self ptr is NULL!"); return HCF_INVALID_PARAMS; } if (!HcfIsClassMatch((HcfObjectBase *)self, GetRandClass())) { - LOGE("Class is not match."); + LOGE_ONE_STR("Class is not match."); return HCF_INVALID_PARAMS; } ((HcfRandImpl *)self)->spiObj->engineSetSeed( @@ -117,11 +117,11 @@ static HcfResult SetSeed(HcfRand *self, HcfBlob *seed) static void HcfRandDestroy(HcfObjectBase *self) { if (self == NULL) { - LOGE("The input self ptr is NULL!"); + LOGE_ONE_STR("The input self ptr is NULL!"); return; } if (!HcfIsClassMatch((HcfObjectBase *)self, GetRandClass())) { - LOGE("Class is not match."); + LOGE_ONE_STR("Class is not match."); return; } HcfRandImpl *impl = (HcfRandImpl *)self; @@ -132,7 +132,7 @@ static void HcfRandDestroy(HcfObjectBase *self) HcfResult HcfRandCreate(HcfRand **random) { if (random == NULL) { - LOGE("Invalid input params while creating rand!"); + LOGE_ONE_STR("Invalid input params while creating rand!"); return HCF_INVALID_PARAMS; } #ifdef CRYPTO_MBEDTLS @@ -141,18 +141,18 @@ HcfResult HcfRandCreate(HcfRand **random) HcfRandSpiCreateFunc createSpiFunc = FindAbility("OpensslRand"); #endif if (createSpiFunc == NULL) { - LOGE("Algo not supported!"); + LOGE_ONE_STR("Algo not supported!"); return HCF_NOT_SUPPORT; } HcfRandImpl *returnRandApi = (HcfRandImpl *)HcfMalloc(sizeof(HcfRandImpl), 0); if (returnRandApi == NULL) { - LOGE("Failed to allocate Rand Obj memory!"); + LOGE_ONE_STR("Failed to allocate Rand Obj memory!"); return HCF_ERR_MALLOC; } HcfRandSpi *spiObj = NULL; HcfResult res = createSpiFunc(&spiObj); if (res != HCF_SUCCESS) { - LOGE("Failed to create spi object!"); + LOGE_ONE_STR("Failed to create spi object!"); HcfFree(returnRandApi); return res; } diff --git a/frameworks/crypto_operation/signature.c b/frameworks/crypto_operation/signature.c index 7867c927404c36c66f948fbb04afeb6898e1c106..04b468845ef7241ddd5549a5b04370e6f57f6f04 100644 --- a/frameworks/crypto_operation/signature.c +++ b/frameworks/crypto_operation/signature.c @@ -97,7 +97,7 @@ static HcfSignSpiCreateFunc FindSignAbility(HcfSignatureParams *params) static HcfVerifySpiCreateFunc FindVerifyAbility(HcfSignatureParams *params) { if (params->operation == HCF_ALG_VERIFY_RECOVER && params->algo != HCF_ALG_RSA) { - LOGE("Failed to check recover params!"); + LOGE_ONE_STR("Failed to check recover params!"); return NULL; } @@ -181,7 +181,7 @@ static void SetKeyType(HcfAlgParaValue value, HcfSignatureParams *paramsObj) paramsObj->algo = HCF_ALG_ED25519; break; default: - LOGE("there is not matched algorithm."); + LOGE_ONE_STR("there is not matched algorithm."); break; } } @@ -189,7 +189,7 @@ static void SetKeyType(HcfAlgParaValue value, HcfSignatureParams *paramsObj) static HcfResult ParseSignatureParams(const HcfParaConfig *config, void *params) { if (config == NULL || params == NULL) { - LOGE("Invalid signature params"); + LOGE_ONE_STR("Invalid signature params"); return HCF_INVALID_PARAMS; } HcfResult ret = HCF_SUCCESS; @@ -237,7 +237,7 @@ static const char *GetVerifyClass(void) static const char *GetSignAlgoName(HcfSign *self) { if (self == NULL) { - LOGE("The input self ptr is NULL!"); + LOGE_ONE_STR("The input self ptr is NULL!"); return NULL; } if (!HcfIsClassMatch((HcfObjectBase *)self, GetSignClass())) { @@ -249,7 +249,7 @@ static const char *GetSignAlgoName(HcfSign *self) static const char *GetVerifyAlgoName(HcfVerify *self) { if (self == NULL) { - LOGE("The input self ptr is NULL!"); + LOGE_ONE_STR("The input self ptr is NULL!"); return NULL; } if (!HcfIsClassMatch((HcfObjectBase *)self, GetVerifyClass())) { @@ -264,7 +264,7 @@ static void DestroySign(HcfObjectBase *self) return; } if (!HcfIsClassMatch(self, GetSignClass())) { - LOGE("Class not match."); + LOGE_ONE_STR("Class not match."); return; } HcfSignImpl *impl = (HcfSignImpl *)self; @@ -279,7 +279,7 @@ static void DestroyVerify(HcfObjectBase *self) return; } if (!HcfIsClassMatch(self, GetVerifyClass())) { - LOGE("Class not match."); + LOGE_ONE_STR("Class not match."); return; } HcfVerifyImpl *impl = (HcfVerifyImpl *)self; @@ -291,11 +291,11 @@ static void DestroyVerify(HcfObjectBase *self) static HcfResult SetSignSpecInt(HcfSign *self, SignSpecItem item, int32_t saltLen) { if (self == NULL) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return HCF_INVALID_PARAMS; } if (!HcfIsClassMatch((HcfObjectBase *)self, GetSignClass())) { - LOGE("Class not match."); + LOGE_ONE_STR("Class not match."); return HCF_INVALID_PARAMS; } HcfSignImpl *tmpSelf = (HcfSignImpl *)self; @@ -305,11 +305,11 @@ static HcfResult SetSignSpecInt(HcfSign *self, SignSpecItem item, int32_t saltLe static HcfResult GetSignSpecString(HcfSign *self, SignSpecItem item, char **returnString) { if (self == NULL || returnString == NULL) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return HCF_INVALID_PARAMS; } if (!HcfIsClassMatch((HcfObjectBase *)self, GetSignClass())) { - LOGE("Class not match."); + LOGE_ONE_STR("Class not match."); return HCF_INVALID_PARAMS; } HcfSignImpl *tmpSelf = (HcfSignImpl *)self; @@ -319,11 +319,11 @@ static HcfResult GetSignSpecString(HcfSign *self, SignSpecItem item, char **retu static HcfResult SetSignSpecUint8Array(HcfSign *self, SignSpecItem item, HcfBlob blob) { if (self == NULL) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return HCF_INVALID_PARAMS; } if (!HcfIsClassMatch((HcfObjectBase *)self, GetSignClass())) { - LOGE("Class not match."); + LOGE_ONE_STR("Class not match."); return HCF_INVALID_PARAMS; } HcfSignImpl *tmpSelf = (HcfSignImpl *)self; @@ -333,11 +333,11 @@ static HcfResult SetSignSpecUint8Array(HcfSign *self, SignSpecItem item, HcfBlob static HcfResult GetSignSpecInt(HcfSign *self, SignSpecItem item, int32_t *returnInt) { if (self == NULL || returnInt == NULL) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return HCF_INVALID_PARAMS; } if (!HcfIsClassMatch((HcfObjectBase *)self, GetSignClass())) { - LOGE("Class not match."); + LOGE_ONE_STR("Class not match."); return HCF_INVALID_PARAMS; } HcfSignImpl *tmpSelf = (HcfSignImpl *)self; @@ -347,12 +347,12 @@ static HcfResult GetSignSpecInt(HcfSign *self, SignSpecItem item, int32_t *retur static HcfResult SignInit(HcfSign *self, HcfParamsSpec *params, HcfPriKey *privateKey) { if (self == NULL) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return HCF_INVALID_PARAMS; } if (!HcfIsClassMatch((HcfObjectBase *)self, GetSignClass())) { - LOGE("Class not match."); + LOGE_ONE_STR("Class not match."); return HCF_INVALID_PARAMS; } return ((HcfSignImpl *)self)->spiObj->engineInit(((HcfSignImpl *)self)->spiObj, params, privateKey); @@ -361,12 +361,12 @@ static HcfResult SignInit(HcfSign *self, HcfParamsSpec *params, HcfPriKey *priva static HcfResult SignUpdate(HcfSign *self, HcfBlob *data) { if (self == NULL) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return HCF_INVALID_PARAMS; } if (!HcfIsClassMatch((HcfObjectBase *)self, GetSignClass())) { - LOGE("Class not match."); + LOGE_ONE_STR("Class not match."); return HCF_INVALID_PARAMS; } return ((HcfSignImpl *)self)->spiObj->engineUpdate(((HcfSignImpl *)self)->spiObj, data); @@ -375,12 +375,12 @@ static HcfResult SignUpdate(HcfSign *self, HcfBlob *data) static HcfResult SignDoFinal(HcfSign *self, HcfBlob *data, HcfBlob *returnSignatureData) { if (self == NULL) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return HCF_INVALID_PARAMS; } if (!HcfIsClassMatch((HcfObjectBase *)self, GetSignClass())) { - LOGE("Class not match."); + LOGE_ONE_STR("Class not match."); return HCF_INVALID_PARAMS; } return ((HcfSignImpl *)self)->spiObj->engineSign(((HcfSignImpl *)self)->spiObj, data, returnSignatureData); @@ -389,11 +389,11 @@ static HcfResult SignDoFinal(HcfSign *self, HcfBlob *data, HcfBlob *returnSignat static HcfResult SetVerifySpecInt(HcfVerify *self, SignSpecItem item, int32_t saltLen) { if (self == NULL) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return HCF_INVALID_PARAMS; } if (!HcfIsClassMatch((HcfObjectBase *)self, GetVerifyClass())) { - LOGE("Class not match."); + LOGE_ONE_STR("Class not match."); return HCF_INVALID_PARAMS; } HcfVerifyImpl *tmpSelf = (HcfVerifyImpl *)self; @@ -403,11 +403,11 @@ static HcfResult SetVerifySpecInt(HcfVerify *self, SignSpecItem item, int32_t sa static HcfResult GetVerifySpecString(HcfVerify *self, SignSpecItem item, char **returnString) { if (self == NULL || returnString == NULL) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return HCF_INVALID_PARAMS; } if (!HcfIsClassMatch((HcfObjectBase *)self, GetVerifyClass())) { - LOGE("Class not match."); + LOGE_ONE_STR("Class not match."); return HCF_INVALID_PARAMS; } HcfVerifyImpl *tmpSelf = (HcfVerifyImpl *)self; @@ -417,11 +417,11 @@ static HcfResult GetVerifySpecString(HcfVerify *self, SignSpecItem item, char ** static HcfResult SetVerifySpecUint8Array(HcfVerify *self, SignSpecItem item, HcfBlob blob) { if (self == NULL) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return HCF_INVALID_PARAMS; } if (!HcfIsClassMatch((HcfObjectBase *)self, GetVerifyClass())) { - LOGE("Class not match."); + LOGE_ONE_STR("Class not match."); return HCF_INVALID_PARAMS; } HcfVerifyImpl *tmpSelf = (HcfVerifyImpl *)self; @@ -431,11 +431,11 @@ static HcfResult SetVerifySpecUint8Array(HcfVerify *self, SignSpecItem item, Hcf static HcfResult GetVerifySpecInt(HcfVerify *self, SignSpecItem item, int32_t *returnInt) { if (self == NULL || returnInt == NULL) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return HCF_INVALID_PARAMS; } if (!HcfIsClassMatch((HcfObjectBase *)self, GetVerifyClass())) { - LOGE("Class not match."); + LOGE_ONE_STR("Class not match."); return HCF_INVALID_PARAMS; } HcfVerifyImpl *tmpSelf = (HcfVerifyImpl *)self; @@ -445,12 +445,12 @@ static HcfResult GetVerifySpecInt(HcfVerify *self, SignSpecItem item, int32_t *r static HcfResult VerifyInit(HcfVerify *self, HcfParamsSpec *params, HcfPubKey *publicKey) { if (self == NULL) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return HCF_INVALID_PARAMS; } if (!HcfIsClassMatch((HcfObjectBase *)self, GetVerifyClass())) { - LOGE("Class not match."); + LOGE_ONE_STR("Class not match."); return HCF_INVALID_PARAMS; } return ((HcfVerifyImpl *)self)->spiObj->engineInit(((HcfVerifyImpl *)self)->spiObj, params, publicKey); @@ -459,12 +459,12 @@ static HcfResult VerifyInit(HcfVerify *self, HcfParamsSpec *params, HcfPubKey *p static HcfResult VerifyUpdate(HcfVerify *self, HcfBlob *data) { if (self == NULL) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return HCF_INVALID_PARAMS; } if (!HcfIsClassMatch((HcfObjectBase *)self, GetVerifyClass())) { - LOGE("Class not match."); + LOGE_ONE_STR("Class not match."); return HCF_INVALID_PARAMS; } return ((HcfVerifyImpl *)self)->spiObj->engineUpdate(((HcfVerifyImpl *)self)->spiObj, data); @@ -473,11 +473,11 @@ static HcfResult VerifyUpdate(HcfVerify *self, HcfBlob *data) static bool VerifyDoFinal(HcfVerify *self, HcfBlob *data, HcfBlob *signatureData) { if (self == NULL) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return false; } if (!HcfIsClassMatch((HcfObjectBase *)self, GetVerifyClass())) { - LOGE("Class not match."); + LOGE_ONE_STR("Class not match."); return false; } return ((HcfVerifyImpl *)self)->spiObj->engineVerify(((HcfVerifyImpl *)self)->spiObj, data, signatureData); @@ -486,16 +486,16 @@ static bool VerifyDoFinal(HcfVerify *self, HcfBlob *data, HcfBlob *signatureData static HcfResult VerifyRecover(HcfVerify *self, HcfBlob *signatureData, HcfBlob *rawSignatureData) { if (self == NULL) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return HCF_INVALID_PARAMS; } if (!HcfIsClassMatch((HcfObjectBase *)self, GetVerifyClass())) { - LOGE("Class not match."); + LOGE_ONE_STR("Class not match."); return HCF_INVALID_PARAMS; } HcfVerifySpi *verifySpiObj = ((HcfVerifyImpl *)self)->spiObj; if (verifySpiObj->engineRecover == NULL) { - LOGE("Not support verify recover operation."); + LOGE_ONE_STR("Not support verify recover operation."); return HCF_INVALID_PARAMS; } @@ -504,37 +504,37 @@ static HcfResult VerifyRecover(HcfVerify *self, HcfBlob *signatureData, HcfBlob HcfResult HcfSignCreate(const char *algoName, HcfSign **returnObj) { - LOGD("HcfSignCreate start"); + LOGD_ONE_STR("HcfSignCreate start"); if ((!HcfIsStrValid(algoName, HCF_MAX_ALGO_NAME_LEN)) || (returnObj == NULL)) { return HCF_INVALID_PARAMS; } HcfSignatureParams params = { 0 }; if (ParseAndSetParameter(algoName, ¶ms, ParseSignatureParams) != HCF_SUCCESS) { - LOGE("Failed to parse params!"); + LOGE_ONE_STR("Failed to parse params!"); return HCF_INVALID_PARAMS; } HcfSignSpiCreateFunc createSpiFunc = FindSignAbility(¶ms); if (createSpiFunc == NULL) { - LOGE("Can not find ability."); + LOGE_ONE_STR("Can not find ability."); return HCF_NOT_SUPPORT; } HcfSignImpl *returnSign = (HcfSignImpl *)HcfMalloc(sizeof(HcfSignImpl), 0); if (returnSign == NULL) { - LOGE("Failed to allocate returnSign memory!"); + LOGE_ONE_STR("Failed to allocate returnSign memory!"); return HCF_ERR_MALLOC; } if (strcpy_s(returnSign->algoName, HCF_MAX_ALGO_NAME_LEN, algoName) != EOK) { - LOGE("Failed to copy algoName!"); + LOGE_ONE_STR("Failed to copy algoName!"); HcfFree(returnSign); return HCF_INVALID_PARAMS; } HcfSignSpi *spiObj = NULL; HcfResult res = createSpiFunc(¶ms, &spiObj); if (res != HCF_SUCCESS) { - LOGE("Failed to create spi object!"); + LOGE_ONE_STR("Failed to create spi object!"); HcfFree(returnSign); return res; } @@ -551,19 +551,19 @@ HcfResult HcfSignCreate(const char *algoName, HcfSign **returnObj) returnSign->spiObj = spiObj; *returnObj = (HcfSign *)returnSign; - LOGD("HcfSignCreate end"); + LOGD_ONE_STR("HcfSignCreate end"); return HCF_SUCCESS; } HcfResult HcfVerifyCreate(const char *algoName, HcfVerify **returnObj) { - LOGD("HcfVerifyCreate start"); + LOGD_ONE_STR("HcfVerifyCreate start"); if ((!HcfIsStrValid(algoName, HCF_MAX_ALGO_NAME_LEN)) || (returnObj == NULL)) { return HCF_INVALID_PARAMS; } HcfSignatureParams params = {0}; if (ParseAndSetParameter(algoName, ¶ms, ParseSignatureParams) != HCF_SUCCESS) { - LOGE("Failed to parse params!"); + LOGE_ONE_STR("Failed to parse params!"); return HCF_INVALID_PARAMS; } @@ -574,18 +574,18 @@ HcfResult HcfVerifyCreate(const char *algoName, HcfVerify **returnObj) HcfVerifyImpl *returnVerify = (HcfVerifyImpl *)HcfMalloc(sizeof(HcfVerifyImpl), 0); if (returnVerify == NULL) { - LOGE("Failed to allocate returnVerify memory!"); + LOGE_ONE_STR("Failed to allocate returnVerify memory!"); return HCF_ERR_MALLOC; } if (strcpy_s(returnVerify->algoName, HCF_MAX_ALGO_NAME_LEN, algoName) != EOK) { - LOGE("Failed to copy algoName!"); + LOGE_ONE_STR("Failed to copy algoName!"); HcfFree(returnVerify); return HCF_INVALID_PARAMS; } HcfVerifySpi *spiObj = NULL; HcfResult res = createSpiFunc(¶ms, &spiObj); if (res != HCF_SUCCESS) { - LOGE("Failed to create spi object!"); + LOGE_ONE_STR("Failed to create spi object!"); HcfFree(returnVerify); return res; } @@ -602,6 +602,6 @@ HcfResult HcfVerifyCreate(const char *algoName, HcfVerify **returnObj) returnVerify->base.setVerifySpecUint8Array = SetVerifySpecUint8Array; returnVerify->spiObj = spiObj; *returnObj = (HcfVerify *)returnVerify; - LOGD("HcfVerifyCreate end"); + LOGD_ONE_STR("HcfVerifyCreate end"); return HCF_SUCCESS; } diff --git a/frameworks/crypto_operation/sm2_crypto_util.c b/frameworks/crypto_operation/sm2_crypto_util.c index a28cece0b31016348193ac5e23cd3dab407a63f1..4ef2a9f6811a8c6d3913459c8f11355de36d556a 100644 --- a/frameworks/crypto_operation/sm2_crypto_util.c +++ b/frameworks/crypto_operation/sm2_crypto_util.c @@ -57,34 +57,34 @@ static bool CheckMode(const char *mode) return true; } } - LOGE("Invalid param mode"); + LOGE_ONE_STR("Invalid param mode"); return false; } static bool CheckSm2CipherTextSpec(Sm2CipherTextSpec *spec) { if (spec == NULL) { - LOGE("Spec is null"); + LOGE_ONE_STR("Spec is null"); return false; } if ((spec->xCoordinate.data == NULL) || (spec->xCoordinate.len == 0)) { - LOGE("Spec.xCoordinate is null"); + LOGE_ONE_STR("Spec.xCoordinate is null"); return false; } if ((spec->yCoordinate.data == NULL) || (spec->yCoordinate.len == 0)) { - LOGE("Spec.yCoordinate is null"); + LOGE_ONE_STR("Spec.yCoordinate is null"); return false; } if ((spec->hashData.data == NULL) || (spec->hashData.len == 0)) { - LOGE("Spec.hashData is null"); + LOGE_ONE_STR("Spec.hashData is null"); return false; } if ((spec->cipherTextData.data == NULL) || (spec->cipherTextData.len == 0)) { - LOGE("Spec.cipherTextData is null"); + LOGE_ONE_STR("Spec.cipherTextData is null"); return false; } if (spec->hashData.len != HCF_SM2_C3_LEN) { - LOGE("Invalid param hashData"); + LOGE_ONE_STR("Invalid param hashData"); return false; } return true; @@ -93,21 +93,21 @@ static bool CheckSm2CipherTextSpec(Sm2CipherTextSpec *spec) HcfResult HcfGenCipherTextBySpec(Sm2CipherTextSpec *spec, const char *mode, HcfBlob *output) { if (!CheckMode(mode)) { - LOGE("Invalid param mode!"); + LOGE_ONE_STR("Invalid param mode!"); return HCF_INVALID_PARAMS; } if (output == NULL) { - LOGE("Invalid param output!"); + LOGE_ONE_STR("Invalid param output!"); return HCF_INVALID_PARAMS; } if (!CheckSm2CipherTextSpec(spec)) { - LOGE("Invalid param spec!"); + LOGE_ONE_STR("Invalid param spec!"); return HCF_INVALID_PARAMS; } HcfSm2SpecToASN1CreateFunc createFunc = FindAbility(mode); HcfResult res = createFunc(spec, output); if (res != HCF_SUCCESS) { - LOGE("Failed to convert construct to asn1!"); + LOGE_ONE_STR("Failed to convert construct to asn1!"); } return res; } @@ -115,20 +115,20 @@ HcfResult HcfGenCipherTextBySpec(Sm2CipherTextSpec *spec, const char *mode, HcfB HcfResult HcfGetCipherTextSpec(HcfBlob *input, const char *mode, Sm2CipherTextSpec **returnSpc) { if (!CheckMode(mode)) { - LOGE("Invalid param mode!"); + LOGE_ONE_STR("Invalid param mode!"); return HCF_INVALID_PARAMS; } if (input == NULL) { - LOGE("Invalid param input!"); + LOGE_ONE_STR("Invalid param input!"); return HCF_INVALID_PARAMS; } if (returnSpc == NULL) { - LOGE("Invalid param returnSpc!"); + LOGE_ONE_STR("Invalid param returnSpc!"); return HCF_INVALID_PARAMS; } HcfResult res = HcfAsn1ToSm2Spec(input, returnSpc); if (res != HCF_SUCCESS) { - LOGE("Failed to convert asn1 to construct!"); + LOGE_ONE_STR("Failed to convert asn1 to construct!"); return res; } return HCF_SUCCESS; diff --git a/frameworks/js/jsi/src/jsi_md.cpp b/frameworks/js/jsi/src/jsi_md.cpp index 08bf0109bf08833c3d3570fd44319d78a457c510..fdf08863dce53b8a6abd61252ec765938615a2ab 100644 --- a/frameworks/js/jsi/src/jsi_md.cpp +++ b/frameworks/js/jsi/src/jsi_md.cpp @@ -27,12 +27,12 @@ namespace ACELite { JSIValue CryptoFrameworkLiteModule::CreateMd(const JSIValue thisVal, const JSIValue *args, uint8_t argsNum) { if ((args == nullptr) || (argsNum != ARRAY_INDEX_ONE)) { - LOGE("CreateMd args is err!"); + LOGE_ONE_STR("CreateMd args is err!"); return ThrowErrorCodeResult(HCF_INVALID_PARAMS); } char *alg = JSI::ValueToString(args[0]); if (alg == nullptr) { - LOGE("Update alg is null!"); + LOGE_ONE_STR("Update alg is null!"); return ThrowErrorCodeResult(HCF_INVALID_PARAMS); } @@ -69,12 +69,12 @@ JSIValue CryptoFrameworkLiteModule::CreateMd(const JSIValue thisVal, const JSIVa JSIValue CryptoFrameworkLiteModule::Update(const JSIValue thisVal, const JSIValue *args, uint8_t argsNum) { if ((args == nullptr) || (argsNum != ARRAY_MAX_SIZE)) { - LOGE("Update args is null!"); + LOGE_ONE_STR("Update args is null!"); return JSI::CreateUndefined(); } HcfMd *mdObj = reinterpret_cast((uint32_t)JSI::GetNumberProperty(thisVal, "mdObj")); if (mdObj == nullptr) { - LOGE("Update mdObj is null!!"); + LOGE_ONE_STR("Update mdObj is null!!"); CallbackErrorCodeOrDataResult(thisVal, args[ARRAY_INDEX_ONE], HCF_INVALID_PARAMS, JSI::CreateNull()); return JSI::CreateUndefined(); } @@ -83,7 +83,7 @@ JSIValue CryptoFrameworkLiteModule::Update(const JSIValue thisVal, const JSIValu HcfBlob inBlob = { .data = nullptr, .len = 0 }; HcfResult errCode = ParseUint8ArrayToBlob(inVlaue, &inBlob); if (errCode != HCF_SUCCESS) { - LOGE("Update inBlob is null!"); + LOGE_ONE_STR("Update inBlob is null!"); CallbackErrorCodeOrDataResult(thisVal, args[ARRAY_INDEX_ONE], HCF_INVALID_PARAMS, JSI::CreateNull()); return JSI::CreateUndefined(); } @@ -91,7 +91,7 @@ JSIValue CryptoFrameworkLiteModule::Update(const JSIValue thisVal, const JSIValu errCode = mdObj->update(mdObj, &inBlob); HcfBlobDataClearAndFree(&inBlob); if (errCode != HCF_SUCCESS) { - LOGE("Update errCode not is success!"); + LOGE_ONE_STR("Update errCode not is success!"); CallbackErrorCodeOrDataResult(thisVal, args[ARRAY_INDEX_ONE], errCode, JSI::CreateNull()); return JSI::CreateUndefined(); } @@ -103,26 +103,26 @@ JSIValue CryptoFrameworkLiteModule::Update(const JSIValue thisVal, const JSIValu JSIValue CryptoFrameworkLiteModule::UpdateSync(const JSIValue thisVal, const JSIValue *args, uint8_t argsNum) { if ((args == nullptr) || (argsNum != ARRAY_INDEX_ONE)) { - LOGE("UpdateSync args is null!"); + LOGE_ONE_STR("UpdateSync args is null!"); return ThrowErrorCodeResult(HCF_INVALID_PARAMS); } HcfMd *mdObj = reinterpret_cast((uint32_t)JSI::GetNumberProperty(thisVal, "mdObj")); if (mdObj == nullptr) { - LOGE("UpdateSync mdObj is null!!"); + LOGE_ONE_STR("UpdateSync mdObj is null!!"); return ThrowErrorCodeResult(HCF_INVALID_PARAMS); } JSIValue inVlaue = JSI::GetNamedProperty(args[ARRAY_INDEX_ZERO], "data"); HcfBlob inBlob = { .data = nullptr, .len = 0 }; HcfResult errCode = ParseUint8ArrayToBlob(inVlaue, &inBlob); if (errCode != HCF_SUCCESS) { - LOGE("UpdateSync inBlob is null!"); + LOGE_ONE_STR("UpdateSync inBlob is null!"); return ThrowErrorCodeResult(errCode); } errCode = mdObj->update(mdObj, &inBlob); HcfBlobDataClearAndFree(&inBlob); if (errCode != HCF_SUCCESS) { - LOGE("UpdateSync update ret is error!"); + LOGE_ONE_STR("UpdateSync update ret is error!"); } return ThrowErrorCodeResult(errCode); @@ -131,19 +131,19 @@ JSIValue CryptoFrameworkLiteModule::UpdateSync(const JSIValue thisVal, const JSI JSIValue CryptoFrameworkLiteModule::Digest(const JSIValue thisVal, const JSIValue *args, uint8_t argsNum) { if ((args == nullptr) || (argsNum != ARRAY_INDEX_ONE)) { - LOGE("Digest args is err or mdObj nullptr!"); + LOGE_ONE_STR("Digest args is err or mdObj nullptr!"); return JSI::CreateUndefined(); } HcfMd *mdObj = reinterpret_cast((uint32_t)JSI::GetNumberProperty(thisVal, "mdObj")); if (mdObj == nullptr) { - LOGE("Digest mdObj is null!!"); + LOGE_ONE_STR("Digest mdObj is null!!"); CallbackErrorCodeOrDataResult(thisVal, args[ARRAY_INDEX_ONE], HCF_INVALID_PARAMS, JSI::CreateUndefined()); return JSI::CreateUndefined(); } HcfBlob outBlob = { .data = nullptr, .len = 0 }; HcfResult errCode = mdObj->doFinal(mdObj, &outBlob); if (errCode != HCF_SUCCESS) { - LOGE("Digest errCode not is success!"); + LOGE_ONE_STR("Digest errCode not is success!"); HcfBlobDataClearAndFree(&outBlob); CallbackErrorCodeOrDataResult(thisVal, args[ARRAY_INDEX_ONE], errCode, JSI::CreateUndefined()); return JSI::CreateUndefined(); @@ -159,14 +159,14 @@ JSIValue CryptoFrameworkLiteModule::DigestSync(const JSIValue thisVal, const JSI { HcfMd *mdObj = reinterpret_cast((uint32_t)JSI::GetNumberProperty(thisVal, "mdObj")); if (mdObj == nullptr) { - LOGE("DigestSync mdObj is null!!"); + LOGE_ONE_STR("DigestSync mdObj is null!!"); return ThrowErrorCodeResult(HCF_INVALID_PARAMS); } HcfBlob outBlob = { .data = nullptr, .len = 0 }; HcfResult errCode = mdObj->doFinal(mdObj, &outBlob); if (errCode != HCF_SUCCESS) { - LOGE("DigestSync errCode not is success!"); + LOGE_ONE_STR("DigestSync errCode not is success!"); HcfBlobDataClearAndFree(&outBlob); return ThrowErrorCodeResult(errCode); } @@ -181,7 +181,7 @@ JSIValue CryptoFrameworkLiteModule::GetMdLength(const JSIValue thisVal, const JS { HcfMd *mdObj = reinterpret_cast((uint32_t)JSI::GetNumberProperty(thisVal, "mdObj")); if (mdObj == nullptr) { - LOGE("GetMdLength mdObj is null!"); + LOGE_ONE_STR("GetMdLength mdObj is null!"); return ThrowErrorCodeResult(HCF_INVALID_PARAMS); } diff --git a/frameworks/js/jsi/src/jsi_rand.cpp b/frameworks/js/jsi/src/jsi_rand.cpp index 9cb57bb5ce0e7b36baa54a835e6d4943271974ec..28539ec139e9e7a3b53051aa9e4e9bd0f6d81cf8 100644 --- a/frameworks/js/jsi/src/jsi_rand.cpp +++ b/frameworks/js/jsi/src/jsi_rand.cpp @@ -59,27 +59,27 @@ JSIValue CryptoFrameworkLiteModule::CreateRandom(const JSIValue thisVal, const J JSIValue CryptoFrameworkLiteModule::GenerateRandom(const JSIValue thisVal, const JSIValue *args, uint8_t argsNum) { if ((args == nullptr) || (argsNum != ARRAY_MAX_SIZE) || (args[ARRAY_INDEX_ONE] == nullptr)) { - LOGE("GenerateRandom params is err!"); + LOGE_ONE_STR("GenerateRandom params is err!"); return JSI::CreateUndefined(); } HcfRand *randObj = reinterpret_cast((uint32_t)JSI::GetNumberProperty(thisVal, "randObj")); if (randObj == nullptr) { - LOGE("GenerateRandom randObj is null!"); + LOGE_ONE_STR("GenerateRandom randObj is null!"); CallbackErrorCodeOrDataResult(thisVal, args[ARRAY_INDEX_ONE], HCF_INVALID_PARAMS, JSI::CreateUndefined()); return JSI::CreateUndefined(); } int32_t numBytes = (int32_t)JSI::ValueToNumber(args[0]); if (numBytes <= 0) { - LOGE("GenerateRandom numBytes too small!"); + LOGE_ONE_STR("GenerateRandom numBytes too small!"); CallbackErrorCodeOrDataResult(thisVal, args[ARRAY_INDEX_ONE], HCF_INVALID_PARAMS, JSI::CreateUndefined()); return JSI::CreateUndefined(); } HcfBlob randBlob = { .data = nullptr, .len = 0 }; HcfResult res = randObj->generateRandom(randObj, numBytes, &randBlob); if (res != HCF_SUCCESS) { - LOGE("GenerateRandom randObj not is success!"); + LOGE_ONE_STR("GenerateRandom randObj not is success!"); CallbackErrorCodeOrDataResult(thisVal, args[ARRAY_INDEX_ONE], res, JSI::CreateUndefined()); return JSI::CreateUndefined(); } @@ -94,25 +94,25 @@ JSIValue CryptoFrameworkLiteModule::GenerateRandom(const JSIValue thisVal, const JSIValue CryptoFrameworkLiteModule::GenerateRandomSync(const JSIValue thisVal, const JSIValue *args, uint8_t argsNum) { if ((args == nullptr) || (argsNum != ARRAY_INDEX_ONE)) { - LOGE("GenerateRandomSync params is err"); + LOGE_ONE_STR("GenerateRandomSync params is err"); return ThrowErrorCodeResult(HCF_INVALID_PARAMS); } HcfRand *randObj = reinterpret_cast((uint32_t)JSI::GetNumberProperty(thisVal, "randObj")); if (randObj == nullptr) { - LOGE("GenerateRandom randObj is null!!"); + LOGE_ONE_STR("GenerateRandom randObj is null!!"); return ThrowErrorCodeResult(HCF_INVALID_PARAMS); } int32_t numBytes = (int32_t)JSI::ValueToNumber(args[0]); if (numBytes <= 0) { - LOGE("GenerateRandomSync numBytes too small!"); + LOGE_ONE_STR("GenerateRandomSync numBytes too small!"); return ThrowErrorCodeResult(HCF_INVALID_PARAMS); } HcfBlob randBlob = { .data = nullptr, .len = 0 }; HcfResult res = randObj->generateRandom(randObj, numBytes, &randBlob); if (res != HCF_SUCCESS) { - LOGE("GenerateRandomSync randObj not is success!"); + LOGE_ONE_STR("GenerateRandomSync randObj not is success!"); HcfBlobDataClearAndFree(&randBlob); return ThrowErrorCodeResult(res); } @@ -126,25 +126,25 @@ JSIValue CryptoFrameworkLiteModule::SetSeed(const JSIValue thisVal, const JSIVal { HcfRand *randObj = reinterpret_cast((uint32_t)JSI::GetNumberProperty(thisVal, "randObj")); if (randObj == nullptr) { - LOGE("SetSeed randObj is null!!"); + LOGE_ONE_STR("SetSeed randObj is null!!"); return ThrowErrorCodeResult(HCF_INVALID_PARAMS); } if ((args == nullptr) || (argsNum != ARRAY_INDEX_ONE)) { - LOGE("SetSeed params is null"); + LOGE_ONE_STR("SetSeed params is null"); return ThrowErrorCodeResult(HCF_INVALID_PARAMS); } JSIValue inVlaue = JSI::GetNamedProperty(args[ARRAY_INDEX_ZERO], "data"); HcfBlob seedBlob = { .data = nullptr, .len = 0 }; HcfResult errCode = ParseUint8ArrayToBlob(inVlaue, &seedBlob); if (errCode != HCF_SUCCESS) { - LOGE("SetSeed seedBlob is null!"); + LOGE_ONE_STR("SetSeed seedBlob is null!"); return ThrowErrorCodeResult(HCF_ERR_MALLOC); } HcfResult res = randObj->setSeed(randObj, &seedBlob); HcfBlobDataClearAndFree(&seedBlob); if (res != HCF_SUCCESS) { - LOGE("setSeed randObj not is success!"); + LOGE_ONE_STR("setSeed randObj not is success!"); return ThrowErrorCodeResult(res); } diff --git a/frameworks/js/jsi/src/jsi_utils.cpp b/frameworks/js/jsi/src/jsi_utils.cpp index 3320f1d296d54e466a77a76676b830e3c7d91c72..2c549499f62013d6d22002157a160176e5dd175a 100644 --- a/frameworks/js/jsi/src/jsi_utils.cpp +++ b/frameworks/js/jsi/src/jsi_utils.cpp @@ -27,7 +27,7 @@ namespace ACELite { HcfResult ParseUint8ArrayToBlob(JSIValue value, HcfBlob *blob) { if (!JSI::ValueIsTypedArray(value) || (blob == nullptr)) { - LOGE("value is not a typed array!"); + LOGE_ONE_STR("value is not a typed array!"); return HCF_INVALID_PARAMS; } TypedArrayType arrayType; @@ -42,7 +42,7 @@ HcfResult ParseUint8ArrayToBlob(JSIValue value, HcfBlob *blob) break; } if (arrayType != TypedArrayType::JSI_UINT8_ARRAY) { - LOGE("value is not a uint8 array"); + LOGE_ONE_STR("value is not a uint8 array"); ret = HCF_INVALID_PARAMS; break; } @@ -73,7 +73,7 @@ JSIValue ConstructJSIReturnResult(const HcfBlob *blob) uint8_t *arrayBuffer = nullptr; JSIValue buffer = JSI::CreateArrayBuffer(blob->len, arrayBuffer); if (arrayBuffer == nullptr) { - LOGE("create jsi array buffer failed"); + LOGE_ONE_STR("create jsi array buffer failed"); JSI::ReleaseValue(buffer); return res; } diff --git a/frameworks/js/napi/crypto/src/napi_asy_key_generator.cpp b/frameworks/js/napi/crypto/src/napi_asy_key_generator.cpp index 507da11dd97165a56f0ff2f32066fdce7ac0a262..77bca522e218ec2af369d7b4a25808fd1f7faf7e 100644 --- a/frameworks/js/napi/crypto/src/napi_asy_key_generator.cpp +++ b/frameworks/js/napi/crypto/src/napi_asy_key_generator.cpp @@ -191,7 +191,7 @@ static bool BuildGenKeyPairCtx(napi_env env, napi_callback_info info, GenKeyPair NapiAsyKeyGenerator *napiGenerator = nullptr; napi_status status = napi_unwrap(env, thisVar, reinterpret_cast(&napiGenerator)); if (status != napi_ok || napiGenerator == nullptr) { - LOGE("failed to unwrap napi asyKeyGenerator obj."); + LOGE_ONE_STR("failed to unwrap napi asyKeyGenerator obj."); return false; } @@ -199,7 +199,7 @@ static bool BuildGenKeyPairCtx(napi_env env, napi_callback_info info, GenKeyPair ctx->params = nullptr; if (napi_create_reference(env, thisVar, 1, &ctx->generatorRef) != napi_ok) { - LOGE("create generator ref failed generator key pair!"); + LOGE_ONE_STR("create generator ref failed generator key pair!"); return false; } @@ -220,7 +220,7 @@ static bool GetPkAndSkBlobFromNapiValueIfInput(napi_env env, napi_value pkValue, if (valueType != napi_null) { pubKey = GetBlobFromNapiDataBlob(env, pkValue); if (pubKey == nullptr) { - LOGE("failed to get pubKey."); + LOGE_ONE_STR("failed to get pubKey."); return false; } } @@ -233,7 +233,7 @@ static bool GetPkAndSkBlobFromNapiValueIfInput(napi_env env, napi_value pkValue, // if the prikey get func fails, the return pointer will not take the ownership of pubkey and not free it. HcfBlobDataFree(pubKey); HcfFree(pubKey); - LOGE("failed to get priKey."); + LOGE_ONE_STR("failed to get priKey."); return false; } } @@ -252,38 +252,38 @@ static bool GetPkAndSkStringFromNapiValueIfInput(napi_env env, napi_value pkValu napi_typeof(env, pkValue, &valueTypePk); napi_typeof(env, skValue, &valueTypeSk); if (valueTypePk == napi_null && valueTypeSk == napi_null) { - LOGE("valueTypePk and valueTypeSk is all null."); + LOGE_ONE_STR("valueTypePk and valueTypeSk is all null."); return false; } if (valueTypePk != napi_null) { if (valueTypePk != napi_string) { - LOGE("valueTypePk wrong argument type, expect string type."); + LOGE_ONE_STR("valueTypePk wrong argument type, expect string type."); return false; } if (napi_get_value_string_utf8(env, pkValue, nullptr, 0, &length) != napi_ok) { - LOGE("pkValue can not get string length."); + LOGE_ONE_STR("pkValue can not get string length."); return false; } returnPubKey.reserve(length + 1); returnPubKey.resize(length); if (napi_get_value_string_utf8(env, pkValue, returnPubKey.data(), (length + 1), &length) != napi_ok) { - LOGE("pkValue can not get string value."); + LOGE_ONE_STR("pkValue can not get string value."); return false; } } if (valueTypeSk != napi_null) { if (valueTypeSk != napi_string) { - LOGE("valueTypeSk wrong argument type. expect string type."); + LOGE_ONE_STR("valueTypeSk wrong argument type. expect string type."); return false; } if (napi_get_value_string_utf8(env, skValue, nullptr, 0, &length) != napi_ok) { - LOGE("skValue can not get string length."); + LOGE_ONE_STR("skValue can not get string length."); return false; } returnPriKey.reserve(length + 1); returnPriKey.resize(length); if (napi_get_value_string_utf8(env, skValue, returnPriKey.data(), (length + 1), &length) != napi_ok) { - LOGE("skValue can not get string value."); + LOGE_ONE_STR("skValue can not get string value."); return false; } } @@ -306,7 +306,7 @@ static bool BuildConvertKeyCtx(napi_env env, napi_callback_info info, ConvertKey NapiAsyKeyGenerator *napiGenerator = nullptr; napi_status status = napi_unwrap(env, thisVar, reinterpret_cast(&napiGenerator)); if (status != napi_ok || napiGenerator == nullptr) { - LOGE("failed to unwrap napi asyKeyGenerator obj."); + LOGE_ONE_STR("failed to unwrap napi asyKeyGenerator obj."); return false; } @@ -322,7 +322,7 @@ static bool BuildConvertKeyCtx(napi_env env, napi_callback_info info, ConvertKey ctx->priKey = priKey; if (napi_create_reference(env, thisVar, 1, &ctx->generatorRef) != napi_ok) { - LOGE("create generator ref failed when convert asym key!"); + LOGE_ONE_STR("create generator ref failed when convert asym key!"); return false; } @@ -349,14 +349,14 @@ static bool ValidateAndGetParams(napi_env env, napi_callback_info info, std::str } if (!GetPkAndSkStringFromNapiValueIfInput(env, argv[PARAM0], argv[PARAM1], pubKey, priKey)) { - LOGE("GetPkAndSkStringFromNapiValueIfInput failed."); + LOGE_ONE_STR("GetPkAndSkStringFromNapiValueIfInput failed."); napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "GetPkAndSkStringFromNapiValueIfInput failed.")); return false; } if (argc == expectedArgc) { if (!GetDecodingParamsSpec(env, argv[PARAM2], paramsSpec)) { - LOGE("get params failed!"); + LOGE_ONE_STR("get params failed!"); napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "get napi paramsSpec failed!")); return false; } @@ -377,7 +377,7 @@ static bool BuildConvertPemKeyCtx(napi_env env, napi_callback_info info, Convert NapiAsyKeyGenerator *napiGenerator = nullptr; napi_status status = napi_unwrap(env, thisVar, reinterpret_cast(&napiGenerator)); if (status != napi_ok || napiGenerator == nullptr) { - LOGE("failed to unwrap napi asyKeyGenerator obj."); + LOGE_ONE_STR("failed to unwrap napi asyKeyGenerator obj."); return false; } @@ -386,7 +386,7 @@ static bool BuildConvertPemKeyCtx(napi_env env, napi_callback_info info, Convert ctx->pubKey = pubKey; ctx->priKey = priKey; if (napi_create_reference(env, thisVar, 1, &ctx->generatorRef) != napi_ok) { - LOGE("create generator ref failed when convert pem asym key!"); + LOGE_ONE_STR("create generator ref failed when convert pem asym key!"); return false; } napi_create_promise(env, &ctx->deferred, &ctx->promise); @@ -465,7 +465,7 @@ static void GenKeyPairAsyncWorkProcess(napi_env env, void *data) ctx->errCode = ctx->generator->generateKeyPair(ctx->generator, ctx->params, &(ctx->returnKeyPair)); if (ctx->errCode != HCF_SUCCESS) { - LOGD("[error] generate key pair fail."); + LOGD_ONE_STR("[error] generate key pair fail."); ctx->errMsg = "generate key pair fail."; } } @@ -479,7 +479,7 @@ static void GenKeyPairAsyncWorkReturn(napi_env env, napi_status status, void *da NapiKeyPair *napiKeyPair = new (std::nothrow) NapiKeyPair(ctx->returnKeyPair); if (napiKeyPair == nullptr) { napi_throw(env, GenerateBusinessError(env, HCF_ERR_MALLOC, "new napi key pair failed!")); - LOGE("new napi key pair failed"); + LOGE_ONE_STR("new napi key pair failed"); FreeGenKeyPairCtx(env, ctx); return; } @@ -493,7 +493,7 @@ static void GenKeyPairAsyncWorkReturn(napi_env env, napi_status status, void *da return; }, nullptr, nullptr); if (ret != napi_ok) { - LOGE("failed to wrap napiKeyPair obj!"); + LOGE_ONE_STR("failed to wrap napiKeyPair obj!"); ctx->errCode = HCF_INVALID_PARAMS; ctx->errMsg = "failed to wrap napiKeyPair obj!"; delete napiKeyPair; @@ -515,7 +515,7 @@ static void ConvertKeyAsyncWorkProcess(napi_env env, void *data) ctx->errCode = ctx->generator->convertKey(ctx->generator, ctx->params, ctx->pubKey, ctx->priKey, &(ctx->returnKeyPair)); if (ctx->errCode != HCF_SUCCESS) { - LOGD("[error] convert key fail."); + LOGD_ONE_STR("[error] convert key fail."); ctx->errMsg = "convert key fail."; } } @@ -526,7 +526,7 @@ static void ConvertPemKeyAsyncWorkProcess(napi_env env, void *data) ctx->errCode = ctx->generator->convertPemKey(ctx->generator, ctx->params, ctx->pubKey.c_str(), ctx->priKey.c_str(), &(ctx->returnKeyPair)); if (ctx->errCode != HCF_SUCCESS) { - LOGE("ConvertPemKey fail."); + LOGE_ONE_STR("ConvertPemKey fail."); ctx->errMsg = "ConvertPemKey fail."; } } @@ -540,7 +540,7 @@ static void ConvertKeyAsyncWorkReturn(napi_env env, napi_status status, void *da NapiKeyPair *napiKeyPair = new (std::nothrow) NapiKeyPair(ctx->returnKeyPair); if (napiKeyPair == nullptr) { napi_throw(env, GenerateBusinessError(env, HCF_ERR_MALLOC, "new napi key pair failed!")); - LOGE("new napi key pair failed"); + LOGE_ONE_STR("new napi key pair failed"); FreeConvertKeyCtx(env, ctx); return; } @@ -554,7 +554,7 @@ static void ConvertKeyAsyncWorkReturn(napi_env env, napi_status status, void *da return; }, nullptr, nullptr); if (ret != napi_ok) { - LOGE("failed to wrap napiKeyPair obj!"); + LOGE_ONE_STR("failed to wrap napiKeyPair obj!"); ctx->errCode = HCF_INVALID_PARAMS; ctx->errMsg = "failed to wrap napiKeyPair obj!"; delete napiKeyPair; @@ -577,7 +577,7 @@ static void ConvertPemKeyAsyncWorkReturn(napi_env env, napi_status status, void if (ctx->errCode == HCF_SUCCESS) { NapiKeyPair *napiKeyPair = new (std::nothrow) NapiKeyPair(ctx->returnKeyPair); if (napiKeyPair == nullptr) { - LOGE("new napi key pair failed."); + LOGE_ONE_STR("new napi key pair failed."); napi_throw(env, GenerateBusinessError(env, HCF_ERR_MALLOC, "new napi key pair failed!")); HcfObjDestroy(ctx->returnKeyPair); ctx->returnKeyPair = nullptr; @@ -594,7 +594,7 @@ static void ConvertPemKeyAsyncWorkReturn(napi_env env, napi_status status, void return; }, nullptr, nullptr); if (ret != napi_ok) { - LOGE("failed to wrap napiKeyPair obj!"); + LOGE_ONE_STR("failed to wrap napiKeyPair obj!"); ctx->errCode = HCF_INVALID_PARAMS; ctx->errMsg = "failed to wrap napiKeyPair obj!"; ctx->returnKeyPair = nullptr; @@ -699,13 +699,13 @@ napi_value NapiAsyKeyGenerator::JsGenerateKeyPair(napi_env env, napi_callback_in GenKeyPairCtx *ctx = static_cast(HcfMalloc(sizeof(GenKeyPairCtx), 0)); if (ctx == nullptr) { napi_throw(env, GenerateBusinessError(env, HCF_ERR_MALLOC, "malloc ctx fail.")); - LOGE("create context fail."); + LOGE_ONE_STR("create context fail."); return nullptr; } if (!BuildGenKeyPairCtx(env, info, ctx)) { napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "build context fail.")); - LOGE("build context fail."); + LOGE_ONE_STR("build context fail."); FreeGenKeyPairCtx(env, ctx); return nullptr; } @@ -718,7 +718,7 @@ static bool GetHcfKeyPairInstance(napi_env env, HcfKeyPair *returnKeyPair, napi_ NapiKeyPair *napiKeyPair = new (std::nothrow) NapiKeyPair(returnKeyPair); if (napiKeyPair == nullptr) { HcfObjDestroy(returnKeyPair); - LOGE("new napi key pair failed"); + LOGE_ONE_STR("new napi key pair failed"); return false; } @@ -731,7 +731,7 @@ static bool GetHcfKeyPairInstance(napi_env env, HcfKeyPair *returnKeyPair, napi_ return; }, nullptr, nullptr); if (ret != napi_ok) { - LOGE("failed to wrap napiKeyPair obj!"); + LOGE_ONE_STR("failed to wrap napiKeyPair obj!"); delete napiKeyPair; return false; } @@ -747,14 +747,14 @@ napi_value NapiAsyKeyGenerator::JsGenerateKeyPairSync(napi_env env, napi_callbac NapiAsyKeyGenerator *napiGenerator = nullptr; napi_status status = napi_unwrap(env, thisVar, reinterpret_cast(&napiGenerator)); if (status != napi_ok || napiGenerator == nullptr) { - LOGE("failed to unwrap napi asyKeyGenerator obj."); + LOGE_ONE_STR("failed to unwrap napi asyKeyGenerator obj."); napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "failed to unwrap napi asyKeyGenerator obj.")); return nullptr; } HcfAsyKeyGenerator *generator = napiGenerator->GetAsyKeyGenerator(); if (generator == nullptr) { - LOGE("get generator fail."); + LOGE_ONE_STR("get generator fail."); napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "get generator fail!")); return nullptr; } @@ -763,14 +763,14 @@ napi_value NapiAsyKeyGenerator::JsGenerateKeyPairSync(napi_env env, napi_callbac HcfKeyPair *returnKeyPair = nullptr; HcfResult errCode = generator->generateKeyPair(generator, params, &returnKeyPair); if (errCode != HCF_SUCCESS) { - LOGE("generate key pair fail."); + LOGE_ONE_STR("generate key pair fail."); napi_throw(env, GenerateBusinessError(env, errCode, "generate key pair fail.")); return nullptr; } napi_value instance = nullptr; if (!GetHcfKeyPairInstance(env, returnKeyPair, &instance)) { - LOGE("failed to get generate key pair instance!"); + LOGE_ONE_STR("failed to get generate key pair instance!"); napi_throw(env, GenerateBusinessError(env, HCF_ERR_MALLOC, "failed to get generate key pair instance!")); return nullptr; } @@ -782,13 +782,13 @@ napi_value NapiAsyKeyGenerator::JsConvertKey(napi_env env, napi_callback_info in ConvertKeyCtx *ctx = static_cast(HcfMalloc(sizeof(ConvertKeyCtx), 0)); if (ctx == nullptr) { napi_throw(env, GenerateBusinessError(env, HCF_ERR_MALLOC, "create context fail!")); - LOGE("create context fail."); + LOGE_ONE_STR("create context fail."); return nullptr; } if (!BuildConvertKeyCtx(env, info, ctx)) { napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "build context fail.")); - LOGE("build context fail."); + LOGE_ONE_STR("build context fail."); FreeConvertKeyCtx(env, ctx); return nullptr; } @@ -819,7 +819,7 @@ napi_value NapiAsyKeyGenerator::JsConvertKeySync(napi_env env, napi_callback_inf NapiAsyKeyGenerator *napiGenerator = nullptr; napi_status status = napi_unwrap(env, thisVar, reinterpret_cast(&napiGenerator)); if (status != napi_ok || napiGenerator == nullptr) { - LOGE("failed to unwrap napi asyKeyGenerator obj."); + LOGE_ONE_STR("failed to unwrap napi asyKeyGenerator obj."); napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "failed to unwrap napi asyKeyGenerator obj.")); return nullptr; } @@ -827,7 +827,7 @@ napi_value NapiAsyKeyGenerator::JsConvertKeySync(napi_env env, napi_callback_inf HcfBlob *pubKey = nullptr; HcfBlob *priKey = nullptr; if (!GetPkAndSkBlobFromNapiValueIfInput(env, argv[PARAM0], argv[PARAM1], &pubKey, &priKey)) { - LOGE("failed to unwrap napi asyKeyGenerator obj."); + LOGE_ONE_STR("failed to unwrap napi asyKeyGenerator obj."); napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "failed to unwrap napi asyKeyGenerator obj.")); return nullptr; } @@ -835,7 +835,7 @@ napi_value NapiAsyKeyGenerator::JsConvertKeySync(napi_env env, napi_callback_inf HcfAsyKeyGenerator *generator = napiGenerator->GetAsyKeyGenerator(); if (generator == nullptr) { HcfFreePubKeyAndPriKey(pubKey, priKey); - LOGE("get generator fail."); + LOGE_ONE_STR("get generator fail."); napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "get generator fail!")); return nullptr; } @@ -845,14 +845,14 @@ napi_value NapiAsyKeyGenerator::JsConvertKeySync(napi_env env, napi_callback_inf HcfResult errCode = generator->convertKey(generator, params, pubKey, priKey, &(returnKeyPair)); HcfFreePubKeyAndPriKey(pubKey, priKey); if (errCode != HCF_SUCCESS) { - LOGE("convert key fail."); + LOGE_ONE_STR("convert key fail."); napi_throw(env, GenerateBusinessError(env, errCode, "convert key fail.")); return nullptr; } napi_value instance = nullptr; if (!GetHcfKeyPairInstance(env, returnKeyPair, &instance)) { - LOGE("failed to get convert key instance!"); + LOGE_ONE_STR("failed to get convert key instance!"); napi_throw(env, GenerateBusinessError(env, HCF_ERR_MALLOC, "failed to get convert key instance!")); return nullptr; } @@ -864,12 +864,12 @@ napi_value NapiAsyKeyGenerator::JsConvertPemKey(napi_env env, napi_callback_info { ConvertPemKeyCtx *ctx = static_cast(HcfMalloc(sizeof(ConvertPemKeyCtx), 0)); if (ctx == nullptr) { - LOGE("create context fail."); + LOGE_ONE_STR("create context fail."); napi_throw(env, GenerateBusinessError(env, HCF_ERR_MALLOC, "create context fail!")); return nullptr; } if (!BuildConvertPemKeyCtx(env, info, ctx)) { - LOGE("build context fail."); + LOGE_ONE_STR("build context fail."); napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "build context fail.")); FreeConvertPemKeyCtx(env, ctx); return nullptr; @@ -883,7 +883,7 @@ static HcfResult ConvertPemKeySync(std::string &pubKey, std::string &priKey, Hc HcfResult errCode = generator->convertPemKey(generator, paramsSpec, pubKey.c_str(), priKey.c_str(), returnKeyPair); if (errCode != HCF_SUCCESS) { - LOGE("convertPemKey error!"); + LOGE_ONE_STR("convertPemKey error!"); return errCode; } return HCF_SUCCESS; @@ -906,7 +906,7 @@ napi_value NapiAsyKeyGenerator::JsConvertPemKeySync(napi_env env, napi_callback_ napi_status status = napi_unwrap(env, thisVar, reinterpret_cast(&napiGenerator)); if (status != napi_ok || napiGenerator == nullptr) { FreeDecodeParamsSpec(paramsSpec); - LOGE("failed to unwrap napi asyKeyGenerator obj."); + LOGE_ONE_STR("failed to unwrap napi asyKeyGenerator obj."); napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "failed to unwrap napi asyKeyGenerator obj.")); return nullptr; } @@ -914,7 +914,7 @@ napi_value NapiAsyKeyGenerator::JsConvertPemKeySync(napi_env env, napi_callback_ HcfAsyKeyGenerator *generator = napiGenerator->GetAsyKeyGenerator(); if (generator == nullptr) { FreeDecodeParamsSpec(paramsSpec); - LOGE("GetAsyKeyGenerator failed!"); + LOGE_ONE_STR("GetAsyKeyGenerator failed!"); napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "GetAsyKeyGenerator failed!")); return nullptr; } @@ -923,7 +923,7 @@ napi_value NapiAsyKeyGenerator::JsConvertPemKeySync(napi_env env, napi_callback_ HcfResult errCode = ConvertPemKeySync(pubKey, priKey, generator, paramsSpec, &(returnKeyPair)); if (errCode != HCF_SUCCESS) { FreeDecodeParamsSpec(paramsSpec); - LOGE("ConvertPemKeySync error!"); + LOGE_ONE_STR("ConvertPemKeySync error!"); napi_throw(env, GenerateBusinessError(env, errCode, "ConvertPemKeySync error!")); return nullptr; } @@ -931,7 +931,7 @@ napi_value NapiAsyKeyGenerator::JsConvertPemKeySync(napi_env env, napi_callback_ NapiKeyPair *napiKeyPair = new (std::nothrow) NapiKeyPair(returnKeyPair); if (napiKeyPair == nullptr) { FreeDecodeParamsSpec(paramsSpec); - LOGE("new napi key pair failed"); + LOGE_ONE_STR("new napi key pair failed"); napi_throw(env, GenerateBusinessError(env, HCF_ERR_MALLOC, "malloc context failed.")); HcfObjDestroy(returnKeyPair); returnKeyPair = nullptr; @@ -963,7 +963,7 @@ static napi_value NapiWrapAsyKeyGen(napi_env env, napi_value instance, NapiAsyKe napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "failed to wrap napiAsyKeyGenerator obj!")); delete napiAsyKeyGenerator; napiAsyKeyGenerator = nullptr; - LOGE("failed to wrap napiAsyKeyGenerator obj!"); + LOGE_ONE_STR("failed to wrap napiAsyKeyGenerator obj!"); return nullptr; } return instance; @@ -977,7 +977,7 @@ napi_value NapiAsyKeyGenerator::CreateJsAsyKeyGenerator(napi_env env, napi_callb napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr); if (argc != expectedArgc) { napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "The input args num is invalid.")); - LOGE("The input args num is invalid."); + LOGE_ONE_STR("The input args num is invalid."); return NapiGetNull(env); } @@ -989,7 +989,7 @@ napi_value NapiAsyKeyGenerator::CreateJsAsyKeyGenerator(napi_env env, napi_callb std::string algName; if (!GetStringFromJSParams(env, argv[0], algName)) { napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "failed to get algoName.")); - LOGE("failed to get algoName."); + LOGE_ONE_STR("failed to get algoName."); return NapiGetNull(env); } @@ -997,14 +997,14 @@ napi_value NapiAsyKeyGenerator::CreateJsAsyKeyGenerator(napi_env env, napi_callb HcfResult res = HcfAsyKeyGeneratorCreate(algName.c_str(), &generator); if (res != HCF_SUCCESS) { napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "create c generator fail.")); - LOGE("create c generator fail."); + LOGE_ONE_STR("create c generator fail."); return NapiGetNull(env); } NapiAsyKeyGenerator *napiAsyKeyGenerator = new (std::nothrow) NapiAsyKeyGenerator(generator); if (napiAsyKeyGenerator == nullptr) { napi_throw(env, GenerateBusinessError(env, HCF_ERR_MALLOC, "new napi asy key napi generator failed!")); - LOGE("new napi asy key napi generator failed"); + LOGE_ONE_STR("new napi asy key napi generator failed"); HcfObjDestroy(generator); return NapiGetNull(env); } diff --git a/frameworks/js/napi/crypto/src/napi_asy_key_spec_generator.cpp b/frameworks/js/napi/crypto/src/napi_asy_key_spec_generator.cpp index 442c3289aa599540d51705f2564cc361bd44e284..ec89577df3aad37ca23846c75e00ae4eb6a815f1 100644 --- a/frameworks/js/napi/crypto/src/napi_asy_key_spec_generator.cpp +++ b/frameworks/js/napi/crypto/src/napi_asy_key_spec_generator.cpp @@ -88,13 +88,13 @@ static bool BuildAsyKeyCtx(napi_env env, napi_callback_info info, AsyKeyCtx *ctx NapiAsyKeyGeneratorBySpec *napiGenerator = nullptr; napi_status status = napi_unwrap(env, thisVar, reinterpret_cast(&napiGenerator)); if (status != napi_ok || napiGenerator == nullptr) { - LOGE("failed to unwrap napi asyKeyGenerator obj."); + LOGE_ONE_STR("failed to unwrap napi asyKeyGenerator obj."); return false; } ctx->generator = napiGenerator->GetAsyKeyGeneratorBySpec(); if (napi_create_reference(env, thisVar, 1, &ctx->generatorRef) != napi_ok) { - LOGE("create generator ref failed when generator asym key by spec!"); + LOGE_ONE_STR("create generator ref failed when generator asym key by spec!"); return false; } @@ -114,7 +114,7 @@ static bool GetAsyKeyGenerator(napi_env env, napi_callback_info info, HcfAsyKeyG NapiAsyKeyGeneratorBySpec *napiGenerator = nullptr; napi_status status = napi_unwrap(env, thisVar, reinterpret_cast(&napiGenerator)); if (status != napi_ok || napiGenerator == nullptr) { - LOGE("failed to unwrap napi asyKeyGenerator obj."); + LOGE_ONE_STR("failed to unwrap napi asyKeyGenerator obj."); return false; } *generator = napiGenerator->GetAsyKeyGeneratorBySpec(); @@ -155,7 +155,7 @@ static void GenKeyPairAsyncWorkProcess(napi_env env, void *data) ctx->errCode = ctx->generator->generateKeyPair(ctx->generator, &(ctx->returnKeyPair)); if (ctx->errCode != HCF_SUCCESS) { - LOGD("[error] generate key pair fail."); + LOGD_ONE_STR("[error] generate key pair fail."); ctx->errMsg = "generate key pair fail."; } } @@ -169,7 +169,7 @@ static void GenKeyPairAsyncWorkReturn(napi_env env, napi_status status, void *da NapiKeyPair *napiKeyPair = new (std::nothrow) NapiKeyPair(ctx->returnKeyPair); if (napiKeyPair == nullptr) { napi_throw(env, GenerateBusinessError(env, HCF_ERR_MALLOC, "new napi key pair failed!")); - LOGE("new napi key pair failed"); + LOGE_ONE_STR("new napi key pair failed"); HcfObjDestroy(ctx->returnKeyPair); FreeAsyKeyCtx(env, ctx); return; @@ -184,7 +184,7 @@ static void GenKeyPairAsyncWorkReturn(napi_env env, napi_status status, void *da return; }, nullptr, nullptr); if (ret != napi_ok) { - LOGE("failed to wrap napiKeyPair obj!"); + LOGE_ONE_STR("failed to wrap napiKeyPair obj!"); ctx->errCode = HCF_INVALID_PARAMS; ctx->errMsg = "failed to wrap napiKeyPair obj!"; delete napiKeyPair; @@ -205,7 +205,7 @@ static void PubKeyAsyncWorkProcess(napi_env env, void *data) ctx->errCode = ctx->generator->generatePubKey(ctx->generator, &(ctx->returnPubKey)); if (ctx->errCode != HCF_SUCCESS) { - LOGD("[error] generate PubKey fail."); + LOGD_ONE_STR("[error] generate PubKey fail."); ctx->errMsg = "generate PubKey fail."; } } @@ -219,7 +219,7 @@ static void PubKeyAsyncWorkReturn(napi_env env, napi_status status, void *data) NapiPubKey *napiPubKey = new (std::nothrow) NapiPubKey(ctx->returnPubKey); if (napiPubKey == nullptr) { napi_throw(env, GenerateBusinessError(env, HCF_ERR_MALLOC, "new napi pub key failed!")); - LOGE("new napi pub key failed"); + LOGE_ONE_STR("new napi pub key failed"); HcfObjDestroy(ctx->returnPubKey); FreeAsyKeyCtx(env, ctx); return; @@ -235,7 +235,7 @@ static void PubKeyAsyncWorkReturn(napi_env env, napi_status status, void *data) return; }, nullptr, nullptr); if (ret != napi_ok) { - LOGE("failed to wrap napiPubKey obj!"); + LOGE_ONE_STR("failed to wrap napiPubKey obj!"); ctx->errCode = HCF_INVALID_PARAMS; ctx->errMsg = "failed to wrap napiPubKey obj!"; HcfObjDestroy(napiPubKey->GetPubKey()); @@ -257,7 +257,7 @@ static void PriKeyAsyncWorkProcess(napi_env env, void *data) ctx->errCode = ctx->generator->generatePriKey(ctx->generator, &(ctx->returnPriKey)); if (ctx->errCode != HCF_SUCCESS) { - LOGD("[error] generate PriKey fail."); + LOGD_ONE_STR("[error] generate PriKey fail."); ctx->errMsg = "generate PriKey fail."; } } @@ -271,7 +271,7 @@ static void PriKeyAsyncWorkReturn(napi_env env, napi_status status, void *data) NapiPriKey *napiPriKey = new (std::nothrow) NapiPriKey(ctx->returnPriKey); if (napiPriKey == nullptr) { napi_throw(env, GenerateBusinessError(env, HCF_ERR_MALLOC, "new napi pri key failed!")); - LOGE("new napi pri key failed"); + LOGE_ONE_STR("new napi pri key failed"); HcfObjDestroy(ctx->returnPriKey); FreeAsyKeyCtx(env, ctx); return; @@ -287,7 +287,7 @@ static void PriKeyAsyncWorkReturn(napi_env env, napi_status status, void *data) return; }, nullptr, nullptr); if (ret != napi_ok) { - LOGE("failed to wrap napiPriKey obj!"); + LOGE_ONE_STR("failed to wrap napiPriKey obj!"); ctx->errCode = HCF_INVALID_PARAMS; ctx->errMsg = "failed to wrap napiPriKey obj!"; HcfObjDestroy(napiPriKey->GetPriKey()); @@ -401,13 +401,13 @@ napi_value NapiAsyKeyGeneratorBySpec::JsGenerateKeyPair(napi_env env, napi_callb AsyKeyCtx *ctx = static_cast(HcfMalloc(sizeof(AsyKeyCtx), 0)); if (ctx == nullptr) { napi_throw(env, GenerateBusinessError(env, HCF_ERR_MALLOC, "create context fail!")); - LOGE("create context fail."); + LOGE_ONE_STR("create context fail."); return nullptr; } if (!BuildAsyKeyCtx(env, info, ctx)) { napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "build context fail!")); - LOGE("build context fail."); + LOGE_ONE_STR("build context fail."); FreeAsyKeyCtx(env, ctx); return nullptr; } @@ -419,7 +419,7 @@ napi_value NapiAsyKeyGeneratorBySpec::JsGenerateKeyPairSync(napi_env env, napi_c { HcfAsyKeyGeneratorBySpec *generator = nullptr; if (!GetAsyKeyGenerator(env, info, &generator) || generator == nullptr) { - LOGE("build generator fail."); + LOGE_ONE_STR("build generator fail."); napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "build generator fail!")); return nullptr; } @@ -427,7 +427,7 @@ napi_value NapiAsyKeyGeneratorBySpec::JsGenerateKeyPairSync(napi_env env, napi_c HcfKeyPair *returnKeyPair = nullptr; HcfResult errCode = generator->generateKeyPair(generator, &(returnKeyPair)); if (errCode != HCF_SUCCESS) { - LOGE("generate key pair fail."); + LOGE_ONE_STR("generate key pair fail."); napi_throw(env, GenerateBusinessError(env, errCode, "generate key pair fail.")); return nullptr; } @@ -436,7 +436,7 @@ napi_value NapiAsyKeyGeneratorBySpec::JsGenerateKeyPairSync(napi_env env, napi_c NapiKeyPair *napiKeyPair = new (std::nothrow) NapiKeyPair(returnKeyPair); if (napiKeyPair == nullptr) { HcfObjDestroy(returnKeyPair); - LOGE("new napi key pair failed"); + LOGE_ONE_STR("new napi key pair failed"); napi_throw(env, GenerateBusinessError(env, HCF_ERR_MALLOC, "new napi key pair failed!")); return nullptr; } @@ -450,7 +450,7 @@ napi_value NapiAsyKeyGeneratorBySpec::JsGenerateKeyPairSync(napi_env env, napi_c return; }, nullptr, nullptr); if (ret != napi_ok) { - LOGE("failed to wrap napiKeyPair obj!"); + LOGE_ONE_STR("failed to wrap napiKeyPair obj!"); delete napiKeyPair; napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "failed to wrap napiKeyPair obj!")); return nullptr; @@ -463,13 +463,13 @@ napi_value NapiAsyKeyGeneratorBySpec::JsGeneratePubKey(napi_env env, napi_callba AsyKeyCtx *ctx = static_cast(HcfMalloc(sizeof(AsyKeyCtx), 0)); if (ctx == nullptr) { napi_throw(env, GenerateBusinessError(env, HCF_ERR_MALLOC, "create context fail!")); - LOGE("create context fail."); + LOGE_ONE_STR("create context fail."); return nullptr; } if (!BuildAsyKeyCtx(env, info, ctx)) { napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "build context fail!")); - LOGE("build context fail."); + LOGE_ONE_STR("build context fail."); FreeAsyKeyCtx(env, ctx); return nullptr; } @@ -481,7 +481,7 @@ napi_value NapiAsyKeyGeneratorBySpec::JsGeneratePubKeySync(napi_env env, napi_ca { HcfAsyKeyGeneratorBySpec *generator = nullptr; if (!GetAsyKeyGenerator(env, info, &generator) || generator == nullptr) { - LOGE("build generator fail."); + LOGE_ONE_STR("build generator fail."); napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "build generator fail!")); return nullptr; } @@ -489,7 +489,7 @@ napi_value NapiAsyKeyGeneratorBySpec::JsGeneratePubKeySync(napi_env env, napi_ca HcfPubKey *returnPubKey = nullptr; HcfResult errCode = generator->generatePubKey(generator, &(returnPubKey)); if (errCode != HCF_SUCCESS) { - LOGE("generate PubKey fail."); + LOGE_ONE_STR("generate PubKey fail."); napi_throw(env, GenerateBusinessError(env, errCode, "generate PubKey fail.")); return nullptr; } @@ -498,7 +498,7 @@ napi_value NapiAsyKeyGeneratorBySpec::JsGeneratePubKeySync(napi_env env, napi_ca NapiPubKey *napiPubKey = new (std::nothrow) NapiPubKey(returnPubKey); if (napiPubKey == nullptr) { HcfObjDestroy(returnPubKey); - LOGE("new napi pub key failed"); + LOGE_ONE_STR("new napi pub key failed"); napi_throw(env, GenerateBusinessError(env, HCF_ERR_MALLOC, "new napi pub key failed!")); return nullptr; } @@ -513,7 +513,7 @@ napi_value NapiAsyKeyGeneratorBySpec::JsGeneratePubKeySync(napi_env env, napi_ca return; }, nullptr, nullptr); if (ret != napi_ok) { - LOGE("failed to wrap napiPubKey obj!"); + LOGE_ONE_STR("failed to wrap napiPubKey obj!"); HcfObjDestroy(napiPubKey->GetPubKey()); delete napiPubKey; napi_throw(env, GenerateBusinessError(env, HCF_ERR_MALLOC, "failed to wrap napiPubKey obj!")); @@ -528,13 +528,13 @@ napi_value NapiAsyKeyGeneratorBySpec::JsGeneratePriKey(napi_env env, napi_callba AsyKeyCtx *ctx = static_cast(HcfMalloc(sizeof(AsyKeyCtx), 0)); if (ctx == nullptr) { napi_throw(env, GenerateBusinessError(env, HCF_ERR_MALLOC, "create context fail!")); - LOGE("create context fail."); + LOGE_ONE_STR("create context fail."); return nullptr; } if (!BuildAsyKeyCtx(env, info, ctx)) { napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "build context fail!")); - LOGE("build context fail."); + LOGE_ONE_STR("build context fail."); FreeAsyKeyCtx(env, ctx); return nullptr; } @@ -546,7 +546,7 @@ napi_value NapiAsyKeyGeneratorBySpec::JsGeneratePriKeySync(napi_env env, napi_ca { HcfAsyKeyGeneratorBySpec *generator = nullptr; if (!GetAsyKeyGenerator(env, info, &generator) || generator == nullptr) { - LOGE("build generator fail."); + LOGE_ONE_STR("build generator fail."); napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "build generator fail!")); return nullptr; } @@ -554,7 +554,7 @@ napi_value NapiAsyKeyGeneratorBySpec::JsGeneratePriKeySync(napi_env env, napi_ca HcfPriKey *returnPriKey = nullptr; HcfResult errCode = generator->generatePriKey(generator, &(returnPriKey)); if (errCode != HCF_SUCCESS) { - LOGE("generate PriKey fail."); + LOGE_ONE_STR("generate PriKey fail."); napi_throw(env, GenerateBusinessError(env, errCode, "generate PriKey fail.")); return nullptr; } @@ -563,7 +563,7 @@ napi_value NapiAsyKeyGeneratorBySpec::JsGeneratePriKeySync(napi_env env, napi_ca NapiPriKey *napiPriKey = new (std::nothrow) NapiPriKey(returnPriKey); if (napiPriKey == nullptr) { HcfObjDestroy(returnPriKey); - LOGE("new napi pri key failed"); + LOGE_ONE_STR("new napi pri key failed"); napi_throw(env, GenerateBusinessError(env, HCF_ERR_MALLOC, "new napi pri key failed!")); return nullptr; } @@ -578,7 +578,7 @@ napi_value NapiAsyKeyGeneratorBySpec::JsGeneratePriKeySync(napi_env env, napi_ca return; }, nullptr, nullptr); if (ret != napi_ok) { - LOGE("failed to wrap napiPriKey obj!"); + LOGE_ONE_STR("failed to wrap napiPriKey obj!"); HcfObjDestroy(napiPriKey->GetPriKey()); delete napiPriKey; napi_throw(env, GenerateBusinessError(env, HCF_ERR_MALLOC, "failed to wrap napiPriKey obj!")); @@ -597,7 +597,7 @@ napi_value NapiAsyKeyGeneratorBySpec::AsyKeyGeneratorBySpecConstructor(napi_env napi_value NapiAsyKeyGeneratorBySpec::CreateJsAsyKeyGeneratorBySpec(napi_env env, napi_callback_info info) { - LOGD("Enter CreateJsAsyKeyGeneratorBySpec..."); + LOGD_ONE_STR("Enter CreateJsAsyKeyGeneratorBySpec..."); size_t expectedArgc = PARAMS_NUM_ONE; size_t argc = expectedArgc; napi_value argv[PARAMS_NUM_ONE] = { nullptr }; @@ -605,7 +605,7 @@ napi_value NapiAsyKeyGeneratorBySpec::CreateJsAsyKeyGeneratorBySpec(napi_env env if (argc != expectedArgc) { napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "The input args num is invalid.")); - LOGE("The input args num is invalid."); + LOGE_ONE_STR("The input args num is invalid."); return nullptr; } @@ -617,7 +617,7 @@ napi_value NapiAsyKeyGeneratorBySpec::CreateJsAsyKeyGeneratorBySpec(napi_env env HcfAsyKeyParamsSpec *asyKeySpec = nullptr; if (!GetAsyKeySpecFromNapiValue(env, argv[0], &asyKeySpec)) { napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "failed to get valid asyKeySpec!")); - LOGE("GetAsyKeySpecFromNapiValue failed!"); + LOGE_ONE_STR("GetAsyKeySpecFromNapiValue failed!"); return nullptr; } HcfAsyKeyGeneratorBySpec *generator = nullptr; @@ -625,14 +625,14 @@ napi_value NapiAsyKeyGeneratorBySpec::CreateJsAsyKeyGeneratorBySpec(napi_env env FreeAsyKeySpec(asyKeySpec); if (res != HCF_SUCCESS) { napi_throw(env, GenerateBusinessError(env, res, "create C generator by sepc fail.")); - LOGE("create C generator by spec fail."); + LOGE_ONE_STR("create C generator by spec fail."); return nullptr; } NapiAsyKeyGeneratorBySpec *napiAsyKeyGeneratorBySpec = new (std::nothrow) NapiAsyKeyGeneratorBySpec(generator); if (napiAsyKeyGeneratorBySpec == nullptr) { napi_throw(env, GenerateBusinessError(env, HCF_ERR_MALLOC, "new napi asy key generator by spec failed!")); - LOGE("new napi asy key generator by spec failed!"); + LOGE_ONE_STR("new napi asy key generator by spec failed!"); HcfObjDestroy(generator); return nullptr; } @@ -645,7 +645,7 @@ napi_value NapiAsyKeyGeneratorBySpec::CreateJsAsyKeyGeneratorBySpec(napi_env env }, nullptr, nullptr); if (status != napi_ok) { napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "wrap napiAsyKeyGeneratorBySpec failed!")); - LOGE("failed to wrap napiAsyKeyGeneratorBySpec obj!"); + LOGE_ONE_STR("failed to wrap napiAsyKeyGeneratorBySpec obj!"); delete napiAsyKeyGeneratorBySpec; return nullptr; } @@ -660,13 +660,13 @@ napi_value NapiAsyKeyGeneratorBySpec::JsGetAlgorithm(napi_env env, napi_callback napi_status status = napi_unwrap(env, thisVar, reinterpret_cast(&napiAsyKeyGeneratorBySpec)); if (status != napi_ok || napiAsyKeyGeneratorBySpec == nullptr) { napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "failed to unwrap napi asyKeyGenerator obj.")); - LOGE("failed to unwrap napi asyKeyGenerator obj."); + LOGE_ONE_STR("failed to unwrap napi asyKeyGenerator obj."); return nullptr; } HcfAsyKeyGeneratorBySpec *generator = napiAsyKeyGeneratorBySpec->GetAsyKeyGeneratorBySpec(); if (generator == nullptr) { napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "fail to get generator by spec obj!")); - LOGE("fail to get generator by spec obj!"); + LOGE_ONE_STR("fail to get generator by spec obj!"); return nullptr; } diff --git a/frameworks/js/napi/crypto/src/napi_cipher.cpp b/frameworks/js/napi/crypto/src/napi_cipher.cpp index ac947b7dbefcd20d457f41b739f4da1e66c40d79..c3c0d5aed839e019ef0466bc42a8a8be158ce4c0 100644 --- a/frameworks/js/napi/crypto/src/napi_cipher.cpp +++ b/frameworks/js/napi/crypto/src/napi_cipher.cpp @@ -140,12 +140,12 @@ static void FreeCipherFwkCtx(napi_env env, CipherFwkCtx &context) static bool CreateCipherRef(napi_env env, napi_value thisVar, napi_value key, CipherFwkCtx ctx) { if (napi_create_reference(env, thisVar, 1, &ctx->cipherRef) != napi_ok) { - LOGE("create cipher ref failed when do cipher init!"); + LOGE_ONE_STR("create cipher ref failed when do cipher init!"); return false; } if (napi_create_reference(env, key, 1, &ctx->keyRef) != napi_ok) { - LOGE("create key ref failed when do cipher init!"); + LOGE_ONE_STR("create key ref failed when do cipher init!"); return false; } @@ -169,7 +169,7 @@ static bool BuildContextForInit(napi_env env, napi_callback_info info, CipherFwk napi_status status = napi_unwrap(env, thisVar, reinterpret_cast(&napiCipher)); if (status != napi_ok || napiCipher == nullptr) { - LOGE("failed to unwrap napi napiCipher obj!"); + LOGE_ONE_STR("failed to unwrap napi napiCipher obj!"); return false; } context->cipher = napiCipher->GetCipher(); @@ -177,14 +177,14 @@ static bool BuildContextForInit(napi_env env, napi_callback_info info, CipherFwk // get opMode, type is uint32 size_t index = 0; if (napi_get_value_uint32(env, argv[index++], reinterpret_cast(&(context->opMode))) != napi_ok) { - LOGE("get opMode failed!"); + LOGE_ONE_STR("get opMode failed!"); return false; } // get key, unwrap from JS status = napi_unwrap(env, argv[index++], reinterpret_cast(&napiKey)); if (status != napi_ok || napiKey == nullptr) { - LOGE("failed to unwrap napi napiSymKey obj!"); + LOGE_ONE_STR("failed to unwrap napi napiSymKey obj!"); return false; } context->key = napiKey->GetHcfKey(); @@ -194,7 +194,7 @@ static bool BuildContextForInit(napi_env env, napi_callback_info info, CipherFwk napi_typeof(env, argv[index], &valueType); if (valueType != napi_null) { if (!GetParamsSpecFromNapiValue(env, argv[index], context->opMode, &context->paramsSpec)) { - LOGE("GetParamsSpecFromNapiValue failed!"); + LOGE_ONE_STR("GetParamsSpecFromNapiValue failed!"); return false; } } @@ -229,7 +229,7 @@ static bool BuildContextForUpdate(napi_env env, napi_callback_info info, CipherF napi_status status = napi_unwrap(env, thisVar, reinterpret_cast(&napiCipher)); if (status != napi_ok || napiCipher == nullptr) { - LOGE("failed to unwrap napi napiCipher obj!"); + LOGE_ONE_STR("failed to unwrap napi napiCipher obj!"); return false; } context->cipher = napiCipher->GetCipher(); @@ -239,7 +239,7 @@ static bool BuildContextForUpdate(napi_env env, napi_callback_info info, CipherF HcfBlob *input = nullptr; input = GetBlobFromNapiDataBlob(env, argv[index++]); if (input == nullptr) { - LOGE("GetBlobFromNapiDataBlob failed!"); + LOGE_ONE_STR("GetBlobFromNapiDataBlob failed!"); return false; } context->input.data = input->data; @@ -247,7 +247,7 @@ static bool BuildContextForUpdate(napi_env env, napi_callback_info info, CipherF HcfFree(input); if (napi_create_reference(env, thisVar, 1, &context->cipherRef) != napi_ok) { - LOGE("create cipher ref failed when do cipher update!"); + LOGE_ONE_STR("create cipher ref failed when do cipher update!"); return false; } @@ -275,7 +275,7 @@ static bool BuildContextForFinal(napi_env env, napi_callback_info info, CipherFw napi_status status = napi_unwrap(env, thisVar, reinterpret_cast(&napiCipher)); if (status != napi_ok || napiCipher == nullptr) { - LOGE("failed to unwrap napi napiCipher obj!"); + LOGE_ONE_STR("failed to unwrap napi napiCipher obj!"); return false; } context->cipher = napiCipher->GetCipher(); @@ -288,7 +288,7 @@ static bool BuildContextForFinal(napi_env env, napi_callback_info info, CipherFw HcfBlob *input = nullptr; input = GetBlobFromNapiDataBlob(env, argv[index]); if (input == nullptr) { - LOGE("GetBlobFromNapiDataBlob failed!"); + LOGE_ONE_STR("GetBlobFromNapiDataBlob failed!"); return false; } context->input.data = input->data; @@ -297,7 +297,7 @@ static bool BuildContextForFinal(napi_env env, napi_callback_info info, CipherFw } if (napi_create_reference(env, thisVar, 1, &context->cipherRef) != napi_ok) { - LOGE("create cipher ref failed when do cipher final!"); + LOGE_ONE_STR("create cipher ref failed when do cipher final!"); return false; } @@ -394,7 +394,7 @@ static void AsyncUpdateReturn(napi_env env, napi_status status, void *data) CipherFwkCtx context = static_cast(data); napi_value instance = ConvertBlobToNapiValue(env, &context->output); if (instance == nullptr) { - LOGE("May be nullptr!"); + LOGE_ONE_STR("May be nullptr!"); instance = NapiGetNull(env); } @@ -411,7 +411,7 @@ static void AsyncDoFinalReturn(napi_env env, napi_status status, void *data) CipherFwkCtx context = static_cast(data); napi_value instance = ConvertBlobToNapiValue(env, &context->output); if (instance == nullptr) { - LOGE("Maybe in decrypt mode, or CCM crypto maybe occur!"); + LOGE_ONE_STR("Maybe in decrypt mode, or CCM crypto maybe occur!"); instance = NapiGetNull(env); } @@ -521,13 +521,13 @@ napi_value NapiCipher::JsCipherInit(napi_env env, napi_callback_info info) CipherFwkCtx context = static_cast(HcfMalloc(sizeof(CipherFwkCtxT), 0)); if (context == nullptr) { napi_throw(env, GenerateBusinessError(env, HCF_ERR_MALLOC, "create context fail!")); - LOGE("create context fail!"); + LOGE_ONE_STR("create context fail!"); return nullptr; } if (!BuildContextForInit(env, info, context)) { napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "build context for init fail!")); - LOGE("build context for init fail!"); + LOGE_ONE_STR("build context for init fail!"); FreeCipherFwkCtx(env, context); return nullptr; } @@ -540,7 +540,7 @@ static napi_value SyncInit(napi_env env, HcfCipher *cipher, HcfCryptoMode opMode { HcfResult res = cipher->init(cipher, opMode, key, paramsSpec); if (res != HCF_SUCCESS) { - LOGE("failed to cipher init."); + LOGE_ONE_STR("failed to cipher init."); napi_throw(env, GenerateBusinessError(env, res, "init cipher fail.")); return nullptr; } @@ -561,7 +561,7 @@ napi_value NapiCipher::JsCipherInitSync(napi_env env, napi_callback_info info) NapiCipher *napiCipher = nullptr; napi_status status = napi_unwrap(env, thisVar, reinterpret_cast(&napiCipher)); if (status != napi_ok || napiCipher == nullptr) { - LOGE("failed to unwrap napi napiCipher obj!"); + LOGE_ONE_STR("failed to unwrap napi napiCipher obj!"); napi_throw(env, GenerateBusinessError(env, HCF_ERR_NAPI, "unwrap napi napiCipher failed!")); return nullptr; } @@ -570,7 +570,7 @@ napi_value NapiCipher::JsCipherInitSync(napi_env env, napi_callback_info info) size_t index = 0; enum HcfCryptoMode opMode = ENCRYPT_MODE; if (napi_get_value_uint32(env, argv[index++], reinterpret_cast(&opMode)) != napi_ok) { - LOGE("get option mode failed!"); + LOGE_ONE_STR("get option mode failed!"); napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "get napi option mode failed!")); return nullptr; } @@ -578,7 +578,7 @@ napi_value NapiCipher::JsCipherInitSync(napi_env env, napi_callback_info info) NapiKey *napiKey = nullptr; status = napi_unwrap(env, argv[index++], reinterpret_cast(&napiKey)); if (status != napi_ok || napiKey == nullptr) { - LOGE("get key obj failed!"); + LOGE_ONE_STR("get key obj failed!"); napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "get napi key failed!")); return nullptr; } @@ -589,7 +589,7 @@ napi_value NapiCipher::JsCipherInitSync(napi_env env, napi_callback_info info) napi_typeof(env, argv[index], &valueType); if (valueType != napi_null) { if (!GetParamsSpecFromNapiValue(env, argv[index], opMode, ¶msSpec)) { - LOGE("get params failed!"); + LOGE_ONE_STR("get params failed!"); napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "get napi paramsSpec failed!")); return nullptr; } @@ -604,13 +604,13 @@ napi_value NapiCipher::JsCipherUpdate(napi_env env, napi_callback_info info) CipherFwkCtx context = static_cast(HcfMalloc(sizeof(CipherFwkCtxT), 0)); if (context == nullptr) { napi_throw(env, GenerateBusinessError(env, HCF_ERR_MALLOC, "create context fail!")); - LOGE("create context fail!"); + LOGE_ONE_STR("create context fail!"); return nullptr; } if (!BuildContextForUpdate(env, info, context)) { napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "build context for update fail!")); - LOGE("build context for update fail!"); + LOGE_ONE_STR("build context for update fail!"); FreeCipherFwkCtx(env, context); return nullptr; } @@ -633,7 +633,7 @@ napi_value NapiCipher::JsCipherUpdateSync(napi_env env, napi_callback_info info) HcfCipher *cipher = nullptr; napi_status status = napi_unwrap(env, thisVar, reinterpret_cast(&napiCipher)); if (status != napi_ok || napiCipher == nullptr) { - LOGE("failed to unwrap napi napiCipher obj!"); + LOGE_ONE_STR("failed to unwrap napi napiCipher obj!"); napi_throw(env, GenerateBusinessError(env, HCF_ERR_NAPI, "unwrap napi cipher failed!")); return nullptr; } @@ -642,7 +642,7 @@ napi_value NapiCipher::JsCipherUpdateSync(napi_env env, napi_callback_info info) HcfBlob input = { 0 }; HcfResult errCode = GetBlobFromNapiValue(env, argv[PARAM0], &input); if (errCode != HCF_SUCCESS) { - LOGE("failed to get input blob!"); + LOGE_ONE_STR("failed to get input blob!"); napi_throw(env, GenerateBusinessError(env, errCode, "get input blob failed!")); return nullptr; } @@ -650,7 +650,7 @@ napi_value NapiCipher::JsCipherUpdateSync(napi_env env, napi_callback_info info) errCode = cipher->update(cipher, &input, &output); HcfBlobDataClearAndFree(&input); if (errCode != HCF_SUCCESS) { - LOGE("failed to update!"); + LOGE_ONE_STR("failed to update!"); napi_throw(env, GenerateBusinessError(env, errCode, "update fail!")); return nullptr; } @@ -659,7 +659,7 @@ napi_value NapiCipher::JsCipherUpdateSync(napi_env env, napi_callback_info info) errCode = ConvertDataBlobToNapiValue(env, &output, &instance); HcfBlobDataClearAndFree(&output); if (errCode != HCF_SUCCESS) { - LOGE("cipher update convert dataBlob to napi_value failed!"); + LOGE_ONE_STR("cipher update convert dataBlob to napi_value failed!"); napi_throw(env, GenerateBusinessError(env, errCode, "cipher update convert dataBlob to napi_value failed!")); return nullptr; } @@ -671,13 +671,13 @@ napi_value NapiCipher::JsCipherDoFinal(napi_env env, napi_callback_info info) CipherFwkCtx context = static_cast(HcfMalloc(sizeof(CipherFwkCtxT), 0)); if (context == nullptr) { napi_throw(env, GenerateBusinessError(env, HCF_ERR_MALLOC, "create context fail!")); - LOGE("create context fail!"); + LOGE_ONE_STR("create context fail!"); return nullptr; } if (!BuildContextForFinal(env, info, context)) { napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "build context for final fail!")); - LOGE("build context for final fail!"); + LOGE_ONE_STR("build context for final fail!"); FreeCipherFwkCtx(env, context); return nullptr; } @@ -700,7 +700,7 @@ napi_value NapiCipher::JsCipherDoFinalSync(napi_env env, napi_callback_info info HcfCipher *cipher = nullptr; napi_status status = napi_unwrap(env, thisVar, reinterpret_cast(&napiCipher)); if (status != napi_ok || napiCipher == nullptr) { - LOGE("failed to unwrap napi cipher obj!"); + LOGE_ONE_STR("failed to unwrap napi cipher obj!"); napi_throw(env, GenerateBusinessError(env, HCF_ERR_NAPI, "unwrap napi cipher failed")); return nullptr; } @@ -713,7 +713,7 @@ napi_value NapiCipher::JsCipherDoFinalSync(napi_env env, napi_callback_info info if (valueType != napi_null) { HcfResult ret = GetBlobFromNapiValue(env, argv[PARAM0], &blob); if (ret != HCF_SUCCESS) { - LOGE("failed to get input blob!"); + LOGE_ONE_STR("failed to get input blob!"); napi_throw(env, GenerateBusinessError(env, ret, "get input blob failed!")); return nullptr; } @@ -723,7 +723,7 @@ napi_value NapiCipher::JsCipherDoFinalSync(napi_env env, napi_callback_info info HcfResult res = cipher->doFinal(cipher, input, &output); HcfBlobDataClearAndFree(input); if (res != HCF_SUCCESS) { - LOGE("failed to do final!"); + LOGE_ONE_STR("failed to do final!"); napi_throw(env, GenerateBusinessError(env, res, "do final fail!")); return nullptr; } @@ -732,7 +732,7 @@ napi_value NapiCipher::JsCipherDoFinalSync(napi_env env, napi_callback_info info res = ConvertDataBlobToNapiValue(env, &output, &instance); HcfBlobDataClearAndFree(&output); if (res != HCF_SUCCESS) { - LOGE("cipher convert dataBlob to napi_value failed!"); + LOGE_ONE_STR("cipher convert dataBlob to napi_value failed!"); napi_throw(env, GenerateBusinessError(env, res, "cipher convert dataBlob to napi_value failed!")); return nullptr; } @@ -748,13 +748,13 @@ napi_value NapiCipher::JsGetAlgorithm(napi_env env, napi_callback_info info) napi_status status = napi_unwrap(env, thisVar, reinterpret_cast(&napiCipher)); if (status != napi_ok || napiCipher == nullptr) { - LOGE("failed to unwrap napiCipher obj!"); + LOGE_ONE_STR("failed to unwrap napiCipher obj!"); return nullptr; } HcfCipher *cipher = napiCipher->GetCipher(); if (cipher == nullptr) { - LOGE("failed to get cipher obj!"); + LOGE_ONE_STR("failed to get cipher obj!"); return nullptr; } @@ -775,7 +775,7 @@ napi_value NapiCipher::CipherConstructor(napi_env env, napi_callback_info info) napi_value NapiCipher::CreateCipher(napi_env env, napi_callback_info info) { - LOGD("Enter CreateCipher..."); + LOGD_ONE_STR("Enter CreateCipher..."); size_t expectedArgc = ARGS_SIZE_ONE; size_t argc = ARGS_SIZE_ONE; napi_value argv[ARGS_SIZE_ONE] = { nullptr }; @@ -783,7 +783,7 @@ napi_value NapiCipher::CreateCipher(napi_env env, napi_callback_info info) if (argc != expectedArgc) { napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "The input args num is invalid.")); - LOGE("The input args num is invalid."); + LOGE_ONE_STR("The input args num is invalid."); return nullptr; } @@ -797,7 +797,7 @@ napi_value NapiCipher::CreateCipher(napi_env env, napi_callback_info info) std::string algoName; if (!GetStringFromJSParams(env, argv[0], algoName)) { napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "failed to get algoName.")); - LOGE("failed to get algoName."); + LOGE_ONE_STR("failed to get algoName."); return nullptr; } @@ -806,13 +806,13 @@ napi_value NapiCipher::CreateCipher(napi_env env, napi_callback_info info) HcfResult res = HcfCipherCreate(algoName.c_str(), &cipher); if (res != HCF_SUCCESS) { napi_throw(env, GenerateBusinessError(env, res, "create C cipher fail!")); - LOGE("create C cipher fail!"); + LOGE_ONE_STR("create C cipher fail!"); return nullptr; } NapiCipher *napiCipher = new (std::nothrow) NapiCipher(cipher); if (napiCipher == nullptr) { napi_throw(env, GenerateBusinessError(env, HCF_ERR_MALLOC, "new napiCipher failed!")); - LOGE("new napiCipher failed!"); + LOGE_ONE_STR("new napiCipher failed!"); HcfObjDestroy(cipher); return nullptr; } @@ -825,7 +825,7 @@ napi_value NapiCipher::CreateCipher(napi_env env, napi_callback_info info) }, nullptr, nullptr); if (status != napi_ok) { napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "failed to wrap napiCipher obj.")); - LOGE("failed to wrap napiCipher obj!"); + LOGE_ONE_STR("failed to wrap napiCipher obj!"); delete napiCipher; return nullptr; } @@ -848,12 +848,12 @@ napi_value NapiCipher::JsSetCipherSpec(napi_env env, napi_callback_info info) CipherSpecItem item; if (napi_get_value_uint32(env, argv[0], reinterpret_cast(&item)) != napi_ok) { napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "get JsGetCipherSpecUint8Array failed!")); - LOGE("get JsGetCipherSpecUint8Array failed!"); + LOGE_ONE_STR("get JsGetCipherSpecUint8Array failed!"); return nullptr; } HcfBlob *pSource = GetBlobFromNapiUint8Arr(env, argv[1]); if (pSource == nullptr || pSource->len == 0) { - LOGE("failed to get pSource."); + LOGE_ONE_STR("failed to get pSource."); napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "[pSource]: must be of the DataBlob type.")); return nullptr; } @@ -862,7 +862,7 @@ napi_value NapiCipher::JsSetCipherSpec(napi_env env, napi_callback_info info) HcfBlobDataFree(pSource); HcfFree(pSource); napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "failed to unwrap napiCipher obj!")); - LOGE("failed to unwrap napiCipher obj!"); + LOGE_ONE_STR("failed to unwrap napiCipher obj!"); return nullptr; } HcfCipher *cipher = napiCipher->GetCipher(); @@ -871,7 +871,7 @@ napi_value NapiCipher::JsSetCipherSpec(napi_env env, napi_callback_info info) HcfBlobDataFree(pSource); HcfFree(pSource); napi_throw(env, GenerateBusinessError(env, res, "c set cipher spec failed.")); - LOGE("c set cipher spec failed."); + LOGE_ONE_STR("c set cipher spec failed."); return nullptr; } HcfBlobDataFree(pSource); @@ -885,7 +885,7 @@ static napi_value GetCipherSpecString(napi_env env, CipherSpecItem item, HcfCiph HcfResult res = cipher->getCipherSpecString(cipher, item, &returnString); if (res != HCF_SUCCESS) { napi_throw(env, GenerateBusinessError(env, res, "c getCipherSpecString failed.")); - LOGE("c getCipherSpecString fail."); + LOGE_ONE_STR("c getCipherSpecString fail."); return nullptr; } @@ -901,7 +901,7 @@ static napi_value GetCipherSpecUint8Array(napi_env env, CipherSpecItem item, Hcf HcfResult res = cipher->getCipherSpecUint8Array(cipher, item, &blob); if (res != HCF_SUCCESS) { napi_throw(env, GenerateBusinessError(env, res, "c getCipherSpecUint8Array fail.")); - LOGE("c getCipherSpecUint8Array fail."); + LOGE_ONE_STR("c getCipherSpecUint8Array fail."); return nullptr; } @@ -926,20 +926,20 @@ napi_value NapiCipher::JsGetCipherSpec(napi_env env, napi_callback_info info) CipherSpecItem item; if (napi_get_value_uint32(env, argv[0], reinterpret_cast(&item)) != napi_ok) { napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "get getCipherSpecString failed!")); - LOGE("get getCipherSpecString failed!"); + LOGE_ONE_STR("get getCipherSpecString failed!"); return nullptr; } napi_status status = napi_unwrap(env, thisVar, reinterpret_cast(&napiCipher)); if (status != napi_ok || napiCipher == nullptr) { napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "failed to unwrap napiCipher obj!")); - LOGE("failed to unwrap napiCipher obj!"); + LOGE_ONE_STR("failed to unwrap napiCipher obj!"); return nullptr; } HcfCipher *cipher = napiCipher->GetCipher(); if (cipher == nullptr) { napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "failed to get cipher obj!")); - LOGE("failed to get cipher obj!"); + LOGE_ONE_STR("failed to get cipher obj!"); return nullptr; } diff --git a/frameworks/js/napi/crypto/src/napi_dh_key_util.cpp b/frameworks/js/napi/crypto/src/napi_dh_key_util.cpp index 24e364bb8b1bcf4a54c52501837116ea3dd07f74..085f0428b9e9f8ecf6d0135b8247582db1b9ef15 100644 --- a/frameworks/js/napi/crypto/src/napi_dh_key_util.cpp +++ b/frameworks/js/napi/crypto/src/napi_dh_key_util.cpp @@ -35,22 +35,22 @@ NapiDHKeyUtil::~NapiDHKeyUtil() {} static bool BuildDhInstanceToNapiValueSub(napi_env env, HcfDhCommParamsSpec *blob, napi_value *instance) { if (!BuildSetNamedProperty(env, &(blob->p), "p", instance)) { - LOGE("build setNamedProperty a failed!"); + LOGE_ONE_STR("build setNamedProperty a failed!"); return false; } if (!BuildSetNamedProperty(env, &(blob->g), "g", instance)) { - LOGE("build setNamedProperty b failed!"); + LOGE_ONE_STR("build setNamedProperty b failed!"); return false; } napi_value length; napi_status status = napi_create_int32(env, blob->length, &length); if (status != napi_ok) { - LOGE("create length number failed!"); + LOGE_ONE_STR("create length number failed!"); return false; } status = napi_set_named_property(env, *instance, "l", length); if (status != napi_ok) { - LOGE("create length number failed!"); + LOGE_ONE_STR("create length number failed!"); return false; } return true; @@ -61,32 +61,32 @@ static bool BuildDhInstanceToNapiValue(napi_env env, HcfDhCommParamsSpec *blob, napi_value algName; size_t algNameLength = HcfStrlen(blob->base.algName); if (!algNameLength) { - LOGE("algName is empty!"); + LOGE_ONE_STR("algName is empty!"); return false; } napi_status status = napi_create_string_utf8(env, blob->base.algName, algNameLength, &algName); if (status != napi_ok) { - LOGE("create algName failed!"); + LOGE_ONE_STR("create algName failed!"); return false; } napi_value specType; status = napi_create_uint32(env, blob->base.specType, &specType); if (status != napi_ok) { - LOGE("create uint32 failed!"); + LOGE_ONE_STR("create uint32 failed!"); return false; } status = napi_set_named_property(env, *instance, "algName", algName); if (status != napi_ok) { - LOGE("create set algName failed!"); + LOGE_ONE_STR("create set algName failed!"); return false; } status = napi_set_named_property(env, *instance, "specType", specType); if (status != napi_ok) { - LOGE("create set specType failed!"); + LOGE_ONE_STR("create set specType failed!"); return false; } if (!BuildDhInstanceToNapiValueSub(env, blob, instance)) { - LOGE("create intance parter napi value failed!"); + LOGE_ONE_STR("create intance parter napi value failed!"); return false; } return true; @@ -95,19 +95,19 @@ static bool BuildDhInstanceToNapiValue(napi_env env, HcfDhCommParamsSpec *blob, static bool CheckDhCommonParamSpec(napi_env env, HcfDhCommParamsSpec *blob) { if (blob == nullptr) { - LOGE("Invalid blob!"); + LOGE_ONE_STR("Invalid blob!"); return false; } if (blob->base.algName == nullptr) { - LOGE("Invalid blob algName!"); + LOGE_ONE_STR("Invalid blob algName!"); return false; } if (blob->p.data == nullptr || blob->p.len == 0) { - LOGE("Invalid blob a!"); + LOGE_ONE_STR("Invalid blob a!"); return false; } if (blob->g.data == nullptr || blob->g.len == 0) { - LOGE("Invalid blob point x!"); + LOGE_ONE_STR("Invalid blob point x!"); return false; } return true; @@ -117,19 +117,19 @@ static napi_value ConvertDhCommParamsSpecToNapiValue(napi_env env, HcfDhCommPara { if (!CheckDhCommonParamSpec(env, blob)) { napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "Invalid blob!")); - LOGE("Invalid blob!"); + LOGE_ONE_STR("Invalid blob!"); return NapiGetNull(env); } napi_value instance; napi_status status = napi_create_object(env, &instance); if (status != napi_ok) { napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "create object failed!")); - LOGE("create object failed!"); + LOGE_ONE_STR("create object failed!"); return NapiGetNull(env); } if (!BuildDhInstanceToNapiValue(env, blob, &instance)) { napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "build object failed!")); - LOGE("Build object failed!"); + LOGE_ONE_STR("Build object failed!"); return NapiGetNull(env); } return instance; @@ -144,14 +144,14 @@ napi_value NapiDHKeyUtil::JsGenDHCommonParamsSpec(napi_env env, napi_callback_in if ((argc != expectedArgc) && (argc != (expectedArgc - 1))) { napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "The input args num is invalid.")); - LOGE("The input args num is invalid."); + LOGE_ONE_STR("The input args num is invalid."); return nullptr; } int32_t pLen = 0; if (!GetInt32FromJSParams(env, argv[0], pLen)) { napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "failed to get pLen.")); - LOGE("failed to get pLen."); + LOGE_ONE_STR("failed to get pLen."); return NapiGetNull(env); } @@ -159,14 +159,14 @@ napi_value NapiDHKeyUtil::JsGenDHCommonParamsSpec(napi_env env, napi_callback_in if (argc == expectedArgc) { if (!GetInt32FromJSParams(env, argv[1], skLen)) { napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "failed to get skLen.")); - LOGE("failed to get skLen."); + LOGE_ONE_STR("failed to get skLen."); return NapiGetNull(env); } } HcfDhCommParamsSpec *dhCommParamsSpec = nullptr; if (HcfDhKeyUtilCreate(pLen, skLen, &dhCommParamsSpec) != HCF_SUCCESS) { napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "create c generator fail.")); - LOGE("create c generator fail."); + LOGE_ONE_STR("create c generator fail."); return NapiGetNull(env); } diff --git a/frameworks/js/napi/crypto/src/napi_ecc_key_util.cpp b/frameworks/js/napi/crypto/src/napi_ecc_key_util.cpp index eb11d77b8acf89a6fa67f3ae0f73474d276a02f9..a0c4c98bd983987a2cf6cb76987669da44af1a09 100644 --- a/frameworks/js/napi/crypto/src/napi_ecc_key_util.cpp +++ b/frameworks/js/napi/crypto/src/napi_ecc_key_util.cpp @@ -35,15 +35,15 @@ NapiECCKeyUtil::~NapiECCKeyUtil() {} static bool CheckEccCommonParamSpecBase(napi_env env, HcfEccCommParamsSpec *blob) { if (blob->a.data == nullptr || blob->a.len == 0) { - LOGE("Invalid blob a!"); + LOGE_ONE_STR("Invalid blob a!"); return false; } if (blob->b.data == nullptr || blob->b.len == 0) { - LOGE("Invalid blob b!"); + LOGE_ONE_STR("Invalid blob b!"); return false; } if (blob->n.data == nullptr || blob->n.len == 0) { - LOGE("Invalid blob n!"); + LOGE_ONE_STR("Invalid blob n!"); return false; } return true; @@ -52,36 +52,36 @@ static bool CheckEccCommonParamSpecBase(napi_env env, HcfEccCommParamsSpec *blob static bool CheckEccCommonParamSpec(napi_env env, HcfEccCommParamsSpec *blob) { if (blob == nullptr) { - LOGE("Invalid blob!"); + LOGE_ONE_STR("Invalid blob!"); return false; } if (!CheckEccCommonParamSpecBase(env, blob)) { - LOGE("Invalid blob ecc commonParamSpec base!"); + LOGE_ONE_STR("Invalid blob ecc commonParamSpec base!"); return false; } if (blob->base.algName == nullptr) { - LOGE("Invalid blob algName!"); + LOGE_ONE_STR("Invalid blob algName!"); return false; } if (blob->field == nullptr) { - LOGE("Invalid blob field!"); + LOGE_ONE_STR("Invalid blob field!"); return false; } if (blob->field->fieldType == nullptr) { - LOGE("Invalid blob fieldType!"); + LOGE_ONE_STR("Invalid blob fieldType!"); return false; } if (blob->g.x.data == nullptr || blob->g.x.len == 0) { - LOGE("Invalid blob point x!"); + LOGE_ONE_STR("Invalid blob point x!"); return false; } if (blob->g.y.data == nullptr || blob->g.y.len == 0) { - LOGE("Invalid blob point y!"); + LOGE_ONE_STR("Invalid blob point y!"); return false; } HcfECFieldFp *tmpField = reinterpret_cast(blob->field); if (tmpField->p.data == nullptr || tmpField->p.len == 0) { - LOGE("Invalid blob p!"); + LOGE_ONE_STR("Invalid blob p!"); return false; } return true; @@ -93,33 +93,33 @@ static napi_value ConvertEccCommonParamFieldFpToNapiValue(napi_env env, HcfEccCo napi_value fieldType; napi_status status = napi_create_object(env, &fieldFp); if (status != napi_ok) { - LOGE("create fieldFp failed!"); + LOGE_ONE_STR("create fieldFp failed!"); return NapiGetNull(env); } size_t fieldTypeLength = HcfStrlen(blob->field->fieldType); if (!fieldTypeLength) { - LOGE("fieldType is empty!"); + LOGE_ONE_STR("fieldType is empty!"); return NapiGetNull(env); } status = napi_create_string_utf8(env, blob->field->fieldType, fieldTypeLength, &fieldType); if (status != napi_ok) { - LOGE("create object failed!"); + LOGE_ONE_STR("create object failed!"); return NapiGetNull(env); } status = napi_set_named_property(env, fieldFp, "fieldType", fieldType); if (status != napi_ok) { - LOGE("create object failed!"); + LOGE_ONE_STR("create object failed!"); return NapiGetNull(env); } HcfECFieldFp *tmpField = reinterpret_cast(blob->field); napi_value p = ConvertBigIntToNapiValue(env, &(tmpField->p)); if (p == nullptr) { - LOGE("p is null!"); + LOGE_ONE_STR("p is null!"); return NapiGetNull(env); } status = napi_set_named_property(env, fieldFp, "p", p); if (status != napi_ok) { - LOGE("create object failed!"); + LOGE_ONE_STR("create object failed!"); return NapiGetNull(env); } return fieldFp; @@ -135,7 +135,7 @@ static bool IsNapiNull(napi_env env, napi_value value) static napi_value ConvertEccPointToNapiValue(napi_env env, HcfPoint *p) { if (p == nullptr) { - LOGE("Invalid point data!"); + LOGE_ONE_STR("Invalid point data!"); napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "Invalid point data!")); return nullptr; } @@ -143,33 +143,33 @@ static napi_value ConvertEccPointToNapiValue(napi_env env, HcfPoint *p) napi_value point; napi_status status = napi_create_object(env, &point); if (status != napi_ok) { - LOGE("create object failed!"); + LOGE_ONE_STR("create object failed!"); napi_throw(env, GenerateBusinessError(env, HCF_ERR_MALLOC, "create object failed!")); return nullptr; } napi_value x = ConvertBigIntToNapiValue(env, &(p->x)); if (x == nullptr || IsNapiNull(env, x)) { - LOGE("Failed to convert x to NapiValue!"); + LOGE_ONE_STR("Failed to convert x to NapiValue!"); return nullptr; } napi_value y = ConvertBigIntToNapiValue(env, &(p->y)); if (y == nullptr || IsNapiNull(env, y)) { - LOGE("Failed to convert y to NapiValue!"); + LOGE_ONE_STR("Failed to convert y to NapiValue!"); return nullptr; } status = napi_set_named_property(env, point, "x", x); if (status != napi_ok) { - LOGE("set x property failed!"); + LOGE_ONE_STR("set x property failed!"); napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "set x property failed!")); return nullptr; } status = napi_set_named_property(env, point, "y", y); if (status != napi_ok) { - LOGE("set y property failed!"); + LOGE_ONE_STR("set y property failed!"); napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "set y property failed!")); return nullptr; } @@ -182,28 +182,28 @@ static napi_value ConvertEccCommonParamPointToNapiValue(napi_env env, HcfEccComm napi_value point; napi_status status = napi_create_object(env, &point); if (status != napi_ok) { - LOGE("create object failed!"); + LOGE_ONE_STR("create object failed!"); return NapiGetNull(env); } napi_value x = ConvertBigIntToNapiValue(env, &(blob->g.x)); if (x == nullptr) { - LOGE("x is null!"); + LOGE_ONE_STR("x is null!"); return NapiGetNull(env); } napi_value y = ConvertBigIntToNapiValue(env, &(blob->g.y)); if (y == nullptr) { - LOGE("y is null!"); + LOGE_ONE_STR("y is null!"); return NapiGetNull(env); } status = napi_set_named_property(env, point, "x", x); if (status != napi_ok) { - LOGE("create object failed!"); + LOGE_ONE_STR("create object failed!"); return NapiGetNull(env); } status = napi_set_named_property(env, point, "y", y); if (status != napi_ok) { - LOGE("create object failed!"); + LOGE_ONE_STR("create object failed!"); return NapiGetNull(env); } return point; @@ -213,26 +213,26 @@ static bool BuildIntancePartertoNapiValueSon(napi_env env, napi_status status, H napi_value *instance) { if (!BuildSetNamedProperty(env, &(blob->a), "a", instance)) { - LOGE("build setNamedProperty a failed!"); + LOGE_ONE_STR("build setNamedProperty a failed!"); return false; } if (!BuildSetNamedProperty(env, &(blob->b), "b", instance)) { - LOGE("build setNamedProperty b failed!"); + LOGE_ONE_STR("build setNamedProperty b failed!"); return false; } if (!BuildSetNamedProperty(env, &(blob->n), "n", instance)) { - LOGE("build setNamedProperty n failed!"); + LOGE_ONE_STR("build setNamedProperty n failed!"); return false; } napi_value h; status = napi_create_int32(env, blob->h, &h); if (status != napi_ok) { - LOGE("create h uint32 failed!"); + LOGE_ONE_STR("create h uint32 failed!"); return false; } status = napi_set_named_property(env, *instance, "h", h); if (status != napi_ok) { - LOGE("create h uint32 failed!"); + LOGE_ONE_STR("create h uint32 failed!"); return false; } return true; @@ -243,32 +243,32 @@ static bool BuildInstanceParterToNapiValue(napi_env env, HcfEccCommParamsSpec *b napi_value algName; size_t algNameLength = HcfStrlen(blob->base.algName); if (!algNameLength) { - LOGE("algName is empty!"); + LOGE_ONE_STR("algName is empty!"); return false; } napi_status status = napi_create_string_utf8(env, blob->base.algName, algNameLength, &algName); if (status != napi_ok) { - LOGE("create algName failed!"); + LOGE_ONE_STR("create algName failed!"); return false; } napi_value specType; status = napi_create_uint32(env, blob->base.specType, &specType); if (status != napi_ok) { - LOGE("create uint32 failed!"); + LOGE_ONE_STR("create uint32 failed!"); return false; } status = napi_set_named_property(env, *instance, "algName", algName); if (status != napi_ok) { - LOGE("create set algName failed!"); + LOGE_ONE_STR("create set algName failed!"); return false; } status = napi_set_named_property(env, *instance, "specType", specType); if (status != napi_ok) { - LOGE("create set specType failed!"); + LOGE_ONE_STR("create set specType failed!"); return false; } if (!BuildIntancePartertoNapiValueSon(env, status, blob, instance)) { - LOGE("create intance parter napi value failed!"); + LOGE_ONE_STR("create intance parter napi value failed!"); return false; } return true; @@ -278,43 +278,43 @@ static napi_value ConvertEccCommParamsSpecToNapiValue(napi_env env, HcfEccCommPa { if (!CheckEccCommonParamSpec(env, blob)) { napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "Invalid blob!")); - LOGE("Invalid blob!"); + LOGE_ONE_STR("Invalid blob!"); return NapiGetNull(env); } napi_value instance; napi_status status = napi_create_object(env, &instance); if (status != napi_ok) { napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "create object failed!")); - LOGE("create object failed!"); + LOGE_ONE_STR("create object failed!"); return NapiGetNull(env); } napi_value point = ConvertEccCommonParamPointToNapiValue(env, blob); if (point == NapiGetNull(env)) { napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "covert commonParam failed!")); - LOGE("Covert commonParam failed!"); + LOGE_ONE_STR("Covert commonParam failed!"); return NapiGetNull(env); } napi_value field = ConvertEccCommonParamFieldFpToNapiValue(env, blob); if (field == NapiGetNull(env)) { napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "covert commonParam fieldFp failed!")); - LOGE("Covert commonParam fieldFp failed!"); + LOGE_ONE_STR("Covert commonParam fieldFp failed!"); return NapiGetNull(env); } if (!BuildInstanceParterToNapiValue(env, blob, &instance)) { napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "build object failed!")); - LOGE("Build object failed!"); + LOGE_ONE_STR("Build object failed!"); return NapiGetNull(env); } status = napi_set_named_property(env, instance, "field", field); if (status != napi_ok) { napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "set fieldFp failed!")); - LOGE("set fieldFp failed!"); + LOGE_ONE_STR("set fieldFp failed!"); return NapiGetNull(env); } status = napi_set_named_property(env, instance, "g", point); if (status != napi_ok) { napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "set g failed!")); - LOGE("set g failed!"); + LOGE_ONE_STR("set g failed!"); return NapiGetNull(env); } return instance; @@ -329,21 +329,21 @@ napi_value NapiECCKeyUtil::JsGenECCCommonParamsSpec(napi_env env, napi_callback_ if (argc != expectedArgc) { napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "The input args num is invalid.")); - LOGE("The input args num is invalid."); + LOGE_ONE_STR("The input args num is invalid."); return nullptr; } std::string algName; if (!GetStringFromJSParams(env, argv[0], algName)) { napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "failed to get algoName.")); - LOGE("failed to get algoName."); + LOGE_ONE_STR("failed to get algoName."); return NapiGetNull(env); } HcfEccCommParamsSpec *eccCommParamsSpec = nullptr; if (HcfEccKeyUtilCreate(algName.c_str(), &eccCommParamsSpec) != HCF_SUCCESS) { napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "create c generator fail.")); - LOGE("create c generator fail."); + LOGE_ONE_STR("create c generator fail."); return NapiGetNull(env); } napi_value instance = ConvertEccCommParamsSpecToNapiValue(env, eccCommParamsSpec); @@ -360,21 +360,21 @@ napi_value NapiECCKeyUtil::JsConvertPoint(napi_env env, napi_callback_info info) napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr); if (argc != expectedArgc) { - LOGE("The input args num is invalid."); + LOGE_ONE_STR("The input args num is invalid."); napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "The input args num is invalid.")); return nullptr; } std::string curveName; if (!GetStringFromJSParams(env, argv[PARAM0], curveName)) { - LOGE("failed to get curveName."); + LOGE_ONE_STR("failed to get curveName."); napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "failed to get curveName.")); return nullptr; } HcfBlob *pointBlob = GetBlobFromNapiUint8Arr(env, argv[PARAM1]); if (pointBlob == nullptr) { - LOGE("failed to get point blob."); + LOGE_ONE_STR("failed to get point blob."); napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "failed to get point blob.")); return nullptr; } @@ -382,7 +382,7 @@ napi_value NapiECCKeyUtil::JsConvertPoint(napi_env env, napi_callback_info info) HcfPoint point; HcfResult ret = HcfConvertPoint(curveName.c_str(), pointBlob, &point); if (ret != HCF_SUCCESS) { - LOGE("failed to convert point."); + LOGE_ONE_STR("failed to convert point."); HcfBlobDataFree(pointBlob); HcfFree(pointBlob); napi_throw(env, GenerateBusinessError(env, ret, "failed to convert point.")); @@ -403,28 +403,28 @@ napi_value NapiECCKeyUtil::JsGetEncodedPoint(napi_env env, napi_callback_info in napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr); if (argc != expectedArgc) { - LOGE("The input args num is invalid."); + LOGE_ONE_STR("The input args num is invalid."); napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "The input args num is invalid.")); return nullptr; } std::string curveName; if (!GetStringFromJSParams(env, argv[PARAM0], curveName)) { - LOGE("failed to get curveName."); + LOGE_ONE_STR("failed to get curveName."); napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "failed to get curveName.")); return nullptr; } HcfPoint point; if (!GetPointFromNapiValue(env, argv[PARAM1], &point)) { - LOGE("failed to get point."); + LOGE_ONE_STR("failed to get point."); napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "failed to get point.")); return nullptr; } std::string format; if (!GetStringFromJSParams(env, argv[PARAM2], format)) { - LOGE("failed to get format."); + LOGE_ONE_STR("failed to get format."); FreeEcPointMem(&point); napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "failed to get format.")); return nullptr; @@ -433,7 +433,7 @@ napi_value NapiECCKeyUtil::JsGetEncodedPoint(napi_env env, napi_callback_info in HcfBlob returnBlob; HcfResult ret = HcfGetEncodedPoint(curveName.c_str(), &point, format.c_str(), &returnBlob); if (ret != HCF_SUCCESS) { - LOGE("fail to get point data."); + LOGE_ONE_STR("fail to get point data."); FreeEcPointMem(&point); napi_throw(env, GenerateBusinessError(env, ret, "failed to get point data.")); return nullptr; diff --git a/frameworks/js/napi/crypto/src/napi_init.cpp b/frameworks/js/napi/crypto/src/napi_init.cpp index b36f0d3db991d60887b0b6a86de7b355d6161178..69f275016a611efb1873fa5277ba52be7f652022 100644 --- a/frameworks/js/napi/crypto/src/napi_init.cpp +++ b/frameworks/js/napi/crypto/src/napi_init.cpp @@ -203,7 +203,7 @@ static void DefineSignSpecItemProperties(napi_env env, napi_value exports) ***********************************************/ static napi_value ModuleExport(napi_env env, napi_value exports) { - LOGD("module init start."); + LOGD_ONE_STR("module init start."); DefineCryptoModeProperties(env, exports); DefineResultCodeProperties(env, exports); @@ -233,7 +233,7 @@ static napi_value ModuleExport(napi_env env, napi_value exports) NapiECCKeyUtil::DefineNapiECCKeyUtilJSClass(env, exports); NapiDHKeyUtil::DefineNapiDHKeyUtilJSClass(env, exports); NapiSm2CryptoUtil::DefineNapiSm2CryptoUtilJSClass(env, exports); - LOGD("module init end."); + LOGD_ONE_STR("module init end."); return exports; } diff --git a/frameworks/js/napi/crypto/src/napi_kdf.cpp b/frameworks/js/napi/crypto/src/napi_kdf.cpp index 9890ae183930ad648356003d75f01170fbbd43bf..46dcd42b70dffa58409ca3356a2af4d45b23c2c8 100644 --- a/frameworks/js/napi/crypto/src/napi_kdf.cpp +++ b/frameworks/js/napi/crypto/src/napi_kdf.cpp @@ -135,7 +135,7 @@ static void KdfGenSecretExecute(napi_env env, void *data) HcfKdf *kdf = context->kdf; context->errCode = kdf->generateSecret(kdf, context->paramsSpec); if (context->errCode != HCF_SUCCESS) { - LOGD("[error] KDF generateSecret failed!"); + LOGD_ONE_STR("[error] KDF generateSecret failed!"); context->errMsg = "KDF generateSecret failed"; return; } @@ -157,7 +157,7 @@ static void KdfGenSecretComplete(napi_env env, napi_status status, void *data) } if (returnBlob == nullptr) { - LOGE("returnOutBlob is nullptr!"); + LOGE_ONE_STR("returnOutBlob is nullptr!"); returnBlob = NapiGetNull(env); } if (context->asyncType == ASYNC_CALLBACK) { @@ -176,7 +176,7 @@ static bool GetInt32FromKdfParams(napi_env env, napi_value arg, const std::strin napi_status status = napi_get_named_property(env, arg, name.c_str(), &dataInt); napi_typeof(env, dataInt, &valueType); if ((status != napi_ok) || (dataInt == nullptr) || (valueType == napi_undefined)) { - LOGE("failed to get valid napi int"); + LOGE_ONE_STR("failed to get valid napi int"); return false; } return GetInt32FromJSParams(env, dataInt, retInt); @@ -189,7 +189,7 @@ static bool GetUint64FromKdfParams(napi_env env, napi_value arg, const std::stri napi_status status = napi_get_named_property(env, arg, name.c_str(), &dataInt); napi_typeof(env, dataInt, &valueType); if ((status != napi_ok) || (dataInt == nullptr) || (valueType == napi_undefined)) { - LOGE("failed to get valid napi int"); + LOGE_ONE_STR("failed to get valid napi int"); return false; } return GetUint64FromJSParams(env, dataInt, retInt); @@ -206,25 +206,25 @@ static bool GetCharArrayFromUint8Arr(napi_env env, napi_value data, HcfBlob *ret napi_status status = napi_get_typedarray_info(env, data, &arrayType, &length, reinterpret_cast(&rawData), &arrayBuffer, &offset); if ((status != napi_ok)) { - LOGE("failed to get valid rawData."); + LOGE_ONE_STR("failed to get valid rawData."); return false; } if (arrayType != napi_uint8_array) { - LOGE("input data is not uint8 array."); + LOGE_ONE_STR("input data is not uint8 array."); return false; } // input empty uint8Arr, ex: new Uint8Arr(), the length is 0 and rawData is nullptr; if ((length == 0) || (rawData == nullptr)) { - LOGD("napi Uint8Arr is null"); + LOGD_ONE_STR("napi Uint8Arr is null"); return true; } if (length > INT_MAX) { - LOGE("Beyond the size"); + LOGE_ONE_STR("Beyond the size"); return false; } uint8_t *tmp = static_cast(HcfMalloc(length, 0)); if (tmp == nullptr) { - LOGE("malloc blob data failed!"); + LOGE_ONE_STR("malloc blob data failed!"); return false; } (void)memcpy_s(tmp, length, rawData, length); @@ -237,24 +237,24 @@ static bool GetCharArrayFromJsString(napi_env env, napi_value arg, HcfBlob *retB { size_t length = 0; if (napi_get_value_string_utf8(env, arg, nullptr, 0, &length) != napi_ok) { - LOGE("can not get char string length"); + LOGE_ONE_STR("can not get char string length"); return false; } if (length > INT_MAX) { - LOGE("password length should not exceed INT_MAX"); + LOGE_ONE_STR("password length should not exceed INT_MAX"); return false; } if (length == 0) { - LOGD("empty string"); + LOGD_ONE_STR("empty string"); return true; } char *tmpPassword = static_cast(HcfMalloc(length + 1, 0)); if (tmpPassword == nullptr) { - LOGE("malloc string failed"); + LOGE_ONE_STR("malloc string failed"); return false; } if (napi_get_value_string_utf8(env, arg, tmpPassword, (length + 1), &length) != napi_ok) { - LOGE("can not get char string value"); + LOGE_ONE_STR("can not get char string value"); HcfFree(tmpPassword); return false; } @@ -270,17 +270,17 @@ static bool GetKeyOrPwdFromKdfParams(napi_env env, napi_value arg, const std::st napi_status status = napi_get_named_property(env, arg, name.c_str(), &data); napi_typeof(env, data, &valueType); if ((status != napi_ok) || (data == nullptr) || (valueType == napi_undefined)) { - LOGE("failed to get valid password"); + LOGE_ONE_STR("failed to get valid password"); return false; } if (valueType == napi_string) { if (GetCharArrayFromJsString(env, data, retBlob) != true) { - LOGE("get char string failed"); + LOGE_ONE_STR("get char string failed"); return false; } } else { if (GetCharArrayFromUint8Arr(env, data, retBlob) != true) { - LOGE("get uint8arr failed"); + LOGE_ONE_STR("get uint8arr failed"); return false; } } @@ -295,7 +295,7 @@ static HcfBlob *GetBlobFromKdfParamsSpec(napi_env env, napi_value arg, const std napi_status status = napi_get_named_property(env, arg, name.c_str(), &data); napi_typeof(env, data, &valueType); if ((status != napi_ok) || (data == nullptr) || (valueType == napi_undefined)) { - LOGE("failed to get valid salt"); + LOGE_ONE_STR("failed to get valid salt"); return nullptr; } @@ -340,16 +340,16 @@ static bool GetPBKDF2ParamsSpec(napi_env env, napi_value arg, HcfKdfParamsSpec * int keySize = -1; if (!GetInt32FromKdfParams(env, arg, PBKDF2_PARAMS_ITER, iter) || !GetInt32FromKdfParams(env, arg, KDF_PARAMS_KEY_SIZE, keySize)) { - LOGE("failed to get valid num"); + LOGE_ONE_STR("failed to get valid num"); return false; } if (iter <= 0 || keySize <= 0) { - LOGE("iter and keySize should larger than 0"); + LOGE_ONE_STR("iter and keySize should larger than 0"); return false; } HcfBlob out = { .data = static_cast(HcfMalloc(keySize, 0)), .len = keySize }; if (out.data == nullptr) { - LOGE("output malloc failed!"); + LOGE_ONE_STR("output malloc failed!"); return false; } HcfBlob tmpPassword = { .data = nullptr, .len = 0 }; @@ -358,19 +358,19 @@ static bool GetPBKDF2ParamsSpec(napi_env env, napi_value arg, HcfKdfParamsSpec * do { // get password if (!GetKeyOrPwdFromKdfParams(env, arg, PBKDF2_PARAMS_PASSWORD, &tmpPassword)) { - LOGE("failed to get password"); + LOGE_ONE_STR("failed to get password"); break; } // get salt attribute salt = GetBlobFromKdfParamsSpec(env, arg, KDF_PARAMS_SALT); if (salt == nullptr) { - LOGE("fail to get salt"); + LOGE_ONE_STR("fail to get salt"); break; } // malloc params tmp = static_cast(HcfMalloc(sizeof(HcfPBKDF2ParamsSpec), 0)); if (tmp == nullptr) { - LOGE("pbkdf2 spec malloc failed!"); + LOGE_ONE_STR("pbkdf2 spec malloc failed!"); break; } SetPBKDF2ParamsSpecAttribute(iter, out, salt, tmpPassword, tmp); @@ -390,16 +390,16 @@ static bool GetHkdfParamsSpec(napi_env env, napi_value arg, HcfKdfParamsSpec **p { int keySize = -1; if (!GetInt32FromKdfParams(env, arg, KDF_PARAMS_KEY_SIZE, keySize)) { - LOGE("failed to get valid num"); + LOGE_ONE_STR("failed to get valid num"); return false; } if (keySize <= 0) { - LOGE("keySize should larger than 0"); + LOGE_ONE_STR("keySize should larger than 0"); return false; } HcfBlob out = { .data = static_cast(HcfMalloc(keySize, 0)), .len = keySize }; if (out.data == nullptr) { - LOGE("output malloc failed!"); + LOGE_ONE_STR("output malloc failed!"); return false; } @@ -410,7 +410,7 @@ static bool GetHkdfParamsSpec(napi_env env, napi_value arg, HcfKdfParamsSpec **p do { // get key if (!GetKeyOrPwdFromKdfParams(env, arg, HKDF_PARAMS_KEY, &key)) { - LOGE("failed to get key"); + LOGE_ONE_STR("failed to get key"); break; } @@ -418,14 +418,14 @@ static bool GetHkdfParamsSpec(napi_env env, napi_value arg, HcfKdfParamsSpec **p info = GetBlobFromKdfParamsSpec(env, arg, HKDF_PARAMS_INFO); salt = GetBlobFromKdfParamsSpec(env, arg, KDF_PARAMS_SALT); if (info == nullptr || salt == nullptr) { - LOGE("fail to get info or salt"); + LOGE_ONE_STR("fail to get info or salt"); break; } // malloc tmpParams tmpParams = static_cast(HcfMalloc(sizeof(HcfHkdfParamsSpec), 0)); if (tmpParams == nullptr) { - LOGE("hkdf spec malloc failed!"); + LOGE_ONE_STR("hkdf spec malloc failed!"); break; } SetHkdfParamsSpecAttribute(out, salt, key, info, tmpParams); @@ -450,19 +450,19 @@ static bool AllocateAndSetScryptParams(napi_env env, napi_value arg, HcfBlob &ou HcfBlob passPhrase = { .data = nullptr, .len = 0 }; do { if (!GetKeyOrPwdFromKdfParams(env, arg, SCRYPT_PASSPHRASE, &passPhrase)) { - LOGE("failed to get passPhrase"); + LOGE_ONE_STR("failed to get passPhrase"); break; } salt = GetBlobFromKdfParamsSpec(env, arg, KDF_PARAMS_SALT); if (salt == nullptr) { - LOGE("fail to get salt"); + LOGE_ONE_STR("fail to get salt"); break; } tmpParams = static_cast(HcfMalloc(sizeof(HcfScryptParamsSpec), 0)); if (tmpParams == nullptr) { - LOGE("scrypt spec malloc failed!"); + LOGE_ONE_STR("scrypt spec malloc failed!"); break; } @@ -481,11 +481,11 @@ static bool GetScryptParamsSpec(napi_env env, napi_value arg, HcfKdfParamsSpec * { int keySize = -1; if (!GetInt32FromKdfParams(env, arg, KDF_PARAMS_KEY_SIZE, keySize)) { - LOGE("failed to get valid num"); + LOGE_ONE_STR("failed to get valid num"); return false; } if (keySize <= 0) { - LOGE("keySize should larger than 0"); + LOGE_ONE_STR("keySize should larger than 0"); return false; } @@ -495,18 +495,18 @@ static bool GetScryptParamsSpec(napi_env env, napi_value arg, HcfKdfParamsSpec * uint64_t maxMemory = 0; if (!GetUint64FromKdfParams(env, arg, SCRYPT_N, n) || !GetUint64FromKdfParams(env, arg, SCRYPT_R, r) || !GetUint64FromKdfParams(env, arg, SCRYPT_P, p) || !GetUint64FromKdfParams(env, arg, SCRYPT_MEMORY, maxMemory)) { - LOGE("failed to get valid num"); + LOGE_ONE_STR("failed to get valid num"); return false; } if (n < 0 || r < 0 || p < 0 || maxMemory < 0) { - LOGE("n, r, p, or maxMemory cannot be negative number."); + LOGE_ONE_STR("n, r, p, or maxMemory cannot be negative number."); return false; } HcfBlob out = { .data = static_cast(HcfMalloc(keySize, 0)), .len = keySize }; if (out.data == nullptr) { - LOGE("output malloc failed!"); + LOGE_ONE_STR("output malloc failed!"); return false; } @@ -529,19 +529,19 @@ static bool GetKdfParamsSpec(napi_env env, napi_value arg, HcfKdfParamsSpec **pa napi_value data = nullptr; napi_valuetype valueType = napi_undefined; if ((env == nullptr) || (arg == nullptr) || (params == nullptr)) { - LOGE("Invalid params!"); + LOGE_ONE_STR("Invalid params!"); return false; } napi_status status = napi_get_named_property(env, arg, ALGO_PARAMS.c_str(), &data); napi_typeof(env, data, &valueType); if ((status != napi_ok) || (data == nullptr) || (valueType == napi_undefined)) { - LOGE("failed to get valid algo name!"); + LOGE_ONE_STR("failed to get valid algo name!"); return false; } std::string algoName; if (!GetStringFromJSParams(env, data, algoName)) { - LOGE("GetStringFromJSParams failed!"); + LOGE_ONE_STR("GetStringFromJSParams failed!"); return false; } if (algoName.compare(PBKDF2_ALG_NAME) == 0) { @@ -551,7 +551,7 @@ static bool GetKdfParamsSpec(napi_env env, napi_value arg, HcfKdfParamsSpec **pa } else if (algoName.compare(SCRYPT_ALG_NAME) == 0) { return GetScryptParamsSpec(env, arg, params); } else { - LOGE("Not support that alg"); + LOGE_ONE_STR("Not support that alg"); return false; } } @@ -564,27 +564,27 @@ static bool BuildKdfGenSecretCtx(napi_env env, napi_callback_info info, KdfCtx * napi_value argv[ARGS_SIZE_TWO] = { nullptr }; napi_get_cb_info(env, info, &argc, argv, &thisVar, nullptr); if ((argc != expectedArgsCount) && (argc != expectedArgsCount - CALLBACK_SIZE)) { - LOGE("The arguments count is not expected!"); + LOGE_ONE_STR("The arguments count is not expected!"); return false; } NapiKdf *napiKdf = nullptr; napi_status status = napi_unwrap(env, thisVar, reinterpret_cast(&napiKdf)); if (status != napi_ok || napiKdf == nullptr) { - LOGE("failed to unwrap NapiKdf obj!"); + LOGE_ONE_STR("failed to unwrap NapiKdf obj!"); return false; } context->kdf = napiKdf->GetKdf(); if (!GetKdfParamsSpec(env, argv[PARAM0], &(context->paramsSpec))) { - LOGE("get kdf paramsspec failed!"); + LOGE_ONE_STR("get kdf paramsspec failed!"); return false; } context->asyncType = isCallback(env, argv[expectedArgsCount - 1], argc, expectedArgsCount) ? ASYNC_CALLBACK : ASYNC_PROMISE; if (napi_create_reference(env, thisVar, 1, &context->kdfRef) != napi_ok) { - LOGE("create kdf ref failed when derive secret key using kdf!"); + LOGE_ONE_STR("create kdf ref failed when derive secret key using kdf!"); return false; } @@ -639,13 +639,13 @@ napi_value NapiKdf::JsKdfGenerateSecret(napi_env env, napi_callback_info info) KdfCtx *context = static_cast(HcfMalloc(sizeof(KdfCtx), 0)); if (context == nullptr) { napi_throw(env, GenerateBusinessError(env, HCF_ERR_MALLOC, "malloc context failed")); - LOGE("malloc context failed!"); + LOGE_ONE_STR("malloc context failed!"); return nullptr; } if (!BuildKdfGenSecretCtx(env, info, context)) { napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "build context fail.")); - LOGE("build context fail."); + LOGE_ONE_STR("build context fail."); FreeCryptoFwkCtx(env, context); return nullptr; } @@ -667,7 +667,7 @@ static napi_value NewKdfJsGenSecretSyncWork(napi_env env, HcfKdfParamsSpec *para returnBlob = ConvertBlobToNapiValue(env, &(params->output)); } if (returnBlob == nullptr) { - LOGE("returnBlob is nullptr!"); + LOGE_ONE_STR("returnBlob is nullptr!"); napi_throw(env, GenerateBusinessError(env, HCF_ERR_NAPI, "returnBlob is nullptr!")); returnBlob = NapiGetNull(env); } @@ -683,26 +683,26 @@ napi_value NapiKdf::JsKdfGenerateSecretSync(napi_env env, napi_callback_info inf napi_value argv[ARGS_SIZE_ONE] = { nullptr }; napi_get_cb_info(env, info, &argc, argv, &thisVar, nullptr); if (argc != ARGS_SIZE_ONE) { - LOGE("The arguments count is not expected!"); + LOGE_ONE_STR("The arguments count is not expected!"); napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "The arguments count is not expected!")); return nullptr; } NapiKdf *napiKdf = nullptr; napi_status status = napi_unwrap(env, thisVar, reinterpret_cast(&napiKdf)); if (status != napi_ok || napiKdf == nullptr) { - LOGE("failed to unwrap NapiKdf obj!"); + LOGE_ONE_STR("failed to unwrap NapiKdf obj!"); napi_throw(env, GenerateBusinessError(env, HCF_ERR_NAPI, "failed to unwrap NapiKdf obj!")); return nullptr; } HcfKdf *kdf = napiKdf->GetKdf(); if (kdf == nullptr) { - LOGE("fail to get kdf obj!"); + LOGE_ONE_STR("fail to get kdf obj!"); napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "fail to get kdf obj!")); return nullptr; } HcfKdfParamsSpec *paramsSpec = nullptr; if (!GetKdfParamsSpec(env, argv[PARAM0], ¶msSpec)) { - LOGE("get kdf paramsspec failed!"); + LOGE_ONE_STR("get kdf paramsspec failed!"); napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "get kdf paramsspec failed!")); FreeKdfParamsSpec(paramsSpec); paramsSpec = nullptr; @@ -710,7 +710,7 @@ napi_value NapiKdf::JsKdfGenerateSecretSync(napi_env env, napi_callback_info inf } HcfResult errCode = kdf->generateSecret(kdf, paramsSpec); if (errCode != HCF_SUCCESS) { - LOGE("KDF generateSecret failed!"); + LOGE_ONE_STR("KDF generateSecret failed!"); napi_throw(env, GenerateBusinessError(env, errCode, "KDF generateSecret failed!")); FreeKdfParamsSpec(paramsSpec); return nullptr; @@ -727,13 +727,13 @@ napi_value NapiKdf::JsGetAlgorithm(napi_env env, napi_callback_info info) napi_get_cb_info(env, info, nullptr, nullptr, &thisVar, nullptr); napi_status status = napi_unwrap(env, thisVar, reinterpret_cast(&napiKdf)); if (status != napi_ok || napiKdf == nullptr) { - LOGE("failed to unwrap NapiKdf obj!"); + LOGE_ONE_STR("failed to unwrap NapiKdf obj!"); return nullptr; } HcfKdf *kdf = napiKdf->GetKdf(); if (kdf == nullptr) { - LOGE("fail to get kdf obj!"); + LOGE_ONE_STR("fail to get kdf obj!"); return nullptr; } @@ -758,20 +758,20 @@ napi_value NapiKdf::CreateJsKdf(napi_env env, napi_callback_info info) napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr); if (argc != expectedArgc) { napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "The input args num is invalid.")); - LOGE("The input args num is invalid."); + LOGE_ONE_STR("The input args num is invalid."); return nullptr; } std::string algoName; if (!GetStringFromJSParams(env, argv[PARAM0], algoName)) { napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "Failed to get algorithm.")); - LOGE("Failed to get algorithm."); + LOGE_ONE_STR("Failed to get algorithm."); return nullptr; } HcfKdf *kdf = nullptr; HcfResult res = HcfKdfCreate(algoName.c_str(), &kdf); if (res != HCF_SUCCESS) { napi_throw(env, GenerateBusinessError(env, res, "create C obj failed.")); - LOGE("create c kdf obj failed."); + LOGE_ONE_STR("create c kdf obj failed."); return nullptr; } napi_value instance = nullptr; @@ -782,7 +782,7 @@ napi_value NapiKdf::CreateJsKdf(napi_env env, napi_callback_info info) if (napiKdf == nullptr) { napi_throw(env, GenerateBusinessError(env, HCF_ERR_MALLOC, "new kdf napi obj failed.")); HcfObjDestroy(kdf); - LOGE("create kdf napi obj failed"); + LOGE_ONE_STR("create kdf napi obj failed"); return nullptr; } napi_status status = napi_wrap(env, instance, napiKdf, @@ -794,7 +794,7 @@ napi_value NapiKdf::CreateJsKdf(napi_env env, napi_callback_info info) if (status != napi_ok) { napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "failed to wrap NapiKdf obj!")); delete napiKdf; - LOGE("failed to wrap NapiKdf obj!"); + LOGE_ONE_STR("failed to wrap NapiKdf obj!"); return nullptr; } return instance; diff --git a/frameworks/js/napi/crypto/src/napi_key.cpp b/frameworks/js/napi/crypto/src/napi_key.cpp index f6a816d7df28d704e8322aa3a40d8000fbe16f7f..039b46b4505bfa8467f85b7ce4ee10799f388c79 100644 --- a/frameworks/js/napi/crypto/src/napi_key.cpp +++ b/frameworks/js/napi/crypto/src/napi_key.cpp @@ -45,13 +45,13 @@ napi_value NapiKey::JsGetAlgorithm(napi_env env, napi_callback_info info) napi_status status = napi_unwrap(env, thisVar, reinterpret_cast(&napiKey)); if (status != napi_ok || napiKey == nullptr) { napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "failed to unwrap napi key obj.")); - LOGE("failed to unwrap napi key obj."); + LOGE_ONE_STR("failed to unwrap napi key obj."); return nullptr; } HcfKey *key = napiKey->GetHcfKey(); if (key == nullptr) { napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "fail to get key obj!")); - LOGE("fail to get key obj!"); + LOGE_ONE_STR("fail to get key obj!"); return nullptr; } @@ -70,13 +70,13 @@ napi_value NapiKey::JsGetFormat(napi_env env, napi_callback_info info) napi_status status = napi_unwrap(env, thisVar, reinterpret_cast(&napiKey)); if (status != napi_ok || napiKey == nullptr) { napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "failed to unwrap napi key obj.")); - LOGE("failed to unwrap napi key obj."); + LOGE_ONE_STR("failed to unwrap napi key obj."); return nullptr; } HcfKey *key = napiKey->GetHcfKey(); if (key == nullptr) { napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "fail to get key obj!")); - LOGE("fail to get key obj!"); + LOGE_ONE_STR("fail to get key obj!"); return nullptr; } @@ -95,13 +95,13 @@ napi_value NapiKey::JsGetEncoded(napi_env env, napi_callback_info info) napi_status status = napi_unwrap(env, thisVar, reinterpret_cast(&napiKey)); if (status != napi_ok || napiKey == nullptr) { napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "failed to unwrap napi key obj.")); - LOGE("failed to unwrap napi key obj."); + LOGE_ONE_STR("failed to unwrap napi key obj."); return nullptr; } HcfKey *key = napiKey->GetHcfKey(); if (key == nullptr) { napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "fail to get key obj!")); - LOGE("fail to get key obj!"); + LOGE_ONE_STR("fail to get key obj!"); return nullptr; } @@ -109,7 +109,7 @@ napi_value NapiKey::JsGetEncoded(napi_env env, napi_callback_info info) HcfResult res = key->getEncoded(key, &blob); if (res != HCF_SUCCESS) { napi_throw(env, GenerateBusinessError(env, res, "getEncoded failed.")); - LOGD("[error] getEncoded failed!"); + LOGD_ONE_STR("[error] getEncoded failed!"); return nullptr; } napi_value instance = ConvertBlobToNapiValue(env, &blob); diff --git a/frameworks/js/napi/crypto/src/napi_key_agreement.cpp b/frameworks/js/napi/crypto/src/napi_key_agreement.cpp index aa9ab989ca9fe021a0f78d4a1013016f7c2f36fd..5d69a7de00005419186f0371a6e93df60a6ef389 100644 --- a/frameworks/js/napi/crypto/src/napi_key_agreement.cpp +++ b/frameworks/js/napi/crypto/src/napi_key_agreement.cpp @@ -93,17 +93,17 @@ static bool CreateKeyAgreementRef(napi_env env, napi_value thisVar, napi_value p KeyAgreementCtx *ctx) { if (napi_create_reference(env, thisVar, 1, &ctx->keyAgreementRef) != napi_ok) { - LOGE("create key agreement ref failed when derive secret key using key agreement!"); + LOGE_ONE_STR("create key agreement ref failed when derive secret key using key agreement!"); return false; } if (napi_create_reference(env, priKey, 1, &ctx->priKeyRef) != napi_ok) { - LOGE("create private key ref failed when derive secret key using key agreement!"); + LOGE_ONE_STR("create private key ref failed when derive secret key using key agreement!"); return false; } if (napi_create_reference(env, pubKey, 1, &ctx->pubKeyRef) != napi_ok) { - LOGE("create public key ref failed when derive secret key using key agreement!"); + LOGE_ONE_STR("create public key ref failed when derive secret key using key agreement!"); return false; } @@ -126,7 +126,7 @@ static bool BuildKeyAgreementJsCtx(napi_env env, napi_callback_info info, KeyAgr NapiKeyAgreement *napiKeyAgreement = nullptr; napi_status status = napi_unwrap(env, thisVar, reinterpret_cast(&napiKeyAgreement)); if (status != napi_ok || napiKeyAgreement == nullptr) { - LOGE("failed to unwrap napi verify obj."); + LOGE_ONE_STR("failed to unwrap napi verify obj."); return false; } @@ -134,7 +134,7 @@ static bool BuildKeyAgreementJsCtx(napi_env env, napi_callback_info info, KeyAgr NapiPriKey *napiPriKey = nullptr; status = napi_unwrap(env, argv[index], reinterpret_cast(&napiPriKey)); if (status != napi_ok || napiPriKey == nullptr) { - LOGE("failed to unwrap priKey verify obj."); + LOGE_ONE_STR("failed to unwrap priKey verify obj."); return false; } @@ -142,7 +142,7 @@ static bool BuildKeyAgreementJsCtx(napi_env env, napi_callback_info info, KeyAgr NapiPubKey *napiPubKey = nullptr; status = napi_unwrap(env, argv[index], reinterpret_cast(&napiPubKey)); if (status != napi_ok || napiPubKey == nullptr) { - LOGE("failed to unwrap napi pubKey obj."); + LOGE_ONE_STR("failed to unwrap napi pubKey obj."); return false; } @@ -197,7 +197,7 @@ static void KeyAgreementAsyncWorkProcess(napi_env env, void *data) ctx->errCode = ctx->keyAgreement->generateSecret(ctx->keyAgreement, ctx->priKey, ctx->pubKey, &ctx->returnSecret); if (ctx->errCode != HCF_SUCCESS) { - LOGD("[error] generate secret fail."); + LOGD_ONE_STR("[error] generate secret fail."); ctx->errMsg = "generate secret fail."; } } @@ -265,13 +265,13 @@ napi_value NapiKeyAgreement::JsGenerateSecret(napi_env env, napi_callback_info i KeyAgreementCtx *ctx = static_cast(HcfMalloc(sizeof(KeyAgreementCtx), 0)); if (ctx == nullptr) { napi_throw(env, GenerateBusinessError(env, HCF_ERR_MALLOC, "create context fail.")); - LOGE("create context fail."); + LOGE_ONE_STR("create context fail."); return nullptr; } if (!BuildKeyAgreementJsCtx(env, info, ctx)) { napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "build context fail.")); - LOGE("build context fail."); + LOGE_ONE_STR("build context fail."); FreeKeyAgreementCtx(env, ctx); return nullptr; } @@ -284,23 +284,23 @@ static HcfResult GetPriKeyAndPubKeyFromParam(napi_env env, napi_value priKeyPara { napi_status status = napi_unwrap(env, priKeyParam, reinterpret_cast(napiPriKey)); if (status != napi_ok) { - LOGE("failed to unwrap priKey verify obj."); + LOGE_ONE_STR("failed to unwrap priKey verify obj."); return HCF_ERR_NAPI; } if (*napiPriKey == nullptr) { - LOGE("priKey param is nullptr."); + LOGE_ONE_STR("priKey param is nullptr."); return HCF_ERR_NAPI; } status = napi_unwrap(env, pubKeyParam, reinterpret_cast(napiPubKey)); if (status != napi_ok) { - LOGE("failed to unwrap pubKey verify obj."); + LOGE_ONE_STR("failed to unwrap pubKey verify obj."); return HCF_ERR_NAPI; } if (*napiPubKey == nullptr) { - LOGE("pubKey param is nullptr."); + LOGE_ONE_STR("pubKey param is nullptr."); return HCF_ERR_NAPI; } @@ -322,7 +322,7 @@ napi_value NapiKeyAgreement::JsGenerateSecretSync(napi_env env, napi_callback_in NapiKeyAgreement *napiKeyAgreement = nullptr; napi_status status = napi_unwrap(env, thisVar, reinterpret_cast(&napiKeyAgreement)); if (status != napi_ok || napiKeyAgreement == nullptr) { - LOGE("failed to unwrap napi verify obj."); + LOGE_ONE_STR("failed to unwrap napi verify obj."); napi_throw(env, GenerateBusinessError(env, HCF_ERR_NAPI, "failed to unwrap napi verify obj.")); return nullptr; } @@ -341,7 +341,7 @@ napi_value NapiKeyAgreement::JsGenerateSecretSync(napi_env env, napi_callback_in HcfBlob returnSecret = { .data = nullptr, .len = 0 }; ret = keyAgreement->generateSecret(keyAgreement, priKey, pubKey, &returnSecret); if (ret != HCF_SUCCESS) { - LOGE("generate secret fail."); + LOGE_ONE_STR("generate secret fail."); napi_throw(env, GenerateBusinessError(env, ret, "generate secret fail.")); return nullptr; } @@ -350,7 +350,7 @@ napi_value NapiKeyAgreement::JsGenerateSecretSync(napi_env env, napi_callback_in ret = ConvertDataBlobToNapiValue(env, &returnSecret, &instance); HcfBlobDataClearAndFree(&returnSecret); if (ret != HCF_SUCCESS) { - LOGE("key agreement convert dataBlob to napi_value failed!"); + LOGE_ONE_STR("key agreement convert dataBlob to napi_value failed!"); napi_throw(env, GenerateBusinessError(env, ret, "key agreement convert dataBlob to napi_value failed!")); return nullptr; } @@ -367,14 +367,14 @@ napi_value NapiKeyAgreement::KeyAgreementConstructor(napi_env env, napi_callback napi_value NapiKeyAgreement::CreateJsKeyAgreement(napi_env env, napi_callback_info info) { - LOGD("Enter CreateJsKeyAgreement..."); + LOGD_ONE_STR("Enter CreateJsKeyAgreement..."); size_t expectedArgc = PARAMS_NUM_ONE; size_t argc = PARAMS_NUM_ONE; napi_value argv[PARAMS_NUM_ONE] = { nullptr }; napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr); if (argc != expectedArgc) { napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "The input args num is invalid.")); - LOGE("The input args num is invalid."); + LOGE_ONE_STR("The input args num is invalid."); return nullptr; } @@ -393,14 +393,14 @@ napi_value NapiKeyAgreement::CreateJsKeyAgreement(napi_env env, napi_callback_in HcfResult res = HcfKeyAgreementCreate(algName.c_str(), &keyAgreement); if (res != HCF_SUCCESS) { napi_throw(env, GenerateBusinessError(env, res, "create c keyAgreement fail.")); - LOGE("create c keyAgreement fail."); + LOGE_ONE_STR("create c keyAgreement fail."); return nullptr; } NapiKeyAgreement *napiKeyAgreement = new (std::nothrow) NapiKeyAgreement(keyAgreement); if (napiKeyAgreement == nullptr) { napi_throw(env, GenerateBusinessError(env, HCF_ERR_MALLOC, "new napi key agreement failed.")); - LOGE("new napi key agreement failed"); + LOGE_ONE_STR("new napi key agreement failed"); HcfObjDestroy(keyAgreement); return nullptr; } @@ -413,7 +413,7 @@ napi_value NapiKeyAgreement::CreateJsKeyAgreement(napi_env env, napi_callback_in }, nullptr, nullptr); if (status != napi_ok) { napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "failed to wrap napiKeyAgreement obj!")); - LOGE("failed to wrap napiKeyAgreement obj!"); + LOGE_ONE_STR("failed to wrap napiKeyAgreement obj!"); delete napiKeyAgreement; return nullptr; } @@ -429,7 +429,7 @@ napi_value NapiKeyAgreement::JsGetAlgorithm(napi_env env, napi_callback_info inf napi_status status = napi_unwrap(env, thisVar, reinterpret_cast(&napiKeyAgreement)); if (status != napi_ok || napiKeyAgreement == nullptr) { napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "failed to unwrap napiKeyAgreement obj!")); - LOGE("failed to unwrap napiKeyAgreement obj!"); + LOGE_ONE_STR("failed to unwrap napiKeyAgreement obj!"); return nullptr; } HcfKeyAgreement *keyAgreement = napiKeyAgreement->GetKeyAgreement(); diff --git a/frameworks/js/napi/crypto/src/napi_key_pair.cpp b/frameworks/js/napi/crypto/src/napi_key_pair.cpp index 9c5586d876f07796308f43564e7203d8d769c295..8c19825f64ea8811b09058d7571b3f375eb86bed 100644 --- a/frameworks/js/napi/crypto/src/napi_key_pair.cpp +++ b/frameworks/js/napi/crypto/src/napi_key_pair.cpp @@ -48,7 +48,7 @@ static bool WrapPubKey(napi_env env, napi_value instance, HcfPubKey *key) { NapiPubKey *napiPubKey = new (std::nothrow) NapiPubKey(key); if (napiPubKey == nullptr) { - LOGE("new napi pub key failed"); + LOGE_ONE_STR("new napi pub key failed"); return false; } napi_value pubKey = napiPubKey->ConvertToJsPubKey(env); @@ -61,7 +61,7 @@ static bool WrapPubKey(napi_env env, napi_value instance, HcfPubKey *key) return; }, nullptr, nullptr); if (status != napi_ok) { - LOGE("failed to wrap napiPubKey obj!"); + LOGE_ONE_STR("failed to wrap napiPubKey obj!"); delete napiPubKey; return false; } @@ -73,7 +73,7 @@ static bool WrapPriKey(napi_env env, napi_value instance, HcfPriKey *key) { NapiPriKey *napiPriKey = new (std::nothrow) NapiPriKey(key); if (napiPriKey == nullptr) { - LOGE("new napi pri key failed"); + LOGE_ONE_STR("new napi pri key failed"); return false; } napi_value priKey = napiPriKey->ConvertToJsPriKey(env); @@ -86,7 +86,7 @@ static bool WrapPriKey(napi_env env, napi_value instance, HcfPriKey *key) return; }, nullptr, nullptr); if (status != napi_ok) { - LOGE("failed to wrap napiPriKey obj!"); + LOGE_ONE_STR("failed to wrap napiPriKey obj!"); delete napiPriKey; return false; } diff --git a/frameworks/js/napi/crypto/src/napi_mac.cpp b/frameworks/js/napi/crypto/src/napi_mac.cpp index 858283a18a612dfc65710ee8ec675a62ee73a424..6d1911d89704615fba8035230f2647fa57d9ad60 100644 --- a/frameworks/js/napi/crypto/src/napi_mac.cpp +++ b/frameworks/js/napi/crypto/src/napi_mac.cpp @@ -136,7 +136,7 @@ static void MacInitExecute(napi_env env, void *data) HcfSymKey *symKey = context->symKey; context->errCode = macObj->init(macObj, symKey); if (context->errCode != HCF_SUCCESS) { - LOGD("[error] init failed!"); + LOGD_ONE_STR("[error] init failed!"); context->errMsg = "init failed"; } } @@ -161,7 +161,7 @@ static void MacUpdateExecute(napi_env env, void *data) HcfBlob *inBlob = reinterpret_cast(context->inBlob); context->errCode = macObj->update(macObj, inBlob); if (context->errCode != HCF_SUCCESS) { - LOGD("[error] update failed!"); + LOGD_ONE_STR("[error] update failed!"); context->errMsg = "update failed"; } } @@ -185,7 +185,7 @@ static void MacDoFinalExecute(napi_env env, void *data) HcfMac *macObj = context->mac; HcfBlob *outBlob = reinterpret_cast(HcfMalloc(sizeof(HcfBlob), 0)); if (outBlob == nullptr) { - LOGD("[error] outBlob is null!"); + LOGD_ONE_STR("[error] outBlob is null!"); context->errCode = HCF_ERR_MALLOC; context->errMsg = "malloc data blob failed"; return; @@ -193,7 +193,7 @@ static void MacDoFinalExecute(napi_env env, void *data) context->errCode = macObj->doFinal(macObj, outBlob); if (context->errCode != HCF_SUCCESS) { HcfFree(outBlob); - LOGE("doFinal failed!"); + LOGE_ONE_STR("doFinal failed!"); context->errMsg = "doFinal failed"; return; } @@ -205,7 +205,7 @@ static void MacDoFinalComplete(napi_env env, napi_status status, void *data) MacCtx *context = static_cast(data); napi_value returnOutBlob = ConvertBlobToNapiValue(env, context->outBlob); if (returnOutBlob == nullptr) { - LOGE("returnOutBlob is nullptr!"); + LOGE_ONE_STR("returnOutBlob is nullptr!"); returnOutBlob = NapiGetNull(env); } if (context->asyncType == ASYNC_CALLBACK) { @@ -233,25 +233,25 @@ static bool BuildMacJsInitCtx(napi_env env, napi_callback_info info, MacCtx *con NapiSymKey *symKey = nullptr; napi_status status = napi_unwrap(env, argv[PARAM0], reinterpret_cast(&symKey)); if (status != napi_ok || symKey == nullptr) { - LOGE("symKey is null!"); + LOGE_ONE_STR("symKey is null!"); return false; } context->symKey = symKey->GetSymKey(); status = napi_unwrap(env, thisVar, reinterpret_cast(&napiMac)); if (status != napi_ok || napiMac == nullptr) { - LOGE("failed to unwrap napiMac obj!"); + LOGE_ONE_STR("failed to unwrap napiMac obj!"); return false; } context->mac = napiMac->GetMac(); if (napi_create_reference(env, thisVar, 1, &context->macRef) != napi_ok) { - LOGE("create mac ref failed when do mac init!"); + LOGE_ONE_STR("create mac ref failed when do mac init!"); return false; } if (napi_create_reference(env, argv[PARAM0], 1, &context->symKeyRef) != napi_ok) { - LOGE("create sym key ref failed when do mac init!"); + LOGE_ONE_STR("create sym key ref failed when do mac init!"); return false; } @@ -279,19 +279,19 @@ static bool BuildMacJsUpdateCtx(napi_env env, napi_callback_info info, MacCtx *c ASYNC_CALLBACK : ASYNC_PROMISE; context->inBlob = GetBlobFromNapiDataBlob(env, argv[PARAM0]); if (context->inBlob == nullptr) { - LOGE("inBlob is null!"); + LOGE_ONE_STR("inBlob is null!"); return false; } napi_status status = napi_unwrap(env, thisVar, reinterpret_cast(&napiMac)); if (status != napi_ok || napiMac == nullptr) { - LOGE("failed to unwrap napiMac obj!"); + LOGE_ONE_STR("failed to unwrap napiMac obj!"); return false; } context->mac = napiMac->GetMac(); if (napi_create_reference(env, thisVar, 1, &context->macRef) != napi_ok) { - LOGE("create mac ref failed when do mac update!"); + LOGE_ONE_STR("create mac ref failed when do mac update!"); return false; } @@ -319,14 +319,14 @@ static bool BuildMacJsDoFinalCtx(napi_env env, napi_callback_info info, MacCtx * ASYNC_CALLBACK : ASYNC_PROMISE; napi_status status = napi_unwrap(env, thisVar, reinterpret_cast(&napiMac)); if (status != napi_ok || napiMac == nullptr) { - LOGE("failed to unwrap napiMac obj!"); + LOGE_ONE_STR("failed to unwrap napiMac obj!"); return false; } context->mac = napiMac->GetMac(); if (napi_create_reference(env, thisVar, 1, &context->macRef) != napi_ok) { - LOGE("create mac ref failed when do mac final!"); + LOGE_ONE_STR("create mac ref failed when do mac final!"); return false; } @@ -428,13 +428,13 @@ napi_value NapiMac::JsMacInit(napi_env env, napi_callback_info info) MacCtx *context = static_cast(HcfMalloc(sizeof(MacCtx), 0)); if (context == nullptr) { napi_throw(env, GenerateBusinessError(env, HCF_ERR_MALLOC, "malloc context failed")); - LOGE("malloc context failed!"); + LOGE_ONE_STR("malloc context failed!"); return nullptr; } if (!BuildMacJsInitCtx(env, info, context)) { napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "build context fail.")); - LOGE("build context fail."); + LOGE_ONE_STR("build context fail."); FreeCryptoFwkCtx(env, context); return nullptr; } @@ -450,33 +450,33 @@ napi_value NapiMac::JsMacInitSync(napi_env env, napi_callback_info info) napi_value argv[ARGS_SIZE_ONE] = { nullptr }; napi_get_cb_info(env, info, &argc, argv, &thisVar, nullptr); if (argc != ARGS_SIZE_ONE) { - LOGE("The input args num is invalid."); + LOGE_ONE_STR("The input args num is invalid."); napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "The input args num is invalid.")); return nullptr; } NapiSymKey *napiSysKey = nullptr; napi_status status = napi_unwrap(env, argv[PARAM0], reinterpret_cast(&napiSysKey)); if (status != napi_ok || napiSysKey == nullptr) { - LOGE("napiSysKey is null!"); + LOGE_ONE_STR("napiSysKey is null!"); napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "napiSysKey is null!")); return nullptr; } HcfSymKey *symKey = napiSysKey->GetSymKey(); status = napi_unwrap(env, thisVar, reinterpret_cast(&napiMac)); if (status != napi_ok || napiMac == nullptr) { - LOGE("failed to unwrap napiMac obj!"); + LOGE_ONE_STR("failed to unwrap napiMac obj!"); napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "failed to unwrap napiMac obj!")); return nullptr; } HcfMac *mac = napiMac->GetMac(); if (mac == nullptr) { - LOGE("mac is nullptr!"); + LOGE_ONE_STR("mac is nullptr!"); napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "mac is nullptr!")); return nullptr; } HcfResult errCode = mac->init(mac, symKey); if (errCode != HCF_SUCCESS) { - LOGE("mac init failed!"); + LOGE_ONE_STR("mac init failed!"); napi_throw(env, GenerateBusinessError(env, HCF_ERR_CRYPTO_OPERATION, "mac init failed!")); return nullptr; } @@ -490,13 +490,13 @@ napi_value NapiMac::JsMacUpdate(napi_env env, napi_callback_info info) MacCtx *context = static_cast(HcfMalloc(sizeof(MacCtx), 0)); if (context == nullptr) { napi_throw(env, GenerateBusinessError(env, HCF_ERR_MALLOC, "malloc context failed")); - LOGE("malloc context failed!"); + LOGE_ONE_STR("malloc context failed!"); return nullptr; } if (!BuildMacJsUpdateCtx(env, info, context)) { napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "build context fail.")); - LOGE("build context fail."); + LOGE_ONE_STR("build context fail."); FreeCryptoFwkCtx(env, context); return nullptr; } @@ -512,28 +512,28 @@ napi_value NapiMac::JsMacUpdateSync(napi_env env, napi_callback_info info) napi_value argv[ARGS_SIZE_ONE] = { nullptr }; napi_get_cb_info(env, info, &argc, argv, &thisVar, nullptr); if (argc != ARGS_SIZE_ONE) { - LOGE("The input args num is invalid."); + LOGE_ONE_STR("The input args num is invalid."); napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "The input args num is invalid.")); return nullptr; } napi_status status = napi_unwrap(env, thisVar, reinterpret_cast(&napiMac)); if (status != napi_ok || napiMac == nullptr) { - LOGE("failed to unwrap napiMac obj!"); + LOGE_ONE_STR("failed to unwrap napiMac obj!"); napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "failed to unwrap napiMac obj!")); return nullptr; } HcfBlob *inBlob = GetBlobFromNapiDataBlob(env, argv[PARAM0]); if (inBlob == nullptr) { - LOGE("inBlob is null!"); + LOGE_ONE_STR("inBlob is null!"); napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "inBlob is null!")); return nullptr; } HcfMac *mac = napiMac->GetMac(); if (mac == nullptr) { - LOGE("mac is nullptr!"); + LOGE_ONE_STR("mac is nullptr!"); napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "mac is nullptr!")); HcfBlobDataClearAndFree(inBlob); HcfFree(inBlob); @@ -543,7 +543,7 @@ napi_value NapiMac::JsMacUpdateSync(napi_env env, napi_callback_info info) HcfBlobDataClearAndFree(inBlob); HcfFree(inBlob); if (errCode != HCF_SUCCESS) { - LOGE("mac update failed!"); + LOGE_ONE_STR("mac update failed!"); napi_throw(env, GenerateBusinessError(env, HCF_ERR_CRYPTO_OPERATION, "mac update failed!")); return nullptr; } @@ -557,13 +557,13 @@ napi_value NapiMac::JsMacDoFinal(napi_env env, napi_callback_info info) MacCtx *context = static_cast(HcfMalloc(sizeof(MacCtx), 0)); if (context == nullptr) { napi_throw(env, GenerateBusinessError(env, HCF_ERR_MALLOC, "malloc context failed")); - LOGE("malloc context failed!"); + LOGE_ONE_STR("malloc context failed!"); return nullptr; } if (!BuildMacJsDoFinalCtx(env, info, context)) { napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "build context fail.")); - LOGE("build context fail."); + LOGE_ONE_STR("build context fail."); FreeCryptoFwkCtx(env, context); return nullptr; } @@ -578,20 +578,20 @@ napi_value NapiMac::JsMacDoFinalSync(napi_env env, napi_callback_info info) napi_get_cb_info(env, info, nullptr, nullptr, &thisVar, nullptr); napi_status status = napi_unwrap(env, thisVar, reinterpret_cast(&napiMac)); if (status != napi_ok || napiMac == nullptr) { - LOGE("failed to unwrap napiMac obj!"); + LOGE_ONE_STR("failed to unwrap napiMac obj!"); napi_throw(env, GenerateBusinessError(env, HCF_ERR_NAPI, "failed to unwrap napiMac obj.")); return nullptr; } HcfMac *mac = napiMac->GetMac(); if (mac == nullptr) { - LOGE("mac is nullptr!"); + LOGE_ONE_STR("mac is nullptr!"); napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "mac is nullptr!")); return nullptr; } HcfBlob outBlob = { .data = nullptr, .len = 0 }; HcfResult errCode = mac->doFinal(mac, &outBlob); if (errCode != HCF_SUCCESS) { - LOGE("mac doFinal failed!"); + LOGE_ONE_STR("mac doFinal failed!"); napi_throw(env, GenerateBusinessError(env, errCode, "mac doFinal failed!")); HcfBlobDataClearAndFree(&outBlob); return nullptr; @@ -601,7 +601,7 @@ napi_value NapiMac::JsMacDoFinalSync(napi_env env, napi_callback_info info) errCode = ConvertDataBlobToNapiValue(env, &outBlob, &returnOutBlob); HcfBlobDataClearAndFree(&outBlob); if (errCode != HCF_SUCCESS) { - LOGE("mac convert dataBlob to napi_value failed!"); + LOGE_ONE_STR("mac convert dataBlob to napi_value failed!"); napi_throw(env, GenerateBusinessError(env, errCode, "mac convert dataBlob to napi_value failed!")); return nullptr; } @@ -618,14 +618,14 @@ napi_value NapiMac::JsGetMacLength(napi_env env, napi_callback_info info) napi_status status = napi_unwrap(env, thisVar, reinterpret_cast(&napiMac)); if (status != napi_ok || napiMac == nullptr) { napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "failed to unwrap napiMac obj!")); - LOGE("failed to unwrap napiMac obj!"); + LOGE_ONE_STR("failed to unwrap napiMac obj!"); return nullptr; } HcfMac *mac = napiMac->GetMac(); if (mac == nullptr) { napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "fail to get mac obj!")); - LOGE("fail to get mac obj!"); + LOGE_ONE_STR("fail to get mac obj!"); return nullptr; } @@ -654,7 +654,7 @@ static napi_value NapiWrapMac(napi_env env, napi_value instance, NapiMac *macNap if (status != napi_ok) { napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "failed to wrap NapiMac obj!")); delete macNapiObj; - LOGE("failed to wrap NapiMac obj!"); + LOGE_ONE_STR("failed to wrap NapiMac obj!"); return nullptr; } return instance; @@ -665,34 +665,34 @@ static bool GetHmacParamsSpec(napi_env env, napi_value arg, const char *algName, napi_value data = nullptr; napi_valuetype valueType = napi_undefined; if ((env == nullptr) || (arg == nullptr) || (paramsSpec == nullptr)) { - LOGE("Invalid params!"); + LOGE_ONE_STR("Invalid params!"); return false; } napi_status status = napi_get_named_property(env, arg, MD_NAME.c_str(), &data); napi_typeof(env, data, &valueType); if ((status != napi_ok) || (data == nullptr) || (valueType == napi_undefined)) { - LOGE("failed to get valid algo name!"); + LOGE_ONE_STR("failed to get valid algo name!"); return false; } std::string mdName; if (!GetStringFromJSParams(env, data, mdName)) { - LOGE("GetStringFromJSParams failed!"); + LOGE_ONE_STR("GetStringFromJSParams failed!"); return false; } HcfHmacParamsSpec *tmp = static_cast(HcfMalloc(sizeof(HcfHmacParamsSpec), 0)); if (tmp == nullptr) { - LOGE("malloc hmac spec failed!"); + LOGE_ONE_STR("malloc hmac spec failed!"); return false; } char* mdNameCopy = static_cast(HcfMalloc(mdName.length() + 1, 0)); if (mdNameCopy == nullptr) { - LOGE("malloc mdName failed!"); + LOGE_ONE_STR("malloc mdName failed!"); HcfFree(tmp); return false; } if (memcpy_s(mdNameCopy, mdName.length() + 1, mdName.c_str(), mdName.length() + 1) != EOK) { - LOGE("copy mdName failed!"); + LOGE_ONE_STR("copy mdName failed!"); HcfFree(mdNameCopy); HcfFree(tmp); return false; @@ -708,35 +708,35 @@ static bool GetCmacParamsSpec(napi_env env, napi_value arg, const char *algName, napi_value data = nullptr; napi_valuetype valueType = napi_undefined; if ((env == nullptr) || (arg == nullptr) || (paramsSpec == nullptr)) { - LOGE("Invalid params!"); + LOGE_ONE_STR("Invalid params!"); return false; } napi_status status = napi_get_named_property(env, arg, CIPHER_NAME.c_str(), &data); napi_typeof(env, data, &valueType); if ((status != napi_ok) || (data == nullptr) || (valueType == napi_undefined)) { - LOGE("failed to get valid algo name!"); + LOGE_ONE_STR("failed to get valid algo name!"); return false; } std::string cipherName; if (!GetStringFromJSParams(env, data, cipherName)) { - LOGE("GetStringFromJSParams failed!"); + LOGE_ONE_STR("GetStringFromJSParams failed!"); return false; } HcfCmacParamsSpec *tmp = nullptr; tmp = static_cast(HcfMalloc(sizeof(HcfCmacParamsSpec), 0)); if (tmp == nullptr) { - LOGE("malloc hmac spec failed!"); + LOGE_ONE_STR("malloc hmac spec failed!"); return false; } char* cipherNameCopy = static_cast(HcfMalloc(cipherName.length() + 1, 0)); if (cipherNameCopy == nullptr) { - LOGE("malloc cipherName failed!"); + LOGE_ONE_STR("malloc cipherName failed!"); HcfFree(tmp); return false; } if (memcpy_s(cipherNameCopy, cipherName.length() + 1, cipherName.c_str(), cipherName.length() + 1) != EOK) { - LOGE("copy cipherName failed!"); + LOGE_ONE_STR("copy cipherName failed!"); HcfFree(cipherNameCopy); HcfFree(tmp); return false; @@ -752,19 +752,19 @@ static bool GetMacSpecFromJSParams(napi_env env, napi_value arg, HcfMacParamsSpe napi_value data = nullptr; napi_valuetype valueType = napi_undefined; if ((env == nullptr) || (arg == nullptr) || (params == nullptr)) { - LOGE("Invalid params!"); + LOGE_ONE_STR("Invalid params!"); return false; } napi_status status = napi_get_named_property(env, arg, ALGO_PARAMS.c_str(), &data); napi_typeof(env, data, &valueType); if ((status != napi_ok) || (data == nullptr) || (valueType == napi_undefined)) { - LOGE("failed to get valid algo name!"); + LOGE_ONE_STR("failed to get valid algo name!"); return false; } std::string algoName; if (!GetStringFromJSParams(env, data, algoName)) { - LOGE("GetStringFromJSParams failed!"); + LOGE_ONE_STR("GetStringFromJSParams failed!"); return false; } if (algoName.compare("HMAC") == 0) { @@ -772,7 +772,7 @@ static bool GetMacSpecFromJSParams(napi_env env, napi_value arg, HcfMacParamsSpe } else if (algoName.compare("CMAC") == 0) { return GetCmacParamsSpec(env, arg, algoName.c_str(), params); } else { - LOGE("Not support that alg"); + LOGE_ONE_STR("Not support that alg"); return false; } return true; @@ -781,28 +781,28 @@ static bool GetMacSpecFromJSParams(napi_env env, napi_value arg, HcfMacParamsSpe static bool GetStringMacParams(napi_env env, napi_value argv, HcfMacParamsSpec **paramsSpec) { if ((env == nullptr) || (paramsSpec == nullptr)) { - LOGE("Invalid params!"); + LOGE_ONE_STR("Invalid params!"); return false; } std::string algoName; if (!GetStringFromJSParams(env, argv, algoName)) { napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "Failed to get algorithm.")); - LOGE("Failed to get algorithm."); + LOGE_ONE_STR("Failed to get algorithm."); return false; } *paramsSpec = reinterpret_cast(HcfMalloc(sizeof(HcfHmacParamsSpec), 0)); if (*paramsSpec == nullptr) { napi_throw(env, GenerateBusinessError(env, HCF_ERR_MALLOC, "Failed to allocate memory.")); - LOGE("Failed to allocate memory."); + LOGE_ONE_STR("Failed to allocate memory."); return false; } char* mdNameCopy = static_cast(HcfMalloc(algoName.length() + 1, 0)); if (mdNameCopy == nullptr) { - LOGE("malloc mdName failed!"); + LOGE_ONE_STR("malloc mdName failed!"); return false; } if (memcpy_s(mdNameCopy, algoName.length() + 1, algoName.c_str(), algoName.length() + 1) != EOK) { - LOGE("copy mdName failed!"); + LOGE_ONE_STR("copy mdName failed!"); HcfFree(mdNameCopy); return false; } @@ -818,13 +818,13 @@ static bool SetparamsSpec(napi_env env, napi_value argv, HcfMacParamsSpec **para if (valueType == napi_string) { if (!GetStringMacParams(env, argv, paramsSpec)) { napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "Failed to get mac params.")); - LOGE("Failed to get mac params."); + LOGE_ONE_STR("Failed to get mac params."); return false; } } else { if (!GetMacSpecFromJSParams(env, argv, paramsSpec)) { napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "Failed to get mac params.")); - LOGE("Failed to get mac params."); + LOGE_ONE_STR("Failed to get mac params."); return false; } } @@ -839,14 +839,14 @@ napi_value NapiMac::CreateMac(napi_env env, napi_callback_info info) napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr); if (argc != expectedArgc) { napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "The input args num is invalid.")); - LOGE("The input args num is invalid."); + LOGE_ONE_STR("The input args num is invalid."); return nullptr; } HcfMacParamsSpec *paramsSpec = nullptr; if (!SetparamsSpec(env, argv[PARAM0], ¶msSpec)) { napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "Failed to set mac params.")); - LOGE("Failed to set mac params."); + LOGE_ONE_STR("Failed to set mac params."); return nullptr; } @@ -854,7 +854,7 @@ napi_value NapiMac::CreateMac(napi_env env, napi_callback_info info) HcfResult res = HcfMacCreate(paramsSpec, &macObj); if (res != HCF_SUCCESS) { napi_throw(env, GenerateBusinessError(env, res, "create C obj failed.")); - LOGE("create c macObj failed."); + LOGE_ONE_STR("create c macObj failed."); FreeMacParams(paramsSpec); return nullptr; } @@ -870,7 +870,7 @@ napi_value NapiMac::CreateMac(napi_env env, napi_callback_info info) if (macNapiObj == nullptr) { napi_throw(env, GenerateBusinessError(env, HCF_ERR_MALLOC, "new mac napi obj failed.")); HcfObjDestroy(macObj); - LOGE("create napi obj failed"); + LOGE_ONE_STR("create napi obj failed"); return nullptr; } diff --git a/frameworks/js/napi/crypto/src/napi_md.cpp b/frameworks/js/napi/crypto/src/napi_md.cpp index 7ebe265d4e74a114fe4e937c92e843059f8b34cc..5dcab151ce4187aafecc6c664f4b051bc9d724e4 100644 --- a/frameworks/js/napi/crypto/src/napi_md.cpp +++ b/frameworks/js/napi/crypto/src/napi_md.cpp @@ -114,7 +114,7 @@ static void MdUpdateExecute(napi_env env, void *data) HcfMd *mdObj = context->md; context->errCode = mdObj->update(mdObj, context->inBlob); if (context->errCode != HCF_SUCCESS) { - LOGD("[error] update failed!"); + LOGD_ONE_STR("[error] update failed!"); context->errMsg = "update failed"; } } @@ -125,7 +125,7 @@ static void MdDoFinalExecute(napi_env env, void *data) HcfMd *mdObj = context->md; HcfBlob *outBlob = reinterpret_cast(HcfMalloc(sizeof(HcfBlob), 0)); if (outBlob == nullptr) { - LOGE("outBlob is null!"); + LOGE_ONE_STR("outBlob is null!"); context->errCode = HCF_ERR_MALLOC; context->errMsg = "malloc data blob failed"; return; @@ -133,7 +133,7 @@ static void MdDoFinalExecute(napi_env env, void *data) context->errCode = mdObj->doFinal(mdObj, outBlob); if (context->errCode != HCF_SUCCESS) { HcfFree(outBlob); - LOGD("[error] doFinal failed!"); + LOGD_ONE_STR("[error] doFinal failed!"); context->errMsg = "doFinal failed"; return; } @@ -158,7 +158,7 @@ static void MdDoFinalComplete(napi_env env, napi_status status, void *data) MdCtx *context = static_cast(data); napi_value returnOutBlob = ConvertBlobToNapiValue(env, context->outBlob); if (returnOutBlob == nullptr) { - LOGE("returnOutBlob is nullptr!"); + LOGE_ONE_STR("returnOutBlob is nullptr!"); returnOutBlob = NapiGetNull(env); } if (context->asyncType == ASYNC_CALLBACK) { @@ -185,19 +185,19 @@ static bool BuildMdJsUpdateCtx(napi_env env, napi_callback_info info, MdCtx *con ASYNC_CALLBACK : ASYNC_PROMISE; context->inBlob = GetBlobFromNapiDataBlob(env, argv[PARAM0]); if (context->inBlob == nullptr) { - LOGE("inBlob is null!"); + LOGE_ONE_STR("inBlob is null!"); return false; } napi_status status = napi_unwrap(env, thisVar, reinterpret_cast(&napiMd)); if (status != napi_ok || napiMd == nullptr) { - LOGE("failed to unwrap NapiMd obj!"); + LOGE_ONE_STR("failed to unwrap NapiMd obj!"); return false; } context->md = napiMd->GetMd(); if (napi_create_reference(env, thisVar, 1, &context->mdRef) != napi_ok) { - LOGE("create md ref failed when do md update!"); + LOGE_ONE_STR("create md ref failed when do md update!"); return false; } @@ -226,14 +226,14 @@ static bool BuildMdJsDoFinalCtx(napi_env env, napi_callback_info info, MdCtx *co napi_status status = napi_unwrap(env, thisVar, reinterpret_cast(&napiMd)); if (status != napi_ok || napiMd == nullptr) { - LOGE("failed to unwrap NapiMd obj!"); + LOGE_ONE_STR("failed to unwrap NapiMd obj!"); return false; } context->md = napiMd->GetMd(); if (napi_create_reference(env, thisVar, 1, &context->mdRef) != napi_ok) { - LOGE("create md ref failed when do md final!"); + LOGE_ONE_STR("create md ref failed when do md final!"); return false; } @@ -311,13 +311,13 @@ napi_value NapiMd::JsMdUpdate(napi_env env, napi_callback_info info) MdCtx *context = static_cast(HcfMalloc(sizeof(MdCtx), 0)); if (context == nullptr) { napi_throw(env, GenerateBusinessError(env, HCF_ERR_MALLOC, "malloc context failed")); - LOGE("malloc context failed!"); + LOGE_ONE_STR("malloc context failed!"); return nullptr; } if (!BuildMdJsUpdateCtx(env, info, context)) { napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "build context fail.")); - LOGE("build context fail."); + LOGE_ONE_STR("build context fail."); FreeCryptoFwkCtx(env, context); return nullptr; } @@ -334,19 +334,19 @@ napi_value NapiMd::JsMdUpdateSync(napi_env env, napi_callback_info info) napi_value argv[ARGS_SIZE_ONE] = { nullptr }; napi_get_cb_info(env, info, &argc, argv, &thisVar, nullptr); if (argc != expectedArgsCount) { - LOGE("The input args num is invalid."); + LOGE_ONE_STR("The input args num is invalid."); napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "invalid parameters.")); return nullptr; } HcfBlob *inBlob = GetBlobFromNapiDataBlob(env, argv[PARAM0]); if (inBlob == nullptr) { - LOGE("inBlob is null!"); + LOGE_ONE_STR("inBlob is null!"); napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "invalid parameters.")); return nullptr; } napi_status status = napi_unwrap(env, thisVar, reinterpret_cast(&napiMd)); if (status != napi_ok || napiMd == nullptr) { - LOGE("failed to unwrap NapiMd obj!"); + LOGE_ONE_STR("failed to unwrap NapiMd obj!"); napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "invalid parameters.")); HcfBlobDataClearAndFree(inBlob); HcfFree(inBlob); @@ -354,7 +354,7 @@ napi_value NapiMd::JsMdUpdateSync(napi_env env, napi_callback_info info) } HcfMd *md = napiMd->GetMd(); if (md == nullptr) { - LOGE("md is nullptr!"); + LOGE_ONE_STR("md is nullptr!"); napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "md is nullptr!")); HcfBlobDataClearAndFree(inBlob); HcfFree(inBlob); @@ -362,7 +362,7 @@ napi_value NapiMd::JsMdUpdateSync(napi_env env, napi_callback_info info) } HcfResult errCode = md->update(md, inBlob); if (errCode != HCF_SUCCESS) { - LOGE("update failed!"); + LOGE_ONE_STR("update failed!"); napi_throw(env, GenerateBusinessError(env, HCF_ERR_CRYPTO_OPERATION, "crypto operation error.")); HcfBlobDataClearAndFree(inBlob); HcfFree(inBlob); @@ -380,13 +380,13 @@ napi_value NapiMd::JsMdDoFinal(napi_env env, napi_callback_info info) MdCtx *context = static_cast(HcfMalloc(sizeof(MdCtx), 0)); if (context == nullptr) { napi_throw(env, GenerateBusinessError(env, HCF_ERR_MALLOC, "malloc context failed")); - LOGE("malloc context failed!"); + LOGE_ONE_STR("malloc context failed!"); return nullptr; } if (!BuildMdJsDoFinalCtx(env, info, context)) { napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "build context fail.")); - LOGE("build context fail."); + LOGE_ONE_STR("build context fail."); FreeCryptoFwkCtx(env, context); return nullptr; } @@ -402,14 +402,14 @@ napi_value NapiMd::JsMdDoFinalSync(napi_env env, napi_callback_info info) napi_status status = napi_unwrap(env, thisVar, reinterpret_cast(&napiMd)); if (status != napi_ok || napiMd == nullptr) { - LOGE("failed to unwrap NapiMd obj!"); + LOGE_ONE_STR("failed to unwrap NapiMd obj!"); napi_throw(env, GenerateBusinessError(env, HCF_ERR_NAPI, "failed to unwrap NapiMd obj!")); return nullptr; } HcfMd *md = napiMd->GetMd(); if (md == nullptr) { - LOGE("md is nullptr!"); + LOGE_ONE_STR("md is nullptr!"); napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "md is nullptr!")); return nullptr; } @@ -417,7 +417,7 @@ napi_value NapiMd::JsMdDoFinalSync(napi_env env, napi_callback_info info) HcfBlob outBlob = { .data = nullptr, .len = 0 }; HcfResult errCode = md->doFinal(md, &outBlob); if (errCode != HCF_SUCCESS) { - LOGE("md doFinal failed!"); + LOGE_ONE_STR("md doFinal failed!"); napi_throw(env, GenerateBusinessError(env, errCode, "md doFinal failed!")); HcfBlobDataClearAndFree(&outBlob); return nullptr; @@ -427,7 +427,7 @@ napi_value NapiMd::JsMdDoFinalSync(napi_env env, napi_callback_info info) errCode = ConvertDataBlobToNapiValue(env, &outBlob, &instance); HcfBlobDataClearAndFree(&outBlob); if (errCode != HCF_SUCCESS) { - LOGE("md convert dataBlob to napi_value failed!"); + LOGE_ONE_STR("md convert dataBlob to napi_value failed!"); napi_throw(env, GenerateBusinessError(env, errCode, "md convert dataBlob to napi_value failed!")); return nullptr; } @@ -444,14 +444,14 @@ napi_value NapiMd::JsGetMdLength(napi_env env, napi_callback_info info) napi_status status = napi_unwrap(env, thisVar, reinterpret_cast(&napiMd)); if (status != napi_ok || napiMd == nullptr) { napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "failed to unwrap NapiMd obj!")); - LOGE("failed to unwrap NapiMd obj!"); + LOGE_ONE_STR("failed to unwrap NapiMd obj!"); return nullptr; } HcfMd *md = napiMd->GetMd(); if (md == nullptr) { napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "fail to get md obj!")); - LOGE("fail to get md obj!"); + LOGE_ONE_STR("fail to get md obj!"); return nullptr; } @@ -480,7 +480,7 @@ static napi_value NapiWrapMd(napi_env env, napi_value instance, NapiMd *mdNapiOb if (status != napi_ok) { napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "failed to wrap NapiMd obj!")); delete mdNapiObj; - LOGE("failed to wrap NapiMd obj!"); + LOGE_ONE_STR("failed to wrap NapiMd obj!"); return nullptr; } return instance; @@ -494,20 +494,20 @@ napi_value NapiMd::CreateMd(napi_env env, napi_callback_info info) napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr); if (argc != expectedArgc) { napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "The input args num is invalid.")); - LOGE("The input args num is invalid."); + LOGE_ONE_STR("The input args num is invalid."); return nullptr; } std::string algoName; if (!GetStringFromJSParams(env, argv[PARAM0], algoName)) { napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "Failed to get algorithm.")); - LOGE("Failed to get algorithm."); + LOGE_ONE_STR("Failed to get algorithm."); return nullptr; } HcfMd *mdObj = nullptr; HcfResult res = HcfMdCreate(algoName.c_str(), &mdObj); if (res != HCF_SUCCESS) { napi_throw(env, GenerateBusinessError(env, res, "create C obj failed.")); - LOGE("create c mdObj failed."); + LOGE_ONE_STR("create c mdObj failed."); return nullptr; } napi_value napiAlgName = nullptr; @@ -521,7 +521,7 @@ napi_value NapiMd::CreateMd(napi_env env, napi_callback_info info) if (mdNapiObj == nullptr) { napi_throw(env, GenerateBusinessError(env, HCF_ERR_MALLOC, "new md napi obj failed!")); HcfObjDestroy(mdObj); - LOGE("create md napi obj failed!"); + LOGE_ONE_STR("create md napi obj failed!"); return nullptr; } diff --git a/frameworks/js/napi/crypto/src/napi_pri_key.cpp b/frameworks/js/napi/crypto/src/napi_pri_key.cpp index 6ef2967f82934ea17cfcb0e02c77b19fbbf69116..fd8924d1a51e82ae29f071423dd343279f6f03b4 100644 --- a/frameworks/js/napi/crypto/src/napi_pri_key.cpp +++ b/frameworks/js/napi/crypto/src/napi_pri_key.cpp @@ -90,14 +90,14 @@ napi_value NapiPriKey::JsGetEncoded(napi_env env, napi_callback_info info) napi_status status = napi_unwrap(env, thisVar, reinterpret_cast(&napiPriKey)); if (status != napi_ok || napiPriKey == nullptr) { napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "failed to unwrap napiPriKey obj!")); - LOGE("failed to unwrap napiPriKey obj!"); + LOGE_ONE_STR("failed to unwrap napiPriKey obj!"); return nullptr; } HcfPriKey *priKey = napiPriKey->GetPriKey(); if (priKey == nullptr) { napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "failed to get priKey obj!")); - LOGE("failed to get priKey obj!"); + LOGE_ONE_STR("failed to get priKey obj!"); return nullptr; } @@ -105,7 +105,7 @@ napi_value NapiPriKey::JsGetEncoded(napi_env env, napi_callback_info info) HcfResult res = priKey->base.getEncoded(&priKey->base, &returnBlob); if (res != HCF_SUCCESS) { napi_throw(env, GenerateBusinessError(env, res, "c getEncoded fail.")); - LOGD("[error] c getEncoded fail."); + LOGD_ONE_STR("[error] c getEncoded fail."); return nullptr; } @@ -113,7 +113,7 @@ napi_value NapiPriKey::JsGetEncoded(napi_env env, napi_callback_info info) if (instance == nullptr) { HcfBlobDataFree(&returnBlob); napi_throw(env, GenerateBusinessError(env, res, "covert blob to napi value failed.")); - LOGE("covert blob to napi value failed."); + LOGE_ONE_STR("covert blob to napi value failed."); return nullptr; } HcfBlobDataClearAndFree(&returnBlob); @@ -129,20 +129,20 @@ static bool ValidateAndGetParams(napi_env env, napi_callback_info info, std::str napi_value argv[PARAMS_NUM_TWO] = { nullptr }; napi_get_cb_info(env, info, &argc, argv, &thisVar, nullptr); if ((argc != expectedArgc) && (argc != (expectedArgc - 1))) { - LOGE("The input args num is invalid."); + LOGE_ONE_STR("The input args num is invalid."); napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "The input args num is invalid.")); return false; } if (!GetStringFromJSParams(env, argv[0], format)) { - LOGE("failed to get formatStr."); + LOGE_ONE_STR("failed to get formatStr."); napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "failed to get formatStr.")); return false; } if (argc == expectedArgc) { if (!GetEncodingParamsSpec(env, argv[1], paramsSpec)) { - LOGE("get params failed!"); + LOGE_ONE_STR("get params failed!"); napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "get napi paramsSpec failed!")); return false; } @@ -150,7 +150,7 @@ static bool ValidateAndGetParams(napi_env env, napi_callback_info info, std::str napi_status status = napi_unwrap(env, thisVar, reinterpret_cast(napiPriKey)); if (status != napi_ok || napiPriKey == nullptr) { - LOGE("failed to unwrap napiPriKey obj!"); + LOGE_ONE_STR("failed to unwrap napiPriKey obj!"); napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "failed to unwrap napiPriKey obj!")); return false; } @@ -169,7 +169,7 @@ napi_value NapiPriKey::JsGetEncodedPem(napi_env env, napi_callback_info info) HcfPriKey *priKey = napiPriKey->GetPriKey(); if (priKey == nullptr) { FreeEncodeParamsSpec(paramsSpec); - LOGE("failed to get priKey obj!"); + LOGE_ONE_STR("failed to get priKey obj!"); napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "failed to get priKey obj!")); return nullptr; } @@ -178,7 +178,7 @@ napi_value NapiPriKey::JsGetEncodedPem(napi_env env, napi_callback_info info) HcfResult res = priKey->getEncodedPem(priKey, paramsSpec, format.c_str(), &returnString); if (res != HCF_SUCCESS) { FreeEncodeParamsSpec(paramsSpec); - LOGE("getEncodedPem fail."); + LOGE_ONE_STR("getEncodedPem fail."); napi_throw(env, GenerateBusinessError(env, res, "getEncodedPem fail.")); return nullptr; } @@ -197,14 +197,14 @@ napi_value NapiPriKey::JsClearMem(napi_env env, napi_callback_info info) napi_status status = napi_unwrap(env, thisVar, reinterpret_cast(&napiPriKey)); if (status != napi_ok || napiPriKey == nullptr) { napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "failed to unwrap napiPriKey obj!")); - LOGE("failed to unwrap napiPriKey obj!"); + LOGE_ONE_STR("failed to unwrap napiPriKey obj!"); return nullptr; } HcfPriKey *priKey = napiPriKey->GetPriKey(); if (priKey == nullptr) { napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "failed to get priKey obj!")); - LOGE("failed to get priKey obj!"); + LOGE_ONE_STR("failed to get priKey obj!"); return nullptr; } @@ -218,7 +218,7 @@ static napi_value GetAsyKeySpecBigInt(napi_env env, AsyKeySpecItem item, HcfPriK HcfResult res = priKey->getAsyKeySpecBigInteger(priKey, item, &returnBigInteger); if (res != HCF_SUCCESS) { napi_throw(env, GenerateBusinessError(env, res, "C getAsyKeySpecBigInteger failed.")); - LOGE("C getAsyKeySpecBigInteger failed."); + LOGE_ONE_STR("C getAsyKeySpecBigInteger failed."); return nullptr; } @@ -227,7 +227,7 @@ static napi_value GetAsyKeySpecBigInt(napi_env env, AsyKeySpecItem item, HcfPriK HcfFree(returnBigInteger.data); if (instance == nullptr) { napi_throw(env, GenerateBusinessError(env, res, "covert bigInt to napi value failed.")); - LOGE("covert bigInt to napi value failed."); + LOGE_ONE_STR("covert bigInt to napi value failed."); return nullptr; } return instance; @@ -239,7 +239,7 @@ static napi_value GetAsyKeySpecNumber(napi_env env, AsyKeySpecItem item, HcfPriK HcfResult res = priKey->getAsyKeySpecInt(priKey, item, &returnInt); if (res != HCF_SUCCESS) { napi_throw(env, GenerateBusinessError(env, res, "C getAsyKeySpecInt failed.")); - LOGE("C getAsyKeySpecInt fail."); + LOGE_ONE_STR("C getAsyKeySpecInt fail."); return nullptr; } @@ -254,7 +254,7 @@ static napi_value GetAsyKeySpecString(napi_env env, AsyKeySpecItem item, HcfPriK HcfResult res = priKey->getAsyKeySpecString(priKey, item, &returnString); if (res != HCF_SUCCESS) { napi_throw(env, GenerateBusinessError(env, res, "C getAsyKeySpecString failed.")); - LOGE("c getAsyKeySpecString fail."); + LOGE_ONE_STR("c getAsyKeySpecString fail."); return nullptr; } @@ -281,23 +281,23 @@ napi_value NapiPriKey::JsGetAsyKeySpec(napi_env env, napi_callback_info info) AsyKeySpecItem item; if (napi_get_value_uint32(env, argv[0], reinterpret_cast(&item)) != napi_ok) { napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "JsGetAsyKeySpec failed!")); - LOGE("JsGetAsyKeySpec failed!"); + LOGE_ONE_STR("JsGetAsyKeySpec failed!"); return nullptr; } napi_status status = napi_unwrap(env, thisVar, reinterpret_cast(&napiPriKey)); if (status != napi_ok || napiPriKey == nullptr) { napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "failed to unwrap napiPriKey obj!")); - LOGE("failed to unwrap napiPriKey obj!"); + LOGE_ONE_STR("failed to unwrap napiPriKey obj!"); return nullptr; } HcfPriKey *priKey = napiPriKey->GetPriKey(); if (priKey == nullptr) { napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "failed to get priKey obj!")); - LOGE("failed to get priKey obj!"); + LOGE_ONE_STR("failed to get priKey obj!"); return nullptr; } - LOGD("prepare priKey ok."); + LOGD_ONE_STR("prepare priKey ok."); int32_t type = GetAsyKeySpecType(item); if (type == SPEC_ITEM_TYPE_BIG_INT) { @@ -327,26 +327,26 @@ napi_value NapiPriKey::JsGetEncodedDer(napi_env env, napi_callback_info info) std::string format; if (!GetStringFromJSParams(env, argv[0], format)) { napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "failed to get format.")); - LOGE("get format fail."); + LOGE_ONE_STR("get format fail."); return nullptr; } napi_status status = napi_unwrap(env, thisVar, reinterpret_cast(&napiPriKey)); if (status != napi_ok || napiPriKey == nullptr) { napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "failed to unwrap private key obj!")); - LOGE("failed to unwrap private key obj!"); + LOGE_ONE_STR("failed to unwrap private key obj!"); return nullptr; } HcfPriKey *priKey = napiPriKey->GetPriKey(); if (priKey == nullptr) { napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "failed to get private key obj!")); - LOGE("failed to get private key obj!"); + LOGE_ONE_STR("failed to get private key obj!"); return nullptr; } HcfBlob returnBlob = { .data = nullptr, .len = 0 }; HcfResult res = priKey->getEncodedDer(priKey, format.c_str(), &returnBlob); if (res != HCF_SUCCESS) { napi_throw(env, GenerateBusinessError(env, res, "get private key encodedDer fail.")); - LOGE("get private key encodeDer fail."); + LOGE_ONE_STR("get private key encodeDer fail."); return nullptr; } diff --git a/frameworks/js/napi/crypto/src/napi_pub_key.cpp b/frameworks/js/napi/crypto/src/napi_pub_key.cpp index 675cba125f05d87f7a01185bdbbee7977c6542a1..ba695575ee6d20a855a3076c83175c46abd1cb0b 100644 --- a/frameworks/js/napi/crypto/src/napi_pub_key.cpp +++ b/frameworks/js/napi/crypto/src/napi_pub_key.cpp @@ -70,14 +70,14 @@ napi_value NapiPubKey::JsGetEncoded(napi_env env, napi_callback_info info) napi_status status = napi_unwrap(env, thisVar, reinterpret_cast(&napiPubKey)); if (status != napi_ok || napiPubKey == nullptr) { napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "failed to unwrap napiPubKey obj!")); - LOGE("failed to unwrap napiPubKey obj!"); + LOGE_ONE_STR("failed to unwrap napiPubKey obj!"); return nullptr; } HcfPubKey *pubKey = napiPubKey->GetPubKey(); if (pubKey == nullptr) { napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "failed to get pubKey obj!")); - LOGE("failed to get pubKey obj!"); + LOGE_ONE_STR("failed to get pubKey obj!"); return nullptr; } @@ -85,7 +85,7 @@ napi_value NapiPubKey::JsGetEncoded(napi_env env, napi_callback_info info) HcfResult res = pubKey->base.getEncoded(&pubKey->base, &returnBlob); if (res != HCF_SUCCESS) { napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "c getEncoded fail.")); - LOGE("c getEncoded fail."); + LOGE_ONE_STR("c getEncoded fail."); return nullptr; } @@ -93,7 +93,7 @@ napi_value NapiPubKey::JsGetEncoded(napi_env env, napi_callback_info info) if (instance == nullptr) { HcfBlobDataFree(&returnBlob); napi_throw(env, GenerateBusinessError(env, res, "covert blob to napi value failed.")); - LOGE("covert blob to napi value failed."); + LOGE_ONE_STR("covert blob to napi value failed."); return nullptr; } HcfBlobDataFree(&returnBlob); @@ -115,20 +115,20 @@ napi_value NapiPubKey::JsGetEncodedDer(napi_env env, napi_callback_info info) } std::string format; if (!GetStringFromJSParams(env, argv[PARAM0], format)) { - LOGE("get format fail."); + LOGE_ONE_STR("get format fail."); napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "failed to get format.")); return nullptr; } napi_status status = napi_unwrap(env, thisVar, reinterpret_cast(&napiPubKey)); if (status != napi_ok || napiPubKey == nullptr) { - LOGE("failed to unwrap napiPubKeyDer obj!"); + LOGE_ONE_STR("failed to unwrap napiPubKeyDer obj!"); napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "failed to unwrap napiPubKeyDer obj!")); return nullptr; } HcfPubKey *pubKey = napiPubKey->GetPubKey(); if (pubKey == nullptr) { - LOGE("failed to get pubKeyDer obj!"); + LOGE_ONE_STR("failed to get pubKeyDer obj!"); napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "failed to get pubKeyDer obj!")); return nullptr; } @@ -136,7 +136,7 @@ napi_value NapiPubKey::JsGetEncodedDer(napi_env env, napi_callback_info info) HcfBlob returnBlob; HcfResult res = pubKey->getEncodedDer(pubKey, format.c_str(), &returnBlob); if (res != HCF_SUCCESS) { - LOGE("c getEncodedDer fail."); + LOGE_ONE_STR("c getEncodedDer fail."); napi_throw(env, GenerateBusinessError(env, res, "c getEncodedDer fail.")); return nullptr; } @@ -145,7 +145,7 @@ napi_value NapiPubKey::JsGetEncodedDer(napi_env env, napi_callback_info info) if (instance == nullptr) { HcfBlobDataFree(&returnBlob); napi_throw(env, GenerateBusinessError(env, res, "covert blob to napi value failed.")); - LOGE("covert blob to napi value failed."); + LOGE_ONE_STR("covert blob to napi value failed."); return nullptr; } HcfBlobDataFree(&returnBlob); @@ -160,14 +160,14 @@ napi_value NapiPubKey::JsGetEncodedPem(napi_env env, napi_callback_info info) napi_value thisVar = nullptr; napi_get_cb_info(env, info, &argc, argv, &thisVar, nullptr); if (argc != expectedArgc) { - LOGE("The input args num is invalid."); + LOGE_ONE_STR("The input args num is invalid."); napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "The input args num is invalid.")); return NapiGetNull(env); } std::string format = ""; if (!GetStringFromJSParams(env, argv[0], format)) { - LOGE("failed to get formatStr."); + LOGE_ONE_STR("failed to get formatStr."); napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "failed to get formatStr.")); return NapiGetNull(env); } @@ -175,14 +175,14 @@ napi_value NapiPubKey::JsGetEncodedPem(napi_env env, napi_callback_info info) NapiPubKey *napiPubKey = nullptr; napi_status status = napi_unwrap(env, thisVar, reinterpret_cast(&napiPubKey)); if (status != napi_ok || napiPubKey == nullptr) { - LOGE("failed to unwrap napiPriKey obj!"); + LOGE_ONE_STR("failed to unwrap napiPriKey obj!"); napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "failed to unwrap napiPubKey obj!")); return nullptr; } HcfPubKey *pubKey = napiPubKey->GetPubKey(); if (pubKey == nullptr) { - LOGE("failed to get pubKey obj!"); + LOGE_ONE_STR("failed to get pubKey obj!"); napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "failed to get pubKey obj!")); return nullptr; } @@ -190,7 +190,7 @@ napi_value NapiPubKey::JsGetEncodedPem(napi_env env, napi_callback_info info) char *returnString = nullptr; HcfResult res = pubKey->base.getEncodedPem(&pubKey->base, format.c_str(), &returnString); if (res != HCF_SUCCESS) { - LOGE("getEncodedPem fail."); + LOGE_ONE_STR("getEncodedPem fail."); napi_throw(env, GenerateBusinessError(env, res, "getEncodedPem fail.")); return nullptr; } @@ -206,7 +206,7 @@ static napi_value GetAsyKeySpecBigInt(napi_env env, AsyKeySpecItem item, HcfPubK HcfResult res = pubKey->getAsyKeySpecBigInteger(pubKey, item, &returnBigInteger); if (res != HCF_SUCCESS) { napi_throw(env, GenerateBusinessError(env, res, "C getAsyKeySpecBigInteger failed.")); - LOGE("C getAsyKeySpecBigInteger failed."); + LOGE_ONE_STR("C getAsyKeySpecBigInteger failed."); return nullptr; } @@ -214,7 +214,7 @@ static napi_value GetAsyKeySpecBigInt(napi_env env, AsyKeySpecItem item, HcfPubK if (instance == nullptr) { HcfFree(returnBigInteger.data); napi_throw(env, GenerateBusinessError(env, res, "covert bigInt to napi value failed.")); - LOGE("covert bigInt to napi value failed."); + LOGE_ONE_STR("covert bigInt to napi value failed."); return nullptr; } HcfFree(returnBigInteger.data); @@ -227,7 +227,7 @@ static napi_value GetAsyKeySpecNumber(napi_env env, AsyKeySpecItem item, HcfPubK HcfResult res = pubKey->getAsyKeySpecInt(pubKey, item, &returnInt); if (res != HCF_SUCCESS) { napi_throw(env, GenerateBusinessError(env, res, "C getAsyKeySpecInt failed.")); - LOGE("C getAsyKeySpecInt fail."); + LOGE_ONE_STR("C getAsyKeySpecInt fail."); return nullptr; } @@ -242,7 +242,7 @@ static napi_value GetAsyKeySpecString(napi_env env, AsyKeySpecItem item, HcfPubK HcfResult res = pubKey->getAsyKeySpecString(pubKey, item, &returnString); if (res != HCF_SUCCESS) { napi_throw(env, GenerateBusinessError(env, res, "C getAsyKeySpecString failed.")); - LOGE("c getAsyKeySpecString fail."); + LOGE_ONE_STR("c getAsyKeySpecString fail."); return nullptr; } @@ -268,20 +268,20 @@ napi_value NapiPubKey::JsGetAsyKeySpec(napi_env env, napi_callback_info info) AsyKeySpecItem item; if (napi_get_value_uint32(env, argv[0], reinterpret_cast(&item)) != napi_ok) { napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "JsGetAsyKeySpec failed!")); - LOGE("JsGetAsyKeySpec failed!"); + LOGE_ONE_STR("JsGetAsyKeySpec failed!"); return nullptr; } napi_status status = napi_unwrap(env, thisVar, reinterpret_cast(&napiPubKey)); if (status != napi_ok || napiPubKey == nullptr) { napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "failed to unwrap napiPubKey obj!")); - LOGE("failed to unwrap napiPubKey obj!"); + LOGE_ONE_STR("failed to unwrap napiPubKey obj!"); return nullptr; } HcfPubKey *pubKey = napiPubKey->GetPubKey(); if (pubKey == nullptr) { napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "failed to get pubKey obj!")); - LOGE("failed to get pubKey obj!"); + LOGE_ONE_STR("failed to get pubKey obj!"); return nullptr; } diff --git a/frameworks/js/napi/crypto/src/napi_rand.cpp b/frameworks/js/napi/crypto/src/napi_rand.cpp index 4b3c9bfd47c74e542e60237929de7bb3345234c9..15957470b73ca2e6151ba924842aefa55747792d 100644 --- a/frameworks/js/napi/crypto/src/napi_rand.cpp +++ b/frameworks/js/napi/crypto/src/napi_rand.cpp @@ -115,7 +115,7 @@ static void GenerateRandomExecute(napi_env env, void *data) HcfRand *randObj = context->rand; HcfBlob *randBlob = reinterpret_cast(HcfMalloc(sizeof(HcfBlob), 0)); if (randBlob == nullptr) { - LOGE("randBlob is null!"); + LOGE_ONE_STR("randBlob is null!"); context->errCode = HCF_ERR_MALLOC; context->errMsg = "malloc data blob failed"; return; @@ -123,7 +123,7 @@ static void GenerateRandomExecute(napi_env env, void *data) int32_t numBytes = context->numBytes; context->errCode = randObj->generateRandom(randObj, numBytes, randBlob); if (context->errCode != HCF_SUCCESS) { - LOGD("[error] generateRandom failed!"); + LOGD_ONE_STR("[error] generateRandom failed!"); context->errMsg = "generateRandom failed"; HcfFree(randBlob); return; @@ -136,7 +136,7 @@ static void GenerateRandomComplete(napi_env env, napi_status status, void *data) RandCtx *context = static_cast(data); napi_value returnRandBlob = ConvertBlobToNapiValue(env, context->randBlob); if (returnRandBlob == nullptr) { - LOGE("returnOutBlob is nullptr!"); + LOGE_ONE_STR("returnOutBlob is nullptr!"); returnRandBlob = NapiGetNull(env); } if (context->asyncType == ASYNC_CALLBACK) { @@ -155,12 +155,12 @@ static bool BuildGenerateRandomCtx(napi_env env, napi_callback_info info, RandCt napi_value argv[ARGS_SIZE_TWO] = { nullptr }; napi_get_cb_info(env, info, &argc, argv, &thisVar, nullptr); if ((argc != expectedArgsCount) && (argc != expectedArgsCount - CALLBACK_SIZE)) { - LOGE("The arguments count is not expected!"); + LOGE_ONE_STR("The arguments count is not expected!"); return false; } if (!GetInt32FromJSParams(env, argv[PARAM0], context->numBytes)) { - LOGE("get numBytes failed!"); + LOGE_ONE_STR("get numBytes failed!"); return false; } context->asyncType = isCallback(env, argv[expectedArgsCount - 1], argc, expectedArgsCount) ? @@ -169,14 +169,14 @@ static bool BuildGenerateRandomCtx(napi_env env, napi_callback_info info, RandCt NapiRand *napiRand = nullptr; napi_status status = napi_unwrap(env, thisVar, reinterpret_cast(&napiRand)); if (status != napi_ok || napiRand == nullptr) { - LOGE("failed to unwrap NapiRand obj!"); + LOGE_ONE_STR("failed to unwrap NapiRand obj!"); return false; } context->rand = napiRand->GetRand(); if (napi_create_reference(env, thisVar, 1, &context->randomRef) != napi_ok) { - LOGE("create random ref failed when generate random!"); + LOGE_ONE_STR("create random ref failed when generate random!"); return false; } @@ -231,13 +231,13 @@ napi_value NapiRand::JsGenerateRandom(napi_env env, napi_callback_info info) RandCtx *context = static_cast(HcfMalloc(sizeof(RandCtx), 0)); if (context == nullptr) { napi_throw(env, GenerateBusinessError(env, HCF_ERR_MALLOC, "malloc context failed")); - LOGE("malloc context failed!"); + LOGE_ONE_STR("malloc context failed!"); return nullptr; } if (!BuildGenerateRandomCtx(env, info, context)) { napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "build context fail.")); - LOGE("build context fail."); + LOGE_ONE_STR("build context fail."); FreeCryptoFwkCtx(env, context); return nullptr; } @@ -256,26 +256,26 @@ napi_value NapiRand::JsGenerateRandomSync(napi_env env, napi_callback_info info) napi_get_cb_info(env, info, &argc, argv, &thisVar, nullptr); if (argc != expectedArgsCount) { napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "invalid params count")); - LOGE("The arguments count is not expected!"); + LOGE_ONE_STR("The arguments count is not expected!"); return nullptr; } int32_t numBytes = 0; if (!GetInt32FromJSParams(env, argv[PARAM0], numBytes)) { napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "get numBytes failed!")); - LOGE("get numBytes failed!"); + LOGE_ONE_STR("get numBytes failed!"); return nullptr; } napi_status status = napi_unwrap(env, thisVar, reinterpret_cast(&napiRand)); if (status != napi_ok || napiRand == nullptr) { napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "failed to unwrap NapiRand obj!")); - LOGE("failed to unwrap NapiRand obj!"); + LOGE_ONE_STR("failed to unwrap NapiRand obj!"); return nullptr; } HcfRand *rand = napiRand->GetRand(); if (rand == nullptr) { napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "fail to get rand obj!")); - LOGE("fail to get rand obj!"); + LOGE_ONE_STR("fail to get rand obj!"); return nullptr; } @@ -283,7 +283,7 @@ napi_value NapiRand::JsGenerateRandomSync(napi_env env, napi_callback_info info) HcfResult res = rand->generateRandom(rand, numBytes, &randBlob); if (res != HCF_SUCCESS) { napi_throw(env, GenerateBusinessError(env, res, "generateRandom failed!")); - LOGD("[error] generateRandom failed!"); + LOGD_ONE_STR("[error] generateRandom failed!"); return nullptr; } @@ -303,13 +303,13 @@ napi_value NapiRand::JsSetSeed(napi_env env, napi_callback_info info) napi_get_cb_info(env, info, &argc, argv, &thisVar, nullptr); if (argc != expectedArgsCount) { napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "invalid params count")); - LOGE("The arguments count is not expected!"); + LOGE_ONE_STR("The arguments count is not expected!"); return nullptr; } HcfBlob *seedBlob = GetBlobFromNapiDataBlob(env, argv[PARAM0]); if (seedBlob == nullptr) { napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "failed to get seedBlob!")); - LOGE("failed to get seedBlob!"); + LOGE_ONE_STR("failed to get seedBlob!"); return nullptr; } napi_status status = napi_unwrap(env, thisVar, reinterpret_cast(&napiRand)); @@ -317,7 +317,7 @@ napi_value NapiRand::JsSetSeed(napi_env env, napi_callback_info info) HcfBlobDataClearAndFree(seedBlob); HcfFree(seedBlob); napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "failed to unwrap NapiRand obj!")); - LOGE("failed to unwrap NapiRand obj!"); + LOGE_ONE_STR("failed to unwrap NapiRand obj!"); return nullptr; } HcfRand *rand = napiRand->GetRand(); @@ -325,7 +325,7 @@ napi_value NapiRand::JsSetSeed(napi_env env, napi_callback_info info) HcfBlobDataClearAndFree(seedBlob); HcfFree(seedBlob); napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "fail to get rand obj!")); - LOGE("fail to get rand obj!"); + LOGE_ONE_STR("fail to get rand obj!"); return nullptr; } HcfResult res = rand->setSeed(rand, seedBlob); @@ -333,7 +333,7 @@ napi_value NapiRand::JsSetSeed(napi_env env, napi_callback_info info) HcfBlobDataClearAndFree(seedBlob); HcfFree(seedBlob); napi_throw(env, GenerateBusinessError(env, res, "set seed failed.")); - LOGD("[error] set seed failed."); + LOGD_ONE_STR("[error] set seed failed."); return nullptr; } HcfBlobDataClearAndFree(seedBlob); @@ -350,14 +350,14 @@ napi_value NapiRand::JsGetAlgorithm(napi_env env, napi_callback_info info) napi_status status = napi_unwrap(env, thisVar, reinterpret_cast(&napiRand)); if (status != napi_ok || napiRand == nullptr) { napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "failed to unwrap NapiRand obj!")); - LOGE("failed to unwrap NapiRand obj!"); + LOGE_ONE_STR("failed to unwrap NapiRand obj!"); return nullptr; } HcfRand *rand = napiRand->GetRand(); if (rand == nullptr) { napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "fail to get rand obj!")); - LOGE("fail to get rand obj!"); + LOGE_ONE_STR("fail to get rand obj!"); return nullptr; } @@ -380,7 +380,7 @@ napi_value NapiRand::CreateRand(napi_env env, napi_callback_info info) HcfResult res = HcfRandCreate(&randObj); if (res != HCF_SUCCESS) { napi_throw(env, GenerateBusinessError(env, res, "create C obj failed.")); - LOGE("create c randObj failed."); + LOGE_ONE_STR("create c randObj failed."); return nullptr; } napi_value instance = nullptr; @@ -391,7 +391,7 @@ napi_value NapiRand::CreateRand(napi_env env, napi_callback_info info) if (randNapiObj == nullptr) { napi_throw(env, GenerateBusinessError(env, HCF_ERR_MALLOC, "new rand napi obj failed.")); HcfObjDestroy(randObj); - LOGE("create rand napi obj failed"); + LOGE_ONE_STR("create rand napi obj failed"); return nullptr; } napi_status status = napi_wrap( @@ -404,7 +404,7 @@ napi_value NapiRand::CreateRand(napi_env env, napi_callback_info info) if (status != napi_ok) { napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "failed to wrap NapiRand obj!")); delete randNapiObj; - LOGE("failed to wrap NapiRand obj!"); + LOGE_ONE_STR("failed to wrap NapiRand obj!"); return nullptr; } return instance; diff --git a/frameworks/js/napi/crypto/src/napi_sign.cpp b/frameworks/js/napi/crypto/src/napi_sign.cpp index 213550c43166a9743b6794d72c130d808c84d887..3028a9caccf21195a16bc3d76aca93832ad8477c 100644 --- a/frameworks/js/napi/crypto/src/napi_sign.cpp +++ b/frameworks/js/napi/crypto/src/napi_sign.cpp @@ -181,7 +181,7 @@ static bool BuildSignJsInitCtx(napi_env env, napi_callback_info info, SignInitCt NapiSign *napiSign = nullptr; napi_status status = napi_unwrap(env, thisVar, reinterpret_cast(&napiSign)); if (status != napi_ok || napiSign == nullptr) { - LOGE("failed to unwrap napi sign obj."); + LOGE_ONE_STR("failed to unwrap napi sign obj."); return false; } @@ -189,7 +189,7 @@ static bool BuildSignJsInitCtx(napi_env env, napi_callback_info info, SignInitCt NapiPriKey *napiPriKey = nullptr; status = napi_unwrap(env, argv[index], reinterpret_cast(&napiPriKey)); if (status != napi_ok || napiPriKey == nullptr) { - LOGE("failed to unwrap napi priKey obj."); + LOGE_ONE_STR("failed to unwrap napi priKey obj."); return false; } @@ -198,12 +198,12 @@ static bool BuildSignJsInitCtx(napi_env env, napi_callback_info info, SignInitCt ctx->priKey = napiPriKey->GetPriKey(); if (napi_create_reference(env, thisVar, 1, &ctx->signRef) != napi_ok) { - LOGE("create sign ref failed when do sign init!"); + LOGE_ONE_STR("create sign ref failed when do sign init!"); return false; } if (napi_create_reference(env, argv[PARAM0], 1, &ctx->priKeyRef) != napi_ok) { - LOGE("create private key ref failed when do sign init!"); + LOGE_ONE_STR("create private key ref failed when do sign init!"); return false; } @@ -231,14 +231,14 @@ static bool BuildSignJsUpdateCtx(napi_env env, napi_callback_info info, SignUpda NapiSign *napiSign = nullptr; napi_status status = napi_unwrap(env, thisVar, reinterpret_cast(&napiSign)); if (status != napi_ok || napiSign == nullptr) { - LOGE("failed to unwrap napi sign obj."); + LOGE_ONE_STR("failed to unwrap napi sign obj."); return false; } size_t index = 0; HcfBlob *blob = GetBlobFromNapiDataBlob(env, argv[index]); if (blob == nullptr) { - LOGE("failed to get data."); + LOGE_ONE_STR("failed to get data."); return false; } @@ -246,7 +246,7 @@ static bool BuildSignJsUpdateCtx(napi_env env, napi_callback_info info, SignUpda ctx->data = blob; if (napi_create_reference(env, thisVar, 1, &ctx->signRef) != napi_ok) { - LOGE("create sign ref failed when do sign update!"); + LOGE_ONE_STR("create sign ref failed when do sign update!"); return false; } @@ -274,7 +274,7 @@ static bool BuildSignJsDoFinalCtx(napi_env env, napi_callback_info info, SignDoF NapiSign *napiSign = nullptr; napi_status status = napi_unwrap(env, thisVar, reinterpret_cast(&napiSign)); if (status != napi_ok || napiSign == nullptr) { - LOGE("failed to unwrap napi sign obj."); + LOGE_ONE_STR("failed to unwrap napi sign obj."); return false; } @@ -285,7 +285,7 @@ static bool BuildSignJsDoFinalCtx(napi_env env, napi_callback_info info, SignDoF if (valueType != napi_null) { data = GetBlobFromNapiDataBlob(env, argv[index]); if (data == nullptr) { - LOGE("failed to get data."); + LOGE_ONE_STR("failed to get data."); return false; } } @@ -294,7 +294,7 @@ static bool BuildSignJsDoFinalCtx(napi_env env, napi_callback_info info, SignDoF ctx->data = data; if (napi_create_reference(env, thisVar, 1, &ctx->signRef) != napi_ok) { - LOGE("create sign ref failed when do sign final!"); + LOGE_ONE_STR("create sign ref failed when do sign final!"); return false; } @@ -393,7 +393,7 @@ static void SignJsInitAsyncWorkProcess(napi_env env, void *data) ctx->errCode = ctx->sign->init(ctx->sign, ctx->params, ctx->priKey); if (ctx->errCode != HCF_SUCCESS) { - LOGD("[error] sign init fail."); + LOGD_ONE_STR("[error] sign init fail."); ctx->errMsg = "sign init fail."; } } @@ -416,7 +416,7 @@ static void SignJsUpdateAsyncWorkProcess(napi_env env, void *data) ctx->errCode = ctx->sign->update(ctx->sign, ctx->data); if (ctx->errCode != HCF_SUCCESS) { - LOGD("[error] sign update fail."); + LOGD_ONE_STR("[error] sign update fail."); ctx->errMsg = "sign update fail."; } } @@ -439,7 +439,7 @@ static void SignJsDoFinalAsyncWorkProcess(napi_env env, void *data) ctx->errCode = ctx->sign->sign(ctx->sign, ctx->data, &ctx->returnSignatureData); if (ctx->errCode != HCF_SUCCESS) { - LOGD("[error] sign doFinal fail."); + LOGD_ONE_STR("[error] sign doFinal fail."); ctx->errMsg = "sign doFinal fail."; } } @@ -559,13 +559,13 @@ napi_value NapiSign::JsInit(napi_env env, napi_callback_info info) SignInitCtx *ctx = static_cast(HcfMalloc(sizeof(SignInitCtx), 0)); if (ctx == nullptr) { napi_throw(env, GenerateBusinessError(env, HCF_ERR_MALLOC, "create context fail.")); - LOGE("create context fail."); + LOGE_ONE_STR("create context fail."); return nullptr; } if (!BuildSignJsInitCtx(env, info, ctx)) { napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "build context fail.")); - LOGE("build context fail."); + LOGE_ONE_STR("build context fail."); FreeSignInitCtx(env, ctx); return nullptr; } @@ -589,7 +589,7 @@ napi_value NapiSign::JsInitSync(napi_env env, napi_callback_info info) NapiSign *napiSign = nullptr; napi_status status = napi_unwrap(env, thisVar, reinterpret_cast(&napiSign)); if (status != napi_ok || napiSign == nullptr) { - LOGE("failed to unwrap napi sign obj."); + LOGE_ONE_STR("failed to unwrap napi sign obj."); napi_throw(env, GenerateBusinessError(env, HCF_ERR_NAPI, "failed to unwrap napi sign obj.")); return nullptr; } @@ -597,7 +597,7 @@ napi_value NapiSign::JsInitSync(napi_env env, napi_callback_info info) NapiPriKey *napiPriKey = nullptr; status = napi_unwrap(env, argv[PARAM0], reinterpret_cast(&napiPriKey)); if (status != napi_ok || napiPriKey == nullptr) { - LOGE("failed to unwrap napi priKey obj."); + LOGE_ONE_STR("failed to unwrap napi priKey obj."); napi_throw(env, GenerateBusinessError(env, HCF_ERR_NAPI, "failed to unwrap napi priKey obj.")); return nullptr; } @@ -606,7 +606,7 @@ napi_value NapiSign::JsInitSync(napi_env env, napi_callback_info info) HcfPriKey *priKey = napiPriKey->GetPriKey(); HcfResult ret = sign->init(sign, nullptr, priKey); if (ret != HCF_SUCCESS) { - LOGD("sign init fail."); + LOGD_ONE_STR("sign init fail."); napi_throw(env, GenerateBusinessError(env, ret, "sign init fail.")); return nullptr; } @@ -619,13 +619,13 @@ napi_value NapiSign::JsUpdate(napi_env env, napi_callback_info info) SignUpdateCtx *ctx = static_cast(HcfMalloc(sizeof(SignUpdateCtx), 0)); if (ctx == nullptr) { napi_throw(env, GenerateBusinessError(env, HCF_ERR_MALLOC, "create context fail.")); - LOGE("create context fail."); + LOGE_ONE_STR("create context fail."); return nullptr; } if (!BuildSignJsUpdateCtx(env, info, ctx)) { napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "build context fail.")); - LOGE("build context fail."); + LOGE_ONE_STR("build context fail."); FreeSignUpdateCtx(env, ctx); return nullptr; } @@ -648,7 +648,7 @@ napi_value NapiSign::JsUpdateSync(napi_env env, napi_callback_info info) NapiSign *napiSign = nullptr; napi_status status = napi_unwrap(env, thisVar, reinterpret_cast(&napiSign)); if (status != napi_ok || napiSign == nullptr) { - LOGE("failed to unwrap napi sign obj."); + LOGE_ONE_STR("failed to unwrap napi sign obj."); napi_throw(env, GenerateBusinessError(env, HCF_ERR_NAPI, "failed to unwrap napi sign obj.")); return nullptr; } @@ -656,7 +656,7 @@ napi_value NapiSign::JsUpdateSync(napi_env env, napi_callback_info info) HcfBlob blob = { 0 }; HcfResult ret = GetBlobFromNapiValue(env, argv[PARAM0], &blob); if (ret != HCF_SUCCESS) { - LOGE("failed to get input blob!"); + LOGE_ONE_STR("failed to get input blob!"); napi_throw(env, GenerateBusinessError(env, ret, "failed to get data.")); return nullptr; } @@ -665,7 +665,7 @@ napi_value NapiSign::JsUpdateSync(napi_env env, napi_callback_info info) ret = sign->update(sign, &blob); HcfBlobDataFree(&blob); if (ret != HCF_SUCCESS) { - LOGD("sign update fail."); + LOGD_ONE_STR("sign update fail."); napi_throw(env, GenerateBusinessError(env, ret, "sign update fail.")); return nullptr; } @@ -678,13 +678,13 @@ napi_value NapiSign::JsSign(napi_env env, napi_callback_info info) SignDoFinalCtx *ctx = static_cast(HcfMalloc(sizeof(SignDoFinalCtx), 0)); if (ctx == nullptr) { napi_throw(env, GenerateBusinessError(env, HCF_ERR_MALLOC, "create context fail.")); - LOGE("create context fail."); + LOGE_ONE_STR("create context fail."); return nullptr; } if (!BuildSignJsDoFinalCtx(env, info, ctx)) { napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "build context fail.")); - LOGE("build context fail."); + LOGE_ONE_STR("build context fail."); FreeSignDoFinalCtx(env, ctx); return nullptr; } @@ -707,7 +707,7 @@ napi_value NapiSign::JsSignSync(napi_env env, napi_callback_info info) NapiSign *napiSign = nullptr; napi_status status = napi_unwrap(env, thisVar, reinterpret_cast(&napiSign)); if (status != napi_ok || napiSign == nullptr) { - LOGE("failed to unwrap napi sign obj."); + LOGE_ONE_STR("failed to unwrap napi sign obj."); napi_throw(env, GenerateBusinessError(env, HCF_ERR_NAPI, "failed to unwrap napi sign obj.")); return nullptr; } @@ -719,7 +719,7 @@ napi_value NapiSign::JsSignSync(napi_env env, napi_callback_info info) if (valueType != napi_null) { HcfResult ret = GetBlobFromNapiValue(env, argv[PARAM0], &blob); if (ret != HCF_SUCCESS) { - LOGE("failed to get data."); + LOGE_ONE_STR("failed to get data."); napi_throw(env, GenerateBusinessError(env, ret, "failed to get data.")); return nullptr; } @@ -731,7 +731,7 @@ napi_value NapiSign::JsSignSync(napi_env env, napi_callback_info info) HcfResult ret = sign->sign(sign, data, &returnSignatureData); HcfBlobDataFree(data); if (ret != HCF_SUCCESS) { - LOGD("sign doFinal fail."); + LOGD_ONE_STR("sign doFinal fail."); napi_throw(env, GenerateBusinessError(env, ret, "sign doFinal fail.")); return nullptr; } @@ -740,7 +740,7 @@ napi_value NapiSign::JsSignSync(napi_env env, napi_callback_info info) ret = ConvertDataBlobToNapiValue(env, &returnSignatureData, &instance); HcfBlobDataFree(&returnSignatureData); if (ret != HCF_SUCCESS) { - LOGE("sign convert dataBlob to napi_value failed!"); + LOGE_ONE_STR("sign convert dataBlob to napi_value failed!"); napi_throw(env, GenerateBusinessError(env, ret, "sign convert dataBlob to napi_value failed!")); return nullptr; } @@ -765,7 +765,7 @@ static napi_value NapiWrapSign(napi_env env, napi_value instance, NapiSign *napi return; }, nullptr, nullptr); if (status != napi_ok) { - LOGE("failed to wrap napiSign obj!"); + LOGE_ONE_STR("failed to wrap napiSign obj!"); delete napiSign; return nullptr; } @@ -781,7 +781,7 @@ napi_value NapiSign::CreateJsSign(napi_env env, napi_callback_info info) if (argc != expectedArgc) { napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "The input args num is invalid.")); - LOGE("The input args num is invalid."); + LOGE_ONE_STR("The input args num is invalid."); return nullptr; } @@ -800,14 +800,14 @@ napi_value NapiSign::CreateJsSign(napi_env env, napi_callback_info info) HcfResult ret = HcfSignCreate(algName.c_str(), &sign); if (ret != HCF_SUCCESS) { napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "create c sign fail.")); - LOGE("create c sign fail."); + LOGE_ONE_STR("create c sign fail."); return nullptr; } NapiSign *napiSign = new (std::nothrow) NapiSign(sign); if (napiSign == nullptr) { napi_throw(env, GenerateBusinessError(env, HCF_ERR_MALLOC, "new napi sign failed")); - LOGE("new napi sign failed"); + LOGE_ONE_STR("new napi sign failed"); HcfObjDestroy(sign); return nullptr; } @@ -824,14 +824,14 @@ static HcfResult SetSignUserIdUintArray(napi_env env, napi_value *argv, HcfSign HcfBlob *blob = nullptr; blob = GetBlobFromNapiUint8Arr(env, argv[1]); if (blob == nullptr) { - LOGE("failed to get blob."); + LOGE_ONE_STR("failed to get blob."); return HCF_INVALID_PARAMS; } HcfResult ret = sign->setSignSpecUint8Array(sign, SM2_USER_ID_UINT8ARR, *blob); if (ret != HCF_SUCCESS) { HcfBlobDataFree(blob); HcfFree(blob); - LOGE("c setSignSpecUint8Array failed."); + LOGE_ONE_STR("c setSignSpecUint8Array failed."); return HCF_INVALID_PARAMS; } HcfBlobDataFree(blob); @@ -843,13 +843,13 @@ static HcfResult SetSignSaltLenInt(napi_env env, napi_value *argv, HcfSign *sign { int32_t saltLen = 0; if (napi_get_value_int32(env, argv[1], &saltLen) != napi_ok) { - LOGE("get signSpec saltLen failed!"); + LOGE_ONE_STR("get signSpec saltLen failed!"); return HCF_INVALID_PARAMS; } HcfResult ret = HCF_SUCCESS; ret = sign->setSignSpecInt(sign, PSS_SALT_LEN_INT, saltLen); if (ret != HCF_SUCCESS) { - LOGE("c setSignSpecNumber fail."); + LOGE_ONE_STR("c setSignSpecNumber fail."); return HCF_INVALID_PARAMS; } return ret; @@ -867,7 +867,7 @@ static HcfResult SetDetailSignSpec(napi_env env, napi_value *argv, SignSpecItem result = SetSignSaltLenInt(env, argv, sign); break; default: - LOGE("specItem not support."); + LOGE_ONE_STR("specItem not support."); break; } return result; @@ -891,19 +891,19 @@ napi_value NapiSign::JsSetSignSpec(napi_env env, napi_callback_info info) SignSpecItem item; if (napi_get_value_uint32(env, argv[0], reinterpret_cast(&item)) != napi_ok) { napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "get signSpecItem failed!")); - LOGE("get signspecitem failed!"); + LOGE_ONE_STR("get signspecitem failed!"); return nullptr; } napi_status status = napi_unwrap(env, thisVar, reinterpret_cast(&napiSign)); if (status != napi_ok || napiSign == nullptr) { napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "failed to unwrap napiSign obj!")); - LOGE("failed to unwrap napiSign obj!"); + LOGE_ONE_STR("failed to unwrap napiSign obj!"); return nullptr; } HcfSign *sign = napiSign->GetSign(); if (SetDetailSignSpec(env, argv, item, sign) != HCF_SUCCESS) { napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "failed to set sign spec!")); - LOGE("failed to set sign spec!"); + LOGE_ONE_STR("failed to set sign spec!"); return nullptr; } return thisVar; @@ -915,7 +915,7 @@ static napi_value GetSignSpecString(napi_env env, SignSpecItem item, HcfSign *si HcfResult ret = sign->getSignSpecString(sign, item, &returnString); if (ret != HCF_SUCCESS) { napi_throw(env, GenerateBusinessError(env, ret, "C getSignSpecString failed.")); - LOGE("c getSignSpecString fail."); + LOGE_ONE_STR("c getSignSpecString fail."); return nullptr; } @@ -931,7 +931,7 @@ static napi_value GetSignSpecNumber(napi_env env, SignSpecItem item, HcfSign *si HcfResult ret = sign->getSignSpecInt(sign, item, &returnInt); if (ret != HCF_SUCCESS) { napi_throw(env, GenerateBusinessError(env, ret, "C getSignSpecInt failed.")); - LOGE("c getSignSpecInt fail."); + LOGE_ONE_STR("c getSignSpecInt fail."); return nullptr; } @@ -956,20 +956,20 @@ napi_value NapiSign::JsGetSignSpec(napi_env env, napi_callback_info info) SignSpecItem item; if (napi_get_value_uint32(env, argv[0], reinterpret_cast(&item)) != napi_ok) { napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "get signSpecItem failed!")); - LOGE("get signSpecItem failed!"); + LOGE_ONE_STR("get signSpecItem failed!"); return nullptr; } napi_status status = napi_unwrap(env, thisVar, reinterpret_cast(&napiSign)); if (status != napi_ok || napiSign == nullptr) { napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "failed to unwrap napiSign obj!")); - LOGE("failed to unwrap napiSign obj!"); + LOGE_ONE_STR("failed to unwrap napiSign obj!"); return nullptr; } HcfSign *sign = napiSign->GetSign(); if (sign == nullptr) { napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "failed to get sign obj!")); - LOGE("failed to get sign obj!"); + LOGE_ONE_STR("failed to get sign obj!"); return nullptr; } diff --git a/frameworks/js/napi/crypto/src/napi_sm2_crypto_util.cpp b/frameworks/js/napi/crypto/src/napi_sm2_crypto_util.cpp index d44e4262b11e0506488028cccc446372e92f3298..19d5c108e24e95fb10a33c800e86c90e74d8281c 100644 --- a/frameworks/js/napi/crypto/src/napi_sm2_crypto_util.cpp +++ b/frameworks/js/napi/crypto/src/napi_sm2_crypto_util.cpp @@ -35,7 +35,7 @@ static HcfBlob *GetBlobFromNapi(napi_env env, napi_value arg, const std::string napi_status status = napi_get_named_property(env, arg, name.c_str(), &data); napi_typeof(env, data, &valueType); if ((status != napi_ok) || (data == nullptr) || (valueType == napi_undefined)) { - LOGE("failed to get valid salt"); + LOGE_ONE_STR("failed to get valid salt"); return nullptr; } return GetBlobFromNapiUint8Arr(env, data); @@ -44,42 +44,42 @@ static HcfBlob *GetBlobFromNapi(napi_env env, napi_value arg, const std::string static bool GetSm2CipherTextSpecFromNapiValue(napi_env env, napi_value arg, Sm2CipherTextSpec **returnSpec) { if ((env == nullptr) || (arg == nullptr) || (returnSpec == nullptr)) { - LOGE("Invalid params."); + LOGE_ONE_STR("Invalid params."); return false; } Sm2CipherTextSpec *tempSpec = static_cast(HcfMalloc(sizeof(Sm2CipherTextSpec), 0)); if (tempSpec == nullptr) { - LOGE("Malloc failed!"); + LOGE_ONE_STR("Malloc failed!"); return false; } napi_value xCoordinate = GetDetailAsyKeySpecValue(env, arg, SM2_UTIL_PARAM_X_COORDINATE); napi_value yCoordinate = GetDetailAsyKeySpecValue(env, arg, SM2_UTIL_PARAM_Y_COORDINATE); if ((xCoordinate == nullptr) || (yCoordinate == nullptr)) { - LOGE("Invalid params!"); + LOGE_ONE_STR("Invalid params!"); DestroySm2CipherTextSpec(tempSpec); return false; } bool ret = GetBigIntFromNapiValue(env, xCoordinate, &tempSpec->xCoordinate); if (!ret) { - LOGE("Failed to get valid x coordinate."); + LOGE_ONE_STR("Failed to get valid x coordinate."); DestroySm2CipherTextSpec(tempSpec); return false; } ret = GetBigIntFromNapiValue(env, yCoordinate, &tempSpec->yCoordinate); if (!ret) { - LOGE("Failed to get valid y coordinate."); + LOGE_ONE_STR("Failed to get valid y coordinate."); DestroySm2CipherTextSpec(tempSpec); return false; } HcfBlob *cipherTextBlob = GetBlobFromNapi(env, arg, SM2_UTIL_PARAM_CIPHER_TEXT_DATA); if (cipherTextBlob == nullptr) { - LOGE("Failed to get valid cipherTextData."); + LOGE_ONE_STR("Failed to get valid cipherTextData."); DestroySm2CipherTextSpec(tempSpec); return false; } HcfBlob *hashDataBlob = GetBlobFromNapi(env, arg, SM2_UTIL_PARAM_HASH_DATA); if (hashDataBlob == nullptr) { - LOGE("Failed to get valid hashData."); + LOGE_ONE_STR("Failed to get valid hashData."); HcfBlobDataFree(cipherTextBlob); HcfFree(cipherTextBlob); DestroySm2CipherTextSpec(tempSpec); @@ -114,20 +114,20 @@ napi_value NapiSm2CryptoUtil::JsGenCipherTextBySpec(napi_env env, napi_callback_ napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr); // second attribute mode can be null if ((argc != expectedArgc) && (argc != (expectedArgc - 1))) { - LOGE("The input args num is invalid."); + LOGE_ONE_STR("The input args num is invalid."); napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "The input args num is invalid.")); return nullptr; } Sm2CipherTextSpec *spec = nullptr; if (!GetSm2CipherTextSpecFromNapiValue(env, argv[0], &spec)) { - LOGE("Failed to get spec."); + LOGE_ONE_STR("Failed to get spec."); napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "failed to get spec.")); return nullptr; } std::string dataMode; if (argc == expectedArgc) { if (!DealMode(env, argv[1], dataMode)) { - LOGE("Failed to get mode."); + LOGE_ONE_STR("Failed to get mode."); DestroySm2CipherTextSpec(spec); napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "failed to get mode.")); return nullptr; @@ -135,14 +135,14 @@ napi_value NapiSm2CryptoUtil::JsGenCipherTextBySpec(napi_env env, napi_callback_ } HcfBlob *output = static_cast(HcfMalloc(sizeof(HcfBlob), 0)); if (output == NULL) { - LOGE("Failed to allocate HcfBlob memory!"); + LOGE_ONE_STR("Failed to allocate HcfBlob memory!"); DestroySm2CipherTextSpec(spec); napi_throw(env, GenerateBusinessError(env, HCF_ERR_MALLOC, "Failed to allocate memory.")); return nullptr; } HcfResult res = HcfGenCipherTextBySpec(spec, dataMode.c_str(), output); if (res != HCF_SUCCESS) { - LOGE("Gen cipher text by spec fail."); + LOGE_ONE_STR("Gen cipher text by spec fail."); HcfFree(output); DestroySm2CipherTextSpec(spec); napi_throw(env, GenerateBusinessError(env, res, "gen cipher text by spec fail.")); @@ -158,23 +158,23 @@ napi_value NapiSm2CryptoUtil::JsGenCipherTextBySpec(napi_env env, napi_callback_ static bool CheckSm2CipherTextSpec(Sm2CipherTextSpec *spec) { if (spec == nullptr) { - LOGE("Invalid spec!"); + LOGE_ONE_STR("Invalid spec!"); return false; } if (spec->xCoordinate.data == nullptr || spec->xCoordinate.len == 0) { - LOGE("Invalid xCoordinate!"); + LOGE_ONE_STR("Invalid xCoordinate!"); return false; } if (spec->yCoordinate.data == nullptr || spec->yCoordinate.len == 0) { - LOGE("Invalid yCoordinate!"); + LOGE_ONE_STR("Invalid yCoordinate!"); return false; } if (spec->cipherTextData.data == nullptr || spec->cipherTextData.len == 0) { - LOGE("Invalid cipherTextData!"); + LOGE_ONE_STR("Invalid cipherTextData!"); return false; } if (spec->hashData.data == nullptr || spec->hashData.len == 0) { - LOGE("Invalid hashData!"); + LOGE_ONE_STR("Invalid hashData!"); return false; } return true; @@ -185,7 +185,7 @@ static bool BuildBlobNapiValue(napi_env env, HcfBlob *blob, const char *name, na napi_value napiData = ConvertObjectBlobToNapiValue(env, blob); napi_status status = napi_set_named_property(env, *instance, name, napiData); if (status != napi_ok) { - LOGE("Build blob[napi_value] failed!"); + LOGE_ONE_STR("Build blob[napi_value] failed!"); return false; } return true; @@ -194,19 +194,19 @@ static bool BuildBlobNapiValue(napi_env env, HcfBlob *blob, const char *name, na static bool BuildSm2CipherTextSpecToNapiValue(napi_env env, Sm2CipherTextSpec *spec, napi_value *instance) { if (!BuildSetNamedProperty(env, &(spec->xCoordinate), SM2_UTIL_PARAM_X_COORDINATE.c_str(), instance)) { - LOGE("Build xCoordinate failed!"); + LOGE_ONE_STR("Build xCoordinate failed!"); return false; } if (!BuildSetNamedProperty(env, &(spec->yCoordinate), SM2_UTIL_PARAM_Y_COORDINATE.c_str(), instance)) { - LOGE("Build yCoordinate failed!"); + LOGE_ONE_STR("Build yCoordinate failed!"); return false; } if (!BuildBlobNapiValue(env, &(spec->cipherTextData), SM2_UTIL_PARAM_CIPHER_TEXT_DATA.c_str(), instance)) { - LOGE("Build cipherTextData failed!"); + LOGE_ONE_STR("Build cipherTextData failed!"); return false; } if (!BuildBlobNapiValue(env, &(spec->hashData), SM2_UTIL_PARAM_HASH_DATA.c_str(), instance)) { - LOGE("Build hashData failed!"); + LOGE_ONE_STR("Build hashData failed!"); return false; } return true; @@ -215,19 +215,19 @@ static bool BuildSm2CipherTextSpecToNapiValue(napi_env env, Sm2CipherTextSpec *s static napi_value ConvertSm2CipherTextSpecToNapiValue(napi_env env, Sm2CipherTextSpec *spec) { if (!CheckSm2CipherTextSpec(spec)) { - LOGE("Invalid spec!"); + LOGE_ONE_STR("Invalid spec!"); napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "Invalid spec!")); return NapiGetNull(env); } napi_value instance; napi_status status = napi_create_object(env, &instance); if (status != napi_ok) { - LOGE("Create object failed!"); + LOGE_ONE_STR("Create object failed!"); napi_throw(env, GenerateBusinessError(env, HCF_ERR_MALLOC, "create object failed!")); return NapiGetNull(env); } if (!BuildSm2CipherTextSpecToNapiValue(env, spec, &instance)) { - LOGE("Build object failed!"); + LOGE_ONE_STR("Build object failed!"); napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "build object failed!")); return NapiGetNull(env); } @@ -242,20 +242,20 @@ napi_value NapiSm2CryptoUtil::JsGetCipherTextSpec(napi_env env, napi_callback_in napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr); // second attribute mode can be null if ((argc != expectedArgc) && (argc != (expectedArgc - 1))) { - LOGE("The input args num is invalid."); + LOGE_ONE_STR("The input args num is invalid."); napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "The input args num is invalid.")); return nullptr; } HcfBlob *cipherText = GetBlobFromNapiDataBlob(env, argv[0]); if (cipherText == nullptr) { - LOGE("Failed to get cipherText."); + LOGE_ONE_STR("Failed to get cipherText."); napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "failed to get cipherText.")); return nullptr; } std::string dataMode; if (argc == expectedArgc) { if (!DealMode(env, argv[1], dataMode)) { - LOGE("Failed to get mode."); + LOGE_ONE_STR("Failed to get mode."); HcfBlobDataFree(cipherText); HcfFree(cipherText); napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "failed to get mode.")); @@ -265,7 +265,7 @@ napi_value NapiSm2CryptoUtil::JsGetCipherTextSpec(napi_env env, napi_callback_in Sm2CipherTextSpec *returnSpec = nullptr; HcfResult res = HcfGetCipherTextSpec(cipherText, dataMode.c_str(), &returnSpec); if (res != HCF_SUCCESS) { - LOGE("Get cipher text spec fail."); + LOGE_ONE_STR("Get cipher text spec fail."); HcfBlobDataFree(cipherText); HcfFree(cipherText); napi_throw(env, GenerateBusinessError(env, res, "get cipher text spec fail.")); diff --git a/frameworks/js/napi/crypto/src/napi_sym_key.cpp b/frameworks/js/napi/crypto/src/napi_sym_key.cpp index 4f0edfb272437dad03d596edf0cf5f9debbabcdc..9e4f0bf3440efaae34ff9826a10737e0263b093e 100644 --- a/frameworks/js/napi/crypto/src/napi_sym_key.cpp +++ b/frameworks/js/napi/crypto/src/napi_sym_key.cpp @@ -46,7 +46,7 @@ napi_value NapiSymKey::JsClearMem(napi_env env, napi_callback_info info) napi_status status = napi_unwrap(env, thisVar, reinterpret_cast(&napiSymKey)); if (status != napi_ok || napiSymKey == nullptr) { napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "failed to unwrap napiSymKey obj!")); - LOGE("failed to unwrap napiSymKey obj!"); + LOGE_ONE_STR("failed to unwrap napiSymKey obj!"); return nullptr; } HcfSymKey *key = napiSymKey->GetSymKey(); diff --git a/frameworks/js/napi/crypto/src/napi_sym_key_generator.cpp b/frameworks/js/napi/crypto/src/napi_sym_key_generator.cpp index 321d1d0ff7fd5d43750ef1ed9870f69618f7e06e..c9b4c70a3bed1e11a9ef74060b0fb68d557dbd12 100644 --- a/frameworks/js/napi/crypto/src/napi_sym_key_generator.cpp +++ b/frameworks/js/napi/crypto/src/napi_sym_key_generator.cpp @@ -93,18 +93,18 @@ static bool BuildContextForGenerateKey(napi_env env, napi_callback_info info, Sy NapiSymKeyGenerator *napiGenerator = nullptr; napi_status status = napi_unwrap(env, thisVar, reinterpret_cast(&napiGenerator)); if (status != napi_ok || napiGenerator == nullptr) { - LOGE("failed to unwrap NapiSymKeyGenerator obj!"); + LOGE_ONE_STR("failed to unwrap NapiSymKeyGenerator obj!"); return false; } context->generator = napiGenerator->GetSymKeyGenerator(); if (context->generator == nullptr) { - LOGE("failed to get generator obj!"); + LOGE_ONE_STR("failed to get generator obj!"); return false; } if (napi_create_reference(env, thisVar, 1, &context->symKeyGeneratorRef) != napi_ok) { - LOGE("create sym key generator ref failed when generate sym key!"); + LOGE_ONE_STR("create sym key generator ref failed when generate sym key!"); return false; } @@ -132,27 +132,27 @@ static bool BuildContextForConvertKey(napi_env env, napi_callback_info info, Sym NapiSymKeyGenerator *napiGenerator = nullptr; napi_status status = napi_unwrap(env, thisVar, reinterpret_cast(&napiGenerator)); if (status != napi_ok || napiGenerator == nullptr) { - LOGE("failed to unwrap NapiSymKeyGenerator obj!"); + LOGE_ONE_STR("failed to unwrap NapiSymKeyGenerator obj!"); return false; } context->generator = napiGenerator->GetSymKeyGenerator(); if (context->generator == nullptr) { - LOGE("failed to get generator obj!"); + LOGE_ONE_STR("failed to get generator obj!"); return false; } size_t index = 0; HcfBlob *blob = GetBlobFromNapiDataBlob(env, argv[index++]); if (blob == nullptr) { - LOGE("get keyMaterial failed!"); + LOGE_ONE_STR("get keyMaterial failed!"); return false; } context->keyMaterial = *blob; HcfFree(blob); if (napi_create_reference(env, thisVar, 1, &context->symKeyGeneratorRef) != napi_ok) { - LOGE("create sym key generator ref failed when covert sym key!"); + LOGE_ONE_STR("create sym key generator ref failed when covert sym key!"); return false; } @@ -199,7 +199,7 @@ static void AsyncGenKeyProcess(napi_env env, void *data) HcfSymKey *key = nullptr; context->errCode = generator->generateSymKey(generator, &key); if (context->errCode != HCF_SUCCESS) { - LOGE("generate sym key failed."); + LOGE_ONE_STR("generate sym key failed."); context->errMsg = "generate sym key failed."; return; } @@ -216,7 +216,7 @@ static void AsyncKeyReturn(napi_env env, napi_status status, void *data) if (napiSymKey == nullptr) { napi_throw(env, GenerateBusinessError(env, HCF_ERR_MALLOC, "new napi sym key failed.")); FreeSymKeyGeneratorFwkCtx(env, context); - LOGE("new napi sym key failed."); + LOGE_ONE_STR("new napi sym key failed."); return; } @@ -227,7 +227,7 @@ static void AsyncKeyReturn(napi_env env, napi_status status, void *data) return; }, nullptr, nullptr); if (ret != napi_ok) { - LOGE("failed to wrap napiSymKey obj!"); + LOGE_ONE_STR("failed to wrap napiSymKey obj!"); context->errCode = HCF_INVALID_PARAMS; context->errMsg = "failed to wrap napiSymKey obj!"; delete napiSymKey; @@ -249,7 +249,7 @@ static void AsyncConvertKeyProcess(napi_env env, void *data) HcfSymKey *key = nullptr; context->errCode = generator->convertSymKey(generator, &context->keyMaterial, &key); if (context->errCode != HCF_SUCCESS) { - LOGE("convertSymKey key failed!"); + LOGE_ONE_STR("convertSymKey key failed!"); context->errMsg = "convert sym key failed."; return; } @@ -333,7 +333,7 @@ static bool napiGetInstance(napi_env env, HcfSymKey *key, napi_value instance) NapiSymKey *napiSymKey = new (std::nothrow) NapiSymKey(key); if (napiSymKey == nullptr) { napi_throw(env, GenerateBusinessError(env, HCF_ERR_MALLOC, "new napi sym key failed.")); - LOGE("new napi sym key failed."); + LOGE_ONE_STR("new napi sym key failed."); HcfObjDestroy(key); return false; } @@ -346,7 +346,7 @@ static bool napiGetInstance(napi_env env, HcfSymKey *key, napi_value instance) return; }, nullptr, nullptr); if (wrapStatus != napi_ok) { - LOGE("failed to wrap napiSymKey obj!"); + LOGE_ONE_STR("failed to wrap napiSymKey obj!"); delete napiSymKey; return false; } @@ -359,20 +359,20 @@ napi_value NapiSymKeyGenerator::JsGenerateSymKey(napi_env env, napi_callback_inf SymKeyGeneratorFwkCtx context = static_cast(HcfMalloc(sizeof(SymKeyGeneratorFwkCtxT), 0)); if (context == nullptr) { napi_throw(env, GenerateBusinessError(env, HCF_ERR_MALLOC, "Create context failed!")); - LOGE("Create context failed!"); + LOGE_ONE_STR("Create context failed!"); return nullptr; } if (!BuildContextForGenerateKey(env, info, context)) { napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "Build context fail.")); - LOGE("Build context fail."); + LOGE_ONE_STR("Build context fail."); FreeSymKeyGeneratorFwkCtx(env, context); return nullptr; } napi_value result = NewGenKeyAsyncWork(env, context); if (result == nullptr) { - LOGE("NewGenKeyAsyncWork failed!"); + LOGE_ONE_STR("NewGenKeyAsyncWork failed!"); FreeSymKeyGeneratorFwkCtx(env, context); return nullptr; } @@ -387,14 +387,14 @@ napi_value NapiSymKeyGenerator::JsGenerateSymKeySync(napi_env env, napi_callback napi_status unwrapStatus = napi_unwrap(env, thisVar, reinterpret_cast(&napiGenerator)); if (unwrapStatus != napi_ok || napiGenerator == nullptr) { napi_throw(env, GenerateBusinessError(env, HCF_ERR_MALLOC, "failed to unwrap NapiSymKeyGenerator obj.")); - LOGE("failed to unwrap NapiSymKeyGenerator obj!"); + LOGE_ONE_STR("failed to unwrap NapiSymKeyGenerator obj!"); return nullptr; } HcfSymKeyGenerator *generator = napiGenerator->GetSymKeyGenerator(); if (generator == nullptr) { napi_throw(env, GenerateBusinessError(env, HCF_ERR_MALLOC, "failed to get generator obj.")); - LOGE("failed to get generator obj!"); + LOGE_ONE_STR("failed to get generator obj!"); return nullptr; } @@ -402,14 +402,14 @@ napi_value NapiSymKeyGenerator::JsGenerateSymKeySync(napi_env env, napi_callback HcfResult ret = generator->generateSymKey(generator, &key); if (ret != HCF_SUCCESS) { napi_throw(env, GenerateBusinessError(env, HCF_ERR_MALLOC, "generate sym key failed.")); - LOGE("generate sym key failed."); + LOGE_ONE_STR("generate sym key failed."); return nullptr; } napi_value instance = NapiSymKey::CreateSymKey(env); if (!napiGetInstance(env, key, instance)) { napi_throw(env, GenerateBusinessError(env, HCF_ERR_MALLOC, "get instance failed!")); - LOGE("get instance failed!"); + LOGE_ONE_STR("get instance failed!"); return nullptr; } @@ -421,20 +421,20 @@ napi_value NapiSymKeyGenerator::JsConvertKey(napi_env env, napi_callback_info in SymKeyGeneratorFwkCtx context = static_cast(HcfMalloc(sizeof(SymKeyGeneratorFwkCtxT), 0)); if (context == nullptr) { napi_throw(env, GenerateBusinessError(env, HCF_ERR_MALLOC, "malloc SymKeyGeneratorFwkCtx failed!")); - LOGE("malloc SymKeyGeneratorFwkCtx failed!"); + LOGE_ONE_STR("malloc SymKeyGeneratorFwkCtx failed!"); return nullptr; } if (!BuildContextForConvertKey(env, info, context)) { napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "BuildContextForConvertKey failed!")); - LOGE("BuildContextForConvertKey failed!"); + LOGE_ONE_STR("BuildContextForConvertKey failed!"); FreeSymKeyGeneratorFwkCtx(env, context); return nullptr; } napi_value result = NewConvertKeyAsyncWork(env, context); if (result == nullptr) { - LOGE("Get deviceauth async work failed!"); + LOGE_ONE_STR("Get deviceauth async work failed!"); FreeSymKeyGeneratorFwkCtx(env, context); return nullptr; } @@ -456,7 +456,7 @@ napi_value NapiSymKeyGenerator::JsConvertKeySync(napi_env env, napi_callback_inf NapiSymKeyGenerator *napiGenerator = nullptr; napi_status unwrapStatus = napi_unwrap(env, thisVar, reinterpret_cast(&napiGenerator)); if (unwrapStatus != napi_ok || napiGenerator == nullptr) { - LOGE("failed to unwrap NapiSymKeyGenerator obj!"); + LOGE_ONE_STR("failed to unwrap NapiSymKeyGenerator obj!"); napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "failed to unwrap NapiSymKeyGenerator obj!")); return nullptr; } @@ -464,14 +464,14 @@ napi_value NapiSymKeyGenerator::JsConvertKeySync(napi_env env, napi_callback_inf HcfSymKeyGenerator *generator = napiGenerator->GetSymKeyGenerator(); if (generator == nullptr) { napi_throw(env, GenerateBusinessError(env, HCF_ERR_MALLOC, "failed to get generator obj!")); - LOGE("failed to get generator obj!"); + LOGE_ONE_STR("failed to get generator obj!"); return nullptr; } HcfBlob *keyMaterial = GetBlobFromNapiDataBlob(env, argv[PARAM0]); if (keyMaterial == nullptr) { napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "get keyMaterial failed!")); - LOGE("get keyMaterial failed!"); + LOGE_ONE_STR("get keyMaterial failed!"); return nullptr; } @@ -481,14 +481,14 @@ napi_value NapiSymKeyGenerator::JsConvertKeySync(napi_env env, napi_callback_inf HcfFree(keyMaterial); if (ret != HCF_SUCCESS) { napi_throw(env, GenerateBusinessError(env, ret, "convertSymKey key failed!")); - LOGE("convertSymKey key failed!"); + LOGE_ONE_STR("convertSymKey key failed!"); return nullptr; } napi_value instance = NapiSymKey::CreateSymKey(env); if (!napiGetInstance(env, key, instance)) { napi_throw(env, GenerateBusinessError(env, HCF_ERR_MALLOC, "get instance failed!")); - LOGE("get instance failed!"); + LOGE_ONE_STR("get instance failed!"); return nullptr; } @@ -504,7 +504,7 @@ napi_value NapiSymKeyGenerator::SymKeyGeneratorConstructor(napi_env env, napi_ca napi_value NapiSymKeyGenerator::CreateSymKeyGenerator(napi_env env, napi_callback_info info) { - LOGD("Enter CreateSymKeyGenerator..."); + LOGD_ONE_STR("Enter CreateSymKeyGenerator..."); size_t expectedArgc = ARGS_SIZE_ONE; size_t argc = ARGS_SIZE_ONE; napi_value argv[ARGS_SIZE_ONE] = { nullptr }; @@ -512,7 +512,7 @@ napi_value NapiSymKeyGenerator::CreateSymKeyGenerator(napi_env env, napi_callbac if (argc != expectedArgc) { napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "The input args num is invalid.")); - LOGE("The input args num is invalid."); + LOGE_ONE_STR("The input args num is invalid."); return nullptr; } @@ -524,7 +524,7 @@ napi_value NapiSymKeyGenerator::CreateSymKeyGenerator(napi_env env, napi_callbac std::string algoName; if (!GetStringFromJSParams(env, argv[0], algoName)) { napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "failed to get algoName.")); - LOGE("failed to get algoName."); + LOGE_ONE_STR("failed to get algoName."); return nullptr; } @@ -532,13 +532,13 @@ napi_value NapiSymKeyGenerator::CreateSymKeyGenerator(napi_env env, napi_callbac HcfResult res = HcfSymKeyGeneratorCreate(algoName.c_str(), &generator); if (res != HCF_SUCCESS) { napi_throw(env, GenerateBusinessError(env, res, "create C generator fail.")); - LOGE("create C generator fail."); + LOGE_ONE_STR("create C generator fail."); return nullptr; } NapiSymKeyGenerator *napiSymKeyGenerator = new (std::nothrow) NapiSymKeyGenerator(generator); if (napiSymKeyGenerator == nullptr) { napi_throw(env, GenerateBusinessError(env, HCF_ERR_MALLOC, "new napi sym key generator failed.")); - LOGE("new napi sym key generator failed!"); + LOGE_ONE_STR("new napi sym key generator failed!"); HcfObjDestroy(generator); return nullptr; } @@ -551,7 +551,7 @@ napi_value NapiSymKeyGenerator::CreateSymKeyGenerator(napi_env env, napi_callbac }, nullptr, nullptr); if (status != napi_ok) { napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "failed to wrap napiSymKeyGenerator obj!")); - LOGE("failed to wrap napiSymKeyGenerator obj!"); + LOGE_ONE_STR("failed to wrap napiSymKeyGenerator obj!"); delete napiSymKeyGenerator; return nullptr; } @@ -566,7 +566,7 @@ napi_value NapiSymKeyGenerator::JsGetAlgorithm(napi_env env, napi_callback_info napi_status status = napi_unwrap(env, thisVar, reinterpret_cast(&napiSymKeyGenerator)); if (status != napi_ok || napiSymKeyGenerator == nullptr) { napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "failed to unwrap napiSymKeyGenerator obj!")); - LOGE("failed to unwrap napiSymKeyGenerator obj!"); + LOGE_ONE_STR("failed to unwrap napiSymKeyGenerator obj!"); return nullptr; } HcfSymKeyGenerator *generator = napiSymKeyGenerator->GetSymKeyGenerator(); diff --git a/frameworks/js/napi/crypto/src/napi_utils.cpp b/frameworks/js/napi/crypto/src/napi_utils.cpp index d1a1afaaff65449651b8914bdcbba58e17022780..c50b0dc5255802a16ca9f498c85eef697a9c164a 100644 --- a/frameworks/js/napi/crypto/src/napi_utils.cpp +++ b/frameworks/js/napi/crypto/src/napi_utils.cpp @@ -127,7 +127,7 @@ napi_value NapiGetNull(napi_env env) static napi_value GetUint8ArrFromNapiDataBlob(napi_env env, napi_value arg) { if ((env == nullptr) || (arg == nullptr)) { - LOGE("Invalid params!"); + LOGE_ONE_STR("Invalid params!"); return nullptr; } napi_value data = nullptr; @@ -135,7 +135,7 @@ static napi_value GetUint8ArrFromNapiDataBlob(napi_env env, napi_value arg) napi_status status = napi_get_named_property(env, arg, CRYPTO_TAG_DATA.c_str(), &data); napi_typeof(env, data, &valueType); if ((status != napi_ok) || (data == nullptr) || (valueType == napi_undefined)) { - LOGE("failed to get valid data property!"); + LOGE_ONE_STR("failed to get valid data property!"); return nullptr; } return data; @@ -152,17 +152,17 @@ HcfBlob *GetBlobFromNapiUint8Arr(napi_env env, napi_value data) napi_status status = napi_get_typedarray_info(env, data, &arrayType, &length, reinterpret_cast(&rawData), &arrayBuffer, &offset); if ((status != napi_ok)) { - LOGE("failed to get valid rawData."); + LOGE_ONE_STR("failed to get valid rawData."); return nullptr; } if (arrayType != napi_uint8_array) { - LOGE("input data is not uint8 array."); + LOGE_ONE_STR("input data is not uint8 array."); return nullptr; } HcfBlob *newBlob = reinterpret_cast(HcfMalloc(sizeof(HcfBlob), 0)); if (newBlob == nullptr) { - LOGE("Failed to allocate newBlob memory!"); + LOGE_ONE_STR("Failed to allocate newBlob memory!"); return nullptr; } @@ -170,13 +170,13 @@ HcfBlob *GetBlobFromNapiUint8Arr(napi_env env, napi_value data) if ((length == 0) || (rawData == nullptr)) { newBlob->len = 0; newBlob->data = nullptr; - LOGD("napi Uint8Arr is null"); + LOGD_ONE_STR("napi Uint8Arr is null"); return newBlob; } newBlob->len = length; newBlob->data = static_cast(HcfMalloc(length, 0)); if (newBlob->data == nullptr) { - LOGE("malloc blob data failed!"); + LOGE_ONE_STR("malloc blob data failed!"); HcfFree(newBlob); return nullptr; } @@ -188,7 +188,7 @@ HcfBlob *GetBlobFromNapiDataBlob(napi_env env, napi_value arg) { napi_value data = GetUint8ArrFromNapiDataBlob(env, arg); if (data == nullptr) { - LOGE("failed to get data in DataBlob"); + LOGE_ONE_STR("failed to get data in DataBlob"); return nullptr; } return GetBlobFromNapiUint8Arr(env, data); @@ -198,7 +198,7 @@ HcfResult GetBlobFromNapiValue(napi_env env, napi_value arg, HcfBlob *blob) { napi_value data = GetUint8ArrFromNapiDataBlob(env, arg); if (data == nullptr) { - LOGE("failed to get data in DataBlob"); + LOGE_ONE_STR("failed to get data in DataBlob"); return HCF_INVALID_PARAMS; } @@ -207,23 +207,23 @@ HcfResult GetBlobFromNapiValue(napi_env env, napi_value arg, HcfBlob *blob) napi_status status = napi_get_typedarray_info(env, data, &arrayType, &(blob->len), reinterpret_cast(&rawData), nullptr, nullptr); if (status != napi_ok) { - LOGE("failed to get valid rawData."); + LOGE_ONE_STR("failed to get valid rawData."); return HCF_ERR_NAPI; } if (arrayType != napi_uint8_array) { - LOGE("input data is not uint8 array."); + LOGE_ONE_STR("input data is not uint8 array."); return HCF_INVALID_PARAMS; } blob->data = nullptr; if (blob->len == 0 || rawData == nullptr) { - LOGD("napi Uint8Arr is null"); + LOGD_ONE_STR("napi Uint8Arr is null"); return HCF_SUCCESS; } blob->data = static_cast(HcfMalloc(blob->len, 0)); if (blob->data == nullptr) { - LOGE("malloc blob data failed!"); + LOGE_ONE_STR("malloc blob data failed!"); return HCF_ERR_MALLOC; } (void)memcpy_s(blob->data, blob->len, rawData, blob->len); @@ -239,20 +239,20 @@ static HcfBlob *GetAadFromParamsSpec(napi_env env, napi_value arg) napi_status status = napi_get_named_property(env, arg, AAD_PARAMS.c_str(), &data); napi_typeof(env, data, &valueType); if ((status != napi_ok) || (data == nullptr) || (valueType == napi_undefined)) { - LOGE("failed to get valid param property!"); + LOGE_ONE_STR("failed to get valid param property!"); return nullptr; } if (valueType == napi_null) { blob = reinterpret_cast(HcfMalloc(sizeof(HcfBlob), 0)); if (blob == nullptr) { - LOGE("Failed to allocate newBlob memory!"); + LOGE_ONE_STR("Failed to allocate newBlob memory!"); return nullptr; } return blob; } blob = GetBlobFromNapiDataBlob(env, data); if (blob == nullptr) { - LOGE("GetBlobFromNapiDataBlob failed!"); + LOGE_ONE_STR("GetBlobFromNapiDataBlob failed!"); return nullptr; } return blob; @@ -261,7 +261,7 @@ static HcfBlob *GetAadFromParamsSpec(napi_env env, napi_value arg) bool GetBigIntFromNapiValue(napi_env env, napi_value arg, HcfBigInteger *bigInt) { if ((env == nullptr) || (arg == nullptr) || (bigInt == nullptr)) { - LOGE("Invalid params!"); + LOGE_ONE_STR("Invalid params!"); return false; } @@ -270,23 +270,23 @@ bool GetBigIntFromNapiValue(napi_env env, napi_value arg, HcfBigInteger *bigInt) napi_get_value_bigint_words(env, arg, nullptr, &wordCount, nullptr); if ((wordCount == 0) || (wordCount > (INT_MAX / sizeof(uint64_t)))) { - LOGE("Get big int failed."); + LOGE_ONE_STR("Get big int failed."); return false; } int length = wordCount * sizeof(uint64_t); uint8_t *retArr = reinterpret_cast(HcfMalloc(length, 0)); if (retArr == nullptr) { - LOGE("malloc blob data failed!"); + LOGE_ONE_STR("malloc blob data failed!"); return false; } if (napi_get_value_bigint_words(env, arg, &signBit, &wordCount, reinterpret_cast(retArr)) != napi_ok) { HcfFree(retArr); - LOGE("failed to get valid rawData."); + LOGE_ONE_STR("failed to get valid rawData."); return false; } if (signBit != 0) { HcfFree(retArr); - LOGE("failed to get gegative rawData."); + LOGE_ONE_STR("failed to get gegative rawData."); return false; } bigInt->data = retArr; @@ -297,7 +297,7 @@ bool GetBigIntFromNapiValue(napi_env env, napi_value arg, HcfBigInteger *bigInt) bool GetPointFromNapiValue(napi_env env, napi_value arg, HcfPoint *point) { if ((env == nullptr) || (arg == nullptr) || (point == nullptr)) { - LOGE("Invalid params!"); + LOGE_ONE_STR("Invalid params!"); return false; } napi_value dataX = nullptr; @@ -306,24 +306,24 @@ bool GetPointFromNapiValue(napi_env env, napi_value arg, HcfPoint *point) napi_status status = napi_get_named_property(env, arg, "x", &dataX); napi_typeof(env, dataX, &valueType); if ((status != napi_ok) || (dataX == nullptr) || (valueType == napi_undefined)) { - LOGE("failed to get valid algo name!"); + LOGE_ONE_STR("failed to get valid algo name!"); return false; } status = napi_get_named_property(env, arg, "y", &dataY); napi_typeof(env, dataY, &valueType); if ((status != napi_ok) || (dataY == nullptr) || (valueType == napi_undefined)) { - LOGE("failed to get valid algo name!"); + LOGE_ONE_STR("failed to get valid algo name!"); return false; } bool ret = GetBigIntFromNapiValue(env, dataX, &point->x); if (!ret) { - LOGE("get point x failed!"); + LOGE_ONE_STR("get point x failed!"); return false; } ret = GetBigIntFromNapiValue(env, dataY, &point->y); if (!ret) { - LOGE("get point y failed!"); + LOGE_ONE_STR("get point y failed!"); HcfFree((point->x).data); (point->x).data = nullptr; return false; @@ -355,12 +355,12 @@ static HcfBlob *GetBlobFromParamsSpec(napi_env env, napi_value arg, const string napi_status status = napi_get_named_property(env, arg, type.c_str(), &data); napi_typeof(env, data, &valueType); if ((status != napi_ok) || (data == nullptr) || (valueType == napi_undefined)) { - LOGE("failed to get valid param property!"); + LOGE_ONE_STR("failed to get valid param property!"); return nullptr; } blob = GetBlobFromNapiDataBlob(env, data); if (blob == nullptr) { - LOGE("GetBlobFromNapiDataBlob failed!"); + LOGE_ONE_STR("GetBlobFromNapiDataBlob failed!"); return nullptr; } return blob; @@ -370,13 +370,13 @@ static bool GetIvParamsSpec(napi_env env, napi_value arg, HcfParamsSpec **params { HcfIvParamsSpec *ivParamsSpec = reinterpret_cast(HcfMalloc(sizeof(HcfIvParamsSpec), 0)); if (ivParamsSpec == nullptr) { - LOGE("ivParamsSpec malloc failed!"); + LOGE_ONE_STR("ivParamsSpec malloc failed!"); return false; } HcfBlob *iv = GetBlobFromParamsSpec(env, arg, IV_PARAMS); if (iv == nullptr) { - LOGE("GetBlobFromNapiDataBlob failed!"); + LOGE_ONE_STR("GetBlobFromNapiDataBlob failed!"); HcfFree(ivParamsSpec); return false; } @@ -391,14 +391,14 @@ static bool GetIvAndAadBlob(napi_env env, napi_value arg, HcfBlob **iv, HcfBlob { *iv = GetBlobFromParamsSpec(env, arg, IV_PARAMS); if (*iv == nullptr) { - LOGE("get iv failed!"); + LOGE_ONE_STR("get iv failed!"); return false; } *aad = GetAadFromParamsSpec(env, arg); // error case free is in get paramspec func. if (*aad == nullptr) { - LOGE("get aad failed!"); + LOGE_ONE_STR("get aad failed!"); return false; } return true; @@ -414,26 +414,26 @@ static bool GetGcmParamsSpec(napi_env env, napi_value arg, HcfCryptoMode opMode, HcfGcmParamsSpec *gcmParamsSpec = reinterpret_cast(HcfMalloc(sizeof(HcfGcmParamsSpec), 0)); if (gcmParamsSpec == nullptr) { - LOGE("gcmParamsSpec malloc failed!"); + LOGE_ONE_STR("gcmParamsSpec malloc failed!"); return false; } ret = GetIvAndAadBlob(env, arg, &iv, &aad); if (!ret) { - LOGE("GetIvAndAadBlob failed!"); + LOGE_ONE_STR("GetIvAndAadBlob failed!"); goto clearup; } if (opMode == DECRYPT_MODE) { tag = GetBlobFromParamsSpec(env, arg, AUTHTAG_PARAMS); if (tag == nullptr) { - LOGE("get tag failed!"); + LOGE_ONE_STR("get tag failed!"); goto clearup; } } else if (opMode == ENCRYPT_MODE) { authTag.data = static_cast(HcfMalloc(GCM_AUTH_TAG_LEN, 0)); if (authTag.data == nullptr) { - LOGE("get tag failed!"); + LOGE_ONE_STR("get tag failed!"); goto clearup; } authTag.len = GCM_AUTH_TAG_LEN; @@ -470,25 +470,25 @@ static bool GetCcmParamsSpec(napi_env env, napi_value arg, HcfCryptoMode opMode, HcfCcmParamsSpec *ccmParamsSpec = reinterpret_cast(HcfMalloc(sizeof(HcfCcmParamsSpec), 0)); if (ccmParamsSpec == nullptr) { - LOGE("ccmParamsSpec malloc failed!"); + LOGE_ONE_STR("ccmParamsSpec malloc failed!"); return ret; } ret = GetIvAndAadBlob(env, arg, &iv, &aad); if (!ret) { - LOGE("GetIvAndAadBlob failed!"); + LOGE_ONE_STR("GetIvAndAadBlob failed!"); goto clearup; } if (opMode == DECRYPT_MODE) { tag = GetBlobFromParamsSpec(env, arg, AUTHTAG_PARAMS); if (tag == nullptr) { - LOGE("get tag failed!"); + LOGE_ONE_STR("get tag failed!"); goto clearup; } } else if (opMode == ENCRYPT_MODE) { authTag.data = static_cast(HcfMalloc(CCM_AUTH_TAG_LEN, 0)); if (authTag.data == nullptr) { - LOGE("get tag failed!"); + LOGE_ONE_STR("get tag failed!"); goto clearup; } authTag.len = CCM_AUTH_TAG_LEN; @@ -519,7 +519,7 @@ bool GetParamsSpecFromNapiValue(napi_env env, napi_value arg, HcfCryptoMode opMo napi_value data = nullptr; napi_valuetype valueType = napi_undefined; if ((env == nullptr) || (arg == nullptr) || (paramsSpec == nullptr)) { - LOGE("Invalid params!"); + LOGE_ONE_STR("Invalid params!"); return false; } @@ -529,13 +529,13 @@ bool GetParamsSpecFromNapiValue(napi_env env, napi_value arg, HcfCryptoMode opMo status = napi_get_named_property(env, arg, ALGO_PARAMS_OLD.c_str(), &data); napi_typeof(env, data, &valueType); if ((status != napi_ok) || (data == nullptr) || (valueType == napi_undefined)) { - LOGE("failed to get valid algo name!"); + LOGE_ONE_STR("failed to get valid algo name!"); return false; } } string algoName; if (!GetStringFromJSParams(env, data, algoName)) { - LOGE("GetStringFromJSParams failed!"); + LOGE_ONE_STR("GetStringFromJSParams failed!"); return false; } if (algoName.compare(IV_PARAMS_SPEC) == 0) { @@ -553,24 +553,24 @@ static bool GetCharArrayFromJsString(napi_env env, napi_value arg, HcfBlob *retB { size_t length = 0; if (napi_get_value_string_utf8(env, arg, nullptr, 0, &length) != napi_ok) { - LOGE("can not get char string length"); + LOGE_ONE_STR("can not get char string length"); return false; } if (length > PASSWORD_MAX_LENGTH) { - LOGE("password length should not exceed 4096"); + LOGE_ONE_STR("password length should not exceed 4096"); return false; } if (length == 0) { - LOGD("empty string"); + LOGD_ONE_STR("empty string"); return false; } char *tmpPassword = static_cast(HcfMalloc(length + 1, 0)); if (tmpPassword == nullptr) { - LOGE("malloc string failed"); + LOGE_ONE_STR("malloc string failed"); return false; } if (napi_get_value_string_utf8(env, arg, tmpPassword, (length + 1), &length) != napi_ok) { - LOGE("can not get char string value"); + LOGE_ONE_STR("can not get char string value"); HcfFree(tmpPassword); return false; } @@ -585,17 +585,17 @@ static bool InitEncodingParams(napi_env env, napi_value arg, HcfKeyEncodingParam napi_value passWd = GetDetailAsyKeySpecValue(env, arg, PASSWD_PARAMS); napi_value cipher = GetDetailAsyKeySpecValue(env, arg, CIPHER_PARAMS); if ((passWd == nullptr) || (cipher == nullptr)) { - LOGE("Invalid params."); + LOGE_ONE_STR("Invalid params."); return false; } if (!GetCharArrayFromJsString(env, passWd, tmpPw)) { - LOGE("Failed to get passWord string from napi!"); + LOGE_ONE_STR("Failed to get passWord string from napi!"); return false; } if (!GetCharArrayFromJsString(env, cipher, tmpCipher)) { - LOGE("Failed to get cipher string from napi!"); + LOGE_ONE_STR("Failed to get cipher string from napi!"); HcfBlobDataClearAndFree(tmpPw); return false; } @@ -608,21 +608,21 @@ static bool InitEncodingParams(napi_env env, napi_value arg, HcfKeyEncodingParam bool GetEncodingParamsSpec(napi_env env, napi_value arg, HcfParamsSpec **returnSpec) { if ((env == nullptr) || (arg == nullptr) || (returnSpec == nullptr)) { - LOGE("Invalid params."); + LOGE_ONE_STR("Invalid params."); return false; } HcfKeyEncodingParamsSpec *encodingParamsSpec = reinterpret_cast(HcfMalloc(sizeof(HcfKeyEncodingParamsSpec), 0)); if (encodingParamsSpec == nullptr) { - LOGE("encodingParamsSpec malloc failed!"); + LOGE_ONE_STR("encodingParamsSpec malloc failed!"); return false; } HcfBlob tmpPw = { .data = nullptr, .len = 0 }; HcfBlob tmpCipher = { .data = nullptr, .len = 0 }; if (!InitEncodingParams(env, arg, encodingParamsSpec, &tmpPw, &tmpCipher)) { - LOGE("Failed to get passWord string from napi!"); + LOGE_ONE_STR("Failed to get passWord string from napi!"); HcfFree(encodingParamsSpec); return false; } @@ -641,32 +641,32 @@ static HcfBlob *GetBlobFromStringJSParams(napi_env env, napi_value arg) size_t length = 0; if (napi_get_value_string_utf8(env, arg, nullptr, 0, &length) != napi_ok) { - LOGE("can not get string length"); + LOGE_ONE_STR("can not get string length"); return nullptr; } if (length == 0) { - LOGE("string length is 0"); + LOGE_ONE_STR("string length is 0"); return nullptr; } HcfBlob *newBlob = static_cast(HcfMalloc(sizeof(HcfBlob), 0)); if (newBlob == nullptr) { - LOGE("Failed to allocate newBlob memory!"); + LOGE_ONE_STR("Failed to allocate newBlob memory!"); return nullptr; } newBlob->len = length + 1; newBlob->data = static_cast(HcfMalloc(newBlob->len, 0)); if (newBlob->data == nullptr) { - LOGE("malloc blob data failed!"); + LOGE_ONE_STR("malloc blob data failed!"); HcfFree(newBlob); return nullptr; } if (napi_get_value_string_utf8(env, arg, reinterpret_cast(newBlob->data), newBlob->len, &length) != napi_ok) { - LOGE("can not get string value"); + LOGE_ONE_STR("can not get string value"); HcfBlobDataClearAndFree(newBlob); HcfFree(newBlob); return nullptr; @@ -680,18 +680,18 @@ bool GetDecodingParamsSpec(napi_env env, napi_value arg, HcfParamsSpec **returnS HcfKeyDecodingParamsSpec *decodingParamsSpec = reinterpret_cast(HcfMalloc(sizeof(HcfKeyDecodingParamsSpec), 0)); if (decodingParamsSpec == nullptr) { - LOGE("decodingParamsSpec malloc failed!"); + LOGE_ONE_STR("decodingParamsSpec malloc failed!"); return false; } HcfBlob *tmpPw = GetBlobFromStringJSParams(env, arg); if (tmpPw == nullptr) { - LOGE("Failed to get passWord string from napi!"); + LOGE_ONE_STR("Failed to get passWord string from napi!"); HcfFree(decodingParamsSpec); return false; } if (tmpPw->len > PASSWORD_MAX_LENGTH) { - LOGE("Password length exceeds max length limit of 4096 bytes!"); + LOGE_ONE_STR("Password length exceeds max length limit of 4096 bytes!"); HcfBlobDataClearAndFree(tmpPw); HcfFree(decodingParamsSpec); return false; @@ -708,13 +708,13 @@ napi_value GetDetailAsyKeySpecValue(napi_env env, napi_value arg, string argName napi_value data = nullptr; napi_valuetype valueType = napi_undefined; if ((env == nullptr) || (arg == nullptr)) { - LOGE("Invalid params!"); + LOGE_ONE_STR("Invalid params!"); return nullptr; } napi_status status = napi_get_named_property(env, arg, argName.c_str(), &data); napi_typeof(env, data, &valueType); if ((status != napi_ok) || (data == nullptr) || (valueType == napi_undefined)) { - LOGE("failed to get valid algo name!"); + LOGE_ONE_STR("failed to get valid algo name!"); return nullptr; } return data; @@ -729,7 +729,7 @@ static napi_value GetCommSpecNapiValue(napi_env env, napi_value arg) napi_typeof(env, data, &valueType); if ((status != napi_ok) || (data == nullptr) || (valueType == napi_undefined)) { - LOGE("failed to get valid algo name!"); + LOGE_ONE_STR("failed to get valid algo name!"); return nullptr; } return data; @@ -740,7 +740,7 @@ static bool InitDsaCommonAsyKeySpec(napi_env env, napi_value arg, HcfDsaCommPara size_t algNameLen = DSA_ASY_KEY_SPEC.length(); spec->base.algName = static_cast(HcfMalloc(algNameLen + 1, 0)); if (spec->base.algName == nullptr) { - LOGE("malloc DSA algName failed!"); + LOGE_ONE_STR("malloc DSA algName failed!"); return false; } (void)memcpy_s(spec->base.algName, algNameLen+ 1, DSA_ASY_KEY_SPEC.c_str(), algNameLen); @@ -772,11 +772,11 @@ static bool GetDsaCommonAsyKeySpec(napi_env env, napi_value arg, HcfAsyKeyParams { HcfDsaCommParamsSpec *spec = reinterpret_cast(HcfMalloc(sizeof(HcfDsaCommParamsSpec), 0)); if (spec == nullptr) { - LOGE("malloc failed!"); + LOGE_ONE_STR("malloc failed!"); return false; } if (!InitDsaCommonAsyKeySpec(env, arg, spec)) { - LOGE("InitDsaCommonAsyKeySpec failed!"); + LOGE_ONE_STR("InitDsaCommonAsyKeySpec failed!"); HcfFree(spec); return false; } @@ -789,18 +789,18 @@ static bool GetDsaPubKeySpec(napi_env env, napi_value arg, HcfAsyKeyParamsSpec * HcfDsaPubKeyParamsSpec *spec = reinterpret_cast( HcfMalloc(sizeof(HcfDsaPubKeyParamsSpec), 0)); if (spec == nullptr) { - LOGE("malloc failed!"); + LOGE_ONE_STR("malloc failed!"); return false; } napi_value commSpecValue = GetCommSpecNapiValue(env, arg); if (commSpecValue == nullptr) { - LOGE("Get comm spec napi value failed."); + LOGE_ONE_STR("Get comm spec napi value failed."); HcfFree(spec); return false; } if (!InitDsaCommonAsyKeySpec(env, commSpecValue, reinterpret_cast(spec))) { - LOGE("InitDsaCommonAsyKeySpec failed."); + LOGE_ONE_STR("InitDsaCommonAsyKeySpec failed."); HcfFree(spec); return false; } @@ -821,18 +821,18 @@ static bool GetDsaKeyPairAsyKeySpec(napi_env env, napi_value arg, HcfAsyKeyParam HcfDsaKeyPairParamsSpec *spec = reinterpret_cast( HcfMalloc(sizeof(HcfDsaKeyPairParamsSpec), 0)); if (spec == nullptr) { - LOGE("malloc failed!"); + LOGE_ONE_STR("malloc failed!"); return false; } napi_value commSpecValue = GetCommSpecNapiValue(env, arg); if (commSpecValue == nullptr) { - LOGE("Get comm spec napi value failed."); + LOGE_ONE_STR("Get comm spec napi value failed."); HcfFree(spec); return false; } if (!InitDsaCommonAsyKeySpec(env, commSpecValue, reinterpret_cast(spec))) { - LOGE("InitDsaCommonAsyKeySpec failed!"); + LOGE_ONE_STR("InitDsaCommonAsyKeySpec failed!"); HcfFree(spec); return false; } @@ -865,13 +865,13 @@ static bool GetDsaAsyKeySpec(napi_env env, napi_value arg, HcfAsyKeyParamsSpec * napi_status status = napi_get_named_property(env, arg, TAG_SPEC_TYPE.c_str(), &data); napi_typeof(env, data, &valueType); if ((status != napi_ok) || (data == nullptr) || (valueType == napi_undefined)) { - LOGE("failed to get valid algo name!"); + LOGE_ONE_STR("failed to get valid algo name!"); return false; } HcfAsyKeySpecType asyKeySpecType; status = napi_get_value_uint32(env, data, reinterpret_cast(&asyKeySpecType)); if (status != napi_ok) { - LOGE("failed to get valid asyKeySpecType!"); + LOGE_ONE_STR("failed to get valid asyKeySpecType!"); return false; } if (asyKeySpecType == HCF_COMMON_PARAMS_SPEC) { @@ -889,14 +889,14 @@ static bool GetFpField(napi_env env, napi_value arg, HcfECField **ecField) { HcfECFieldFp *fp = reinterpret_cast(HcfMalloc(sizeof(HcfECFieldFp), 0)); if (fp == nullptr) { - LOGE("malloc fp failed!"); + LOGE_ONE_STR("malloc fp failed!"); return false; } size_t fieldTpyeLen = ECC_FIELD_TYPE_FP.length(); fp->base.fieldType = static_cast(HcfMalloc(fieldTpyeLen + 1, 0)); if (fp->base.fieldType == nullptr) { - LOGE("malloc fieldType failed!"); + LOGE_ONE_STR("malloc fieldType failed!"); HcfFree(fp); return false; } @@ -921,7 +921,7 @@ static bool GetField(napi_env env, napi_value arg, HcfECField **ecField) napi_status status = napi_get_named_property(env, arg, "field", &fieldData); napi_typeof(env, fieldData, &valueType); if ((status != napi_ok) || (fieldData == nullptr) || (valueType == napi_undefined)) { - LOGE("failed to get valid field data!"); + LOGE_ONE_STR("failed to get valid field data!"); return false; } @@ -930,12 +930,12 @@ static bool GetField(napi_env env, napi_value arg, HcfECField **ecField) status = napi_get_named_property(env, fieldData, "fieldType", &fieldTypeData); napi_typeof(env, fieldTypeData, &valueType); if ((status != napi_ok) || (fieldTypeData == nullptr) || (valueType == napi_undefined)) { - LOGE("failed to get valid fieldType data!"); + LOGE_ONE_STR("failed to get valid fieldType data!"); return false; } string fieldType; if (!GetStringFromJSParams(env, fieldTypeData, fieldType)) { - LOGE("GetStringFromJSParams failed when extracting fieldType!"); + LOGE_ONE_STR("GetStringFromJSParams failed when extracting fieldType!"); return false; } @@ -954,22 +954,22 @@ static bool InitEccDetailAsyKeySpec(napi_env env, napi_value arg, HcfEccCommPara napi_value g = GetDetailAsyKeySpecValue(env, arg, "g"); bool ret = GetBigIntFromNapiValue(env, a, &spec->a); if (!ret) { - LOGE("get ecc asyKeySpec a failed!"); + LOGE_ONE_STR("get ecc asyKeySpec a failed!"); return false; } ret = GetBigIntFromNapiValue(env, b, &spec->b); if (!ret) { - LOGE("get ecc asyKeySpec b failed!"); + LOGE_ONE_STR("get ecc asyKeySpec b failed!"); return false; } ret = GetBigIntFromNapiValue(env, n, &spec->n); if (!ret) { - LOGE("get ecc asyKeySpec n failed!"); + LOGE_ONE_STR("get ecc asyKeySpec n failed!"); return false; } ret = GetPointFromNapiValue(env, g, &spec->g); if (!ret) { - LOGE("get ecc asyKeySpec g failed!"); + LOGE_ONE_STR("get ecc asyKeySpec g failed!"); return false; } return true; @@ -980,7 +980,7 @@ static bool InitEccCommonAsyKeySpec(napi_env env, napi_value arg, HcfEccCommPara size_t algNameLen = ECC_ASY_KEY_SPEC.length(); spec->base.algName = static_cast(HcfMalloc(algNameLen + 1, 0)); if (spec->base.algName == nullptr) { - LOGE("malloc ECC algName failed!"); + LOGE_ONE_STR("malloc ECC algName failed!"); return false; } (void)memcpy_s(spec->base.algName, algNameLen+ 1, algName.c_str(), algNameLen); @@ -992,27 +992,27 @@ static bool InitEccCommonAsyKeySpec(napi_env env, napi_value arg, HcfEccCommPara napi_status status = napi_get_named_property(env, arg, "h", &hData); napi_typeof(env, hData, &valueType); if ((status != napi_ok) || (hData == nullptr) || (valueType == napi_undefined)) { - LOGE("failed to get valid h!"); + LOGE_ONE_STR("failed to get valid h!"); HcfFree(spec->base.algName); spec->base.algName = nullptr; return false; } if (!GetInt32FromJSParams(env, hData, spec->h)) { - LOGE("get ecc asyKeySpec h failed!"); + LOGE_ONE_STR("get ecc asyKeySpec h failed!"); HcfFree(spec->base.algName); spec->base.algName = nullptr; return false; } // get field if (!GetField(env, arg, &spec->field)) { - LOGE("GetField failed!"); + LOGE_ONE_STR("GetField failed!"); HcfFree(spec->base.algName); spec->base.algName = nullptr; return false; } bool ret = InitEccDetailAsyKeySpec(env, arg, spec); if (!ret) { - LOGE("get ecc asyKeySpec g failed!"); + LOGE_ONE_STR("get ecc asyKeySpec g failed!"); FreeEccCommParamsSpec(spec); return false; } @@ -1024,11 +1024,11 @@ static bool GetEccCommonAsyKeySpec(napi_env env, napi_value arg, HcfAsyKeyParams { HcfEccCommParamsSpec *spec = reinterpret_cast(HcfMalloc(sizeof(HcfEccCommParamsSpec), 0)); if (spec == nullptr) { - LOGE("malloc failed!"); + LOGE_ONE_STR("malloc failed!"); return false; } if (!InitEccCommonAsyKeySpec(env, arg, spec, algName)) { - LOGE("InitEccCommonAsyKeySpec failed!"); + LOGE_ONE_STR("InitEccCommonAsyKeySpec failed!"); HcfFree(spec); return false; } @@ -1041,18 +1041,18 @@ static bool GetEccPriKeySpec(napi_env env, napi_value arg, HcfAsyKeyParamsSpec * HcfEccPriKeyParamsSpec *spec = reinterpret_cast(HcfMalloc(sizeof(HcfEccPriKeyParamsSpec), 0)); if (spec == nullptr) { - LOGE("malloc failed!"); + LOGE_ONE_STR("malloc failed!"); return false; } napi_value commSpecValue = GetCommSpecNapiValue(env, arg); if (commSpecValue == nullptr) { - LOGE("Get comm spec napi value failed."); + LOGE_ONE_STR("Get comm spec napi value failed."); HcfFree(spec); return false; } if (!InitEccCommonAsyKeySpec(env, commSpecValue, reinterpret_cast(spec), algName)) { - LOGE("InitEccCommonAsyKeySpec failed!"); + LOGE_ONE_STR("InitEccCommonAsyKeySpec failed!"); HcfFree(spec); return false; } @@ -1075,18 +1075,18 @@ static bool GetEccPubKeySpec(napi_env env, napi_value arg, HcfAsyKeyParamsSpec * HcfEccPubKeyParamsSpec *spec = reinterpret_cast(HcfMalloc(sizeof(HcfEccPubKeyParamsSpec), 0)); if (spec == nullptr) { - LOGE("malloc failed!"); + LOGE_ONE_STR("malloc failed!"); return false; } napi_value commSpecValue = GetCommSpecNapiValue(env, arg); if (commSpecValue == nullptr) { - LOGE("Get comm spec napi value failed."); + LOGE_ONE_STR("Get comm spec napi value failed."); HcfFree(spec); return false; } if (!InitEccCommonAsyKeySpec(env, commSpecValue, reinterpret_cast(spec), algName)) { - LOGE("InitEccCommonAsyKeySpec failed!"); + LOGE_ONE_STR("InitEccCommonAsyKeySpec failed!"); HcfFree(spec); return false; } @@ -1108,18 +1108,18 @@ static bool GetEccKeyPairAsyKeySpec(napi_env env, napi_value arg, HcfAsyKeyParam HcfEccKeyPairParamsSpec *spec = reinterpret_cast(HcfMalloc(sizeof(HcfEccKeyPairParamsSpec), 0)); if (spec == nullptr) { - LOGE("malloc failed!"); + LOGE_ONE_STR("malloc failed!"); return false; } napi_value commSpecValue = GetCommSpecNapiValue(env, arg); if (commSpecValue == nullptr) { - LOGE("Get comm spec napi value failed."); + LOGE_ONE_STR("Get comm spec napi value failed."); HcfFree(spec); return false; } if (!InitEccCommonAsyKeySpec(env, commSpecValue, reinterpret_cast(spec), algName)) { - LOGE("InitEccCommonAsyKeySpec failed!"); + LOGE_ONE_STR("InitEccCommonAsyKeySpec failed!"); HcfFree(spec); return false; } @@ -1154,13 +1154,13 @@ static bool GetEccAsyKeySpec(napi_env env, napi_value arg, HcfAsyKeyParamsSpec * napi_status status = napi_get_named_property(env, arg, TAG_SPEC_TYPE.c_str(), &data); napi_typeof(env, data, &valueType); if ((status != napi_ok) || (data == nullptr) || (valueType == napi_undefined)) { - LOGE("failed to get valid algo name!"); + LOGE_ONE_STR("failed to get valid algo name!"); return false; } HcfAsyKeySpecType asyKeySpecType; status = napi_get_value_uint32(env, data, reinterpret_cast(&asyKeySpecType)); if (status != napi_ok) { - LOGE("failed to get valid asyKeySpecType!"); + LOGE_ONE_STR("failed to get valid asyKeySpecType!"); return false; } if (asyKeySpecType == HCF_COMMON_PARAMS_SPEC) { @@ -1172,7 +1172,7 @@ static bool GetEccAsyKeySpec(napi_env env, napi_value arg, HcfAsyKeyParamsSpec * } else if (asyKeySpecType == HCF_KEY_PAIR_SPEC) { return GetEccKeyPairAsyKeySpec(env, arg, asyKeySpec, algName); } else { - LOGE("keySpec not support!"); + LOGE_ONE_STR("keySpec not support!"); return false; } } @@ -1182,7 +1182,7 @@ static bool InitRsaCommonAsyKeySpec(napi_env env, napi_value arg, HcfRsaCommPara size_t algNameLen = RSA_ASY_KEY_SPEC.length(); spec->base.algName = static_cast(HcfMalloc(algNameLen + 1, 0)); if (spec->base.algName == nullptr) { - LOGE("malloc RSA algName failed!"); + LOGE_ONE_STR("malloc RSA algName failed!"); return false; } (void)memcpy_s(spec->base.algName, algNameLen+ 1, RSA_ASY_KEY_SPEC.c_str(), algNameLen); @@ -1192,7 +1192,7 @@ static bool InitRsaCommonAsyKeySpec(napi_env env, napi_value arg, HcfRsaCommPara bool ret = GetBigIntFromNapiValue(env, n, &spec->n); if (!ret) { - LOGE("Rsa asyKeySpec get n failed!"); + LOGE_ONE_STR("Rsa asyKeySpec get n failed!"); HcfFree(spec->base.algName); spec->base.algName = nullptr; return false; @@ -1205,18 +1205,18 @@ static bool GetRsaPubKeySpec(napi_env env, napi_value arg, HcfAsyKeyParamsSpec * HcfRsaPubKeyParamsSpec *spec = reinterpret_cast(HcfMalloc(sizeof(HcfRsaPubKeyParamsSpec), 0)); if (spec == nullptr) { - LOGE("malloc failed!"); + LOGE_ONE_STR("malloc failed!"); return false; } napi_value commSpecValue = GetCommSpecNapiValue(env, arg); if (commSpecValue == nullptr) { - LOGE("Get comm spec napi value failed."); + LOGE_ONE_STR("Get comm spec napi value failed."); HcfFree(spec); return false; } if (!InitRsaCommonAsyKeySpec(env, commSpecValue, reinterpret_cast(spec))) { - LOGE("InitRsaCommonAsyKeySpec failed!"); + LOGE_ONE_STR("InitRsaCommonAsyKeySpec failed!"); HcfFree(spec); return false; } @@ -1237,18 +1237,18 @@ static bool GetRsaKeyPairAsyKeySpec(napi_env env, napi_value arg, HcfAsyKeyParam HcfRsaKeyPairParamsSpec *spec = reinterpret_cast(HcfMalloc(sizeof(HcfRsaKeyPairParamsSpec), 0)); if (spec == nullptr) { - LOGE("malloc failed!"); + LOGE_ONE_STR("malloc failed!"); return false; } napi_value commSpecValue = GetCommSpecNapiValue(env, arg); if (commSpecValue == nullptr) { - LOGE("Get comm spec napi value failed."); + LOGE_ONE_STR("Get comm spec napi value failed."); HcfFree(spec); return false; } if (!InitRsaCommonAsyKeySpec(env, commSpecValue, reinterpret_cast(spec))) { - LOGE("InitRsaCommonAsyKeySpec failed!"); + LOGE_ONE_STR("InitRsaCommonAsyKeySpec failed!"); HcfFree(spec); return false; } @@ -1281,17 +1281,17 @@ static bool GetRsaAsyKeySpec(napi_env env, napi_value arg, HcfAsyKeyParamsSpec * napi_status status = napi_get_named_property(env, arg, TAG_SPEC_TYPE.c_str(), &data); napi_typeof(env, data, &valueType); if ((status != napi_ok) || (data == nullptr) || (valueType == napi_undefined)) { - LOGE("failed to get valid algo name!"); + LOGE_ONE_STR("failed to get valid algo name!"); return false; } HcfAsyKeySpecType asyKeySpecType; status = napi_get_value_uint32(env, data, reinterpret_cast(&asyKeySpecType)); if (status != napi_ok) { - LOGE("failed to get valid asyKeySpecType!"); + LOGE_ONE_STR("failed to get valid asyKeySpecType!"); return false; } if (asyKeySpecType == HCF_COMMON_PARAMS_SPEC) { - LOGE("RSA not support comm key spec"); + LOGE_ONE_STR("RSA not support comm key spec"); return false; } else if (asyKeySpecType == HCF_PUBLIC_KEY_SPEC) { return GetRsaPubKeySpec(env, arg, asyKeySpec); @@ -1307,7 +1307,7 @@ static bool InitAlg25519CommonAsyKeySpec(HcfAsyKeyParamsSpec *spec, const string size_t algNameLen = algName.length(); spec->algName = static_cast(HcfMalloc(algNameLen + 1, 0)); if (spec->algName == nullptr) { - LOGE("malloc alg25519 algName failed!"); + LOGE_ONE_STR("malloc alg25519 algName failed!"); return false; } (void)memcpy_s(spec->algName, algNameLen + 1, algName.c_str(), algNameLen); @@ -1319,11 +1319,11 @@ static bool GetAlg25519PriKeySpec(napi_env env, napi_value arg, HcfAsyKeyParamsS HcfAlg25519PriKeyParamsSpec *spec = reinterpret_cast(HcfMalloc(sizeof(HcfAlg25519PriKeyParamsSpec), 0)); if (spec == nullptr) { - LOGE("malloc failed!"); + LOGE_ONE_STR("malloc failed!"); return false; } if (!InitAlg25519CommonAsyKeySpec(reinterpret_cast(spec), algName)) { - LOGE("InitRsaCommonAsyKeySpec failed!"); + LOGE_ONE_STR("InitRsaCommonAsyKeySpec failed!"); DestroyAlg25519PriKeySpec(spec); return false; } @@ -1345,11 +1345,11 @@ static bool GetAlg25519PubKeySpec(napi_env env, napi_value arg, HcfAsyKeyParamsS HcfAlg25519PubKeyParamsSpec *spec = reinterpret_cast(HcfMalloc(sizeof(HcfAlg25519PubKeyParamsSpec), 0)); if (spec == nullptr) { - LOGE("malloc failed!"); + LOGE_ONE_STR("malloc failed!"); return false; } if (!InitAlg25519CommonAsyKeySpec(reinterpret_cast(spec), algName)) { - LOGE("InitRsaCommonAsyKeySpec failed!"); + LOGE_ONE_STR("InitRsaCommonAsyKeySpec failed!"); DestroyAlg25519PubKeySpec(spec); return false; } @@ -1371,11 +1371,11 @@ static bool GetAlg25519KeyPairAsyKeySpec(napi_env env, napi_value arg, HcfAlg25519KeyPairParamsSpec *spec = reinterpret_cast(HcfMalloc(sizeof(HcfAlg25519KeyPairParamsSpec), 0)); if (spec == nullptr) { - LOGE("malloc failed!"); + LOGE_ONE_STR("malloc failed!"); return false; } if (!InitAlg25519CommonAsyKeySpec(reinterpret_cast(spec), algName)) { - LOGE("InitRsaCommonAsyKeySpec failed!"); + LOGE_ONE_STR("InitRsaCommonAsyKeySpec failed!"); HcfFree(spec); return false; } @@ -1406,13 +1406,13 @@ static bool GetAlg25519AsyKeySpec(napi_env env, napi_value arg, HcfAsyKeyParamsS napi_status status = napi_get_named_property(env, arg, TAG_SPEC_TYPE.c_str(), &data); napi_typeof(env, data, &valueType); if ((status != napi_ok) || (data == nullptr) || (valueType == napi_undefined)) { - LOGE("failed to get valid algo name!"); + LOGE_ONE_STR("failed to get valid algo name!"); return false; } HcfAsyKeySpecType asyKeySpecType; status = napi_get_value_uint32(env, data, reinterpret_cast(&asyKeySpecType)); if (status != napi_ok) { - LOGE("failed to get valid asyKeySpecType!"); + LOGE_ONE_STR("failed to get valid asyKeySpecType!"); return false; } if (asyKeySpecType == HCF_PRIVATE_KEY_SPEC) { @@ -1422,7 +1422,7 @@ static bool GetAlg25519AsyKeySpec(napi_env env, napi_value arg, HcfAsyKeyParamsS } else if (asyKeySpecType == HCF_KEY_PAIR_SPEC) { return GetAlg25519KeyPairAsyKeySpec(env, arg, asyKeySpec, algName); } else { - LOGE("keySpec not support!"); + LOGE_ONE_STR("keySpec not support!"); return false; } } @@ -1432,7 +1432,7 @@ static bool InitDhCommonAsyKeySpec(napi_env env, napi_value arg, HcfDhCommParams size_t algNameLen = DH_ASY_KEY_SPEC.length(); spec->base.algName = static_cast(HcfMalloc(algNameLen + 1, 0)); if (spec->base.algName == nullptr) { - LOGE("malloc DH algName failed!"); + LOGE_ONE_STR("malloc DH algName failed!"); return false; } (void)memcpy_s(spec->base.algName, algNameLen+ 1, DH_ASY_KEY_SPEC.c_str(), algNameLen); @@ -1443,13 +1443,13 @@ static bool InitDhCommonAsyKeySpec(napi_env env, napi_value arg, HcfDhCommParams napi_status status = napi_get_named_property(env, arg, "l", &length); napi_typeof(env, length, &valueType); if ((status != napi_ok) || (length == nullptr) || (valueType == napi_undefined)) { - LOGE("failed to get valid l!"); + LOGE_ONE_STR("failed to get valid l!"); HcfFree(spec->base.algName); spec->base.algName = nullptr; return false; } if (!GetInt32FromJSParams(env, length, spec->length)) { - LOGE("get dh asyKeySpec length failed!"); + LOGE_ONE_STR("get dh asyKeySpec length failed!"); HcfFree(spec->base.algName); spec->base.algName = nullptr; return false; @@ -1474,11 +1474,11 @@ static bool GetDhCommonAsyKeySpec(napi_env env, napi_value arg, HcfAsyKeyParamsS { HcfDhCommParamsSpec *spec = reinterpret_cast(HcfMalloc(sizeof(HcfDhCommParamsSpec), 0)); if (spec == nullptr) { - LOGE("malloc failed!"); + LOGE_ONE_STR("malloc failed!"); return false; } if (!InitDhCommonAsyKeySpec(env, arg, spec)) { - LOGE("InitDhCommonAsyKeySpec failed!"); + LOGE_ONE_STR("InitDhCommonAsyKeySpec failed!"); HcfFree(spec); return false; } @@ -1491,18 +1491,18 @@ static bool GetDhPubKeySpec(napi_env env, napi_value arg, HcfAsyKeyParamsSpec ** HcfDhPubKeyParamsSpec *spec = reinterpret_cast( HcfMalloc(sizeof(HcfDhPubKeyParamsSpec), 0)); if (spec == nullptr) { - LOGE("malloc failed!"); + LOGE_ONE_STR("malloc failed!"); return false; } napi_value commSpecValue = GetCommSpecNapiValue(env, arg); if (commSpecValue == nullptr) { - LOGE("Get comm spec napi value failed."); + LOGE_ONE_STR("Get comm spec napi value failed."); HcfFree(spec); return false; } if (!InitDhCommonAsyKeySpec(env, commSpecValue, reinterpret_cast(spec))) { - LOGE("InitDhCommonAsyKeySpec failed."); + LOGE_ONE_STR("InitDhCommonAsyKeySpec failed."); HcfFree(spec); return false; } @@ -1523,18 +1523,18 @@ static bool GetDhPriKeySpec(napi_env env, napi_value arg, HcfAsyKeyParamsSpec ** HcfDhPriKeyParamsSpec *spec = reinterpret_cast( HcfMalloc(sizeof(HcfDhPriKeyParamsSpec), 0)); if (spec == nullptr) { - LOGE("malloc failed!"); + LOGE_ONE_STR("malloc failed!"); return false; } napi_value commSpecValue = GetCommSpecNapiValue(env, arg); if (commSpecValue == nullptr) { - LOGE("Get comm spec napi value failed."); + LOGE_ONE_STR("Get comm spec napi value failed."); HcfFree(spec); return false; } if (!InitDhCommonAsyKeySpec(env, commSpecValue, reinterpret_cast(spec))) { - LOGE("InitDhCommonAsyKeySpec failed."); + LOGE_ONE_STR("InitDhCommonAsyKeySpec failed."); HcfFree(spec); return false; } @@ -1555,18 +1555,18 @@ static bool GetDhKeyPairAsyKeySpec(napi_env env, napi_value arg, HcfAsyKeyParams HcfDhKeyPairParamsSpec *spec = reinterpret_cast( HcfMalloc(sizeof(HcfDhKeyPairParamsSpec), 0)); if (spec == nullptr) { - LOGE("malloc failed!"); + LOGE_ONE_STR("malloc failed!"); return false; } napi_value commSpecValue = GetCommSpecNapiValue(env, arg); if (commSpecValue == nullptr) { - LOGE("Get comm spec napi value failed."); + LOGE_ONE_STR("Get comm spec napi value failed."); HcfFree(spec); return false; } if (!InitDhCommonAsyKeySpec(env, commSpecValue, reinterpret_cast(spec))) { - LOGE("InitDhCommonAsyKeySpec failed!"); + LOGE_ONE_STR("InitDhCommonAsyKeySpec failed!"); HcfFree(spec); return false; } @@ -1599,13 +1599,13 @@ static bool GetDh25519AsyKeySpec(napi_env env, napi_value arg, HcfAsyKeyParamsSp napi_status status = napi_get_named_property(env, arg, TAG_SPEC_TYPE.c_str(), &data); napi_typeof(env, data, &valueType); if ((status != napi_ok) || (data == nullptr) || (valueType == napi_undefined)) { - LOGE("failed to get valid algo name!"); + LOGE_ONE_STR("failed to get valid algo name!"); return false; } HcfAsyKeySpecType asyKeySpecType; status = napi_get_value_uint32(env, data, reinterpret_cast(&asyKeySpecType)); if (status != napi_ok) { - LOGE("failed to get valid asyKeySpecType!"); + LOGE_ONE_STR("failed to get valid asyKeySpecType!"); return false; } if (asyKeySpecType == HCF_PRIVATE_KEY_SPEC) { @@ -1617,7 +1617,7 @@ static bool GetDh25519AsyKeySpec(napi_env env, napi_value arg, HcfAsyKeyParamsSp } else if (asyKeySpecType == HCF_COMMON_PARAMS_SPEC) { return GetDhCommonAsyKeySpec(env, arg, asyKeySpec); } else { - LOGE("keySpec not support!"); + LOGE_ONE_STR("keySpec not support!"); return false; } } @@ -1627,7 +1627,7 @@ bool GetAsyKeySpecFromNapiValue(napi_env env, napi_value arg, HcfAsyKeyParamsSpe napi_value data = nullptr; if ((env == nullptr) || (arg == nullptr) || (asyKeySpec == nullptr)) { - LOGE("Invalid params!"); + LOGE_ONE_STR("Invalid params!"); return false; } @@ -1636,12 +1636,12 @@ bool GetAsyKeySpecFromNapiValue(napi_env env, napi_value arg, HcfAsyKeyParamsSpe napi_status status = napi_get_named_property(env, arg, CRYPTO_TAG_ALG_NAME.c_str(), &data); napi_typeof(env, data, &valueType); if ((status != napi_ok) || (data == nullptr) || (valueType == napi_undefined)) { - LOGE("failed to get valid algName!"); + LOGE_ONE_STR("failed to get valid algName!"); return false; } string algName; if (!GetStringFromJSParams(env, data, algName)) { - LOGE("GetStringFromJSParams failed!"); + LOGE_ONE_STR("GetStringFromJSParams failed!"); return false; } if (algName.compare(DSA_ASY_KEY_SPEC) == 0) { @@ -1663,17 +1663,17 @@ bool GetAsyKeySpecFromNapiValue(napi_env env, napi_value arg, HcfAsyKeyParamsSpe napi_value ConvertBlobToNapiValue(napi_env env, HcfBlob *blob) { if (blob == nullptr || blob->data == nullptr || blob->len == 0) { - LOGD("Invalid blob!"); + LOGD_ONE_STR("Invalid blob!"); return NapiGetNull(env); } uint8_t *buffer = reinterpret_cast(HcfMalloc(blob->len, 0)); if (buffer == nullptr) { - LOGE("malloc uint8 array buffer failed!"); + LOGE_ONE_STR("malloc uint8 array buffer failed!"); return NapiGetNull(env); } if (memcpy_s(buffer, blob->len, blob->data, blob->len) != EOK) { - LOGE("memcpy_s data to buffer failed!"); + LOGE_ONE_STR("memcpy_s data to buffer failed!"); HcfFree(buffer); return NapiGetNull(env); } @@ -1682,7 +1682,7 @@ napi_value ConvertBlobToNapiValue(napi_env env, HcfBlob *blob) napi_status status = napi_create_external_arraybuffer( env, buffer, blob->len, [](napi_env env, void *data, void *hint) { HcfFree(data); }, nullptr, &outBuffer); if (status != napi_ok) { - LOGE("create uint8 array buffer failed!"); + LOGE_ONE_STR("create uint8 array buffer failed!"); (void)memset_s(buffer, blob->len, 0, blob->len); HcfFree(buffer); return NapiGetNull(env); @@ -1707,7 +1707,7 @@ HcfResult ConvertDataBlobToNapiValue(napi_env env, HcfBlob *blob, napi_value *na uint8_t *buffer = reinterpret_cast(HcfMalloc(blob->len, 0)); if (buffer == nullptr) { - LOGE("malloc uint8 array buffer failed!"); + LOGE_ONE_STR("malloc uint8 array buffer failed!"); return HCF_ERR_MALLOC; } (void)memcpy_s(buffer, blob->len, blob->data, blob->len); @@ -1716,7 +1716,7 @@ HcfResult ConvertDataBlobToNapiValue(napi_env env, HcfBlob *blob, napi_value *na napi_status status = napi_create_external_arraybuffer( env, buffer, blob->len, [](napi_env env, void *data, void *hint) { HcfFree(data); }, nullptr, &outBuffer); if (status != napi_ok) { - LOGE("create napi uint8 array buffer failed!"); + LOGE_ONE_STR("create napi uint8 array buffer failed!"); HcfFree(buffer); return HCF_ERR_NAPI; } @@ -1734,19 +1734,19 @@ napi_value ConvertObjectBlobToNapiValue(napi_env env, HcfBlob *blob) { if (blob == nullptr || blob->data == nullptr || blob->len == 0) { napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "Invalid blob!")); - LOGE("Invalid blob!"); + LOGE_ONE_STR("Invalid blob!"); return NapiGetNull(env); } uint8_t *buffer = reinterpret_cast(HcfMalloc(blob->len, 0)); if (buffer == nullptr) { napi_throw(env, GenerateBusinessError(env, HCF_ERR_MALLOC, "malloc uint8 array buffer failed!")); - LOGE("malloc uint8 array buffer failed!"); + LOGE_ONE_STR("malloc uint8 array buffer failed!"); return NapiGetNull(env); } if (memcpy_s(buffer, blob->len, blob->data, blob->len) != EOK) { napi_throw(env, GenerateBusinessError(env, HCF_ERR_MALLOC, "memcpy_s data to buffer failed!")); - LOGE("memcpy_s data to buffer failed!"); + LOGE_ONE_STR("memcpy_s data to buffer failed!"); HcfFree(buffer); return NapiGetNull(env); } @@ -1756,7 +1756,7 @@ napi_value ConvertObjectBlobToNapiValue(napi_env env, HcfBlob *blob) env, buffer, blob->len, [](napi_env env, void *data, void *hint) { HcfFree(data); }, nullptr, &outBuffer); if (status != napi_ok) { napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "create uint8 array buffer failed!")); - LOGE("create uint8 array buffer failed!"); + LOGE_ONE_STR("create uint8 array buffer failed!"); HcfFree(buffer); return NapiGetNull(env); } @@ -1771,14 +1771,14 @@ napi_value ConvertBigIntToNapiValue(napi_env env, HcfBigInteger *blob) { if (blob == nullptr || blob->data == nullptr || blob->len == 0) { napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "Invalid blob!")); - LOGE("Invalid blob!"); + LOGE_ONE_STR("Invalid blob!"); return NapiGetNull(env); } size_t wordsCount = (blob->len / sizeof(uint64_t)) + ((blob->len % sizeof(uint64_t)) == 0 ? 0 : 1); uint64_t *words = reinterpret_cast(HcfMalloc(wordsCount * sizeof(uint64_t), 0)); if (words == nullptr) { napi_throw(env, GenerateBusinessError(env, HCF_ERR_MALLOC, "malloc uint8 array buffer failed!")); - LOGE("malloc uint8 array buffer failed!"); + LOGE_ONE_STR("malloc uint8 array buffer failed!"); return NapiGetNull(env); } @@ -1796,14 +1796,14 @@ napi_value ConvertBigIntToNapiValue(napi_env env, HcfBigInteger *blob) napi_status status = napi_create_bigint_words(env, 0, wordsCount, words, &bigInt); if (status != napi_ok) { napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "create bigint failed!")); - LOGE("create bigint failed!"); + LOGE_ONE_STR("create bigint failed!"); (void)memset_s(words, wordsCount * sizeof(uint64_t), 0, wordsCount * sizeof(uint64_t)); HcfFree(words); return NapiGetNull(env); } if (bigInt == nullptr) { napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "bigInt is null!")); - LOGE("bigInt is null!"); + LOGE_ONE_STR("bigInt is null!"); } (void)memset_s(words, wordsCount * sizeof(uint64_t), 0, wordsCount * sizeof(uint64_t)); HcfFree(words); @@ -1816,19 +1816,19 @@ bool GetStringFromJSParams(napi_env env, napi_value arg, string &returnStr) napi_valuetype valueType; napi_typeof(env, arg, &valueType); if (valueType != napi_string) { - LOGE("wrong argument type. expect string type."); + LOGE_ONE_STR("wrong argument type. expect string type."); return false; } size_t length = 0; if (napi_get_value_string_utf8(env, arg, nullptr, 0, &length) != napi_ok) { - LOGE("can not get string length"); + LOGE_ONE_STR("can not get string length"); return false; } returnStr.reserve(length + 1); returnStr.resize(length); if (napi_get_value_string_utf8(env, arg, returnStr.data(), (length + 1), &length) != napi_ok) { - LOGE("can not get string value"); + LOGE_ONE_STR("can not get string value"); return false; } return true; @@ -1844,7 +1844,7 @@ bool GetInt32FromJSParams(napi_env env, napi_value arg, int32_t &returnInt) } if (napi_get_value_int32(env, arg, &returnInt) != napi_ok) { - LOGE("can not get int value"); + LOGE_ONE_STR("can not get int value"); return false; } return true; @@ -1860,7 +1860,7 @@ bool GetUint32FromJSParams(napi_env env, napi_value arg, uint32_t &returnInt) } if (napi_get_value_uint32(env, arg, &returnInt) != napi_ok) { - LOGE("can not get int value"); + LOGE_ONE_STR("can not get int value"); return false; } return true; @@ -1876,11 +1876,11 @@ bool GetUint64FromJSParams(napi_env env, napi_value arg, uint64_t &returnInt) } int64_t int64Value = 0; if (napi_get_value_int64(env, arg, &int64Value) != napi_ok) { - LOGE("can not get int value"); + LOGE_ONE_STR("can not get int value"); return false; } if (int64Value < 0) { - LOGE("int64Value is less than 0"); + LOGE_ONE_STR("int64Value is less than 0"); return false; } returnInt = static_cast(int64Value); @@ -1938,12 +1938,12 @@ bool CheckArgsCount(napi_env env, size_t argc, size_t expectedCount, bool isSync { if (isSync) { if (argc != expectedCount) { - LOGE("invalid params count!"); + LOGE_ONE_STR("invalid params count!"); return false; } } else { if ((argc != expectedCount) && (argc != (expectedCount - ARGS_SIZE_ONE))) { - LOGE("invalid params count!"); + LOGE_ONE_STR("invalid params count!"); return false; } } @@ -1975,7 +1975,7 @@ bool BuildSetNamedProperty(napi_env env, HcfBigInteger *number, const char *name napi_value value = ConvertBigIntToNapiValue(env, number); napi_status status = napi_set_named_property(env, *instance, name, value); if (status != napi_ok) { - LOGE("create value failed!"); + LOGE_ONE_STR("create value failed!"); return false; } return true; diff --git a/frameworks/js/napi/crypto/src/napi_verify.cpp b/frameworks/js/napi/crypto/src/napi_verify.cpp index a03a02ca1a618ce4bc8248ab6f957118f2dc5709..f299bc84cdad5b860cc7bb054ae512add125aa48 100644 --- a/frameworks/js/napi/crypto/src/napi_verify.cpp +++ b/frameworks/js/napi/crypto/src/napi_verify.cpp @@ -225,7 +225,7 @@ static bool BuildVerifyJsInitCtx(napi_env env, napi_callback_info info, VerifyIn NapiVerify *napiVerify = nullptr; napi_status status = napi_unwrap(env, thisVar, reinterpret_cast(&napiVerify)); if (status != napi_ok || napiVerify == nullptr) { - LOGE("failed to unwrap napi verify obj."); + LOGE_ONE_STR("failed to unwrap napi verify obj."); return false; } @@ -233,7 +233,7 @@ static bool BuildVerifyJsInitCtx(napi_env env, napi_callback_info info, VerifyIn NapiPubKey *napiPubKey = nullptr; status = napi_unwrap(env, argv[index], reinterpret_cast(&napiPubKey)); if (status != napi_ok || napiPubKey == nullptr) { - LOGE("failed to unwrap napi pubKey obj."); + LOGE_ONE_STR("failed to unwrap napi pubKey obj."); return false; } @@ -242,12 +242,12 @@ static bool BuildVerifyJsInitCtx(napi_env env, napi_callback_info info, VerifyIn ctx->pubKey = napiPubKey->GetPubKey(); if (napi_create_reference(env, thisVar, 1, &ctx->verifyRef) != napi_ok) { - LOGE("create verify ref failed when do verify init!"); + LOGE_ONE_STR("create verify ref failed when do verify init!"); return false; } if (napi_create_reference(env, argv[PARAM0], 1, &ctx->pubKeyRef) != napi_ok) { - LOGE("create verify ref failed when do verify init!"); + LOGE_ONE_STR("create verify ref failed when do verify init!"); return false; } @@ -275,14 +275,14 @@ static bool BuildVerifyJsUpdateCtx(napi_env env, napi_callback_info info, Verify NapiVerify *napiVerify = nullptr; napi_status status = napi_unwrap(env, thisVar, reinterpret_cast(&napiVerify)); if (status != napi_ok || napiVerify == nullptr) { - LOGE("failed to unwrap napi verify obj."); + LOGE_ONE_STR("failed to unwrap napi verify obj."); return false; } size_t index = 0; HcfBlob *blob = GetBlobFromNapiDataBlob(env, argv[index]); if (blob == nullptr) { - LOGE("failed to get blob data from napi."); + LOGE_ONE_STR("failed to get blob data from napi."); return false; } @@ -290,7 +290,7 @@ static bool BuildVerifyJsUpdateCtx(napi_env env, napi_callback_info info, Verify ctx->data = blob; if (napi_create_reference(env, thisVar, 1, &ctx->verifyRef) != napi_ok) { - LOGE("create verify ref failed when do verify update!"); + LOGE_ONE_STR("create verify ref failed when do verify update!"); return false; } @@ -311,14 +311,14 @@ static bool GetDataBlobAndSignatureFromInput(napi_env env, napi_value dataValue, if (valueType != napi_null) { data = GetBlobFromNapiDataBlob(env, dataValue); if (data == nullptr) { - LOGE("failed to get data."); + LOGE_ONE_STR("failed to get data."); return false; } } HcfBlob *signatureData = GetBlobFromNapiDataBlob(env, signatureDataValue); if (signatureData == nullptr) { - LOGE("failed to get signature."); + LOGE_ONE_STR("failed to get signature."); HcfBlobDataFree(data); HcfFree(data); return false; @@ -334,7 +334,7 @@ static HcfResult GetDataAndSignatureFromInput(napi_env env, napi_value dataValue { HcfResult ret = GetBlobFromNapiValue(env, signatureDataValue, returnSignatureData); if (ret != HCF_SUCCESS) { - LOGE("failed to get signature."); + LOGE_ONE_STR("failed to get signature."); return ret; } @@ -348,7 +348,7 @@ static HcfResult GetDataAndSignatureFromInput(napi_env env, napi_value dataValue ret = GetBlobFromNapiValue(env, dataValue, returnData); if (ret != HCF_SUCCESS) { - LOGE("failed to get data."); + LOGE_ONE_STR("failed to get data."); HcfBlobDataFree(returnSignatureData); returnSignatureData->data = nullptr; returnSignatureData->len = 0; @@ -373,7 +373,7 @@ static bool BuildVerifyJsDoFinalCtx(napi_env env, napi_callback_info info, Verif NapiVerify *napiVerify = nullptr; napi_status status = napi_unwrap(env, thisVar, reinterpret_cast(&napiVerify)); if (status != napi_ok || napiVerify == nullptr) { - LOGE("failed to unwrap napi verify obj."); + LOGE_ONE_STR("failed to unwrap napi verify obj."); return false; } @@ -388,7 +388,7 @@ static bool BuildVerifyJsDoFinalCtx(napi_env env, napi_callback_info info, Verif ctx->signatureData = signatureData; if (napi_create_reference(env, thisVar, 1, &ctx->verifyRef) != napi_ok) { - LOGE("create verify ref failed when do verify final!"); + LOGE_ONE_STR("create verify ref failed when do verify final!"); return false; } @@ -499,7 +499,7 @@ static void VerifyJsInitAsyncWorkProcess(napi_env env, void *data) ctx->errCode = ctx->verify->init(ctx->verify, ctx->params, ctx->pubKey); if (ctx->errCode != HCF_SUCCESS) { - LOGD("[error] verify init fail."); + LOGD_ONE_STR("[error] verify init fail."); ctx->errMsg = "verify init fail."; } } @@ -522,7 +522,7 @@ static void VerifyJsUpdateAsyncWorkProcess(napi_env env, void *data) ctx->errCode = ctx->verify->update(ctx->verify, ctx->data); if (ctx->errCode != HCF_SUCCESS) { - LOGD("[error] verify update fail."); + LOGD_ONE_STR("[error] verify update fail."); ctx->errMsg = "verify update fail."; } } @@ -546,7 +546,7 @@ static void VerifyJsDoFinalAsyncWorkProcess(napi_env env, void *data) ctx->isVerifySucc = ctx->verify->verify(ctx->verify, ctx->data, ctx->signatureData); ctx->errCode = HCF_SUCCESS; if (!ctx->isVerifySucc) { - LOGD("[error] verify doFinal fail."); + LOGD_ONE_STR("[error] verify doFinal fail."); return; } } @@ -574,7 +574,7 @@ static void VerifyJsRecoverAsyncWorkProcess(napi_env env, void *data) ctx->errCode = ctx->verify->recover(ctx->verify, ctx->signatureData, &ctx->rawSignatureData); if (ctx->errCode != HCF_SUCCESS) { - LOGD("[error] verify revover fail."); + LOGD_ONE_STR("[error] verify revover fail."); ctx->errMsg = "verify revover fail."; } } @@ -713,13 +713,13 @@ napi_value NapiVerify::JsInit(napi_env env, napi_callback_info info) VerifyInitCtx *ctx = static_cast(HcfMalloc(sizeof(VerifyInitCtx), 0)); if (ctx == nullptr) { napi_throw(env, GenerateBusinessError(env, HCF_ERR_MALLOC, "create context fail.")); - LOGE("create context fail."); + LOGE_ONE_STR("create context fail."); return nullptr; } if (!BuildVerifyJsInitCtx(env, info, ctx)) { napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "build context fail.")); - LOGE("build context fail."); + LOGE_ONE_STR("build context fail."); FreeVerifyInitCtx(env, ctx); return nullptr; } @@ -742,7 +742,7 @@ napi_value NapiVerify::JsInitSync(napi_env env, napi_callback_info info) NapiVerify *napiVerify = nullptr; napi_status status = napi_unwrap(env, thisVar, reinterpret_cast(&napiVerify)); if (status != napi_ok || napiVerify == nullptr) { - LOGE("failed to unwrap napi verify obj."); + LOGE_ONE_STR("failed to unwrap napi verify obj."); napi_throw(env, GenerateBusinessError(env, HCF_ERR_NAPI, "failed to unwrap napi verify obj.")); return nullptr; } @@ -750,7 +750,7 @@ napi_value NapiVerify::JsInitSync(napi_env env, napi_callback_info info) NapiPubKey *napiPubKey = nullptr; status = napi_unwrap(env, argv[PARAM0], reinterpret_cast(&napiPubKey)); if (status != napi_ok || napiPubKey == nullptr) { - LOGE("failed to unwrap napi pubKey obj."); + LOGE_ONE_STR("failed to unwrap napi pubKey obj."); napi_throw(env, GenerateBusinessError(env, HCF_ERR_NAPI, "failed to unwrap napi pubKey obj.")); return nullptr; } @@ -760,7 +760,7 @@ napi_value NapiVerify::JsInitSync(napi_env env, napi_callback_info info) HcfResult ret = verify->init(verify, nullptr, pubKey); if (ret != HCF_SUCCESS) { - LOGE("verify init fail."); + LOGE_ONE_STR("verify init fail."); napi_throw(env, GenerateBusinessError(env, ret, "verify init fail.")); return nullptr; } @@ -773,13 +773,13 @@ napi_value NapiVerify::JsUpdate(napi_env env, napi_callback_info info) VerifyUpdateCtx *ctx = static_cast(HcfMalloc(sizeof(VerifyUpdateCtx), 0)); if (ctx == nullptr) { napi_throw(env, GenerateBusinessError(env, HCF_ERR_MALLOC, "create context fail.")); - LOGE("create context fail."); + LOGE_ONE_STR("create context fail."); return nullptr; } if (!BuildVerifyJsUpdateCtx(env, info, ctx)) { napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "build context fail.")); - LOGE("build context fail."); + LOGE_ONE_STR("build context fail."); FreeVerifyUpdateCtx(env, ctx); return nullptr; } @@ -802,7 +802,7 @@ napi_value NapiVerify::JsUpdateSync(napi_env env, napi_callback_info info) NapiVerify *napiVerify = nullptr; napi_status status = napi_unwrap(env, thisVar, reinterpret_cast(&napiVerify)); if (status != napi_ok || napiVerify == nullptr) { - LOGE("failed to unwrap napi verify obj."); + LOGE_ONE_STR("failed to unwrap napi verify obj."); napi_throw(env, GenerateBusinessError(env, HCF_ERR_NAPI, "failed to unwrap napi verify obj.")); return nullptr; } @@ -810,21 +810,21 @@ napi_value NapiVerify::JsUpdateSync(napi_env env, napi_callback_info info) HcfBlob blob = { 0 }; HcfResult ret = GetBlobFromNapiValue(env, argv[PARAM0], &blob); if (ret != HCF_SUCCESS) { - LOGE("failed to get input blob!"); + LOGE_ONE_STR("failed to get input blob!"); napi_throw(env, GenerateBusinessError(env, ret, "failed to get input blob.")); return nullptr; } HcfVerify *verify = napiVerify->GetVerify(); if (verify == nullptr) { - LOGE("failed to get verify obj."); + LOGE_ONE_STR("failed to get verify obj."); napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "fail to get verify obj.")); return nullptr; } ret = verify->update(verify, &blob); HcfBlobDataFree(&blob); if (ret != HCF_SUCCESS) { - LOGE("verify update fail."); + LOGE_ONE_STR("verify update fail."); napi_throw(env, GenerateBusinessError(env, ret, "verify update fail.")); } napi_value instance = NapiGetNull(env); @@ -836,13 +836,13 @@ napi_value NapiVerify::JsVerify(napi_env env, napi_callback_info info) VerifyDoFinalCtx *ctx = static_cast(HcfMalloc(sizeof(VerifyDoFinalCtx), 0)); if (ctx == nullptr) { napi_throw(env, GenerateBusinessError(env, HCF_ERR_MALLOC, "create context fail.")); - LOGE("create context fail."); + LOGE_ONE_STR("create context fail."); return nullptr; } if (!BuildVerifyJsDoFinalCtx(env, info, ctx)) { napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "build context fail.")); - LOGE("build context fail."); + LOGE_ONE_STR("build context fail."); FreeVerifyDoFinalCtx(env, ctx); return nullptr; } @@ -865,7 +865,7 @@ napi_value NapiVerify::JsVerifySync(napi_env env, napi_callback_info info) NapiVerify *napiVerify = nullptr; napi_status status = napi_unwrap(env, thisVar, reinterpret_cast(&napiVerify)); if (status != napi_ok || napiVerify == nullptr) { - LOGE("failed to unwrap napi verify obj."); + LOGE_ONE_STR("failed to unwrap napi verify obj."); napi_throw(env, GenerateBusinessError(env, HCF_ERR_NAPI, "failed to unwrap napi verify obj.")); return nullptr; } @@ -883,7 +883,7 @@ napi_value NapiVerify::JsVerifySync(napi_env env, napi_callback_info info) HcfBlobDataFree(&data); HcfBlobDataFree(&signatureData); if (!isVerifySucc) { - LOGD("verify doFinal fail."); + LOGD_ONE_STR("verify doFinal fail."); } napi_value result = nullptr; napi_get_boolean(env, isVerifySucc, &result); @@ -905,19 +905,19 @@ HcfResult BuildVerifyJsRecoverCtx(napi_env env, napi_callback_info info, VerifyR NapiVerify *napiVerify = nullptr; napi_status status = napi_unwrap(env, thisVar, reinterpret_cast(&napiVerify)); if (status != napi_ok || napiVerify == nullptr) { - LOGE("failed to unwrap napi verify obj."); + LOGE_ONE_STR("failed to unwrap napi verify obj."); return HCF_ERR_NAPI; } ctx->verify = napiVerify->GetVerify(); if (ctx->verify == nullptr) { - LOGE("failed to get verify obj."); + LOGE_ONE_STR("failed to get verify obj."); return HCF_INVALID_PARAMS; } ctx->signatureData = reinterpret_cast(HcfMalloc(sizeof(HcfBlob), 0)); if (ctx->signatureData == nullptr) { - LOGE("failed to allocate newBlob memory!"); + LOGE_ONE_STR("failed to allocate newBlob memory!"); return HCF_ERR_MALLOC; } @@ -927,7 +927,7 @@ HcfResult BuildVerifyJsRecoverCtx(napi_env env, napi_callback_info info, VerifyR } if (napi_create_reference(env, thisVar, 1, &ctx->verifyRef) != napi_ok) { - LOGE("create verify ref failed when do verify recover!"); + LOGE_ONE_STR("create verify ref failed when do verify recover!"); return HCF_ERR_NAPI; } @@ -939,14 +939,14 @@ napi_value NapiVerify::JsRecover(napi_env env, napi_callback_info info) { VerifyRecoverCtx *ctx = static_cast(HcfMalloc(sizeof(VerifyRecoverCtx), 0)); if (ctx == nullptr) { - LOGE("create context fail."); + LOGE_ONE_STR("create context fail."); napi_throw(env, GenerateBusinessError(env, HCF_ERR_MALLOC, "create context fail.")); return nullptr; } HcfResult ret = BuildVerifyJsRecoverCtx(env, info, ctx); if (ret != HCF_SUCCESS) { - LOGE("build context fail."); + LOGE_ONE_STR("build context fail."); napi_throw(env, GenerateBusinessError(env, ret, "build context fail.")); FreeVerifyRecoverCtx(env, ctx); return nullptr; @@ -971,14 +971,14 @@ napi_value NapiVerify::JsRecoverSync(napi_env env, napi_callback_info info) NapiVerify *napiVerify = nullptr; napi_status status = napi_unwrap(env, thisVar, reinterpret_cast(&napiVerify)); if (status != napi_ok || napiVerify == nullptr) { - LOGE("failed to unwrap napi verify obj."); + LOGE_ONE_STR("failed to unwrap napi verify obj."); napi_throw(env, GenerateBusinessError(env, HCF_ERR_NAPI, "failed to unwrap napi verify obj.")); return nullptr; } HcfVerify *verify = napiVerify->GetVerify(); if (verify == nullptr) { - LOGE("failed to get verify obj."); + LOGE_ONE_STR("failed to get verify obj."); napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "fail to get verify obj.")); return nullptr; } @@ -986,7 +986,7 @@ napi_value NapiVerify::JsRecoverSync(napi_env env, napi_callback_info info) HcfBlob signatureData = { 0 }; HcfResult ret = GetBlobFromNapiValue(env, argv[PARAM0], &signatureData); if (ret != HCF_SUCCESS) { - LOGE("failed to get signature data."); + LOGE_ONE_STR("failed to get signature data."); napi_throw(env, GenerateBusinessError(env, ret, "failed to get signature data.")); return nullptr; } @@ -995,7 +995,7 @@ napi_value NapiVerify::JsRecoverSync(napi_env env, napi_callback_info info) HcfResult res = verify->recover(verify, &signatureData, &rawSignatureData); HcfBlobDataFree(&signatureData); if (res != HCF_SUCCESS) { - LOGE("failed to verify recover."); + LOGE_ONE_STR("failed to verify recover."); napi_throw(env, GenerateBusinessError(env, res, "failed to verify recover.")); return nullptr; } @@ -1004,7 +1004,7 @@ napi_value NapiVerify::JsRecoverSync(napi_env env, napi_callback_info info) res = ConvertDataBlobToNapiValue(env, &rawSignatureData, &instance); HcfBlobDataFree(&rawSignatureData); if (res != HCF_SUCCESS) { - LOGE("verify recover convert dataBlob to napi_value failed!"); + LOGE_ONE_STR("verify recover convert dataBlob to napi_value failed!"); napi_throw(env, GenerateBusinessError(env, res, "verify recover convert dataBlob to napi_value failed!")); return nullptr; } @@ -1029,7 +1029,7 @@ static napi_value NapiWrapVerify(napi_env env, napi_value instance, NapiVerify * return; }, nullptr, nullptr); if (status != napi_ok) { - LOGE("failed to wrap napiVerify obj!"); + LOGE_ONE_STR("failed to wrap napiVerify obj!"); delete napiVerify; return nullptr; } @@ -1045,7 +1045,7 @@ napi_value NapiVerify::CreateJsVerify(napi_env env, napi_callback_info info) if (argc != expectedArgc) { napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "The input args num is invalid.")); - LOGE("The input args num is invalid."); + LOGE_ONE_STR("The input args num is invalid."); return nullptr; } @@ -1057,7 +1057,7 @@ napi_value NapiVerify::CreateJsVerify(napi_env env, napi_callback_info info) std::string algName; if (!GetStringFromJSParams(env, argv[0], algName)) { napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "failed to get algoName.")); - LOGE("failed to get algoName."); + LOGE_ONE_STR("failed to get algoName."); return nullptr; } @@ -1065,14 +1065,14 @@ napi_value NapiVerify::CreateJsVerify(napi_env env, napi_callback_info info) HcfResult ret = HcfVerifyCreate(algName.c_str(), &verify); if (ret != HCF_SUCCESS) { napi_throw(env, GenerateBusinessError(env, ret, "create c verify fail.")); - LOGE("create c verify fail."); + LOGE_ONE_STR("create c verify fail."); return nullptr; } NapiVerify *napiVerify = new (std::nothrow) NapiVerify(verify); if (napiVerify == nullptr) { napi_throw(env, GenerateBusinessError(env, HCF_ERR_MALLOC, "new napi verify failed")); - LOGE("new napi verify failed"); + LOGE_ONE_STR("new napi verify failed"); HcfObjDestroy(verify); return nullptr; } @@ -1089,14 +1089,14 @@ static HcfResult SetVerifyUserIdUintArray(napi_env env, napi_value *argv, HcfVer HcfBlob *blob = nullptr; blob = GetBlobFromNapiUint8Arr(env, argv[1]); if (blob == nullptr) { - LOGE("failed to get blob."); + LOGE_ONE_STR("failed to get blob."); return HCF_INVALID_PARAMS; } HcfResult ret = verify->setVerifySpecUint8Array(verify, SM2_USER_ID_UINT8ARR, *blob); if (ret != HCF_SUCCESS) { HcfBlobDataFree(blob); HcfFree(blob); - LOGE("c SetVerifyUserIdUintArray failed."); + LOGE_ONE_STR("c SetVerifyUserIdUintArray failed."); return HCF_INVALID_PARAMS; } HcfBlobDataFree(blob); @@ -1108,12 +1108,12 @@ static HcfResult SetVerifySaltLenInt(napi_env env, napi_value *argv, HcfVerify * { int32_t saltLen = 0; if (napi_get_value_int32(env, argv[1], &saltLen) != napi_ok) { - LOGE("get signSpec saltLen failed!"); + LOGE_ONE_STR("get signSpec saltLen failed!"); return HCF_INVALID_PARAMS; } HcfResult ret = verify->setVerifySpecInt(verify, PSS_SALT_LEN_INT, saltLen); if (ret != HCF_SUCCESS) { - LOGE("c setSignSpecNumber fail."); + LOGE_ONE_STR("c setSignSpecNumber fail."); return HCF_INVALID_PARAMS; } return ret; @@ -1131,7 +1131,7 @@ static HcfResult SetDetailVerifySpec(napi_env env, napi_value *argv, SignSpecIte result = SetVerifySaltLenInt(env, argv, verify); break; default: - LOGE("specItem not support."); + LOGE_ONE_STR("specItem not support."); break; } return result; @@ -1154,19 +1154,19 @@ napi_value NapiVerify::JsSetVerifySpec(napi_env env, napi_callback_info info) SignSpecItem item; if (napi_get_value_uint32(env, argv[0], reinterpret_cast(&item)) != napi_ok) { napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "get signSpecItem failed!")); - LOGE("get signspecitem failed!"); + LOGE_ONE_STR("get signspecitem failed!"); return nullptr; } napi_status status = napi_unwrap(env, thisVar, reinterpret_cast(&napiVerify)); if (status != napi_ok || napiVerify == nullptr) { napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "failed to unwrap napiVerify obj!")); - LOGE("failed to unwrap napiVerify obj!"); + LOGE_ONE_STR("failed to unwrap napiVerify obj!"); return nullptr; } HcfVerify *verify = napiVerify->GetVerify(); if (SetDetailVerifySpec(env, argv, item, verify) != HCF_SUCCESS) { napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "failed to set verify spec!")); - LOGE("failed to set verify spec!"); + LOGE_ONE_STR("failed to set verify spec!"); return nullptr; } return thisVar; @@ -1178,7 +1178,7 @@ static napi_value GetVerifySpecString(napi_env env, SignSpecItem item, HcfVerify HcfResult ret = verify->getVerifySpecString(verify, item, &returnString); if (ret != HCF_SUCCESS) { napi_throw(env, GenerateBusinessError(env, ret, "C getVerifySpecString failed.")); - LOGE("c getVerifySpecString fail."); + LOGE_ONE_STR("c getVerifySpecString fail."); return nullptr; } @@ -1194,7 +1194,7 @@ static napi_value GetVerifySpecNumber(napi_env env, SignSpecItem item, HcfVerify HcfResult ret = verify->getVerifySpecInt(verify, item, &returnInt); if (ret != HCF_SUCCESS) { napi_throw(env, GenerateBusinessError(env, ret, "C getVerifySpecInt failed.")); - LOGE("c getVerifySpecInt fail."); + LOGE_ONE_STR("c getVerifySpecInt fail."); return nullptr; } @@ -1219,20 +1219,20 @@ napi_value NapiVerify::JsGetVerifySpec(napi_env env, napi_callback_info info) SignSpecItem item; if (napi_get_value_uint32(env, argv[0], reinterpret_cast(&item)) != napi_ok) { napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "get signSpecItem failed!")); - LOGE("get signSpecItem failed!"); + LOGE_ONE_STR("get signSpecItem failed!"); return nullptr; } napi_status status = napi_unwrap(env, thisVar, reinterpret_cast(&napiVerify)); if (status != napi_ok || napiVerify == nullptr) { napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "failed to unwrap napiVerify obj!")); - LOGE("failed to unwrap napiVerify obj!"); + LOGE_ONE_STR("failed to unwrap napiVerify obj!"); return nullptr; } HcfVerify *verify = napiVerify->GetVerify(); if (verify == nullptr) { napi_throw(env, GenerateBusinessError(env, HCF_INVALID_PARAMS, "failed to get verify obj!")); - LOGE("failed to get verfiy obj!"); + LOGE_ONE_STR("failed to get verfiy obj!"); return nullptr; } diff --git a/frameworks/key/asy_key_generator.c b/frameworks/key/asy_key_generator.c index 28f23fcc5d52df98898fec3456e2df2d502da30c..b6e6fafe4f467583e2a9435c61ea85b1292e461f 100644 --- a/frameworks/key/asy_key_generator.c +++ b/frameworks/key/asy_key_generator.c @@ -135,15 +135,15 @@ static const KeyTypeAlg KEY_TYPE_MAP[] = { static bool IsDsaCommParamsSpecValid(HcfDsaCommParamsSpec *paramsSpec) { if ((paramsSpec->p.data == NULL) || (paramsSpec->p.len == 0)) { - LOGE("BigInteger p is invalid"); + LOGE_ONE_STR("BigInteger p is invalid"); return false; } if ((paramsSpec->q.data == NULL) || (paramsSpec->q.len == 0)) { - LOGE("BigInteger q is invalid"); + LOGE_ONE_STR("BigInteger q is invalid"); return false; } if ((paramsSpec->g.data == NULL) || (paramsSpec->g.len == 0)) { - LOGE("BigInteger g is invalid"); + LOGE_ONE_STR("BigInteger g is invalid"); return false; } return true; @@ -155,7 +155,7 @@ static bool IsDsaPubKeySpecValid(HcfDsaPubKeyParamsSpec *paramsSpec) return false; } if ((paramsSpec->pk.data == NULL) || (paramsSpec->pk.len == 0)) { - LOGE("BigInteger pk is invalid"); + LOGE_ONE_STR("BigInteger pk is invalid"); return false; } return true; @@ -167,11 +167,11 @@ static bool IsDsaKeyPairSpecValid(HcfDsaKeyPairParamsSpec *paramsSpec) return false; } if ((paramsSpec->pk.data == NULL) || (paramsSpec->pk.len == 0)) { - LOGE("BigInteger pk is invalid"); + LOGE_ONE_STR("BigInteger pk is invalid"); return false; } if ((paramsSpec->sk.data == NULL) || (paramsSpec->sk.len == 0)) { - LOGE("BigInteger sk is invalid"); + LOGE_ONE_STR("BigInteger sk is invalid"); return false; } return true; @@ -200,11 +200,11 @@ static bool IsDsaParamsSpecValid(const HcfAsyKeyParamsSpec *paramsSpec) static bool IsDhCommParamsSpecValid(HcfDhCommParamsSpec *paramsSpec) { if ((paramsSpec->p.data == NULL) || (paramsSpec->p.len == 0)) { - LOGE("BigInteger p is invalid"); + LOGE_ONE_STR("BigInteger p is invalid"); return false; } if ((paramsSpec->g.data == NULL) || (paramsSpec->g.len == 0)) { - LOGE("BigInteger g is invalid"); + LOGE_ONE_STR("BigInteger g is invalid"); return false; } return true; @@ -216,7 +216,7 @@ static bool IsDhPriKeySpecValid(HcfDhPriKeyParamsSpec *paramsSpec) return false; } if ((paramsSpec->sk.data == NULL) || (paramsSpec->sk.len == 0)) { - LOGE("BigInteger sk is invalid"); + LOGE_ONE_STR("BigInteger sk is invalid"); return false; } return true; @@ -228,7 +228,7 @@ static bool IsDhPubKeySpecValid(HcfDhPubKeyParamsSpec *paramsSpec) return false; } if ((paramsSpec->pk.data == NULL) || (paramsSpec->pk.len == 0)) { - LOGE("BigInteger pk is invalid"); + LOGE_ONE_STR("BigInteger pk is invalid"); return false; } return true; @@ -240,11 +240,11 @@ static bool IsDhKeyPairSpecValid(HcfDhKeyPairParamsSpec *paramsSpec) return false; } if ((paramsSpec->pk.data == NULL) || (paramsSpec->pk.len == 0)) { - LOGE("BigInteger pk is invalid"); + LOGE_ONE_STR("BigInteger pk is invalid"); return false; } if ((paramsSpec->sk.data == NULL) || (paramsSpec->sk.len == 0)) { - LOGE("BigInteger sk is invalid"); + LOGE_ONE_STR("BigInteger sk is invalid"); return false; } return true; @@ -276,33 +276,33 @@ static bool IsDhParamsSpecValid(const HcfAsyKeyParamsSpec *paramsSpec) static bool IsEccCommParamsSpecValid(HcfEccCommParamsSpec *paramsSpec) { if ((paramsSpec->a.data == NULL) || (paramsSpec->a.len == 0)) { - LOGE("BigInteger a is invalid"); + LOGE_ONE_STR("BigInteger a is invalid"); return false; } if ((paramsSpec->b.data == NULL) || (paramsSpec->b.len == 0)) { - LOGE("BigInteger b is invalid"); + LOGE_ONE_STR("BigInteger b is invalid"); return false; } if ((paramsSpec->n.data == NULL) || (paramsSpec->n.len == 0)) { - LOGE("BigInteger n is invalid"); + LOGE_ONE_STR("BigInteger n is invalid"); return false; } if ((paramsSpec->g.x.data == NULL) || (paramsSpec->g.x.len == 0) || (paramsSpec->g.y.data == NULL) || (paramsSpec->g.y.len == 0)) { - LOGE("Point g is invalid"); + LOGE_ONE_STR("Point g is invalid"); return false; } if (paramsSpec->field == NULL) { - LOGE("Field is null."); + LOGE_ONE_STR("Field is null."); return false; } if (strcmp(paramsSpec->field->fieldType, "Fp") != 0) { - LOGE("Unknown field type."); + LOGE_ONE_STR("Unknown field type."); return false; } HcfECFieldFp *tmp = (HcfECFieldFp *)(paramsSpec->field); if ((tmp->p.data == NULL) || (tmp->p.len == 0)) { - LOGE("EcFieldFp p is invalid"); + LOGE_ONE_STR("EcFieldFp p is invalid"); return false; } return true; @@ -314,7 +314,7 @@ static bool IsEccPriKeySpecValid(HcfEccPriKeyParamsSpec *paramsSpec) return false; } if ((paramsSpec->sk.data == NULL) || (paramsSpec->sk.len == 0)) { - LOGE("BigInteger sk is invalid"); + LOGE_ONE_STR("BigInteger sk is invalid"); return false; } return true; @@ -327,7 +327,7 @@ static bool IsEccPubKeySpecValid(HcfEccPubKeyParamsSpec *paramsSpec) } if ((paramsSpec->pk.x.data == NULL) || (paramsSpec->pk.x.len == 0) || (paramsSpec->pk.y.data == NULL) || (paramsSpec->pk.y.len == 0)) { - LOGE("Point pk is invalid"); + LOGE_ONE_STR("Point pk is invalid"); return false; } return true; @@ -340,11 +340,11 @@ static bool IsEccKeyPairSpecValid(HcfEccKeyPairParamsSpec *paramsSpec) } if ((paramsSpec->pk.x.data == NULL) || (paramsSpec->pk.x.len == 0) || (paramsSpec->pk.y.data == NULL) || (paramsSpec->pk.y.len == 0)) { - LOGE("Point pk is invalid"); + LOGE_ONE_STR("Point pk is invalid"); return false; } if ((paramsSpec->sk.data == NULL) || (paramsSpec->sk.len == 0)) { - LOGE("BigInteger sk is invalid"); + LOGE_ONE_STR("BigInteger sk is invalid"); return false; } return true; @@ -376,7 +376,7 @@ static bool IsEccParamsSpecValid(const HcfAsyKeyParamsSpec *paramsSpec) static bool IsAlg25519PriKeySpecValid(HcfAlg25519PriKeyParamsSpec *paramsSpec) { if ((paramsSpec->sk.data == NULL) || (paramsSpec->sk.len == 0)) { - LOGE("Uint8Array sk is invalid"); + LOGE_ONE_STR("Uint8Array sk is invalid"); return false; } return true; @@ -385,7 +385,7 @@ static bool IsAlg25519PriKeySpecValid(HcfAlg25519PriKeyParamsSpec *paramsSpec) static bool IsAlg25519PubKeySpecValid(HcfAlg25519PubKeyParamsSpec *paramsSpec) { if ((paramsSpec->pk.data == NULL) || (paramsSpec->pk.len == 0)) { - LOGE("Uint8Array pk is invalid"); + LOGE_ONE_STR("Uint8Array pk is invalid"); return false; } return true; @@ -394,11 +394,11 @@ static bool IsAlg25519PubKeySpecValid(HcfAlg25519PubKeyParamsSpec *paramsSpec) static bool IsAlg25519KeyPairSpecValid(HcfAlg25519KeyPairParamsSpec *paramsSpec) { if ((paramsSpec->pk.data == NULL) || (paramsSpec->pk.len == 0)) { - LOGE("Uint8Array pk is invalid"); + LOGE_ONE_STR("Uint8Array pk is invalid"); return false; } if ((paramsSpec->sk.data == NULL) || (paramsSpec->sk.len == 0)) { - LOGE("Uint8Array sk is invalid"); + LOGE_ONE_STR("Uint8Array sk is invalid"); return false; } return true; @@ -427,7 +427,7 @@ static bool IsAlg25519ParamsSpecValid(const HcfAsyKeyParamsSpec *paramsSpec) static bool IsRsaCommParamsSpecValid(HcfRsaCommParamsSpec *paramsSpec) { if ((paramsSpec->n.data == NULL) || (paramsSpec->n.len == 0)) { - LOGE("BigInteger n is invalid"); + LOGE_ONE_STR("BigInteger n is invalid"); return false; } return true; @@ -439,7 +439,7 @@ static bool IsRsaPubKeySpecValid(HcfRsaPubKeyParamsSpec *paramsSpec) return false; } if ((paramsSpec->pk.data == NULL) || (paramsSpec->pk.len == 0)) { - LOGE("BigInteger pk is invalid"); + LOGE_ONE_STR("BigInteger pk is invalid"); return false; } return true; @@ -451,11 +451,11 @@ static bool IsRsaKeyPairSpecValid(HcfRsaKeyPairParamsSpec *paramsSpec) return false; } if ((paramsSpec->pk.data == NULL) || (paramsSpec->pk.len == 0)) { - LOGE("BigInteger pk is invalid"); + LOGE_ONE_STR("BigInteger pk is invalid"); return false; } if ((paramsSpec->sk.data == NULL) || (paramsSpec->sk.len == 0)) { - LOGE("BigInteger sk is invalid"); + LOGE_ONE_STR("BigInteger sk is invalid"); return false; } return true; @@ -484,7 +484,7 @@ static bool IsRsaParamsSpecValid(const HcfAsyKeyParamsSpec *paramsSpec) static bool IsParamsSpecValid(const HcfAsyKeyParamsSpec *paramsSpec) { if ((paramsSpec == NULL) || (paramsSpec->algName == NULL)) { - LOGE("Params spec is null"); + LOGE_ONE_STR("Params spec is null"); return false; } if (strcmp(paramsSpec->algName, ALG_NAME_DSA) == 0) { @@ -518,7 +518,7 @@ static HcfAsyKeyGeneratorSpiCreateFunc FindAbility(HcfAsyKeyGenParams *params) static void SetPrimes(HcfAlgParaValue value, HcfAsyKeyGenParams *params) { if (params == NULL) { - LOGE("params is null."); + LOGE_ONE_STR("params is null."); return; } switch (value) { @@ -536,7 +536,7 @@ static void SetPrimes(HcfAlgParaValue value, HcfAsyKeyGenParams *params) break; default: params->primes = (int32_t)HCF_RSA_PRIMES_SIZE_2; // default primes is 2 - LOGD("user default primes 2"); + LOGD_ONE_STR("user default primes 2"); break; } LOGD("Set primes:%d!", params->primes); @@ -551,7 +551,7 @@ static void SetKeyType(HcfAlgParaValue value, HcfAsyKeyGenParams *params) return; } } - LOGE("There is not matched algorithm."); + LOGE_ONE_STR("There is not matched algorithm."); } static HcfResult ParseAsyKeyGenParams(const HcfParaConfig* config, void *params) @@ -583,19 +583,19 @@ static HcfResult CopyDsaCommonSpec(const HcfDsaCommParamsSpec *srcSpec, HcfDsaCo } destSpec->p.data = (unsigned char *)HcfMalloc(srcSpec->p.len, 0); if (destSpec->p.data == NULL) { - LOGE("Failed to allocate p data memory"); + LOGE_ONE_STR("Failed to allocate p data memory"); FreeDsaCommParamsSpec(destSpec); return HCF_ERR_MALLOC; } destSpec->q.data = (unsigned char *)HcfMalloc(srcSpec->q.len, 0); if (destSpec->q.data == NULL) { - LOGE("Failed to allocate q data memory"); + LOGE_ONE_STR("Failed to allocate q data memory"); FreeDsaCommParamsSpec(destSpec); return HCF_ERR_MALLOC; } destSpec->g.data = (unsigned char *)HcfMalloc(srcSpec->g.len, 0); if (destSpec->g.data == NULL) { - LOGE("Failed to allocate g data memory"); + LOGE_ONE_STR("Failed to allocate g data memory"); FreeDsaCommParamsSpec(destSpec); return HCF_ERR_MALLOC; } @@ -612,7 +612,7 @@ static HcfResult CreateDsaCommonSpecImpl(const HcfDsaCommParamsSpec *srcSpec, Hc { HcfDsaCommParamsSpec *spec = (HcfDsaCommParamsSpec *)HcfMalloc(sizeof(HcfDsaCommParamsSpec), 0); if (spec == NULL) { - LOGE("Failed to allocate dest spec memory"); + LOGE_ONE_STR("Failed to allocate dest spec memory"); return HCF_ERR_MALLOC; } @@ -629,7 +629,7 @@ static HcfResult CreateDsaPubKeySpecImpl(const HcfDsaPubKeyParamsSpec *srcSpec, { HcfDsaPubKeyParamsSpec *spec = (HcfDsaPubKeyParamsSpec *)HcfMalloc(sizeof(HcfDsaPubKeyParamsSpec), 0); if (spec == NULL) { - LOGE("Failed to allocate dest spec memory"); + LOGE_ONE_STR("Failed to allocate dest spec memory"); return HCF_ERR_MALLOC; } if (CopyDsaCommonSpec(&(srcSpec->base), &(spec->base)) != HCF_SUCCESS) { @@ -638,7 +638,7 @@ static HcfResult CreateDsaPubKeySpecImpl(const HcfDsaPubKeyParamsSpec *srcSpec, } spec->pk.data = (unsigned char *)HcfMalloc(srcSpec->pk.len, 0); if (spec->pk.data == NULL) { - LOGE("Failed to allocate public key memory"); + LOGE_ONE_STR("Failed to allocate public key memory"); FreeDsaCommParamsSpec(&(spec->base)); HcfFree(spec); return HCF_ERR_MALLOC; @@ -654,7 +654,7 @@ static HcfResult CreateDsaKeyPairSpecImpl(const HcfDsaKeyPairParamsSpec *srcSpec { HcfDsaKeyPairParamsSpec *spec = (HcfDsaKeyPairParamsSpec *)HcfMalloc(sizeof(HcfDsaKeyPairParamsSpec), 0); if (spec == NULL) { - LOGE("Failed to allocate dest spec memory"); + LOGE_ONE_STR("Failed to allocate dest spec memory"); return HCF_ERR_MALLOC; } if (CopyDsaCommonSpec(&(srcSpec->base), &(spec->base)) != HCF_SUCCESS) { @@ -663,14 +663,14 @@ static HcfResult CreateDsaKeyPairSpecImpl(const HcfDsaKeyPairParamsSpec *srcSpec } spec->pk.data = (unsigned char *)HcfMalloc(srcSpec->pk.len, 0); if (spec->pk.data == NULL) { - LOGE("Failed to allocate public key memory"); + LOGE_ONE_STR("Failed to allocate public key memory"); FreeDsaCommParamsSpec(&(spec->base)); HcfFree(spec); return HCF_ERR_MALLOC; } spec->sk.data = (unsigned char *)HcfMalloc(srcSpec->sk.len, 0); if (spec->sk.data == NULL) { - LOGE("Failed to allocate private key memory"); + LOGE_ONE_STR("Failed to allocate private key memory"); FreeDsaCommParamsSpec(&(spec->base)); HcfFree(spec->pk.data); HcfFree(spec); @@ -713,17 +713,17 @@ static HcfResult CreateDhPubKeySpecImpl(const HcfDhPubKeyParamsSpec *srcSpec, Hc { HcfDhPubKeyParamsSpec *spec = (HcfDhPubKeyParamsSpec *)HcfMalloc(sizeof(HcfDhPubKeyParamsSpec), 0); if (spec == NULL) { - LOGE("Failed to allocate dest spec memory"); + LOGE_ONE_STR("Failed to allocate dest spec memory"); return HCF_ERR_MALLOC; } if (CopyDhCommonSpec(&(srcSpec->base), &(spec->base)) != HCF_SUCCESS) { - LOGE("Failed to copy src spec"); + LOGE_ONE_STR("Failed to copy src spec"); HcfFree(spec); return HCF_INVALID_PARAMS; } spec->pk.data = (unsigned char *)HcfMalloc(srcSpec->pk.len, 0); if (spec->pk.data == NULL) { - LOGE("Failed to allocate public key memory"); + LOGE_ONE_STR("Failed to allocate public key memory"); DestroyDhPubKeySpec(spec); return HCF_ERR_MALLOC; } @@ -738,17 +738,17 @@ static HcfResult CreateDhPriKeySpecImpl(const HcfDhPriKeyParamsSpec *srcSpec, Hc { HcfDhPriKeyParamsSpec *spec = (HcfDhPriKeyParamsSpec *)HcfMalloc(sizeof(HcfDhPriKeyParamsSpec), 0); if (spec == NULL) { - LOGE("Failed to allocate dest spec memory"); + LOGE_ONE_STR("Failed to allocate dest spec memory"); return HCF_ERR_MALLOC; } if (CopyDhCommonSpec(&(srcSpec->base), &(spec->base)) != HCF_SUCCESS) { - LOGE("Failed to copy src spec"); + LOGE_ONE_STR("Failed to copy src spec"); HcfFree(spec); return HCF_INVALID_PARAMS; } spec->sk.data = (unsigned char *)HcfMalloc(srcSpec->sk.len, 0); if (spec->sk.data == NULL) { - LOGE("Failed to allocate private key memory"); + LOGE_ONE_STR("Failed to allocate private key memory"); FreeDhCommParamsSpec(&(spec->base)); HcfFree(spec); return HCF_ERR_MALLOC; @@ -764,24 +764,24 @@ static HcfResult CreateDhKeyPairSpecImpl(const HcfDhKeyPairParamsSpec *srcSpec, { HcfDhKeyPairParamsSpec *spec = (HcfDhKeyPairParamsSpec *)HcfMalloc(sizeof(HcfDhKeyPairParamsSpec), 0); if (spec == NULL) { - LOGE("Failed to allocate dest spec memory"); + LOGE_ONE_STR("Failed to allocate dest spec memory"); return HCF_ERR_MALLOC; } if (CopyDhCommonSpec(&(srcSpec->base), &(spec->base)) != HCF_SUCCESS) { - LOGE("Failed to copy src spec"); + LOGE_ONE_STR("Failed to copy src spec"); HcfFree(spec); return HCF_INVALID_PARAMS; } spec->pk.data = (unsigned char *)HcfMalloc(srcSpec->pk.len, 0); if (spec->pk.data == NULL) { - LOGE("Failed to allocate public key memory"); + LOGE_ONE_STR("Failed to allocate public key memory"); FreeDhCommParamsSpec(&(spec->base)); HcfFree(spec); return HCF_ERR_MALLOC; } spec->sk.data = (unsigned char *)HcfMalloc(srcSpec->sk.len, 0); if (spec->sk.data == NULL) { - LOGE("Failed to allocate private key memory"); + LOGE_ONE_STR("Failed to allocate private key memory"); FreeDhCommParamsSpec(&(spec->base)); HcfFree(spec->pk.data); HcfFree(spec); @@ -828,7 +828,7 @@ static HcfResult CreateEccPubKeySpecImpl(const HcfEccPubKeyParamsSpec *srcSpec, { HcfEccPubKeyParamsSpec *tmpSpec = (HcfEccPubKeyParamsSpec *)HcfMalloc(sizeof(HcfEccPubKeyParamsSpec), 0); if (tmpSpec == NULL) { - LOGE("Failed to allocate dest spec memory"); + LOGE_ONE_STR("Failed to allocate dest spec memory"); return HCF_ERR_MALLOC; } if (CopyEccCommonSpec(&(srcSpec->base), &(tmpSpec->base)) != HCF_SUCCESS) { @@ -837,7 +837,7 @@ static HcfResult CreateEccPubKeySpecImpl(const HcfEccPubKeyParamsSpec *srcSpec, } HcfResult res = CopyPoint(&(srcSpec->pk), &(tmpSpec->pk)); if (res != HCF_SUCCESS) { - LOGE("Failed to allocate public key memory"); + LOGE_ONE_STR("Failed to allocate public key memory"); FreeEccCommParamsSpec(&(tmpSpec->base)); HcfFree(tmpSpec); return res; @@ -851,7 +851,7 @@ static HcfResult CreateEccPriKeySpecImpl(const HcfEccPriKeyParamsSpec *srcSpec, { HcfEccPriKeyParamsSpec *tmpSpec = (HcfEccPriKeyParamsSpec *)HcfMalloc(sizeof(HcfEccPriKeyParamsSpec), 0); if (tmpSpec == NULL) { - LOGE("Failed to allocate dest spec memory"); + LOGE_ONE_STR("Failed to allocate dest spec memory"); return HCF_ERR_MALLOC; } if (CopyEccCommonSpec(&(srcSpec->base), &(tmpSpec->base)) != HCF_SUCCESS) { @@ -860,7 +860,7 @@ static HcfResult CreateEccPriKeySpecImpl(const HcfEccPriKeyParamsSpec *srcSpec, } tmpSpec->sk.data = (unsigned char *)HcfMalloc(srcSpec->sk.len, 0); if (tmpSpec->sk.data == NULL) { - LOGE("Failed to allocate private key memory"); + LOGE_ONE_STR("Failed to allocate private key memory"); FreeEccCommParamsSpec(&(tmpSpec->base)); HcfFree(tmpSpec); return HCF_ERR_MALLOC; @@ -876,7 +876,7 @@ static HcfResult CreateEccKeyPairSpecImpl(const HcfEccKeyPairParamsSpec *srcSpec { HcfEccKeyPairParamsSpec *tmpSpec = (HcfEccKeyPairParamsSpec *)HcfMalloc(sizeof(HcfEccKeyPairParamsSpec), 0); if (tmpSpec == NULL) { - LOGE("Failed to allocate dest spec memory"); + LOGE_ONE_STR("Failed to allocate dest spec memory"); return HCF_ERR_MALLOC; } if (CopyEccCommonSpec(&(srcSpec->base), &(tmpSpec->base)) != HCF_SUCCESS) { @@ -885,14 +885,14 @@ static HcfResult CreateEccKeyPairSpecImpl(const HcfEccKeyPairParamsSpec *srcSpec } HcfResult res = CopyPoint(&(srcSpec->pk), &(tmpSpec->pk)); if (res != HCF_SUCCESS) { - LOGE("Failed to allocate public key memory"); + LOGE_ONE_STR("Failed to allocate public key memory"); FreeEccCommParamsSpec(&(tmpSpec->base)); HcfFree(tmpSpec); return res; } tmpSpec->sk.data = (unsigned char *)HcfMalloc(srcSpec->sk.len, 0); if (tmpSpec->sk.data == NULL) { - LOGE("Failed to allocate private key memory"); + LOGE_ONE_STR("Failed to allocate private key memory"); FreeEccCommParamsSpec(&(tmpSpec->base)); HcfFree(tmpSpec->pk.x.data); HcfFree(tmpSpec->pk.y.data); @@ -940,7 +940,7 @@ static HcfResult CopyRsaCommonSpec(const HcfRsaCommParamsSpec *srcSpec, HcfRsaCo } destSpec->n.data = (unsigned char *)HcfMalloc(srcSpec->n.len, 0); if (destSpec->n.data == NULL) { - LOGE("Failed to allocate n data memory"); + LOGE_ONE_STR("Failed to allocate n data memory"); HcfFree(destSpec->base.algName); return HCF_ERR_MALLOC; } @@ -953,7 +953,7 @@ static HcfResult CreateRsaPubKeySpecImpl(const HcfRsaPubKeyParamsSpec *srcSpec, { HcfRsaPubKeyParamsSpec *spec = (HcfRsaPubKeyParamsSpec *)HcfMalloc(sizeof(HcfRsaPubKeyParamsSpec), 0); if (spec == NULL) { - LOGE("Failed to allocate dest spec memory"); + LOGE_ONE_STR("Failed to allocate dest spec memory"); return HCF_ERR_MALLOC; } if (CopyRsaCommonSpec(&(srcSpec->base), &(spec->base)) != HCF_SUCCESS) { @@ -962,7 +962,7 @@ static HcfResult CreateRsaPubKeySpecImpl(const HcfRsaPubKeyParamsSpec *srcSpec, } spec->pk.data = (unsigned char *)HcfMalloc(srcSpec->pk.len, 0); if (spec->pk.data == NULL) { - LOGE("Failed to allocate public key memory"); + LOGE_ONE_STR("Failed to allocate public key memory"); DestroyRsaPubKeySpec(spec); return HCF_ERR_MALLOC; } @@ -977,7 +977,7 @@ static HcfResult CreateRsaKeyPairSpecImpl(const HcfRsaKeyPairParamsSpec *srcSpec { HcfRsaKeyPairParamsSpec *spec = (HcfRsaKeyPairParamsSpec *)HcfMalloc(sizeof(HcfRsaKeyPairParamsSpec), 0); if (spec == NULL) { - LOGE("Failed to allocate dest spec memory"); + LOGE_ONE_STR("Failed to allocate dest spec memory"); return HCF_ERR_MALLOC; } if (CopyRsaCommonSpec(&(srcSpec->base), &(spec->base)) != HCF_SUCCESS) { @@ -986,14 +986,14 @@ static HcfResult CreateRsaKeyPairSpecImpl(const HcfRsaKeyPairParamsSpec *srcSpec } spec->pk.data = (unsigned char *)HcfMalloc(srcSpec->pk.len, 0); if (spec->pk.data == NULL) { - LOGE("Failed to allocate public key memory"); + LOGE_ONE_STR("Failed to allocate public key memory"); FreeRsaCommParamsSpec(&(spec->base)); HcfFree(spec); return HCF_ERR_MALLOC; } spec->sk.data = (unsigned char *)HcfMalloc(srcSpec->sk.len, 0); if (spec->sk.data == NULL) { - LOGE("Failed to allocate private key memory"); + LOGE_ONE_STR("Failed to allocate private key memory"); FreeRsaCommParamsSpec(&(spec->base)); HcfFree(spec->pk.data); HcfFree(spec); @@ -1015,7 +1015,7 @@ static HcfResult CreateRsaParamsSpecImpl(const HcfAsyKeyParamsSpec *paramsSpec, switch (paramsSpec->specType) { // commonspe should not be used in RSA case HCF_COMMON_PARAMS_SPEC: - LOGE("RSA not support comm spec"); + LOGE_ONE_STR("RSA not support comm spec"); ret = HCF_INVALID_PARAMS; break; case HCF_PUBLIC_KEY_SPEC: @@ -1040,17 +1040,17 @@ static HcfResult CreateAlg25519PubKeySpecImpl(const HcfAlg25519PubKeyParamsSpec HcfAlg25519PubKeyParamsSpec *tmpSpec = (HcfAlg25519PubKeyParamsSpec *)HcfMalloc(sizeof(HcfAlg25519PubKeyParamsSpec), 0); if (tmpSpec == NULL) { - LOGE("Failed to allocate dest spec memory"); + LOGE_ONE_STR("Failed to allocate dest spec memory"); return HCF_ERR_MALLOC; } if (CopyAsyKeyParamsSpec(&(srcSpec->base), &(tmpSpec->base)) != HCF_SUCCESS) { DestroyAlg25519PubKeySpec(tmpSpec); - LOGE("Copy alg25519 commonSpec memory"); + LOGE_ONE_STR("Copy alg25519 commonSpec memory"); return HCF_INVALID_PARAMS; } tmpSpec->pk.data = (unsigned char *)HcfMalloc(srcSpec->pk.len, 0); if (tmpSpec->pk.data == NULL) { - LOGE("Failed to allocate private key memory"); + LOGE_ONE_STR("Failed to allocate private key memory"); DestroyAlg25519PubKeySpec(tmpSpec); return HCF_ERR_MALLOC; } @@ -1067,17 +1067,17 @@ static HcfResult CreateAlg25519PriKeySpecImpl(const HcfAlg25519PriKeyParamsSpec HcfAlg25519PriKeyParamsSpec *tmpSpec = (HcfAlg25519PriKeyParamsSpec *)HcfMalloc(sizeof(HcfAlg25519PriKeyParamsSpec), 0); if (tmpSpec == NULL) { - LOGE("Failed to allocate dest spec memory"); + LOGE_ONE_STR("Failed to allocate dest spec memory"); return HCF_ERR_MALLOC; } if (CopyAsyKeyParamsSpec(&(srcSpec->base), &(tmpSpec->base)) != HCF_SUCCESS) { DestroyAlg25519PriKeySpec(tmpSpec); - LOGE("Copy alg25519 commonSpec memory"); + LOGE_ONE_STR("Copy alg25519 commonSpec memory"); return HCF_INVALID_PARAMS; } tmpSpec->sk.data = (unsigned char *)HcfMalloc(srcSpec->sk.len, 0); if (tmpSpec->sk.data == NULL) { - LOGE("Failed to allocate private key memory"); + LOGE_ONE_STR("Failed to allocate private key memory"); DestroyAlg25519PriKeySpec(tmpSpec); return HCF_ERR_MALLOC; } @@ -1094,24 +1094,24 @@ static HcfResult CreateAlg25519KeyPairSpecImpl(const HcfAlg25519KeyPairParamsSpe HcfAlg25519KeyPairParamsSpec *tmpSpec = (HcfAlg25519KeyPairParamsSpec *)HcfMalloc(sizeof(HcfAlg25519KeyPairParamsSpec), 0); if (tmpSpec == NULL) { - LOGE("Failed to allocate dest spec memory"); + LOGE_ONE_STR("Failed to allocate dest spec memory"); return HCF_ERR_MALLOC; } if (CopyAsyKeyParamsSpec(&(srcSpec->base), &(tmpSpec->base)) != HCF_SUCCESS) { DestroyAlg25519KeyPairSpec(tmpSpec); - LOGE("Copy alg25519 commonSpec memory"); + LOGE_ONE_STR("Copy alg25519 commonSpec memory"); return HCF_INVALID_PARAMS; } tmpSpec->pk.data = (unsigned char *)HcfMalloc(srcSpec->pk.len, 0); if (tmpSpec->pk.data == NULL) { - LOGE("Failed to allocate private key memory"); + LOGE_ONE_STR("Failed to allocate private key memory"); DestroyAlg25519KeyPairSpec(tmpSpec); return HCF_ERR_MALLOC; } tmpSpec->sk.data = (unsigned char *)HcfMalloc(srcSpec->sk.len, 0); if (tmpSpec->sk.data == NULL) { - LOGE("Failed to allocate private key memory"); + LOGE_ONE_STR("Failed to allocate private key memory"); DestroyAlg25519KeyPairSpec(tmpSpec); return HCF_ERR_MALLOC; } @@ -1200,7 +1200,7 @@ static const char *GetAsyKeyGeneratorBySpecClass(void) static const char *GetAlgoName(HcfAsyKeyGenerator *self) { if (self == NULL) { - LOGE("The input self ptr is NULL!"); + LOGE_ONE_STR("The input self ptr is NULL!"); return NULL; } if (!HcfIsClassMatch((HcfObjectBase *)self, GetAsyKeyGeneratorClass())) { @@ -1213,7 +1213,7 @@ static const char *GetAlgoName(HcfAsyKeyGenerator *self) static const char *GetAlgNameBySpec(const HcfAsyKeyGeneratorBySpec *self) { if (self == NULL) { - LOGE("The input self ptr is NULL!"); + LOGE_ONE_STR("The input self ptr is NULL!"); return NULL; } if (!HcfIsClassMatch((HcfObjectBase *)self, GetAsyKeyGeneratorBySpecClass())) { @@ -1227,7 +1227,7 @@ static HcfResult ConvertKey(HcfAsyKeyGenerator *self, HcfParamsSpec *params, Hcf HcfBlob *priKeyBlob, HcfKeyPair **returnKeyPair) { if (self == NULL) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return HCF_INVALID_PARAMS; } if (!HcfIsClassMatch((HcfObjectBase *)self, GetAsyKeyGeneratorClass())) { @@ -1235,7 +1235,7 @@ static HcfResult ConvertKey(HcfAsyKeyGenerator *self, HcfParamsSpec *params, Hcf } HcfAsyKeyGeneratorImpl *impl = (HcfAsyKeyGeneratorImpl *)self; if (impl->spiObj == NULL || impl->spiObj->engineConvertKey == NULL) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return HCF_INVALID_PARAMS; } return impl->spiObj->engineConvertKey(impl->spiObj, params, pubKeyBlob, priKeyBlob, returnKeyPair); @@ -1245,7 +1245,7 @@ static HcfResult ConvertPemKey(HcfAsyKeyGenerator *self, HcfParamsSpec *params, const char *priKeyStr, HcfKeyPair **returnKeyPair) { if (self == NULL) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return HCF_INVALID_PARAMS; } if (!HcfIsClassMatch((HcfObjectBase *)self, GetAsyKeyGeneratorClass())) { @@ -1253,7 +1253,7 @@ static HcfResult ConvertPemKey(HcfAsyKeyGenerator *self, HcfParamsSpec *params, } HcfAsyKeyGeneratorImpl *impl = (HcfAsyKeyGeneratorImpl *)self; if (impl->spiObj == NULL || impl->spiObj->engineConvertPemKey == NULL) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return HCF_INVALID_PARAMS; } return impl->spiObj->engineConvertPemKey(impl->spiObj, params, pubKeyStr, priKeyStr, returnKeyPair); @@ -1264,7 +1264,7 @@ static HcfResult GenerateKeyPair(HcfAsyKeyGenerator *self, HcfParamsSpec *params { (void)params; if (self == NULL) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return HCF_INVALID_PARAMS; } if (!HcfIsClassMatch((HcfObjectBase *)self, GetAsyKeyGeneratorClass())) { @@ -1272,7 +1272,7 @@ static HcfResult GenerateKeyPair(HcfAsyKeyGenerator *self, HcfParamsSpec *params } HcfAsyKeyGeneratorImpl *impl = (HcfAsyKeyGeneratorImpl *)self; if (impl->spiObj == NULL || impl->spiObj->engineGenerateKeyPair == NULL) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return HCF_INVALID_PARAMS; } return impl->spiObj->engineGenerateKeyPair(impl->spiObj, returnKeyPair); @@ -1281,7 +1281,7 @@ static HcfResult GenerateKeyPair(HcfAsyKeyGenerator *self, HcfParamsSpec *params static HcfResult GenerateKeyPairBySpec(const HcfAsyKeyGeneratorBySpec *self, HcfKeyPair **returnKeyPair) { if (self == NULL) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return HCF_INVALID_PARAMS; } if (!HcfIsClassMatch((HcfObjectBase *)self, GetAsyKeyGeneratorBySpecClass())) { @@ -1289,7 +1289,7 @@ static HcfResult GenerateKeyPairBySpec(const HcfAsyKeyGeneratorBySpec *self, Hcf } HcfAsyKeyGeneratorBySpecImpl *impl = (HcfAsyKeyGeneratorBySpecImpl *)self; if (impl->spiObj == NULL || impl->spiObj->engineGenerateKeyPairBySpec == NULL) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return HCF_INVALID_PARAMS; } return impl->spiObj->engineGenerateKeyPairBySpec(impl->spiObj, impl->paramsSpec, returnKeyPair); @@ -1298,7 +1298,7 @@ static HcfResult GenerateKeyPairBySpec(const HcfAsyKeyGeneratorBySpec *self, Hcf static HcfResult GeneratePubKeyBySpec(const HcfAsyKeyGeneratorBySpec *self, HcfPubKey **returnPubKey) { if (self == NULL) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return HCF_INVALID_PARAMS; } if (!HcfIsClassMatch((HcfObjectBase *)self, GetAsyKeyGeneratorBySpecClass())) { @@ -1306,7 +1306,7 @@ static HcfResult GeneratePubKeyBySpec(const HcfAsyKeyGeneratorBySpec *self, HcfP } HcfAsyKeyGeneratorBySpecImpl *impl = (HcfAsyKeyGeneratorBySpecImpl *)self; if (impl->spiObj == NULL || impl->spiObj->engineGeneratePubKeyBySpec == NULL) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return HCF_INVALID_PARAMS; } return impl->spiObj->engineGeneratePubKeyBySpec(impl->spiObj, impl->paramsSpec, returnPubKey); @@ -1315,7 +1315,7 @@ static HcfResult GeneratePubKeyBySpec(const HcfAsyKeyGeneratorBySpec *self, HcfP static HcfResult GeneratePriKeyBySpec(const HcfAsyKeyGeneratorBySpec *self, HcfPriKey **returnPriKey) { if (self == NULL) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return HCF_INVALID_PARAMS; } if (!HcfIsClassMatch((HcfObjectBase *)self, GetAsyKeyGeneratorBySpecClass())) { @@ -1323,7 +1323,7 @@ static HcfResult GeneratePriKeyBySpec(const HcfAsyKeyGeneratorBySpec *self, HcfP } HcfAsyKeyGeneratorBySpecImpl *impl = (HcfAsyKeyGeneratorBySpecImpl *)self; if (impl->spiObj == NULL || impl->spiObj->engineGeneratePriKeyBySpec == NULL) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return HCF_INVALID_PARAMS; } return impl->spiObj->engineGeneratePriKeyBySpec(impl->spiObj, impl->paramsSpec, returnPriKey); @@ -1367,7 +1367,7 @@ HcfResult HcfAsyKeyGeneratorCreate(const char *algoName, HcfAsyKeyGenerator **re HcfAsyKeyGenParams params = { 0 }; if (ParseAndSetParameter(algoName, ¶ms, ParseAsyKeyGenParams) != HCF_SUCCESS) { - LOGE("Failed to parse params!"); + LOGE_ONE_STR("Failed to parse params!"); return HCF_INVALID_PARAMS; } @@ -1378,11 +1378,11 @@ HcfResult HcfAsyKeyGeneratorCreate(const char *algoName, HcfAsyKeyGenerator **re HcfAsyKeyGeneratorImpl *returnGenerator = (HcfAsyKeyGeneratorImpl *)HcfMalloc(sizeof(HcfAsyKeyGeneratorImpl), 0); if (returnGenerator == NULL) { - LOGE("Failed to allocate returnGenerator memory!"); + LOGE_ONE_STR("Failed to allocate returnGenerator memory!"); return HCF_ERR_MALLOC; } if (strcpy_s(returnGenerator->algoName, HCF_MAX_ALGO_NAME_LEN, algoName) != EOK) { - LOGE("Failed to copy algoName!"); + LOGE_ONE_STR("Failed to copy algoName!"); HcfFree(returnGenerator); return HCF_INVALID_PARAMS; } @@ -1390,7 +1390,7 @@ HcfResult HcfAsyKeyGeneratorCreate(const char *algoName, HcfAsyKeyGenerator **re HcfResult res = HCF_SUCCESS; res = createSpiFunc(¶ms, &spiObj); if (res != HCF_SUCCESS) { - LOGE("Failed to create spi object!"); + LOGE_ONE_STR("Failed to create spi object!"); HcfFree(returnGenerator); return res; } @@ -1412,7 +1412,7 @@ HcfResult HcfAsyKeyGeneratorBySpecCreate(const HcfAsyKeyParamsSpec *paramsSpec, } HcfAsyKeyGenParams params = { 0 }; if (ParseAlgNameToParams(paramsSpec->algName, ¶ms) != HCF_SUCCESS) { - LOGE("Failed to parse params!"); + LOGE_ONE_STR("Failed to parse params!"); return HCF_INVALID_PARAMS; } HcfAsyKeyGeneratorSpiCreateFunc createSpiFunc = FindAbility(¶ms); @@ -1422,20 +1422,20 @@ HcfResult HcfAsyKeyGeneratorBySpecCreate(const HcfAsyKeyParamsSpec *paramsSpec, HcfAsyKeyGeneratorBySpecImpl *returnGenerator = (HcfAsyKeyGeneratorBySpecImpl *)HcfMalloc(sizeof(HcfAsyKeyGeneratorBySpecImpl), 0); if (returnGenerator == NULL) { - LOGE("Failed to allocate returnGenerator memory!"); + LOGE_ONE_STR("Failed to allocate returnGenerator memory!"); return HCF_ERR_MALLOC; } HcfAsyKeyParamsSpec *paramsSpecImpl = NULL; HcfResult ret = CreateAsyKeyParamsSpecImpl(paramsSpec, params.algo, ¶msSpecImpl); if (ret != HCF_SUCCESS) { - LOGE("Failed to create asy key params spec impl!"); + LOGE_ONE_STR("Failed to create asy key params spec impl!"); HcfFree(returnGenerator); return ret; } HcfAsyKeyGeneratorSpi *spiObj = NULL; ret = createSpiFunc(¶ms, &spiObj); if (ret != HCF_SUCCESS) { - LOGE("Failed to create spi object!"); + LOGE_ONE_STR("Failed to create spi object!"); HcfFree(returnGenerator); FreeAsyKeySpec(paramsSpecImpl); return ret; diff --git a/frameworks/key/dh_key_util.c b/frameworks/key/dh_key_util.c index af6c831536fd68606a968bd45bef190b16d094a1..40c478e005f267939ffd31c877e72e488039f983 100644 --- a/frameworks/key/dh_key_util.c +++ b/frameworks/key/dh_key_util.c @@ -27,24 +27,24 @@ HcfResult HcfDhKeyUtilCreate(int32_t pLen, int32_t skLen, HcfDhCommParamsSpec **returnCommonParamSpec) { if ((pLen < 0) || (skLen < 0) || (returnCommonParamSpec == NULL)) { - LOGE("Failed to parse params!"); + LOGE_ONE_STR("Failed to parse params!"); return HCF_INVALID_PARAMS; } if (skLen > pLen) { - LOGE("skLen is greater than pLen!"); + LOGE_ONE_STR("skLen is greater than pLen!"); return HCF_INVALID_PARAMS; } HcfDhCommParamsSpecSpi *spiInstance = NULL; HcfResult ret = HcfDhCommonParamSpecCreate(pLen, skLen, &spiInstance); if (ret != HCF_SUCCESS) { - LOGE("Failed to create spi object!"); + LOGE_ONE_STR("Failed to create spi object!"); return HCF_ERR_MALLOC; } ret = CreateDhCommonSpecImpl(&(spiInstance->paramsSpec), returnCommonParamSpec); if (ret != HCF_SUCCESS) { - LOGE("Failed to create spi impl object!"); + LOGE_ONE_STR("Failed to create spi impl object!"); } FreeDhCommParamsSpec(&(spiInstance->paramsSpec)); HcfFree(spiInstance); diff --git a/frameworks/key/ecc_key_util.c b/frameworks/key/ecc_key_util.c index 31565684ece1120926df30ab7779aad270c5ff98..254a1277f61fa2f6e4d20ec9f1d924e863dfaaf6 100644 --- a/frameworks/key/ecc_key_util.c +++ b/frameworks/key/ecc_key_util.c @@ -39,7 +39,7 @@ static const HcfEccCommParamsSpecAbility ASY_KEY_GEN_ABILITY_SET[] = { static HcfEccCommParamsSpecCreateFunc FindAbility(HcfAsyKeyGenParams *params) { if (params == NULL) { - LOGE("params is null"); + LOGE_ONE_STR("params is null"); return NULL; } for (uint32_t i = 0; i < sizeof(ASY_KEY_GEN_ABILITY_SET) / sizeof(ASY_KEY_GEN_ABILITY_SET[0]); i++) { @@ -54,15 +54,15 @@ static HcfEccCommParamsSpecCreateFunc FindAbility(HcfAsyKeyGenParams *params) static bool IsBigIntegerValid(const HcfBigInteger *bigInt) { if (bigInt == NULL) { - LOGE("Invalid HcfBigInteger parameter"); + LOGE_ONE_STR("Invalid HcfBigInteger parameter"); return false; } if (bigInt->data == NULL) { - LOGE("BigInteger data is NULL"); + LOGE_ONE_STR("BigInteger data is NULL"); return false; } if (bigInt->len == 0) { - LOGE("BigInteger length is 0"); + LOGE_ONE_STR("BigInteger length is 0"); return false; } return true; @@ -71,15 +71,15 @@ static bool IsBigIntegerValid(const HcfBigInteger *bigInt) static bool IsPointValid(const HcfPoint *point) { if (point == NULL) { - LOGE("Invalid point parameter"); + LOGE_ONE_STR("Invalid point parameter"); return false; } if (!IsBigIntegerValid(&(point->x))) { - LOGE("Invalid x coordinate parameter"); + LOGE_ONE_STR("Invalid x coordinate parameter"); return false; } if (!IsBigIntegerValid(&(point->y))) { - LOGE("Invalid y coordinate parameter"); + LOGE_ONE_STR("Invalid y coordinate parameter"); return false; } return true; @@ -88,30 +88,30 @@ static bool IsPointValid(const HcfPoint *point) HcfResult HcfConvertPoint(const char *curveName, HcfBlob *encodedPoint, HcfPoint *returnPoint) { if (!HcfIsStrValid(curveName, HCF_MAX_ALGO_NAME_LEN)) { - LOGE("Failed to parse params: curveName is invalid!"); + LOGE_ONE_STR("Failed to parse params: curveName is invalid!"); return HCF_INVALID_PARAMS; } if (!HcfIsBlobValid(encodedPoint)) { - LOGE("Failed to parse params: encodedPoint is invalid!"); + LOGE_ONE_STR("Failed to parse params: encodedPoint is invalid!"); return HCF_INVALID_PARAMS; } if (returnPoint == NULL) { - LOGE("Failed to parse params: returnPoint is NULL!"); + LOGE_ONE_STR("Failed to parse params: returnPoint is NULL!"); return HCF_INVALID_PARAMS; } HcfAlgParaValue algValue = 0; HcfResult ret = GetAlgValueByCurveName(curveName, &algValue); if (ret != HCF_SUCCESS) { - LOGE("Failed to get algValue."); + LOGE_ONE_STR("Failed to get algValue."); return ret; } ret = HcfEngineConvertPoint(algValue, encodedPoint, returnPoint); if (ret != HCF_SUCCESS) { - LOGE("Failed to create spi object!"); + LOGE_ONE_STR("Failed to create spi object!"); return ret; } return HCF_SUCCESS; @@ -120,42 +120,42 @@ HcfResult HcfConvertPoint(const char *curveName, HcfBlob *encodedPoint, HcfPoint HcfResult HcfGetEncodedPoint(const char *curveName, HcfPoint *point, const char *format, HcfBlob *returnBlob) { if (!HcfIsStrValid(curveName, HCF_MAX_ALGO_NAME_LEN)) { - LOGE("Failed to parse params: curveName is invalid!"); + LOGE_ONE_STR("Failed to parse params: curveName is invalid!"); return HCF_INVALID_PARAMS; } if (!IsPointValid(point)) { - LOGE("Failed to parse params: point is invalid!"); + LOGE_ONE_STR("Failed to parse params: point is invalid!"); return HCF_INVALID_PARAMS; } if (format == NULL) { - LOGE("Failed to parse params: format is NULL!"); + LOGE_ONE_STR("Failed to parse params: format is NULL!"); return HCF_INVALID_PARAMS; } HcfFormatValue formatValue = 0; HcfResult ret = GetFormatValueByFormatName(format, &formatValue); if (ret != HCF_SUCCESS) { - LOGE("Failed to get formatValue."); + LOGE_ONE_STR("Failed to get formatValue."); return ret; } if (returnBlob == NULL) { - LOGE("Failed to parse params: returnBlob is NULL!"); + LOGE_ONE_STR("Failed to parse params: returnBlob is NULL!"); return HCF_INVALID_PARAMS; } HcfAlgParaValue algValue = 0; ret = GetAlgValueByCurveName(curveName, &algValue); if (ret != HCF_SUCCESS) { - LOGE("Failed to get algValue."); + LOGE_ONE_STR("Failed to get algValue."); return ret; } ret = HcfEngineGetEncodedPoint(algValue, point, formatValue, returnBlob); if (ret != HCF_SUCCESS) { - LOGE("Failed to create spi object!"); + LOGE_ONE_STR("Failed to create spi object!"); return ret; } return HCF_SUCCESS; @@ -164,30 +164,30 @@ HcfResult HcfGetEncodedPoint(const char *curveName, HcfPoint *point, const char HcfResult HcfEccKeyUtilCreate(const char *algName, HcfEccCommParamsSpec **returnCommonParamSpec) { if ((!HcfIsStrValid(algName, HCF_MAX_ALGO_NAME_LEN)) || (returnCommonParamSpec == NULL)) { - LOGE("Failed to parse params!"); + LOGE_ONE_STR("Failed to parse params!"); return HCF_INVALID_PARAMS; } HcfAsyKeyGenParams params = { 0 }; if (ParseCurveNameToParams(algName, ¶ms) != HCF_SUCCESS) { - LOGE("Failed to parse params!"); + LOGE_ONE_STR("Failed to parse params!"); return HCF_INVALID_PARAMS; } HcfEccCommParamsSpecCreateFunc createSpiFunc = FindAbility(¶ms); if (createSpiFunc == NULL) { - LOGE("Failed to find ability!"); + LOGE_ONE_STR("Failed to find ability!"); return HCF_NOT_SUPPORT; } HcfEccCommParamsSpecSpi *spiInstance = NULL; HcfResult ret = createSpiFunc(¶ms, &spiInstance); if (ret != HCF_SUCCESS) { - LOGE("Failed to create spi object!"); + LOGE_ONE_STR("Failed to create spi object!"); return ret; } ret = CreateEccCommonSpecImpl(&(spiInstance->paramsSpec), returnCommonParamSpec); if (ret != HCF_SUCCESS) { - LOGE("Failed to create spi object!"); + LOGE_ONE_STR("Failed to create spi object!"); } FreeEccCommParamsSpec(&(spiInstance->paramsSpec)); HcfFree(spiInstance); diff --git a/frameworks/key/key_utils.c b/frameworks/key/key_utils.c index 6a34ab3ebf822703ae90441c0f1db219fe341a10..dede7894b99ac8ee8808f557fa1723415039170a 100644 --- a/frameworks/key/key_utils.c +++ b/frameworks/key/key_utils.c @@ -24,17 +24,17 @@ HcfResult CopyAsyKeyParamsSpec(const HcfAsyKeyParamsSpec *srcSpec, HcfAsyKeyParamsSpec *destSpec) { if (srcSpec == NULL || srcSpec->algName == NULL || destSpec == NULL) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return HCF_INVALID_PARAMS; } size_t srcAlgNameLen = HcfStrlen(srcSpec->algName); if (!srcAlgNameLen) { - LOGE("algName is empty!"); + LOGE_ONE_STR("algName is empty!"); return HCF_INVALID_PARAMS; } destSpec->algName = (char *)HcfMalloc(srcAlgNameLen + 1, 0); if (destSpec->algName == NULL) { - LOGE("Failed to allocate alg name memory"); + LOGE_ONE_STR("Failed to allocate alg name memory"); return HCF_ERR_MALLOC; } (void)memcpy_s(destSpec->algName, srcAlgNameLen, srcSpec->algName, srcAlgNameLen); @@ -46,17 +46,17 @@ HcfResult CopyPoint(const HcfPoint *src, HcfPoint *dest) { if (src == NULL || src->x.data == NULL || src->x.len == 0 || src->y.data == NULL || src->y.len == 0 || dest == NULL) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return HCF_INVALID_PARAMS; } dest->x.data = (unsigned char *)HcfMalloc(src->x.len, 0); if (dest->x.data == NULL) { - LOGE("Failed to allocate x data memory"); + LOGE_ONE_STR("Failed to allocate x data memory"); return HCF_ERR_MALLOC; } dest->y.data = (unsigned char *)HcfMalloc(src->y.len, 0); if (dest->y.data == NULL) { - LOGE("Failed to allocate y data memory"); + LOGE_ONE_STR("Failed to allocate y data memory"); HcfFree(dest->x.data); dest->x.data = NULL; return HCF_ERR_MALLOC; @@ -71,23 +71,23 @@ HcfResult CopyPoint(const HcfPoint *src, HcfPoint *dest) static HcfResult CopyEcField(const HcfECField *src, HcfECField **dest) { if (src == NULL || src->fieldType == NULL || dest == NULL) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return HCF_INVALID_PARAMS; } HcfECField *tmpField = (HcfECField *)HcfMalloc(sizeof(HcfECFieldFp), 0); if (tmpField == NULL) { - LOGE("Alloc memory failed."); + LOGE_ONE_STR("Alloc memory failed."); return HCF_ERR_MALLOC; } size_t srcFieldTypeLen = HcfStrlen(src->fieldType); if (!srcFieldTypeLen) { - LOGE("fieldType is empty!"); + LOGE_ONE_STR("fieldType is empty!"); HcfFree(tmpField); return HCF_INVALID_PARAMS; } tmpField->fieldType = (char *)HcfMalloc(srcFieldTypeLen + 1, 0); if (tmpField->fieldType == NULL) { - LOGE("Failed to allocate field memory."); + LOGE_ONE_STR("Failed to allocate field memory."); HcfFree(tmpField); return HCF_ERR_MALLOC; } @@ -95,7 +95,7 @@ static HcfResult CopyEcField(const HcfECField *src, HcfECField **dest) HcfECFieldFp *tmpSrc = (HcfECFieldFp *)(src); tmpDest->p.data = (unsigned char *)HcfMalloc(tmpSrc->p.len, 0); if (tmpDest->p.data == NULL) { - LOGE("Failed to allocate b data memory"); + LOGE_ONE_STR("Failed to allocate b data memory"); HcfFree(tmpField->fieldType); HcfFree(tmpField); return HCF_ERR_MALLOC; @@ -111,40 +111,40 @@ HcfResult CopyEccCommonSpec(const HcfEccCommParamsSpec *srcSpec, HcfEccCommParam { if (srcSpec == NULL || srcSpec->a.data == NULL || srcSpec->a.len == 0 || srcSpec->b.data == NULL || srcSpec->b.len == 0 || srcSpec->n.data == NULL || srcSpec->n.len == 0 || destSpec == NULL) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return HCF_INVALID_PARAMS; } if (CopyAsyKeyParamsSpec(&(srcSpec->base), &(destSpec->base)) != HCF_SUCCESS) { - LOGE("Failed to copy src common spec"); + LOGE_ONE_STR("Failed to copy src common spec"); return HCF_INVALID_PARAMS; } destSpec->a.data = (unsigned char *)HcfMalloc(srcSpec->a.len, 0); if (destSpec->a.data == NULL) { - LOGE("Failed to allocate a data memory"); + LOGE_ONE_STR("Failed to allocate a data memory"); FreeEccCommParamsSpec(destSpec); return HCF_ERR_MALLOC; } destSpec->b.data = (unsigned char *)HcfMalloc(srcSpec->b.len, 0); if (destSpec->b.data == NULL) { - LOGE("Failed to allocate b data memory"); + LOGE_ONE_STR("Failed to allocate b data memory"); FreeEccCommParamsSpec(destSpec); return HCF_ERR_MALLOC; } destSpec->n.data = (unsigned char *)HcfMalloc(srcSpec->n.len, 0); if (destSpec->n.data == NULL) { - LOGE("Failed to allocate n data memory"); + LOGE_ONE_STR("Failed to allocate n data memory"); FreeEccCommParamsSpec(destSpec); return HCF_ERR_MALLOC; } HcfResult res = CopyEcField(srcSpec->field, &(destSpec->field)); if (res != HCF_SUCCESS) { - LOGE("Failed to allocate field data memory"); + LOGE_ONE_STR("Failed to allocate field data memory"); FreeEccCommParamsSpec(destSpec); return HCF_ERR_MALLOC; } res = CopyPoint(&(srcSpec->g), &(destSpec->g)); if (res != HCF_SUCCESS) { - LOGE("Failed to allocate field data memory"); + LOGE_ONE_STR("Failed to allocate field data memory"); FreeEccCommParamsSpec(destSpec); return HCF_ERR_MALLOC; } @@ -161,16 +161,16 @@ HcfResult CopyEccCommonSpec(const HcfEccCommParamsSpec *srcSpec, HcfEccCommParam HcfResult CreateEccCommonSpecImpl(const HcfEccCommParamsSpec *srcSpec, HcfEccCommParamsSpec **destSpec) { if (srcSpec == NULL || destSpec == NULL) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return HCF_INVALID_PARAMS; } HcfEccCommParamsSpec *tmpSpec = (HcfEccCommParamsSpec *)HcfMalloc(sizeof(HcfEccCommParamsSpec), 0); if (tmpSpec == NULL) { - LOGE("Failed to allocate dest spec memory"); + LOGE_ONE_STR("Failed to allocate dest spec memory"); return HCF_ERR_MALLOC; } if (CopyEccCommonSpec(srcSpec, tmpSpec) != HCF_SUCCESS) { - LOGE("CreateEccCommonSpecImpl error!"); + LOGE_ONE_STR("CreateEccCommonSpecImpl error!"); HcfFree(tmpSpec); return HCF_INVALID_PARAMS; } @@ -181,19 +181,19 @@ HcfResult CreateEccCommonSpecImpl(const HcfEccCommParamsSpec *srcSpec, HcfEccCom HcfResult CopyDhCommonSpec(const HcfDhCommParamsSpec *srcSpec, HcfDhCommParamsSpec *destSpec) { if (CopyAsyKeyParamsSpec(&(srcSpec->base), &(destSpec->base)) != HCF_SUCCESS) { - LOGE("Failed to copy src common spec"); + LOGE_ONE_STR("Failed to copy src common spec"); return HCF_INVALID_PARAMS; } destSpec->p.data = (unsigned char *)HcfMalloc(srcSpec->p.len, 0); if (destSpec->p.data == NULL) { - LOGE("Failed to allocate p data memory"); + LOGE_ONE_STR("Failed to allocate p data memory"); FreeDhCommParamsSpec(destSpec); return HCF_ERR_MALLOC; } destSpec->g.data = (unsigned char *)HcfMalloc(srcSpec->g.len, 0); if (destSpec->g.data == NULL) { - LOGE("Failed to allocate g data memory"); + LOGE_ONE_STR("Failed to allocate g data memory"); FreeDhCommParamsSpec(destSpec); return HCF_ERR_MALLOC; } @@ -209,12 +209,12 @@ HcfResult CreateDhCommonSpecImpl(const HcfDhCommParamsSpec *srcSpec, HcfDhCommPa { HcfDhCommParamsSpec *spec = (HcfDhCommParamsSpec *)HcfMalloc(sizeof(HcfDhCommParamsSpec), 0); if (spec == NULL) { - LOGE("Failed to allocate dest spec memory"); + LOGE_ONE_STR("Failed to allocate dest spec memory"); return HCF_ERR_MALLOC; } if (CopyDhCommonSpec(srcSpec, spec) != HCF_SUCCESS) { - LOGE("Failed to copy src spec"); + LOGE_ONE_STR("Failed to copy src spec"); HcfFree(spec); return HCF_INVALID_PARAMS; } diff --git a/frameworks/key/sym_key_generator.c b/frameworks/key/sym_key_generator.c index de3cba8ce8d1cd419921d2f268e2e3a18cb4bf65..27a8a217e830cba4be719eedc91dee5aca448a3e 100644 --- a/frameworks/key/sym_key_generator.c +++ b/frameworks/key/sym_key_generator.c @@ -143,7 +143,7 @@ static void SetKeyLenByDigest(HcfAlgParaValue value, void *attr) break; default: // We will ignore the and 'NoHash' inputs - LOGE("Invalid digest input: NoHash"); + LOGE_ONE_STR("Invalid digest input: NoHash"); break; } } @@ -180,11 +180,11 @@ static const char *GetSymKeyGeneratorClass(void) static const char *GetAlgoName(HcfSymKeyGenerator *self) { if (self == NULL) { - LOGE("The input self ptr is NULL!"); + LOGE_ONE_STR("The input self ptr is NULL!"); return NULL; } if (!HcfIsClassMatch((HcfObjectBase *)self, GetSymKeyGeneratorClass())) { - LOGE("Class is not match!"); + LOGE_ONE_STR("Class is not match!"); return NULL; } return ((HcfSymmKeyGeneratorImpl *)self)->algoName; @@ -196,7 +196,7 @@ static void DestroySymmKeyGenerator(HcfObjectBase *base) return; } if (!HcfIsClassMatch((HcfObjectBase *)base, GetSymKeyGeneratorClass())) { - LOGE("Class is not match."); + LOGE_ONE_STR("Class is not match."); return; } HcfSymmKeyGeneratorImpl *impl = (HcfSymmKeyGeneratorImpl *)base; @@ -207,17 +207,17 @@ static void DestroySymmKeyGenerator(HcfObjectBase *base) static HcfResult GenerateSymmKey(HcfSymKeyGenerator *self, HcfSymKey **symmKey) { if ((self == NULL) || (symmKey == NULL)) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return HCF_INVALID_PARAMS; } if (!HcfIsClassMatch((HcfObjectBase *)self, GetSymKeyGeneratorClass())) { - LOGE("Class is not match."); + LOGE_ONE_STR("Class is not match."); return HCF_INVALID_PARAMS; } HcfSymmKeyGeneratorImpl *impl = (HcfSymmKeyGeneratorImpl *)self; if (impl->spiObj == NULL || impl->spiObj->engineGenerateSymmKey == NULL) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return HCF_INVALID_PARAMS; } @@ -227,16 +227,16 @@ static HcfResult GenerateSymmKey(HcfSymKeyGenerator *self, HcfSymKey **symmKey) static HcfResult ConvertSymmKey(HcfSymKeyGenerator *self, const HcfBlob *key, HcfSymKey **symmKey) { if ((self == NULL) || (symmKey == NULL) || !HcfIsBlobValid(key)) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return HCF_INVALID_PARAMS; } if (!HcfIsClassMatch((HcfObjectBase *)self, GetSymKeyGeneratorClass())) { - LOGE("Class is not match."); + LOGE_ONE_STR("Class is not match."); return HCF_INVALID_PARAMS; } HcfSymmKeyGeneratorImpl *impl = (HcfSymmKeyGeneratorImpl *)self; if (impl->spiObj == NULL || impl->spiObj->engineConvertSymmKey == NULL) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return HCF_INVALID_PARAMS; } return impl->spiObj->engineConvertSymmKey(impl->spiObj, key, symmKey); @@ -245,35 +245,35 @@ static HcfResult ConvertSymmKey(HcfSymKeyGenerator *self, const HcfBlob *key, Hc HcfResult HcfSymKeyGeneratorCreate(const char *algoName, HcfSymKeyGenerator **returnObj) { if (!HcfIsStrValid(algoName, HCF_MAX_ALGO_NAME_LEN) || (returnObj == NULL)) { - LOGE("Invalid input params while creating symkey!"); + LOGE_ONE_STR("Invalid input params while creating symkey!"); return HCF_INVALID_PARAMS; } SymKeyAttr attr = {0}; if (ParseAndSetParameter(algoName, (void *)&attr, OnSetSymKeyParameter) != HCF_SUCCESS) { - LOGE("ParseAndSetParameter Failed!"); + LOGE_ONE_STR("ParseAndSetParameter Failed!"); return HCF_NOT_SUPPORT; } const SymKeyGenFuncSet *funcSet = FindAbility(&attr); if (funcSet == NULL) { - LOGE("FindAbility Failed!"); + LOGE_ONE_STR("FindAbility Failed!"); return HCF_NOT_SUPPORT; } HcfSymmKeyGeneratorImpl *returnGenerator = (HcfSymmKeyGeneratorImpl *)HcfMalloc(sizeof(HcfSymmKeyGeneratorImpl), 0); if (returnGenerator == NULL) { - LOGE("Failed to allocate returnGenerator memory!"); + LOGE_ONE_STR("Failed to allocate returnGenerator memory!"); return HCF_ERR_MALLOC; } if (strcpy_s(returnGenerator->algoName, HCF_MAX_ALGO_NAME_LEN, algoName) != EOK) { - LOGE("Failed to copy algoName!"); + LOGE_ONE_STR("Failed to copy algoName!"); HcfFree(returnGenerator); return HCF_INVALID_PARAMS; } HcfSymKeyGeneratorSpi *spiObj = NULL; HcfResult res = funcSet->createFunc(&attr, &spiObj); if (res != HCF_SUCCESS) { - LOGE("Failed to create spi object!"); + LOGE_ONE_STR("Failed to create spi object!"); HcfFree(returnGenerator); return res; } diff --git a/plugin/mbedtls_plugin/md/src/mbedtls_md.c b/plugin/mbedtls_plugin/md/src/mbedtls_md.c index 73a5fd680191873de98caade4e9317713fa67bae..59993837481ace2839a30f8d849778bbc1635314 100644 --- a/plugin/mbedtls_plugin/md/src/mbedtls_md.c +++ b/plugin/mbedtls_plugin/md/src/mbedtls_md.c @@ -47,7 +47,7 @@ static const char *MbedtlsGetMdClass(void) static mbedtls_md_context_t *MbedtlsGetMdCtx(HcfMdSpi *self) { if (!HcfIsClassMatch((HcfObjectBase *)self, MbedtlsGetMdClass())) { - LOGE("Class is not match."); + LOGE_ONE_STR("Class is not match."); return NULL; } @@ -58,7 +58,7 @@ static HcfResult MbedtlsEngineUpdateMd(HcfMdSpi *self, HcfBlob *input) { mbedtls_md_context_t *ctx = MbedtlsGetMdCtx(self); if (ctx == NULL) { - LOGD("The CTX is NULL!"); + LOGD_ONE_STR("The CTX is NULL!"); return HCF_INVALID_PARAMS; } int32_t ret = mbedtls_md_update(ctx, (const unsigned char *)input->data, input->len); @@ -73,18 +73,18 @@ static HcfResult MbedtlsEngineUpdateMd(HcfMdSpi *self, HcfBlob *input) static HcfResult MbedtlsEngineDoFinalMd(HcfMdSpi *self, HcfBlob *output) { if ((self == NULL) || (output == NULL)) { - LOGE("The input self ptr is NULL!"); + LOGE_ONE_STR("The input self ptr is NULL!"); return HCF_INVALID_PARAMS; } mbedtls_md_context_t *ctx = MbedtlsGetMdCtx(self); if (ctx == NULL) { - LOGE("The CTX is NULL!"); + LOGE_ONE_STR("The CTX is NULL!"); return HCF_INVALID_PARAMS; } unsigned char outputBuf[HCF_EVP_MAX_MD_SIZE] = { 0 }; uint8_t outputLen = mbedtls_md_get_size(mbedtls_md_info_from_ctx(ctx)); if (outputLen == 0) { - LOGD("Failed to md get size is 0!"); + LOGD_ONE_STR("Failed to md get size is 0!"); return HCF_ERR_CRYPTO_OPERATION; } int32_t ret = mbedtls_md_finish(ctx, outputBuf); @@ -94,7 +94,7 @@ static HcfResult MbedtlsEngineDoFinalMd(HcfMdSpi *self, HcfBlob *output) } output->data = (uint8_t *)HcfMalloc(outputLen, 0); if (output->data == NULL) { - LOGE("Failed to allocate output->data memory!"); + LOGE_ONE_STR("Failed to allocate output->data memory!"); return HCF_ERR_MALLOC; } (void)memcpy_s(output->data, outputLen, outputBuf, outputLen); @@ -107,7 +107,7 @@ static uint32_t MbedtlsEngineGetMdLength(HcfMdSpi *self) { mbedtls_md_context_t *ctx = MbedtlsGetMdCtx(self); if (ctx == NULL) { - LOGD("The CTX is NULL!"); + LOGD_ONE_STR("The CTX is NULL!"); return HCF_MBEDTLS_INVALID_MD_LEN; } uint8_t outputLen = mbedtls_md_get_size(mbedtls_md_info_from_ctx(ctx)); @@ -122,11 +122,11 @@ static uint32_t MbedtlsEngineGetMdLength(HcfMdSpi *self) static void MbedtlsDestroyMd(HcfObjectBase *self) { if (self == NULL) { - LOGE("The input self ptr is NULL!"); + LOGE_ONE_STR("The input self ptr is NULL!"); return; } if (!HcfIsClassMatch(self, MbedtlsGetMdClass())) { - LOGE("Class is not match."); + LOGE_ONE_STR("Class is not match."); return; } if (MbedtlsGetMdCtx((HcfMdSpi *)self) != NULL) { @@ -165,17 +165,17 @@ int MbedtlsEvpDigestInitEx(mbedtls_md_context_t *ctx, const char *mbedtlsAlgoNam HcfResult MbedtlsMdSpiCreate(const char *mbedtlsAlgoName, HcfMdSpi **spiObj) { if (spiObj == NULL) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return HCF_INVALID_PARAMS; } MbedtlsMdSpiImpl *returnSpiImpl = (MbedtlsMdSpiImpl *)HcfMalloc(sizeof(MbedtlsMdSpiImpl), 0); if (returnSpiImpl == NULL) { - LOGE("Failed to allocate returnImpl memory!"); + LOGE_ONE_STR("Failed to allocate returnImpl memory!"); return HCF_ERR_MALLOC; } returnSpiImpl->ctx = MbedtlsEvpMdCtxNew(); if (returnSpiImpl->ctx == NULL) { - LOGE("Failed to create ctx!"); + LOGE_ONE_STR("Failed to create ctx!"); HcfFree(returnSpiImpl); return HCF_ERR_MALLOC; } diff --git a/plugin/mbedtls_plugin/rand/src/mbedtls_rand.c b/plugin/mbedtls_plugin/rand/src/mbedtls_rand.c index 247eb691e6207982f92aa4b20a013de07497b1ef..3846dc669b4fda6ea469a5e869f95ea291ba669a 100644 --- a/plugin/mbedtls_plugin/rand/src/mbedtls_rand.c +++ b/plugin/mbedtls_plugin/rand/src/mbedtls_rand.c @@ -36,7 +36,7 @@ static const char *GetMbedtlsRandClass(void) static mbedtls_entropy_context *MbedtlsGetMdEntropy(HcfRandSpi *self) { if (!HcfIsClassMatch((HcfObjectBase *)self, GetMbedtlsRandClass())) { - LOGE("Class is not match."); + LOGE_ONE_STR("Class is not match."); return NULL; } @@ -46,7 +46,7 @@ static mbedtls_entropy_context *MbedtlsGetMdEntropy(HcfRandSpi *self) static mbedtls_ctr_drbg_context *MbedtlsGetMdCtrDrbg(HcfRandSpi *self) { if (!HcfIsClassMatch((HcfObjectBase *)self, GetMbedtlsRandClass())) { - LOGE("Class is not match."); + LOGE_ONE_STR("Class is not match."); return NULL; } return ((HcfRandSpiImpl *)self)->ctrDrbg; @@ -55,21 +55,21 @@ static mbedtls_ctr_drbg_context *MbedtlsGetMdCtrDrbg(HcfRandSpi *self) static HcfResult MbedtlsGenerateRandom(HcfRandSpi *self, int32_t numBytes, HcfBlob *random) { if ((self == NULL) || (random == NULL)) { - LOGE("Invalid params!"); + LOGE_ONE_STR("Invalid params!"); return HCF_INVALID_PARAMS; } if (numBytes <= 0) { - LOGE("Invalid numBytes!"); + LOGE_ONE_STR("Invalid numBytes!"); return HCF_INVALID_PARAMS; } mbedtls_ctr_drbg_context *ctrDrbg = MbedtlsGetMdCtrDrbg(self); if (ctrDrbg == NULL) { - LOGE("Invalid ctrDrbg null!"); + LOGE_ONE_STR("Invalid ctrDrbg null!"); return HCF_INVALID_PARAMS; } random->data = (uint8_t *)HcfMalloc(numBytes, 0); if (random->data == NULL) { - LOGE("Failed to allocate random->data memory!"); + LOGE_ONE_STR("Failed to allocate random->data memory!"); return HCF_ERR_MALLOC; } int32_t ret = mbedtls_ctr_drbg_random(ctrDrbg, random->data, numBytes); @@ -87,11 +87,11 @@ static HcfResult MbedtlsGenerateRandom(HcfRandSpi *self, int32_t numBytes, HcfBl static const char *MbedtlsGetRandAlgoName(HcfRandSpi *self) { if (self == NULL) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return NULL; } if (!HcfIsClassMatch((HcfObjectBase *)self, GetMbedtlsRandClass())) { - LOGE("Class is not match."); + LOGE_ONE_STR("Class is not match."); return NULL; } @@ -101,21 +101,21 @@ static const char *MbedtlsGetRandAlgoName(HcfRandSpi *self) static void MbedtlsSetSeed(HcfRandSpi *self, HcfBlob *seed) { if ((self == NULL) || (seed == NULL)) { - LOGE("Invalid params!"); + LOGE_ONE_STR("Invalid params!"); return; } if ((seed->data == NULL) || (seed->len == 0)) { - LOGE("Invalid numBytes!"); + LOGE_ONE_STR("Invalid numBytes!"); return; } mbedtls_ctr_drbg_context *ctrDrbg = MbedtlsGetMdCtrDrbg(self); if (ctrDrbg == NULL) { - LOGE("Invalid ctrDrbg params!"); + LOGE_ONE_STR("Invalid ctrDrbg params!"); return; } mbedtls_entropy_context *entropy = MbedtlsGetMdEntropy(self); if (entropy == NULL) { - LOGE("Invalid entropy params!"); + LOGE_ONE_STR("Invalid entropy params!"); return; } int32_t ret = mbedtls_ctr_drbg_seed(ctrDrbg, mbedtls_entropy_func, entropy, @@ -129,11 +129,11 @@ static void MbedtlsSetSeed(HcfRandSpi *self, HcfBlob *seed) static void DestroyMbedtlsRand(HcfObjectBase *self) { if (self == NULL) { - LOGE("Self ptr is NULL!"); + LOGE_ONE_STR("Self ptr is NULL!"); return; } if (!HcfIsClassMatch(self, GetMbedtlsRandClass())) { - LOGE("Class is not match."); + LOGE_ONE_STR("Class is not match."); return; } mbedtls_ctr_drbg_context *ctrDrbg = MbedtlsGetMdCtrDrbg((HcfRandSpi *)self); @@ -152,18 +152,18 @@ static void DestroyMbedtlsRand(HcfObjectBase *self) static int32_t MbedtlsRandInitEx(mbedtls_entropy_context **entropy, mbedtls_ctr_drbg_context **ctrDrbg) { if ((entropy == NULL) || (ctrDrbg == NULL)) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return HCF_INVALID_PARAMS; } *entropy = (mbedtls_entropy_context *)HcfMalloc(sizeof(mbedtls_entropy_context), 0); if (*entropy == NULL) { - LOGE("Failed to allocate *entropy memory!"); + LOGE_ONE_STR("Failed to allocate *entropy memory!"); return HCF_ERR_MALLOC; } *ctrDrbg = (mbedtls_ctr_drbg_context *)HcfMalloc(sizeof(mbedtls_ctr_drbg_context), 0); if (*ctrDrbg == NULL) { HcfFree(*entropy); - LOGE("Failed to allocate *ctrDrbg memory!"); + LOGE_ONE_STR("Failed to allocate *ctrDrbg memory!"); return HCF_ERR_MALLOC; } mbedtls_entropy_init(*entropy); @@ -184,17 +184,17 @@ static int32_t MbedtlsRandInitEx(mbedtls_entropy_context **entropy, mbedtls_ctr_ HcfResult MbedtlsRandSpiCreate(HcfRandSpi **spiObj) { if (spiObj == NULL) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return HCF_INVALID_PARAMS; } HcfRandSpiImpl *returnSpiImpl = (HcfRandSpiImpl *)HcfMalloc(sizeof(HcfRandSpiImpl), 0); if (returnSpiImpl == NULL) { - LOGE("Failed to allocate *returnSpiImpl memory!"); + LOGE_ONE_STR("Failed to allocate *returnSpiImpl memory!"); return HCF_ERR_MALLOC; } int32_t ret = MbedtlsRandInitEx(&(returnSpiImpl->entropy), &(returnSpiImpl->ctrDrbg)); if (ret != HCF_SUCCESS) { - LOGE("Failed to allocate entropy ctrDrbg memory!"); + LOGE_ONE_STR("Failed to allocate entropy ctrDrbg memory!"); return HCF_ERR_MALLOC; } returnSpiImpl->base.base.getClass = GetMbedtlsRandClass; diff --git a/plugin/openssl_plugin/common/src/dh_openssl_common.c b/plugin/openssl_plugin/common/src/dh_openssl_common.c index c9c4ed65fef5ea72607bd50203bd2314520921c9..44fdf4887ebecf63e0b6b3b4bb3aea1cddd367ee 100644 --- a/plugin/openssl_plugin/common/src/dh_openssl_common.c +++ b/plugin/openssl_plugin/common/src/dh_openssl_common.c @@ -81,25 +81,25 @@ static const NidNameByPLen NID_NAME_PLEN_MAP[] = { EVP_PKEY *NewEvpPkeyByDh(DH *dh, bool withDuplicate) { if (dh == NULL) { - LOGE("DH is NULL"); + LOGE_ONE_STR("DH is NULL"); return NULL; } EVP_PKEY *pKey = OpensslEvpPkeyNew(); if (pKey == NULL) { - LOGD("[error] EVP_PKEY_new fail"); + LOGD_ONE_STR("[error] EVP_PKEY_new fail"); HcfPrintOpensslError(); return NULL; } if (withDuplicate) { if (OpensslEvpPkeySet1Dh(pKey, dh) != HCF_OPENSSL_SUCCESS) { - LOGD("[error] EVP_PKEY_set1_DH fail"); + LOGD_ONE_STR("[error] EVP_PKEY_set1_DH fail"); HcfPrintOpensslError(); OpensslEvpPkeyFree(pKey); return NULL; } } else { if (OpensslEvpPkeyAssignDh(pKey, dh) != HCF_OPENSSL_SUCCESS) { - LOGD("[error] EVP_PKEY_assign_DH fail"); + LOGD_ONE_STR("[error] EVP_PKEY_assign_DH fail"); HcfPrintOpensslError(); OpensslEvpPkeyFree(pKey); return NULL; @@ -111,7 +111,7 @@ EVP_PKEY *NewEvpPkeyByDh(DH *dh, bool withDuplicate) char *GetNidNameByDhId(int32_t pLen) { if (pLen < 0) { - LOGE("Invalid pLen"); + LOGE_ONE_STR("Invalid pLen"); return NULL; } for (uint32_t i = 0; i < sizeof(NID_NAME_BY_TYPE_MAP) / sizeof(NID_NAME_BY_TYPE_MAP[0]); i++) { @@ -126,7 +126,7 @@ char *GetNidNameByDhId(int32_t pLen) char *GetNidNameByDhPLen(int32_t pLen) { if (pLen < 0) { - LOGE("Invalid pLen"); + LOGE_ONE_STR("Invalid pLen"); return NULL; } for (uint32_t i = 0; i < sizeof(NID_NAME_PLEN_MAP) / sizeof(NID_NAME_PLEN_MAP[0]); i++) { diff --git a/plugin/openssl_plugin/common/src/ecc_openssl_common.c b/plugin/openssl_plugin/common/src/ecc_openssl_common.c index 3711721c8e7fd233d791b6145a3d6c18dc2af085..e40458d96835043b2fa8ffc76f2483eb07355f29 100644 --- a/plugin/openssl_plugin/common/src/ecc_openssl_common.c +++ b/plugin/openssl_plugin/common/src/ecc_openssl_common.c @@ -25,16 +25,16 @@ HcfResult NewEcKeyPair(int32_t curveId, EC_KEY **returnEcKey) { EC_KEY *ecKey = OpensslEcKeyNewByCurveName(curveId); if (ecKey == NULL) { - LOGD("[error] new ec key failed."); + LOGD_ONE_STR("[error] new ec key failed."); return HCF_ERR_CRYPTO_OPERATION; } if (OpensslEcKeyGenerateKey(ecKey) <= 0) { - LOGD("[error] generate ec key failed."); + LOGD_ONE_STR("[error] generate ec key failed."); OpensslEcKeyFree(ecKey); return HCF_ERR_CRYPTO_OPERATION; } if (OpensslEcKeyCheckKey(ecKey) <= 0) { - LOGD("[error] check key fail."); + LOGD_ONE_STR("[error] check key fail."); OpensslEcKeyFree(ecKey); return HCF_ERR_CRYPTO_OPERATION; } @@ -62,13 +62,13 @@ static HcfResult NewGroupFromCurveGFp(const HcfEccCommParamsSpec *ecParams, EC_G if (BigIntegerToBigNum(&(field->p), &p) != HCF_SUCCESS || BigIntegerToBigNum(&(ecParams->a), &a) != HCF_SUCCESS || BigIntegerToBigNum(&(ecParams->b), &b) != HCF_SUCCESS) { - LOGD("[error] BigInteger to BigNum failed"); + LOGD_ONE_STR("[error] BigInteger to BigNum failed"); ret = HCF_ERR_CRYPTO_OPERATION; break; } group = OpensslEcGroupNewCurveGfp(p, a, b, ctx); if (group == NULL) { - LOGD("[error] Alloc group memory failed."); + LOGD_ONE_STR("[error] Alloc group memory failed."); ret = HCF_ERR_CRYPTO_OPERATION; break; } @@ -94,7 +94,7 @@ static HcfResult SetEcPointToGroup(const HcfEccCommParamsSpec *ecParams, EC_GROU EC_POINT *generator = NULL; BIGNUM *cofactor = OpensslBnNew(); if (cofactor == NULL) { - LOGE("Alloc cofactor memory failed."); + LOGE_ONE_STR("Alloc cofactor memory failed."); return HCF_ERR_MALLOC; } do { @@ -102,25 +102,25 @@ static HcfResult SetEcPointToGroup(const HcfEccCommParamsSpec *ecParams, EC_GROU BigIntegerToBigNum(&(ecParams->g.y), &y) != HCF_SUCCESS || BigIntegerToBigNum(&(ecParams->n), &order) != HCF_SUCCESS || !OpensslBnSetWord(cofactor, (uint32_t)ecParams->h)) { - LOGD("[error] BigInteger to BigNum failed."); + LOGD_ONE_STR("[error] BigInteger to BigNum failed."); ret = HCF_ERR_CRYPTO_OPERATION; break; } generator = OpensslEcPointNew(group); if (generator == NULL) { - LOGE("Alloc group memory failed."); + LOGE_ONE_STR("Alloc group memory failed."); ret = HCF_ERR_CRYPTO_OPERATION; break; } if (!OpensslEcPointSetAffineCoordinatesGfp(group, generator, x, y, ctx)) { - LOGD("[error] OpensslEcPointSetAffineCoordinatesGfp failed."); + LOGD_ONE_STR("[error] OpensslEcPointSetAffineCoordinatesGfp failed."); ret = HCF_ERR_CRYPTO_OPERATION; HcfPrintOpensslError(); break; } if (!OpensslEcGroupSetGenerator(group, generator, order, cofactor)) { - LOGD("[error] OpensslEcGroupSetGenerator failed."); + LOGD_ONE_STR("[error] OpensslEcGroupSetGenerator failed."); ret = HCF_ERR_CRYPTO_OPERATION; HcfPrintOpensslError(); break; @@ -137,18 +137,18 @@ static HcfResult SetEcPointToGroup(const HcfEccCommParamsSpec *ecParams, EC_GROU HcfResult GenerateEcGroupWithParamsSpec(const HcfEccCommParamsSpec *ecParams, EC_GROUP **ecGroup) { if (ecParams == NULL || ecGroup == NULL) { - LOGE("Invalid input parameters."); + LOGE_ONE_STR("Invalid input parameters."); return HCF_INVALID_PARAMS; } EC_GROUP *group = NULL; BN_CTX *ctx = OpensslBnCtxNew(); if (ctx == NULL) { - LOGE("Alloc ctx memory failed."); + LOGE_ONE_STR("Alloc ctx memory failed."); return HCF_ERR_MALLOC; } HcfResult ret = NewGroupFromCurveGFp(ecParams, &group, ctx); if (ret != HCF_SUCCESS) { - LOGD("[error] New Ec group fail"); + LOGD_ONE_STR("[error] New Ec group fail"); OpensslBnCtxFree(ctx); return ret; } @@ -156,7 +156,7 @@ HcfResult GenerateEcGroupWithParamsSpec(const HcfEccCommParamsSpec *ecParams, EC if (ret != HCF_SUCCESS) { OpensslBnCtxFree(ctx); OpensslEcGroupFree(group); - LOGD("[error] Set Ec point fail"); + LOGD_ONE_STR("[error] Set Ec point fail"); return ret; } OpensslBnCtxFree(ctx); @@ -168,19 +168,19 @@ static HcfResult InitEcKeyByPubKey(const HcfPoint *pubKey, EC_KEY *ecKey) { const EC_GROUP *group = OpensslEcKeyGet0Group(ecKey); if (group == NULL) { - LOGD("[error] Not find group from ecKey."); + LOGD_ONE_STR("[error] Not find group from ecKey."); return HCF_ERR_CRYPTO_OPERATION; } EC_POINT *point = OpensslEcPointNew(group); if (point == NULL) { - LOGD("[error] New ec point failed."); + LOGD_ONE_STR("[error] New ec point failed."); return HCF_ERR_CRYPTO_OPERATION; } BIGNUM *pkX = NULL; BIGNUM *pkY = NULL; if (BigIntegerToBigNum(&(pubKey->x), &pkX) != HCF_SUCCESS || BigIntegerToBigNum(&(pubKey->y), &pkY) != HCF_SUCCESS) { - LOGD("[error] BigInteger to BigNum failed."); + LOGD_ONE_STR("[error] BigInteger to BigNum failed."); OpensslEcPointFree(point); OpensslBnFree(pkX); OpensslBnFree(pkY); @@ -194,13 +194,13 @@ static HcfResult InitEcKeyByPubKey(const HcfPoint *pubKey, EC_KEY *ecKey) OpensslBnFree(pkY); if (ret != HCF_OPENSSL_SUCCESS) { - LOGD("[error] OpensslEcPointSetAffineCoordinatesGfp failed."); + LOGD_ONE_STR("[error] OpensslEcPointSetAffineCoordinatesGfp failed."); OpensslEcPointFree(point); return HCF_ERR_CRYPTO_OPERATION; } ret = OpensslEcKeySetPublicKey(ecKey, point); if (ret != HCF_OPENSSL_SUCCESS) { - LOGD("[error] OpensslEcKeySetPublicKey failed."); + LOGD_ONE_STR("[error] OpensslEcKeySetPublicKey failed."); OpensslEcPointFree(point); return HCF_ERR_CRYPTO_OPERATION; } @@ -212,12 +212,12 @@ static HcfResult InitEcKeyByPriKey(const HcfBigInteger *priKey, EC_KEY *ecKey) { BIGNUM *sk = NULL; if (BigIntegerToBigNum(priKey, &sk) != HCF_SUCCESS) { - LOGD("[error] BigInteger to BigNum failed."); + LOGD_ONE_STR("[error] BigInteger to BigNum failed."); return HCF_ERR_CRYPTO_OPERATION; } int32_t ret = (int32_t)OpensslEcKeySetPrivateKey(ecKey, sk); if (ret != HCF_OPENSSL_SUCCESS) { - LOGD("[error] OpensslEcKeySetPrivateKey failed."); + LOGD_ONE_STR("[error] OpensslEcKeySetPrivateKey failed."); OpensslBnClearFree(sk); return HCF_ERR_CRYPTO_OPERATION; } @@ -229,29 +229,29 @@ static HcfResult SetEcPubKeyFromPriKey(const HcfBigInteger *priKey, EC_KEY *ecKe { const EC_GROUP *group = OpensslEcKeyGet0Group(ecKey); if (group == NULL) { - LOGD("[error] Not find group from ecKey."); + LOGD_ONE_STR("[error] Not find group from ecKey."); return HCF_ERR_CRYPTO_OPERATION; } BIGNUM *sk = NULL; if (BigIntegerToBigNum(priKey, &sk) != HCF_SUCCESS) { - LOGD("[error] BigInteger to BigNum failed."); + LOGD_ONE_STR("[error] BigInteger to BigNum failed."); return HCF_ERR_CRYPTO_OPERATION; } HcfResult ret = HCF_SUCCESS; EC_POINT *point = OpensslEcPointNew(group); do { if (point == NULL) { - LOGD("[error] OpensslEcPointNew failed."); + LOGD_ONE_STR("[error] OpensslEcPointNew failed."); ret = HCF_ERR_CRYPTO_OPERATION; break; } if (!OpensslEcPointMul(group, point, sk, NULL, NULL, NULL)) { - LOGD("[error] EC_POINT_mul failed."); + LOGD_ONE_STR("[error] EC_POINT_mul failed."); ret = HCF_ERR_CRYPTO_OPERATION; break; } if (!OpensslEcKeySetPublicKey(ecKey, point)) { - LOGD("[error] OpensslEcKeySetPublicKey failed."); + LOGD_ONE_STR("[error] OpensslEcKeySetPublicKey failed."); ret = HCF_ERR_CRYPTO_OPERATION; } } while (0); @@ -266,20 +266,20 @@ HcfResult SetEcKey(const HcfPoint *pubKey, const HcfBigInteger *priKey, EC_KEY * if (pubKey != NULL) { ret = InitEcKeyByPubKey(pubKey, ecKey); if (ret != HCF_SUCCESS) { - LOGD("[error] InitEcKeyByPubKey failed."); + LOGD_ONE_STR("[error] InitEcKeyByPubKey failed."); return HCF_ERR_CRYPTO_OPERATION; } } if (priKey != NULL) { ret = InitEcKeyByPriKey(priKey, ecKey); if (ret != HCF_SUCCESS) { - LOGD("[error] InitEcKeyByPriKey failed."); + LOGD_ONE_STR("[error] InitEcKeyByPriKey failed."); return HCF_ERR_CRYPTO_OPERATION; } if (pubKey == NULL) { ret = SetEcPubKeyFromPriKey(priKey, ecKey); if (ret != HCF_SUCCESS) { - LOGD("[error] SetEcPubKeyFromPriKey failed."); + LOGD_ONE_STR("[error] SetEcPubKeyFromPriKey failed."); return HCF_ERR_CRYPTO_OPERATION; } } @@ -293,7 +293,7 @@ HcfResult GetCurveGFp(const EC_GROUP *group, const AsyKeySpecItem item, HcfBigIn BIGNUM *a = OpensslBnNew(); BIGNUM *b = OpensslBnNew(); if (p == NULL || a == NULL || b == NULL) { - LOGD("[error] new BN failed."); + LOGD_ONE_STR("[error] new BN failed."); OpensslBnFree(p); OpensslBnFree(a); OpensslBnFree(b); @@ -301,7 +301,7 @@ HcfResult GetCurveGFp(const EC_GROUP *group, const AsyKeySpecItem item, HcfBigIn } if (OpensslEcGroupGetCurveGfp(group, p, a, b, NULL) != HCF_OPENSSL_SUCCESS) { - LOGD("[error] OpensslEcGroupGetCurveGfp failed."); + LOGD_ONE_STR("[error] OpensslEcGroupGetCurveGfp failed."); OpensslBnFree(p); OpensslBnFree(a); OpensslBnFree(b); @@ -328,7 +328,7 @@ HcfResult GetCurveGFp(const EC_GROUP *group, const AsyKeySpecItem item, HcfBigIn ret = BigNumToBigInteger(b, returnBigInteger); break; default: - LOGD("[error] Invalid ecc key big number spec!"); + LOGD_ONE_STR("[error] Invalid ecc key big number spec!"); break; } OpensslBnFree(p); @@ -341,21 +341,21 @@ HcfResult GetGenerator(const EC_GROUP *group, const AsyKeySpecItem item, HcfBigI { const EC_POINT *generator = OpensslEcGroupGet0Generator(group); if (generator == NULL) { - LOGD("[error] OpensslEcGroupGet0Generator failed."); + LOGD_ONE_STR("[error] OpensslEcGroupGet0Generator failed."); return HCF_ERR_CRYPTO_OPERATION; } BIGNUM *gX = OpensslBnNew(); BIGNUM *gY = OpensslBnNew(); if (gX == NULL || gY == NULL) { - LOGD("[error] new BN failed."); + LOGD_ONE_STR("[error] new BN failed."); OpensslBnFree(gX); OpensslBnFree(gY); return HCF_ERR_CRYPTO_OPERATION; } if (OpensslEcPointGetAffineCoordinatesGfp(group, generator, gX, gY, NULL) != HCF_OPENSSL_SUCCESS) { - LOGD("[error] OpensslEcPointGetAffineCoordinatesGfp failed."); + LOGD_ONE_STR("[error] OpensslEcPointGetAffineCoordinatesGfp failed."); OpensslBnFree(gX); OpensslBnFree(gY); return HCF_ERR_CRYPTO_OPERATION; @@ -370,7 +370,7 @@ HcfResult GetGenerator(const EC_GROUP *group, const AsyKeySpecItem item, HcfBigI ret = BigNumToBigInteger(gY, returnBigInteger); break; default: - LOGE("Invalid ecc key big number spec!"); + LOGE_ONE_STR("Invalid ecc key big number spec!"); break; } OpensslBnFree(gX); @@ -382,12 +382,12 @@ HcfResult GetOrder(const EC_GROUP *group, HcfBigInteger *returnBigInteger) { BIGNUM *order = OpensslBnNew(); if (order == NULL) { - LOGD("[error] new BN failed."); + LOGD_ONE_STR("[error] new BN failed."); return HCF_ERR_CRYPTO_OPERATION; } if (OpensslEcGroupGetOrder(group, order, NULL) != HCF_OPENSSL_SUCCESS) { - LOGD("[error] OpensslEcPointGetAffineCoordinatesGfp failed."); + LOGD_ONE_STR("[error] OpensslEcPointGetAffineCoordinatesGfp failed."); OpensslBnFree(order); return HCF_ERR_CRYPTO_OPERATION; } @@ -401,12 +401,12 @@ HcfResult GetCofactor(const EC_GROUP *group, int *returnCofactor) { BIGNUM *cofactor = OpensslBnNew(); if (cofactor == NULL) { - LOGD("[error] new BN failed."); + LOGD_ONE_STR("[error] new BN failed."); return HCF_ERR_CRYPTO_OPERATION; } if (OpensslEcGroupGetCofactor(group, cofactor, NULL) != HCF_OPENSSL_SUCCESS) { - LOGD("[error] OpensslEcPointGetAffineCoordinatesGfp failed."); + LOGD_ONE_STR("[error] OpensslEcPointGetAffineCoordinatesGfp failed."); OpensslBnFree(cofactor); return HCF_ERR_CRYPTO_OPERATION; } @@ -414,7 +414,7 @@ HcfResult GetCofactor(const EC_GROUP *group, int *returnCofactor) *returnCofactor = (int)(OpensslBnGetWord(cofactor)); // cofactor should not be zero. if (*returnCofactor == 0) { - LOGD("[error] OpensslBnGetWord failed."); + LOGD_ONE_STR("[error] OpensslBnGetWord failed."); OpensslBnFree(cofactor); return HCF_ERR_CRYPTO_OPERATION; } @@ -426,7 +426,7 @@ HcfResult GetFieldSize(const EC_GROUP *group, int32_t *fieldSize) { *fieldSize = OpensslEcGroupGetDegree(group); if (*fieldSize == 0) { - LOGD("[error] OpensslEcGroupGetDegree failed."); + LOGD_ONE_STR("[error] OpensslEcGroupGetDegree failed."); return HCF_ERR_CRYPTO_OPERATION; } return HCF_SUCCESS; @@ -442,18 +442,18 @@ HcfResult GetFieldType(const HcfKey *self, const bool isPrivate, char **returnSt } if (fieldType == NULL) { - LOGE("No fieldType in EccPubKey struct."); + LOGE_ONE_STR("No fieldType in EccPubKey struct."); return HCF_INVALID_PARAMS; } size_t len = HcfStrlen(fieldType); if (len == 0) { - LOGE("fieldType is empty!"); + LOGE_ONE_STR("fieldType is empty!"); return HCF_INVALID_PARAMS; } *returnString = (char *)HcfMalloc(len + 1, 0); if (*returnString == NULL) { - LOGE("Alloc returnString memory failed."); + LOGE_ONE_STR("Alloc returnString memory failed."); return HCF_ERR_MALLOC; } (void)memcpy_s(*returnString, len, fieldType, len); @@ -467,14 +467,14 @@ static HcfResult GetPubKeyXOrY(const EC_GROUP *group, const EC_POINT *point, con BIGNUM *pkX = OpensslBnNew(); BIGNUM *pkY = OpensslBnNew(); if (pkX == NULL || pkY == NULL) { - LOGD("[error] new BN failed."); + LOGD_ONE_STR("[error] new BN failed."); OpensslBnFree(pkX); OpensslBnFree(pkY); return HCF_ERR_CRYPTO_OPERATION; } if (OpensslEcPointGetAffineCoordinatesGfp(group, point, pkX, pkY, NULL) != HCF_OPENSSL_SUCCESS) { - LOGD("[error] OpensslEcPointGetAffineCoordinatesGfp failed."); + LOGD_ONE_STR("[error] OpensslEcPointGetAffineCoordinatesGfp failed."); OpensslBnFree(pkX); OpensslBnFree(pkY); return HCF_ERR_CRYPTO_OPERATION; @@ -489,7 +489,7 @@ static HcfResult GetPubKeyXOrY(const EC_GROUP *group, const EC_POINT *point, con ret = BigNumToBigInteger(pkY, returnBigInteger); break; default: - LOGD("[error] Invalid ecc key big number spec!"); + LOGD_ONE_STR("[error] Invalid ecc key big number spec!"); break; } OpensslBnFree(pkX); @@ -503,14 +503,14 @@ HcfResult GetPkSkBigInteger(const HcfKey *self, bool isPrivate, HcfResult ret = HCF_INVALID_PARAMS; if (item == ECC_SK_BN) { if (!isPrivate) { - LOGD("[error] ecc pub key has no private key spec item"); + LOGD_ONE_STR("[error] ecc pub key has no private key spec item"); return ret; } ret = BigNumToBigInteger(OpensslEcKeyGet0PrivateKey(((HcfOpensslEccPriKey *)self)->ecKey), returnBigInteger); } else { if (isPrivate) { - LOGD("[error] ecc pri key cannot get pub key spec item"); + LOGD_ONE_STR("[error] ecc pri key cannot get pub key spec item"); return ret; } ret = GetPubKeyXOrY(OpensslEcKeyGet0Group(((HcfOpensslEccPubKey *)self)->ecKey), diff --git a/plugin/openssl_plugin/common/src/openssl_common.c b/plugin/openssl_plugin/common/src/openssl_common.c index 599792d0a777fe6c24cd095ef4b279581e7123cc..40f4fc4877c34af56e0bc56801fb485529ef87f1 100644 --- a/plugin/openssl_plugin/common/src/openssl_common.c +++ b/plugin/openssl_plugin/common/src/openssl_common.c @@ -137,7 +137,7 @@ static const FormatType FORMAT_TYPE_MAP[] = { HcfResult GetCurveNameByCurveId(int32_t curveId, char **curveName) { if (curveName == NULL) { - LOGE("Invalid curveName"); + LOGE_ONE_STR("Invalid curveName"); return HCF_INVALID_PARAMS; } for (uint32_t i = 0; i < sizeof(CURVE_NAME_MAP) / sizeof(CURVE_NAME_MAP[0]); i++) { @@ -153,7 +153,7 @@ HcfResult GetCurveNameByCurveId(int32_t curveId, char **curveName) HcfResult GetNidByCurveNameValue(int32_t curveNameValue, int32_t *nid) { if (nid == NULL) { - LOGE("Invalid nid"); + LOGE_ONE_STR("Invalid nid"); return HCF_INVALID_PARAMS; } for (uint32_t i = 0; i < sizeof(NID_TYPE_MAP) / sizeof(NID_TYPE_MAP[0]); i++) { @@ -169,7 +169,7 @@ HcfResult GetNidByCurveNameValue(int32_t curveNameValue, int32_t *nid) HcfResult GetGroupNameByNid(int32_t nid, char **groupName) { if (groupName == NULL) { - LOGE("Invalid groupName"); + LOGE_ONE_STR("Invalid groupName"); return HCF_INVALID_PARAMS; } for (uint32_t i = 0; i < sizeof(NID_TYPE_MAP) / sizeof(NID_TYPE_MAP[0]); i++) { @@ -185,7 +185,7 @@ HcfResult GetGroupNameByNid(int32_t nid, char **groupName) HcfResult GetFormatTypeByFormatValue(int32_t formatValue, int32_t *formatType) { if (formatType == NULL) { - LOGE("Invalid formatType"); + LOGE_ONE_STR("Invalid formatType"); return HCF_INVALID_PARAMS; } for (uint32_t i = 0; i < sizeof(FORMAT_TYPE_MAP) / sizeof(FORMAT_TYPE_MAP[0]); i++) { @@ -201,23 +201,23 @@ HcfResult GetFormatTypeByFormatValue(int32_t formatValue, int32_t *formatType) HcfResult GetAlgNameByBits(int32_t keyLen, char **algName) { if (algName == NULL) { - LOGE("Invalid algName"); + LOGE_ONE_STR("Invalid algName"); return HCF_INVALID_PARAMS; } for (uint32_t i = 0; i < sizeof(ALG_NAME_TYPE_MAP) / sizeof(ALG_NAME_TYPE_MAP[0]); i++) { if (ALG_NAME_TYPE_MAP[i].bits == keyLen) { size_t srcAlgNameLen = HcfStrlen(ALG_NAME_TYPE_MAP[i].algName); if (srcAlgNameLen == 0) { - LOGE("algName is empty!"); + LOGE_ONE_STR("algName is empty!"); return HCF_ERR_MALLOC; } *algName = (char *)HcfMalloc(srcAlgNameLen + 1, 0); if (*algName == NULL) { - LOGE("algName malloc failed."); + LOGE_ONE_STR("algName malloc failed."); return HCF_ERR_MALLOC; } if (memcpy_s(*algName, srcAlgNameLen, ALG_NAME_TYPE_MAP[i].algName, srcAlgNameLen) != EOK) { - LOGE("memcpy algName failed."); + LOGE_ONE_STR("memcpy algName failed."); HcfFree(*algName); *algName = NULL; return HCF_ERR_MALLOC; @@ -232,7 +232,7 @@ HcfResult GetAlgNameByBits(int32_t keyLen, char **algName) HcfResult GetOpensslCurveId(int32_t keyLen, int32_t *returnCurveId) { if (returnCurveId == NULL) { - LOGE("Invalid algName"); + LOGE_ONE_STR("Invalid algName"); return HCF_INVALID_PARAMS; } for (uint32_t i = 0; i < sizeof(NID_TYPE_MAP) / sizeof(NID_TYPE_MAP[0]); i++) { @@ -248,7 +248,7 @@ HcfResult GetOpensslCurveId(int32_t keyLen, int32_t *returnCurveId) HcfResult GetOpensslDigestAlg(uint32_t alg, EVP_MD **digestAlg) { if (digestAlg == NULL) { - LOGE("Invalid MD pointer"); + LOGE_ONE_STR("Invalid MD pointer"); return HCF_INVALID_PARAMS; } switch (alg) { @@ -277,7 +277,7 @@ HcfResult GetOpensslDigestAlg(uint32_t alg, EVP_MD **digestAlg) *digestAlg = (EVP_MD *)EVP_sha512(); break; default: - LOGD("[error] Invalid digest num is %u.", alg); + LOGD("[error] Invalid digest num is %u.", alg); return HCF_INVALID_PARAMS; } return HCF_SUCCESS; @@ -286,7 +286,7 @@ HcfResult GetOpensslDigestAlg(uint32_t alg, EVP_MD **digestAlg) HcfResult GetRsaSpecStringMd(const HcfAlgParaValue md, char **returnString) { if (returnString == NULL) { - LOGE("return string is null"); + LOGE_ONE_STR("return string is null"); return HCF_INVALID_PARAMS; } char *tmp = NULL; @@ -318,12 +318,12 @@ HcfResult GetRsaSpecStringMd(const HcfAlgParaValue md, char **returnString) } size_t mdLen = HcfStrlen(tmp); if (mdLen == 0) { - LOGE("mdLen is empty!"); + LOGE_ONE_STR("mdLen is empty!"); return HCF_ERR_MALLOC; } char *mdStr = (char *)HcfMalloc(mdLen + 1, 0); if (mdStr == NULL) { - LOGE("Failed to allocate md name memory"); + LOGE_ONE_STR("Failed to allocate md name memory"); return HCF_ERR_MALLOC; } (void)memcpy_s(mdStr, mdLen, tmp, mdLen); @@ -334,17 +334,17 @@ HcfResult GetRsaSpecStringMd(const HcfAlgParaValue md, char **returnString) HcfResult GetRsaSpecStringMGF(char **returnString) { if (returnString == NULL) { - LOGE("return string is null"); + LOGE_ONE_STR("return string is null"); return HCF_INVALID_PARAMS; } size_t mgf1Len = HcfStrlen(HCF_OPENSSL_MGF1); if (mgf1Len == 0) { - LOGE("mgf1Len is empty!"); + LOGE_ONE_STR("mgf1Len is empty!"); return HCF_ERR_MALLOC; } char *mgf1Str = (char *)HcfMalloc(mgf1Len + 1, 0); if (mgf1Str == NULL) { - LOGE("Failed to allocate mgf1 name memory"); + LOGE_ONE_STR("Failed to allocate mgf1 name memory"); return HCF_ERR_MALLOC; } (void)memcpy_s(mgf1Str, mgf1Len, HCF_OPENSSL_MGF1, mgf1Len); @@ -355,21 +355,21 @@ HcfResult GetRsaSpecStringMGF(char **returnString) HcfResult GetSm2SpecStringSm3(char **returnString) { if (returnString == NULL) { - LOGE("return string is null"); + LOGE_ONE_STR("return string is null"); return HCF_INVALID_PARAMS; } size_t sm2Len = HcfStrlen(HCF_OPENSSL_DIGEST_SM3_STR); if (sm2Len == 0) { - LOGE("sm2Len is empty!"); + LOGE_ONE_STR("sm2Len is empty!"); return HCF_ERR_MALLOC; } char *sm2Str = (char *)HcfMalloc(sm2Len + 1, 0); if (sm2Str == NULL) { - LOGE("Failed to allocate sm2 name memory"); + LOGE_ONE_STR("Failed to allocate sm2 name memory"); return HCF_ERR_MALLOC; } if (memcpy_s(sm2Str, sm2Len, HCF_OPENSSL_DIGEST_SM3_STR, sm2Len) != EOK) { - LOGE("memcpy sm2Str failed."); + LOGE_ONE_STR("memcpy sm2Str failed."); HcfFree(sm2Str); return HCF_ERR_MALLOC; } @@ -391,7 +391,7 @@ void HcfPrintOpensslError(void) HcfResult GetOpensslPadding(int32_t padding, int32_t *opensslPadding) { if (opensslPadding == NULL) { - LOGE("return openssl padding pointer is null"); + LOGE_ONE_STR("return openssl padding pointer is null"); return HCF_INVALID_PARAMS; } switch (padding) { @@ -412,7 +412,7 @@ HcfResult GetOpensslPadding(int32_t padding, int32_t *opensslPadding) return HCF_SUCCESS; default: - LOGD("[error] Invalid framwork padding = %d", padding); + LOGD("[error] Invalid framwork padding = %d", padding); return HCF_INVALID_PARAMS; } } @@ -431,7 +431,7 @@ bool IsBigEndian(void) HcfResult BigIntegerToBigNum(const HcfBigInteger *src, BIGNUM **dest) { if (src == NULL || dest == NULL) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return HCF_INVALID_PARAMS; } @@ -442,7 +442,7 @@ HcfResult BigIntegerToBigNum(const HcfBigInteger *src, BIGNUM **dest) } if (*dest == NULL) { - LOGD("[error] translate BigInteger to BIGNUM failed."); + LOGD_ONE_STR("[error] translate BigInteger to BIGNUM failed."); HcfPrintOpensslError(); return HCF_ERR_CRYPTO_OPERATION; } @@ -452,13 +452,13 @@ HcfResult BigIntegerToBigNum(const HcfBigInteger *src, BIGNUM **dest) HcfResult BigNumToBigIntegerSecp256k1(const BIGNUM *src, HcfBigInteger *dest) { if (src == NULL || dest == NULL) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return HCF_INVALID_PARAMS; } int len = 1; dest->data = (unsigned char *)HcfMalloc(len, 0); if (dest->data == NULL) { - LOGE("Alloc dest->data memeory failed."); + LOGE_ONE_STR("Alloc dest->data memeory failed."); return HCF_ERR_MALLOC; } dest->len = len; @@ -469,19 +469,19 @@ HcfResult BigNumToBigIntegerSecp256k1(const BIGNUM *src, HcfBigInteger *dest) HcfResult BigNumToBigInteger(const BIGNUM *src, HcfBigInteger *dest) { if (src == NULL || dest == NULL) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return HCF_INVALID_PARAMS; } int len = OpensslBnNumBytes(src); if (len <= 0) { - LOGD("[error] Invalid input parameter."); + LOGD_ONE_STR("[error] Invalid input parameter."); HcfPrintOpensslError(); return HCF_ERR_CRYPTO_OPERATION; } dest->data = (unsigned char *)HcfMalloc(len, 0); if (dest->data == NULL) { - LOGE("Alloc dest->data memeory failed."); + LOGE_ONE_STR("Alloc dest->data memeory failed."); return HCF_ERR_MALLOC; } dest->len = len; @@ -494,7 +494,7 @@ HcfResult BigNumToBigInteger(const BIGNUM *src, HcfBigInteger *dest) } if (resLen != len) { - LOGD("[error] translate BIGNUM to BigInteger failed."); + LOGD_ONE_STR("[error] translate BIGNUM to BigInteger failed."); HcfPrintOpensslError(); HcfFree(dest->data); dest->data = NULL; @@ -508,37 +508,37 @@ HcfResult KeyDerive(EVP_PKEY *priKey, EVP_PKEY *pubKey, HcfBlob *returnSecret) { EVP_PKEY_CTX *ctx = OpensslEvpPkeyCtxNew(priKey, NULL); if (ctx == NULL) { - LOGD("[error] EVP_PKEY_CTX_new failed!"); + LOGD_ONE_STR("[error] EVP_PKEY_CTX_new failed!"); HcfPrintOpensslError(); return HCF_ERR_CRYPTO_OPERATION; } HcfResult ret = HCF_ERR_CRYPTO_OPERATION; do { if (OpensslEvpPkeyDeriveInit(ctx) != HCF_OPENSSL_SUCCESS) { - LOGD("[error] Evp key derive init failed!"); + LOGD_ONE_STR("[error] Evp key derive init failed!"); HcfPrintOpensslError(); break; } if (OpensslEvpPkeyDeriveSetPeer(ctx, pubKey) != HCF_OPENSSL_SUCCESS) { - LOGD("[error] Evp key derive set peer failed!"); + LOGD_ONE_STR("[error] Evp key derive set peer failed!"); HcfPrintOpensslError(); break; } size_t maxLen; if (OpensslEvpPkeyDerive(ctx, NULL, &maxLen) != HCF_OPENSSL_SUCCESS) { - LOGD("[error] Evp key derive failed!"); + LOGD_ONE_STR("[error] Evp key derive failed!"); HcfPrintOpensslError(); break; } uint8_t *secretData = (uint8_t *)HcfMalloc(maxLen, 0); if (secretData == NULL) { - LOGE("Failed to allocate secretData memory!"); + LOGE_ONE_STR("Failed to allocate secretData memory!"); ret = HCF_ERR_MALLOC; break; } if (OpensslEvpPkeyDerive(ctx, secretData, &maxLen) != HCF_OPENSSL_SUCCESS) { - LOGD("[error] Evp key derive failed!"); + LOGD_ONE_STR("[error] Evp key derive failed!"); HcfPrintOpensslError(); HcfFree(secretData); break; @@ -556,7 +556,7 @@ HcfResult GetKeyEncodedPem(EVP_PKEY *pkey, const char *outPutStruct, int selecti { OSSL_ENCODER_CTX *ctx = OpensslOsslEncoderCtxNewForPkey(pkey, selection, "PEM", outPutStruct, NULL); if (ctx == NULL) { - LOGE("OSSL_ENCODER_CTX_new_for_pkey failed."); + LOGE_ONE_STR("OSSL_ENCODER_CTX_new_for_pkey failed."); HcfPrintOpensslError(); return HCF_ERR_CRYPTO_OPERATION; } @@ -577,7 +577,7 @@ HcfResult ConvertPubPemStrToKey(EVP_PKEY **pkey, const char *keyType, int select { OSSL_DECODER_CTX *ctx = OpensslOsslDecoderCtxNewForPkey(pkey, "PEM", NULL, keyType, selection, NULL, NULL); if (ctx == NULL) { - LOGE("Failed to init pem public key decoder ctx."); + LOGE_ONE_STR("Failed to init pem public key decoder ctx."); HcfPrintOpensslError(); return HCF_ERR_CRYPTO_OPERATION; } @@ -586,7 +586,7 @@ HcfResult ConvertPubPemStrToKey(EVP_PKEY **pkey, const char *keyType, int select int ret = OpensslOsslDecoderFromData(ctx, &pdata, &pdataLen); OpensslOsslDecoderCtxFree(ctx); if (ret != HCF_OPENSSL_SUCCESS) { - LOGE("Failed to decode public key from pem data."); + LOGE_ONE_STR("Failed to decode public key from pem data."); HcfPrintOpensslError(); return HCF_ERR_CRYPTO_OPERATION; } @@ -595,7 +595,7 @@ HcfResult ConvertPubPemStrToKey(EVP_PKEY **pkey, const char *keyType, int select int PrivateKeyReadNullCb(char *buf, int size, int rwflag, void *userdata) { - LOGE("Failed to read private key from bio."); + LOGE_ONE_STR("Failed to read private key from bio."); return -1; } @@ -603,14 +603,14 @@ HcfResult ConvertPriPemStrToKey(const char *keyStr, EVP_PKEY **pkey, const char { BIO *bio = OpensslBioNew(OpensslBioSMem()); if (bio == NULL) { - LOGE("Failed to init bio."); + LOGE_ONE_STR("Failed to init bio."); HcfPrintOpensslError(); return HCF_ERR_CRYPTO_OPERATION; } if (OpensslBioWrite(bio, keyStr, strlen(keyStr)) <= 0) { OpensslBioFreeAll(bio); - LOGE("Failed to write pem private key to bio"); + LOGE_ONE_STR("Failed to write pem private key to bio"); HcfPrintOpensslError(); return HCF_ERR_CRYPTO_OPERATION; } @@ -618,7 +618,7 @@ HcfResult ConvertPriPemStrToKey(const char *keyStr, EVP_PKEY **pkey, const char EVP_PKEY *pkeyRet = OpensslPemReadBioPrivateKey(bio, pkey, PrivateKeyReadNullCb, NULL); OpensslBioFreeAll(bio); if (pkeyRet == NULL) { - LOGE("Failed to read private key from bio"); + LOGE_ONE_STR("Failed to read private key from bio"); HcfPrintOpensslError(); return HCF_ERR_CRYPTO_OPERATION; } diff --git a/plugin/openssl_plugin/common/src/rsa_openssl_common.c b/plugin/openssl_plugin/common/src/rsa_openssl_common.c index 36291b1720aeacf4ab5157a5b965811e138bc521..27134a8ab1102733379456a9e9062a5e7780380c 100644 --- a/plugin/openssl_plugin/common/src/rsa_openssl_common.c +++ b/plugin/openssl_plugin/common/src/rsa_openssl_common.c @@ -21,7 +21,7 @@ static RSA *DuplicateRsaPriKeyForSpec(const RSA *rsa) { RSA *tmp = OpensslRsaNew(); if (tmp == NULL) { - LOGE("malloc rsa failed"); + LOGE_ONE_STR("malloc rsa failed"); return NULL; } const BIGNUM *n = NULL; @@ -29,7 +29,7 @@ static RSA *DuplicateRsaPriKeyForSpec(const RSA *rsa) const BIGNUM *d = NULL; OpensslRsaGet0Key(rsa, &n, &e, &d); if (n == NULL || e == NULL || d == NULL) { - LOGE("get key attribute fail"); + LOGE_ONE_STR("get key attribute fail"); OpensslRsaFree(tmp); return NULL; } @@ -37,7 +37,7 @@ static RSA *DuplicateRsaPriKeyForSpec(const RSA *rsa) BIGNUM *dupE = OpensslBnDup(e); BIGNUM *dupD = OpensslBnDup(d); if (dupN == NULL || dupE == NULL || dupD == NULL) { - LOGE("Duplicate key attribute fail"); + LOGE_ONE_STR("Duplicate key attribute fail"); OpensslBnFree(dupN); OpensslBnFree(dupE); OpensslBnClearFree(dupD); @@ -45,7 +45,7 @@ static RSA *DuplicateRsaPriKeyForSpec(const RSA *rsa) return NULL; } if (OpensslRsaSet0Key(tmp, dupN, dupE, dupD) != HCF_OPENSSL_SUCCESS) { - LOGE("assign RSA n, e, d failed"); + LOGE_ONE_STR("assign RSA n, e, d failed"); OpensslBnFree(dupN); OpensslBnFree(dupE); OpensslBnClearFree(dupD); @@ -59,7 +59,7 @@ HcfResult DuplicateRsa(RSA *rsa, bool needPrivate, RSA **dupRsa) { RSA *retRSA = NULL; if (rsa == NULL || dupRsa == NULL) { - LOGE("Rsa or dupRsa is NULL."); + LOGE_ONE_STR("Rsa or dupRsa is NULL."); return HCF_INVALID_PARAMS; } if (needPrivate) { @@ -72,7 +72,7 @@ HcfResult DuplicateRsa(RSA *rsa, bool needPrivate, RSA **dupRsa) retRSA = OpensslRsaPublicKeyDup(rsa); } if (retRSA == NULL) { - LOGD("[error] Duplicate RSA fail."); + LOGD_ONE_STR("[error] Duplicate RSA fail."); HcfPrintOpensslError(); return HCF_ERR_CRYPTO_OPERATION; } @@ -83,25 +83,25 @@ HcfResult DuplicateRsa(RSA *rsa, bool needPrivate, RSA **dupRsa) EVP_PKEY *NewEvpPkeyByRsa(RSA *rsa, bool withDuplicate) { if (rsa == NULL) { - LOGE("RSA is NULL"); + LOGE_ONE_STR("RSA is NULL"); return NULL; } EVP_PKEY *pKey = OpensslEvpPkeyNew(); if (pKey == NULL) { - LOGD("[error] EVP_PKEY_new fail"); + LOGD_ONE_STR("[error] EVP_PKEY_new fail"); HcfPrintOpensslError(); return NULL; } if (withDuplicate) { if (OpensslEvpPkeySet1Rsa(pKey, rsa) != HCF_OPENSSL_SUCCESS) { - LOGD("[error] EVP_PKEY_set1_RSA fail"); + LOGD_ONE_STR("[error] EVP_PKEY_set1_RSA fail"); HcfPrintOpensslError(); OpensslEvpPkeyFree(pKey); return NULL; } } else { if (OpensslEvpPkeyAssignRsa(pKey, rsa) != HCF_OPENSSL_SUCCESS) { - LOGD("[error] EVP_PKEY_assign_RSA fail"); + LOGD_ONE_STR("[error] EVP_PKEY_assign_RSA fail"); HcfPrintOpensslError(); OpensslEvpPkeyFree(pKey); return NULL; diff --git a/plugin/openssl_plugin/crypto_operation/cipher/src/cipher_3des_openssl.c b/plugin/openssl_plugin/crypto_operation/cipher/src/cipher_3des_openssl.c index b8c1c458979c72c5946af99b96dcf698eb59776a..f4955b305032d8fe5a0cc96d561fe6c8adc1ed06 100644 --- a/plugin/openssl_plugin/crypto_operation/cipher/src/cipher_3des_openssl.c +++ b/plugin/openssl_plugin/crypto_operation/cipher/src/cipher_3des_openssl.c @@ -72,7 +72,7 @@ static HcfResult InitCipherData(enum HcfCryptoMode opMode, CipherData **cipherDa *cipherData = (CipherData *)HcfMalloc(sizeof(CipherData), 0); if (*cipherData == NULL) { - LOGE("malloc failed."); + LOGE_ONE_STR("malloc failed."); return HCF_ERR_MALLOC; } @@ -80,7 +80,7 @@ static HcfResult InitCipherData(enum HcfCryptoMode opMode, CipherData **cipherDa (*cipherData)->ctx = OpensslEvpCipherCtxNew(); if ((*cipherData)->ctx == NULL) { HcfPrintOpensslError(); - LOGD("[error] Failed to allocate ctx memroy."); + LOGD_ONE_STR("[error] Failed to allocate ctx memroy."); goto clearup; } @@ -95,15 +95,15 @@ static HcfResult EngineCipherInit(HcfCipherGeneratorSpi *self, enum HcfCryptoMod HcfKey *key, HcfParamsSpec *params) { if ((self == NULL) || (key == NULL)) { /* params maybe is null */ - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return HCF_INVALID_PARAMS; } if (!HcfIsClassMatch((const HcfObjectBase *)self, GetDesGeneratorClass())) { - LOGE("Class is not match."); + LOGE_ONE_STR("Class is not match."); return HCF_INVALID_PARAMS; } if (!HcfIsClassMatch((const HcfObjectBase *)key, OPENSSL_SYM_KEY_CLASS)) { - LOGE("Class is not match."); + LOGE_ONE_STR("Class is not match."); return HCF_INVALID_PARAMS; } @@ -112,29 +112,29 @@ static HcfResult EngineCipherInit(HcfCipherGeneratorSpi *self, enum HcfCryptoMod int32_t enc = (opMode == ENCRYPT_MODE) ? 1 : 0; if (keyImpl->keyMaterial.len < DES_SIZE_192) { - LOGE("Init failed, the input key size is smaller than keySize specified in cipher."); + LOGE_ONE_STR("Init failed, the input key size is smaller than keySize specified in cipher."); return HCF_INVALID_PARAMS; } if (InitCipherData(opMode, &(cipherImpl->cipherData)) != HCF_SUCCESS) { - LOGE("InitCipherData failed"); + LOGE_ONE_STR("InitCipherData failed"); return HCF_INVALID_PARAMS; } HcfResult ret = HCF_ERR_CRYPTO_OPERATION; CipherData *data = cipherImpl->cipherData; if (OpensslEvpCipherInit(data->ctx, GetCipherType(cipherImpl), NULL, NULL, enc) != HCF_OPENSSL_SUCCESS) { HcfPrintOpensslError(); - LOGD("[error] Cipher init failed."); + LOGD_ONE_STR("[error] Cipher init failed."); goto clearup; } if (OpensslEvpCipherInit(data->ctx, NULL, keyImpl->keyMaterial.data, GetIv(params), enc) != HCF_OPENSSL_SUCCESS) { HcfPrintOpensslError(); - LOGD("[error] Cipher init key and iv failed."); + LOGD_ONE_STR("[error] Cipher init key and iv failed."); goto clearup; } int32_t padding = (cipherImpl->attr.paddingMode == HCF_ALG_NOPADDING) ? 0 : EVP_PADDING_PKCS7; if (OpensslEvpCipherCtxSetPadding(data->ctx, padding) != HCF_OPENSSL_SUCCESS) { HcfPrintOpensslError(); - LOGD("[error] Set padding failed."); + LOGD_ONE_STR("[error] Set padding failed."); goto clearup; } return HCF_SUCCESS; @@ -151,7 +151,7 @@ static HcfResult AllocateOutput(HcfBlob *input, HcfBlob *output) } output->data = (uint8_t *)HcfMalloc(outLen, 0); if (output->data == NULL) { - LOGE("Malloc output failed."); + LOGE_ONE_STR("Malloc output failed."); return HCF_ERR_MALLOC; } output->len = outLen; @@ -161,23 +161,23 @@ static HcfResult AllocateOutput(HcfBlob *input, HcfBlob *output) static HcfResult EngineUpdate(HcfCipherGeneratorSpi *self, HcfBlob *input, HcfBlob *output) { if ((self == NULL) || (input == NULL) || (output == NULL)) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return HCF_INVALID_PARAMS; } if (!HcfIsClassMatch((const HcfObjectBase *)self, GetDesGeneratorClass())) { - LOGE("Class is not match."); + LOGE_ONE_STR("Class is not match."); return HCF_INVALID_PARAMS; } HcfCipherDesGeneratorSpiOpensslImpl *cipherImpl = (HcfCipherDesGeneratorSpiOpensslImpl *)self; CipherData *data = cipherImpl->cipherData; if (data == NULL) { - LOGE("CipherData is null."); + LOGE_ONE_STR("CipherData is null."); return HCF_INVALID_PARAMS; } HcfResult res = AllocateOutput(input, output); if (res != HCF_SUCCESS) { - LOGE("AllocateOutput failed."); + LOGE_ONE_STR("AllocateOutput failed."); goto clearup; } @@ -185,7 +185,7 @@ static HcfResult EngineUpdate(HcfCipherGeneratorSpi *self, HcfBlob *input, HcfBl input->data, input->len); if (ret != HCF_OPENSSL_SUCCESS) { HcfPrintOpensslError(); - LOGD("[error] Cipher update failed."); + LOGD_ONE_STR("[error] Cipher update failed."); res = HCF_ERR_CRYPTO_OPERATION; goto clearup; } @@ -210,7 +210,7 @@ static HcfResult DesDoFinal(CipherData *data, HcfBlob *input, HcfBlob *output) input->data, input->len); if (ret != HCF_OPENSSL_SUCCESS) { HcfPrintOpensslError(); - LOGD("[error] Cipher update failed."); + LOGD_ONE_STR("[error] Cipher update failed."); return HCF_ERR_CRYPTO_OPERATION; } len += output->len; @@ -218,7 +218,7 @@ static HcfResult DesDoFinal(CipherData *data, HcfBlob *input, HcfBlob *output) ret = OpensslEvpCipherFinalEx(data->ctx, output->data + len, (int *)&output->len); if (ret != HCF_OPENSSL_SUCCESS) { HcfPrintOpensslError(); - LOGD("[error] Cipher final filed."); + LOGD_ONE_STR("[error] Cipher final filed."); return HCF_ERR_CRYPTO_OPERATION; } output->len += len; @@ -228,28 +228,28 @@ static HcfResult DesDoFinal(CipherData *data, HcfBlob *input, HcfBlob *output) static HcfResult EngineDoFinal(HcfCipherGeneratorSpi *self, HcfBlob *input, HcfBlob *output) { if ((self == NULL) || (output == NULL)) { /* input maybe is null */ - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return HCF_INVALID_PARAMS; } if (!HcfIsClassMatch((const HcfObjectBase *)self, GetDesGeneratorClass())) { - LOGE("Class is not match."); + LOGE_ONE_STR("Class is not match."); return HCF_INVALID_PARAMS; } HcfCipherDesGeneratorSpiOpensslImpl *cipherImpl = (HcfCipherDesGeneratorSpiOpensslImpl *)self; CipherData *data = cipherImpl->cipherData; if (data == NULL) { - LOGE("CipherData is null."); + LOGE_ONE_STR("CipherData is null."); return HCF_INVALID_PARAMS; } HcfResult res = AllocateOutput(input, output); if (res != HCF_SUCCESS) { - LOGE("AllocateOutput failed."); + LOGE_ONE_STR("AllocateOutput failed."); goto clearup; } res = DesDoFinal(data, input, output); if (res != HCF_SUCCESS) { - LOGD("[error] DesDoFinal failed."); + LOGD_ONE_STR("[error] DesDoFinal failed."); } clearup: if (res != HCF_SUCCESS) { @@ -267,7 +267,7 @@ static void EngineDesGeneratorDestroy(HcfObjectBase *self) return; } if (!HcfIsClassMatch(self, GetDesGeneratorClass())) { - LOGE("Class is not match."); + LOGE_ONE_STR("Class is not match."); return; } HcfCipherDesGeneratorSpiOpensslImpl *impl = (HcfCipherDesGeneratorSpiOpensslImpl *)self; @@ -302,13 +302,13 @@ static HcfResult SetDesCipherSpecUint8Array(HcfCipherGeneratorSpi *self, CipherS HcfResult HcfCipherDesGeneratorSpiCreate(CipherAttr *attr, HcfCipherGeneratorSpi **generator) { if ((attr == NULL) || (generator == NULL)) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return HCF_INVALID_PARAMS; } HcfCipherDesGeneratorSpiOpensslImpl *returnImpl = (HcfCipherDesGeneratorSpiOpensslImpl *)HcfMalloc( sizeof(HcfCipherDesGeneratorSpiOpensslImpl), 0); if (returnImpl == NULL) { - LOGE("Failed to allocate returnImpl memroy."); + LOGE_ONE_STR("Failed to allocate returnImpl memroy."); return HCF_ERR_MALLOC; } (void)memcpy_s(&returnImpl->attr, sizeof(CipherAttr), attr, sizeof(CipherAttr)); diff --git a/plugin/openssl_plugin/crypto_operation/cipher/src/cipher_aes_openssl.c b/plugin/openssl_plugin/crypto_operation/cipher/src/cipher_aes_openssl.c index d3df53b248469e9e36572236136e5395b3baee44..d2c895a436ea00a325ed53b9a6d5a1945b3d4423 100644 --- a/plugin/openssl_plugin/crypto_operation/cipher/src/cipher_aes_openssl.c +++ b/plugin/openssl_plugin/crypto_operation/cipher/src/cipher_aes_openssl.c @@ -197,15 +197,15 @@ static const EVP_CIPHER *GetCipherType(HcfCipherAesGeneratorSpiOpensslImpl *impl static bool IsGcmParamsValid(HcfGcmParamsSpec *params) { if (params == NULL) { - LOGE("params is null!"); + LOGE_ONE_STR("params is null!"); return false; } if ((params->iv.data == NULL) || (params->iv.len < GCM_IV_MIN_LEN) || (params->iv.len > GCM_IV_MAX_LEN)) { - LOGE("iv is invalid!"); + LOGE_ONE_STR("iv is invalid!"); return false; } if ((params->tag.data == NULL) || (params->tag.len == 0)) { - LOGE("tag is invalid!"); + LOGE_ONE_STR("tag is invalid!"); return false; } return true; @@ -214,19 +214,19 @@ static bool IsGcmParamsValid(HcfGcmParamsSpec *params) static bool IsCcmParamsValid(HcfCcmParamsSpec *params) { if (params == NULL) { - LOGE("params is null!"); + LOGE_ONE_STR("params is null!"); return false; } if ((params->aad.data == NULL) || (params->aad.len == 0) || (params->aad.len > CCM_AAD_MAX_LEN)) { - LOGE("aad is invalid!"); + LOGE_ONE_STR("aad is invalid!"); return false; } if ((params->iv.data == NULL) || (params->iv.len < CCM_IV_MIN_LEN) || (params->iv.len > CCM_IV_MAX_LEN)) { - LOGE("iv is invalid!"); + LOGE_ONE_STR("iv is invalid!"); return false; } if ((params->tag.data == NULL) || (params->tag.len == 0)) { - LOGE("tag is invalid!"); + LOGE_ONE_STR("tag is invalid!"); return false; } return true; @@ -235,11 +235,11 @@ static bool IsCcmParamsValid(HcfCcmParamsSpec *params) static HcfResult IsIvParamsValid(HcfIvParamsSpec *params) { if (params == NULL) { - LOGE("params is null!"); + LOGE_ONE_STR("params is null!"); return HCF_INVALID_PARAMS; } if ((params->iv.data == NULL) || (params->iv.len != CBC_CTR_OFB_CFB_IV_LEN)) { - LOGE("iv is invalid!"); + LOGE_ONE_STR("iv is invalid!"); return HCF_INVALID_PARAMS; } return HCF_SUCCESS; @@ -248,14 +248,14 @@ static HcfResult IsIvParamsValid(HcfIvParamsSpec *params) static HcfResult InitAadAndTagFromGcmParams(enum HcfCryptoMode opMode, HcfGcmParamsSpec *params, CipherData *data) { if (!IsGcmParamsValid(params)) { - LOGE("gcm params is invalid!"); + LOGE_ONE_STR("gcm params is invalid!"); return HCF_INVALID_PARAMS; } if (params->aad.data != NULL && params->aad.len != 0) { data->aad = (uint8_t *)HcfMalloc(params->aad.len, 0); if (data->aad == NULL) { - LOGE("aad malloc failed!"); + LOGE_ONE_STR("aad malloc failed!"); return HCF_ERR_MALLOC; } (void)memcpy_s(data->aad, params->aad.len, params->aad.data, params->aad.len); @@ -274,7 +274,7 @@ static HcfResult InitAadAndTagFromGcmParams(enum HcfCryptoMode opMode, HcfGcmPar if (data->tag == NULL) { HcfFree(data->aad); data->aad = NULL; - LOGE("tag malloc failed!"); + LOGE_ONE_STR("tag malloc failed!"); return HCF_ERR_MALLOC; } (void)memcpy_s(data->tag, params->tag.len, params->tag.data, params->tag.len); @@ -284,13 +284,13 @@ static HcfResult InitAadAndTagFromGcmParams(enum HcfCryptoMode opMode, HcfGcmPar static HcfResult InitAadAndTagFromCcmParams(enum HcfCryptoMode opMode, HcfCcmParamsSpec *params, CipherData *data) { if (!IsCcmParamsValid(params)) { - LOGE("gcm params is invalid!"); + LOGE_ONE_STR("gcm params is invalid!"); return HCF_INVALID_PARAMS; } data->aad = (uint8_t *)HcfMalloc(params->aad.len, 0); if (data->aad == NULL) { - LOGE("aad malloc failed!"); + LOGE_ONE_STR("aad malloc failed!"); return HCF_ERR_MALLOC; } (void)memcpy_s(data->aad, params->aad.len, params->aad.data, params->aad.len); @@ -305,7 +305,7 @@ static HcfResult InitAadAndTagFromCcmParams(enum HcfCryptoMode opMode, HcfCcmPar if (data->tag == NULL) { HcfFree(data->aad); data->aad = NULL; - LOGE("tag malloc failed!"); + LOGE_ONE_STR("tag malloc failed!"); return HCF_ERR_MALLOC; } (void)memcpy_s(data->tag, params->tag.len, params->tag.data, params->tag.len); @@ -318,7 +318,7 @@ static HcfResult InitCipherData(HcfCipherGeneratorSpi *self, enum HcfCryptoMode HcfResult ret = HCF_ERR_MALLOC; *cipherData = (CipherData *)HcfMalloc(sizeof(CipherData), 0); if (*cipherData == NULL) { - LOGE("malloc is failed!"); + LOGE_ONE_STR("malloc is failed!"); return ret; } HcfCipherAesGeneratorSpiOpensslImpl *cipherImpl = (HcfCipherAesGeneratorSpiOpensslImpl *)self; @@ -328,7 +328,7 @@ static HcfResult InitCipherData(HcfCipherGeneratorSpi *self, enum HcfCryptoMode (*cipherData)->ctx = OpensslEvpCipherCtxNew(); if ((*cipherData)->ctx == NULL) { HcfPrintOpensslError(); - LOGD("[error] Failed to allocate ctx memory!"); + LOGD_ONE_STR("[error] Failed to allocate ctx memory!"); goto clearup; } @@ -353,7 +353,7 @@ static HcfResult InitCipherData(HcfCipherGeneratorSpi *self, enum HcfCryptoMode break; } if (ret != HCF_SUCCESS) { - LOGE("gcm or ccm or iv init failed!"); + LOGE_ONE_STR("gcm or ccm or iv init failed!"); goto clearup; } return ret; @@ -371,7 +371,7 @@ static bool SetCipherAttribute(HcfCipherAesGeneratorSpiOpensslImpl *cipherImpl, if (OpensslEvpCipherInit(data->ctx, GetCipherType(cipherImpl, keyImpl), keyImpl->keyMaterial.data, GetIv(params), enc) != HCF_OPENSSL_SUCCESS) { HcfPrintOpensslError(); - LOGD("[error] EVP_CipherInit failed!"); + LOGD_ONE_STR("[error] EVP_CipherInit failed!"); return false; } return true; @@ -379,19 +379,19 @@ static bool SetCipherAttribute(HcfCipherAesGeneratorSpiOpensslImpl *cipherImpl, if (OpensslEvpCipherInit(data->ctx, GetCipherType(cipherImpl, keyImpl), NULL, NULL, enc) != HCF_OPENSSL_SUCCESS) { HcfPrintOpensslError(); - LOGD("[error] EVP_CipherInit failed!"); + LOGD_ONE_STR("[error] EVP_CipherInit failed!"); return false; } if (OpensslEvpCipherCtxCtrl(data->ctx, EVP_CTRL_AEAD_SET_IVLEN, GetIvLen(params), NULL) != HCF_OPENSSL_SUCCESS) { HcfPrintOpensslError(); - LOGD("[error]EVP_Cipher set iv len failed!"); + LOGD_ONE_STR("[error]EVP_Cipher set iv len failed!"); return false; } if (OpensslEvpCipherInit(data->ctx, NULL, keyImpl->keyMaterial.data, GetIv(params), enc) != HCF_OPENSSL_SUCCESS) { HcfPrintOpensslError(); - LOGD("[error]EVP_CipherInit failed!"); + LOGD_ONE_STR("[error]EVP_CipherInit failed!"); return false; } return true; @@ -402,7 +402,7 @@ static HcfResult EngineCipherInit(HcfCipherGeneratorSpi *self, enum HcfCryptoMod { // params spec may be null, do not check if ((self == NULL) || (key == NULL)) { - LOGE("Invalid input parameter!"); + LOGE_ONE_STR("Invalid input parameter!"); return HCF_INVALID_PARAMS; } if ((!HcfIsClassMatch((const HcfObjectBase *)self, GetAesGeneratorClass())) || @@ -414,14 +414,14 @@ static HcfResult EngineCipherInit(HcfCipherGeneratorSpi *self, enum HcfCryptoMod int enc = (opMode == ENCRYPT_MODE) ? 1 : 0; cipherImpl->attr.keySize = keyImpl->keyMaterial.len; if (InitCipherData(self, opMode, params, &(cipherImpl->cipherData)) != HCF_SUCCESS) { - LOGE("InitCipherData failed!"); + LOGE_ONE_STR("InitCipherData failed!"); return HCF_INVALID_PARAMS; } CipherData *data = cipherImpl->cipherData; HcfResult ret = HCF_ERR_CRYPTO_OPERATION; if (!SetCipherAttribute(cipherImpl, keyImpl, enc, params)) { - LOGD("[error]Set cipher attribute failed!"); + LOGD_ONE_STR("[error]Set cipher attribute failed!"); goto clearup; } @@ -429,7 +429,7 @@ static HcfResult EngineCipherInit(HcfCipherGeneratorSpi *self, enum HcfCryptoMod if (OpensslEvpCipherCtxSetPadding(data->ctx, padding) != HCF_OPENSSL_SUCCESS) { HcfPrintOpensslError(); - LOGD("[error]set padding failed!"); + LOGD_ONE_STR("[error]set padding failed!"); goto clearup; } @@ -440,7 +440,7 @@ static HcfResult EngineCipherInit(HcfCipherGeneratorSpi *self, enum HcfCryptoMod if (OpensslEvpCipherCtxCtrl(data->ctx, EVP_CTRL_AEAD_SET_TAG, GetCcmTagLen(params), GetCcmTag(params)) != HCF_OPENSSL_SUCCESS) { HcfPrintOpensslError(); - LOGD("[error]set AuthTag failed!"); + LOGD_ONE_STR("[error]set AuthTag failed!"); goto clearup; } return HCF_SUCCESS; @@ -455,7 +455,7 @@ static HcfResult CommonUpdate(CipherData *data, HcfBlob *input, HcfBlob *output) input->data, input->len); if (ret != HCF_OPENSSL_SUCCESS) { HcfPrintOpensslError(); - LOGD("[error]cipher update failed!"); + LOGD_ONE_STR("[error]cipher update failed!"); return HCF_ERR_CRYPTO_OPERATION; } return HCF_SUCCESS; @@ -466,7 +466,7 @@ static HcfResult AeadUpdate(CipherData *data, HcfAlgParaValue mode, HcfBlob *inp if (mode == HCF_ALG_MODE_CCM) { if (OpensslEvpCipherUpdate(data->ctx, NULL, (int *)&output->len, NULL, input->len) != HCF_OPENSSL_SUCCESS) { HcfPrintOpensslError(); - LOGD("[error]ccm cipher update failed!"); + LOGD_ONE_STR("[error]ccm cipher update failed!"); return HCF_ERR_CRYPTO_OPERATION; } } @@ -474,13 +474,13 @@ static HcfResult AeadUpdate(CipherData *data, HcfAlgParaValue mode, HcfBlob *inp int32_t ret = OpensslEvpCipherUpdate(data->ctx, NULL, (int *)&output->len, data->aad, data->aadLen); if (ret != HCF_OPENSSL_SUCCESS) { HcfPrintOpensslError(); - LOGD("[error]aad cipher update failed!"); + LOGD_ONE_STR("[error]aad cipher update failed!"); return HCF_ERR_CRYPTO_OPERATION; } ret = OpensslEvpCipherUpdate(data->ctx, output->data, (int *)&output->len, input->data, input->len); if (ret != HCF_OPENSSL_SUCCESS) { HcfPrintOpensslError(); - LOGD("[error]gcm cipher update failed!"); + LOGD_ONE_STR("[error]gcm cipher update failed!"); return HCF_ERR_CRYPTO_OPERATION; } return HCF_SUCCESS; @@ -495,7 +495,7 @@ static HcfResult AllocateOutput(HcfBlob *input, HcfBlob *output, bool *isUpdateI } output->data = (uint8_t *)HcfMalloc(outLen, 0); if (output->data == NULL) { - LOGE("malloc output failed!"); + LOGE_ONE_STR("malloc output failed!"); return HCF_ERR_MALLOC; } output->len = outLen; @@ -505,24 +505,24 @@ static HcfResult AllocateOutput(HcfBlob *input, HcfBlob *output, bool *isUpdateI static HcfResult EngineUpdate(HcfCipherGeneratorSpi *self, HcfBlob *input, HcfBlob *output) { if ((self == NULL) || (input == NULL) || (output == NULL)) { - LOGE("Invalid input parameter!"); + LOGE_ONE_STR("Invalid input parameter!"); return HCF_INVALID_PARAMS; } if (!HcfIsClassMatch((const HcfObjectBase *)self, GetAesGeneratorClass())) { - LOGE("Class is not match."); + LOGE_ONE_STR("Class is not match."); return HCF_INVALID_PARAMS; } HcfCipherAesGeneratorSpiOpensslImpl *cipherImpl = (HcfCipherAesGeneratorSpiOpensslImpl *)self; CipherData *data = cipherImpl->cipherData; if (data == NULL) { - LOGE("cipherData is null!"); + LOGE_ONE_STR("cipherData is null!"); return HCF_INVALID_PARAMS; } bool isUpdateInput = false; HcfResult ret = AllocateOutput(input, output, &isUpdateInput); if (ret != HCF_SUCCESS) { - LOGE("AllocateOutput failed!"); + LOGE_ONE_STR("AllocateOutput failed!"); return ret; } @@ -547,21 +547,21 @@ static HcfResult CommonDoFinal(CipherData *data, HcfBlob *input, HcfBlob *output bool isUpdateInput = false; HcfResult res = AllocateOutput(input, output, &isUpdateInput); if (res != HCF_SUCCESS) { - LOGE("AllocateOutput failed!"); + LOGE_ONE_STR("AllocateOutput failed!"); return res; } if (isUpdateInput) { ret = OpensslEvpCipherUpdate(data->ctx, output->data, (int32_t *)&len, input->data, input->len); if (ret != HCF_OPENSSL_SUCCESS) { HcfPrintOpensslError(); - LOGD("[error]EVP_CipherUpdate failed!"); + LOGD_ONE_STR("[error]EVP_CipherUpdate failed!"); return HCF_ERR_CRYPTO_OPERATION; } } ret = OpensslEvpCipherFinalEx(data->ctx, output->data + len, (int *)&output->len); if (ret != HCF_OPENSSL_SUCCESS) { HcfPrintOpensslError(); - LOGD("[error]EVP_CipherFinal_ex failed!"); + LOGD_ONE_STR("[error]EVP_CipherFinal_ex failed!"); return HCF_ERR_CRYPTO_OPERATION; } output->len += len; @@ -578,12 +578,12 @@ static HcfResult AllocateCcmOutput(CipherData *data, HcfBlob *input, HcfBlob *ou uint32_t authTagLen = (data->enc == ENCRYPT_MODE) ? CCM_TAG_SIZE : 0; outLen += authTagLen + AES_BLOCK_SIZE; if (outLen == 0) { - LOGE("output size is invaild!"); + LOGE_ONE_STR("output size is invaild!"); return HCF_INVALID_PARAMS; } output->data = (uint8_t *)HcfMalloc(outLen, 0); if (output->data == NULL) { - LOGE("malloc output failed!"); + LOGE_ONE_STR("malloc output failed!"); return HCF_ERR_MALLOC; } output->len = outLen; @@ -606,7 +606,7 @@ static HcfResult CcmEncryptDoFinal(CipherData *data, HcfBlob *output, uint32_t l int32_t ret = OpensslEvpCipherCtxCtrl(data->ctx, EVP_CTRL_AEAD_GET_TAG, data->tagLen, output->data + len); if (ret != HCF_OPENSSL_SUCCESS) { HcfPrintOpensslError(); - LOGD("[error]get AuthTag failed!"); + LOGD_ONE_STR("[error]get AuthTag failed!"); return HCF_ERR_CRYPTO_OPERATION; } output->len = data->tagLen + len; @@ -619,13 +619,13 @@ static HcfResult CcmDoFinal(CipherData *data, HcfBlob *input, HcfBlob *output) uint32_t len = 0; HcfResult res = AllocateCcmOutput(data, input, output, &isUpdateInput); if (res != HCF_SUCCESS) { - LOGE("AllocateCcmOutput failed!"); + LOGE_ONE_STR("AllocateCcmOutput failed!"); return res; } if (isUpdateInput) { HcfResult result = AeadUpdate(data, HCF_ALG_MODE_CCM, input, output); if (result != HCF_SUCCESS) { - LOGE("AeadUpdate failed!"); + LOGE_ONE_STR("AeadUpdate failed!"); return result; } len = output->len; @@ -642,19 +642,19 @@ static HcfResult CcmDoFinal(CipherData *data, HcfBlob *input, HcfBlob *output) static HcfResult GcmDecryptDoFinal(CipherData *data, HcfBlob *input, HcfBlob *output, uint32_t len) { if (data->tag == NULL) { - LOGE("gcm decrypt has not AuthTag!"); + LOGE_ONE_STR("gcm decrypt has not AuthTag!"); return HCF_INVALID_PARAMS; } int32_t ret = OpensslEvpCipherCtxCtrl(data->ctx, EVP_CTRL_AEAD_SET_TAG, data->tagLen, (void *)data->tag); if (ret != HCF_OPENSSL_SUCCESS) { HcfPrintOpensslError(); - LOGD("[error]gcm decrypt set AuthTag failed!"); + LOGD_ONE_STR("[error]gcm decrypt set AuthTag failed!"); return HCF_ERR_CRYPTO_OPERATION; } ret = OpensslEvpCipherFinalEx(data->ctx, output->data + len, (int *)&output->len); if (ret != HCF_OPENSSL_SUCCESS) { HcfPrintOpensslError(); - LOGD("[error]EVP_CipherFinal_ex failed!"); + LOGD_ONE_STR("[error]EVP_CipherFinal_ex failed!"); return HCF_ERR_CRYPTO_OPERATION; } output->len = output->len + len; @@ -666,7 +666,7 @@ static HcfResult GcmEncryptDoFinal(CipherData *data, HcfBlob *input, HcfBlob *ou int32_t ret = OpensslEvpCipherFinalEx(data->ctx, output->data + len, (int *)&output->len); if (ret != HCF_OPENSSL_SUCCESS) { HcfPrintOpensslError(); - LOGD("[error]EVP_CipherFinal_ex failed!"); + LOGD_ONE_STR("[error]EVP_CipherFinal_ex failed!"); return HCF_ERR_CRYPTO_OPERATION; } output->len += len; @@ -674,7 +674,7 @@ static HcfResult GcmEncryptDoFinal(CipherData *data, HcfBlob *input, HcfBlob *ou output->data + output->len); if (ret != HCF_OPENSSL_SUCCESS) { HcfPrintOpensslError(); - LOGD("[error]get AuthTag failed!"); + LOGD_ONE_STR("[error]get AuthTag failed!"); return HCF_ERR_CRYPTO_OPERATION; } output->len += data->tagLen; @@ -691,12 +691,12 @@ static HcfResult AllocateGcmOutput(CipherData *data, HcfBlob *input, HcfBlob *ou uint32_t authTagLen = (data->enc == ENCRYPT_MODE) ? GCM_TAG_SIZE : 0; outLen += data->updateLen + authTagLen + AES_BLOCK_SIZE; if (outLen == 0) { - LOGE("output size is invaild!"); + LOGE_ONE_STR("output size is invaild!"); return HCF_INVALID_PARAMS; } output->data = (uint8_t *)HcfMalloc(outLen, 0); if (output->data == NULL) { - LOGE("malloc output failed!"); + LOGE_ONE_STR("malloc output failed!"); return HCF_ERR_MALLOC; } output->len = outLen; @@ -709,7 +709,7 @@ static HcfResult GcmDoFinal(CipherData *data, HcfBlob *input, HcfBlob *output) bool isUpdateInput = false; HcfResult res = AllocateGcmOutput(data, input, output, &isUpdateInput); if (res != HCF_SUCCESS) { - LOGE("AllocateGcmOutput failed!"); + LOGE_ONE_STR("AllocateGcmOutput failed!"); return res; } @@ -717,13 +717,13 @@ static HcfResult GcmDoFinal(CipherData *data, HcfBlob *input, HcfBlob *output) if (data->aad != NULL && data->aadLen != 0) { HcfResult result = AeadUpdate(data, HCF_ALG_MODE_GCM, input, output); if (result != HCF_SUCCESS) { - LOGD("[error]AeadUpdate failed!"); + LOGD_ONE_STR("[error]AeadUpdate failed!"); return result; } } else { HcfResult result = CommonUpdate(data, input, output); if (result != HCF_SUCCESS) { - LOGD("[error]No aad update failed!"); + LOGD_ONE_STR("[error]No aad update failed!"); return result; } } @@ -741,11 +741,11 @@ static HcfResult GcmDoFinal(CipherData *data, HcfBlob *input, HcfBlob *output) static HcfResult EngineDoFinal(HcfCipherGeneratorSpi *self, HcfBlob *input, HcfBlob *output) { if ((self == NULL) || (output == NULL)) { /* input maybe is null */ - LOGE("Invalid input parameter!"); + LOGE_ONE_STR("Invalid input parameter!"); return HCF_INVALID_PARAMS; } if (!HcfIsClassMatch((const HcfObjectBase *)self, GetAesGeneratorClass())) { - LOGE("Class is not match."); + LOGE_ONE_STR("Class is not match."); return HCF_INVALID_PARAMS; } HcfResult ret = HCF_ERR_CRYPTO_OPERATION; @@ -753,7 +753,7 @@ static HcfResult EngineDoFinal(HcfCipherGeneratorSpi *self, HcfBlob *input, HcfB CipherData *data = cipherImpl->cipherData; HcfAlgParaValue mode = cipherImpl->attr.mode; if (data == NULL) { - LOGE("cipherData is null!"); + LOGE_ONE_STR("cipherData is null!"); return HCF_INVALID_PARAMS; } @@ -779,7 +779,7 @@ static void EngineAesGeneratorDestroy(HcfObjectBase *self) return; } if (!HcfIsClassMatch(self, GetAesGeneratorClass())) { - LOGE("Class is not match."); + LOGE_ONE_STR("Class is not match."); return; } @@ -815,13 +815,13 @@ static HcfResult SetAesCipherSpecUint8Array(HcfCipherGeneratorSpi *self, CipherS HcfResult HcfCipherAesGeneratorSpiCreate(CipherAttr *attr, HcfCipherGeneratorSpi **generator) { if ((attr == NULL) || (generator == NULL)) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return HCF_INVALID_PARAMS; } HcfCipherAesGeneratorSpiOpensslImpl *returnImpl = (HcfCipherAesGeneratorSpiOpensslImpl *)HcfMalloc( sizeof(HcfCipherAesGeneratorSpiOpensslImpl), 0); if (returnImpl == NULL) { - LOGE("Failed to allocate returnImpl memroy!"); + LOGE_ONE_STR("Failed to allocate returnImpl memroy!"); return HCF_ERR_MALLOC; } (void)memcpy_s(&returnImpl->attr, sizeof(CipherAttr), attr, sizeof(CipherAttr)); diff --git a/plugin/openssl_plugin/crypto_operation/cipher/src/cipher_rsa_openssl.c b/plugin/openssl_plugin/crypto_operation/cipher/src/cipher_rsa_openssl.c index d567d0bc1c303c90dd2e4809e3b6c5dbe7baa22c..9e376aae670726fd1b9a9751b1b42f987e918ba2 100644 --- a/plugin/openssl_plugin/crypto_operation/cipher/src/cipher_rsa_openssl.c +++ b/plugin/openssl_plugin/crypto_operation/cipher/src/cipher_rsa_openssl.c @@ -45,13 +45,13 @@ static HcfResult CheckCipherInitParams(enum HcfCryptoMode opMode, HcfKey *key) switch (opMode) { case ENCRYPT_MODE: if (!HcfIsClassMatch((HcfObjectBase *)key, OPENSSL_RSA_PUBKEY_CLASS)) { - LOGE("Class not match"); + LOGE_ONE_STR("Class not match"); return HCF_INVALID_PARAMS; } break; case DECRYPT_MODE: if (!HcfIsClassMatch((HcfObjectBase *)key, OPENSSL_RSA_PRIKEY_CLASS)) { - LOGE("Class not match"); + LOGE_ONE_STR("Class not match"); return HCF_INVALID_PARAMS; } break; @@ -69,18 +69,18 @@ static HcfResult DuplicateRsaFromKey(HcfKey *key, enum HcfCryptoMode opMode, RSA if (opMode == ENCRYPT_MODE) { ret = DuplicateRsa(((HcfOpensslRsaPubKey *)key)->pk, false, dupRsa); if (ret != HCF_SUCCESS) { - LOGD("[error] dup pub RSA fail."); + LOGD_ONE_STR("[error] dup pub RSA fail."); return ret; } } else if (opMode == DECRYPT_MODE) { // dup will check if rsa is NULL ret = DuplicateRsa(((HcfOpensslRsaPriKey *)key)->sk, true, dupRsa); if (ret != HCF_SUCCESS) { - LOGD("[error] dup pri RSA fail."); + LOGD_ONE_STR("[error] dup pri RSA fail."); return ret; } } else { - LOGD("[error] OpMode not match."); + LOGD_ONE_STR("[error] OpMode not match."); return HCF_INVALID_PARAMS; } return ret; @@ -92,19 +92,19 @@ static HcfResult InitEvpPkeyCtx(HcfCipherRsaGeneratorSpiImpl *impl, HcfKey *key, HcfResult ret = HCF_SUCCESS; ret = DuplicateRsaFromKey(key, opMode, &rsa); if (ret != HCF_SUCCESS) { - LOGD("[error] DuplicateRsaFromKey fail."); + LOGD_ONE_STR("[error] DuplicateRsaFromKey fail."); return ret; } EVP_PKEY *pkey = NewEvpPkeyByRsa(rsa, false); if (pkey == NULL) { - LOGD("[error] NewEvpPkeyByRsa fail"); + LOGD_ONE_STR("[error] NewEvpPkeyByRsa fail"); HcfPrintOpensslError(); OpensslRsaFree(rsa); return HCF_ERR_CRYPTO_OPERATION; } impl->ctx = EVP_PKEY_CTX_new(pkey, NULL); if (impl->ctx == NULL) { - LOGD("[error] EVP_PKEY_CTX_new fail"); + LOGD_ONE_STR("[error] EVP_PKEY_CTX_new fail"); HcfPrintOpensslError(); OpensslEvpPkeyFree(pkey); return HCF_ERR_CRYPTO_OPERATION; @@ -116,7 +116,7 @@ static HcfResult InitEvpPkeyCtx(HcfCipherRsaGeneratorSpiImpl *impl, HcfKey *key, sslRet = OpensslEvpPkeyDecryptInit(impl->ctx); } if (sslRet != HCF_OPENSSL_SUCCESS) { - LOGD("[error] Init EVP_PKEY fail"); + LOGD_ONE_STR("[error] Init EVP_PKEY fail"); HcfPrintOpensslError(); OpensslEvpPkeyFree(pkey); OpensslEvpPkeyCtxFree(impl->ctx); @@ -132,7 +132,7 @@ static HcfResult SetPsourceFromBlob(HcfBlob pSource, EVP_PKEY_CTX *ctx) // If pSource is NULL or len is 0, the pSource will be cleared. if (pSource.data == NULL || pSource.len == 0) { if (OpensslEvpPkeyCtxSet0RsaOaepLabel(ctx, NULL, 0) != HCF_OPENSSL_SUCCESS) { - LOGD("[error] Openssl Set psource fail"); + LOGD_ONE_STR("[error] Openssl Set psource fail"); HcfPrintOpensslError(); return HCF_ERR_CRYPTO_OPERATION; } @@ -140,13 +140,13 @@ static HcfResult SetPsourceFromBlob(HcfBlob pSource, EVP_PKEY_CTX *ctx) // deep copy from pSource uint8_t *opensslPsource = (uint8_t *)HcfMalloc(pSource.len, 0); if (opensslPsource == NULL) { - LOGE("Failed to allocate openssl pSource data memory"); + LOGE_ONE_STR("Failed to allocate openssl pSource data memory"); return HCF_ERR_MALLOC; } (void)memcpy_s(opensslPsource, pSource.len, pSource.data, pSource.len); if (OpensslEvpPkeyCtxSet0RsaOaepLabel(ctx, opensslPsource, pSource.len) != HCF_OPENSSL_SUCCESS) { - LOGD("[error] Openssl Set psource fail"); + LOGD_ONE_STR("[error] Openssl Set psource fail"); HcfPrintOpensslError(); HcfFree(opensslPsource); return HCF_ERR_CRYPTO_OPERATION; @@ -161,7 +161,7 @@ static HcfResult SetDetailParams(HcfCipherRsaGeneratorSpiImpl *impl) int32_t opensslPadding = 0; (void)GetOpensslPadding(attr.paddingMode, &opensslPadding); if (OpensslEvpPkeyCtxSetRsaPadding(impl->ctx, opensslPadding) != HCF_OPENSSL_SUCCESS) { - LOGD("[error] Cipher set padding fail."); + LOGD_ONE_STR("[error] Cipher set padding fail."); HcfPrintOpensslError(); return HCF_ERR_CRYPTO_OPERATION; } @@ -176,7 +176,7 @@ static HcfResult SetDetailParams(HcfCipherRsaGeneratorSpiImpl *impl) // set md and mgf1md if (OpensslEvpPkeyCtxSetRsaOaepMd(impl->ctx, md) != HCF_OPENSSL_SUCCESS || OpensslEvpPkeyCtxSetRsaMgf1Md(impl->ctx, mgf1md) != HCF_OPENSSL_SUCCESS) { - LOGD("[error] Set md or mgf1md fail"); + LOGD_ONE_STR("[error] Set md or mgf1md fail"); HcfPrintOpensslError(); return HCF_ERR_CRYPTO_OPERATION; } @@ -187,7 +187,7 @@ static HcfResult SetDetailParams(HcfCipherRsaGeneratorSpiImpl *impl) // check if clean the pSource when init fail at it. HcfFree(impl->pSource.data); impl->pSource.data = NULL; - LOGD("[error] Set pSource fail, clean the pSource"); + LOGD_ONE_STR("[error] Set pSource fail, clean the pSource"); return ret; } } @@ -200,21 +200,21 @@ static HcfResult SetRsaCipherSpecUint8Array(HcfCipherGeneratorSpi *self, CipherS { // If pSource is NULL or len is 0, the pSource will be cleared. if (self == NULL) { - LOGE("Param is invalid."); + LOGE_ONE_STR("Param is invalid."); return HCF_INVALID_PARAMS; } if (item != OAEP_MGF1_PSRC_UINT8ARR) { - LOGE("Invalid cipher spec item"); + LOGE_ONE_STR("Invalid cipher spec item"); return HCF_INVALID_PARAMS; } if (!HcfIsClassMatch((HcfObjectBase *)self, EngineGetClass())) { - LOGE("Class not match"); + LOGE_ONE_STR("Class not match"); return HCF_INVALID_PARAMS; } HcfCipherRsaGeneratorSpiImpl *impl = (HcfCipherRsaGeneratorSpiImpl *)self; CipherAttr attr = impl->attr; if (attr.paddingMode != HCF_OPENSSL_RSA_PKCS1_OAEP_PADDING) { - LOGE("Psource is not supported."); + LOGE_ONE_STR("Psource is not supported."); return HCF_INVALID_PARAMS; } // if it has pSource from previous set, it should be free at first; @@ -230,7 +230,7 @@ static HcfResult SetRsaCipherSpecUint8Array(HcfCipherGeneratorSpi *self, CipherS // deep copy two pSource, one for impl struct and one for openssl. impl->pSource.data = (uint8_t *)HcfMalloc(pSource.len, 0); if (impl->pSource.data == NULL) { - LOGE("Failed to allocate pSource data memory"); + LOGE_ONE_STR("Failed to allocate pSource data memory"); return HCF_ERR_MALLOC; } (void)memcpy_s(impl->pSource.data, pSource.len, pSource.data, pSource.len); @@ -241,7 +241,7 @@ static HcfResult SetRsaCipherSpecUint8Array(HcfCipherGeneratorSpi *self, CipherS if (impl->initFlag == INITIALIZED) { HcfResult ret = SetPsourceFromBlob(impl->pSource, impl->ctx); if (ret != HCF_SUCCESS) { - LOGE("Set pSource fail"); + LOGE_ONE_STR("Set pSource fail"); HcfFree(impl->pSource.data); impl->pSource.data = NULL; return ret; @@ -253,28 +253,28 @@ static HcfResult SetRsaCipherSpecUint8Array(HcfCipherGeneratorSpi *self, CipherS static HcfResult GetRsaCipherSpecUint8Array(HcfCipherGeneratorSpi *self, CipherSpecItem item, HcfBlob* returnPSource) { if (self == NULL || returnPSource == NULL) { - LOGE("Param is invalid."); + LOGE_ONE_STR("Param is invalid."); return HCF_INVALID_PARAMS; } if (item != OAEP_MGF1_PSRC_UINT8ARR) { - LOGE("Invalid cipher spec item"); + LOGE_ONE_STR("Invalid cipher spec item"); return HCF_INVALID_PARAMS; } if (!HcfIsClassMatch((HcfObjectBase *)self, EngineGetClass())) { - LOGE("Class not match"); + LOGE_ONE_STR("Class not match"); return HCF_INVALID_PARAMS; } HcfCipherRsaGeneratorSpiImpl *impl = (HcfCipherRsaGeneratorSpiImpl *)self; CipherAttr attr = impl->attr; if (attr.paddingMode != HCF_OPENSSL_RSA_PKCS1_OAEP_PADDING) { - LOGE("Psource is not supported."); + LOGE_ONE_STR("Psource is not supported."); return HCF_INVALID_PARAMS; } // use the pSource from struct at first. if (impl->pSource.data != NULL && impl->pSource.len > 0) { uint8_t *pSource = (uint8_t *)HcfMalloc(impl->pSource.len, 0); if (pSource == NULL) { - LOGE("Failed to allocate pSource memory!"); + LOGE_ONE_STR("Failed to allocate pSource memory!"); return HCF_ERR_MALLOC; } (void)memcpy_s(pSource, impl->pSource.len, impl->pSource.data, impl->pSource.len); @@ -290,17 +290,17 @@ static HcfResult GetRsaCipherSpecUint8Array(HcfCipherGeneratorSpi *self, CipherS static HcfResult GetRsaCipherSpecString(HcfCipherGeneratorSpi *self, CipherSpecItem item, char **returnString) { if (self == NULL || returnString == NULL) { - LOGE("Param is invalid."); + LOGE_ONE_STR("Param is invalid."); return HCF_INVALID_PARAMS; } if (!HcfIsClassMatch((HcfObjectBase *)self, EngineGetClass())) { - LOGE("Class not match"); + LOGE_ONE_STR("Class not match"); return HCF_INVALID_PARAMS; } HcfCipherRsaGeneratorSpiImpl *impl = (HcfCipherRsaGeneratorSpiImpl *)self; CipherAttr attr = impl->attr; if (attr.paddingMode != HCF_OPENSSL_RSA_PKCS1_OAEP_PADDING) { - LOGE("cipher spec string is not supported."); + LOGE_ONE_STR("cipher spec string is not supported."); return HCF_INVALID_PARAMS; } HcfResult ret = HCF_INVALID_PARAMS; @@ -316,7 +316,7 @@ static HcfResult GetRsaCipherSpecString(HcfCipherGeneratorSpi *self, CipherSpecI ret = GetRsaSpecStringMd((const HcfAlgParaValue)(attr.mgf1md), returnString); break; default: - LOGE("Invalid input cipher spec"); + LOGE_ONE_STR("Invalid input cipher spec"); return HCF_INVALID_PARAMS; } return ret; @@ -327,34 +327,34 @@ static HcfResult EngineInit(HcfCipherGeneratorSpi *self, enum HcfCryptoMode opMo { (void)params; if (self == NULL || key == NULL) { - LOGE("Param is invalid."); + LOGE_ONE_STR("Param is invalid."); return HCF_INVALID_PARAMS; } if (!HcfIsClassMatch((HcfObjectBase *)self, EngineGetClass())) { - LOGE("Class not match"); + LOGE_ONE_STR("Class not match"); return HCF_INVALID_PARAMS; } HcfCipherRsaGeneratorSpiImpl *impl = (HcfCipherRsaGeneratorSpiImpl *)self; if (impl->initFlag != UNINITIALIZED) { - LOGE("The cipher has been initialize, don't init again."); + LOGE_ONE_STR("The cipher has been initialize, don't init again."); return HCF_INVALID_PARAMS; } // check opMode is matched with Key if (CheckCipherInitParams(opMode, key) != HCF_SUCCESS) { - LOGE("OpMode dismatch with keyType."); + LOGE_ONE_STR("OpMode dismatch with keyType."); return HCF_INVALID_PARAMS; } impl->attr.mode = (int32_t)opMode; if (InitEvpPkeyCtx(impl, key, opMode) != HCF_SUCCESS) { - LOGD("[error] InitEvpPkeyCtx fail"); + LOGD_ONE_STR("[error] InitEvpPkeyCtx fail"); return HCF_ERR_CRYPTO_OPERATION; } if (SetDetailParams(impl) != HCF_SUCCESS) { OpensslEvpPkeyCtxFree(impl->ctx); impl->ctx = NULL; - LOGD("[error] SetDetailParams fail."); + LOGD_ONE_STR("[error] SetDetailParams fail."); return HCF_ERR_CRYPTO_OPERATION; } impl->initFlag = INITIALIZED; @@ -363,7 +363,7 @@ static HcfResult EngineInit(HcfCipherGeneratorSpi *self, enum HcfCryptoMode opMo static HcfResult EngineUpdate(HcfCipherGeneratorSpi *self, HcfBlob *input, HcfBlob *output) { - LOGE("Openssl don't support update"); + LOGE_ONE_STR("Openssl don't support update"); (void)self; (void)input; (void)output; @@ -378,11 +378,11 @@ static HcfResult DoRsaCrypt(EVP_PKEY_CTX *ctx, HcfBlob *input, HcfBlob *output, } else if (mode == DECRYPT_MODE) { ret = OpensslEvpPkeyDecrypt(ctx, output->data, &output->len, input->data, input->len); } else { - LOGE("OpMode is invalid."); + LOGE_ONE_STR("OpMode is invalid."); return HCF_INVALID_PARAMS; } if (ret != HCF_OPENSSL_SUCCESS) { - LOGD("[error] RSA openssl error"); + LOGD_ONE_STR("[error] RSA openssl error"); HcfPrintOpensslError(); return HCF_ERR_CRYPTO_OPERATION; } @@ -392,16 +392,16 @@ static HcfResult DoRsaCrypt(EVP_PKEY_CTX *ctx, HcfBlob *input, HcfBlob *output, static HcfResult EngineDoFinal(HcfCipherGeneratorSpi *self, HcfBlob *input, HcfBlob *output) { if (self == NULL || !HcfIsBlobValid(input) || output == NULL) { - LOGE("Param is invalid."); + LOGE_ONE_STR("Param is invalid."); return HCF_INVALID_PARAMS; } if (!HcfIsClassMatch((HcfObjectBase *)self, EngineGetClass())) { - LOGE("Class not match"); + LOGE_ONE_STR("Class not match"); return HCF_INVALID_PARAMS; } HcfCipherRsaGeneratorSpiImpl *impl = (HcfCipherRsaGeneratorSpiImpl *)self; if (impl->initFlag != INITIALIZED) { - LOGE("RSACipher has not been init"); + LOGE_ONE_STR("RSACipher has not been init"); return HCF_INVALID_PARAMS; } CipherAttr attr = impl->attr; @@ -409,13 +409,13 @@ static HcfResult EngineDoFinal(HcfCipherGeneratorSpi *self, HcfBlob *input, HcfB output->data = NULL; HcfResult ret = DoRsaCrypt(impl->ctx, input, output, attr.mode); if (ret != HCF_SUCCESS) { - LOGD("[error] GetOutLen fail."); + LOGD_ONE_STR("[error] GetOutLen fail."); return HCF_ERR_CRYPTO_OPERATION; } output->data = (uint8_t *)HcfMalloc(sizeof(uint8_t) * output->len, 0); if (output->data == NULL) { - LOGE("failed to allocate memory!"); + LOGE_ONE_STR("failed to allocate memory!"); return HCF_ERR_MALLOC; } ret = DoRsaCrypt(impl->ctx, input, output, attr.mode); @@ -434,7 +434,7 @@ static void EngineDestroySpiImpl(HcfObjectBase *generator) return; } if (!HcfIsClassMatch((HcfObjectBase *)generator, EngineGetClass())) { - LOGE("Class not match"); + LOGE_ONE_STR("Class not match"); return; } HcfCipherRsaGeneratorSpiImpl *impl = (HcfCipherRsaGeneratorSpiImpl *)generator; @@ -459,12 +459,12 @@ static HcfResult CheckRsaCipherParams(CipherAttr *params) return HCF_INVALID_PARAMS; } if (GetOpensslPadding(params->paddingMode, &opensslPadding) != HCF_SUCCESS) { - LOGE("Cipher create without padding mode"); + LOGE_ONE_STR("Cipher create without padding mode"); return HCF_INVALID_PARAMS; } // cannot use pss padding mode in RSA cipher. if (opensslPadding == RSA_PKCS1_PSS_PADDING) { - LOGE("Cipher cannot use PSS mode"); + LOGE_ONE_STR("Cipher cannot use PSS mode"); return HCF_INVALID_PARAMS; } if (params->paddingMode == HCF_OPENSSL_RSA_PKCS1_OAEP_PADDING) { @@ -473,11 +473,11 @@ static HcfResult CheckRsaCipherParams(CipherAttr *params) (void)GetOpensslDigestAlg(params->md, &md); (void)GetOpensslDigestAlg(params->mgf1md, &mgf1md); if (md == NULL) { - LOGE("Use pkcs1_oaep padding, but md is NULL"); + LOGE_ONE_STR("Use pkcs1_oaep padding, but md is NULL"); return HCF_INVALID_PARAMS; } if (mgf1md == NULL) { - LOGE("Use pkcs1_oaep padding, but mgf1md is NULL"); + LOGE_ONE_STR("Use pkcs1_oaep padding, but mgf1md is NULL"); return HCF_INVALID_PARAMS; } } @@ -487,13 +487,13 @@ static HcfResult CheckRsaCipherParams(CipherAttr *params) HcfResult HcfCipherRsaCipherSpiCreate(CipherAttr *params, HcfCipherGeneratorSpi **generator) { if (generator == NULL || params == NULL) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return HCF_INVALID_PARAMS; } HcfCipherRsaGeneratorSpiImpl *returnImpl = (HcfCipherRsaGeneratorSpiImpl *)HcfMalloc( sizeof(HcfCipherRsaGeneratorSpiImpl), 0); if (returnImpl == NULL) { - LOGE("Malloc rsa cipher fail."); + LOGE_ONE_STR("Malloc rsa cipher fail."); return HCF_ERR_MALLOC; } (void)memcpy_s(&returnImpl->attr, sizeof(CipherAttr), params, sizeof(CipherAttr)); diff --git a/plugin/openssl_plugin/crypto_operation/cipher/src/cipher_sm2_crypto_util_openssl.c b/plugin/openssl_plugin/crypto_operation/cipher/src/cipher_sm2_crypto_util_openssl.c index 94d70a89d2c663c2fa38094c5f15604aa2ea1a66..83348d159f2675b9837b35b2033011a0ab508b32 100644 --- a/plugin/openssl_plugin/crypto_operation/cipher/src/cipher_sm2_crypto_util_openssl.c +++ b/plugin/openssl_plugin/crypto_operation/cipher/src/cipher_sm2_crypto_util_openssl.c @@ -26,26 +26,26 @@ static HcfResult BuildSm2Ciphertext(const Sm2CipherTextSpec *spec, struct Sm2CipherTextSt *sm2Text) { if (BigIntegerToBigNum(&(spec->xCoordinate), &(sm2Text->c1X)) != HCF_SUCCESS) { - LOGE("Build x failed."); + LOGE_ONE_STR("Build x failed."); return HCF_ERR_CRYPTO_OPERATION; } if (BigIntegerToBigNum(&(spec->yCoordinate), &(sm2Text->c1Y)) != HCF_SUCCESS) { - LOGE("Build y failed."); + LOGE_ONE_STR("Build y failed."); return HCF_ERR_CRYPTO_OPERATION; } if (sm2Text->c3 == NULL || sm2Text->c2 == NULL) { - LOGE("SM2 openssl [ASN1_OCTET_STRING_new] c3 c2 fail"); + LOGE_ONE_STR("SM2 openssl [ASN1_OCTET_STRING_new] c3 c2 fail"); HcfPrintOpensslError(); return HCF_ERR_CRYPTO_OPERATION; } if (OpensslAsn1OctetStringSet(sm2Text->c3, spec->hashData.data, spec->hashData.len) != HCF_OPENSSL_SUCCESS) { - LOGE("SM2 openssl [ASN1_OCTET_STRING_set] c3 error"); + LOGE_ONE_STR("SM2 openssl [ASN1_OCTET_STRING_set] c3 error"); HcfPrintOpensslError(); return HCF_ERR_CRYPTO_OPERATION; } if (OpensslAsn1OctetStringSet(sm2Text->c2, spec->cipherTextData.data, spec->cipherTextData.len) != HCF_OPENSSL_SUCCESS) { - LOGE("SM2 openssl [ASN1_OCTET_STRING_set] c2 error"); + LOGE_ONE_STR("SM2 openssl [ASN1_OCTET_STRING_set] c2 error"); HcfPrintOpensslError(); return HCF_ERR_CRYPTO_OPERATION; } @@ -56,21 +56,21 @@ HcfResult HcfSm2SpecToAsn1(Sm2CipherTextSpec *spec, HcfBlob *output) { struct Sm2CipherTextSt *sm2Text = OpensslSm2CipherTextNew(); if (sm2Text == NULL) { - LOGE("SM2 openssl [SM2_Ciphertext_new] failed"); + LOGE_ONE_STR("SM2 openssl [SM2_Ciphertext_new] failed"); HcfPrintOpensslError(); return HCF_ERR_CRYPTO_OPERATION; } HcfResult res = BuildSm2Ciphertext(spec, sm2Text); if (res != HCF_SUCCESS) { OpensslSm2CipherTextFree(sm2Text); - LOGE("SM2 build SM2Ciphertext fail"); + LOGE_ONE_STR("SM2 build SM2Ciphertext fail"); return res; } unsigned char *returnData = NULL; int returnDataLen = OpensslI2dSm2CipherText(sm2Text, &returnData); OpensslSm2CipherTextFree(sm2Text); if (returnData == NULL || returnDataLen < 0) { - LOGE("SM2 openssl [i2d_SM2_Ciphertext] error"); + LOGE_ONE_STR("SM2 openssl [i2d_SM2_Ciphertext] error"); HcfPrintOpensslError(); return HCF_ERR_CRYPTO_OPERATION; } @@ -82,34 +82,34 @@ HcfResult HcfSm2SpecToAsn1(Sm2CipherTextSpec *spec, HcfBlob *output) static HcfResult BuildSm2CiphertextSpec(struct Sm2CipherTextSt *sm2Text, Sm2CipherTextSpec *tempSpec) { if (BigNumToBigInteger(sm2Text->c1X, &(tempSpec->xCoordinate)) != HCF_SUCCESS) { - LOGE("BigNumToBigInteger xCoordinate failed."); + LOGE_ONE_STR("BigNumToBigInteger xCoordinate failed."); return HCF_ERR_CRYPTO_OPERATION; } if (BigNumToBigInteger(sm2Text->c1Y, &(tempSpec->yCoordinate)) != HCF_SUCCESS) { - LOGE("BigNumToBigInteger yCoordinate failed."); + LOGE_ONE_STR("BigNumToBigInteger yCoordinate failed."); return HCF_ERR_CRYPTO_OPERATION; } const unsigned char *c2Data = OpensslAsn1StringGet0Data(sm2Text->c2); int c2Len = OpensslAsn1StringLength(sm2Text->c2); if (c2Data == NULL || c2Len <= 0) { - LOGE("SM2 openssl [OpensslAsn1StringGet0Data] error."); + LOGE_ONE_STR("SM2 openssl [OpensslAsn1StringGet0Data] error."); return HCF_ERR_CRYPTO_OPERATION; } const unsigned char *c3Data = OpensslAsn1StringGet0Data(sm2Text->c3); int c3Len = OpensslAsn1StringLength(sm2Text->c3); if (c3Data == NULL || c3Len <= 0) { - LOGE("SM2 openssl [OpensslAsn1StringGet0Data] error."); + LOGE_ONE_STR("SM2 openssl [OpensslAsn1StringGet0Data] error."); return HCF_ERR_CRYPTO_OPERATION; } tempSpec->cipherTextData.data = (unsigned char *)HcfMalloc(c2Len, 0); if (tempSpec->cipherTextData.data == NULL) { - LOGE("Failed to allocate cipherTextData.data memory"); + LOGE_ONE_STR("Failed to allocate cipherTextData.data memory"); return HCF_ERR_MALLOC; } tempSpec->hashData.data = (unsigned char *)HcfMalloc(c3Len, 0); if (tempSpec->hashData.data == NULL) { - LOGE("Failed to allocate hashData.data memory"); + LOGE_ONE_STR("Failed to allocate hashData.data memory"); return HCF_ERR_MALLOC; } (void)memcpy_s(tempSpec->cipherTextData.data, c2Len, c2Data, c2Len); @@ -123,18 +123,18 @@ HcfResult HcfAsn1ToSm2Spec(HcfBlob *input, Sm2CipherTextSpec **returnSpec) { struct Sm2CipherTextSt *sm2Text = OpensslD2iSm2CipherText(input->data, input->len); if (sm2Text == NULL) { - LOGE("SM2 openssl [d2i_SM2_Ciphertext] error"); + LOGE_ONE_STR("SM2 openssl [d2i_SM2_Ciphertext] error"); return HCF_ERR_CRYPTO_OPERATION; } Sm2CipherTextSpec *tempSpec = (Sm2CipherTextSpec *)(HcfMalloc(sizeof(Sm2CipherTextSpec), 0)); if (tempSpec == NULL) { - LOGE("Failed to allocate Sm2CipherTextSpec memory"); + LOGE_ONE_STR("Failed to allocate Sm2CipherTextSpec memory"); OpensslSm2CipherTextFree(sm2Text); return HCF_ERR_MALLOC; } HcfResult res = BuildSm2CiphertextSpec(sm2Text, tempSpec); if (res != HCF_SUCCESS) { - LOGE("SM2 build SM2Ciphertext fail"); + LOGE_ONE_STR("SM2 build SM2Ciphertext fail"); DestroySm2CipherTextSpec(tempSpec); OpensslSm2CipherTextFree(sm2Text); return res; diff --git a/plugin/openssl_plugin/crypto_operation/cipher/src/cipher_sm2_openssl.c b/plugin/openssl_plugin/crypto_operation/cipher/src/cipher_sm2_openssl.c index 17df4882e5d1eeead97c548472a308aacaad80a2..a270b23c6a1d6fde1c82d63b37860413e405413d 100644 --- a/plugin/openssl_plugin/crypto_operation/cipher/src/cipher_sm2_openssl.c +++ b/plugin/openssl_plugin/crypto_operation/cipher/src/cipher_sm2_openssl.c @@ -46,13 +46,13 @@ static HcfResult CheckCipherInitParams(enum HcfCryptoMode opMode, HcfKey *key) switch (opMode) { case ENCRYPT_MODE: if (!HcfIsClassMatch((HcfObjectBase *)key, HCF_OPENSSL_SM2_PUB_KEY_CLASS)) { - LOGE("Class not match"); + LOGE_ONE_STR("Class not match"); return HCF_INVALID_PARAMS; } break; case DECRYPT_MODE: if (!HcfIsClassMatch((HcfObjectBase *)key, HCF_OPENSSL_SM2_PRI_KEY_CLASS)) { - LOGE("Class not match"); + LOGE_ONE_STR("Class not match"); return HCF_INVALID_PARAMS; } break; @@ -72,7 +72,7 @@ static HcfResult InitSm2Key(HcfCipherSm2GeneratorSpiImpl *impl, HcfKey *key, enu // dup will check if ecKey is NULL impl->sm2Key = OpensslEcKeyDup(((HcfOpensslSm2PriKey *)key)->ecKey); } else { - LOGE("OpMode not match."); + LOGE_ONE_STR("OpMode not match."); return HCF_INVALID_PARAMS; } if (impl->sm2Key == NULL) { @@ -85,15 +85,15 @@ static HcfResult InitSm2Key(HcfCipherSm2GeneratorSpiImpl *impl, HcfKey *key, enu static HcfResult GetSm2CipherSpecString(HcfCipherGeneratorSpi *self, CipherSpecItem item, char **returnString) { if (self == NULL || returnString == NULL) { - LOGE("Param is invalid."); + LOGE_ONE_STR("Param is invalid."); return HCF_INVALID_PARAMS; } if (!HcfIsClassMatch((HcfObjectBase *)self, EngineGetClass())) { - LOGE("Class not match"); + LOGE_ONE_STR("Class not match"); return HCF_INVALID_PARAMS; } if (item != SM2_MD_NAME_STR) { - LOGE("Invalid input cipher spec"); + LOGE_ONE_STR("Invalid input cipher spec"); return HCF_INVALID_PARAMS; } // only support sm3 @@ -121,26 +121,26 @@ static HcfResult EngineInit(HcfCipherGeneratorSpi *self, enum HcfCryptoMode opMo { (void)params; if (self == NULL || key == NULL) { - LOGE("Param is invalid."); + LOGE_ONE_STR("Param is invalid."); return HCF_INVALID_PARAMS; } if (!HcfIsClassMatch((HcfObjectBase *)self, self->base.getClass())) { - LOGE("Class not match"); + LOGE_ONE_STR("Class not match"); return HCF_INVALID_PARAMS; } HcfCipherSm2GeneratorSpiImpl *impl = (HcfCipherSm2GeneratorSpiImpl *)self; if (impl->initFlag != UNINITIALIZED) { - LOGE("The cipher has been initialize, don't init again."); + LOGE_ONE_STR("The cipher has been initialize, don't init again."); return HCF_INVALID_PARAMS; } // check opMode is matched with Key if (CheckCipherInitParams(opMode, key) != HCF_SUCCESS) { - LOGE("OpMode dismatch with keyType."); + LOGE_ONE_STR("OpMode dismatch with keyType."); return HCF_INVALID_PARAMS; } impl->attr.mode = (int32_t)opMode; if (InitSm2Key(impl, key, opMode) != HCF_SUCCESS) { - LOGD("[error] InitSm2Key fail"); + LOGD_ONE_STR("[error] InitSm2Key fail"); return HCF_ERR_CRYPTO_OPERATION; } impl->initFlag = INITIALIZED; @@ -149,7 +149,7 @@ static HcfResult EngineInit(HcfCipherGeneratorSpi *self, enum HcfCryptoMode opMo static HcfResult EngineUpdate(HcfCipherGeneratorSpi *self, HcfBlob *input, HcfBlob *output) { - LOGD("[error] Openssl don't support update"); + LOGD_ONE_STR("[error] Openssl don't support update"); (void)self; (void)input; (void)output; @@ -161,18 +161,18 @@ static size_t GetTextLen(HcfCipherSm2GeneratorSpiImpl *impl, HcfBlob *input, int size_t textLen = 0; if (mode == ENCRYPT_MODE) { if (OpensslSm2CipherTextSize(impl->sm2Key, impl->sm2Digest, input->len, &textLen) != HCF_OPENSSL_SUCCESS) { - LOGD("[error] Failed to get ciphertext size!"); + LOGD_ONE_STR("[error] Failed to get ciphertext size!"); HcfPrintOpensslError(); return 0; } } else if (mode == DECRYPT_MODE) { if (OpensslSm2PlainTextSize(input->data, input->len, &textLen) != HCF_OPENSSL_SUCCESS) { - LOGD("[error] Failed to get plaintext size!"); + LOGD_ONE_STR("[error] Failed to get plaintext size!"); HcfPrintOpensslError(); return 0; } } else { - LOGD("[error] invalid ops!"); + LOGD_ONE_STR("[error] invalid ops!"); } return textLen; } @@ -182,7 +182,7 @@ static HcfResult DoSm2EncryptAndDecrypt(HcfCipherSm2GeneratorSpiImpl *impl, HcfB { uint8_t *outputText = (uint8_t *)HcfMalloc(sizeof(uint8_t) * textLen, 0); if (outputText == NULL) { - LOGE("Failed to allocate plaintext memory!"); + LOGE_ONE_STR("Failed to allocate plaintext memory!"); return HCF_ERR_MALLOC; } int32_t ret = HCF_OPENSSL_SUCCESS; @@ -191,12 +191,12 @@ static HcfResult DoSm2EncryptAndDecrypt(HcfCipherSm2GeneratorSpiImpl *impl, HcfB } else if (mode == DECRYPT_MODE) { ret = OpensslOsslSm2Decrypt(impl->sm2Key, impl->sm2Digest, input->data, input->len, outputText, &textLen); } else { - LOGE("OpMode is invalid."); + LOGE_ONE_STR("OpMode is invalid."); HcfFree(outputText); return HCF_INVALID_PARAMS; } if (ret != HCF_OPENSSL_SUCCESS) { - LOGD("[error] SM2 openssl error"); + LOGD_ONE_STR("[error] SM2 openssl error"); HcfFree(outputText); HcfPrintOpensslError(); return HCF_ERR_CRYPTO_OPERATION; @@ -210,7 +210,7 @@ static HcfResult DoSm2Crypt(HcfCipherSm2GeneratorSpiImpl *impl, HcfBlob *input, { size_t textLen = GetTextLen(impl, input, mode); if (textLen == 0) { - LOGD("[error] textLen is 0"); + LOGD_ONE_STR("[error] textLen is 0"); return HCF_ERR_CRYPTO_OPERATION; } if (DoSm2EncryptAndDecrypt(impl, input, output, mode, textLen) != HCF_SUCCESS) { @@ -222,18 +222,18 @@ static HcfResult DoSm2Crypt(HcfCipherSm2GeneratorSpiImpl *impl, HcfBlob *input, static HcfResult EngineDoFinal(HcfCipherGeneratorSpi *self, HcfBlob *input, HcfBlob *output) { if (self == NULL || input == NULL || input->data == NULL || output == NULL) { - LOGE("Param is invalid."); + LOGE_ONE_STR("Param is invalid."); return HCF_INVALID_PARAMS; } if (!HcfIsClassMatch((HcfObjectBase *)self, self->base.getClass())) { - LOGE("Class not match"); + LOGE_ONE_STR("Class not match"); return HCF_INVALID_PARAMS; } HcfCipherSm2GeneratorSpiImpl *impl = (HcfCipherSm2GeneratorSpiImpl *)self; if (impl->initFlag != INITIALIZED) { - LOGE("SM2Cipher has not been init"); + LOGE_ONE_STR("SM2Cipher has not been init"); return HCF_INVALID_PARAMS; } CipherAttr attr = impl->attr; @@ -241,7 +241,7 @@ static HcfResult EngineDoFinal(HcfCipherGeneratorSpi *self, HcfBlob *input, HcfB output->data = NULL; HcfResult ret = DoSm2Crypt(impl, input, output, attr.mode); if (ret != HCF_SUCCESS) { - LOGD("[error] GetOutLen fail."); + LOGD_ONE_STR("[error] GetOutLen fail."); return HCF_ERR_CRYPTO_OPERATION; } return HCF_SUCCESS; @@ -253,7 +253,7 @@ static void EngineDestroySpiImpl(HcfObjectBase *generator) return; } if (!HcfIsClassMatch(generator, generator->getClass())) { - LOGE("Class not match"); + LOGE_ONE_STR("Class not match"); return; } HcfCipherSm2GeneratorSpiImpl *impl = (HcfCipherSm2GeneratorSpiImpl *)generator; @@ -269,13 +269,13 @@ static void EngineDestroySpiImpl(HcfObjectBase *generator) HcfResult HcfCipherSm2CipherSpiCreate(CipherAttr *params, HcfCipherGeneratorSpi **generator) { if (generator == NULL || params == NULL) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return HCF_INVALID_PARAMS; } HcfCipherSm2GeneratorSpiImpl *returnImpl = (HcfCipherSm2GeneratorSpiImpl *)HcfMalloc( sizeof(HcfCipherSm2GeneratorSpiImpl), 0); if (returnImpl == NULL) { - LOGE("Malloc sm2 cipher fail."); + LOGE_ONE_STR("Malloc sm2 cipher fail."); return HCF_ERR_MALLOC; } (void)memcpy_s(&returnImpl->attr, sizeof(CipherAttr), params, sizeof(CipherAttr)); @@ -283,7 +283,7 @@ HcfResult HcfCipherSm2CipherSpiCreate(CipherAttr *params, HcfCipherGeneratorSpi EVP_MD *getMD = NULL; HcfResult ret = GetOpensslDigestAlg(returnImpl->attr.md, &getMD); if (ret != HCF_SUCCESS || getMD == NULL) { - LOGE("get md failed"); + LOGE_ONE_STR("get md failed"); HcfFree(returnImpl); return HCF_INVALID_PARAMS; } @@ -299,6 +299,6 @@ HcfResult HcfCipherSm2CipherSpiCreate(CipherAttr *params, HcfCipherGeneratorSpi returnImpl->super.base.getClass = EngineGetClass; returnImpl->initFlag = UNINITIALIZED; *generator = (HcfCipherGeneratorSpi *)returnImpl; - LOGD("Sm2 Cipher create success."); + LOGD_ONE_STR("Sm2 Cipher create success."); return HCF_SUCCESS; } \ No newline at end of file diff --git a/plugin/openssl_plugin/crypto_operation/cipher/src/cipher_sm4_openssl.c b/plugin/openssl_plugin/crypto_operation/cipher/src/cipher_sm4_openssl.c index 0d3fafd5f0935f99e7f0822a44355f6dd5728700..16fe750442de8c5715e0c24146ecc8c56d566015 100644 --- a/plugin/openssl_plugin/crypto_operation/cipher/src/cipher_sm4_openssl.c +++ b/plugin/openssl_plugin/crypto_operation/cipher/src/cipher_sm4_openssl.c @@ -147,11 +147,11 @@ static const EVP_CIPHER *GetCipherType(HcfCipherSm4GeneratorSpiOpensslImpl *impl static HcfResult IsIvParamsValid(HcfIvParamsSpec *params) { if (params == NULL) { - LOGE("params is null!"); + LOGE_ONE_STR("params is null!"); return HCF_INVALID_PARAMS; } if ((params->iv.data == NULL) || (params->iv.len != CBC_CTR_OFB_CFB_IV_LEN)) { - LOGE("iv is invalid!"); + LOGE_ONE_STR("iv is invalid!"); return HCF_INVALID_PARAMS; } return HCF_SUCCESS; @@ -160,15 +160,15 @@ static HcfResult IsIvParamsValid(HcfIvParamsSpec *params) static bool IsGcmParamsValid(HcfGcmParamsSpec *params) { if (params == NULL) { - LOGE("params is null!"); + LOGE_ONE_STR("params is null!"); return false; } if ((params->iv.data == NULL) || (params->iv.len < GCM_IV_MIN_LEN) || (params->iv.len > GCM_IV_MAX_LEN)) { - LOGE("iv is invalid!"); + LOGE_ONE_STR("iv is invalid!"); return false; } if ((params->tag.data == NULL) || (params->tag.len == 0)) { - LOGE("tag is invalid!"); + LOGE_ONE_STR("tag is invalid!"); return false; } return true; @@ -177,14 +177,14 @@ static bool IsGcmParamsValid(HcfGcmParamsSpec *params) static HcfResult InitAadAndTagFromGcmParams(enum HcfCryptoMode opMode, HcfGcmParamsSpec *params, CipherData *data) { if (!IsGcmParamsValid(params)) { - LOGE("gcm params is invalid!"); + LOGE_ONE_STR("gcm params is invalid!"); return HCF_INVALID_PARAMS; } if (params->aad.data != NULL && params->aad.len != 0) { data->aad = (uint8_t *)HcfMalloc(params->aad.len, 0); if (data->aad == NULL) { - LOGE("aad malloc failed!"); + LOGE_ONE_STR("aad malloc failed!"); return HCF_ERR_MALLOC; } (void)memcpy_s(data->aad, params->aad.len, params->aad.data, params->aad.len); @@ -203,7 +203,7 @@ static HcfResult InitAadAndTagFromGcmParams(enum HcfCryptoMode opMode, HcfGcmPar if (data->tag == NULL) { HcfFree(data->aad); data->aad = NULL; - LOGE("tag malloc failed!"); + LOGE_ONE_STR("tag malloc failed!"); return HCF_ERR_MALLOC; } (void)memcpy_s(data->tag, params->tag.len, params->tag.data, params->tag.len); @@ -216,7 +216,7 @@ static HcfResult InitCipherData(HcfCipherGeneratorSpi* self, enum HcfCryptoMode HcfResult ret = HCF_ERR_MALLOC; *cipherData = (CipherData *)HcfMalloc(sizeof(CipherData), 0); if (*cipherData == NULL) { - LOGE("malloc is failed!"); + LOGE_ONE_STR("malloc is failed!"); return ret; } HcfCipherSm4GeneratorSpiOpensslImpl *cipherImpl = (HcfCipherSm4GeneratorSpiOpensslImpl *)self; @@ -226,7 +226,7 @@ static HcfResult InitCipherData(HcfCipherGeneratorSpi* self, enum HcfCryptoMode (*cipherData)->ctx = OpensslEvpCipherCtxNew(); if ((*cipherData)->ctx == NULL) { HcfPrintOpensslError(); - LOGE("Failed to allocate ctx memory!"); + LOGE_ONE_STR("Failed to allocate ctx memory!"); goto clearup; } @@ -249,7 +249,7 @@ static HcfResult InitCipherData(HcfCipherGeneratorSpi* self, enum HcfCryptoMode break; } if (ret != HCF_SUCCESS) { - LOGE("init cipher data failed!"); + LOGE_ONE_STR("init cipher data failed!"); goto clearup; } return ret; @@ -268,7 +268,7 @@ static HcfResult GetPaddingMode(HcfCipherSm4GeneratorSpiOpensslImpl* cipherImpl) case HCF_ALG_PADDING_PKCS7: return EVP_PADDING_PKCS7; default: - LOGE("No Params!"); + LOGE_ONE_STR("No Params!"); break; } return HCF_SUCCESS; @@ -277,15 +277,15 @@ static HcfResult GetPaddingMode(HcfCipherSm4GeneratorSpiOpensslImpl* cipherImpl) static HcfResult CheckParam(HcfCipherGeneratorSpi* self, enum HcfCryptoMode opMode, HcfKey* key) { if ((self == NULL) || (key == NULL)) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return HCF_INVALID_PARAMS; } if (!HcfIsClassMatch((HcfObjectBase *)self, self->base.getClass())) { - LOGE("Class is not match."); + LOGE_ONE_STR("Class is not match."); return HCF_INVALID_PARAMS; } if (!HcfIsClassMatch((HcfObjectBase *)key, OPENSSL_SYM_KEY_CLASS)) { - LOGE("Class is not match."); + LOGE_ONE_STR("Class is not match."); return HCF_INVALID_PARAMS; } if (opMode != ENCRYPT_MODE && opMode != DECRYPT_MODE) { @@ -294,7 +294,7 @@ static HcfResult CheckParam(HcfCipherGeneratorSpi* self, enum HcfCryptoMode opMo } SymKeyImpl* keyImpl = (SymKeyImpl*)key; if (keyImpl->keyMaterial.len < SM4_SIZE_128) { - LOGE("Init failed, the input key size is smaller than keySize specified in cipher."); + LOGE_ONE_STR("Init failed, the input key size is smaller than keySize specified in cipher."); return HCF_INVALID_PARAMS; } HcfCipherSm4GeneratorSpiOpensslImpl *cipherImpl = (HcfCipherSm4GeneratorSpiOpensslImpl *)self; @@ -318,21 +318,21 @@ static bool SetCipherAttribute(HcfCipherSm4GeneratorSpiOpensslImpl *cipherImpl, const EVP_CIPHER *cipher = GetCipherType(cipherImpl, keyImpl); if (cipher == NULL) { HcfPrintOpensslError(); - LOGE("fetch cipher failed!"); + LOGE_ONE_STR("fetch cipher failed!"); return false; } if (mode != HCF_ALG_MODE_GCM) { if (OpensslEvpCipherInit(data->ctx, cipher, keyImpl->keyMaterial.data, GetIv(params), enc) != HCF_OPENSSL_SUCCESS) { HcfPrintOpensslError(); - LOGE("EVP_CipherInit failed!"); + LOGE_ONE_STR("EVP_CipherInit failed!"); return false; } return true; } if (OpensslEvpCipherInit(data->ctx, cipher, NULL, NULL, enc) != HCF_OPENSSL_SUCCESS) { HcfPrintOpensslError(); - LOGE("EVP_CipherInit failed!"); + LOGE_ONE_STR("EVP_CipherInit failed!"); OpensslEvpCipherFree((EVP_CIPHER *)cipher); return false; } @@ -340,13 +340,13 @@ static bool SetCipherAttribute(HcfCipherSm4GeneratorSpiOpensslImpl *cipherImpl, if (OpensslEvpCipherCtxCtrl(data->ctx, EVP_CTRL_AEAD_SET_IVLEN, GetIvLen(params), NULL) != HCF_OPENSSL_SUCCESS) { HcfPrintOpensslError(); - LOGE("EVP_Cipher set iv len failed!"); + LOGE_ONE_STR("EVP_Cipher set iv len failed!"); return false; } if (OpensslEvpCipherInit(data->ctx, NULL, keyImpl->keyMaterial.data, GetIv(params), enc) != HCF_OPENSSL_SUCCESS) { HcfPrintOpensslError(); - LOGE("EVP_CipherInit failed!"); + LOGE_ONE_STR("EVP_CipherInit failed!"); return false; } return true; @@ -364,18 +364,18 @@ static HcfResult EngineCipherInit(HcfCipherGeneratorSpi* self, enum HcfCryptoMod cipherImpl->attr.keySize = keyImpl->keyMaterial.len; HcfResult res = InitCipherData(self, opMode, params, &(cipherImpl->cipherData)); if (res != HCF_SUCCESS) { - LOGE("InitCipherData failed"); + LOGE_ONE_STR("InitCipherData failed"); return res; } CipherData *data = cipherImpl->cipherData; HcfResult ret = HCF_ERR_CRYPTO_OPERATION; if (!SetCipherAttribute(cipherImpl, keyImpl, enc, params)) { - LOGE("Set cipher attribute failed!"); + LOGE_ONE_STR("Set cipher attribute failed!"); goto clearup; } if (OpensslEvpCipherCtxSetPadding(data->ctx, GetPaddingMode(cipherImpl)) != HCF_OPENSSL_SUCCESS) { HcfPrintOpensslError(); - LOGE("Set padding failed."); + LOGE_ONE_STR("Set padding failed."); goto clearup; } return HCF_SUCCESS; @@ -393,7 +393,7 @@ static HcfResult AllocateOutput(HcfBlob* input, HcfBlob* output, bool *isUpdateI } output->data = (uint8_t*)HcfMalloc(outLen, 0); if (output->data == NULL) { - LOGE("Malloc output failed."); + LOGE_ONE_STR("Malloc output failed."); return HCF_ERR_MALLOC; } output->len = outLen; @@ -406,7 +406,7 @@ static HcfResult CommonUpdate(CipherData *data, HcfBlob *input, HcfBlob *output) input->data, input->len); if (ret != HCF_OPENSSL_SUCCESS) { HcfPrintOpensslError(); - LOGE("cipher update failed!"); + LOGE_ONE_STR("cipher update failed!"); return HCF_ERR_CRYPTO_OPERATION; } return HCF_SUCCESS; @@ -417,13 +417,13 @@ static HcfResult AeadUpdate(CipherData *data, HcfAlgParaValue mode, HcfBlob *inp int32_t ret = OpensslEvpCipherUpdate(data->ctx, NULL, (int *)&output->len, data->aad, data->aadLen); if (ret != HCF_OPENSSL_SUCCESS) { HcfPrintOpensslError(); - LOGE("aad cipher update failed!"); + LOGE_ONE_STR("aad cipher update failed!"); return HCF_ERR_CRYPTO_OPERATION; } ret = OpensslEvpCipherUpdate(data->ctx, output->data, (int *)&output->len, input->data, input->len); if (ret != HCF_OPENSSL_SUCCESS) { HcfPrintOpensslError(); - LOGE("gcm cipher update failed!"); + LOGE_ONE_STR("gcm cipher update failed!"); return HCF_ERR_CRYPTO_OPERATION; } return HCF_SUCCESS; @@ -432,24 +432,24 @@ static HcfResult AeadUpdate(CipherData *data, HcfAlgParaValue mode, HcfBlob *inp static HcfResult EngineUpdate(HcfCipherGeneratorSpi *self, HcfBlob *input, HcfBlob *output) { if ((self == NULL) || (input == NULL) || (output == NULL)) { - LOGE("Invalid input parameter!"); + LOGE_ONE_STR("Invalid input parameter!"); return HCF_INVALID_PARAMS; } if (!HcfIsClassMatch((HcfObjectBase *)self, self->base.getClass())) { - LOGE("Class is not match."); + LOGE_ONE_STR("Class is not match."); return HCF_INVALID_PARAMS; } HcfCipherSm4GeneratorSpiOpensslImpl *cipherImpl = (HcfCipherSm4GeneratorSpiOpensslImpl *)self; CipherData *data = cipherImpl->cipherData; if (data == NULL) { - LOGE("cipherData is null!"); + LOGE_ONE_STR("cipherData is null!"); return HCF_INVALID_PARAMS; } bool isUpdateInput = false; HcfResult ret = AllocateOutput(input, output, &isUpdateInput); if (ret != HCF_SUCCESS) { - LOGE("AllocateOutput failed!"); + LOGE_ONE_STR("AllocateOutput failed!"); return ret; } @@ -477,12 +477,12 @@ static HcfResult AllocateGcmOutput(CipherData *data, HcfBlob *input, HcfBlob *ou uint32_t authTagLen = (data->enc == ENCRYPT_MODE) ? GCM_TAG_SIZE : 0; outLen += data->updateLen + authTagLen + SM4_BLOCK_SIZE; if (outLen == 0) { - LOGE("output size is invaild!"); + LOGE_ONE_STR("output size is invaild!"); return HCF_INVALID_PARAMS; } output->data = (uint8_t *)HcfMalloc(outLen, 0); if (output->data == NULL) { - LOGE("malloc output failed!"); + LOGE_ONE_STR("malloc output failed!"); return HCF_ERR_MALLOC; } output->len = outLen; @@ -492,19 +492,19 @@ static HcfResult AllocateGcmOutput(CipherData *data, HcfBlob *input, HcfBlob *ou static HcfResult GcmDecryptDoFinal(CipherData *data, HcfBlob *input, HcfBlob *output, uint32_t len) { if (data->tag == NULL) { - LOGE("gcm decrypt has not AuthTag!"); + LOGE_ONE_STR("gcm decrypt has not AuthTag!"); return HCF_INVALID_PARAMS; } int32_t ret = OpensslEvpCipherCtxCtrl(data->ctx, EVP_CTRL_AEAD_SET_TAG, data->tagLen, (void *)data->tag); if (ret != HCF_OPENSSL_SUCCESS) { HcfPrintOpensslError(); - LOGE("gcm decrypt set AuthTag failed!"); + LOGE_ONE_STR("gcm decrypt set AuthTag failed!"); return HCF_ERR_CRYPTO_OPERATION; } ret = OpensslEvpCipherFinalEx(data->ctx, output->data + len, (int *)&output->len); if (ret != HCF_OPENSSL_SUCCESS) { HcfPrintOpensslError(); - LOGE("EVP_CipherFinal_ex failed!"); + LOGE_ONE_STR("EVP_CipherFinal_ex failed!"); return HCF_ERR_CRYPTO_OPERATION; } output->len = output->len + len; @@ -516,7 +516,7 @@ static HcfResult GcmEncryptDoFinal(CipherData *data, HcfBlob *input, HcfBlob *ou int32_t ret = OpensslEvpCipherFinalEx(data->ctx, output->data + len, (int *)&output->len); if (ret != HCF_OPENSSL_SUCCESS) { HcfPrintOpensslError(); - LOGE("EVP_CipherFinal_ex failed!"); + LOGE_ONE_STR("EVP_CipherFinal_ex failed!"); return HCF_ERR_CRYPTO_OPERATION; } output->len += len; @@ -524,7 +524,7 @@ static HcfResult GcmEncryptDoFinal(CipherData *data, HcfBlob *input, HcfBlob *ou output->data + output->len); if (ret != HCF_OPENSSL_SUCCESS) { HcfPrintOpensslError(); - LOGE("get AuthTag failed!"); + LOGE_ONE_STR("get AuthTag failed!"); return HCF_ERR_CRYPTO_OPERATION; } output->len += data->tagLen; @@ -537,7 +537,7 @@ static HcfResult GcmDoFinal(CipherData *data, HcfBlob *input, HcfBlob *output) bool isUpdateInput = false; HcfResult res = AllocateGcmOutput(data, input, output, &isUpdateInput); if (res != HCF_SUCCESS) { - LOGE("AllocateGcmOutput failed!"); + LOGE_ONE_STR("AllocateGcmOutput failed!"); return res; } @@ -545,13 +545,13 @@ static HcfResult GcmDoFinal(CipherData *data, HcfBlob *input, HcfBlob *output) if (data->aad != NULL && data->aadLen != 0) { HcfResult result = AeadUpdate(data, HCF_ALG_MODE_GCM, input, output); if (result != HCF_SUCCESS) { - LOGE("AeadUpdate failed!"); + LOGE_ONE_STR("AeadUpdate failed!"); return result; } } else { HcfResult result = CommonUpdate(data, input, output); if (result != HCF_SUCCESS) { - LOGE("No aad update failed!"); + LOGE_ONE_STR("No aad update failed!"); return result; } } @@ -573,7 +573,7 @@ static HcfResult CommonDoFinal(CipherData *data, HcfBlob *input, HcfBlob *output bool isUpdateInput = false; HcfResult res = AllocateOutput(input, output, &isUpdateInput); if (res != HCF_SUCCESS) { - LOGE("AllocateOutput failed!"); + LOGE_ONE_STR("AllocateOutput failed!"); return res; } if (isUpdateInput) { @@ -581,7 +581,7 @@ static HcfResult CommonDoFinal(CipherData *data, HcfBlob *input, HcfBlob *output input->data, input->len); if (ret != HCF_OPENSSL_SUCCESS) { HcfPrintOpensslError(); - LOGE("EVP_CipherUpdate failed!"); + LOGE_ONE_STR("EVP_CipherUpdate failed!"); return HCF_ERR_CRYPTO_OPERATION; } len += output->len; @@ -589,7 +589,7 @@ static HcfResult CommonDoFinal(CipherData *data, HcfBlob *input, HcfBlob *output ret = OpensslEvpCipherFinalEx(data->ctx, output->data + len, (int *)&output->len); if (ret != HCF_OPENSSL_SUCCESS) { HcfPrintOpensslError(); - LOGE("EVP_CipherFinal_ex failed!"); + LOGE_ONE_STR("EVP_CipherFinal_ex failed!"); return HCF_ERR_CRYPTO_OPERATION; } output->len += len; @@ -599,11 +599,11 @@ static HcfResult CommonDoFinal(CipherData *data, HcfBlob *input, HcfBlob *output static HcfResult EngineDoFinal(HcfCipherGeneratorSpi* self, HcfBlob* input, HcfBlob* output) { if ((self == NULL) || (output == NULL)) { /* input maybe is null */ - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return HCF_INVALID_PARAMS; } if (!HcfIsClassMatch((HcfObjectBase*)self, self->base.getClass())) { - LOGE("Class is not match."); + LOGE_ONE_STR("Class is not match."); return HCF_INVALID_PARAMS; } @@ -611,7 +611,7 @@ static HcfResult EngineDoFinal(HcfCipherGeneratorSpi* self, HcfBlob* input, HcfB HcfCipherSm4GeneratorSpiOpensslImpl *cipherImpl = (HcfCipherSm4GeneratorSpiOpensslImpl *)self; CipherData *data = cipherImpl->cipherData; if (data == NULL) { - LOGE("cipherData is null!"); + LOGE_ONE_STR("cipherData is null!"); return HCF_INVALID_PARAMS; } @@ -636,7 +636,7 @@ static void EngineSm4GeneratorDestroy(HcfObjectBase *self) return; } if (!HcfIsClassMatch(self, self->getClass())) { - LOGE("Class is not match."); + LOGE_ONE_STR("Class is not match."); return; } @@ -672,13 +672,13 @@ static HcfResult SetSm4CipherSpecUint8Array(HcfCipherGeneratorSpi *self, CipherS HcfResult HcfCipherSm4GeneratorSpiCreate(CipherAttr *attr, HcfCipherGeneratorSpi **generator) { if (attr == NULL || generator == NULL) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return HCF_INVALID_PARAMS; } HcfCipherSm4GeneratorSpiOpensslImpl *returnImpl = (HcfCipherSm4GeneratorSpiOpensslImpl *)HcfMalloc( sizeof(HcfCipherSm4GeneratorSpiOpensslImpl), 0); if (returnImpl == NULL) { - LOGE("Failed to allocate returnImpl memroy!"); + LOGE_ONE_STR("Failed to allocate returnImpl memroy!"); return HCF_ERR_MALLOC; } (void)memcpy_s(&returnImpl->attr, sizeof(CipherAttr), attr, sizeof(CipherAttr)); diff --git a/plugin/openssl_plugin/crypto_operation/hmac/src/mac_openssl.c b/plugin/openssl_plugin/crypto_operation/hmac/src/mac_openssl.c index 9767baa61e59fc84c0bd9142f72634abb5bb5aeb..30aff49eef7a85bd984418efbe6ab2428b91881a 100644 --- a/plugin/openssl_plugin/crypto_operation/hmac/src/mac_openssl.c +++ b/plugin/openssl_plugin/crypto_operation/hmac/src/mac_openssl.c @@ -55,7 +55,7 @@ static const char *OpensslGetCmacClass(void) static HMAC_CTX *OpensslGetHmacCtx(HcfMacSpi *self) { if (!HcfIsClassMatch((HcfObjectBase *)self, OpensslGetHmacClass())) { - LOGE("Class is not match."); + LOGE_ONE_STR("Class is not match."); return NULL; } return ((HcfHmacSpiImpl *)self)->ctx; @@ -64,7 +64,7 @@ static HMAC_CTX *OpensslGetHmacCtx(HcfMacSpi *self) static EVP_MAC_CTX *OpensslGetCmacCtx(HcfMacSpi *self) { if (!HcfIsClassMatch((HcfObjectBase *)self, OpensslGetCmacClass())) { - LOGE("Class is not match."); + LOGE_ONE_STR("Class is not match."); return NULL; } return ((HcfCmacSpiImpl *)self)->ctx; @@ -93,26 +93,26 @@ static const EVP_MD *OpensslGetHmacAlgoFromString(const char *mdName) static HcfResult OpensslEngineInitHmac(HcfMacSpi *self, const HcfSymKey *key) { if (OpensslGetHmacCtx(self) == NULL) { - LOGD("[error] The CTX is NULL!"); + LOGD_ONE_STR("[error] The CTX is NULL!"); return HCF_ERR_CRYPTO_OPERATION; } if (!HcfIsClassMatch((const HcfObjectBase *)key, OPENSSL_SYM_KEY_CLASS)) { - LOGE("Class is not match."); + LOGE_ONE_STR("Class is not match."); return HCF_INVALID_PARAMS; } if (!HcfIsClassMatch((HcfObjectBase *)self, OpensslGetHmacClass())) { - LOGE("Class is not match."); + LOGE_ONE_STR("Class is not match."); return HCF_INVALID_PARAMS; } HcfBlob keyBlob = ((SymKeyImpl *)key)->keyMaterial; if (!HcfIsBlobValid(&keyBlob)) { - LOGE("Invalid keyMaterial"); + LOGE_ONE_STR("Invalid keyMaterial"); return HCF_INVALID_PARAMS; } const EVP_MD *mdfunc = OpensslGetHmacAlgoFromString(((HcfHmacSpiImpl *)self)->opensslMdName); int32_t ret = OpensslHmacInitEx(OpensslGetHmacCtx(self), keyBlob.data, keyBlob.len, mdfunc, NULL); if (ret != HCF_OPENSSL_SUCCESS) { - LOGD("[error] HMAC_Init_ex return error!"); + LOGD_ONE_STR("[error] HMAC_Init_ex return error!"); HcfPrintOpensslError(); return HCF_ERR_CRYPTO_OPERATION; } @@ -122,11 +122,11 @@ static HcfResult OpensslEngineInitHmac(HcfMacSpi *self, const HcfSymKey *key) static HcfResult OpensslEngineUpdateHmac(HcfMacSpi *self, HcfBlob *input) { if (OpensslGetHmacCtx(self) == NULL) { - LOGD("[error] The CTX is NULL!"); + LOGD_ONE_STR("[error] The CTX is NULL!"); return HCF_ERR_CRYPTO_OPERATION; } if (HMAC_Update(OpensslGetHmacCtx(self), input->data, input->len) != HCF_OPENSSL_SUCCESS) { - LOGD("[error] HMAC_Update return error!"); + LOGD_ONE_STR("[error] HMAC_Update return error!"); HcfPrintOpensslError(); return HCF_ERR_CRYPTO_OPERATION; } @@ -136,20 +136,20 @@ static HcfResult OpensslEngineUpdateHmac(HcfMacSpi *self, HcfBlob *input) static HcfResult OpensslEngineDoFinalHmac(HcfMacSpi *self, HcfBlob *output) { if (OpensslGetHmacCtx(self) == NULL) { - LOGD("[error] The CTX is NULL!"); + LOGD_ONE_STR("[error] The CTX is NULL!"); return HCF_ERR_CRYPTO_OPERATION; } unsigned char outputBuf[EVP_MAX_MD_SIZE]; uint32_t outputLen; int32_t ret = OpensslHmacFinal(OpensslGetHmacCtx(self), outputBuf, &outputLen); if (ret != HCF_OPENSSL_SUCCESS) { - LOGD("[error] HMAC_Final return error!"); + LOGD_ONE_STR("[error] HMAC_Final return error!"); HcfPrintOpensslError(); return HCF_ERR_CRYPTO_OPERATION; } output->data = (uint8_t *)HcfMalloc(outputLen, 0); if (output->data == NULL) { - LOGE("Failed to allocate output->data memory!"); + LOGE_ONE_STR("Failed to allocate output->data memory!"); return HCF_ERR_MALLOC; } (void)memcpy_s(output->data, outputLen, outputBuf, outputLen); @@ -160,7 +160,7 @@ static HcfResult OpensslEngineDoFinalHmac(HcfMacSpi *self, HcfBlob *output) static uint32_t OpensslEngineGetHmacLength(HcfMacSpi *self) { if (OpensslGetHmacCtx(self) == NULL) { - LOGD("[error] The CTX is NULL!"); + LOGD_ONE_STR("[error] The CTX is NULL!"); return HCF_OPENSSL_INVALID_MAC_LEN; } return OpensslHmacSize(OpensslGetHmacCtx(self)); @@ -169,11 +169,11 @@ static uint32_t OpensslEngineGetHmacLength(HcfMacSpi *self) static void OpensslDestroyHmac(HcfObjectBase *self) { if (self == NULL) { - LOGE("Self ptr is NULL"); + LOGE_ONE_STR("Self ptr is NULL"); return; } if (!HcfIsClassMatch(self, OpensslGetHmacClass())) { - LOGE("Class is not match."); + LOGE_ONE_STR("Class is not match."); return; } if (OpensslGetHmacCtx((HcfMacSpi *)self) != NULL) { @@ -185,22 +185,22 @@ static void OpensslDestroyHmac(HcfObjectBase *self) HcfResult OpensslHmacSpiCreate(HcfMacParamsSpec *paramsSpec, HcfMacSpi **spiObj) { if (paramsSpec == NULL || spiObj == NULL) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return HCF_INVALID_PARAMS; } HcfHmacSpiImpl *returnSpiImpl = (HcfHmacSpiImpl *)HcfMalloc(sizeof(HcfHmacSpiImpl), 0); if (returnSpiImpl == NULL) { - LOGE("Failed to allocate returnImpl memory!"); + LOGE_ONE_STR("Failed to allocate returnImpl memory!"); return HCF_ERR_MALLOC; } if (strcpy_s(returnSpiImpl->opensslMdName, HCF_MAX_MD_NAME_LEN, ((HcfHmacParamsSpec *)paramsSpec)->mdName) != EOK) { - LOGE("Failed to copy algoName!"); + LOGE_ONE_STR("Failed to copy algoName!"); HcfFree(returnSpiImpl); return HCF_INVALID_PARAMS; } returnSpiImpl->ctx = OpensslHmacCtxNew(); if (returnSpiImpl->ctx == NULL) { - LOGD("[error] Failed to create ctx!"); + LOGD_ONE_STR("[error] Failed to create ctx!"); HcfFree(returnSpiImpl); return HCF_ERR_CRYPTO_OPERATION; } @@ -219,20 +219,20 @@ static HcfResult OpensslEngineInitCmac(HcfMacSpi *self, const HcfSymKey *key) OSSL_PARAM params[4] = {}; OSSL_PARAM *p = params; if (OpensslGetCmacCtx(self) == NULL) { - LOGD("[error] The CTX is NULL!"); + LOGD_ONE_STR("[error] The CTX is NULL!"); return HCF_ERR_CRYPTO_OPERATION; } if (!HcfIsClassMatch((const HcfObjectBase *)key, OPENSSL_SYM_KEY_CLASS)) { - LOGE("Class is not match."); + LOGE_ONE_STR("Class is not match."); return HCF_INVALID_PARAMS; } if (!HcfIsClassMatch((HcfObjectBase *)self, OpensslGetCmacClass())) { - LOGE("Class is not match."); + LOGE_ONE_STR("Class is not match."); return HCF_INVALID_PARAMS; } HcfBlob keyBlob = ((SymKeyImpl *)key)->keyMaterial; if (!HcfIsBlobValid(&keyBlob)) { - LOGE("Invalid keyMaterial"); + LOGE_ONE_STR("Invalid keyMaterial"); return HCF_INVALID_PARAMS; } *p++ = OpensslOsslParamConstructUtf8String("cipher", ((HcfCmacSpiImpl *)self)->opensslCipherName, @@ -240,7 +240,7 @@ static HcfResult OpensslEngineInitCmac(HcfMacSpi *self, const HcfSymKey *key) *p++ = OpensslOsslParamConstructEnd(); int32_t ret = OpensslCmacInit(OpensslGetCmacCtx(self), keyBlob.data, keyBlob.len, params); if (ret != HCF_OPENSSL_SUCCESS) { - LOGE("CMAC_Init return error!"); + LOGE_ONE_STR("CMAC_Init return error!"); HcfPrintOpensslError(); return HCF_ERR_CRYPTO_OPERATION; } @@ -250,11 +250,11 @@ static HcfResult OpensslEngineInitCmac(HcfMacSpi *self, const HcfSymKey *key) static HcfResult OpensslEngineUpdateCmac(HcfMacSpi *self, HcfBlob *input) { if (OpensslGetCmacCtx(self) == NULL) { - LOGE("The CTX is NULL!"); + LOGE_ONE_STR("The CTX is NULL!"); return HCF_ERR_CRYPTO_OPERATION; } if (OpensslCmacUpdate(OpensslGetCmacCtx(self), input->data, input->len) != HCF_OPENSSL_SUCCESS) { - LOGE("CMAC_Update return error!"); + LOGE_ONE_STR("CMAC_Update return error!"); HcfPrintOpensslError(); return HCF_ERR_CRYPTO_OPERATION; } @@ -264,26 +264,26 @@ static HcfResult OpensslEngineUpdateCmac(HcfMacSpi *self, HcfBlob *input) static HcfResult OpensslEngineDoFinalCmac(HcfMacSpi *self, HcfBlob *output) { if (OpensslGetCmacCtx(self) == NULL) { - LOGE("The CTX is NULL!"); + LOGE_ONE_STR("The CTX is NULL!"); return HCF_ERR_CRYPTO_OPERATION; } size_t outputLen = 0; unsigned char outputBuf[EVP_MAX_MD_SIZE]; int32_t ret = OpensslCmacFinal(OpensslGetCmacCtx(self), NULL, &outputLen, 0); if (ret != HCF_OPENSSL_SUCCESS) { - LOGE("CMAC_Final return error!"); + LOGE_ONE_STR("CMAC_Final return error!"); HcfPrintOpensslError(); return HCF_ERR_CRYPTO_OPERATION; } ret = OpensslCmacFinal(OpensslGetCmacCtx(self), outputBuf, &outputLen, outputLen); if (ret != HCF_OPENSSL_SUCCESS) { - LOGE("CMAC_Final return error!"); + LOGE_ONE_STR("CMAC_Final return error!"); HcfPrintOpensslError(); return HCF_ERR_CRYPTO_OPERATION; } output->data = (uint8_t *)HcfMalloc(outputLen, 0); if (output->data == NULL) { - LOGE("Failed to allocate output->data memory!"); + LOGE_ONE_STR("Failed to allocate output->data memory!"); return HCF_ERR_MALLOC; } (void)memcpy_s(output->data, outputLen, outputBuf, outputLen); @@ -294,7 +294,7 @@ static HcfResult OpensslEngineDoFinalCmac(HcfMacSpi *self, HcfBlob *output) static uint32_t OpensslEngineGetCmacLength(HcfMacSpi *self) { if (OpensslGetCmacCtx(self) == NULL) { - LOGE("The CTX is NULL!"); + LOGE_ONE_STR("The CTX is NULL!"); return HCF_OPENSSL_INVALID_MAC_LEN; } return OpensslCmacSize(OpensslGetCmacCtx(self)); @@ -303,11 +303,11 @@ static uint32_t OpensslEngineGetCmacLength(HcfMacSpi *self) static void OpensslDestroyCmac(HcfObjectBase *self) { if (self == NULL) { - LOGE("Self ptr is NULL"); + LOGE_ONE_STR("Self ptr is NULL"); return; } if (!HcfIsClassMatch(self, OpensslGetCmacClass())) { - LOGE("Class is not match."); + LOGE_ONE_STR("Class is not match."); return; } if (OpensslGetCmacCtx((HcfMacSpi *)self) != NULL) { @@ -319,28 +319,28 @@ static void OpensslDestroyCmac(HcfObjectBase *self) HcfResult OpensslCmacSpiCreate(HcfMacParamsSpec *paramsSpec, HcfMacSpi **spiObj) { if (paramsSpec == NULL || spiObj == NULL) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return HCF_INVALID_PARAMS; } HcfCmacSpiImpl *returnSpiImpl = (HcfCmacSpiImpl *)HcfMalloc(sizeof(HcfCmacSpiImpl), 0); if (returnSpiImpl == NULL) { - LOGE("Failed to allocate returnImpl memory!"); + LOGE_ONE_STR("Failed to allocate returnImpl memory!"); return HCF_ERR_MALLOC; } if (strcpy_s(returnSpiImpl->opensslCipherName, HCF_MAX_CIPHER_NAME_LEN, ((HcfCmacParamsSpec *)paramsSpec)->cipherName) != EOK) { - LOGE("Failed to copy algoName!"); + LOGE_ONE_STR("Failed to copy algoName!"); HcfFree(returnSpiImpl); return HCF_INVALID_PARAMS; } EVP_MAC *mac = EVP_MAC_fetch(NULL, "CMAC", NULL); if (mac == NULL) { - LOGD("fetch failed"); + LOGD_ONE_STR("fetch failed"); return HCF_ERR_CRYPTO_OPERATION; } returnSpiImpl->ctx = EVP_MAC_CTX_new(mac); if (returnSpiImpl->ctx == NULL) { - LOGD("[error] Failed to create ctx!"); + LOGD_ONE_STR("[error] Failed to create ctx!"); HcfFree(returnSpiImpl); return HCF_ERR_CRYPTO_OPERATION; } diff --git a/plugin/openssl_plugin/crypto_operation/kdf/src/hkdf_openssl.c b/plugin/openssl_plugin/crypto_operation/kdf/src/hkdf_openssl.c index 4f3f2b5b4cefa0af15f1f9e1f15d3d1eae69749a..cd28997440be40fc86dd8448fee1f65c9fc1920e 100644 --- a/plugin/openssl_plugin/crypto_operation/kdf/src/hkdf_openssl.c +++ b/plugin/openssl_plugin/crypto_operation/kdf/src/hkdf_openssl.c @@ -77,11 +77,11 @@ static void FreeHkdfData(HcfHkdfData **data) static void EngineDestroyKdf(HcfObjectBase *self) { if (self == NULL) { - LOGE("Self ptr is NULL!"); + LOGE_ONE_STR("Self ptr is NULL!"); return; } if (!HcfIsClassMatch(self, EngineGetKdfClass())) { - LOGE("Class is not match."); + LOGE_ONE_STR("Class is not match."); return; } OpensslHkdfSpiImpl *impl = (OpensslHkdfSpiImpl *)self; @@ -94,22 +94,22 @@ static bool CheckHkdfParams(HcfHkdfParamsSpec *params) // openssl only support INT and blob attribute is size_t, it should samller than INT_MAX. if (params->output.len > INT_MAX || params->salt.len > INT_MAX || params->key.len > INT_MAX || params->info.len > INT_MAX) { - LOGE("beyond the length"); + LOGE_ONE_STR("beyond the length"); return false; } if (params->key.data == NULL && params->key.len == 0) { - LOGE("check params failed, key is NULL"); + LOGE_ONE_STR("check params failed, key is NULL"); return false; } if (params->output.data == NULL || params->output.len == 0) { - LOGE("check params failed, output data is NULL"); + LOGE_ONE_STR("check params failed, output data is NULL"); return false; } if (params->salt.data == NULL && params->salt.len == 0) { - LOGD("empty salt"); + LOGD_ONE_STR("empty salt"); } if (params->info.data == NULL && params->info.len == 0) { - LOGD("empty info"); + LOGD_ONE_STR("empty info"); } return true; } @@ -142,12 +142,12 @@ static int GetHkdfMode(OpensslHkdfSpiImpl *self) static bool GetHkdfInfoFromSpec(OpensslHkdfSpiImpl *self, HcfHkdfData *data, HcfHkdfParamsSpec *params) { if (self->mode == HCF_ALG_MODE_EXTRACT_ONLY) { - LOGD("EXTRACT_ONLY mode does not require info"); + LOGD_ONE_STR("EXTRACT_ONLY mode does not require info"); return true; } if (params->info.len == 0) { - LOGD("info can be empty."); + LOGD_ONE_STR("info can be empty."); return true; } @@ -163,12 +163,12 @@ static bool GetHkdfInfoFromSpec(OpensslHkdfSpiImpl *self, HcfHkdfData *data, Hcf static bool GetHkdfSaltFromSpec(OpensslHkdfSpiImpl *self, HcfHkdfData *data, HcfHkdfParamsSpec *params) { if (self->mode == HCF_ALG_MODE_EXPAND_ONLY) { - LOGD("EXPAND_ONLY mode does not require salt"); + LOGD_ONE_STR("EXPAND_ONLY mode does not require salt"); return true; } if (params->salt.len == 0) { - LOGD("salt can be empty."); + LOGD_ONE_STR("salt can be empty."); return true; } @@ -187,24 +187,24 @@ static HcfResult InitHkdfData(OpensslHkdfSpiImpl *self, HcfHkdfParamsSpec *param HcfHkdfData *data = (HcfHkdfData *)HcfMalloc(sizeof(HcfHkdfData), 0); do { if (data == NULL) { - LOGE("malloc data failed"); + LOGE_ONE_STR("malloc data failed"); break; } if (!GetHkdfKeyFromSpec(data, params)) { - LOGE("malloc key failed!"); + LOGE_ONE_STR("malloc key failed!"); break; } if (!GetHkdfSaltFromSpec(self, data, params)) { - LOGE("malloc salt failed!"); + LOGE_ONE_STR("malloc salt failed!"); break; } if (!GetHkdfInfoFromSpec(self, data, params)) { - LOGE("malloc info failed!"); + LOGE_ONE_STR("malloc info failed!"); break; } data->out = (unsigned char *)HcfMalloc(params->output.len, 0); if (data->out == NULL) { - LOGE("malloc out failed!"); + LOGE_ONE_STR("malloc out failed!"); break; } data->outLen = params->output.len; @@ -249,14 +249,14 @@ static HcfResult OpensslHkdf(OpensslHkdfSpiImpl *self, HcfBlob *output) kdf = OpensslEvpKdfFetch(NULL, "HKDF", NULL); if (kdf == NULL) { - LOGE("kdf fetch failed"); + LOGE_ONE_STR("kdf fetch failed"); return HCF_ERR_CRYPTO_OPERATION; } kctx = OpensslEvpKdfCtxNew(kdf); OpensslEvpKdfFree(kdf); if (kctx == NULL) { - LOGE("kdf ctx new failed"); + LOGE_ONE_STR("kdf ctx new failed"); return HCF_ERR_CRYPTO_OPERATION; } @@ -270,7 +270,7 @@ static HcfResult OpensslHkdf(OpensslHkdfSpiImpl *self, HcfBlob *output) *p = OpensslOsslParamConstructEnd(); if (OpensslEvpKdfDerive(kctx, output->data, output->len, params) <= 0) { HcfPrintOpensslError(); - LOGE("EVP_KDF_derive failed"); + LOGE_ONE_STR("EVP_KDF_derive failed"); OpensslEvpKdfCtxFree(kctx); return HCF_ERR_CRYPTO_OPERATION; } @@ -281,7 +281,7 @@ static HcfResult OpensslHkdf(OpensslHkdfSpiImpl *self, HcfBlob *output) static HcfResult EngineGenerateSecret(HcfKdfSpi *self, HcfKdfParamsSpec *paramsSpec) { if (self == NULL || paramsSpec == NULL) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return HCF_INVALID_PARAMS; } if (!HcfIsClassMatch((HcfObjectBase *)self, EngineGetKdfClass())) { @@ -289,17 +289,17 @@ static HcfResult EngineGenerateSecret(HcfKdfSpi *self, HcfKdfParamsSpec *paramsS } OpensslHkdfSpiImpl *hkdfImpl = (OpensslHkdfSpiImpl *)self; if (paramsSpec->algName == NULL || strcmp(paramsSpec->algName, HKDF_ALG_NAME) != 0) { - LOGE("Not hkdf paramsSpec"); + LOGE_ONE_STR("Not hkdf paramsSpec"); return HCF_INVALID_PARAMS; } HcfHkdfParamsSpec *params = (HcfHkdfParamsSpec *)paramsSpec; if (!CheckHkdfParams(params)) { - LOGE("params error"); + LOGE_ONE_STR("params error"); return HCF_INVALID_PARAMS; } HcfResult res = InitHkdfData(hkdfImpl, params); if (res != HCF_SUCCESS) { - LOGE("InitCipherData failed!"); + LOGE_ONE_STR("InitCipherData failed!"); return res; } res = OpensslHkdf(hkdfImpl, ¶ms->output); @@ -310,12 +310,12 @@ static HcfResult EngineGenerateSecret(HcfKdfSpi *self, HcfKdfParamsSpec *paramsS HcfResult HcfKdfHkdfSpiCreate(HcfKdfDeriveParams *params, HcfKdfSpi **spiObj) { if (params == NULL || spiObj == NULL) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return HCF_INVALID_PARAMS; } OpensslHkdfSpiImpl *returnSpiImpl = (OpensslHkdfSpiImpl *)HcfMalloc(sizeof(OpensslHkdfSpiImpl), 0); if (returnSpiImpl == NULL) { - LOGE("Failed to allocate returnImpl memory!"); + LOGE_ONE_STR("Failed to allocate returnImpl memory!"); return HCF_ERR_MALLOC; } returnSpiImpl->base.base.getClass = EngineGetKdfClass; diff --git a/plugin/openssl_plugin/crypto_operation/kdf/src/pbkdf2_openssl.c b/plugin/openssl_plugin/crypto_operation/kdf/src/pbkdf2_openssl.c index a324f10da12b924e50a11b1352aecdc54d9c423c..f4294a19598fbd24f988f369fa014b4ad26dcff5 100644 --- a/plugin/openssl_plugin/crypto_operation/kdf/src/pbkdf2_openssl.c +++ b/plugin/openssl_plugin/crypto_operation/kdf/src/pbkdf2_openssl.c @@ -51,7 +51,7 @@ static void HcfClearAndFreeUnsignedChar(unsigned char *blob, int len) { // when blob == null, len must be 0; in check func, len >= 0 if (blob == NULL) { - LOGD("The input blob is null, no need to free."); + LOGD_ONE_STR("The input blob is null, no need to free."); return; } (void)memset_s(blob, len, 0, len); @@ -85,11 +85,11 @@ static void FreeKdfData(HcfKdfData **data) static void EngineDestroyKdf(HcfObjectBase *self) { if (self == NULL) { - LOGE("Self ptr is NULL!"); + LOGE_ONE_STR("Self ptr is NULL!"); return; } if (!HcfIsClassMatch(self, EngineGetKdfClass())) { - LOGE("Class is not match."); + LOGE_ONE_STR("Class is not match."); return; } OpensslKdfSpiImpl *impl = (OpensslKdfSpiImpl *)self; @@ -101,21 +101,21 @@ static void EngineDestroyKdf(HcfObjectBase *self) static bool CheckPBKDF2Params(HcfPBKDF2ParamsSpec *params) { if (params->iterations < 1) { - LOGE("invalid kdf iter"); + LOGE_ONE_STR("invalid kdf iter"); return false; } // openssl only support INT and blob attribute is size_t, it should samller than INT_MAX. if (params->output.len > INT_MAX || params->salt.len > INT_MAX || params->password.len > INT_MAX) { - LOGE("beyond the length"); + LOGE_ONE_STR("beyond the length"); return false; } // when params password == nullptr, the size will be set 0 by openssl; if (params->output.data == NULL || params->output.len == 0) { - LOGE("invalid output"); + LOGE_ONE_STR("invalid output"); return false; } if (params->salt.data == NULL && params->salt.len == 0) { - LOGD("empty salt"); + LOGD_ONE_STR("empty salt"); return true; } if (params->salt.data != NULL && params->salt.len != 0) { @@ -162,20 +162,20 @@ static HcfResult InitPBKDF2Data(OpensslKdfSpiImpl *self, HcfPBKDF2ParamsSpec *pa HcfKdfData *data = (HcfKdfData *)HcfMalloc(sizeof(HcfKdfData), 0); do { if (data == NULL) { - LOGE("malloc data failed"); + LOGE_ONE_STR("malloc data failed"); break; } if (!GetPBKDF2PasswordFromSpec(data, params)) { - LOGE("password malloc failed!"); + LOGE_ONE_STR("password malloc failed!"); break; } if (!GetPBKDF2SaltFromSpec(data, params)) { - LOGE("salt malloc failed!"); + LOGE_ONE_STR("salt malloc failed!"); break; } data->out = (unsigned char *)HcfMalloc(params->output.len, 0); if (data->out == NULL) { - LOGE("out malloc failed!"); + LOGE_ONE_STR("out malloc failed!"); break; } data->outLen = params->output.len; @@ -193,7 +193,7 @@ static HcfResult OpensslPBKDF2(OpensslKdfSpiImpl *self, HcfPBKDF2ParamsSpec *par if (OpensslPkcs5Pbkdf2Hmac((char *)(data->password), data->passwordLen, data->salt, data->saltLen, data->iter, self->digestAlg, data->outLen, data->out) != HCF_OPENSSL_SUCCESS) { HcfPrintOpensslError(); - LOGD("[error] pbkdf2 openssl failed!"); + LOGD_ONE_STR("[error] pbkdf2 openssl failed!"); return HCF_ERR_CRYPTO_OPERATION; } (void)memcpy_s(params->output.data, data->outLen, data->out, data->outLen); @@ -203,7 +203,7 @@ static HcfResult OpensslPBKDF2(OpensslKdfSpiImpl *self, HcfPBKDF2ParamsSpec *par static HcfResult EngineGenerateSecret(HcfKdfSpi *self, HcfKdfParamsSpec *paramsSpec) { if (self == NULL || paramsSpec == NULL) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return HCF_INVALID_PARAMS; } if (!HcfIsClassMatch((HcfObjectBase *)self, EngineGetKdfClass())) { @@ -211,17 +211,17 @@ static HcfResult EngineGenerateSecret(HcfKdfSpi *self, HcfKdfParamsSpec *paramsS } OpensslKdfSpiImpl *pbkdf2Impl = (OpensslKdfSpiImpl *)self; if (paramsSpec->algName == NULL || strcmp(paramsSpec->algName, PBKDF2_ALG_NAME) != 0) { - LOGE("Not pbkdf2 paramsSpec"); + LOGE_ONE_STR("Not pbkdf2 paramsSpec"); return HCF_INVALID_PARAMS; } HcfPBKDF2ParamsSpec *params = (HcfPBKDF2ParamsSpec *)paramsSpec; if (!CheckPBKDF2Params(params)) { - LOGE("params error"); + LOGE_ONE_STR("params error"); return HCF_INVALID_PARAMS; } HcfResult res = InitPBKDF2Data(pbkdf2Impl, params); if (res != HCF_SUCCESS) { - LOGE("InitCipherData failed!"); + LOGE_ONE_STR("InitCipherData failed!"); return HCF_INVALID_PARAMS; } res = OpensslPBKDF2(pbkdf2Impl, params); @@ -232,18 +232,18 @@ static HcfResult EngineGenerateSecret(HcfKdfSpi *self, HcfKdfParamsSpec *paramsS HcfResult HcfKdfPBKDF2SpiCreate(HcfKdfDeriveParams *params, HcfKdfSpi **spiObj) { if (params == NULL || spiObj == NULL) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return HCF_INVALID_PARAMS; } EVP_MD *md = NULL; HcfResult res = GetOpensslDigestAlg(params->md, &md); if (res != HCF_SUCCESS || md == NULL) { - LOGE("get md failed"); + LOGE_ONE_STR("get md failed"); return HCF_INVALID_PARAMS; } OpensslKdfSpiImpl *returnSpiImpl = (OpensslKdfSpiImpl *)HcfMalloc(sizeof(OpensslKdfSpiImpl), 0); if (returnSpiImpl == NULL) { - LOGE("Failed to allocate returnImpl memory!"); + LOGE_ONE_STR("Failed to allocate returnImpl memory!"); return HCF_ERR_MALLOC; } returnSpiImpl->base.base.getClass = EngineGetKdfClass; diff --git a/plugin/openssl_plugin/crypto_operation/kdf/src/scrypt_openssl.c b/plugin/openssl_plugin/crypto_operation/kdf/src/scrypt_openssl.c index 95a5eedb8f807d30a8240ca6b53d2c1aa23c297b..591f4b4d152843bb4f37c9cc6c0fdda269c1342d 100644 --- a/plugin/openssl_plugin/crypto_operation/kdf/src/scrypt_openssl.c +++ b/plugin/openssl_plugin/crypto_operation/kdf/src/scrypt_openssl.c @@ -76,11 +76,11 @@ static void FreeScryptData(HcfScryptData **data) static void EngineDestroyKdf(HcfObjectBase *self) { if (self == NULL) { - LOGE("Self ptr is NULL!"); + LOGE_ONE_STR("Self ptr is NULL!"); return; } if (!HcfIsClassMatch(self, EngineGetKdfClass())) { - LOGE("Class is not match."); + LOGE_ONE_STR("Class is not match."); return; } OpensslScryptSpiImpl *impl = (OpensslScryptSpiImpl *)self; @@ -92,19 +92,19 @@ static bool CheckScryptParams(HcfScryptParamsSpec *params) { // openssl only support INT and blob attribute is size_t, it should samller than INT_MAX. if (params->output.len > INT_MAX || params->salt.len > INT_MAX || params->passPhrase.len > INT_MAX) { - LOGE("beyond the length"); + LOGE_ONE_STR("beyond the length"); return false; } if (params->passPhrase.data == NULL && params->passPhrase.len == 0) { - LOGE("check params failed, passPhrase is NULL"); + LOGE_ONE_STR("check params failed, passPhrase is NULL"); return false; } if (params->output.data == NULL || params->output.len == 0) { - LOGE("check params failed, output data is NULL"); + LOGE_ONE_STR("check params failed, output data is NULL"); return false; } if (params->salt.data == NULL && params->salt.len == 0) { - LOGD("empty salt"); + LOGD_ONE_STR("empty salt"); } return true; @@ -113,7 +113,7 @@ static bool CheckScryptParams(HcfScryptParamsSpec *params) static bool GetScryptSaltFromSpec(HcfScryptData *data, HcfScryptParamsSpec *params) { if (params->salt.len == 0) { - LOGD("salt can be empty."); + LOGD_ONE_STR("salt can be empty."); return true; } @@ -147,20 +147,20 @@ static HcfResult InitScryptData(OpensslScryptSpiImpl *self, HcfScryptParamsSpec HcfScryptData *data = (HcfScryptData *)HcfMalloc(sizeof(HcfScryptData), 0); do { if (data == NULL) { - LOGE("malloc data failed"); + LOGE_ONE_STR("malloc data failed"); break; } if (!GetScryptSaltFromSpec(data, params)) { - LOGE("malloc salt failed!"); + LOGE_ONE_STR("malloc salt failed!"); break; } if (!GetScryptPasswordFromSpec(data, params)) { - LOGE("malloc salt failed!"); + LOGE_ONE_STR("malloc salt failed!"); break; } data->out = (unsigned char *)HcfMalloc(params->output.len, 0); if (data->out == NULL) { - LOGE("malloc out failed!"); + LOGE_ONE_STR("malloc out failed!"); break; } data->n = params->n; @@ -185,14 +185,14 @@ static HcfResult OpensslScrypt(OpensslScryptSpiImpl *self, HcfBlob *output) kdf = OpensslEvpKdfFetch(NULL, "SCRYPT", NULL); if (kdf == NULL) { - LOGE("kdf fetch failed"); + LOGE_ONE_STR("kdf fetch failed"); return HCF_ERR_CRYPTO_OPERATION; } kctx = OpensslEvpKdfCtxNew(kdf); OpensslEvpKdfFree(kdf); if (kctx == NULL) { - LOGE("kdf ctx new failed"); + LOGE_ONE_STR("kdf ctx new failed"); return HCF_ERR_CRYPTO_OPERATION; } @@ -205,11 +205,11 @@ static HcfResult OpensslScrypt(OpensslScryptSpiImpl *self, HcfBlob *output) *p = OpensslOsslParamConstructEnd(); if (OpensslEvpKdfDerive(kctx, output->data, output->len, params) <= 0) { HcfPrintOpensslError(); - LOGE("EVP_KDF_derive failed"); + LOGE_ONE_STR("EVP_KDF_derive failed"); OpensslEvpKdfCtxFree(kctx); return HCF_ERR_CRYPTO_OPERATION; } - LOGD("scrypt success"); + LOGD_ONE_STR("scrypt success"); OpensslEvpKdfCtxFree(kctx); return HCF_SUCCESS; } @@ -217,7 +217,7 @@ static HcfResult OpensslScrypt(OpensslScryptSpiImpl *self, HcfBlob *output) static HcfResult EngineGenerateSecret(HcfKdfSpi *self, HcfKdfParamsSpec *paramsSpec) { if (self == NULL || paramsSpec == NULL) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return HCF_INVALID_PARAMS; } if (!HcfIsClassMatch((HcfObjectBase *)self, EngineGetKdfClass())) { @@ -225,17 +225,17 @@ static HcfResult EngineGenerateSecret(HcfKdfSpi *self, HcfKdfParamsSpec *paramsS } OpensslScryptSpiImpl *scryptImpl = (OpensslScryptSpiImpl *)self; if (paramsSpec->algName == NULL || strcmp(paramsSpec->algName, SCRYPT_ALG_NAME) != 0) { - LOGE("Not scrypt paramsSpec"); + LOGE_ONE_STR("Not scrypt paramsSpec"); return HCF_INVALID_PARAMS; } HcfScryptParamsSpec *params = (HcfScryptParamsSpec *)paramsSpec; if (!CheckScryptParams(params)) { - LOGE("params error"); + LOGE_ONE_STR("params error"); return HCF_INVALID_PARAMS; } HcfResult res = InitScryptData(scryptImpl, params); if (res != HCF_SUCCESS) { - LOGE("InitCipherData failed!"); + LOGE_ONE_STR("InitCipherData failed!"); return res; } res = OpensslScrypt(scryptImpl, ¶ms->output); @@ -246,12 +246,12 @@ static HcfResult EngineGenerateSecret(HcfKdfSpi *self, HcfKdfParamsSpec *paramsS HcfResult HcfKdfScryptSpiCreate(HcfKdfDeriveParams *params, HcfKdfSpi **spiObj) { if (params == NULL || spiObj == NULL) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return HCF_INVALID_PARAMS; } OpensslScryptSpiImpl *returnSpiImpl = (OpensslScryptSpiImpl *)HcfMalloc(sizeof(OpensslScryptSpiImpl), 0); if (returnSpiImpl == NULL) { - LOGE("Failed to allocate returnImpl memory!"); + LOGE_ONE_STR("Failed to allocate returnImpl memory!"); return HCF_ERR_MALLOC; } returnSpiImpl->base.base.getClass = EngineGetKdfClass; diff --git a/plugin/openssl_plugin/crypto_operation/key_agreement/src/dh_openssl.c b/plugin/openssl_plugin/crypto_operation/key_agreement/src/dh_openssl.c index c9693c9d22aa8fe467cbbbd6f8b56dabd1bae950..430f35b50e5f4bbde4fd0b4cdde9bed349322fac 100644 --- a/plugin/openssl_plugin/crypto_operation/key_agreement/src/dh_openssl.c +++ b/plugin/openssl_plugin/crypto_operation/key_agreement/src/dh_openssl.c @@ -39,11 +39,11 @@ static const char *GetDhClass(void) static void DestroyDh(HcfObjectBase *self) { if (self == NULL) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return; } if (!HcfIsClassMatch(self, GetDhClass())) { - LOGE("Invalid class of self."); + LOGE_ONE_STR("Invalid class of self."); return; } HcfFree(self); @@ -53,23 +53,23 @@ static HcfResult EngineGenerateSecret(HcfKeyAgreementSpi *self, HcfPriKey *priKe HcfPubKey *pubKey, HcfBlob *returnSecret) { if ((self == NULL) || (priKey == NULL) || (pubKey == NULL) || (returnSecret == NULL)) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return HCF_INVALID_PARAMS; } if ((!HcfIsClassMatch((HcfObjectBase *)self, GetDhClass())) || (!HcfIsClassMatch((HcfObjectBase *)priKey, OPENSSL_DH_PRIKEY_CLASS)) || (!HcfIsClassMatch((HcfObjectBase *)pubKey, OPENSSL_DH_PUBKEY_CLASS))) { - LOGE("Invalid class of self."); + LOGE_ONE_STR("Invalid class of self."); return HCF_INVALID_PARAMS; } EVP_PKEY *pubPKey = NewEvpPkeyByDh(((HcfOpensslDhPubKey *)pubKey)->pk, true); if (pubPKey == NULL) { - LOGE("Failed to get public pkey."); + LOGE_ONE_STR("Failed to get public pkey."); return HCF_ERR_CRYPTO_OPERATION; } EVP_PKEY *priPKey = NewEvpPkeyByDh(((HcfOpensslDhPriKey *)priKey)->sk, true); if (priPKey == NULL) { - LOGE("Failed to get private pkey."); + LOGE_ONE_STR("Failed to get private pkey."); OpensslEvpPkeyFree(pubPKey); return HCF_ERR_CRYPTO_OPERATION; } @@ -83,14 +83,14 @@ HcfResult HcfKeyAgreementSpiDhCreate(HcfKeyAgreementParams *params, HcfKeyAgreem { (void)params; if ((params == NULL) || (returnObj == NULL)) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return HCF_INVALID_PARAMS; } HcfKeyAgreementSpiDhOpensslImpl *returnImpl = (HcfKeyAgreementSpiDhOpensslImpl *)HcfMalloc( sizeof(HcfKeyAgreementSpiDhOpensslImpl), 0); if (returnImpl == NULL) { - LOGE("Failed to allocate returnImpl memroy!"); + LOGE_ONE_STR("Failed to allocate returnImpl memroy!"); return HCF_ERR_MALLOC; } returnImpl->base.base.getClass = GetDhClass; diff --git a/plugin/openssl_plugin/crypto_operation/key_agreement/src/ecdh_openssl.c b/plugin/openssl_plugin/crypto_operation/key_agreement/src/ecdh_openssl.c index 996c03b074ac713a950e058e571cdc5bed9ccac4..bf698308470251f06d215135eadb10e709465f13 100644 --- a/plugin/openssl_plugin/crypto_operation/key_agreement/src/ecdh_openssl.c +++ b/plugin/openssl_plugin/crypto_operation/key_agreement/src/ecdh_openssl.c @@ -91,7 +91,7 @@ static HcfResult EngineGenerateSecret(HcfKeyAgreementSpi *self, HcfPriKey *priKe HcfPubKey *pubKey, HcfBlob *returnSecret) { if ((self == NULL) || (priKey == NULL) || (pubKey == NULL) || (returnSecret == NULL)) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return HCF_INVALID_PARAMS; } if ((!HcfIsClassMatch((HcfObjectBase *)self, GetEcdhClass())) || @@ -102,12 +102,12 @@ static HcfResult EngineGenerateSecret(HcfKeyAgreementSpi *self, HcfPriKey *priKe EVP_PKEY *priPKey = NewPKeyByEccPriKey((HcfOpensslEccPriKey *)priKey); if (priPKey == NULL) { - LOGD("[error] Gen EVP_PKEY priKey failed"); + LOGD_ONE_STR("[error] Gen EVP_PKEY priKey failed"); return HCF_ERR_CRYPTO_OPERATION; } EVP_PKEY *pubPKey = NewPKeyByEccPubKey((HcfOpensslEccPubKey *)pubKey); if (pubPKey == NULL) { - LOGD("[error] Gen EVP_PKEY pubKey failed"); + LOGD_ONE_STR("[error] Gen EVP_PKEY pubKey failed"); EVP_PKEY_free(priPKey); return HCF_ERR_CRYPTO_OPERATION; } @@ -122,14 +122,14 @@ HcfResult HcfKeyAgreementSpiEcdhCreate(HcfKeyAgreementParams *params, HcfKeyAgre { (void)params; if ((params == NULL) || (returnObj == NULL)) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return HCF_INVALID_PARAMS; } HcfKeyAgreementSpiEcdhOpensslImpl *returnImpl = (HcfKeyAgreementSpiEcdhOpensslImpl *)HcfMalloc( sizeof(HcfKeyAgreementSpiEcdhOpensslImpl), 0); if (returnImpl == NULL) { - LOGE("Failed to allocate returnImpl memroy!"); + LOGE_ONE_STR("Failed to allocate returnImpl memroy!"); return HCF_ERR_MALLOC; } returnImpl->base.base.getClass = GetEcdhClass; diff --git a/plugin/openssl_plugin/crypto_operation/key_agreement/src/x25519_openssl.c b/plugin/openssl_plugin/crypto_operation/key_agreement/src/x25519_openssl.c index 611b1153290b0553a4bf726e13241a2ec89fabaa..a94818bfd82741267ef9d32b92283beadf3fa6c6 100644 --- a/plugin/openssl_plugin/crypto_operation/key_agreement/src/x25519_openssl.c +++ b/plugin/openssl_plugin/crypto_operation/key_agreement/src/x25519_openssl.c @@ -38,11 +38,11 @@ static const char *GetX25519Class(void) static void DestroyX25519(HcfObjectBase *self) { if (self == NULL) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return; } if (!HcfIsClassMatch(self, GetX25519Class())) { - LOGE("Invalid class of self."); + LOGE_ONE_STR("Invalid class of self."); return; } HcfFree(self); @@ -52,23 +52,23 @@ static HcfResult EngineGenerateSecret(HcfKeyAgreementSpi *self, HcfPriKey *priKe HcfPubKey *pubKey, HcfBlob *returnSecret) { if ((self == NULL) || (priKey == NULL) || (pubKey == NULL) || (returnSecret == NULL)) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return HCF_INVALID_PARAMS; } if ((!HcfIsClassMatch((HcfObjectBase *)self, GetX25519Class())) || (!HcfIsClassMatch((HcfObjectBase *)priKey, OPENSSL_ALG25519_PRIKEY_CLASS)) || (!HcfIsClassMatch((HcfObjectBase *)pubKey, OPENSSL_ALG25519_PUBKEY_CLASS))) { - LOGE("Invalid class of self."); + LOGE_ONE_STR("Invalid class of self."); return HCF_INVALID_PARAMS; } EVP_PKEY *pubPKey = OpensslEvpPkeyDup(((HcfOpensslAlg25519PubKey *)pubKey)->pkey); if (pubPKey == NULL) { - LOGE("Failed to dup public pkey."); + LOGE_ONE_STR("Failed to dup public pkey."); return HCF_ERR_CRYPTO_OPERATION; } EVP_PKEY *priPKey = OpensslEvpPkeyDup(((HcfOpensslAlg25519PriKey *)priKey)->pkey); if (priPKey == NULL) { - LOGE("Failed to dup private pkey."); + LOGE_ONE_STR("Failed to dup private pkey."); OpensslEvpPkeyFree(pubPKey); return HCF_ERR_CRYPTO_OPERATION; } @@ -82,14 +82,14 @@ HcfResult HcfKeyAgreementSpiX25519Create(HcfKeyAgreementParams *params, HcfKeyAg { (void)params; if ((params == NULL) || (returnObj == NULL)) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return HCF_INVALID_PARAMS; } HcfKeyAgreementSpiX25519OpensslImpl *returnImpl = (HcfKeyAgreementSpiX25519OpensslImpl *)HcfMalloc( sizeof(HcfKeyAgreementSpiX25519OpensslImpl), 0); if (returnImpl == NULL) { - LOGE("Failed to allocate returnImpl memroy!"); + LOGE_ONE_STR("Failed to allocate returnImpl memroy!"); return HCF_ERR_MALLOC; } returnImpl->base.base.getClass = GetX25519Class; diff --git a/plugin/openssl_plugin/crypto_operation/md/src/md_openssl.c b/plugin/openssl_plugin/crypto_operation/md/src/md_openssl.c index ffcb32e8a085d1211c9c12c6c679a872652c9bda..9f351a6dca99e1a108a3592e6ec30da4df208974 100644 --- a/plugin/openssl_plugin/crypto_operation/md/src/md_openssl.c +++ b/plugin/openssl_plugin/crypto_operation/md/src/md_openssl.c @@ -39,7 +39,7 @@ static const char *OpensslGetMdClass(void) static EVP_MD_CTX *OpensslGetMdCtx(HcfMdSpi *self) { if (!HcfIsClassMatch((HcfObjectBase *)self, OpensslGetMdClass())) { - LOGE("Class is not match."); + LOGE_ONE_STR("Class is not match."); return NULL; } return ((OpensslMdSpiImpl *)self)->ctx; @@ -68,15 +68,15 @@ static const EVP_MD *OpensslGetMdAlgoFromString(const char *mdName) static HcfResult OpensslEngineUpdateMd(HcfMdSpi *self, HcfBlob *input) { if (input == NULL) { - LOGE("The input is NULL!"); + LOGE_ONE_STR("The input is NULL!"); return HCF_INVALID_PARAMS; } if (OpensslGetMdCtx(self) == NULL) { - LOGD("[error] The CTX is NULL!"); + LOGD_ONE_STR("[error] The CTX is NULL!"); return HCF_ERR_CRYPTO_OPERATION; } if (EVP_DigestUpdate(OpensslGetMdCtx(self), input->data, input->len) != HCF_OPENSSL_SUCCESS) { - LOGD("[error] EVP_DigestUpdate return error!"); + LOGD_ONE_STR("[error] EVP_DigestUpdate return error!"); HcfPrintOpensslError(); return HCF_ERR_CRYPTO_OPERATION; } @@ -86,25 +86,25 @@ static HcfResult OpensslEngineUpdateMd(HcfMdSpi *self, HcfBlob *input) static HcfResult OpensslEngineDoFinalMd(HcfMdSpi *self, HcfBlob *output) { if (output == NULL) { - LOGE("The output is NULL!"); + LOGE_ONE_STR("The output is NULL!"); return HCF_INVALID_PARAMS; } EVP_MD_CTX *localCtx = OpensslGetMdCtx(self); if (localCtx == NULL) { - LOGE("The CTX is NULL!"); + LOGE_ONE_STR("The CTX is NULL!"); return HCF_ERR_CRYPTO_OPERATION; } unsigned char outputBuf[EVP_MAX_MD_SIZE]; uint32_t outputLen; int32_t ret = OpensslEvpDigestFinalEx(localCtx, outputBuf, &outputLen); if (ret != HCF_OPENSSL_SUCCESS) { - LOGD("[error] EVP_DigestFinal_ex return error!"); + LOGD_ONE_STR("[error] EVP_DigestFinal_ex return error!"); HcfPrintOpensslError(); return HCF_ERR_CRYPTO_OPERATION; } output->data = (uint8_t *)HcfMalloc(outputLen, 0); if (output->data == NULL) { - LOGE("Failed to allocate output->data memory!"); + LOGE_ONE_STR("Failed to allocate output->data memory!"); return HCF_ERR_MALLOC; } (void)memcpy_s(output->data, outputLen, outputBuf, outputLen); @@ -115,12 +115,12 @@ static HcfResult OpensslEngineDoFinalMd(HcfMdSpi *self, HcfBlob *output) static uint32_t OpensslEngineGetMdLength(HcfMdSpi *self) { if (OpensslGetMdCtx(self) == NULL) { - LOGD("[error] The CTX is NULL!"); + LOGD_ONE_STR("[error] The CTX is NULL!"); return HCF_OPENSSL_INVALID_MD_LEN; } int32_t size = OpensslEvpMdCtxSize(OpensslGetMdCtx(self)); if (size < 0) { - LOGD("[error] Get the overflow path length in openssl!"); + LOGD_ONE_STR("[error] Get the overflow path length in openssl!"); return HCF_OPENSSL_INVALID_MD_LEN; } return size; @@ -129,11 +129,11 @@ static uint32_t OpensslEngineGetMdLength(HcfMdSpi *self) static void OpensslDestroyMd(HcfObjectBase *self) { if (self == NULL) { - LOGE("Self ptr is NULL!"); + LOGE_ONE_STR("Self ptr is NULL!"); return; } if (!HcfIsClassMatch(self, OpensslGetMdClass())) { - LOGE("Class is not match."); + LOGE_ONE_STR("Class is not match."); return; } if (OpensslGetMdCtx((HcfMdSpi *)self) != NULL) { @@ -145,30 +145,30 @@ static void OpensslDestroyMd(HcfObjectBase *self) HcfResult OpensslMdSpiCreate(const char *opensslAlgoName, HcfMdSpi **spiObj) { if (spiObj == NULL || opensslAlgoName == NULL) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return HCF_INVALID_PARAMS; } OpensslMdSpiImpl *returnSpiImpl = (OpensslMdSpiImpl *)HcfMalloc(sizeof(OpensslMdSpiImpl), 0); if (returnSpiImpl == NULL) { - LOGE("Failed to allocate MdSpiImpl memory!"); + LOGE_ONE_STR("Failed to allocate MdSpiImpl memory!"); return HCF_ERR_MALLOC; } returnSpiImpl->ctx = OpensslEvpMdCtxNew(); if (returnSpiImpl->ctx == NULL) { - LOGE("Failed to create ctx!"); + LOGE_ONE_STR("Failed to create ctx!"); HcfFree(returnSpiImpl); return HCF_ERR_MALLOC; } const EVP_MD *mdfunc = OpensslGetMdAlgoFromString(opensslAlgoName); if (mdfunc == NULL) { - LOGE("OpensslGetMdAlgoFromString failed!"); + LOGE_ONE_STR("OpensslGetMdAlgoFromString failed!"); OpensslEvpMdCtxFree(returnSpiImpl->ctx); HcfFree(returnSpiImpl); return HCF_ERR_CRYPTO_OPERATION; } int32_t ret = OpensslEvpDigestInitEx(returnSpiImpl->ctx, mdfunc, NULL); if (ret != HCF_OPENSSL_SUCCESS) { - LOGD("[error] Failed to init MD!"); + LOGD_ONE_STR("[error] Failed to init MD!"); OpensslEvpMdCtxFree(returnSpiImpl->ctx); HcfFree(returnSpiImpl); return HCF_ERR_CRYPTO_OPERATION; diff --git a/plugin/openssl_plugin/crypto_operation/rand/src/rand_openssl.c b/plugin/openssl_plugin/crypto_operation/rand/src/rand_openssl.c index 78bb9691d9df582a6166a0fe03d9d4fa77112d35..1f5d5403efc3fa1f191c49bc262511e095988047 100644 --- a/plugin/openssl_plugin/crypto_operation/rand/src/rand_openssl.c +++ b/plugin/openssl_plugin/crypto_operation/rand/src/rand_openssl.c @@ -34,21 +34,21 @@ static const char *GetRandOpenSSLClass(void) static HcfResult OpensslGenerateRandom(HcfRandSpi *self, int32_t numBytes, HcfBlob *random) { if ((self == NULL) || (random == NULL)) { - LOGE("Invalid params!"); + LOGE_ONE_STR("Invalid params!"); return HCF_INVALID_PARAMS; } if (numBytes <= 0) { - LOGE("Invalid numBytes!"); + LOGE_ONE_STR("Invalid numBytes!"); return HCF_INVALID_PARAMS; } random->data = (uint8_t *)HcfMalloc(numBytes, 0); if (random->data == NULL) { - LOGE("Failed to allocate random->data memory!"); + LOGE_ONE_STR("Failed to allocate random->data memory!"); return HCF_ERR_MALLOC; } int32_t ret = OpensslRandPrivBytes(random->data, numBytes); if (ret != HCF_OPENSSL_SUCCESS) { - LOGD("[error] RAND_bytes return error!"); + LOGD_ONE_STR("[error] RAND_bytes return error!"); HcfFree(random->data); random->data = NULL; HcfPrintOpensslError(); @@ -62,11 +62,11 @@ static HcfResult OpensslGenerateRandom(HcfRandSpi *self, int32_t numBytes, HcfBl static const char *GetRandAlgoName(HcfRandSpi *self) { if (self == NULL) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return NULL; } if (!HcfIsClassMatch((HcfObjectBase *)self, GetRandOpenSSLClass())) { - LOGE("Class is not match."); + LOGE_ONE_STR("Class is not match."); return NULL; } @@ -77,7 +77,7 @@ static void OpensslSetSeed(HcfRandSpi *self, HcfBlob *seed) { (void)self; if (seed == NULL) { - LOGE("The seed is NULL!"); + LOGE_ONE_STR("The seed is NULL!"); return; } OpensslRandSeed(seed->data, seed->len); @@ -86,11 +86,11 @@ static void OpensslSetSeed(HcfRandSpi *self, HcfBlob *seed) static void DestroyRandOpenssl(HcfObjectBase *self) { if (self == NULL) { - LOGE("Self ptr is NULL!"); + LOGE_ONE_STR("Self ptr is NULL!"); return; } if (!HcfIsClassMatch(self, GetRandOpenSSLClass())) { - LOGE("Class is not match."); + LOGE_ONE_STR("Class is not match."); return; } HcfFree(self); @@ -99,12 +99,12 @@ static void DestroyRandOpenssl(HcfObjectBase *self) HcfResult HcfRandSpiCreate(HcfRandSpi **spiObj) { if (spiObj == NULL) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return HCF_INVALID_PARAMS; } HcfRandSpiImpl *returnSpiImpl = (HcfRandSpiImpl *)HcfMalloc(sizeof(HcfRandSpiImpl), 0); if (returnSpiImpl == NULL) { - LOGE("Failed to allocate returnImpl memory!"); + LOGE_ONE_STR("Failed to allocate returnImpl memory!"); return HCF_ERR_MALLOC; } returnSpiImpl->base.base.getClass = GetRandOpenSSLClass; diff --git a/plugin/openssl_plugin/crypto_operation/signature/src/dsa_openssl.c b/plugin/openssl_plugin/crypto_operation/signature/src/dsa_openssl.c index 03fb3f146492ccf237ba42ca9652ad955df3c04c..016f17902181771bc1bc4b7dda833f3df40543e7 100644 --- a/plugin/openssl_plugin/crypto_operation/signature/src/dsa_openssl.c +++ b/plugin/openssl_plugin/crypto_operation/signature/src/dsa_openssl.c @@ -64,7 +64,7 @@ static const char *GetDsaVerifyClass(void) static bool IsSignInitInputValid(HcfSignSpi *self, HcfPriKey *privateKey) { if ((self == NULL) || (privateKey == NULL)) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return false; } if ((!HcfIsClassMatch((HcfObjectBase *)self, GetDsaSignClass())) || @@ -73,7 +73,7 @@ static bool IsSignInitInputValid(HcfSignSpi *self, HcfPriKey *privateKey) } HcfSignSpiDsaOpensslImpl *impl = (HcfSignSpiDsaOpensslImpl *)self; if (impl->status != UNINITIALIZED) { - LOGE("Repeated initialization is not allowed."); + LOGE_ONE_STR("Repeated initialization is not allowed."); return false; } return true; @@ -82,7 +82,7 @@ static bool IsSignInitInputValid(HcfSignSpi *self, HcfPriKey *privateKey) static bool IsVerifyInitInputValid(HcfVerifySpi *self, HcfPubKey *publicKey) { if ((self == NULL) || (publicKey == NULL)) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return false; } if ((!HcfIsClassMatch((HcfObjectBase *)self, GetDsaVerifyClass())) || @@ -91,7 +91,7 @@ static bool IsVerifyInitInputValid(HcfVerifySpi *self, HcfPubKey *publicKey) } HcfVerifySpiDsaOpensslImpl *impl = (HcfVerifySpiDsaOpensslImpl *)self; if (impl->status != UNINITIALIZED) { - LOGE("Repeated initialization is not allowed."); + LOGE_ONE_STR("Repeated initialization is not allowed."); return false; } return true; @@ -100,7 +100,7 @@ static bool IsVerifyInitInputValid(HcfVerifySpi *self, HcfPubKey *publicKey) static bool IsSignDoFinalInputValid(HcfSignSpi *self, HcfBlob *returnSignatureData) { if ((self == NULL) || (returnSignatureData == NULL)) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return false; } if (!HcfIsClassMatch((HcfObjectBase *)self, GetDsaSignClass())) { @@ -112,7 +112,7 @@ static bool IsSignDoFinalInputValid(HcfSignSpi *self, HcfBlob *returnSignatureDa static bool IsVerifyDoFinalInputValid(HcfVerifySpi *self, HcfBlob *signatureData) { if ((self == NULL) || (!HcfIsBlobValid(signatureData))) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return false; } if (!HcfIsClassMatch((HcfObjectBase *)self, GetDsaVerifyClass())) { @@ -166,18 +166,18 @@ static EVP_PKEY *CreateDsaEvpKeyByDsa(HcfKey *key, bool isSign) { EVP_PKEY *pKey = OpensslEvpPkeyNew(); if (pKey == NULL) { - LOGD("[error] EVP_PKEY_new fail"); + LOGD_ONE_STR("[error] EVP_PKEY_new fail"); HcfPrintOpensslError(); return NULL; } DSA *dsa = isSign ? ((HcfOpensslDsaPriKey *)key)->sk : ((HcfOpensslDsaPubKey *)key)->pk; if (dsa == NULL) { - LOGD("[error] dsa has been cleared"); + LOGD_ONE_STR("[error] dsa has been cleared"); EVP_PKEY_free(pKey); return NULL; } if (OpensslEvpPkeySet1Dsa(pKey, dsa) != HCF_OPENSSL_SUCCESS) { - LOGD("[error] EVP_PKEY_set1_DSA fail"); + LOGD_ONE_STR("[error] EVP_PKEY_set1_DSA fail"); HcfPrintOpensslError(); EVP_PKEY_free(pKey); return NULL; @@ -193,7 +193,7 @@ static HcfResult EngineDsaSignInit(HcfSignSpi *self, HcfParamsSpec *params, HcfP } EVP_PKEY *pKey = CreateDsaEvpKeyByDsa((HcfKey *)privateKey, true); if (pKey == NULL) { - LOGE("Create DSA evp key failed!"); + LOGE_ONE_STR("Create DSA evp key failed!"); return HCF_ERR_CRYPTO_OPERATION; } HcfSignSpiDsaOpensslImpl *impl = (HcfSignSpiDsaOpensslImpl *)self; @@ -216,7 +216,7 @@ static HcfResult EngineDsaSignWithoutDigestInit(HcfSignSpi *self, HcfParamsSpec } EVP_PKEY *pKey = CreateDsaEvpKeyByDsa((HcfKey *)privateKey, true); if (pKey == NULL) { - LOGD("[error] Create DSA evp key failed!"); + LOGD_ONE_STR("[error] Create DSA evp key failed!"); return HCF_ERR_CRYPTO_OPERATION; } HcfSignSpiDsaOpensslImpl *impl = (HcfSignSpiDsaOpensslImpl *)self; @@ -248,7 +248,7 @@ static HcfResult EngineDsaVerifyInit(HcfVerifySpi *self, HcfParamsSpec *params, HcfVerifySpiDsaOpensslImpl *impl = (HcfVerifySpiDsaOpensslImpl *)self; EVP_PKEY *pKey = CreateDsaEvpKeyByDsa((HcfKey *)publicKey, false); if (pKey == NULL) { - LOGD("[error] Create DSA evp key failed!"); + LOGD_ONE_STR("[error] Create DSA evp key failed!"); return HCF_ERR_CRYPTO_OPERATION; } if (OpensslEvpDigestVerifyInit(impl->mdCtx, NULL, impl->digestAlg, NULL, pKey) != HCF_OPENSSL_SUCCESS) { @@ -271,7 +271,7 @@ static HcfResult EngineDsaVerifyWithoutDigestInit(HcfVerifySpi *self, HcfParamsS HcfVerifySpiDsaOpensslImpl *impl = (HcfVerifySpiDsaOpensslImpl *)self; EVP_PKEY *pKey = CreateDsaEvpKeyByDsa((HcfKey *)publicKey, false); if (pKey == NULL) { - LOGD("[error] Create dsa evp key failed!"); + LOGD_ONE_STR("[error] Create dsa evp key failed!"); return HCF_ERR_CRYPTO_OPERATION; } impl->pkeyCtx = OpensslEvpPkeyCtxNew(pKey, NULL); @@ -295,7 +295,7 @@ static HcfResult EngineDsaVerifyWithoutDigestInit(HcfVerifySpi *self, HcfParamsS static HcfResult EngineDsaSignUpdate(HcfSignSpi *self, HcfBlob *data) { if ((self == NULL) || (!HcfIsBlobValid(data))) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return HCF_INVALID_PARAMS; } if (!HcfIsClassMatch((HcfObjectBase *)self, GetDsaSignClass())) { @@ -303,7 +303,7 @@ static HcfResult EngineDsaSignUpdate(HcfSignSpi *self, HcfBlob *data) } HcfSignSpiDsaOpensslImpl *impl = (HcfSignSpiDsaOpensslImpl *)self; if (impl->status == UNINITIALIZED) { - LOGE("Sign object has not been initialized."); + LOGE_ONE_STR("Sign object has not been initialized."); return HCF_INVALID_PARAMS; } if (OpensslEvpDigestSignUpdate(impl->mdCtx, data->data, data->len) != HCF_OPENSSL_SUCCESS) { @@ -324,7 +324,7 @@ static HcfResult EngineDsaSignWithoutDigestUpdate(HcfSignSpi *self, HcfBlob *dat static HcfResult EngineDsaVerifyUpdate(HcfVerifySpi *self, HcfBlob *data) { if ((self == NULL) || (!HcfIsBlobValid(data))) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return HCF_INVALID_PARAMS; } if (!HcfIsClassMatch((HcfObjectBase *)self, GetDsaVerifyClass())) { @@ -332,7 +332,7 @@ static HcfResult EngineDsaVerifyUpdate(HcfVerifySpi *self, HcfBlob *data) } HcfVerifySpiDsaOpensslImpl *impl = (HcfVerifySpiDsaOpensslImpl *)self; if (impl->status == UNINITIALIZED) { - LOGE("Verify object has not been initialized."); + LOGE_ONE_STR("Verify object has not been initialized."); return HCF_INVALID_PARAMS; } @@ -365,7 +365,7 @@ static HcfResult EngineDsaSignDoFinal(HcfSignSpi *self, HcfBlob *data, HcfBlob * impl->status = READY; } if (impl->status != READY) { - LOGE("The message has not been transferred."); + LOGE_ONE_STR("The message has not been transferred."); return HCF_INVALID_PARAMS; } size_t maxLen; @@ -375,7 +375,7 @@ static HcfResult EngineDsaSignDoFinal(HcfSignSpi *self, HcfBlob *data, HcfBlob * } uint8_t *signatureData = (uint8_t *)HcfMalloc(maxLen, 0); if (signatureData == NULL) { - LOGE("Failed to allocate signatureData memory!"); + LOGE_ONE_STR("Failed to allocate signatureData memory!"); return HCF_ERR_MALLOC; } @@ -396,12 +396,12 @@ static HcfResult EngineDsaSignWithoutDigestDoFinal(HcfSignSpi *self, HcfBlob *da return HCF_INVALID_PARAMS; } if (!HcfIsBlobValid(data)) { - LOGE("Src data is invalid."); + LOGE_ONE_STR("Src data is invalid."); return HCF_INVALID_PARAMS; } HcfSignSpiDsaOpensslImpl *impl = (HcfSignSpiDsaOpensslImpl *)self; if (impl->status != READY) { - LOGE("Not init yet."); + LOGE_ONE_STR("Not init yet."); return HCF_INVALID_PARAMS; } size_t maxLen; @@ -412,7 +412,7 @@ static HcfResult EngineDsaSignWithoutDigestDoFinal(HcfSignSpi *self, HcfBlob *da } uint8_t *signatureData = (uint8_t *)HcfMalloc(maxLen, 0); if (signatureData == NULL) { - LOGE("Failed to allocate signatureData memory!"); + LOGE_ONE_STR("Failed to allocate signatureData memory!"); return HCF_ERR_MALLOC; } size_t actualLen = maxLen; @@ -423,7 +423,7 @@ static HcfResult EngineDsaSignWithoutDigestDoFinal(HcfSignSpi *self, HcfBlob *da return HCF_ERR_CRYPTO_OPERATION; } if (actualLen > maxLen) { - LOGD("[error] Signature data too long."); + LOGD_ONE_STR("[error] Signature data too long."); HcfFree(signatureData); return HCF_ERR_CRYPTO_OPERATION; } @@ -442,14 +442,14 @@ static bool EngineDsaVerifyDoFinal(HcfVerifySpi *self, HcfBlob *data, HcfBlob *s HcfVerifySpiDsaOpensslImpl *impl = (HcfVerifySpiDsaOpensslImpl *)self; if (HcfIsBlobValid(data)) { if (OpensslEvpDigestVerifyUpdate(impl->mdCtx, data->data, data->len) != HCF_OPENSSL_SUCCESS) { - LOGD("[error] Openssl update failed."); + LOGD_ONE_STR("[error] Openssl update failed."); HcfPrintOpensslError(); return false; } impl->status = READY; } if (impl->status != READY) { - LOGE("The message has not been transferred."); + LOGE_ONE_STR("The message has not been transferred."); return false; } @@ -466,12 +466,12 @@ static bool EngineDsaVerifyWithoutDigestDoFinal(HcfVerifySpi *self, HcfBlob *dat return false; } if (!HcfIsBlobValid(data)) { - LOGE("Src data is invalid."); + LOGE_ONE_STR("Src data is invalid."); return false; } HcfVerifySpiDsaOpensslImpl *impl = (HcfVerifySpiDsaOpensslImpl *)self; if (impl->status != READY) { - LOGE("Not init yet."); + LOGE_ONE_STR("Not init yet."); return false; } @@ -550,13 +550,13 @@ static HcfResult EngineSetVerifyDsaSpecUint8Array(HcfVerifySpi *self, SignSpecIt HcfResult HcfSignSpiDsaCreate(HcfSignatureParams *params, HcfSignSpi **returnObj) { if ((params == NULL) || (returnObj == NULL)) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return HCF_INVALID_PARAMS; } HcfSignSpiDsaOpensslImpl *impl = (HcfSignSpiDsaOpensslImpl *)HcfMalloc(sizeof(HcfSignSpiDsaOpensslImpl), 0); if (impl == NULL) { - LOGE("Failed to allocate impl memroy!"); + LOGE_ONE_STR("Failed to allocate impl memroy!"); return HCF_ERR_MALLOC; } @@ -577,7 +577,7 @@ HcfResult HcfSignSpiDsaCreate(HcfSignatureParams *params, HcfSignSpi **returnObj impl->base.engineSign = EngineDsaSignDoFinal; impl->mdCtx = OpensslEvpMdCtxNew(); if (impl->mdCtx == NULL) { - LOGE("Failed to allocate ctx memory!"); + LOGE_ONE_STR("Failed to allocate ctx memory!"); HcfFree(impl); return HCF_ERR_MALLOC; } @@ -597,13 +597,13 @@ HcfResult HcfSignSpiDsaCreate(HcfSignatureParams *params, HcfSignSpi **returnObj HcfResult HcfVerifySpiDsaCreate(HcfSignatureParams *params, HcfVerifySpi **returnObj) { if ((params == NULL) || (returnObj == NULL)) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return HCF_INVALID_PARAMS; } HcfVerifySpiDsaOpensslImpl *impl = (HcfVerifySpiDsaOpensslImpl *)HcfMalloc(sizeof(HcfVerifySpiDsaOpensslImpl), 0); if (impl == NULL) { - LOGE("Failed to allocate impl memroy!"); + LOGE_ONE_STR("Failed to allocate impl memroy!"); return HCF_ERR_MALLOC; } @@ -623,7 +623,7 @@ HcfResult HcfVerifySpiDsaCreate(HcfSignatureParams *params, HcfVerifySpi **retur impl->base.engineVerify = EngineDsaVerifyDoFinal; impl->mdCtx = OpensslEvpMdCtxNew(); if (impl->mdCtx == NULL) { - LOGE("Failed to allocate ctx memory!"); + LOGE_ONE_STR("Failed to allocate ctx memory!"); HcfFree(impl); return HCF_ERR_MALLOC; } diff --git a/plugin/openssl_plugin/crypto_operation/signature/src/ecdsa_openssl.c b/plugin/openssl_plugin/crypto_operation/signature/src/ecdsa_openssl.c index 3c8f67176ae76c1cb7bfc568085ec4419bbc49fd..4fa421e190b7a7bcc7596ac4a84fe82bc4f426e9 100644 --- a/plugin/openssl_plugin/crypto_operation/signature/src/ecdsa_openssl.c +++ b/plugin/openssl_plugin/crypto_operation/signature/src/ecdsa_openssl.c @@ -87,11 +87,11 @@ static const char *GetEcdsaVerifyClass(void) static void DestroyEcdsaSign(HcfObjectBase *self) { if (self == NULL) { - LOGE("Class is null."); + LOGE_ONE_STR("Class is null."); return; } if (!HcfIsClassMatch(self, GetEcdsaSignClass())) { - LOGE("Class not match."); + LOGE_ONE_STR("Class not match."); return; } HcfSignSpiEcdsaOpensslImpl *impl = (HcfSignSpiEcdsaOpensslImpl *)self; @@ -103,11 +103,11 @@ static void DestroyEcdsaSign(HcfObjectBase *self) static void DestroyEcdsaVerify(HcfObjectBase *self) { if (self == NULL) { - LOGE("Class is null."); + LOGE_ONE_STR("Class is null."); return; } if (!HcfIsClassMatch(self, GetEcdsaVerifyClass())) { - LOGE("Class not match."); + LOGE_ONE_STR("Class not match."); return; } HcfVerifySpiEcdsaOpensslImpl *impl = (HcfVerifySpiEcdsaOpensslImpl *)self; @@ -120,44 +120,44 @@ static HcfResult EngineSignInit(HcfSignSpi *self, HcfParamsSpec *params, HcfPriK { (void)params; if ((self == NULL) || (privateKey == NULL)) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return HCF_INVALID_PARAMS; } if ((!HcfIsClassMatch((HcfObjectBase *)self, GetEcdsaSignClass())) || (!HcfIsClassMatch((HcfObjectBase *)privateKey, HCF_OPENSSL_ECC_PRI_KEY_CLASS))) { - LOGE("Class not match."); + LOGE_ONE_STR("Class not match."); return HCF_INVALID_PARAMS; } HcfSignSpiEcdsaOpensslImpl *impl = (HcfSignSpiEcdsaOpensslImpl *)self; if (impl->status != UNINITIALIZED) { - LOGE("Repeated initialization is not allowed."); + LOGE_ONE_STR("Repeated initialization is not allowed."); return HCF_INVALID_PARAMS; } // dup will check if ecKey is NULL EC_KEY *ecKey = OpensslEcKeyDup(((HcfOpensslEccPriKey *)privateKey)->ecKey); if (ecKey == NULL) { HcfPrintOpensslError(); - LOGD("[error] Dup ecKey failed."); + LOGD_ONE_STR("[error] Dup ecKey failed."); return HCF_ERR_CRYPTO_OPERATION; } EVP_PKEY *pKey = OpensslEvpPkeyNew(); if (pKey == NULL) { HcfPrintOpensslError(); - LOGD("[error] Dup pKey failed."); + LOGD_ONE_STR("[error] Dup pKey failed."); OpensslEcKeyFree(ecKey); return HCF_ERR_CRYPTO_OPERATION; } if (OpensslEvpPkeyAssignEcKey(pKey, ecKey) != HCF_OPENSSL_SUCCESS) { HcfPrintOpensslError(); - LOGD("[error] EVP_PKEY_assign_EC_KEY failed."); + LOGD_ONE_STR("[error] EVP_PKEY_assign_EC_KEY failed."); OpensslEcKeyFree(ecKey); OpensslEvpPkeyFree(pKey); return HCF_ERR_CRYPTO_OPERATION; } if (OpensslEvpDigestSignInit(impl->ctx, NULL, impl->digestAlg, NULL, pKey) != HCF_OPENSSL_SUCCESS) { HcfPrintOpensslError(); - LOGD("[error] EVP_DigestSignInit failed."); + LOGD_ONE_STR("[error] EVP_DigestSignInit failed."); OpensslEvpPkeyFree(pKey); return HCF_ERR_CRYPTO_OPERATION; } @@ -169,21 +169,21 @@ static HcfResult EngineSignInit(HcfSignSpi *self, HcfParamsSpec *params, HcfPriK static HcfResult EngineSignUpdate(HcfSignSpi *self, HcfBlob *data) { if ((self == NULL) || (!HcfIsBlobValid(data))) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return HCF_INVALID_PARAMS; } if (!HcfIsClassMatch((HcfObjectBase *)self, GetEcdsaSignClass())) { - LOGE("Class not match."); + LOGE_ONE_STR("Class not match."); return HCF_INVALID_PARAMS; } HcfSignSpiEcdsaOpensslImpl *impl = (HcfSignSpiEcdsaOpensslImpl *)self; if (impl->status == UNINITIALIZED) { - LOGE("Sign object has not been initialized."); + LOGE_ONE_STR("Sign object has not been initialized."); return HCF_INVALID_PARAMS; } if (OpensslEvpDigestSignUpdate(impl->ctx, data->data, data->len) != HCF_OPENSSL_SUCCESS) { HcfPrintOpensslError(); - LOGD("[error] EVP_DigestSignUpdate failed."); + LOGD_ONE_STR("[error] EVP_DigestSignUpdate failed."); return HCF_ERR_CRYPTO_OPERATION; } impl->status = READY; @@ -193,11 +193,11 @@ static HcfResult EngineSignUpdate(HcfSignSpi *self, HcfBlob *data) static HcfResult EngineSignDoFinal(HcfSignSpi *self, HcfBlob *data, HcfBlob *returnSignatureData) { if ((self == NULL) || (returnSignatureData == NULL)) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return HCF_INVALID_PARAMS; } if (!HcfIsClassMatch((HcfObjectBase *)self, GetEcdsaSignClass())) { - LOGE("Class not match."); + LOGE_ONE_STR("Class not match."); return HCF_INVALID_PARAMS; } @@ -205,30 +205,30 @@ static HcfResult EngineSignDoFinal(HcfSignSpi *self, HcfBlob *data, HcfBlob *ret if (HcfIsBlobValid(data)) { if (OpensslEvpDigestSignUpdate(impl->ctx, data->data, data->len) != HCF_OPENSSL_SUCCESS) { HcfPrintOpensslError(); - LOGD("[error] EVP_DigestSignUpdate failed."); + LOGD_ONE_STR("[error] EVP_DigestSignUpdate failed."); return HCF_ERR_CRYPTO_OPERATION; } impl->status = READY; } if (impl->status != READY) { - LOGE("The message has not been transferred."); + LOGE_ONE_STR("The message has not been transferred."); return HCF_INVALID_PARAMS; } size_t maxLen; if (OpensslEvpDigestSignFinal(impl->ctx, NULL, &maxLen) != HCF_OPENSSL_SUCCESS) { HcfPrintOpensslError(); - LOGD("[error] EVP_DigestSignFinal failed."); + LOGD_ONE_STR("[error] EVP_DigestSignFinal failed."); return HCF_ERR_CRYPTO_OPERATION; } uint8_t *outData = (uint8_t *)HcfMalloc(maxLen, 0); if (outData == NULL) { - LOGE("Failed to allocate outData memory!"); + LOGE_ONE_STR("Failed to allocate outData memory!"); return HCF_ERR_MALLOC; } if (OpensslEvpDigestSignFinal(impl->ctx, outData, &maxLen) != HCF_OPENSSL_SUCCESS) { HcfPrintOpensslError(); - LOGD("[error] EVP_DigestSignFinal failed."); + LOGD_ONE_STR("[error] EVP_DigestSignFinal failed."); HcfFree(outData); return HCF_ERR_CRYPTO_OPERATION; } @@ -242,43 +242,43 @@ static HcfResult EngineVerifyInit(HcfVerifySpi *self, HcfParamsSpec *params, Hcf { (void)params; if ((self == NULL) || (publicKey == NULL)) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return HCF_INVALID_PARAMS; } if ((!HcfIsClassMatch((HcfObjectBase *)self, GetEcdsaVerifyClass())) || (!HcfIsClassMatch((HcfObjectBase *)publicKey, HCF_OPENSSL_ECC_PUB_KEY_CLASS))) { - LOGE("Class not match."); + LOGE_ONE_STR("Class not match."); return HCF_INVALID_PARAMS; } HcfVerifySpiEcdsaOpensslImpl *impl = (HcfVerifySpiEcdsaOpensslImpl *)self; if (impl->status != UNINITIALIZED) { - LOGE("Repeated initialization is not allowed."); + LOGE_ONE_STR("Repeated initialization is not allowed."); return HCF_INVALID_PARAMS; } EC_KEY *ecKey = OpensslEcKeyDup(((HcfOpensslEccPubKey *)publicKey)->ecKey); if (ecKey == NULL) { HcfPrintOpensslError(); - LOGD("[error] Dup ecKey failed."); + LOGD_ONE_STR("[error] Dup ecKey failed."); return HCF_ERR_CRYPTO_OPERATION; } EVP_PKEY *pKey = OpensslEvpPkeyNew(); if (pKey == NULL) { HcfPrintOpensslError(); - LOGD("[error] New pKey failed."); + LOGD_ONE_STR("[error] New pKey failed."); OpensslEcKeyFree(ecKey); return HCF_ERR_CRYPTO_OPERATION; } if (OpensslEvpPkeyAssignEcKey(pKey, ecKey) != HCF_OPENSSL_SUCCESS) { HcfPrintOpensslError(); - LOGD("[error] EVP_PKEY_assign_EC_KEY failed."); + LOGD_ONE_STR("[error] EVP_PKEY_assign_EC_KEY failed."); OpensslEcKeyFree(ecKey); OpensslEvpPkeyFree(pKey); return HCF_ERR_CRYPTO_OPERATION; } if (OpensslEvpDigestVerifyInit(impl->ctx, NULL, impl->digestAlg, NULL, pKey) != HCF_OPENSSL_SUCCESS) { HcfPrintOpensslError(); - LOGD("[error] EVP_DigestVerifyInit failed."); + LOGD_ONE_STR("[error] EVP_DigestVerifyInit failed."); OpensslEvpPkeyFree(pKey); return HCF_ERR_CRYPTO_OPERATION; } @@ -290,22 +290,22 @@ static HcfResult EngineVerifyInit(HcfVerifySpi *self, HcfParamsSpec *params, Hcf static HcfResult EngineVerifyUpdate(HcfVerifySpi *self, HcfBlob *data) { if ((self == NULL) || (!HcfIsBlobValid(data))) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return HCF_INVALID_PARAMS; } if (!HcfIsClassMatch((HcfObjectBase *)self, GetEcdsaVerifyClass())) { - LOGE("Class not match."); + LOGE_ONE_STR("Class not match."); return HCF_INVALID_PARAMS; } HcfVerifySpiEcdsaOpensslImpl *impl = (HcfVerifySpiEcdsaOpensslImpl *)self; if (impl->status == UNINITIALIZED) { - LOGE("Verify object has not been initialized."); + LOGE_ONE_STR("Verify object has not been initialized."); return HCF_INVALID_PARAMS; } if (OpensslEvpDigestVerifyUpdate(impl->ctx, data->data, data->len) != HCF_OPENSSL_SUCCESS) { HcfPrintOpensslError(); - LOGD("[error] EVP_DigestVerifyUpdate failed."); + LOGD_ONE_STR("[error] EVP_DigestVerifyUpdate failed."); return HCF_ERR_CRYPTO_OPERATION; } impl->status = READY; @@ -315,11 +315,11 @@ static HcfResult EngineVerifyUpdate(HcfVerifySpi *self, HcfBlob *data) static bool EngineVerifyDoFinal(HcfVerifySpi *self, HcfBlob *data, HcfBlob *signatureData) { if ((self == NULL) || (!HcfIsBlobValid(signatureData))) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return false; } if (!HcfIsClassMatch((HcfObjectBase *)self, GetEcdsaVerifyClass())) { - LOGE("Class not match."); + LOGE_ONE_STR("Class not match."); return false; } @@ -327,18 +327,18 @@ static bool EngineVerifyDoFinal(HcfVerifySpi *self, HcfBlob *data, HcfBlob *sign if (HcfIsBlobValid(data)) { if (OpensslEvpDigestVerifyUpdate(impl->ctx, data->data, data->len) != HCF_OPENSSL_SUCCESS) { HcfPrintOpensslError(); - LOGD("[error] EVP_DigestVerifyUpdate failed."); + LOGD_ONE_STR("[error] EVP_DigestVerifyUpdate failed."); return false; } impl->status = READY; } if (impl->status != READY) { - LOGE("The message has not been transferred."); + LOGE_ONE_STR("The message has not been transferred."); return false; } if (OpensslEvpDigestVerifyFinal(impl->ctx, signatureData->data, signatureData->len) != HCF_OPENSSL_SUCCESS) { HcfPrintOpensslError(); - LOGD("[error] EVP_DigestVerifyFinal failed."); + LOGD_ONE_STR("[error] EVP_DigestVerifyFinal failed."); return false; } return true; @@ -411,31 +411,31 @@ static HcfResult EngineSetVerifyEcdsaSpecUint8Array(HcfVerifySpi *self, SignSpec HcfResult HcfSignSpiEcdsaCreate(HcfSignatureParams *params, HcfSignSpi **returnObj) { if ((params == NULL) || (returnObj == NULL)) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return HCF_INVALID_PARAMS; } if (params->algo == HCF_ALG_ECC_BRAINPOOL) { if (!IsBrainPoolDigestAlgValid(params->md)) { - LOGE("Invalid md."); + LOGE_ONE_STR("Invalid md."); return HCF_INVALID_PARAMS; } } else { if (!IsDigestAlgValid(params->md)) { - LOGE("Invalid md."); + LOGE_ONE_STR("Invalid md."); return HCF_INVALID_PARAMS; } } EVP_MD *opensslAlg = NULL; int32_t ret = GetOpensslDigestAlg(params->md, &opensslAlg); if (ret != HCF_SUCCESS || opensslAlg == NULL) { - LOGE("Failed to Invalid digest!"); + LOGE_ONE_STR("Failed to Invalid digest!"); return HCF_INVALID_PARAMS; } HcfSignSpiEcdsaOpensslImpl *returnImpl = (HcfSignSpiEcdsaOpensslImpl *)HcfMalloc( sizeof(HcfSignSpiEcdsaOpensslImpl), 0); if (returnImpl == NULL) { - LOGE("Failed to allocate returnImpl memroy!"); + LOGE_ONE_STR("Failed to allocate returnImpl memroy!"); return HCF_ERR_MALLOC; } returnImpl->base.base.getClass = GetEcdsaSignClass; @@ -451,7 +451,7 @@ HcfResult HcfSignSpiEcdsaCreate(HcfSignatureParams *params, HcfSignSpi **returnO returnImpl->status = UNINITIALIZED; returnImpl->ctx = OpensslEvpMdCtxNew(); if (returnImpl->ctx == NULL) { - LOGE("Failed to allocate ctx memory!"); + LOGE_ONE_STR("Failed to allocate ctx memory!"); HcfFree(returnImpl); return HCF_ERR_MALLOC; } @@ -463,31 +463,31 @@ HcfResult HcfSignSpiEcdsaCreate(HcfSignatureParams *params, HcfSignSpi **returnO HcfResult HcfVerifySpiEcdsaCreate(HcfSignatureParams *params, HcfVerifySpi **returnObj) { if ((params == NULL) || (returnObj == NULL)) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return HCF_INVALID_PARAMS; } if (params->algo == HCF_ALG_ECC_BRAINPOOL) { if (!IsBrainPoolDigestAlgValid(params->md)) { - LOGE("Invalid md."); + LOGE_ONE_STR("Invalid md."); return HCF_INVALID_PARAMS; } } else { if (!IsDigestAlgValid(params->md)) { - LOGE("Invalid md."); + LOGE_ONE_STR("Invalid md."); return HCF_INVALID_PARAMS; } } EVP_MD *opensslAlg = NULL; int32_t ret = GetOpensslDigestAlg(params->md, &opensslAlg); if (ret != HCF_SUCCESS || opensslAlg == NULL) { - LOGE("Failed to Invalid digest!"); + LOGE_ONE_STR("Failed to Invalid digest!"); return HCF_INVALID_PARAMS; } HcfVerifySpiEcdsaOpensslImpl *returnImpl = (HcfVerifySpiEcdsaOpensslImpl *)HcfMalloc( sizeof(HcfVerifySpiEcdsaOpensslImpl), 0); if (returnImpl == NULL) { - LOGE("Failed to allocate returnImpl memroy!"); + LOGE_ONE_STR("Failed to allocate returnImpl memroy!"); return HCF_ERR_MALLOC; } returnImpl->base.base.getClass = GetEcdsaVerifyClass; @@ -503,7 +503,7 @@ HcfResult HcfVerifySpiEcdsaCreate(HcfSignatureParams *params, HcfVerifySpi **ret returnImpl->status = UNINITIALIZED; returnImpl->ctx = OpensslEvpMdCtxNew(); if (returnImpl->ctx == NULL) { - LOGE("Failed to allocate ctx memory!"); + LOGE_ONE_STR("Failed to allocate ctx memory!"); HcfFree(returnImpl); return HCF_ERR_MALLOC; } diff --git a/plugin/openssl_plugin/crypto_operation/signature/src/ed25519_openssl.c b/plugin/openssl_plugin/crypto_operation/signature/src/ed25519_openssl.c index 4c391c64668c06914c776eea721fcdd9725e5553..3e1e1c06a3c9a189386b598f986d87f69cf0b729 100644 --- a/plugin/openssl_plugin/crypto_operation/signature/src/ed25519_openssl.c +++ b/plugin/openssl_plugin/crypto_operation/signature/src/ed25519_openssl.c @@ -60,11 +60,11 @@ static const char *GetEd25519VerifyClass(void) static void DestroyEd25519Sign(HcfObjectBase *self) { if (self == NULL) { - LOGE("Class is null."); + LOGE_ONE_STR("Class is null."); return; } if (!HcfIsClassMatch(self, self->getClass())) { - LOGE("Class not match."); + LOGE_ONE_STR("Class not match."); return; } HcfSignSpiEd25519OpensslImpl *impl = (HcfSignSpiEd25519OpensslImpl *)self; @@ -78,11 +78,11 @@ static void DestroyEd25519Sign(HcfObjectBase *self) static void DestroyEd25519Verify(HcfObjectBase *self) { if (self == NULL) { - LOGE("Class is null."); + LOGE_ONE_STR("Class is null."); return; } if (!HcfIsClassMatch(self, self->getClass())) { - LOGE("Class not match."); + LOGE_ONE_STR("Class not match."); return; } HcfVerifySpiEd25519OpensslImpl *impl = (HcfVerifySpiEd25519OpensslImpl *)self; @@ -97,25 +97,25 @@ static HcfResult EngineSignInit(HcfSignSpi *self, HcfParamsSpec *params, HcfPriK { (void)params; if ((self == NULL) || (privateKey == NULL)) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return HCF_INVALID_PARAMS; } if ((!HcfIsClassMatch((HcfObjectBase *)self, self->base.getClass())) || (!HcfIsClassMatch((HcfObjectBase *)privateKey, OPENSSL_ALG25519_PRIKEY_CLASS))) { - LOGE("Class not match."); + LOGE_ONE_STR("Class not match."); return HCF_INVALID_PARAMS; } HcfSignSpiEd25519OpensslImpl *impl = (HcfSignSpiEd25519OpensslImpl *)self; if (impl->status != UNINITIALIZED) { - LOGE("Repeated initialization is not allowed."); + LOGE_ONE_STR("Repeated initialization is not allowed."); return HCF_INVALID_PARAMS; } if (OpensslEvpDigestSignInit(impl->mdCtx, NULL, NULL, NULL, ((HcfOpensslAlg25519PriKey *)privateKey)->pkey) != HCF_OPENSSL_SUCCESS) { HcfPrintOpensslError(); - LOGD("[error] EVP_DigestSignInit failed."); + LOGD_ONE_STR("[error] EVP_DigestSignInit failed."); return HCF_ERR_CRYPTO_OPERATION; } impl->status = INITIALIZED; @@ -132,36 +132,36 @@ static HcfResult EngineSignUpdate(HcfSignSpi *self, HcfBlob *data) static HcfResult EngineSignDoFinal(HcfSignSpi *self, HcfBlob *data, HcfBlob *returnSignatureData) { if ((self == NULL) || (returnSignatureData == NULL)) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return HCF_INVALID_PARAMS; } if (!HcfIsClassMatch((HcfObjectBase *)self, self->base.getClass())) { - LOGE("Class not match."); + LOGE_ONE_STR("Class not match."); return HCF_INVALID_PARAMS; } if (!HcfIsBlobValid(data)) { - LOGE("Invalid sign data."); + LOGE_ONE_STR("Invalid sign data."); return HCF_INVALID_PARAMS; } HcfSignSpiEd25519OpensslImpl *impl = (HcfSignSpiEd25519OpensslImpl *)self; if (impl->status != INITIALIZED) { - LOGE("The message has not been initialized."); + LOGE_ONE_STR("The message has not been initialized."); return HCF_INVALID_PARAMS; } size_t siglen; if (OpensslEvpDigestSign(impl->mdCtx, NULL, &siglen, data->data, data->len) != HCF_OPENSSL_SUCCESS) { HcfPrintOpensslError(); - LOGD("[error] EVP_DigestSign failed."); + LOGD_ONE_STR("[error] EVP_DigestSign failed."); return HCF_ERR_CRYPTO_OPERATION; } uint8_t *signatureData = (uint8_t *)HcfMalloc(siglen, 0); if (signatureData == NULL) { - LOGE("Failed to allocate signatureData memory!"); + LOGE_ONE_STR("Failed to allocate signatureData memory!"); return HCF_ERR_MALLOC; } if (OpensslEvpDigestSign(impl->mdCtx, signatureData, &siglen, data->data, data->len) != HCF_OPENSSL_SUCCESS) { HcfPrintOpensslError(); - LOGD("[error] EVP_DigestSign failed."); + LOGD_ONE_STR("[error] EVP_DigestSign failed."); HcfFree(signatureData); return HCF_ERR_CRYPTO_OPERATION; } @@ -174,29 +174,29 @@ static HcfResult EngineVerifyInit(HcfVerifySpi *self, HcfParamsSpec *params, Hcf { (void)params; if ((self == NULL) || (publicKey == NULL)) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return HCF_INVALID_PARAMS; } if ((!HcfIsClassMatch((HcfObjectBase *)self, self->base.getClass())) || (!HcfIsClassMatch((HcfObjectBase *)publicKey, OPENSSL_ALG25519_PUBKEY_CLASS))) { - LOGE("Class not match."); + LOGE_ONE_STR("Class not match."); return HCF_INVALID_PARAMS; } HcfVerifySpiEd25519OpensslImpl *impl = (HcfVerifySpiEd25519OpensslImpl *)self; if (impl->status != UNINITIALIZED) { - LOGE("Repeated initialization is not allowed."); + LOGE_ONE_STR("Repeated initialization is not allowed."); return HCF_INVALID_PARAMS; } EVP_PKEY *pKey = OpensslEvpPkeyDup(((HcfOpensslAlg25519PubKey *)publicKey)->pkey); if (pKey == NULL) { HcfPrintOpensslError(); - LOGD("[error] Dup pkey failed."); + LOGD_ONE_STR("[error] Dup pkey failed."); return HCF_ERR_CRYPTO_OPERATION; } if (OpensslEvpDigestVerifyInit(impl->mdCtx, NULL, NULL, NULL, pKey) != HCF_OPENSSL_SUCCESS) { HcfPrintOpensslError(); - LOGD("[error] EVP_DigestVerifyInit failed."); + LOGD_ONE_STR("[error] EVP_DigestVerifyInit failed."); OpensslEvpPkeyFree(pKey); return HCF_ERR_CRYPTO_OPERATION; } @@ -215,26 +215,26 @@ static HcfResult EngineVerifyUpdate(HcfVerifySpi *self, HcfBlob *data) static bool EngineVerifyDoFinal(HcfVerifySpi *self, HcfBlob *data, HcfBlob *signatureData) { if ((self == NULL) || (!HcfIsBlobValid(signatureData))) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return false; } if (!HcfIsClassMatch((HcfObjectBase *)self, self->base.getClass())) { - LOGE("Class not match."); + LOGE_ONE_STR("Class not match."); return false; } if (!HcfIsBlobValid(data)) { - LOGE("Invalid verify data."); + LOGE_ONE_STR("Invalid verify data."); return false; } HcfVerifySpiEd25519OpensslImpl *impl = (HcfVerifySpiEd25519OpensslImpl *)self; if (impl->status != INITIALIZED) { - LOGE("The message has not been initialized."); + LOGE_ONE_STR("The message has not been initialized."); return false; } if (OpensslEvpDigestVerify(impl->mdCtx, signatureData->data, signatureData->len, data->data, data->len) != HCF_OPENSSL_SUCCESS) { HcfPrintOpensslError(); - LOGD("[error] EVP_DigestVerify failed."); + LOGD_ONE_STR("[error] EVP_DigestVerify failed."); return false; } return true; @@ -308,14 +308,14 @@ HcfResult HcfSignSpiEd25519Create(HcfSignatureParams *params, HcfSignSpi **retur { (void)params; if ((params == NULL) || (returnObj == NULL)) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return HCF_INVALID_PARAMS; } HcfSignSpiEd25519OpensslImpl *returnImpl = (HcfSignSpiEd25519OpensslImpl *)HcfMalloc( sizeof(HcfSignSpiEd25519OpensslImpl), 0); if (returnImpl == NULL) { - LOGE("Failed to allocate returnImpl memroy!"); + LOGE_ONE_STR("Failed to allocate returnImpl memroy!"); return HCF_ERR_MALLOC; } returnImpl->base.base.getClass = GetEd25519SignClass; @@ -330,7 +330,7 @@ HcfResult HcfSignSpiEd25519Create(HcfSignatureParams *params, HcfSignSpi **retur returnImpl->status = UNINITIALIZED; returnImpl->mdCtx = OpensslEvpMdCtxNew(); if (returnImpl->mdCtx == NULL) { - LOGE("Failed to allocate mdCtx memory!"); + LOGE_ONE_STR("Failed to allocate mdCtx memory!"); HcfFree(returnImpl); return HCF_ERR_MALLOC; } @@ -343,14 +343,14 @@ HcfResult HcfVerifySpiEd25519Create(HcfSignatureParams *params, HcfVerifySpi **r { (void)params; if ((params == NULL) || (returnObj == NULL)) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return HCF_INVALID_PARAMS; } HcfVerifySpiEd25519OpensslImpl *returnImpl = (HcfVerifySpiEd25519OpensslImpl *)HcfMalloc( sizeof(HcfVerifySpiEd25519OpensslImpl), 0); if (returnImpl == NULL) { - LOGE("Failed to allocate returnImpl memroy!"); + LOGE_ONE_STR("Failed to allocate returnImpl memroy!"); return HCF_ERR_MALLOC; } returnImpl->base.base.getClass = GetEd25519VerifyClass; @@ -365,7 +365,7 @@ HcfResult HcfVerifySpiEd25519Create(HcfSignatureParams *params, HcfVerifySpi **r returnImpl->status = UNINITIALIZED; returnImpl->mdCtx = OpensslEvpMdCtxNew(); if (returnImpl->mdCtx == NULL) { - LOGE("Failed to allocate mdCtx memory!"); + LOGE_ONE_STR("Failed to allocate mdCtx memory!"); HcfFree(returnImpl); return HCF_ERR_MALLOC; } diff --git a/plugin/openssl_plugin/crypto_operation/signature/src/signature_rsa_openssl.c b/plugin/openssl_plugin/crypto_operation/signature/src/signature_rsa_openssl.c index 4ac193d4a344b497cb8408fca435fbc3f62ef760..02349d8a170dc8c9e39c7b77f13f47332d7b3e82 100644 --- a/plugin/openssl_plugin/crypto_operation/signature/src/signature_rsa_openssl.c +++ b/plugin/openssl_plugin/crypto_operation/signature/src/signature_rsa_openssl.c @@ -88,11 +88,11 @@ static const char *GetRsaVerifyClass(void) static void DestroyRsaSign(HcfObjectBase *self) { if (self == NULL) { - LOGE("Class is null"); + LOGE_ONE_STR("Class is null"); return; } if (!HcfIsClassMatch(self, OPENSSL_RSA_SIGN_CLASS)) { - LOGE("Class not match."); + LOGE_ONE_STR("Class not match."); return; } HcfSignSpiRsaOpensslImpl *impl = (HcfSignSpiRsaOpensslImpl *)self; @@ -109,11 +109,11 @@ static void DestroyRsaSign(HcfObjectBase *self) static void DestroyRsaVerify(HcfObjectBase *self) { if (self == NULL) { - LOGE("Class is null"); + LOGE_ONE_STR("Class is null"); return; } if (!HcfIsClassMatch(self, OPENSSL_RSA_VERIFY_CLASS)) { - LOGE("Class not match."); + LOGE_ONE_STR("Class not match."); return; } HcfVerifySpiRsaOpensslImpl *impl = (HcfVerifySpiRsaOpensslImpl *)self; @@ -130,12 +130,12 @@ static HcfResult CheckInitKeyType(HcfKey *key, bool signing) { if (signing) { if (!HcfIsClassMatch((HcfObjectBase *)key, OPENSSL_RSA_PRIKEY_CLASS)) { - LOGE("Input keyType dismatch with sign option, please use priKey."); + LOGE_ONE_STR("Input keyType dismatch with sign option, please use priKey."); return HCF_INVALID_PARAMS; } } else { if (!HcfIsClassMatch((HcfObjectBase *)key, OPENSSL_RSA_PUBKEY_CLASS)) { - LOGE("Input keyType dismatch with sign option, please use pubKey."); + LOGE_ONE_STR("Input keyType dismatch with sign option, please use pubKey."); return HCF_INVALID_PARAMS; } } @@ -148,22 +148,22 @@ static EVP_PKEY *InitRsaEvpKey(const HcfKey *key, bool signing) if (signing == true) { // dup will check if rsa is NULL if (DuplicateRsa(((HcfOpensslRsaPriKey *)key)->sk, signing, &rsa) != HCF_SUCCESS) { - LOGE("dup pri RSA fail"); + LOGE_ONE_STR("dup pri RSA fail"); return NULL; } } else if (signing == false) { if (DuplicateRsa(((HcfOpensslRsaPubKey *)key)->pk, signing, &rsa) != HCF_SUCCESS) { - LOGE("dup pub RSA fail"); + LOGE_ONE_STR("dup pub RSA fail"); return NULL; } } if (rsa == NULL) { - LOGE("The Key has lost."); + LOGE_ONE_STR("The Key has lost."); return NULL; } EVP_PKEY *pkey = NewEvpPkeyByRsa(rsa, false); if (pkey == NULL) { - LOGD("[error] New evp pkey failed"); + LOGD_ONE_STR("[error] New evp pkey failed"); HcfPrintOpensslError(); OpensslRsaFree(rsa); return NULL; @@ -177,16 +177,16 @@ static HcfResult SetPaddingAndDigest(EVP_PKEY_CTX *ctx, int32_t hcfPadding, int3 int32_t opensslPadding = 0; (void)GetOpensslPadding(hcfPadding, &opensslPadding); if (OpensslEvpPkeyCtxSetRsaPadding(ctx, opensslPadding) != HCF_OPENSSL_SUCCESS) { - LOGD("[error] OpensslEvpPkeyCtxSetRsaPadding fail"); + LOGD_ONE_STR("[error] OpensslEvpPkeyCtxSetRsaPadding fail"); HcfPrintOpensslError(); return HCF_ERR_CRYPTO_OPERATION; } if (hcfPadding == HCF_OPENSSL_RSA_PSS_PADDING) { - LOGD("padding is pss, set mgf1 md"); + LOGD_ONE_STR("padding is pss, set mgf1 md"); EVP_MD *opensslAlg = NULL; (void)GetOpensslDigestAlg(mgf1md, &opensslAlg); if (OpensslEvpPkeyCtxSetRsaMgf1Md(ctx, opensslAlg) != HCF_OPENSSL_SUCCESS) { - LOGD("[error] EVP_PKEY_CTX_set_rsa_mgf1_md fail"); + LOGD_ONE_STR("[error] EVP_PKEY_CTX_set_rsa_mgf1_md fail"); HcfPrintOpensslError(); return HCF_ERR_CRYPTO_OPERATION; } @@ -198,7 +198,7 @@ static HcfResult SetOnlySignParams(HcfSignSpiRsaOpensslImpl *impl, HcfPriKey *pr { EVP_PKEY *dupKey = InitRsaEvpKey((HcfKey *)privateKey, true); if (dupKey == NULL) { - LOGD("InitRsaEvpKey fail."); + LOGD_ONE_STR("InitRsaEvpKey fail."); return HCF_ERR_CRYPTO_OPERATION; } EVP_PKEY_CTX *ctx = NULL; @@ -207,17 +207,17 @@ static HcfResult SetOnlySignParams(HcfSignSpiRsaOpensslImpl *impl, HcfPriKey *pr ctx = OpensslEvpPkeyCtxNewFromPkey(NULL, dupKey, NULL); OpensslEvpPkeyFree(dupKey); if (ctx == NULL) { - LOGD("OpensslEvpPkeyCtxNew fail."); + LOGD_ONE_STR("OpensslEvpPkeyCtxNew fail."); return HCF_ERR_CRYPTO_OPERATION; } if (OpensslEvpPkeySignInit(ctx) != HCF_OPENSSL_SUCCESS) { - LOGD("OpensslEvpPkeySignInit fail."); + LOGD_ONE_STR("OpensslEvpPkeySignInit fail."); OpensslEvpPkeyCtxFree(ctx); return HCF_ERR_CRYPTO_OPERATION; } if (opensslAlg != NULL) { if (OpensslEvpPkeyCtxSetSignatureMd(ctx, opensslAlg) != HCF_OPENSSL_SUCCESS) { - LOGD("OpensslEvpPkeyCtxSetSignatureMd fail."); + LOGD_ONE_STR("OpensslEvpPkeyCtxSetSignatureMd fail."); OpensslEvpPkeyCtxFree(ctx); return HCF_ERR_CRYPTO_OPERATION; } @@ -225,7 +225,7 @@ static HcfResult SetOnlySignParams(HcfSignSpiRsaOpensslImpl *impl, HcfPriKey *pr int32_t opensslPadding = 0; (void)GetOpensslPadding(impl->padding, &opensslPadding); if (OpensslEvpPkeyCtxSetRsaPadding(ctx, opensslPadding) != HCF_OPENSSL_SUCCESS) { - LOGD("OpensslEvpPkeyCtxSetRsaPadding fail"); + LOGD_ONE_STR("OpensslEvpPkeyCtxSetRsaPadding fail"); OpensslEvpPkeyCtxFree(ctx); return HCF_ERR_CRYPTO_OPERATION; } @@ -240,7 +240,7 @@ static HcfResult SetSignParams(HcfSignSpiRsaOpensslImpl *impl, HcfPriKey *privat } EVP_PKEY *dupKey = InitRsaEvpKey((HcfKey *)privateKey, true); if (dupKey == NULL) { - LOGD("[error] InitRsaEvpKey fail."); + LOGD_ONE_STR("[error] InitRsaEvpKey fail."); return HCF_ERR_CRYPTO_OPERATION; } EVP_PKEY_CTX *ctx = NULL; @@ -248,22 +248,22 @@ static HcfResult SetSignParams(HcfSignSpiRsaOpensslImpl *impl, HcfPriKey *privat (void)GetOpensslDigestAlg(impl->md, &opensslAlg); if (opensslAlg == NULL) { OpensslEvpPkeyFree(dupKey); - LOGE("Get openssl digest alg fail"); + LOGE_ONE_STR("Get openssl digest alg fail"); return HCF_INVALID_PARAMS; } int ret = OpensslEvpDigestSignInit(impl->mdctx, &ctx, opensslAlg, NULL, dupKey); OpensslEvpPkeyFree(dupKey); if (ret != HCF_OPENSSL_SUCCESS) { - LOGD("[error] OpensslEvpDigestSignInit fail."); + LOGD_ONE_STR("[error] OpensslEvpDigestSignInit fail."); return HCF_ERR_CRYPTO_OPERATION; } if (SetPaddingAndDigest(ctx, impl->padding, impl->md, impl->mgf1md) != HCF_SUCCESS) { - LOGD("[error] set padding and digest fail"); + LOGD_ONE_STR("[error] set padding and digest fail"); return HCF_ERR_CRYPTO_OPERATION; } if (impl->saltLen != PSS_SALTLEN_INVALID_INIT) { if (OpensslEvpPkeyCtxSetRsaPssSaltLen(ctx, impl->saltLen) != HCF_OPENSSL_SUCCESS) { - LOGD("[error] get saltLen fail"); + LOGD_ONE_STR("[error] get saltLen fail"); return HCF_ERR_CRYPTO_OPERATION; } } @@ -275,20 +275,20 @@ static HcfResult EngineSignInit(HcfSignSpi *self, HcfParamsSpec *params, HcfPriK { (void)params; if (self == NULL || privateKey == NULL) { - LOGE("Invalid input params"); + LOGE_ONE_STR("Invalid input params"); return HCF_INVALID_PARAMS; } if (!HcfIsClassMatch((HcfObjectBase *)self, OPENSSL_RSA_SIGN_CLASS)) { - LOGE("Class not match."); + LOGE_ONE_STR("Class not match."); return HCF_INVALID_PARAMS; } HcfSignSpiRsaOpensslImpl *impl = (HcfSignSpiRsaOpensslImpl *)self; if (impl->initFlag != UNINITIALIZED) { - LOGE("Sign has been init"); + LOGE_ONE_STR("Sign has been init"); return HCF_INVALID_PARAMS; } if (CheckInitKeyType((HcfKey *)privateKey, true) != HCF_SUCCESS) { - LOGE("KeyType dismatch."); + LOGE_ONE_STR("KeyType dismatch."); return HCF_INVALID_PARAMS; } @@ -297,7 +297,7 @@ static HcfResult EngineSignInit(HcfSignSpi *self, HcfParamsSpec *params, HcfPriK HcfPrintOpensslError(); } if (ret != HCF_SUCCESS) { - LOGD("[error] Sign set padding or md fail"); + LOGD_ONE_STR("[error] Sign set padding or md fail"); return ret; } impl->initFlag = INITIALIZED; @@ -309,30 +309,30 @@ static HcfResult SetVerifyParams(HcfVerifySpiRsaOpensslImpl *impl, HcfPubKey *pu EVP_PKEY_CTX *ctx = NULL; EVP_PKEY *dupKey = InitRsaEvpKey((HcfKey *)publicKey, false); if (dupKey == NULL) { - LOGD("[error] InitRsaEvpKey fail."); + LOGD_ONE_STR("[error] InitRsaEvpKey fail."); return HCF_ERR_CRYPTO_OPERATION; } EVP_MD *opensslAlg = NULL; (void)GetOpensslDigestAlg(impl->md, &opensslAlg); if (opensslAlg == NULL) { OpensslEvpPkeyFree(dupKey); - LOGE("Get openssl digest alg fail"); + LOGE_ONE_STR("Get openssl digest alg fail"); return HCF_INVALID_PARAMS; } int ret = OpensslEvpDigestVerifyInit(impl->mdctx, &ctx, opensslAlg, NULL, dupKey); OpensslEvpPkeyFree(dupKey); if (ret != HCF_OPENSSL_SUCCESS) { - LOGD("[error] OpensslEvpDigestVerifyInit fail."); + LOGD_ONE_STR("[error] OpensslEvpDigestVerifyInit fail."); HcfPrintOpensslError(); return HCF_ERR_CRYPTO_OPERATION; } if (SetPaddingAndDigest(ctx, impl->padding, impl->md, impl->mgf1md) != HCF_SUCCESS) { - LOGD("[error] set padding and digest fail"); + LOGD_ONE_STR("[error] set padding and digest fail"); return HCF_ERR_CRYPTO_OPERATION; } if (impl->saltLen != PSS_SALTLEN_INVALID_INIT) { if (OpensslEvpPkeyCtxSetRsaPssSaltLen(ctx, impl->saltLen) != HCF_OPENSSL_SUCCESS) { - LOGD("[error] get saltLen fail"); + LOGD_ONE_STR("[error] get saltLen fail"); return HCF_ERR_CRYPTO_OPERATION; } } @@ -344,7 +344,7 @@ static HcfResult SetVerifyRecoverParams(HcfVerifySpiRsaOpensslImpl *impl, HcfPub { EVP_PKEY *dupKey = InitRsaEvpKey((HcfKey *)publicKey, false); if (dupKey == NULL) { - LOGD("[error] InitRsaEvpKey fail."); + LOGD_ONE_STR("[error] InitRsaEvpKey fail."); return HCF_ERR_CRYPTO_OPERATION; } @@ -352,13 +352,13 @@ static HcfResult SetVerifyRecoverParams(HcfVerifySpiRsaOpensslImpl *impl, HcfPub ctx = OpensslEvpPkeyCtxNewFromPkey(NULL, dupKey, NULL); OpensslEvpPkeyFree(dupKey); if (ctx == NULL) { - LOGD("[error] OpensslEvpPkeyCtxNewFromPkey fail."); + LOGD_ONE_STR("[error] OpensslEvpPkeyCtxNewFromPkey fail."); HcfPrintOpensslError(); return HCF_ERR_CRYPTO_OPERATION; } if (OpensslEvpPkeyVerifyRecoverInit(ctx) != HCF_OPENSSL_SUCCESS) { - LOGD("[error] OpensslEvpPkeyVerifyRecoverInit fail"); + LOGD_ONE_STR("[error] OpensslEvpPkeyVerifyRecoverInit fail"); HcfPrintOpensslError(); OpensslEvpPkeyCtxFree(ctx); return HCF_ERR_CRYPTO_OPERATION; @@ -367,7 +367,7 @@ static HcfResult SetVerifyRecoverParams(HcfVerifySpiRsaOpensslImpl *impl, HcfPub int32_t opensslPadding = 0; (void)GetOpensslPadding(impl->padding, &opensslPadding); if (OpensslEvpPkeyCtxSetRsaPadding(ctx, opensslPadding) != HCF_OPENSSL_SUCCESS) { - LOGD("[error] OpensslEvpPkeyCtxSetRsaPadding fail"); + LOGD_ONE_STR("[error] OpensslEvpPkeyCtxSetRsaPadding fail"); HcfPrintOpensslError(); OpensslEvpPkeyCtxFree(ctx); return HCF_ERR_CRYPTO_OPERATION; @@ -377,7 +377,7 @@ static HcfResult SetVerifyRecoverParams(HcfVerifySpiRsaOpensslImpl *impl, HcfPub (void)GetOpensslDigestAlg(impl->md, &opensslAlg); if (opensslAlg != NULL) { if (OpensslEvpPkeyCtxSetSignatureMd(ctx, opensslAlg) != HCF_OPENSSL_SUCCESS) { - LOGD("[error] EVP_PKEY_CTX_set_rsa_mgf1_md fail"); + LOGD_ONE_STR("[error] EVP_PKEY_CTX_set_rsa_mgf1_md fail"); HcfPrintOpensslError(); OpensslEvpPkeyCtxFree(ctx); return HCF_ERR_CRYPTO_OPERATION; @@ -392,31 +392,31 @@ static HcfResult EngineVerifyInit(HcfVerifySpi *self, HcfParamsSpec *params, Hcf { (void)params; if (self == NULL || publicKey == NULL) { - LOGE("Invalid input params."); + LOGE_ONE_STR("Invalid input params."); return HCF_INVALID_PARAMS; } if (!HcfIsClassMatch((HcfObjectBase *)self, OPENSSL_RSA_VERIFY_CLASS)) { - LOGE("Class not match."); + LOGE_ONE_STR("Class not match."); return HCF_INVALID_PARAMS; } HcfVerifySpiRsaOpensslImpl *impl = (HcfVerifySpiRsaOpensslImpl *)self; if (impl->initFlag != UNINITIALIZED) { - LOGE("Verigy has been init."); + LOGE_ONE_STR("Verigy has been init."); return HCF_INVALID_PARAMS; } if (CheckInitKeyType((HcfKey *)publicKey, false) != HCF_SUCCESS) { - LOGE("KeyType dismatch."); + LOGE_ONE_STR("KeyType dismatch."); return HCF_INVALID_PARAMS; } if (impl->operation == RSA_DIGEST_VERIFY) { if (SetVerifyParams(impl, publicKey) != HCF_SUCCESS) { - LOGD("[error] Verify set padding or md fail"); + LOGD_ONE_STR("[error] Verify set padding or md fail"); return HCF_ERR_CRYPTO_OPERATION; } } else { if (SetVerifyRecoverParams(impl, publicKey) != HCF_SUCCESS) { - LOGD("[error] VerifyRecover set padding or md fail"); + LOGD_ONE_STR("[error] VerifyRecover set padding or md fail"); return HCF_ERR_CRYPTO_OPERATION; } } @@ -428,24 +428,24 @@ static HcfResult EngineVerifyInit(HcfVerifySpi *self, HcfParamsSpec *params, Hcf static HcfResult EngineSignUpdate(HcfSignSpi *self, HcfBlob *data) { if ((self == NULL) || (data == NULL) || (data->data == NULL)) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return HCF_INVALID_PARAMS; } if (!HcfIsClassMatch((HcfObjectBase *)self, OPENSSL_RSA_SIGN_CLASS)) { - LOGE("Class not match."); + LOGE_ONE_STR("Class not match."); return HCF_INVALID_PARAMS; } HcfSignSpiRsaOpensslImpl *impl = (HcfSignSpiRsaOpensslImpl *)self; if (impl->initFlag != INITIALIZED) { - LOGE("The Sign has not been init"); + LOGE_ONE_STR("The Sign has not been init"); return HCF_INVALID_PARAMS; } if (impl->operation == HCF_OPERATIOPN_ONLY_SIGN) { - LOGE("Update cannot support in OnlySign"); + LOGE_ONE_STR("Update cannot support in OnlySign"); return HCF_ERR_CRYPTO_OPERATION; } if (OpensslEvpDigestSignUpdate(impl->mdctx, data->data, data->len) != HCF_OPENSSL_SUCCESS) { - LOGD("[error] OpensslEvpDigestSignUpdate fail"); + LOGD_ONE_STR("[error] OpensslEvpDigestSignUpdate fail"); return HCF_ERR_CRYPTO_OPERATION; } return HCF_SUCCESS; @@ -454,26 +454,26 @@ static HcfResult EngineSignUpdate(HcfSignSpi *self, HcfBlob *data) static HcfResult EngineVerifyUpdate(HcfVerifySpi *self, HcfBlob *data) { if ((self == NULL) || (data == NULL) || (data->data == NULL)) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return HCF_INVALID_PARAMS; } if (!HcfIsClassMatch((HcfObjectBase *)self, OPENSSL_RSA_VERIFY_CLASS)) { - LOGE("Class not match."); + LOGE_ONE_STR("Class not match."); return HCF_INVALID_PARAMS; } HcfVerifySpiRsaOpensslImpl *impl = (HcfVerifySpiRsaOpensslImpl *)self; if (impl->initFlag != INITIALIZED) { - LOGE("The Sign has not been init"); + LOGE_ONE_STR("The Sign has not been init"); return HCF_INVALID_PARAMS; } if (impl->operation != RSA_DIGEST_VERIFY) { - LOGE("Invalid digest verify operation."); + LOGE_ONE_STR("Invalid digest verify operation."); return HCF_ERR_CRYPTO_OPERATION; } if (OpensslEvpDigestVerifyUpdate(impl->mdctx, data->data, data->len) != HCF_OPENSSL_SUCCESS) { - LOGD("[error] OpensslEvpDigestSignUpdate fail"); + LOGD_ONE_STR("[error] OpensslEvpDigestSignUpdate fail"); return HCF_ERR_CRYPTO_OPERATION; } return HCF_SUCCESS; @@ -482,23 +482,23 @@ static HcfResult EngineVerifyUpdate(HcfVerifySpi *self, HcfBlob *data) static HcfResult EnginePkeySign(HcfSignSpiRsaOpensslImpl *impl, HcfBlob *data, HcfBlob *returnSignatureData) { if (data == NULL || data->len == 0 || data->data == NULL) { - LOGE("Invalid input params."); + LOGE_ONE_STR("Invalid input params."); return HCF_INVALID_PARAMS; } size_t maxLen; if (OpensslEvpPkeySign(impl->ctx, NULL, &maxLen, data->data, data->len) != HCF_OPENSSL_SUCCESS) { - LOGE("OpensslEvpPkeySign get maxLen fail"); + LOGE_ONE_STR("OpensslEvpPkeySign get maxLen fail"); return HCF_ERR_CRYPTO_OPERATION; } LOGD("sign maxLen is %zu", maxLen); uint8_t *outData = (uint8_t *)HcfMalloc(maxLen, 0); if (outData == NULL) { - LOGE("Failed to allocate outData memory!"); + LOGE_ONE_STR("Failed to allocate outData memory!"); return HCF_ERR_MALLOC; } size_t actualLen = maxLen; if (OpensslEvpPkeySign(impl->ctx, outData, &actualLen, data->data, data->len) != HCF_OPENSSL_SUCCESS) { - LOGE("OpensslEvpPkeySign fail"); + LOGE_ONE_STR("OpensslEvpPkeySign fail"); HcfFree(outData); return HCF_ERR_CRYPTO_OPERATION; } @@ -511,25 +511,25 @@ static HcfResult EngineDigestSign(HcfSignSpiRsaOpensslImpl *impl, HcfBlob *data, { if (data != NULL && data->data != NULL) { if (OpensslEvpDigestSignUpdate(impl->mdctx, data->data, data->len) != HCF_OPENSSL_SUCCESS) { - LOGD("[error] Dofinal update data fail."); + LOGD_ONE_STR("[error] Dofinal update data fail."); return HCF_ERR_CRYPTO_OPERATION; } } size_t maxLen; if (OpensslEvpDigestSignFinal(impl->mdctx, NULL, &maxLen) != HCF_OPENSSL_SUCCESS) { - LOGD("[error] OpensslEvpDigestSignFinal fail"); + LOGD_ONE_STR("[error] OpensslEvpDigestSignFinal fail"); return HCF_ERR_CRYPTO_OPERATION; } LOGD("sign maxLen is %zu", maxLen); uint8_t *outData = (uint8_t *)HcfMalloc(maxLen, 0); if (outData == NULL) { - LOGE("Failed to allocate outData memory!"); + LOGE_ONE_STR("Failed to allocate outData memory!"); return HCF_ERR_MALLOC; } if (OpensslEvpDigestSignFinal(impl->mdctx, outData, &maxLen) != HCF_OPENSSL_SUCCESS) { - LOGD("[error] OpensslEvpDigestSignFinal fail"); + LOGD_ONE_STR("[error] OpensslEvpDigestSignFinal fail"); HcfFree(outData); HcfPrintOpensslError(); return HCF_ERR_CRYPTO_OPERATION; @@ -542,16 +542,16 @@ static HcfResult EngineDigestSign(HcfSignSpiRsaOpensslImpl *impl, HcfBlob *data, static HcfResult EngineSign(HcfSignSpi *self, HcfBlob *data, HcfBlob *returnSignatureData) { if (self == NULL || returnSignatureData == NULL) { - LOGE("Invalid input params."); + LOGE_ONE_STR("Invalid input params."); return HCF_INVALID_PARAMS; } if (!HcfIsClassMatch((HcfObjectBase *)self, OPENSSL_RSA_SIGN_CLASS)) { - LOGE("Class not match."); + LOGE_ONE_STR("Class not match."); return HCF_INVALID_PARAMS; } HcfSignSpiRsaOpensslImpl *impl = (HcfSignSpiRsaOpensslImpl *)self; if (impl->initFlag != INITIALIZED) { - LOGE("The Sign has not been init"); + LOGE_ONE_STR("The Sign has not been init"); return HCF_INVALID_PARAMS; } @@ -568,33 +568,33 @@ static HcfResult EngineSign(HcfSignSpi *self, HcfBlob *data, HcfBlob *returnSign static bool EngineVerify(HcfVerifySpi *self, HcfBlob *data, HcfBlob *signatureData) { if (self == NULL || signatureData == NULL || signatureData->data == NULL) { - LOGE("Invalid input params"); + LOGE_ONE_STR("Invalid input params"); return false; } if (!HcfIsClassMatch((HcfObjectBase *)self, OPENSSL_RSA_VERIFY_CLASS)) { - LOGE("Class not match."); + LOGE_ONE_STR("Class not match."); return false; } HcfVerifySpiRsaOpensslImpl *impl = (HcfVerifySpiRsaOpensslImpl *)self; if (impl->initFlag != INITIALIZED) { - LOGE("The Sign has not been init"); + LOGE_ONE_STR("The Sign has not been init"); return false; } if (impl->operation != RSA_DIGEST_VERIFY) { - LOGE("Invalid digest verify operation."); + LOGE_ONE_STR("Invalid digest verify operation."); return false; } if (data != NULL && data->data != NULL) { if (OpensslEvpDigestVerifyUpdate(impl->mdctx, data->data, data->len) != HCF_OPENSSL_SUCCESS) { - LOGD("[error] OpensslEvpDigestVerifyUpdate fail"); + LOGD_ONE_STR("[error] OpensslEvpDigestVerifyUpdate fail"); return false; } } if (OpensslEvpDigestVerifyFinal(impl->mdctx, signatureData->data, signatureData->len) != HCF_OPENSSL_SUCCESS) { - LOGD("[error] OpensslEvpDigestVerifyFinal fail"); + LOGD_ONE_STR("[error] OpensslEvpDigestVerifyFinal fail"); return false; } return true; @@ -603,42 +603,42 @@ static bool EngineVerify(HcfVerifySpi *self, HcfBlob *data, HcfBlob *signatureDa static HcfResult EngineRecover(HcfVerifySpi *self, HcfBlob *signatureData, HcfBlob *rawSignatureData) { if (self == NULL || signatureData == NULL || signatureData->data == NULL || rawSignatureData == NULL) { - LOGE("Invalid input params"); + LOGE_ONE_STR("Invalid input params"); return HCF_INVALID_PARAMS; } if (!HcfIsClassMatch((HcfObjectBase *)self, OPENSSL_RSA_VERIFY_CLASS)) { - LOGE("Class not match."); + LOGE_ONE_STR("Class not match."); return HCF_INVALID_PARAMS; } HcfVerifySpiRsaOpensslImpl *impl = (HcfVerifySpiRsaOpensslImpl *)self; if (impl->initFlag != INITIALIZED) { - LOGE("The Sign has not been init."); + LOGE_ONE_STR("The Sign has not been init."); return HCF_ERR_CRYPTO_OPERATION; } if (impl->operation != RSA_VERIFY_RECOVER) { - LOGE("Invalid verify recover operation."); + LOGE_ONE_STR("Invalid verify recover operation."); return HCF_ERR_CRYPTO_OPERATION; } size_t bufLen = 0; if (OpensslEvpPkeyVerifyRecover(impl->ctx, NULL, &bufLen, signatureData->data, signatureData->len) != HCF_OPENSSL_SUCCESS) { - LOGE("[error] OpensslEvpPkeyVerifyRecover get len fail."); + LOGE_ONE_STR("[error] OpensslEvpPkeyVerifyRecover get len fail."); HcfPrintOpensslError(); return HCF_ERR_CRYPTO_OPERATION; } uint8_t *buf = (uint8_t *)HcfMalloc((uint32_t)bufLen, 0); if (buf == NULL) { - LOGE("[error] HcfMalloc fail"); + LOGE_ONE_STR("[error] HcfMalloc fail"); return HCF_ERR_MALLOC; } if (OpensslEvpPkeyVerifyRecover(impl->ctx, buf, &bufLen, signatureData->data, signatureData->len) != HCF_OPENSSL_SUCCESS) { - LOGE("[error] OpensslEvpPkeyVerifyRecover fail."); + LOGE_ONE_STR("[error] OpensslEvpPkeyVerifyRecover fail."); HcfPrintOpensslError(); HcfFree(buf); buf = NULL; @@ -654,17 +654,17 @@ static HcfResult CheckOnlySignatureParams(HcfSignatureParams *params) { int32_t opensslPadding = 0; if (GetOpensslPadding(params->padding, &opensslPadding) != HCF_SUCCESS) { - LOGE("getpadding fail."); + LOGE_ONE_STR("getpadding fail."); return HCF_INVALID_PARAMS; } if (opensslPadding != RSA_PKCS1_PADDING && opensslPadding != RSA_NO_PADDING) { - LOGE("only signature cannot use that padding mode."); + LOGE_ONE_STR("only signature cannot use that padding mode."); return HCF_INVALID_PARAMS; } EVP_MD *md = NULL; HcfResult ret = GetOpensslDigestAlg(params->md, &md); if (ret != HCF_SUCCESS) { - LOGE("Md is invalid."); + LOGE_ONE_STR("Md is invalid."); return HCF_INVALID_PARAMS; } @@ -678,24 +678,24 @@ static HcfResult CheckSignatureParams(HcfSignatureParams *params) } int32_t opensslPadding = 0; if (GetOpensslPadding(params->padding, &opensslPadding) != HCF_SUCCESS) { - LOGE("getpadding fail."); + LOGE_ONE_STR("getpadding fail."); return HCF_INVALID_PARAMS; } if (opensslPadding != RSA_PKCS1_PADDING && opensslPadding != RSA_PKCS1_PSS_PADDING) { - LOGE("signature cannot use that padding mode"); + LOGE_ONE_STR("signature cannot use that padding mode"); return HCF_INVALID_PARAMS; } EVP_MD *md = NULL; (void)GetOpensslDigestAlg(params->md, &md); if (md == NULL) { - LOGE("Md is NULL"); + LOGE_ONE_STR("Md is NULL"); return HCF_INVALID_PARAMS; } if (params->padding == HCF_OPENSSL_RSA_PSS_PADDING) { EVP_MD *mgf1md = NULL; (void)GetOpensslDigestAlg(params->mgf1md, &mgf1md); if (mgf1md == NULL) { - LOGE("Use pss padding, but mgf1md is NULL"); + LOGE_ONE_STR("Use pss padding, but mgf1md is NULL"); return HCF_INVALID_PARAMS; } } @@ -705,15 +705,15 @@ static HcfResult CheckSignatureParams(HcfSignatureParams *params) static HcfResult EngineSetSignSpecInt(HcfSignSpi *self, SignSpecItem item, int32_t saltLen) { if (self == NULL) { - LOGE("Invalid input parameter"); + LOGE_ONE_STR("Invalid input parameter"); return HCF_INVALID_PARAMS; } if (item != PSS_SALT_LEN_INT) { - LOGE("Invalid sign spec item"); + LOGE_ONE_STR("Invalid sign spec item"); return HCF_INVALID_PARAMS; } if (!HcfIsClassMatch((HcfObjectBase *)self, OPENSSL_RSA_SIGN_CLASS)) { - LOGE("Class not match."); + LOGE_ONE_STR("Class not match."); return HCF_INVALID_PARAMS; } if (saltLen < 0) { @@ -726,37 +726,37 @@ static HcfResult EngineSetSignSpecInt(HcfSignSpi *self, SignSpecItem item, int32 } HcfSignSpiRsaOpensslImpl *impl = (HcfSignSpiRsaOpensslImpl *)self; if (impl->padding != HCF_OPENSSL_RSA_PSS_PADDING) { - LOGE("Only support pss parameter"); + LOGE_ONE_STR("Only support pss parameter"); return HCF_INVALID_PARAMS; } impl->saltLen = saltLen; if (impl->initFlag == INITIALIZED) { if (OpensslEvpPkeyCtxSetRsaPssSaltLen(impl->ctx, saltLen) != HCF_OPENSSL_SUCCESS) { - LOGD("[error] set saltLen fail"); + LOGD_ONE_STR("[error] set saltLen fail"); return HCF_ERR_CRYPTO_OPERATION; } } - LOGD("Set sign saltLen success"); + LOGD_ONE_STR("Set sign saltLen success"); return HCF_SUCCESS; } static HcfResult EngineGetSignSpecInt(HcfSignSpi *self, SignSpecItem item, int32_t *returnInt) { if (self == NULL || returnInt == NULL) { - LOGE("Invalid input parameter"); + LOGE_ONE_STR("Invalid input parameter"); return HCF_INVALID_PARAMS; } if (!HcfIsClassMatch((HcfObjectBase *)self, OPENSSL_RSA_SIGN_CLASS)) { - LOGE("Class not match."); + LOGE_ONE_STR("Class not match."); return HCF_INVALID_PARAMS; } if (item != PSS_TRAILER_FIELD_INT && item != PSS_SALT_LEN_INT) { - LOGE("Invalid input spec"); + LOGE_ONE_STR("Invalid input spec"); return HCF_INVALID_PARAMS; } HcfSignSpiRsaOpensslImpl *impl = (HcfSignSpiRsaOpensslImpl *)self; if (impl->padding != HCF_OPENSSL_RSA_PSS_PADDING) { - LOGE("Only support pss parameter"); + LOGE_ONE_STR("Only support pss parameter"); return HCF_INVALID_PARAMS; } if (item == PSS_TRAILER_FIELD_INT) { @@ -769,12 +769,12 @@ static HcfResult EngineGetSignSpecInt(HcfSignSpi *self, SignSpecItem item, int32 } if (impl->initFlag == INITIALIZED) { if (OpensslEvpPkeyCtxGetRsaPssSaltLen(impl->ctx, returnInt) != HCF_OPENSSL_SUCCESS) { - LOGD("[error] get saltLen fail"); + LOGD_ONE_STR("[error] get saltLen fail"); return HCF_ERR_CRYPTO_OPERATION; } return HCF_SUCCESS; } else { - LOGE("No set saltLen and not init!"); + LOGE_ONE_STR("No set saltLen and not init!"); return HCF_INVALID_PARAMS; } } @@ -790,16 +790,16 @@ static HcfResult EngineSetSignSpecUint8Array(HcfSignSpi *self, SignSpecItem item static HcfResult EngineGetSignSpecString(HcfSignSpi *self, SignSpecItem item, char **returnString) { if (self == NULL || returnString == NULL) { - LOGE("Invalid input parameter"); + LOGE_ONE_STR("Invalid input parameter"); return HCF_INVALID_PARAMS; } if (!HcfIsClassMatch((HcfObjectBase *)self, OPENSSL_RSA_SIGN_CLASS)) { - LOGE("Class not match."); + LOGE_ONE_STR("Class not match."); return HCF_INVALID_PARAMS; } HcfSignSpiRsaOpensslImpl *impl = (HcfSignSpiRsaOpensslImpl *)self; if (impl->padding != HCF_OPENSSL_RSA_PSS_PADDING) { - LOGE("Only support pss parameter"); + LOGE_ONE_STR("Only support pss parameter"); return HCF_INVALID_PARAMS; } HcfResult ret = HCF_INVALID_PARAMS; @@ -815,7 +815,7 @@ static HcfResult EngineGetSignSpecString(HcfSignSpi *self, SignSpecItem item, ch ret = GetRsaSpecStringMd((const HcfAlgParaValue)(impl->mgf1md), returnString); break; default: - LOGE("Invalid input sign spec item"); + LOGE_ONE_STR("Invalid input sign spec item"); return HCF_INVALID_PARAMS; } return ret; @@ -824,15 +824,15 @@ static HcfResult EngineGetSignSpecString(HcfSignSpi *self, SignSpecItem item, ch static HcfResult EngineSetVerifySpecInt(HcfVerifySpi *self, SignSpecItem item, int32_t saltLen) { if (self == NULL) { - LOGE("Invalid input parameter"); + LOGE_ONE_STR("Invalid input parameter"); return HCF_INVALID_PARAMS; } if (item != PSS_SALT_LEN_INT) { - LOGE("Invalid verify spec item"); + LOGE_ONE_STR("Invalid verify spec item"); return HCF_INVALID_PARAMS; } if (!HcfIsClassMatch((HcfObjectBase *)self, OPENSSL_RSA_VERIFY_CLASS)) { - LOGE("Class not match."); + LOGE_ONE_STR("Class not match."); return HCF_INVALID_PARAMS; } if (saltLen < 0) { @@ -845,13 +845,13 @@ static HcfResult EngineSetVerifySpecInt(HcfVerifySpi *self, SignSpecItem item, i } HcfVerifySpiRsaOpensslImpl *impl = (HcfVerifySpiRsaOpensslImpl *)self; if (impl->padding != HCF_OPENSSL_RSA_PSS_PADDING) { - LOGE("Only support pss parameter"); + LOGE_ONE_STR("Only support pss parameter"); return HCF_INVALID_PARAMS; } impl->saltLen = saltLen; if (impl->initFlag == INITIALIZED) { if (OpensslEvpPkeyCtxSetRsaPssSaltLen(impl->ctx, saltLen) != HCF_OPENSSL_SUCCESS) { - LOGD("[error] set saltLen fail"); + LOGD_ONE_STR("[error] set saltLen fail"); return HCF_ERR_CRYPTO_OPERATION; } } @@ -861,20 +861,20 @@ static HcfResult EngineSetVerifySpecInt(HcfVerifySpi *self, SignSpecItem item, i static HcfResult EngineGetVerifySpecInt(HcfVerifySpi *self, SignSpecItem item, int32_t *returnInt) { if (self == NULL || returnInt == NULL) { - LOGE("Invalid input parameter"); + LOGE_ONE_STR("Invalid input parameter"); return HCF_INVALID_PARAMS; } if (!HcfIsClassMatch((HcfObjectBase *)self, OPENSSL_RSA_VERIFY_CLASS)) { - LOGE("Class not match."); + LOGE_ONE_STR("Class not match."); return HCF_INVALID_PARAMS; } if (item != PSS_TRAILER_FIELD_INT && item != PSS_SALT_LEN_INT) { - LOGE("Invalid input sign spec item"); + LOGE_ONE_STR("Invalid input sign spec item"); return HCF_INVALID_PARAMS; } HcfVerifySpiRsaOpensslImpl *impl = (HcfVerifySpiRsaOpensslImpl *)self; if (impl->padding != HCF_OPENSSL_RSA_PSS_PADDING) { - LOGE("Only support pss parameter"); + LOGE_ONE_STR("Only support pss parameter"); return HCF_INVALID_PARAMS; } if (item == PSS_TRAILER_FIELD_INT) { @@ -887,12 +887,12 @@ static HcfResult EngineGetVerifySpecInt(HcfVerifySpi *self, SignSpecItem item, i } if (impl->initFlag == INITIALIZED) { if (OpensslEvpPkeyCtxGetRsaPssSaltLen(impl->ctx, returnInt) != HCF_OPENSSL_SUCCESS) { - LOGD("[error] get saltLen fail"); + LOGD_ONE_STR("[error] get saltLen fail"); return HCF_ERR_CRYPTO_OPERATION; } return HCF_SUCCESS; } else { - LOGE("No set saltLen and not init!"); + LOGE_ONE_STR("No set saltLen and not init!"); return HCF_INVALID_PARAMS; } } @@ -908,16 +908,16 @@ static HcfResult EngineSetVerifySpecUint8Array(HcfVerifySpi *self, SignSpecItem static HcfResult EngineGetVerifySpecString(HcfVerifySpi *self, SignSpecItem item, char **returnString) { if (self == NULL || returnString == NULL) { - LOGE("Invalid input parameter"); + LOGE_ONE_STR("Invalid input parameter"); return HCF_INVALID_PARAMS; } if (!HcfIsClassMatch((HcfObjectBase *)self, OPENSSL_RSA_VERIFY_CLASS)) { - LOGE("Class not match."); + LOGE_ONE_STR("Class not match."); return HCF_INVALID_PARAMS; } HcfVerifySpiRsaOpensslImpl *impl = (HcfVerifySpiRsaOpensslImpl *)self; if (impl->padding != HCF_OPENSSL_RSA_PSS_PADDING) { - LOGE("Only support pss parameter"); + LOGE_ONE_STR("Only support pss parameter"); return HCF_INVALID_PARAMS; } HcfResult ret = HCF_INVALID_PARAMS; @@ -933,7 +933,7 @@ static HcfResult EngineGetVerifySpecString(HcfVerifySpi *self, SignSpecItem item ret = GetRsaSpecStringMd((const HcfAlgParaValue)(impl->mgf1md), returnString); break; default: - LOGE("Invalid input sign spec item"); + LOGE_ONE_STR("Invalid input sign spec item"); return HCF_INVALID_PARAMS; } return ret; @@ -942,7 +942,7 @@ static HcfResult EngineGetVerifySpecString(HcfVerifySpi *self, SignSpecItem item HcfResult HcfSignSpiRsaCreate(HcfSignatureParams *params, HcfSignSpi **returnObj) { if (params == NULL || returnObj == NULL) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return HCF_INVALID_PARAMS; } if (CheckSignatureParams(params) != HCF_SUCCESS) { @@ -951,7 +951,7 @@ HcfResult HcfSignSpiRsaCreate(HcfSignatureParams *params, HcfSignSpi **returnObj HcfSignSpiRsaOpensslImpl *returnImpl = (HcfSignSpiRsaOpensslImpl *)HcfMalloc( sizeof(HcfSignSpiRsaOpensslImpl), 0); if (returnImpl == NULL) { - LOGE("Failed to allocate returnImpl memroy!"); + LOGE_ONE_STR("Failed to allocate returnImpl memroy!"); return HCF_ERR_MALLOC; } returnImpl->base.base.getClass = GetRsaSignClass; @@ -968,7 +968,7 @@ HcfResult HcfSignSpiRsaCreate(HcfSignatureParams *params, HcfSignSpi **returnObj returnImpl->mgf1md = params->mgf1md; returnImpl->mdctx = OpensslEvpMdCtxNew(); if (returnImpl->mdctx == NULL) { - LOGE("Failed to allocate md ctx!"); + LOGE_ONE_STR("Failed to allocate md ctx!"); HcfFree(returnImpl); return HCF_ERR_MALLOC; } @@ -983,11 +983,11 @@ static HcfResult CheckVerifyRecoverParams(HcfSignatureParams *params) { int32_t opensslPadding = 0; if (GetOpensslPadding(params->padding, &opensslPadding) != HCF_SUCCESS) { - LOGE("getpadding fail."); + LOGE_ONE_STR("getpadding fail."); return HCF_INVALID_PARAMS; } if (opensslPadding != RSA_PKCS1_PADDING && opensslPadding != RSA_NO_PADDING) { - LOGE("VerifyRecover cannot use that padding mode"); + LOGE_ONE_STR("VerifyRecover cannot use that padding mode"); return HCF_INVALID_PARAMS; } return HCF_SUCCESS; @@ -996,7 +996,7 @@ static HcfResult CheckVerifyRecoverParams(HcfSignatureParams *params) HcfResult HcfVerifySpiRsaCreate(HcfSignatureParams *params, HcfVerifySpi **returnObj) { if (params == NULL || returnObj == NULL) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return HCF_INVALID_PARAMS; } if (params->operation != HCF_ALG_VERIFY_RECOVER) { @@ -1012,7 +1012,7 @@ HcfResult HcfVerifySpiRsaCreate(HcfSignatureParams *params, HcfVerifySpi **retur HcfVerifySpiRsaOpensslImpl *returnImpl = (HcfVerifySpiRsaOpensslImpl *)HcfMalloc( sizeof(HcfVerifySpiRsaOpensslImpl), 0); if (returnImpl == NULL) { - LOGE("Failed to allocate returnImpl memroy!"); + LOGE_ONE_STR("Failed to allocate returnImpl memroy!"); return HCF_ERR_MALLOC; } returnImpl->base.base.getClass = GetRsaVerifyClass; @@ -1031,7 +1031,7 @@ HcfResult HcfVerifySpiRsaCreate(HcfSignatureParams *params, HcfVerifySpi **retur returnImpl->mgf1md = params->mgf1md; returnImpl->mdctx = OpensslEvpMdCtxNew(); if (returnImpl->mdctx == NULL) { - LOGE("Failed to allocate md ctx!"); + LOGE_ONE_STR("Failed to allocate md ctx!"); HcfFree(returnImpl); return HCF_ERR_MALLOC; } diff --git a/plugin/openssl_plugin/crypto_operation/signature/src/sm2_openssl.c b/plugin/openssl_plugin/crypto_operation/signature/src/sm2_openssl.c index f2f57bcc9ac7b3aa6b36f6368a52b74173520c93..5a04c5c1e3694af0c8d91b09cd93883f1ed3a2ae 100644 --- a/plugin/openssl_plugin/crypto_operation/signature/src/sm2_openssl.c +++ b/plugin/openssl_plugin/crypto_operation/signature/src/sm2_openssl.c @@ -60,7 +60,7 @@ static bool IsDigestAlgValid(uint32_t alg) if (alg == HCF_OPENSSL_DIGEST_SM3) { return true; } else { - LOGE("Invalid digest num!"); + LOGE_ONE_STR("Invalid digest num!"); return false; } } @@ -79,11 +79,11 @@ static const char *GetSm2VerifyClass(void) static void DestroySm2Sign(HcfObjectBase *self) { if (self == NULL) { - LOGE("Class is null."); + LOGE_ONE_STR("Class is null."); return; } if (!HcfIsClassMatch(self, self->getClass())) { - LOGE("Class not match."); + LOGE_ONE_STR("Class not match."); return; } HcfSignSpiSm2OpensslImpl *impl = (HcfSignSpiSm2OpensslImpl *)self; @@ -101,11 +101,11 @@ static void DestroySm2Sign(HcfObjectBase *self) static void DestroySm2Verify(HcfObjectBase *self) { if (self == NULL) { - LOGE("Class is null."); + LOGE_ONE_STR("Class is null."); return; } if (!HcfIsClassMatch(self, self->getClass())) { - LOGE("Class not match."); + LOGE_ONE_STR("Class not match."); return; } HcfVerifySpiSm2OpensslImpl *impl = (HcfVerifySpiSm2OpensslImpl *)self; @@ -123,14 +123,14 @@ static HcfResult SetUserIdFromBlob(HcfBlob userId, EVP_MD_CTX *mdCtx) { EVP_PKEY_CTX *pKeyCtx = OpensslEvpMdCtxGetPkeyCtx(mdCtx); if (pKeyCtx == NULL) { - LOGD("[error] get pKey ctx fail."); + LOGD_ONE_STR("[error] get pKey ctx fail."); HcfPrintOpensslError(); return HCF_ERR_CRYPTO_OPERATION; } // If userId is NULL or len is 0, the userId will be cleared. if (userId.data == NULL || userId.len == 0) { if (OpensslEvpPkeyCtxSet1Id(pKeyCtx, NULL, 0) != HCF_OPENSSL_SUCCESS) { - LOGD("[error] Openssl Set userId fail"); + LOGD_ONE_STR("[error] Openssl Set userId fail"); HcfPrintOpensslError(); return HCF_ERR_CRYPTO_OPERATION; } @@ -139,7 +139,7 @@ static HcfResult SetUserIdFromBlob(HcfBlob userId, EVP_MD_CTX *mdCtx) } if (OpensslEvpPkeyCtxSet1Id(pKeyCtx, (const void*)userId.data, userId.len) != HCF_OPENSSL_SUCCESS) { - LOGD("[error] Set sm2 user id fail."); + LOGD_ONE_STR("[error] Set sm2 user id fail."); HcfPrintOpensslError(); return HCF_ERR_CRYPTO_OPERATION; } @@ -151,13 +151,13 @@ static HcfResult SetSM2Id(EVP_MD_CTX *mdCtx, EVP_PKEY *pKey, HcfBlob userId) { EVP_PKEY_CTX *pKeyCtx = OpensslEvpPkeyCtxNew(pKey, NULL); if (pKeyCtx == NULL) { - LOGD("[error] new EVP_PKEY_CTX fail"); + LOGD_ONE_STR("[error] new EVP_PKEY_CTX fail"); HcfPrintOpensslError(); return HCF_ERR_CRYPTO_OPERATION; } if (OpensslEvpPkeyCtxSet1Id(pKeyCtx, (const void*)userId.data, userId.len) != HCF_OPENSSL_SUCCESS) { - LOGD("[error] Set sm2 user id fail"); + LOGD_ONE_STR("[error] Set sm2 user id fail"); HcfPrintOpensslError(); OpensslEvpPkeyCtxFree(pKeyCtx); return HCF_ERR_CRYPTO_OPERATION; @@ -169,17 +169,17 @@ static HcfResult SetSM2Id(EVP_MD_CTX *mdCtx, EVP_PKEY *pKey, HcfBlob userId) static bool IsSm2SignInitInputValid(HcfSignSpi *self, HcfPriKey *privateKey) { if ((self == NULL) || (privateKey == NULL)) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return false; } if ((!HcfIsClassMatch((HcfObjectBase *)self, self->base.getClass())) || (!HcfIsClassMatch((HcfObjectBase *)privateKey, HCF_OPENSSL_SM2_PRI_KEY_CLASS))) { - LOGE("Class not match."); + LOGE_ONE_STR("Class not match."); return false; } HcfSignSpiSm2OpensslImpl *impl = (HcfSignSpiSm2OpensslImpl *)self; if (impl->status != UNINITIALIZED) { - LOGE("Repeated initialization is not allowed."); + LOGE_ONE_STR("Repeated initialization is not allowed."); return false; } return true; @@ -195,19 +195,19 @@ static HcfResult EngineSignInit(HcfSignSpi *self, HcfParamsSpec *params, HcfPriK EC_KEY *ecKey = OpensslEcKeyDup(((HcfOpensslSm2PriKey *)privateKey)->ecKey); if (ecKey == NULL) { HcfPrintOpensslError(); - LOGD("[error] Dup ecKey failed."); + LOGD_ONE_STR("[error] Dup ecKey failed."); return HCF_ERR_CRYPTO_OPERATION; } EVP_PKEY *pKey = OpensslEvpPkeyNew(); if (pKey == NULL) { HcfPrintOpensslError(); - LOGD("[error] New pKey failed."); + LOGD_ONE_STR("[error] New pKey failed."); OpensslEcKeyFree(ecKey); return HCF_ERR_CRYPTO_OPERATION; } if (OpensslEvpPkeyAssignEcKey(pKey, ecKey) != HCF_OPENSSL_SUCCESS) { HcfPrintOpensslError(); - LOGD("[error] EVP_PKEY_assign_EC_KEY failed."); + LOGD_ONE_STR("[error] EVP_PKEY_assign_EC_KEY failed."); OpensslEcKeyFree(ecKey); OpensslEvpPkeyFree(pKey); return HCF_ERR_CRYPTO_OPERATION; @@ -216,12 +216,12 @@ static HcfResult EngineSignInit(HcfSignSpi *self, HcfParamsSpec *params, HcfPriK HcfSignSpiSm2OpensslImpl *impl = (HcfSignSpiSm2OpensslImpl *)self; if (SetSM2Id(impl->mdCtx, pKey, impl->userId) != HCF_SUCCESS) { OpensslEvpPkeyFree(pKey); - LOGD("[error] Set sm2 user id failed."); + LOGD_ONE_STR("[error] Set sm2 user id failed."); return HCF_ERR_CRYPTO_OPERATION; } if (OpensslEvpDigestSignInit(impl->mdCtx, NULL, impl->digestAlg, NULL, pKey) != HCF_OPENSSL_SUCCESS) { HcfPrintOpensslError(); - LOGD("[error] EVP_DigestSignInit failed."); + LOGD_ONE_STR("[error] EVP_DigestSignInit failed."); OpensslEvpPkeyFree(pKey); return HCF_ERR_CRYPTO_OPERATION; } @@ -233,21 +233,21 @@ static HcfResult EngineSignInit(HcfSignSpi *self, HcfParamsSpec *params, HcfPriK static HcfResult EngineSignUpdate(HcfSignSpi *self, HcfBlob *data) { if ((self == NULL) || (!HcfIsBlobValid(data))) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return HCF_INVALID_PARAMS; } if (!HcfIsClassMatch((HcfObjectBase *)self, self->base.getClass())) { - LOGE("Class not match."); + LOGE_ONE_STR("Class not match."); return HCF_INVALID_PARAMS; } HcfSignSpiSm2OpensslImpl *impl = (HcfSignSpiSm2OpensslImpl *)self; if (impl->status == UNINITIALIZED) { - LOGE("Sign object has not been initialized."); + LOGE_ONE_STR("Sign object has not been initialized."); return HCF_INVALID_PARAMS; } if (OpensslEvpDigestSignUpdate(impl->mdCtx, data->data, data->len) != HCF_OPENSSL_SUCCESS) { HcfPrintOpensslError(); - LOGD("[error] EVP_DigestSignUpdate failed."); + LOGD_ONE_STR("[error] EVP_DigestSignUpdate failed."); return HCF_ERR_CRYPTO_OPERATION; } impl->status = READY; @@ -257,11 +257,11 @@ static HcfResult EngineSignUpdate(HcfSignSpi *self, HcfBlob *data) static HcfResult EngineSignDoFinal(HcfSignSpi *self, HcfBlob *data, HcfBlob *returnSignatureData) { if ((self == NULL) || (returnSignatureData == NULL)) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return HCF_INVALID_PARAMS; } if (!HcfIsClassMatch((HcfObjectBase *)self, self->base.getClass())) { - LOGE("Class not match."); + LOGE_ONE_STR("Class not match."); return HCF_INVALID_PARAMS; } @@ -269,30 +269,30 @@ static HcfResult EngineSignDoFinal(HcfSignSpi *self, HcfBlob *data, HcfBlob *ret if (HcfIsBlobValid(data)) { if (OpensslEvpDigestSignUpdate(impl->mdCtx, data->data, data->len) != HCF_OPENSSL_SUCCESS) { HcfPrintOpensslError(); - LOGD("[error] EVP_DigestSignUpdate failed."); + LOGD_ONE_STR("[error] EVP_DigestSignUpdate failed."); return HCF_ERR_CRYPTO_OPERATION; } impl->status = READY; } if (impl->status != READY) { - LOGE("The message has not been transferred."); + LOGE_ONE_STR("The message has not been transferred."); return HCF_INVALID_PARAMS; } size_t maxLen; if (OpensslEvpDigestSignFinal(impl->mdCtx, NULL, &maxLen) != HCF_OPENSSL_SUCCESS) { HcfPrintOpensslError(); - LOGD("[error] EVP_DigestSignFinal failed."); + LOGD_ONE_STR("[error] EVP_DigestSignFinal failed."); return HCF_ERR_CRYPTO_OPERATION; } uint8_t *outData = (uint8_t *)HcfMalloc(maxLen, 0); if (outData == NULL) { - LOGE("Failed to allocate outData memory!"); + LOGE_ONE_STR("Failed to allocate outData memory!"); return HCF_ERR_MALLOC; } if (OpensslEvpDigestSignFinal(impl->mdCtx, outData, &maxLen) != HCF_OPENSSL_SUCCESS) { HcfPrintOpensslError(); - LOGD("[error] EVP_DigestSignFinal failed."); + LOGD_ONE_STR("[error] EVP_DigestSignFinal failed."); HcfFree(outData); return HCF_ERR_CRYPTO_OPERATION; } @@ -305,18 +305,18 @@ static HcfResult EngineSignDoFinal(HcfSignSpi *self, HcfBlob *data, HcfBlob *ret static bool IsSm2VerifyInitInputValid(HcfVerifySpi *self, HcfPubKey *publicKey) { if ((self == NULL) || (publicKey == NULL)) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return false; } if ((!HcfIsClassMatch((HcfObjectBase *)self, self->base.getClass())) || (!HcfIsClassMatch((HcfObjectBase *)publicKey, HCF_OPENSSL_SM2_PUB_KEY_CLASS))) { - LOGE("Class not match."); + LOGE_ONE_STR("Class not match."); return false; } HcfVerifySpiSm2OpensslImpl *impl = (HcfVerifySpiSm2OpensslImpl *)self; if (impl->status != UNINITIALIZED) { - LOGE("Repeated initialization is not allowed."); + LOGE_ONE_STR("Repeated initialization is not allowed."); return false; } return true; @@ -332,32 +332,32 @@ static HcfResult EngineVerifyInit(HcfVerifySpi *self, HcfParamsSpec *params, Hcf EC_KEY *ecKey = OpensslEcKeyDup(((HcfOpensslSm2PubKey *)publicKey)->ecKey); if (ecKey == NULL) { HcfPrintOpensslError(); - LOGD("[error] Dup ecKey failed."); + LOGD_ONE_STR("[error] Dup ecKey failed."); return HCF_ERR_CRYPTO_OPERATION; } EVP_PKEY *pKey = OpensslEvpPkeyNew(); if (pKey == NULL) { HcfPrintOpensslError(); - LOGD("[error] New pKey failed."); + LOGD_ONE_STR("[error] New pKey failed."); OpensslEcKeyFree(ecKey); return HCF_ERR_CRYPTO_OPERATION; } if (OpensslEvpPkeyAssignEcKey(pKey, ecKey) != HCF_OPENSSL_SUCCESS) { HcfPrintOpensslError(); - LOGD("[error] EVP_PKEY_assign_EC_KEY failed."); + LOGD_ONE_STR("[error] EVP_PKEY_assign_EC_KEY failed."); OpensslEcKeyFree(ecKey); OpensslEvpPkeyFree(pKey); return HCF_ERR_CRYPTO_OPERATION; } HcfVerifySpiSm2OpensslImpl *impl = (HcfVerifySpiSm2OpensslImpl *)self; if (SetSM2Id(impl->mdCtx, pKey, impl->userId) != HCF_SUCCESS) { - LOGD("[error] Set sm2 user id failed."); + LOGD_ONE_STR("[error] Set sm2 user id failed."); OpensslEvpPkeyFree(pKey); return HCF_ERR_CRYPTO_OPERATION; } if (OpensslEvpDigestVerifyInit(impl->mdCtx, NULL, impl->digestAlg, NULL, pKey) != HCF_OPENSSL_SUCCESS) { HcfPrintOpensslError(); - LOGD("[error] EVP_DigestVerifyInit failed."); + LOGD_ONE_STR("[error] EVP_DigestVerifyInit failed."); OpensslEvpPkeyFree(pKey); return HCF_ERR_CRYPTO_OPERATION; } @@ -369,22 +369,22 @@ static HcfResult EngineVerifyInit(HcfVerifySpi *self, HcfParamsSpec *params, Hcf static HcfResult EngineVerifyUpdate(HcfVerifySpi *self, HcfBlob *data) { if ((self == NULL) || (!HcfIsBlobValid(data))) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return HCF_INVALID_PARAMS; } if (!HcfIsClassMatch((HcfObjectBase *)self, self->base.getClass())) { - LOGE("Class not match."); + LOGE_ONE_STR("Class not match."); return HCF_INVALID_PARAMS; } HcfVerifySpiSm2OpensslImpl *impl = (HcfVerifySpiSm2OpensslImpl *)self; if (impl->status == UNINITIALIZED) { - LOGE("Verify object has not been initialized."); + LOGE_ONE_STR("Verify object has not been initialized."); return HCF_INVALID_PARAMS; } if (OpensslEvpDigestVerifyUpdate(impl->mdCtx, data->data, data->len) != HCF_OPENSSL_SUCCESS) { HcfPrintOpensslError(); - LOGD("[error] EVP_DigestVerifyUpdate failed."); + LOGD_ONE_STR("[error] EVP_DigestVerifyUpdate failed."); return HCF_ERR_CRYPTO_OPERATION; } impl->status = READY; @@ -394,11 +394,11 @@ static HcfResult EngineVerifyUpdate(HcfVerifySpi *self, HcfBlob *data) static bool EngineVerifyDoFinal(HcfVerifySpi *self, HcfBlob *data, HcfBlob *signatureData) { if ((self == NULL) || (!HcfIsBlobValid(signatureData))) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return false; } if (!HcfIsClassMatch((HcfObjectBase *)self, self->base.getClass())) { - LOGE("Class not match."); + LOGE_ONE_STR("Class not match."); return false; } @@ -406,18 +406,18 @@ static bool EngineVerifyDoFinal(HcfVerifySpi *self, HcfBlob *data, HcfBlob *sign if (HcfIsBlobValid(data)) { if (OpensslEvpDigestVerifyUpdate(impl->mdCtx, data->data, data->len) != HCF_OPENSSL_SUCCESS) { HcfPrintOpensslError(); - LOGD("[error] EVP_DigestVerifyUpdate failed."); + LOGD_ONE_STR("[error] EVP_DigestVerifyUpdate failed."); return false; } impl->status = READY; } if (impl->status != READY) { - LOGE("The message has not been transferred."); + LOGE_ONE_STR("The message has not been transferred."); return false; } if (OpensslEvpDigestVerifyFinal(impl->mdCtx, signatureData->data, signatureData->len) != HCF_OPENSSL_SUCCESS) { HcfPrintOpensslError(); - LOGD("[error] EVP_DigestVerifyFinal failed."); + LOGD_ONE_STR("[error] EVP_DigestVerifyFinal failed."); return false; } return true; @@ -434,15 +434,15 @@ static HcfResult EngineGetSignSpecString(HcfSignSpi *self, SignSpecItem item, ch static HcfResult EngineSetSignSpecUint8Array(HcfSignSpi *self, SignSpecItem item, HcfBlob userId) { if (self == NULL) { - LOGE("Invalid input parameter"); + LOGE_ONE_STR("Invalid input parameter"); return HCF_INVALID_PARAMS; } if (!HcfIsClassMatch((HcfObjectBase *)self, OPENSSL_SM2_SIGN_CLASS)) { - LOGE("Class not match."); + LOGE_ONE_STR("Class not match."); return HCF_INVALID_PARAMS; } if (item != SM2_USER_ID_UINT8ARR) { - LOGE("Invalid input spec"); + LOGE_ONE_STR("Invalid input spec"); return HCF_INVALID_PARAMS; } HcfSignSpiSm2OpensslImpl *impl = (HcfSignSpiSm2OpensslImpl *)self; @@ -459,11 +459,11 @@ static HcfResult EngineSetSignSpecUint8Array(HcfSignSpi *self, SignSpecItem item // deep copy two userId, one for impl struct and one for openssl. impl->userId.data = (uint8_t *)HcfMalloc(userId.len, 0); if (impl->userId.data == NULL) { - LOGE("Failed to allocate userId data memory"); + LOGE_ONE_STR("Failed to allocate userId data memory"); return HCF_ERR_MALLOC; } if (memcpy_s(impl->userId.data, userId.len, userId.data, userId.len) != EOK) { - LOGE("memcpy userId failed."); + LOGE_ONE_STR("memcpy userId failed."); HcfFree(impl->userId.data); return HCF_ERR_MALLOC; } @@ -474,7 +474,7 @@ static HcfResult EngineSetSignSpecUint8Array(HcfSignSpi *self, SignSpecItem item if (impl->status == INITIALIZED) { HcfResult ret = SetUserIdFromBlob(impl->userId, impl->mdCtx); if (ret != HCF_SUCCESS) { - LOGE("Set userId fail"); + LOGE_ONE_STR("Set userId fail"); HcfFree(impl->userId.data); impl->userId.data = NULL; return ret; @@ -510,15 +510,15 @@ static HcfResult EngineGetVerifySpecString(HcfVerifySpi *self, SignSpecItem item static HcfResult EngineSetVerifySpecUint8Array(HcfVerifySpi *self, SignSpecItem item, HcfBlob userId) { if (self == NULL) { - LOGE("Invalid input parameter"); + LOGE_ONE_STR("Invalid input parameter"); return HCF_INVALID_PARAMS; } if (!HcfIsClassMatch((HcfObjectBase *)self, OPENSSL_SM2_VERIFY_CLASS)) { - LOGE("Class not match."); + LOGE_ONE_STR("Class not match."); return HCF_INVALID_PARAMS; } if (item != SM2_USER_ID_UINT8ARR) { - LOGE("Invalid input spec"); + LOGE_ONE_STR("Invalid input spec"); return HCF_INVALID_PARAMS; } HcfVerifySpiSm2OpensslImpl *impl = (HcfVerifySpiSm2OpensslImpl *)self; @@ -535,11 +535,11 @@ static HcfResult EngineSetVerifySpecUint8Array(HcfVerifySpi *self, SignSpecItem // deep copy two userId, one for impl struct and one for openssl. impl->userId.data = (uint8_t *)HcfMalloc(userId.len, 0); if (impl->userId.data == NULL) { - LOGE("Failed to allocate userId data memory"); + LOGE_ONE_STR("Failed to allocate userId data memory"); return HCF_ERR_MALLOC; } if (memcpy_s(impl->userId.data, userId.len, userId.data, userId.len) != EOK) { - LOGE("memcpy userId failed."); + LOGE_ONE_STR("memcpy userId failed."); HcfFree(impl->userId.data); return HCF_ERR_MALLOC; } @@ -550,7 +550,7 @@ static HcfResult EngineSetVerifySpecUint8Array(HcfVerifySpi *self, SignSpecItem if (impl->status == INITIALIZED) { HcfResult ret = SetUserIdFromBlob(impl->userId, impl->mdCtx); if (ret != HCF_SUCCESS) { - LOGE("Set userId fail"); + LOGE_ONE_STR("Set userId fail"); HcfFree(impl->userId.data); impl->userId.data = NULL; return ret; @@ -578,11 +578,11 @@ static HcfResult EngineSetVerifySpecInt(HcfVerifySpi *self, SignSpecItem item, i static HcfResult CheckSignInputParamsAndDigest(HcfSignatureParams *params, HcfSignSpi **returnObj) { if ((params == NULL) || (returnObj == NULL)) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return HCF_INVALID_PARAMS; } if (!IsDigestAlgValid(params->md)) { - LOGE("Invalid input md parameter."); + LOGE_ONE_STR("Invalid input md parameter."); return HCF_INVALID_PARAMS; } return HCF_SUCCESS; @@ -591,11 +591,11 @@ static HcfResult CheckSignInputParamsAndDigest(HcfSignatureParams *params, HcfSi static HcfResult CheckVerifyInputParamsAndDigest(HcfSignatureParams *params, HcfVerifySpi **returnObj) { if ((params == NULL) || (returnObj == NULL)) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return HCF_INVALID_PARAMS; } if (!IsDigestAlgValid(params->md)) { - LOGE("Invalid input md parameter."); + LOGE_ONE_STR("Invalid input md parameter."); return HCF_INVALID_PARAMS; } return HCF_SUCCESS; @@ -604,20 +604,20 @@ static HcfResult CheckVerifyInputParamsAndDigest(HcfSignatureParams *params, Hcf HcfResult HcfSignSpiSm2Create(HcfSignatureParams *params, HcfSignSpi **returnObj) { if (CheckSignInputParamsAndDigest(params, returnObj) != HCF_SUCCESS) { - LOGE("Check input params and digest failed."); + LOGE_ONE_STR("Check input params and digest failed."); return HCF_INVALID_PARAMS; } EVP_MD *opensslAlg = NULL; int32_t ret = GetOpensslDigestAlg(params->md, &opensslAlg); if (ret != HCF_SUCCESS || opensslAlg == NULL) { - LOGE("Failed to Invalid digest!"); + LOGE_ONE_STR("Failed to Invalid digest!"); return HCF_INVALID_PARAMS; } HcfSignSpiSm2OpensslImpl *returnImpl = (HcfSignSpiSm2OpensslImpl *)HcfMalloc( sizeof(HcfSignSpiSm2OpensslImpl), 0); if (returnImpl == NULL) { - LOGE("Failed to allocate returnImpl memroy!"); + LOGE_ONE_STR("Failed to allocate returnImpl memroy!"); return HCF_ERR_MALLOC; } returnImpl->base.base.getClass = GetSm2SignClass; @@ -633,7 +633,7 @@ HcfResult HcfSignSpiSm2Create(HcfSignatureParams *params, HcfSignSpi **returnObj returnImpl->status = UNINITIALIZED; returnImpl->userId.data = (uint8_t *)HcfMalloc(strlen(SM2_DEFAULT_USERID) + 1, 0); if (returnImpl->userId.data == NULL) { - LOGE("Failed to allocate userId data memory"); + LOGE_ONE_STR("Failed to allocate userId data memory"); HcfFree(returnImpl); return HCF_ERR_MALLOC; } @@ -641,7 +641,7 @@ HcfResult HcfSignSpiSm2Create(HcfSignatureParams *params, HcfSignSpi **returnObj returnImpl->userId.len = strlen(SM2_DEFAULT_USERID); returnImpl->mdCtx = OpensslEvpMdCtxNew(); if (returnImpl->mdCtx == NULL) { - LOGE("Failed to allocate mdCtx memory!"); + LOGE_ONE_STR("Failed to allocate mdCtx memory!"); HcfFree(returnImpl->userId.data); HcfFree(returnImpl); return HCF_ERR_MALLOC; @@ -654,20 +654,20 @@ HcfResult HcfSignSpiSm2Create(HcfSignatureParams *params, HcfSignSpi **returnObj HcfResult HcfVerifySpiSm2Create(HcfSignatureParams *params, HcfVerifySpi **returnObj) { if (CheckVerifyInputParamsAndDigest(params, returnObj) != HCF_SUCCESS) { - LOGE("Check input params and digest failed."); + LOGE_ONE_STR("Check input params and digest failed."); return HCF_INVALID_PARAMS; } EVP_MD *opensslAlg = NULL; int32_t ret = GetOpensslDigestAlg(params->md, &opensslAlg); if (ret != HCF_SUCCESS || opensslAlg == NULL) { - LOGE("Failed to Invalid digest!"); + LOGE_ONE_STR("Failed to Invalid digest!"); return HCF_INVALID_PARAMS; } HcfVerifySpiSm2OpensslImpl *returnImpl = (HcfVerifySpiSm2OpensslImpl *)HcfMalloc( sizeof(HcfVerifySpiSm2OpensslImpl), 0); if (returnImpl == NULL) { - LOGE("Failed to allocate returnImpl memroy!"); + LOGE_ONE_STR("Failed to allocate returnImpl memroy!"); return HCF_ERR_MALLOC; } returnImpl->base.base.getClass = GetSm2VerifyClass; @@ -683,7 +683,7 @@ HcfResult HcfVerifySpiSm2Create(HcfSignatureParams *params, HcfVerifySpi **retur returnImpl->status = UNINITIALIZED; returnImpl->userId.data = (uint8_t *)HcfMalloc(strlen(SM2_DEFAULT_USERID) + 1, 0); if (returnImpl->userId.data == NULL) { - LOGE("Failed to allocate userId data memory"); + LOGE_ONE_STR("Failed to allocate userId data memory"); HcfFree(returnImpl); return HCF_ERR_MALLOC; } @@ -691,7 +691,7 @@ HcfResult HcfVerifySpiSm2Create(HcfSignatureParams *params, HcfVerifySpi **retur returnImpl->userId.len = strlen(SM2_DEFAULT_USERID); returnImpl->mdCtx = OpensslEvpMdCtxNew(); if (returnImpl->mdCtx == NULL) { - LOGE("Failed to allocate mdCtx memory!"); + LOGE_ONE_STR("Failed to allocate mdCtx memory!"); HcfFree(returnImpl->userId.data); HcfFree(returnImpl); return HCF_ERR_MALLOC; diff --git a/plugin/openssl_plugin/key/asy_key_generator/src/alg_25519_asy_key_generator_openssl.c b/plugin/openssl_plugin/key/asy_key_generator/src/alg_25519_asy_key_generator_openssl.c index 13be947085665971b2349468d30448624da11967..efc15ee6a01f56844d04c99a61682ceae09a3c1d 100644 --- a/plugin/openssl_plugin/key/asy_key_generator/src/alg_25519_asy_key_generator_openssl.c +++ b/plugin/openssl_plugin/key/asy_key_generator/src/alg_25519_asy_key_generator_openssl.c @@ -68,7 +68,7 @@ static const char *GetAlg25519PriKeyClass(void) static void DestroyAlg25519KeyGeneratorSpiImpl(HcfObjectBase *self) { if ((self == NULL) || (self->getClass() == NULL)) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return; } @@ -81,17 +81,17 @@ static void DestroyAlg25519KeyGeneratorSpiImpl(HcfObjectBase *self) HcfFree(self); return; } - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); } static void DestroyAlg25519PubKey(HcfObjectBase *self) { if (self == NULL) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return; } if (!HcfIsClassMatch(self, GetAlg25519PubKeyClass())) { - LOGE("Invalid class of self."); + LOGE_ONE_STR("Invalid class of self."); return; } HcfOpensslAlg25519PubKey *impl = (HcfOpensslAlg25519PubKey *)self; @@ -103,11 +103,11 @@ static void DestroyAlg25519PubKey(HcfObjectBase *self) static void DestroyAlg25519PriKey(HcfObjectBase *self) { if (self == NULL) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return; } if (!HcfIsClassMatch(self, GetAlg25519PriKeyClass())) { - LOGE("Invalid class of self."); + LOGE_ONE_STR("Invalid class of self."); return; } HcfOpensslAlg25519PriKey *impl = (HcfOpensslAlg25519PriKey *)self; @@ -119,11 +119,11 @@ static void DestroyAlg25519PriKey(HcfObjectBase *self) static void DestroyAlg25519KeyPair(HcfObjectBase *self) { if (self == NULL) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return; } if (!HcfIsClassMatch(self, GetAlg25519KeyPairClass())) { - LOGE("Invalid class of self."); + LOGE_ONE_STR("Invalid class of self."); return; } HcfOpensslAlg25519KeyPair *impl = (HcfOpensslAlg25519KeyPair *)self; @@ -137,11 +137,11 @@ static void DestroyAlg25519KeyPair(HcfObjectBase *self) static const char *GetAlg25519PubKeyAlgorithm(HcfKey *self) { if (self == NULL) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return NULL; } if (!HcfIsClassMatch((HcfObjectBase *)self, GetAlg25519PubKeyClass())) { - LOGE("Invalid class of self."); + LOGE_ONE_STR("Invalid class of self."); return NULL; } @@ -156,11 +156,11 @@ static const char *GetAlg25519PubKeyAlgorithm(HcfKey *self) static const char *GetAlg25519PriKeyAlgorithm(HcfKey *self) { if (self == NULL) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return NULL; } if (!HcfIsClassMatch((HcfObjectBase *)self, GetAlg25519PriKeyClass())) { - LOGE("Invalid class of self."); + LOGE_ONE_STR("Invalid class of self."); return NULL; } @@ -175,22 +175,22 @@ static const char *GetAlg25519PriKeyAlgorithm(HcfKey *self) static HcfResult GetAlg25519PubKeyEncoded(HcfKey *self, HcfBlob *returnBlob) { if ((self == NULL) || (returnBlob == NULL)) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return HCF_INVALID_PARAMS; } if (!HcfIsClassMatch((HcfObjectBase *)self, GetAlg25519PubKeyClass())) { - LOGE("Invalid class of self."); + LOGE_ONE_STR("Invalid class of self."); return HCF_INVALID_PARAMS; } HcfOpensslAlg25519PubKey *impl = (HcfOpensslAlg25519PubKey *)self; if (impl->pkey == NULL) { - LOGE("pkey is NULL."); + LOGE_ONE_STR("pkey is NULL."); return HCF_INVALID_PARAMS; } unsigned char *returnData = NULL; int len = OpensslI2dPubKey(impl->pkey, &returnData); if (len <= 0) { - LOGD("[error] Call i2d_PUBKEY failed"); + LOGD_ONE_STR("[error] Call i2d_PUBKEY failed"); HcfPrintOpensslError(); return HCF_ERR_CRYPTO_OPERATION; } @@ -210,22 +210,22 @@ static HcfResult GetAlg25519PubKeyEncodedPem(HcfKey *self, const char *format, c static HcfResult GetAlg25519PriKeyEncoded(HcfKey *self, HcfBlob *returnBlob) { if ((self == NULL) || (returnBlob == NULL)) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return HCF_INVALID_PARAMS; } if (!HcfIsClassMatch((HcfObjectBase *)self, GetAlg25519PriKeyClass())) { - LOGE("Invalid class of self."); + LOGE_ONE_STR("Invalid class of self."); return HCF_INVALID_PARAMS; } HcfOpensslAlg25519PriKey *impl = (HcfOpensslAlg25519PriKey *)self; if (impl->pkey == NULL) { - LOGE("pkey is NULL."); + LOGE_ONE_STR("pkey is NULL."); return HCF_INVALID_PARAMS; } unsigned char *returnData = NULL; int len = OpensslI2dPrivateKey(impl->pkey, &returnData); if (len <= 0) { - LOGD("[error] Call i2d_PrivateKey failed"); + LOGD_ONE_STR("[error] Call i2d_PrivateKey failed"); HcfPrintOpensslError(); return HCF_ERR_CRYPTO_OPERATION; } @@ -247,11 +247,11 @@ static HcfResult GetAlg25519PriKeyEncodedPem(const HcfPriKey *self, HcfParamsSpe static const char *GetAlg25519PubKeyFormat(HcfKey *self) { if (self == NULL) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return NULL; } if (!HcfIsClassMatch((HcfObjectBase *)self, GetAlg25519PubKeyClass())) { - LOGE("Invalid class of self."); + LOGE_ONE_STR("Invalid class of self."); return NULL; } return OPENSSL_ALG_25519_PUBKEY_FORMAT; @@ -260,11 +260,11 @@ static const char *GetAlg25519PubKeyFormat(HcfKey *self) static const char *GetAlg25519PriKeyFormat(HcfKey *self) { if (self == NULL) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return NULL; } if (!HcfIsClassMatch((HcfObjectBase *)self, GetAlg25519PriKeyClass())) { - LOGE("Invalid class of self."); + LOGE_ONE_STR("Invalid class of self."); return NULL; } return OPENSSL_ALG_25519_PRIKEY_FORMAT; @@ -274,16 +274,16 @@ static HcfResult GetAlg25519PubKey(EVP_PKEY *pubKey, HcfBigInteger *returnBigInt { size_t len = 0; if (!OpensslEvpPkeyGetRawPublicKey(pubKey, NULL, &len)) { - LOGD("[error] Get len failed."); + LOGD_ONE_STR("[error] Get len failed."); return HCF_ERR_CRYPTO_OPERATION; } returnBigInteger->data = (unsigned char *)HcfMalloc(len, 0); if (returnBigInteger->data == NULL) { - LOGE("Failed to allocate returnBigInteger memory."); + LOGE_ONE_STR("Failed to allocate returnBigInteger memory."); return HCF_ERR_MALLOC; } if (!OpensslEvpPkeyGetRawPublicKey(pubKey, returnBigInteger->data, &len)) { - LOGD("[error] Get data failed."); + LOGD_ONE_STR("[error] Get data failed."); HcfFree(returnBigInteger->data); returnBigInteger->data = NULL; return HCF_ERR_CRYPTO_OPERATION; @@ -296,12 +296,12 @@ static HcfResult CheckEvpKeyTypeFromAlg25519PubKey(EVP_PKEY *alg25519Pk, const A { int type = OpensslEvpPkeyBaseId(alg25519Pk); if (type != EVP_PKEY_ED25519 && type != EVP_PKEY_X25519) { - LOGE("Invalid pkey type."); + LOGE_ONE_STR("Invalid pkey type."); return HCF_INVALID_PARAMS; } if ((type == EVP_PKEY_ED25519 && item != ED25519_PK_BN) || (type == EVP_PKEY_X25519 && item != X25519_PK_BN)) { - LOGE("Invalid AsyKeySpecItem."); + LOGE_ONE_STR("Invalid AsyKeySpecItem."); return HCF_INVALID_PARAMS; } return HCF_SUCCESS; @@ -311,12 +311,12 @@ static HcfResult CheckEvpKeyTypeFromAlg25519PriKey(EVP_PKEY *alg25519Sk, const A { int type = OpensslEvpPkeyBaseId(alg25519Sk); if (type != EVP_PKEY_ED25519 && type != EVP_PKEY_X25519) { - LOGE("Invalid pkey type."); + LOGE_ONE_STR("Invalid pkey type."); return HCF_INVALID_PARAMS; } if ((type == EVP_PKEY_ED25519 && item != ED25519_SK_BN) || (type == EVP_PKEY_X25519 && item != X25519_SK_BN)) { - LOGE("Invalid AsyKeySpecItem."); + LOGE_ONE_STR("Invalid AsyKeySpecItem."); return HCF_INVALID_PARAMS; } return HCF_SUCCESS; @@ -326,28 +326,28 @@ static HcfResult GetBigIntegerSpecFromAlg25519PubKey(const HcfPubKey *self, cons HcfBigInteger *returnBigInteger) { if (self == NULL || returnBigInteger == NULL) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return HCF_INVALID_PARAMS; } if (!HcfIsClassMatch((HcfObjectBase *)self, GetAlg25519PubKeyClass())) { - LOGE("Invalid class of self."); + LOGE_ONE_STR("Invalid class of self."); return HCF_INVALID_PARAMS; } HcfResult ret = HCF_INVALID_PARAMS; HcfOpensslAlg25519PubKey *impl = (HcfOpensslAlg25519PubKey *)self; EVP_PKEY *alg25519Pk = impl->pkey; if (alg25519Pk == NULL) { - LOGE("pKey is null."); + LOGE_ONE_STR("pKey is null."); return HCF_INVALID_PARAMS; } if (CheckEvpKeyTypeFromAlg25519PubKey(alg25519Pk, item) != HCF_SUCCESS) { - LOGE("Check pKey type failed."); + LOGE_ONE_STR("Check pKey type failed."); return HCF_INVALID_PARAMS; } if (item == ED25519_PK_BN || item == X25519_PK_BN) { ret = GetAlg25519PubKey(alg25519Pk, returnBigInteger); } else { - LOGE("Input item is invalid"); + LOGE_ONE_STR("Input item is invalid"); } return ret; } @@ -356,16 +356,16 @@ static HcfResult GetAlg25519PriKey(EVP_PKEY *priKey, HcfBigInteger *returnBigInt { size_t len = 0; if (!OpensslEvpPkeyGetRawPrivateKey(priKey, NULL, &len)) { - LOGD("[error] Get private key length failed."); + LOGD_ONE_STR("[error] Get private key length failed."); return HCF_ERR_CRYPTO_OPERATION; } returnBigInteger->data = (unsigned char *)HcfMalloc(len, 0); if (returnBigInteger->data == NULL) { - LOGE("Failed to allocate returnBigInteger memory."); + LOGE_ONE_STR("Failed to allocate returnBigInteger memory."); return HCF_ERR_MALLOC; } if (!OpensslEvpPkeyGetRawPrivateKey(priKey, returnBigInteger->data, &len)) { - LOGD("[error] Get data failed."); + LOGD_ONE_STR("[error] Get data failed."); HcfFree(returnBigInteger->data); returnBigInteger->data = NULL; return HCF_ERR_CRYPTO_OPERATION; @@ -378,28 +378,28 @@ static HcfResult GetBigIntegerSpecFromAlg25519PriKey(const HcfPriKey *self, cons HcfBigInteger *returnBigInteger) { if (self == NULL || returnBigInteger == NULL) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return HCF_INVALID_PARAMS; } if (!HcfIsClassMatch((HcfObjectBase *)self, GetAlg25519PriKeyClass())) { - LOGE("Invalid class of self."); + LOGE_ONE_STR("Invalid class of self."); return HCF_INVALID_PARAMS; } HcfResult ret = HCF_INVALID_PARAMS; HcfOpensslAlg25519PriKey *impl = (HcfOpensslAlg25519PriKey *)self; EVP_PKEY *alg25519Sk = impl->pkey; if (alg25519Sk == NULL) { - LOGE("pKey is null."); + LOGE_ONE_STR("pKey is null."); return HCF_INVALID_PARAMS; } if (CheckEvpKeyTypeFromAlg25519PriKey(alg25519Sk, item) != HCF_SUCCESS) { - LOGE("Check pKey type failed."); + LOGE_ONE_STR("Check pKey type failed."); return HCF_INVALID_PARAMS; } if (item == ED25519_SK_BN || item == X25519_SK_BN) { ret = GetAlg25519PriKey(alg25519Sk, returnBigInteger); } else { - LOGE("Input item is invalid"); + LOGE_ONE_STR("Input item is invalid"); } return ret; } @@ -443,11 +443,11 @@ static HcfResult GetAlg25519PriKeyEncodedDer(const HcfPriKey *self, const char * static void ClearAlg25519PriKeyMem(HcfPriKey *self) { if (self == NULL) { - LOGE("Invalid params."); + LOGE_ONE_STR("Invalid params."); return; } if (!HcfIsClassMatch((HcfObjectBase *)self, GetAlg25519PriKeyClass())) { - LOGE("Invalid class of self."); + LOGE_ONE_STR("Invalid class of self."); return; } HcfOpensslAlg25519PriKey *impl = (HcfOpensslAlg25519PriKey *)self; @@ -462,17 +462,17 @@ static HcfResult GenerateAlg25519EvpKey(int type, EVP_PKEY **ppkey) do { paramsCtx = OpensslEvpPkeyCtxNewId(type, NULL); if (paramsCtx == NULL) { - LOGE("Create params ctx failed."); + LOGE_ONE_STR("Create params ctx failed."); ret = HCF_ERR_MALLOC; break; } if (OpensslEvpPkeyKeyGenInit(paramsCtx) != HCF_OPENSSL_SUCCESS) { - LOGD("[error] Key ctx generate init failed."); + LOGD_ONE_STR("[error] Key ctx generate init failed."); ret = HCF_ERR_CRYPTO_OPERATION; break; } if (OpensslEvpPkeyKeyGen(paramsCtx, ppkey) != HCF_OPENSSL_SUCCESS) { - LOGD("[error] Generate pkey failed."); + LOGD_ONE_STR("[error] Generate pkey failed."); ret = HCF_ERR_CRYPTO_OPERATION; break; } @@ -525,7 +525,7 @@ static HcfResult CreateAlg25519PubKey(EVP_PKEY *pkey, HcfOpensslAlg25519PubKey * HcfOpensslAlg25519PubKey *alg25519PubKey = (HcfOpensslAlg25519PubKey *)HcfMalloc(sizeof(HcfOpensslAlg25519PubKey), 0); if (alg25519PubKey == NULL) { - LOGE("Failed to allocate alg25519 public key memory."); + LOGE_ONE_STR("Failed to allocate alg25519 public key memory."); return HCF_ERR_MALLOC; } FillOpensslAlg25519PubKeyFunc(alg25519PubKey); @@ -539,7 +539,7 @@ static HcfResult CreateAlg25519PriKey(EVP_PKEY *pkey, HcfOpensslAlg25519PriKey * HcfOpensslAlg25519PriKey *alg25519PriKey = (HcfOpensslAlg25519PriKey *)HcfMalloc(sizeof(HcfOpensslAlg25519PriKey), 0); if (alg25519PriKey == NULL) { - LOGE("Failed to allocate alg25519 private key memory."); + LOGE_ONE_STR("Failed to allocate alg25519 private key memory."); return HCF_ERR_MALLOC; } FillOpensslAlg25519PriKeyFunc(alg25519PriKey); @@ -554,7 +554,7 @@ static HcfResult CreateAlg25519KeyPair(const HcfOpensslAlg25519PubKey *pubKey, HcfOpensslAlg25519KeyPair *keyPair = (HcfOpensslAlg25519KeyPair *)HcfMalloc(sizeof(HcfOpensslAlg25519KeyPair), 0); if (keyPair == NULL) { - LOGE("Failed to allocate keyPair memory."); + LOGE_ONE_STR("Failed to allocate keyPair memory."); return HCF_ERR_MALLOC; } keyPair->base.base.getClass = GetAlg25519KeyPairClass; @@ -570,13 +570,13 @@ static HcfResult GeneratePubKeyByPkey(EVP_PKEY *pkey, HcfOpensslAlg25519PubKey * { EVP_PKEY *evpPkey = OpensslEvpPkeyDup(pkey); if (evpPkey == NULL) { - LOGD("[error] pkey dup failed"); + LOGD_ONE_STR("[error] pkey dup failed"); HcfPrintOpensslError(); return HCF_ERR_CRYPTO_OPERATION; } HcfResult ret = CreateAlg25519PubKey(evpPkey, returnPubKey); if (ret != HCF_SUCCESS) { - LOGD("[error] Create alg25519 public key failed"); + LOGD_ONE_STR("[error] Create alg25519 public key failed"); OpensslEvpPkeyFree(evpPkey); } return ret; @@ -586,13 +586,13 @@ static HcfResult GeneratePriKeyByPkey(EVP_PKEY *pkey, HcfOpensslAlg25519PriKey * { EVP_PKEY *evpPkey = OpensslEvpPkeyDup(pkey); if (evpPkey == NULL) { - LOGD("[error] pkey dup failed"); + LOGD_ONE_STR("[error] pkey dup failed"); HcfPrintOpensslError(); return HCF_ERR_CRYPTO_OPERATION; } HcfResult ret = CreateAlg25519PriKey(evpPkey, returnPriKey); if (ret != HCF_SUCCESS) { - LOGD("[error] Create alg25519 private key failed"); + LOGD_ONE_STR("[error] Create alg25519 private key failed"); OpensslEvpPkeyFree(evpPkey); } return ret; @@ -604,20 +604,20 @@ static HcfResult GenerateAlg25519PubAndPriKey(int type, HcfOpensslAlg25519PubKey EVP_PKEY *pkey = NULL; HcfResult ret = GenerateAlg25519EvpKey(type, &pkey); if (ret != HCF_SUCCESS) { - LOGD("[error] Generate alg25519 EVP_PKEY failed."); + LOGD_ONE_STR("[error] Generate alg25519 EVP_PKEY failed."); return ret; } ret = GeneratePubKeyByPkey(pkey, returnPubKey); if (ret != HCF_SUCCESS) { - LOGD("[error] Generate pubkey fail."); + LOGD_ONE_STR("[error] Generate pubkey fail."); OpensslEvpPkeyFree(pkey); return ret; } ret = GeneratePriKeyByPkey(pkey, returnPriKey); if (ret != HCF_SUCCESS) { - LOGD("[error] Generate prikey fail."); + LOGD_ONE_STR("[error] Generate prikey fail."); HcfObjDestroy(*returnPubKey); *returnPubKey = NULL; OpensslEvpPkeyFree(pkey); @@ -633,13 +633,13 @@ static HcfResult ConvertAlg25519PubKey(const HcfBlob *pubKeyBlob, HcfOpensslAlg2 const unsigned char *tmpData = (const unsigned char *)(pubKeyBlob->data); EVP_PKEY *pkey = OpensslD2iPubKey(NULL, &tmpData, pubKeyBlob->len); if (pkey == NULL) { - LOGD("[error] Call d2i_PUBKEY fail."); + LOGD_ONE_STR("[error] Call d2i_PUBKEY fail."); HcfPrintOpensslError(); return HCF_ERR_CRYPTO_OPERATION; } HcfResult ret = CreateAlg25519PubKey(pkey, returnPubKey); if (ret != HCF_SUCCESS) { - LOGD("[error] Create alg25519 public key failed"); + LOGD_ONE_STR("[error] Create alg25519 public key failed"); OpensslEvpPkeyFree(pkey); } return ret; @@ -651,13 +651,13 @@ static HcfResult ConvertAlg25519PriKey(int type, const HcfBlob *priKeyBlob, const unsigned char *tmpData = (const unsigned char *)(priKeyBlob->data); EVP_PKEY *pkey = OpensslD2iPrivateKey(type, NULL, &tmpData, priKeyBlob->len); if (pkey == NULL) { - LOGD("[error] Call d2i_PrivateKey fail."); + LOGD_ONE_STR("[error] Call d2i_PrivateKey fail."); HcfPrintOpensslError(); return HCF_ERR_CRYPTO_OPERATION; } HcfResult ret = CreateAlg25519PriKey(pkey, returnPriKey); if (ret != HCF_SUCCESS) { - LOGD("[error] Create alg25519 private key failed"); + LOGD_ONE_STR("[error] Create alg25519 private key failed"); OpensslEvpPkeyFree(pkey); } return ret; @@ -668,13 +668,13 @@ static HcfResult ConvertAlg25519PubAndPriKey(int type, const HcfBlob *pubKeyBlob { if (pubKeyBlob != NULL) { if (ConvertAlg25519PubKey(pubKeyBlob, returnPubKey) != HCF_SUCCESS) { - LOGD("[error] Convert alg25519 public key failed."); + LOGD_ONE_STR("[error] Convert alg25519 public key failed."); return HCF_ERR_CRYPTO_OPERATION; } } if (priKeyBlob != NULL) { if (ConvertAlg25519PriKey(type, priKeyBlob, returnPriKey) != HCF_SUCCESS) { - LOGD("[error] Convert alg25519 private key failed."); + LOGD_ONE_STR("[error] Convert alg25519 private key failed."); HcfObjDestroy(*returnPubKey); *returnPubKey = NULL; return HCF_ERR_CRYPTO_OPERATION; @@ -690,7 +690,7 @@ static HcfResult CheckClassMatch(HcfAsyKeyGeneratorSpi *self, int *type) } else if (HcfIsClassMatch((HcfObjectBase *)self, GetX25519KeyGeneratorSpiClass())) { *type = EVP_PKEY_X25519; } else { - LOGE("Invalid class of self."); + LOGE_ONE_STR("Invalid class of self."); return HCF_INVALID_PARAMS; } return HCF_SUCCESS; @@ -699,12 +699,12 @@ static HcfResult CheckClassMatch(HcfAsyKeyGeneratorSpi *self, int *type) static HcfResult EngineGenerateAlg25519KeyPair(HcfAsyKeyGeneratorSpi *self, HcfKeyPair **returnKeyPair) { if (self == NULL || returnKeyPair == NULL) { - LOGE("Invalid params."); + LOGE_ONE_STR("Invalid params."); return HCF_INVALID_PARAMS; } int type = 0; if (CheckClassMatch(self, &type) != HCF_SUCCESS) { - LOGE("Invalid class of self."); + LOGE_ONE_STR("Invalid class of self."); return HCF_INVALID_PARAMS; } @@ -712,7 +712,7 @@ static HcfResult EngineGenerateAlg25519KeyPair(HcfAsyKeyGeneratorSpi *self, HcfK HcfOpensslAlg25519PriKey *priKey = NULL; HcfResult ret = GenerateAlg25519PubAndPriKey(type, &pubKey, &priKey); if (ret != HCF_SUCCESS) { - LOGE("Generate alg25519 pk and sk by openssl failed."); + LOGE_ONE_STR("Generate alg25519 pk and sk by openssl failed."); return ret; } @@ -726,7 +726,7 @@ static HcfResult EngineGenerateAlg25519KeyPair(HcfAsyKeyGeneratorSpi *self, HcfK ret = CreateAlg25519KeyPair(pubKey, priKey, returnKeyPair); if (ret != HCF_SUCCESS) { - LOGE("Create alg25519 keyPair failed."); + LOGE_ONE_STR("Create alg25519 keyPair failed."); HcfObjDestroy(pubKey); HcfObjDestroy(priKey); return ret; @@ -739,18 +739,18 @@ static HcfResult EngineConvertAlg25519Key(HcfAsyKeyGeneratorSpi *self, HcfParams { (void)params; if ((self == NULL) || (returnKeyPair == NULL)) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return HCF_INVALID_PARAMS; } int type = 0; if (CheckClassMatch(self, &type) != HCF_SUCCESS) { - LOGE("Invalid class of self."); + LOGE_ONE_STR("Invalid class of self."); return HCF_INVALID_PARAMS; } bool pubKeyValid = HcfIsBlobValid(pubKeyBlob); bool priKeyValid = HcfIsBlobValid(priKeyBlob); if ((!pubKeyValid) && (!priKeyValid)) { - LOGE("The private key and public key cannot both be NULL."); + LOGE_ONE_STR("The private key and public key cannot both be NULL."); return HCF_INVALID_PARAMS; } @@ -760,7 +760,7 @@ static HcfResult EngineConvertAlg25519Key(HcfAsyKeyGeneratorSpi *self, HcfParams HcfBlob *inputSk = priKeyValid ? priKeyBlob : NULL; HcfResult ret = ConvertAlg25519PubAndPriKey(type, inputPk, inputSk, &pubKey, &priKey); if (ret != HCF_SUCCESS) { - LOGE("Convert alg25519 keyPair failed."); + LOGE_ONE_STR("Convert alg25519 keyPair failed."); return ret; } @@ -774,7 +774,7 @@ static HcfResult EngineConvertAlg25519Key(HcfAsyKeyGeneratorSpi *self, HcfParams ret = CreateAlg25519KeyPair(pubKey, priKey, returnKeyPair); if (ret != HCF_SUCCESS) { - LOGE("Create alg25519 keyPair failed."); + LOGE_ONE_STR("Create alg25519 keyPair failed."); HcfObjDestroy(pubKey); HcfObjDestroy(priKey); } @@ -794,13 +794,13 @@ static HcfResult ConvertAlg25519PemPubKey(int type, const char *pubKeyStr, HcfOp HcfResult ret = ConvertPubPemStrToKey(&pkey, keyType, EVP_PKEY_PUBLIC_KEY, pubKeyStr); if (ret != HCF_SUCCESS) { - LOGE("Convert public key from pem to key failed."); + LOGE_ONE_STR("Convert public key from pem to key failed."); return ret; } ret = CreateAlg25519PubKey(pkey, returnPubKey); if (ret != HCF_SUCCESS) { - LOGE("Create alg25519 public key failed."); + LOGE_ONE_STR("Create alg25519 public key failed."); OpensslEvpPkeyFree(pkey); } @@ -820,13 +820,13 @@ static HcfResult ConvertAlg25519PemPriKey(int type, const char *priKeyStr, HcfOp HcfResult ret = ConvertPriPemStrToKey(priKeyStr, &pkey, keyType); if (ret != HCF_SUCCESS) { - LOGE("Convert private key from pem to key failed."); + LOGE_ONE_STR("Convert private key from pem to key failed."); return ret; } ret = CreateAlg25519PriKey(pkey, returnPriKey); if (ret != HCF_SUCCESS) { - LOGE("Create alg25519 private key failed."); + LOGE_ONE_STR("Create alg25519 private key failed."); OpensslEvpPkeyFree(pkey); } return ret; @@ -837,13 +837,13 @@ static HcfResult ConvertAlg25519PemPubAndPriKey(int type, const char *pubKeyStr, { if (pubKeyStr != NULL && strlen(pubKeyStr) != 0) { if (ConvertAlg25519PemPubKey(type, pubKeyStr, returnPubKey) != HCF_SUCCESS) { - LOGE("Convert alg25519 pem public key failed."); + LOGE_ONE_STR("Convert alg25519 pem public key failed."); return HCF_ERR_CRYPTO_OPERATION; } } if (priKeyStr != NULL && strlen(priKeyStr) != 0) { if (ConvertAlg25519PemPriKey(type, priKeyStr, returnPriKey) != HCF_SUCCESS) { - LOGE("Convert alg25519 pem private key failed."); + LOGE_ONE_STR("Convert alg25519 pem private key failed."); HcfObjDestroy(*returnPubKey); *returnPubKey = NULL; return HCF_ERR_CRYPTO_OPERATION; @@ -857,12 +857,12 @@ static HcfResult EngineConvertX25519PemKey(HcfAsyKeyGeneratorSpi *self, HcfParam { (void)params; if ((self == NULL) || (returnKeyPair == NULL) || ((pubKeyStr == NULL) && (priKeyStr == NULL))) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return HCF_INVALID_PARAMS; } if (!HcfIsClassMatch((HcfObjectBase *)self, GetX25519KeyGeneratorSpiClass())) { - LOGE("Class not match."); + LOGE_ONE_STR("Class not match."); return HCF_INVALID_PARAMS; } @@ -871,7 +871,7 @@ static HcfResult EngineConvertX25519PemKey(HcfAsyKeyGeneratorSpi *self, HcfParam int type = EVP_PKEY_X25519; HcfResult ret = ConvertAlg25519PemPubAndPriKey(type, pubKeyStr, priKeyStr, &pubKey, &priKey); if (ret != HCF_SUCCESS) { - LOGE("Convert alg25519 pem keyPair failed."); + LOGE_ONE_STR("Convert alg25519 pem keyPair failed."); return ret; } @@ -883,7 +883,7 @@ static HcfResult EngineConvertX25519PemKey(HcfAsyKeyGeneratorSpi *self, HcfParam } ret = CreateAlg25519KeyPair(pubKey, priKey, returnKeyPair); if (ret != HCF_SUCCESS) { - LOGE("Create alg25519 keyPair failed."); + LOGE_ONE_STR("Create alg25519 keyPair failed."); HcfObjDestroy(pubKey); HcfObjDestroy(priKey); } @@ -895,12 +895,12 @@ static HcfResult EngineConvertEd25519PemKey(HcfAsyKeyGeneratorSpi *self, HcfPara { (void)params; if ((self == NULL) || (returnKeyPair == NULL) || ((pubKeyStr == NULL) && (priKeyStr == NULL))) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return HCF_INVALID_PARAMS; } if (!HcfIsClassMatch((HcfObjectBase *)self, GetEd25519KeyGeneratorSpiClass())) { - LOGE("Class not match."); + LOGE_ONE_STR("Class not match."); return HCF_INVALID_PARAMS; } @@ -909,7 +909,7 @@ static HcfResult EngineConvertEd25519PemKey(HcfAsyKeyGeneratorSpi *self, HcfPara int type = EVP_PKEY_ED25519; HcfResult ret = ConvertAlg25519PemPubAndPriKey(type, pubKeyStr, priKeyStr, &pubKey, &priKey); if (ret != HCF_SUCCESS) { - LOGE("Convert alg25519 pem keyPair failed."); + LOGE_ONE_STR("Convert alg25519 pem keyPair failed."); return ret; } @@ -921,7 +921,7 @@ static HcfResult EngineConvertEd25519PemKey(HcfAsyKeyGeneratorSpi *self, HcfPara } ret = CreateAlg25519KeyPair(pubKey, priKey, returnKeyPair); if (ret != HCF_SUCCESS) { - LOGE("Create alg25519 keyPair failed."); + LOGE_ONE_STR("Create alg25519 keyPair failed."); HcfObjDestroy(pubKey); HcfObjDestroy(priKey); } @@ -941,7 +941,7 @@ static HcfResult CreateOpensslAlg25519PubKey(const HcfBigInteger *pk, const char return HCF_INVALID_PARAMS; } if (pubkey == NULL) { - LOGD("[error] Set alg25519 pubKey failed."); + LOGD_ONE_STR("[error] Set alg25519 pubKey failed."); HcfPrintOpensslError(); return HCF_ERR_CRYPTO_OPERATION; } @@ -962,7 +962,7 @@ static HcfResult CreateOpensslAlg25519PriKey(const HcfBigInteger *sk, const char return HCF_INVALID_PARAMS; } if (privkey == NULL) { - LOGD("[error] Get alg25519 priKey failed."); + LOGD_ONE_STR("[error] Get alg25519 priKey failed."); HcfPrintOpensslError(); return HCF_ERR_CRYPTO_OPERATION; } @@ -975,11 +975,11 @@ static HcfResult CreateAlg25519PubKeyByKeyPairSpec(const HcfAlg25519KeyPairParam { EVP_PKEY *alg25519 = NULL; if (CreateOpensslAlg25519PubKey(&(paramsSpec->pk), algName, &alg25519) != HCF_SUCCESS) { - LOGD("[error] Create openssl alg25519 pubKey failed."); + LOGD_ONE_STR("[error] Create openssl alg25519 pubKey failed."); return HCF_ERR_CRYPTO_OPERATION; } if (CreateAlg25519PubKey(alg25519, returnPubKey) != HCF_SUCCESS) { - LOGE("Create alg25519 pubKey failed."); + LOGE_ONE_STR("Create alg25519 pubKey failed."); OpensslEvpPkeyFree(alg25519); return HCF_ERR_MALLOC; } @@ -991,11 +991,11 @@ static HcfResult CreateAlg25519PriKeyByKeyPairSpec(const HcfAlg25519KeyPairParam { EVP_PKEY *alg25519 = NULL; if (CreateOpensslAlg25519PriKey(&(paramsSpec->sk), algName, &alg25519) != HCF_SUCCESS) { - LOGD("[error] Create openssl alg25519 priKey failed."); + LOGD_ONE_STR("[error] Create openssl alg25519 priKey failed."); return HCF_ERR_CRYPTO_OPERATION; } if (CreateAlg25519PriKey(alg25519, returnPriKey) != HCF_SUCCESS) { - LOGE("Create alg25519 priKey failed."); + LOGE_ONE_STR("Create alg25519 priKey failed."); OpensslEvpPkeyFree(alg25519); return HCF_ERR_MALLOC; } @@ -1008,20 +1008,20 @@ static HcfResult CreateAlg25519KeyPairByKeyPairSpec(const HcfAlg25519KeyPairPara HcfOpensslAlg25519PubKey *pubKey = NULL; HcfResult ret = CreateAlg25519PubKeyByKeyPairSpec(paramsSpec, algName, &pubKey); if (ret != HCF_SUCCESS) { - LOGE("Create alg25519 pubKey failed."); + LOGE_ONE_STR("Create alg25519 pubKey failed."); return ret; } HcfOpensslAlg25519PriKey *priKey = NULL; ret = CreateAlg25519PriKeyByKeyPairSpec(paramsSpec, algName, &priKey); if (ret != HCF_SUCCESS) { - LOGE("Create alg25519 priKey failed."); + LOGE_ONE_STR("Create alg25519 priKey failed."); HcfObjDestroy(pubKey); return ret; } ret = CreateAlg25519KeyPair(pubKey, priKey, returnKeyPair); if (ret != HCF_SUCCESS) { - LOGE("Create alg25519 keyPair failed."); + LOGE_ONE_STR("Create alg25519 keyPair failed."); HcfObjDestroy(pubKey); HcfObjDestroy(priKey); return ret; @@ -1034,11 +1034,11 @@ static HcfResult CreateAlg25519PubKeyByPubKeySpec(const HcfAlg25519PubKeyParamsS { EVP_PKEY *alg25519 = NULL; if (CreateOpensslAlg25519PubKey(&(paramsSpec->pk), algName, &alg25519) != HCF_SUCCESS) { - LOGD("[error] Create openssl alg25519 pubKey failed."); + LOGD_ONE_STR("[error] Create openssl alg25519 pubKey failed."); return HCF_ERR_CRYPTO_OPERATION; } if (CreateAlg25519PubKey(alg25519, returnPubKey) != HCF_SUCCESS) { - LOGE("Create alg25519 pubKey failed."); + LOGE_ONE_STR("Create alg25519 pubKey failed."); OpensslEvpPkeyFree(alg25519); return HCF_ERR_MALLOC; } @@ -1050,11 +1050,11 @@ static HcfResult CreateAlg25519PriKeyByPriKeySpec(const HcfAlg25519PriKeyParamsS { EVP_PKEY *alg25519 = NULL; if (CreateOpensslAlg25519PriKey(&(paramsSpec->sk), algName, &alg25519) != HCF_SUCCESS) { - LOGD("[error] Create openssl alg25519 priKey failed."); + LOGD_ONE_STR("[error] Create openssl alg25519 priKey failed."); return HCF_ERR_CRYPTO_OPERATION; } if (CreateAlg25519PriKey(alg25519, returnPriKey) != HCF_SUCCESS) { - LOGE("Create alg25519 priKey failed."); + LOGE_ONE_STR("Create alg25519 priKey failed."); OpensslEvpPkeyFree(alg25519); return HCF_ERR_MALLOC; } @@ -1065,27 +1065,27 @@ static HcfResult EngineGenerateAlg25519PubKeyBySpec(const HcfAsyKeyGeneratorSpi const HcfAsyKeyParamsSpec *paramsSpec, HcfPubKey **returnPubKey) { if ((self == NULL) || (paramsSpec == NULL) || (paramsSpec->algName == NULL) || (returnPubKey == NULL)) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return HCF_INVALID_PARAMS; } int type = 0; if (CheckClassMatch((HcfAsyKeyGeneratorSpi *)self, &type) != HCF_SUCCESS) { - LOGE("Invalid class of self."); + LOGE_ONE_STR("Invalid class of self."); return HCF_INVALID_PARAMS; } if (((strcmp(paramsSpec->algName, ALGORITHM_NAME_ED25519) != 0) && (strcmp(paramsSpec->algName, ALGORITHM_NAME_X25519) != 0)) || (paramsSpec->specType != HCF_PUBLIC_KEY_SPEC)) { - LOGE("Invalid params spec."); + LOGE_ONE_STR("Invalid params spec."); return HCF_INVALID_PARAMS; } HcfOpensslAlg25519PubKey *alg25519Pk = NULL; HcfResult ret = CreateAlg25519PubKeyByPubKeySpec((const HcfAlg25519PubKeyParamsSpec *)paramsSpec, paramsSpec->algName, &alg25519Pk); if (ret != HCF_SUCCESS) { - LOGD("[error] Create alg25519 public key by spec failed."); + LOGD_ONE_STR("[error] Create alg25519 public key by spec failed."); return ret; } @@ -1099,27 +1099,27 @@ static HcfResult EngineGenerateAlg25519PriKeyBySpec(const HcfAsyKeyGeneratorSpi const HcfAsyKeyParamsSpec *paramsSpec, HcfPriKey **returnPriKey) { if ((self == NULL) || (paramsSpec == NULL) || (paramsSpec->algName == NULL) || (returnPriKey == NULL)) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return HCF_INVALID_PARAMS; } int type = 0; if (CheckClassMatch((HcfAsyKeyGeneratorSpi *)self, &type) != HCF_SUCCESS) { - LOGE("Invalid class of self."); + LOGE_ONE_STR("Invalid class of self."); return HCF_INVALID_PARAMS; } if (((strcmp(paramsSpec->algName, ALGORITHM_NAME_ED25519) != 0) && (strcmp(paramsSpec->algName, ALGORITHM_NAME_X25519) != 0)) || (paramsSpec->specType != HCF_PRIVATE_KEY_SPEC)) { - LOGE("Invalid params spec."); + LOGE_ONE_STR("Invalid params spec."); return HCF_INVALID_PARAMS; } HcfOpensslAlg25519PriKey *alg25519Sk = NULL; HcfResult ret = CreateAlg25519PriKeyByPriKeySpec((const HcfAlg25519PriKeyParamsSpec *)paramsSpec, paramsSpec->algName, &alg25519Sk); if (ret != HCF_SUCCESS) { - LOGD("[error] Create alg25519 private key by spec failed."); + LOGD_ONE_STR("[error] Create alg25519 private key by spec failed."); return ret; } @@ -1133,26 +1133,26 @@ static HcfResult EngineGenerateAlg25519KeyPairBySpec(const HcfAsyKeyGeneratorSpi const HcfAsyKeyParamsSpec *paramsSpec, HcfKeyPair **returnKeyPair) { if ((self == NULL) || (paramsSpec == NULL) || (paramsSpec->algName == NULL) || (returnKeyPair == NULL)) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return HCF_INVALID_PARAMS; } int type = 0; if (CheckClassMatch((HcfAsyKeyGeneratorSpi *)self, &type) != HCF_SUCCESS) { - LOGE("Invalid class of self."); + LOGE_ONE_STR("Invalid class of self."); return HCF_INVALID_PARAMS; } if (((strcmp(paramsSpec->algName, ALGORITHM_NAME_ED25519) != 0) && (strcmp(paramsSpec->algName, ALGORITHM_NAME_X25519) != 0)) || (paramsSpec->specType != HCF_KEY_PAIR_SPEC)) { - LOGE("Invalid params spec."); + LOGE_ONE_STR("Invalid params spec."); return HCF_INVALID_PARAMS; } HcfResult ret = CreateAlg25519KeyPairByKeyPairSpec((const HcfAlg25519KeyPairParamsSpec *)paramsSpec, paramsSpec->algName, returnKeyPair); if (ret != HCF_SUCCESS) { - LOGD("[error] Create alg25519 key pair by spec failed."); + LOGD_ONE_STR("[error] Create alg25519 key pair by spec failed."); return ret; } @@ -1168,13 +1168,13 @@ HcfResult HcfAsyKeyGeneratorSpiEd25519Create(HcfAsyKeyGenParams *params, HcfAsyK { (void)params; if (params == NULL || returnObj == NULL) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return HCF_INVALID_PARAMS; } HcfAsyKeyGeneratorSpiAlg25519OpensslImpl *impl = (HcfAsyKeyGeneratorSpiAlg25519OpensslImpl *)HcfMalloc( sizeof(HcfAsyKeyGeneratorSpiAlg25519OpensslImpl), 0); if (impl == NULL) { - LOGE("Failed to allocate generator impl memroy."); + LOGE_ONE_STR("Failed to allocate generator impl memroy."); return HCF_ERR_MALLOC; } impl->base.base.getClass = GetEd25519KeyGeneratorSpiClass; @@ -1194,13 +1194,13 @@ HcfResult HcfAsyKeyGeneratorSpiX25519Create(HcfAsyKeyGenParams *params, HcfAsyKe { (void)params; if (params == NULL || returnObj == NULL) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return HCF_INVALID_PARAMS; } HcfAsyKeyGeneratorSpiAlg25519OpensslImpl *impl = (HcfAsyKeyGeneratorSpiAlg25519OpensslImpl *)HcfMalloc( sizeof(HcfAsyKeyGeneratorSpiAlg25519OpensslImpl), 0); if (impl == NULL) { - LOGE("Failed to allocate generator impl memroy."); + LOGE_ONE_STR("Failed to allocate generator impl memroy."); return HCF_ERR_MALLOC; } impl->base.base.getClass = GetX25519KeyGeneratorSpiClass; diff --git a/plugin/openssl_plugin/key/asy_key_generator/src/dh_asy_key_generator_openssl.c b/plugin/openssl_plugin/key/asy_key_generator/src/dh_asy_key_generator_openssl.c index dc2849491e2fd5d64118161a6c929268c2c07e00..e7e6f5a6552528112fa1e3dcbfed5f0fbe096bc9 100644 --- a/plugin/openssl_plugin/key/asy_key_generator/src/dh_asy_key_generator_openssl.c +++ b/plugin/openssl_plugin/key/asy_key_generator/src/dh_asy_key_generator_openssl.c @@ -83,11 +83,11 @@ static const char *GetDhPriKeyClass(void) static void DestroyDhKeyGeneratorSpiImpl(HcfObjectBase *self) { if (self == NULL) { - LOGE("Class is null."); + LOGE_ONE_STR("Class is null."); return; } if (!HcfIsClassMatch(self, GetDhKeyGeneratorSpiClass())) { - LOGE("Class not match."); + LOGE_ONE_STR("Class not match."); return; } HcfFree(self); @@ -96,11 +96,11 @@ static void DestroyDhKeyGeneratorSpiImpl(HcfObjectBase *self) static void DestroyDhPubKey(HcfObjectBase *self) { if (self == NULL) { - LOGE("Class is null."); + LOGE_ONE_STR("Class is null."); return; } if (!HcfIsClassMatch(self, GetDhPubKeyClass())) { - LOGE("Class not match."); + LOGE_ONE_STR("Class not match."); return; } HcfOpensslDhPubKey *impl = (HcfOpensslDhPubKey *)self; @@ -112,11 +112,11 @@ static void DestroyDhPubKey(HcfObjectBase *self) static void DestroyDhPriKey(HcfObjectBase *self) { if (self == NULL) { - LOGE("Class is null."); + LOGE_ONE_STR("Class is null."); return; } if (!HcfIsClassMatch(self, GetDhPriKeyClass())) { - LOGE("Class not match."); + LOGE_ONE_STR("Class not match."); return; } HcfOpensslDhPriKey *impl = (HcfOpensslDhPriKey *)self; @@ -128,11 +128,11 @@ static void DestroyDhPriKey(HcfObjectBase *self) static void DestroyDhKeyPair(HcfObjectBase *self) { if (self == NULL) { - LOGE("Class is null."); + LOGE_ONE_STR("Class is null."); return; } if (!HcfIsClassMatch(self, GetDhKeyPairClass())) { - LOGE("Class not match."); + LOGE_ONE_STR("Class not match."); return; } HcfOpensslDhKeyPair *impl = (HcfOpensslDhKeyPair *)self; @@ -146,11 +146,11 @@ static void DestroyDhKeyPair(HcfObjectBase *self) static const char *GetDhPubKeyAlgorithm(HcfKey *self) { if (self == NULL) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return NULL; } if (!HcfIsClassMatch((HcfObjectBase *)self, GetDhPubKeyClass())) { - LOGE("Class not match."); + LOGE_ONE_STR("Class not match."); return NULL; } return ALGORITHM_NAME_DH; @@ -159,11 +159,11 @@ static const char *GetDhPubKeyAlgorithm(HcfKey *self) static const char *GetDhPriKeyAlgorithm(HcfKey *self) { if (self == NULL) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return NULL; } if (!HcfIsClassMatch((HcfObjectBase *)self, GetDhPriKeyClass())) { - LOGE("Class not match."); + LOGE_ONE_STR("Class not match."); return NULL; } return ALGORITHM_NAME_DH; @@ -172,23 +172,23 @@ static const char *GetDhPriKeyAlgorithm(HcfKey *self) static HcfResult GetDhPubKeyEncoded(HcfKey *self, HcfBlob *returnBlob) { if ((self == NULL) || (returnBlob == NULL)) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return HCF_INVALID_PARAMS; } if (!HcfIsClassMatch((HcfObjectBase *)self, GetDhPubKeyClass())) { - LOGE("Class not match."); + LOGE_ONE_STR("Class not match."); return HCF_INVALID_PARAMS; } HcfOpensslDhPubKey *impl = (HcfOpensslDhPubKey *)self; unsigned char *returnData = NULL; EVP_PKEY *pKey = NewEvpPkeyByDh(impl->pk, true); if (pKey == NULL) { - LOGD("[error] New pKey by dh fail."); + LOGD_ONE_STR("[error] New pKey by dh fail."); return HCF_ERR_CRYPTO_OPERATION; } int len = OpensslI2dPubKey(pKey, &returnData); if (len <= 0) { - LOGD("[error] Call i2d_PUBKEY failed"); + LOGD_ONE_STR("[error] Call i2d_PUBKEY failed"); HcfPrintOpensslError(); OpensslEvpPkeyFree(pKey); return HCF_ERR_CRYPTO_OPERATION; @@ -210,24 +210,24 @@ static HcfResult GetDhPubKeyEncodedPem(HcfKey *self, const char *format, char ** static HcfResult GetDhPriKeyEncoded(HcfKey *self, HcfBlob *returnBlob) { if ((self == NULL) || (returnBlob == NULL)) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return HCF_INVALID_PARAMS; } if (!HcfIsClassMatch((HcfObjectBase *)self, GetDhPriKeyClass())) { - LOGE("Class not match."); + LOGE_ONE_STR("Class not match."); return HCF_INVALID_PARAMS; } HcfOpensslDhPriKey *impl = (HcfOpensslDhPriKey *)self; unsigned char *returnData = NULL; EVP_PKEY *pKey = NewEvpPkeyByDh(impl->sk, true); if (pKey == NULL) { - LOGD("[error] New pKey by dh fail."); + LOGD_ONE_STR("[error] New pKey by dh fail."); HcfPrintOpensslError(); return HCF_ERR_CRYPTO_OPERATION; } int len = OpensslI2dPrivateKey(pKey, &returnData); if (len <= 0) { - LOGD("[error] Call i2d_PrivateKey failed."); + LOGD_ONE_STR("[error] Call i2d_PrivateKey failed."); HcfPrintOpensslError(); OpensslEvpPkeyFree(pKey); return HCF_ERR_CRYPTO_OPERATION; @@ -251,11 +251,11 @@ static HcfResult GetDhPriKeyEncodedPem(const HcfPriKey *self, HcfParamsSpec *par static const char *GetDhPubKeyFormat(HcfKey *self) { if (self == NULL) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return NULL; } if (!HcfIsClassMatch((HcfObjectBase *)self, GetDhPubKeyClass())) { - LOGE("Class not match."); + LOGE_ONE_STR("Class not match."); return NULL; } return OPENSSL_DH_PUBKEY_FORMAT; @@ -264,11 +264,11 @@ static const char *GetDhPubKeyFormat(HcfKey *self) static const char *GetDhPriKeyFormat(HcfKey *self) { if (self == NULL) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return NULL; } if (!HcfIsClassMatch((HcfObjectBase *)self, GetDhPriKeyClass())) { - LOGE("Class not match."); + LOGE_ONE_STR("Class not match."); return NULL; } return OPENSSL_DH_PRIKEY_FORMAT; @@ -280,21 +280,21 @@ static HcfResult GetBigIntegerSpec(const HcfPubKey *pubSelf, const HcfPriKey *pr DH *dh = NULL; if (pubSelf != NULL) { if (item == DH_SK_BN) { - LOGE("Invalid item."); + LOGE_ONE_STR("Invalid item."); return HCF_INVALID_PARAMS; } HcfOpensslDhPubKey *impl = (HcfOpensslDhPubKey *)pubSelf; dh = impl->pk; } else { if (item == DH_PK_BN) { - LOGE("Invalid item."); + LOGE_ONE_STR("Invalid item."); return HCF_INVALID_PARAMS; } HcfOpensslDhPriKey *impl = (HcfOpensslDhPriKey *)priSelf; dh = impl->sk; } if (dh == NULL) { - LOGE("Dh is null."); + LOGE_ONE_STR("Dh is null."); return HCF_INVALID_PARAMS; } HcfResult ret = HCF_SUCCESS; @@ -323,16 +323,16 @@ static HcfResult GetBigIntegerSpecFromDhPubKey(const HcfPubKey *self, const AsyK HcfBigInteger *returnBigInteger) { if (self == NULL || returnBigInteger == NULL) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return HCF_INVALID_PARAMS; } if (!HcfIsClassMatch((HcfObjectBase *)self, GetDhPubKeyClass())) { - LOGE("Invalid class of self."); + LOGE_ONE_STR("Invalid class of self."); return HCF_INVALID_PARAMS; } HcfResult ret = GetBigIntegerSpec(self, NULL, item, returnBigInteger); if (ret != HCF_SUCCESS) { - LOGE("Get big integer failed."); + LOGE_ONE_STR("Get big integer failed."); } return ret; } @@ -341,16 +341,16 @@ static HcfResult GetBigIntegerSpecFromDhPriKey(const HcfPriKey *self, const AsyK HcfBigInteger *returnBigInteger) { if (self == NULL || returnBigInteger == NULL) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return HCF_INVALID_PARAMS; } if (!HcfIsClassMatch((HcfObjectBase *)self, GetDhPriKeyClass())) { - LOGE("Invalid class of self."); + LOGE_ONE_STR("Invalid class of self."); return HCF_INVALID_PARAMS; } HcfResult ret = GetBigIntegerSpec(NULL, self, item, returnBigInteger); if (ret != HCF_SUCCESS) { - LOGE("Get big integer failed."); + LOGE_ONE_STR("Get big integer failed."); } return ret; } @@ -365,21 +365,21 @@ static HcfResult GetIntSpecFromDhPubKey(const HcfPubKey *self, const AsyKeySpecI static HcfResult GetIntSpecFromDhPriKey(const HcfPriKey *self, const AsyKeySpecItem item, int *returnInt) { if (self == NULL || returnInt == NULL) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return HCF_INVALID_PARAMS; } if (!HcfIsClassMatch((HcfObjectBase *)self, GetDhPriKeyClass())) { - LOGE("Invalid class of self."); + LOGE_ONE_STR("Invalid class of self."); return HCF_INVALID_PARAMS; } if (item != DH_L_NUM) { - LOGE("Invalid input item."); + LOGE_ONE_STR("Invalid input item."); return HCF_INVALID_PARAMS; } HcfOpensslDhPriKey *impl = (HcfOpensslDhPriKey *)self; DH *dh = impl->sk; if (dh == NULL) { - LOGE("Dh is null."); + LOGE_ONE_STR("Dh is null."); return HCF_INVALID_PARAMS; } @@ -412,11 +412,11 @@ static HcfResult GetDhPriKeyEncodedDer(const HcfPriKey *self, const char *format static void ClearDhPriKeyMem(HcfPriKey *self) { if (self == NULL) { - LOGE("Class is null."); + LOGE_ONE_STR("Class is null."); return; } if (!HcfIsClassMatch((HcfObjectBase *)self, GetDhPriKeyClass())) { - LOGE("Class not match."); + LOGE_ONE_STR("Class not match."); return; } HcfOpensslDhPriKey *impl = (HcfOpensslDhPriKey *)self; @@ -430,21 +430,21 @@ static EVP_PKEY *ConstructDhOsslParamsAndGenPkey(int32_t dhId, EVP_PKEY_CTX *par OSSL_PARAM params[PARAMS_NUM_TWO]; char *nidName = GetNidNameByDhId(dhId); if (nidName == NULL) { - LOGE("Get nid name failed."); + LOGE_ONE_STR("Get nid name failed."); return NULL; } params[0] = OpensslOsslParamConstructUtf8String("group", nidName, 0); params[1] = OpensslOsslParamConstructEnd(); if (OpensslEvpPkeyKeyGenInit(paramsCtx) != HCF_OPENSSL_SUCCESS) { - LOGD("[error] ParamsCtx generate init failed."); + LOGD_ONE_STR("[error] ParamsCtx generate init failed."); return NULL; } if (OpensslEvpPkeyCtxSetParams(paramsCtx, params) != HCF_OPENSSL_SUCCESS) { - LOGD("[error] ParamsCtx set failed."); + LOGD_ONE_STR("[error] ParamsCtx set failed."); return NULL; } if (OpensslEvpPkeyGenerate(paramsCtx, ¶msPkey) != HCF_OPENSSL_SUCCESS) { - LOGD("[error] Create generate failed."); + LOGD_ONE_STR("[error] Create generate failed."); return NULL; } return paramsPkey; @@ -460,34 +460,34 @@ static HcfResult GenerateDhEvpKey(int32_t dhId, EVP_PKEY **ppkey) do { paramsCtx = OpensslEvpPkeyCtxNewFromName(NULL, "DH", NULL); if (paramsCtx == NULL) { - LOGD("[error] New paramsCtx from name failed."); + LOGD_ONE_STR("[error] New paramsCtx from name failed."); ret = HCF_ERR_CRYPTO_OPERATION; break; } paramsPkey = ConstructDhOsslParamsAndGenPkey(dhId, paramsCtx); if (paramsPkey == NULL) { - LOGD("[error] Construct dh params and generate pkey failed."); + LOGD_ONE_STR("[error] Construct dh params and generate pkey failed."); ret = HCF_ERR_CRYPTO_OPERATION; break; } pkeyCtx = OpensslEvpPkeyCtxNew(paramsPkey, NULL); if (pkeyCtx == NULL) { - LOGD("[error] Create pkey ctx failed."); + LOGD_ONE_STR("[error] Create pkey ctx failed."); ret = HCF_ERR_CRYPTO_OPERATION; break; } if (OpensslEvpPkeyKeyGenInit(pkeyCtx) != HCF_OPENSSL_SUCCESS) { - LOGD("[error] Key ctx generate init failed."); + LOGD_ONE_STR("[error] Key ctx generate init failed."); ret = HCF_ERR_CRYPTO_OPERATION; break; } if (OpensslEvpPkeyKeyGen(pkeyCtx, ppkey) != HCF_OPENSSL_SUCCESS) { - LOGD("[error] Generate pkey failed."); + LOGD_ONE_STR("[error] Generate pkey failed."); ret = HCF_ERR_CRYPTO_OPERATION; break; } if (OpensslEvpPkeyCheck(pkeyCtx) != HCF_OPENSSL_SUCCESS) { - LOGD("[error] Check pkey fail."); + LOGD_ONE_STR("[error] Check pkey fail."); OpensslEvpPkeyFree(*ppkey); *ppkey = NULL; ret = HCF_ERR_CRYPTO_OPERATION; @@ -539,7 +539,7 @@ static HcfResult CreateDhPubKey(DH *pk, HcfOpensslDhPubKey **returnPubKey) { HcfOpensslDhPubKey *dhPubKey = (HcfOpensslDhPubKey *)HcfMalloc(sizeof(HcfOpensslDhPubKey), 0); if (dhPubKey == NULL) { - LOGE("Failed to allocate DH public key memory."); + LOGE_ONE_STR("Failed to allocate DH public key memory."); return HCF_ERR_MALLOC; } FillOpensslDhPubKeyFunc(dhPubKey); @@ -553,7 +553,7 @@ static HcfResult CreateDhPriKey(DH *sk, HcfOpensslDhPriKey **returnPriKey) { HcfOpensslDhPriKey *dhPriKey = (HcfOpensslDhPriKey *)HcfMalloc(sizeof(HcfOpensslDhPriKey), 0); if (dhPriKey == NULL) { - LOGE("Failed to allocate Dh private key memory."); + LOGE_ONE_STR("Failed to allocate Dh private key memory."); return HCF_ERR_MALLOC; } FillOpensslDhPriKeyFunc(dhPriKey); @@ -568,7 +568,7 @@ static HcfResult CreateDhKeyPair(const HcfOpensslDhPubKey *pubKey, const HcfOpen { HcfOpensslDhKeyPair *keyPair = (HcfOpensslDhKeyPair *)HcfMalloc(sizeof(HcfOpensslDhKeyPair), 0); if (keyPair == NULL) { - LOGE("Failed to allocate keyPair memory."); + LOGE_ONE_STR("Failed to allocate keyPair memory."); return HCF_ERR_MALLOC; } keyPair->base.base.getClass = GetDhKeyPairClass; @@ -584,13 +584,13 @@ static HcfResult GeneratePubKeyByPkey(EVP_PKEY *pkey, HcfOpensslDhPubKey **retur { DH *pk = OpensslEvpPkeyGet1Dh(pkey); if (pk == NULL) { - LOGD("[error] Get dh public key from pkey failed"); + LOGD_ONE_STR("[error] Get dh public key from pkey failed"); HcfPrintOpensslError(); return HCF_ERR_CRYPTO_OPERATION; } HcfResult ret = CreateDhPubKey(pk, returnPubKey); if (ret != HCF_SUCCESS) { - LOGD("[error] Create DH public key failed"); + LOGD_ONE_STR("[error] Create DH public key failed"); OpensslDhFree(pk); } return ret; @@ -600,13 +600,13 @@ static HcfResult GeneratePriKeyByPkey(EVP_PKEY *pkey, HcfOpensslDhPriKey **retur { DH *sk = OpensslEvpPkeyGet1Dh(pkey); if (sk == NULL) { - LOGD("[error] Get DH private key from pkey failed"); + LOGD_ONE_STR("[error] Get DH private key from pkey failed"); HcfPrintOpensslError(); return HCF_ERR_CRYPTO_OPERATION; } HcfResult ret = CreateDhPriKey(sk, returnPriKey); if (ret != HCF_SUCCESS) { - LOGD("[error] Create DH private key failed"); + LOGD_ONE_STR("[error] Create DH private key failed"); OpensslDhFree(sk); } return ret; @@ -618,14 +618,14 @@ static HcfResult GenerateDhPubAndPriKey(int32_t dhId, HcfOpensslDhPubKey **retur EVP_PKEY *pkey = NULL; HcfResult ret = GenerateDhEvpKey(dhId, &pkey); if (ret != HCF_SUCCESS) { - LOGE("Generate DH EVP_PKEY failed."); + LOGE_ONE_STR("Generate DH EVP_PKEY failed."); return ret; } ret = GeneratePubKeyByPkey(pkey, returnPubKey); if (ret != HCF_SUCCESS) { OpensslEvpPkeyFree(pkey); - LOGE("Generate public key failed."); + LOGE_ONE_STR("Generate public key failed."); return ret; } @@ -634,7 +634,7 @@ static HcfResult GenerateDhPubAndPriKey(int32_t dhId, HcfOpensslDhPubKey **retur HcfObjDestroy(*returnPubKey); *returnPubKey = NULL; OpensslEvpPkeyFree(pkey); - LOGE("Generate private key failed."); + LOGE_ONE_STR("Generate private key failed."); return ret; } @@ -645,11 +645,11 @@ static HcfResult GenerateDhPubAndPriKey(int32_t dhId, HcfOpensslDhPubKey **retur static HcfResult ConvertCommSpec2Bn(const HcfDhCommParamsSpec *paramsSpec, BIGNUM **p, BIGNUM **g) { if (BigIntegerToBigNum(&(paramsSpec->p), p) != HCF_SUCCESS) { - LOGD("[error] Get openssl BN p failed"); + LOGD_ONE_STR("[error] Get openssl BN p failed"); return HCF_ERR_CRYPTO_OPERATION; } if (BigIntegerToBigNum(&(paramsSpec->g), g) != HCF_SUCCESS) { - LOGD("[error] Get openssl BN g failed"); + LOGD_ONE_STR("[error] Get openssl BN g failed"); OpensslBnFree(*p); *p = NULL; return HCF_ERR_CRYPTO_OPERATION; @@ -662,18 +662,18 @@ static HcfResult CreateOpensslDhKey(const HcfDhCommParamsSpec *paramsSpec, BIGNU BIGNUM *p = NULL; BIGNUM *g = NULL; if (ConvertCommSpec2Bn(paramsSpec, &p, &g)!= HCF_SUCCESS) { - LOGD("[error] Get openssl BN p q failed"); + LOGD_ONE_STR("[error] Get openssl BN p q failed"); return HCF_ERR_CRYPTO_OPERATION; } DH *dh = OpensslDhNew(); if (dh == NULL) { FreeCommSpecBn(p, g); - LOGD("[error] Openssl dh new failed"); + LOGD_ONE_STR("[error] Openssl dh new failed"); HcfPrintOpensslError(); return HCF_ERR_CRYPTO_OPERATION; } if (OpensslDhSet0Pqg(dh, p, NULL, g) != HCF_OPENSSL_SUCCESS) { - LOGD("[error] Openssl dh set pqg failed"); + LOGD_ONE_STR("[error] Openssl dh set pqg failed"); HcfPrintOpensslError(); FreeCommSpecBn(p, g); OpensslDhFree(dh); @@ -681,7 +681,7 @@ static HcfResult CreateOpensslDhKey(const HcfDhCommParamsSpec *paramsSpec, BIGNU } if (paramsSpec->length > 0) { if (OpensslDhSetLength(dh, paramsSpec->length) != HCF_OPENSSL_SUCCESS) { - LOGD("[error] Openssl dh set length failed"); + LOGD_ONE_STR("[error] Openssl dh set length failed"); HcfPrintOpensslError(); OpensslDhFree(dh); return HCF_ERR_CRYPTO_OPERATION; @@ -692,7 +692,7 @@ static HcfResult CreateOpensslDhKey(const HcfDhCommParamsSpec *paramsSpec, BIGNU return HCF_SUCCESS; } if (OpensslDhSet0Key(dh, pk, sk) != HCF_OPENSSL_SUCCESS) { - LOGD("[error] Openssl DH set key failed"); + LOGD_ONE_STR("[error] Openssl DH set key failed"); HcfPrintOpensslError(); OpensslDhFree(dh); return HCF_ERR_CRYPTO_OPERATION; @@ -704,12 +704,12 @@ static HcfResult CreateOpensslDhKey(const HcfDhCommParamsSpec *paramsSpec, BIGNU static HcfResult GenerateOpensslDhKeyByCommSpec(const HcfDhCommParamsSpec *paramsSpec, DH **returnDh) { if (CreateOpensslDhKey(paramsSpec, NULL, NULL, returnDh) != HCF_SUCCESS) { - LOGD("[error] Create openssl dh key failed"); + LOGD_ONE_STR("[error] Create openssl dh key failed"); return HCF_ERR_CRYPTO_OPERATION; } if (OpensslDhGenerateKey(*returnDh) != HCF_OPENSSL_SUCCESS) { - LOGD("[error] Openssl DH generate key failed"); + LOGD_ONE_STR("[error] Openssl DH generate key failed"); HcfPrintOpensslError(); OpensslDhFree(*returnDh); *returnDh = NULL; @@ -722,12 +722,12 @@ static HcfResult GenerateOpensslDhKeyByPubKeySpec(const HcfDhPubKeyParamsSpec *p { BIGNUM *pubKey = NULL; if (BigIntegerToBigNum(&(paramsSpec->pk), &pubKey) != HCF_SUCCESS) { - LOGD("[error] Get openssl BN pk failed"); + LOGD_ONE_STR("[error] Get openssl BN pk failed"); return HCF_ERR_CRYPTO_OPERATION; } if (CreateOpensslDhKey(&(paramsSpec->base), pubKey, NULL, returnDh) != HCF_SUCCESS) { - LOGD("[error] Create dh key failed."); + LOGD_ONE_STR("[error] Create dh key failed."); OpensslBnFree(pubKey); return HCF_ERR_CRYPTO_OPERATION; } @@ -738,12 +738,12 @@ static HcfResult GenerateOpensslDhKeyByPriKeySpec(const HcfDhPriKeyParamsSpec *p { BIGNUM *priKey = NULL; if (BigIntegerToBigNum(&(paramsSpec->sk), &priKey) != HCF_SUCCESS) { - LOGD("[error] Get openssl BN pk failed"); + LOGD_ONE_STR("[error] Get openssl BN pk failed"); return HCF_ERR_CRYPTO_OPERATION; } if (CreateOpensslDhKey(&(paramsSpec->base), NULL, priKey, returnDh) != HCF_SUCCESS) { - LOGD("[error] Create dh key failed."); + LOGD_ONE_STR("[error] Create dh key failed."); OpensslBnFree(priKey); return HCF_ERR_CRYPTO_OPERATION; } @@ -755,16 +755,16 @@ static HcfResult GenerateOpensslDhKeyByKeyPairSpec(const HcfDhKeyPairParamsSpec BIGNUM *pubKey = NULL; BIGNUM *priKey = NULL; if (BigIntegerToBigNum(&(paramsSpec->pk), &pubKey) != HCF_SUCCESS) { - LOGD("[error] Get openssl BN pk failed"); + LOGD_ONE_STR("[error] Get openssl BN pk failed"); return HCF_ERR_CRYPTO_OPERATION; } if (BigIntegerToBigNum(&(paramsSpec->sk), &priKey) != HCF_SUCCESS) { - LOGD("[error] Get openssl BN sk failed"); + LOGD_ONE_STR("[error] Get openssl BN sk failed"); OpensslBnFree(pubKey); return HCF_ERR_CRYPTO_OPERATION; } if (CreateOpensslDhKey(&(paramsSpec->base), pubKey, priKey, returnDh) != HCF_SUCCESS) { - LOGD("[error] Create dh key failed."); + LOGD_ONE_STR("[error] Create dh key failed."); OpensslBnFree(pubKey); OpensslBnFree(priKey); return HCF_ERR_CRYPTO_OPERATION; @@ -776,18 +776,18 @@ static HcfResult CreateDhKeyPairByCommSpec(const HcfDhCommParamsSpec *paramsSpec { DH *dh = NULL; if (GenerateOpensslDhKeyByCommSpec(paramsSpec, &dh) != HCF_SUCCESS) { - LOGD("[error] Generate openssl dh key by commSpec failed."); + LOGD_ONE_STR("[error] Generate openssl dh key by commSpec failed."); return HCF_ERR_CRYPTO_OPERATION; } HcfOpensslDhPubKey *pubKey = NULL; if (CreateDhPubKey(dh, &pubKey) != HCF_SUCCESS) { - LOGE("Create dh pubKey failed."); + LOGE_ONE_STR("Create dh pubKey failed."); OpensslDhFree(dh); return HCF_ERR_MALLOC; } if (OpensslDhUpRef(dh) != HCF_OPENSSL_SUCCESS) { - LOGD("[error] DH_up_ref failed."); + LOGD_ONE_STR("[error] DH_up_ref failed."); HcfPrintOpensslError(); HcfObjDestroy(pubKey); return HCF_ERR_CRYPTO_OPERATION; @@ -795,14 +795,14 @@ static HcfResult CreateDhKeyPairByCommSpec(const HcfDhCommParamsSpec *paramsSpec HcfOpensslDhPriKey *priKey = NULL; if (CreateDhPriKey(dh, &priKey) != HCF_SUCCESS) { - LOGE("Create dh priKey failed."); + LOGE_ONE_STR("Create dh priKey failed."); OpensslDhFree(dh); HcfObjDestroy(pubKey); return HCF_ERR_MALLOC; } if (CreateDhKeyPair(pubKey, priKey, returnKeyPair) != HCF_SUCCESS) { - LOGE("Create dh keyPair failed."); + LOGE_ONE_STR("Create dh keyPair failed."); HcfObjDestroy(pubKey); HcfObjDestroy(priKey); return HCF_ERR_MALLOC; @@ -815,11 +815,11 @@ static HcfResult CreateDhPubKeyByKeyPairSpec(const HcfDhKeyPairParamsSpec *param { DH *dh = NULL; if (GenerateOpensslDhKeyByKeyPairSpec(paramsSpec, &dh) != HCF_SUCCESS) { - LOGD("[error] Generate openssl dh key by keyPairSpec failed."); + LOGD_ONE_STR("[error] Generate openssl dh key by keyPairSpec failed."); return HCF_ERR_CRYPTO_OPERATION; } if (CreateDhPubKey(dh, returnPubKey) != HCF_SUCCESS) { - LOGE("Create dh pubKey failed."); + LOGE_ONE_STR("Create dh pubKey failed."); OpensslDhFree(dh); return HCF_ERR_MALLOC; } @@ -831,11 +831,11 @@ static HcfResult CreateDhPriKeyByKeyPairSpec(const HcfDhKeyPairParamsSpec *param { DH *dh = NULL; if (GenerateOpensslDhKeyByKeyPairSpec(paramsSpec, &dh) != HCF_SUCCESS) { - LOGD("[error] Generate openssl dh key by keyPairSpec failed."); + LOGD_ONE_STR("[error] Generate openssl dh key by keyPairSpec failed."); return HCF_ERR_CRYPTO_OPERATION; } if (CreateDhPriKey(dh, returnPriKey) != HCF_SUCCESS) { - LOGE("Create dh priKey failed."); + LOGE_ONE_STR("Create dh priKey failed."); OpensslDhFree(dh); return HCF_ERR_MALLOC; } @@ -847,20 +847,20 @@ static HcfResult CreateDhKeyPairByKeyPairSpec(const HcfDhKeyPairParamsSpec *para HcfOpensslDhPubKey *pubKey = NULL; HcfResult ret = CreateDhPubKeyByKeyPairSpec(paramsSpec, &pubKey); if (ret != HCF_SUCCESS) { - LOGD("[error] Create dh pubKey by keyPairSpec failed."); + LOGD_ONE_STR("[error] Create dh pubKey by keyPairSpec failed."); return ret; } HcfOpensslDhPriKey *priKey = NULL; ret = CreateDhPriKeyByKeyPairSpec(paramsSpec, &priKey); if (ret != HCF_SUCCESS) { - LOGD("[error] Create dh priKey by keyPairSpec failed."); + LOGD_ONE_STR("[error] Create dh priKey by keyPairSpec failed."); HcfObjDestroy(pubKey); return ret; } ret = CreateDhKeyPair(pubKey, priKey, returnKeyPair); if (ret != HCF_SUCCESS) { - LOGD("[error] Create dh keyPair failed."); + LOGD_ONE_STR("[error] Create dh keyPair failed."); HcfObjDestroy(pubKey); HcfObjDestroy(priKey); return ret; @@ -881,13 +881,13 @@ static HcfResult CreateDhPubKeyBySpec(const HcfDhPubKeyParamsSpec *paramsSpec, H { DH *dh = NULL; if (GenerateOpensslDhKeyByPubKeySpec(paramsSpec, &dh) != HCF_SUCCESS) { - LOGD("[error] Generate openssl dh key by pubKeySpec failed."); + LOGD_ONE_STR("[error] Generate openssl dh key by pubKeySpec failed."); return HCF_ERR_CRYPTO_OPERATION; } HcfOpensslDhPubKey *pubKey = NULL; if (CreateDhPubKey(dh, &pubKey) != HCF_SUCCESS) { - LOGE("Create dh pubKey failed."); + LOGE_ONE_STR("Create dh pubKey failed."); OpensslDhFree(dh); return HCF_ERR_MALLOC; } @@ -899,13 +899,13 @@ static HcfResult CreateDhPriKeyBySpec(const HcfDhPriKeyParamsSpec *paramsSpec, H { DH *dh = NULL; if (GenerateOpensslDhKeyByPriKeySpec(paramsSpec, &dh) != HCF_SUCCESS) { - LOGD("[error] Generate openssl dh key by priKeySpec failed."); + LOGD_ONE_STR("[error] Generate openssl dh key by priKeySpec failed."); return HCF_ERR_CRYPTO_OPERATION; } HcfOpensslDhPriKey *priKey = NULL; if (CreateDhPriKey(dh, &priKey) != HCF_SUCCESS) { - LOGE("Create dh priKey failed."); + LOGE_ONE_STR("Create dh priKey failed."); OpensslDhFree(dh); return HCF_ERR_MALLOC; } @@ -918,13 +918,13 @@ static HcfResult ConvertDhPubKey(const HcfBlob *pubKeyBlob, HcfOpensslDhPubKey * const unsigned char *temp = (const unsigned char *)pubKeyBlob->data; EVP_PKEY *pKey = OpensslD2iPubKey(NULL, &temp, pubKeyBlob->len); if (pKey == NULL) { - LOGD("[error] Call d2i_PUBKEY failed."); + LOGD_ONE_STR("[error] Call d2i_PUBKEY failed."); HcfPrintOpensslError(); return HCF_ERR_CRYPTO_OPERATION; } DH *dh = OpensslEvpPkeyGet1Dh(pKey); if (dh == NULL) { - LOGD("[error] EVP_PKEY_get1_DH failed"); + LOGD_ONE_STR("[error] EVP_PKEY_get1_DH failed"); HcfPrintOpensslError(); OpensslEvpPkeyFree(pKey); return HCF_ERR_CRYPTO_OPERATION; @@ -932,7 +932,7 @@ static HcfResult ConvertDhPubKey(const HcfBlob *pubKeyBlob, HcfOpensslDhPubKey * OpensslEvpPkeyFree(pKey); HcfResult ret = CreateDhPubKey(dh, returnPubKey); if (ret != HCF_SUCCESS) { - LOGE("Create dh public key failed"); + LOGE_ONE_STR("Create dh public key failed"); OpensslDhFree(dh); } return ret; @@ -943,13 +943,13 @@ static HcfResult ConvertDhPriKey(const HcfBlob *priKeyBlob, HcfOpensslDhPriKey * const unsigned char *temp = (const unsigned char *)priKeyBlob->data; EVP_PKEY *pKey = OpensslD2iPrivateKey(EVP_PKEY_DH, NULL, &temp, priKeyBlob->len); if (pKey == NULL) { - LOGD("[error] Call d2i_PrivateKey failed."); + LOGD_ONE_STR("[error] Call d2i_PrivateKey failed."); HcfPrintOpensslError(); return HCF_ERR_CRYPTO_OPERATION; } DH *dh = OpensslEvpPkeyGet1Dh(pKey); if (dh == NULL) { - LOGD("[error] EVP_PKEY_get1_DH failed"); + LOGD_ONE_STR("[error] EVP_PKEY_get1_DH failed"); HcfPrintOpensslError(); OpensslEvpPkeyFree(pKey); return HCF_ERR_CRYPTO_OPERATION; @@ -957,7 +957,7 @@ static HcfResult ConvertDhPriKey(const HcfBlob *priKeyBlob, HcfOpensslDhPriKey * OpensslEvpPkeyFree(pKey); HcfResult ret = CreateDhPriKey(dh, returnPriKey); if (ret != HCF_SUCCESS) { - LOGE("Create DH private key failed"); + LOGE_ONE_STR("Create DH private key failed"); OpensslDhFree(dh); } return ret; @@ -968,13 +968,13 @@ static HcfResult ConvertDhPubAndPriKey(const HcfBlob *pubKeyBlob, const HcfBlob { if (pubKeyBlob != NULL) { if (ConvertDhPubKey(pubKeyBlob, returnPubKey) != HCF_SUCCESS) { - LOGD("[error] Convert DH public key failed."); + LOGD_ONE_STR("[error] Convert DH public key failed."); return HCF_ERR_CRYPTO_OPERATION; } } if (priKeyBlob != NULL) { if (ConvertDhPriKey(priKeyBlob, returnPriKey) != HCF_SUCCESS) { - LOGD("[error] Convert DH private key failed."); + LOGD_ONE_STR("[error] Convert DH private key failed."); HcfObjDestroy(*returnPubKey); *returnPubKey = NULL; return HCF_ERR_CRYPTO_OPERATION; @@ -986,11 +986,11 @@ static HcfResult ConvertDhPubAndPriKey(const HcfBlob *pubKeyBlob, const HcfBlob static HcfResult EngineGenerateDhKeyPair(HcfAsyKeyGeneratorSpi *self, HcfKeyPair **returnKeyPair) { if (self == NULL || returnKeyPair == NULL) { - LOGE("Invalid params."); + LOGE_ONE_STR("Invalid params."); return HCF_INVALID_PARAMS; } if (!HcfIsClassMatch((HcfObjectBase *)self, GetDhKeyGeneratorSpiClass())) { - LOGE("Class not match."); + LOGE_ONE_STR("Class not match."); return HCF_INVALID_PARAMS; } HcfAsyKeyGeneratorSpiDhOpensslImpl *impl = (HcfAsyKeyGeneratorSpiDhOpensslImpl *)self; @@ -999,12 +999,12 @@ static HcfResult EngineGenerateDhKeyPair(HcfAsyKeyGeneratorSpi *self, HcfKeyPair HcfOpensslDhPriKey *priKey = NULL; HcfResult ret = GenerateDhPubAndPriKey(impl->pBits, &pubKey, &priKey); if (ret != HCF_SUCCESS) { - LOGE("Generate DH pk and sk by openssl failed."); + LOGE_ONE_STR("Generate DH pk and sk by openssl failed."); return ret; } ret = CreateDhKeyPair(pubKey, priKey, returnKeyPair); if (ret != HCF_SUCCESS) { - LOGE("Create dh keyPair failed."); + LOGE_ONE_STR("Create dh keyPair failed."); HcfObjDestroy(pubKey); HcfObjDestroy(priKey); return ret; @@ -1017,17 +1017,17 @@ static HcfResult EngineConvertDhKey(HcfAsyKeyGeneratorSpi *self, HcfParamsSpec * { (void)params; if ((self == NULL) || (returnKeyPair == NULL)) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return HCF_INVALID_PARAMS; } if (!HcfIsClassMatch((HcfObjectBase *)self, GetDhKeyGeneratorSpiClass())) { - LOGE("Class not match."); + LOGE_ONE_STR("Class not match."); return HCF_INVALID_PARAMS; } bool pubKeyValid = HcfIsBlobValid(pubKeyBlob); bool priKeyValid = HcfIsBlobValid(priKeyBlob); if ((!pubKeyValid) && (!priKeyValid)) { - LOGE("The private key and public key cannot both be NULL."); + LOGE_ONE_STR("The private key and public key cannot both be NULL."); return HCF_INVALID_PARAMS; } @@ -1037,12 +1037,12 @@ static HcfResult EngineConvertDhKey(HcfAsyKeyGeneratorSpi *self, HcfParamsSpec * HcfBlob *inputSk = priKeyValid ? priKeyBlob : NULL; HcfResult ret = ConvertDhPubAndPriKey(inputPk, inputSk, &pubKey, &priKey); if (ret != HCF_SUCCESS) { - LOGE("Convert dh pubKey and priKey failed."); + LOGE_ONE_STR("Convert dh pubKey and priKey failed."); return ret; } ret = CreateDhKeyPair(pubKey, priKey, returnKeyPair); if (ret != HCF_SUCCESS) { - LOGE("Create dh keyPair failed."); + LOGE_ONE_STR("Create dh keyPair failed."); HcfObjDestroy(pubKey); HcfObjDestroy(priKey); } @@ -1055,21 +1055,21 @@ static HcfResult ConvertDhPemPubKey(const char *pubKeyStr, HcfOpensslDhPubKey ** const char *keyType = "DH"; HcfResult ret = ConvertPubPemStrToKey(&pkey, keyType, EVP_PKEY_PUBLIC_KEY, pubKeyStr); if (ret != HCF_SUCCESS) { - LOGE("Convert dh pem public key failed."); + LOGE_ONE_STR("Convert dh pem public key failed."); return ret; } DH *dh = OpensslEvpPkeyGet1Dh(pkey); OpensslEvpPkeyFree(pkey); if (dh == NULL) { - LOGE("Pkey to dh key failed."); + LOGE_ONE_STR("Pkey to dh key failed."); HcfPrintOpensslError(); return HCF_ERR_CRYPTO_OPERATION; } ret = CreateDhPubKey(dh, returnPubKey); if (ret != HCF_SUCCESS) { - LOGE("Create dh public key failed."); + LOGE_ONE_STR("Create dh public key failed."); OpensslDhFree(dh); } @@ -1082,21 +1082,21 @@ static HcfResult ConvertDhPemPriKey(const char *priKeyStr, HcfOpensslDhPriKey ** const char *keyType = "DH"; HcfResult ret = ConvertPriPemStrToKey(priKeyStr, &pkey, keyType); if (ret != HCF_SUCCESS) { - LOGE("Convert dh pem private key failed."); + LOGE_ONE_STR("Convert dh pem private key failed."); return ret; } DH *dh = OpensslEvpPkeyGet1Dh(pkey); OpensslEvpPkeyFree(pkey); if (dh == NULL) { - LOGE("Pkey to dh key failed."); + LOGE_ONE_STR("Pkey to dh key failed."); HcfPrintOpensslError(); return HCF_ERR_CRYPTO_OPERATION; } ret = CreateDhPriKey(dh, returnPriKey); if (ret != HCF_SUCCESS) { - LOGE("Create DH private key failed."); + LOGE_ONE_STR("Create DH private key failed."); OpensslDhFree(dh); } @@ -1108,14 +1108,14 @@ static HcfResult ConvertDhPemPubAndPriKey(const char *pubKeyStr, const char *pri { if (pubKeyStr != NULL && strlen(pubKeyStr) != 0) { if (ConvertDhPemPubKey(pubKeyStr, returnPubKey) != HCF_SUCCESS) { - LOGE("Convert dh pem public key failed."); + LOGE_ONE_STR("Convert dh pem public key failed."); return HCF_ERR_CRYPTO_OPERATION; } } if (priKeyStr != NULL && strlen(priKeyStr) != 0) { if (ConvertDhPemPriKey(priKeyStr, returnPriKey) != HCF_SUCCESS) { - LOGE("Convert dh pem private key failed."); + LOGE_ONE_STR("Convert dh pem private key failed."); HcfObjDestroy(*returnPubKey); *returnPubKey = NULL; return HCF_ERR_CRYPTO_OPERATION; @@ -1130,11 +1130,11 @@ static HcfResult EngineConvertDhPemKey(HcfAsyKeyGeneratorSpi *self, HcfParamsSpe { (void)params; if ((self == NULL) || (returnKeyPair == NULL) || ((pubKeyStr == NULL) && (priKeyStr == NULL))) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return HCF_INVALID_PARAMS; } if (!HcfIsClassMatch((HcfObjectBase *)self, GetDhKeyGeneratorSpiClass())) { - LOGE("Class not match."); + LOGE_ONE_STR("Class not match."); return HCF_INVALID_PARAMS; } @@ -1143,13 +1143,13 @@ static HcfResult EngineConvertDhPemKey(HcfAsyKeyGeneratorSpi *self, HcfParamsSpe HcfResult ret = ConvertDhPemPubAndPriKey(pubKeyStr, priKeyStr, &pubKey, &priKey); if (ret != HCF_SUCCESS) { - LOGE("Convert dh pem pubKey and priKey failed."); + LOGE_ONE_STR("Convert dh pem pubKey and priKey failed."); return ret; } ret = CreateDhKeyPair(pubKey, priKey, returnKeyPair); if (ret != HCF_SUCCESS) { - LOGE("Create dh keyPair failed."); + LOGE_ONE_STR("Create dh keyPair failed."); HcfObjDestroy(pubKey); HcfObjDestroy(priKey); } @@ -1161,23 +1161,23 @@ static HcfResult EngineGenerateDhKeyPairBySpec(const HcfAsyKeyGeneratorSpi *self const HcfAsyKeyParamsSpec *paramsSpec, HcfKeyPair **returnKeyPair) { if ((self == NULL) || (paramsSpec == NULL) || (paramsSpec->algName == NULL) || (returnKeyPair == NULL)) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return HCF_INVALID_PARAMS; } if (!HcfIsClassMatch((HcfObjectBase *)self, GetDhKeyGeneratorSpiClass())) { - LOGE("Class not match."); + LOGE_ONE_STR("Class not match."); return HCF_INVALID_PARAMS; } if ((strcmp(paramsSpec->algName, ALGORITHM_NAME_DH) != 0) || ((paramsSpec->specType != HCF_COMMON_PARAMS_SPEC) && (paramsSpec->specType != HCF_KEY_PAIR_SPEC))) { - LOGE("Invalid params spec."); + LOGE_ONE_STR("Invalid params spec."); return HCF_INVALID_PARAMS; } HcfResult ret = CreateDhKeyPairBySpec(paramsSpec, returnKeyPair); if (ret != HCF_SUCCESS) { - LOGE("Create DH key pair by spec failed."); + LOGE_ONE_STR("Create DH key pair by spec failed."); } return ret; } @@ -1186,24 +1186,24 @@ static HcfResult EngineGenerateDhPubKeyBySpec(const HcfAsyKeyGeneratorSpi *self, const HcfAsyKeyParamsSpec *paramsSpec, HcfPubKey **returnPubKey) { if ((self == NULL) || (paramsSpec == NULL) || (paramsSpec->algName == NULL) || (returnPubKey == NULL)) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return HCF_INVALID_PARAMS; } if (!HcfIsClassMatch((HcfObjectBase *)self, GetDhKeyGeneratorSpiClass())) { - LOGE("Class not match."); + LOGE_ONE_STR("Class not match."); return HCF_INVALID_PARAMS; } if ((strcmp(paramsSpec->algName, ALGORITHM_NAME_DH) != 0) || ((paramsSpec->specType != HCF_PUBLIC_KEY_SPEC) && (paramsSpec->specType != HCF_KEY_PAIR_SPEC))) { - LOGE("Invalid params spec."); + LOGE_ONE_STR("Invalid params spec."); return HCF_INVALID_PARAMS; } HcfResult ret = CreateDhPubKeyBySpec((const HcfDhPubKeyParamsSpec *)paramsSpec, returnPubKey); if (ret != HCF_SUCCESS) { - LOGE("Create DH public key by spec failed."); + LOGE_ONE_STR("Create DH public key by spec failed."); } return ret; } @@ -1212,22 +1212,22 @@ static HcfResult EngineGenerateDhPriKeyBySpec(const HcfAsyKeyGeneratorSpi *self, const HcfAsyKeyParamsSpec *paramsSpec, HcfPriKey **returnPriKey) { if ((self == NULL) || (paramsSpec == NULL) || (paramsSpec->algName == NULL) || (returnPriKey == NULL)) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return HCF_INVALID_PARAMS; } if (!HcfIsClassMatch((HcfObjectBase *)self, GetDhKeyGeneratorSpiClass())) { - LOGE("Class not match."); + LOGE_ONE_STR("Class not match."); return HCF_INVALID_PARAMS; } if ((strcmp(paramsSpec->algName, ALGORITHM_NAME_DH) != 0) || ((paramsSpec->specType != HCF_PRIVATE_KEY_SPEC) && (paramsSpec->specType != HCF_KEY_PAIR_SPEC))) { - LOGE("Invalid params spec."); + LOGE_ONE_STR("Invalid params spec."); return HCF_INVALID_PARAMS; } HcfResult ret = CreateDhPriKeyBySpec((const HcfDhPriKeyParamsSpec *)paramsSpec, returnPriKey); if (ret != HCF_SUCCESS) { - LOGE("Create DH private key by spec failed."); + LOGE_ONE_STR("Create DH private key by spec failed."); } return ret; } @@ -1235,13 +1235,13 @@ static HcfResult EngineGenerateDhPriKeyBySpec(const HcfAsyKeyGeneratorSpi *self, HcfResult HcfAsyKeyGeneratorSpiDhCreate(HcfAsyKeyGenParams *params, HcfAsyKeyGeneratorSpi **generator) { if (params == NULL || generator == NULL) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return HCF_INVALID_PARAMS; } HcfAsyKeyGeneratorSpiDhOpensslImpl *impl = (HcfAsyKeyGeneratorSpiDhOpensslImpl *)HcfMalloc( sizeof(HcfAsyKeyGeneratorSpiDhOpensslImpl), 0); if (impl == NULL) { - LOGE("Failed to allocate generator impl memroy."); + LOGE_ONE_STR("Failed to allocate generator impl memroy."); return HCF_ERR_MALLOC; } impl->pBits = params->bits; diff --git a/plugin/openssl_plugin/key/asy_key_generator/src/dh_common_param_spec_generator_openssl.c b/plugin/openssl_plugin/key/asy_key_generator/src/dh_common_param_spec_generator_openssl.c index 928dab78d12531a56266ec7deb191f4cbb3b216f..fecf434e2b1f5ff272214175caf9acbe82f5043f 100644 --- a/plugin/openssl_plugin/key/asy_key_generator/src/dh_common_param_spec_generator_openssl.c +++ b/plugin/openssl_plugin/key/asy_key_generator/src/dh_common_param_spec_generator_openssl.c @@ -32,26 +32,26 @@ static HcfResult GenerateDhUnknownGroupEvpKey(int32_t pLen, EVP_PKEY **ppkey) EVP_PKEY_CTX *paramsCtx = OpensslEvpPkeyCtxNewId(EVP_PKEY_DH, NULL); if (paramsCtx == NULL) { HcfPrintOpensslError(); - LOGD("[error] Create params ctx failed."); + LOGD_ONE_STR("[error] Create params ctx failed."); return HCF_ERR_CRYPTO_OPERATION; } HcfResult ret = HCF_SUCCESS; do { if (OpensslEvpPkeyParamGenInit(paramsCtx) != HCF_OPENSSL_SUCCESS) { HcfPrintOpensslError(); - LOGD("[error] Params ctx paramgen init failed."); + LOGD_ONE_STR("[error] Params ctx paramgen init failed."); ret = HCF_ERR_CRYPTO_OPERATION; break; } if (OpensslEvpPkeyCtxSetDhParamgenPrimeLen(paramsCtx, pLen) <= 0) { HcfPrintOpensslError(); - LOGD("[error] Set prime length of bits to params ctx failed."); + LOGD_ONE_STR("[error] Set prime length of bits to params ctx failed."); ret = HCF_ERR_CRYPTO_OPERATION; break; } if (OpensslEvpPkeyParamGen(paramsCtx, ppkey) != HCF_OPENSSL_SUCCESS) { HcfPrintOpensslError(); - LOGD("[error] Generate params pkey failed."); + LOGD_ONE_STR("[error] Generate params pkey failed."); ret = HCF_ERR_CRYPTO_OPERATION; break; } @@ -76,24 +76,24 @@ static HcfResult GenerateDhKnownGroupEvpKey(int32_t skLen, char *nidName, EVP_PK do { paramsCtx = OpensslEvpPkeyCtxNewFromName(NULL, "DH", NULL); if (paramsCtx == NULL) { - LOGD("[error] New paramsCtx from name failed."); + LOGD_ONE_STR("[error] New paramsCtx from name failed."); ret = HCF_ERR_CRYPTO_OPERATION; break; } if (OpensslEvpPkeyKeyGenInit(paramsCtx) != HCF_OPENSSL_SUCCESS) { - LOGD("[error] Pkey keygen init failed."); + LOGD_ONE_STR("[error] Pkey keygen init failed."); HcfPrintOpensslError(); ret = HCF_ERR_CRYPTO_OPERATION; break; } if (OpensslEvpPkeyCtxSetParams(paramsCtx, params) != HCF_OPENSSL_SUCCESS) { - LOGD("[error] Set paramsCtx failed."); + LOGD_ONE_STR("[error] Set paramsCtx failed."); HcfPrintOpensslError(); ret = HCF_ERR_CRYPTO_OPERATION; break; } if (OpensslEvpPkeyGenerate(paramsCtx, ppkey) != HCF_OPENSSL_SUCCESS) { - LOGD("[error] Generate pKey failed."); + LOGD_ONE_STR("[error] Generate pKey failed."); HcfPrintOpensslError(); ret = HCF_ERR_CRYPTO_OPERATION; break; @@ -109,17 +109,17 @@ static HcfResult BuildCommonParam(EVP_PKEY *dhKey, HcfDhCommParamsSpecSpi *retur { DH *sk = OpensslEvpPkeyGet1Dh(dhKey); if (sk == NULL) { - LOGD("[error] Get dh private key from pkey failed"); + LOGD_ONE_STR("[error] Get dh private key from pkey failed"); HcfPrintOpensslError(); return HCF_ERR_CRYPTO_OPERATION; } if (BigNumToBigInteger(OpensslDhGet0P(sk), &(returnCommonParamSpec->paramsSpec.p)) != HCF_SUCCESS) { - LOGD("[error] BuildCommonParamPrime failed."); + LOGD_ONE_STR("[error] BuildCommonParamPrime failed."); OpensslDhFree(sk); return HCF_ERR_CRYPTO_OPERATION; } if (BigNumToBigInteger(OpensslDhGet0G(sk), &(returnCommonParamSpec->paramsSpec.g)) != HCF_SUCCESS) { - LOGD("[error] BuildCommonParamGenerator failed."); + LOGD_ONE_STR("[error] BuildCommonParamGenerator failed."); OpensslDhFree(sk); HcfFree(returnCommonParamSpec->paramsSpec.p.data); return HCF_ERR_CRYPTO_OPERATION; @@ -132,12 +132,12 @@ static HcfResult SetAlgName(const char *algName, char **returnAlgName) { size_t srcAlgNameLen = HcfStrlen(algName); if (srcAlgNameLen == 0) { - LOGE("AlgName is empty!"); + LOGE_ONE_STR("AlgName is empty!"); return HCF_INVALID_PARAMS; } *returnAlgName = (char *)HcfMalloc(srcAlgNameLen + 1, 0); if (*returnAlgName == NULL) { - LOGE("Failed to malloc algName memory."); + LOGE_ONE_STR("Failed to malloc algName memory."); return HCF_ERR_MALLOC; } (void)memcpy_s(*returnAlgName, srcAlgNameLen + 1, algName, srcAlgNameLen); @@ -147,25 +147,25 @@ static HcfResult SetAlgName(const char *algName, char **returnAlgName) HcfResult HcfDhCommonParamSpecCreate(int32_t pLen, int32_t skLen, HcfDhCommParamsSpecSpi **returnCommonParamSpec) { if (returnCommonParamSpec == NULL) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return HCF_INVALID_PARAMS; } EVP_PKEY *dhKey = NULL; char *nidName = GetNidNameByDhPLen(pLen); if (nidName == NULL) { if (GenerateDhUnknownGroupEvpKey(pLen, &dhKey) != HCF_SUCCESS) { - LOGD("[error] Generate dh unknown group evpKey failed."); + LOGD_ONE_STR("[error] Generate dh unknown group evpKey failed."); return HCF_ERR_CRYPTO_OPERATION; } } else { if (GenerateDhKnownGroupEvpKey(skLen, nidName, &dhKey) != HCF_SUCCESS) { - LOGD("[error] Generate dh known group evpKey failed."); + LOGD_ONE_STR("[error] Generate dh known group evpKey failed."); return HCF_ERR_CRYPTO_OPERATION; } } HcfDhCommParamsSpecSpi *object = (HcfDhCommParamsSpecSpi*)HcfMalloc(sizeof(HcfDhCommParamsSpecSpi), 0); if (object == NULL) { - LOGE("Build dh common params object failed."); + LOGE_ONE_STR("Build dh common params object failed."); OpensslEvpPkeyFree(dhKey); return HCF_ERR_MALLOC; } @@ -173,13 +173,13 @@ HcfResult HcfDhCommonParamSpecCreate(int32_t pLen, int32_t skLen, HcfDhCommParam object->paramsSpec.base.specType = HCF_COMMON_PARAMS_SPEC; object->paramsSpec.length = skLen; if (SetAlgName(algName, &(object->paramsSpec.base.algName)) != HCF_SUCCESS) { - LOGE("Set algName parameter failed."); + LOGE_ONE_STR("Set algName parameter failed."); HcfFree(object); OpensslEvpPkeyFree(dhKey); return HCF_INVALID_PARAMS; } if (BuildCommonParam(dhKey, object)!= HCF_SUCCESS) { - LOGD("[error] Get common params failed."); + LOGD_ONE_STR("[error] Get common params failed."); HcfFree(object->paramsSpec.base.algName); HcfFree(object); OpensslEvpPkeyFree(dhKey); diff --git a/plugin/openssl_plugin/key/asy_key_generator/src/dsa_asy_key_generator_openssl.c b/plugin/openssl_plugin/key/asy_key_generator/src/dsa_asy_key_generator_openssl.c index 0a29419b21b8146ca567f3c0049e267f3a9d2836..094305d11e2f52dd977592fc6f407eb16c9441d5 100644 --- a/plugin/openssl_plugin/key/asy_key_generator/src/dsa_asy_key_generator_openssl.c +++ b/plugin/openssl_plugin/key/asy_key_generator/src/dsa_asy_key_generator_openssl.c @@ -142,7 +142,7 @@ static void DestroyDsaKeyPair(HcfObjectBase *self) static const char *GetDsaPubKeyAlgorithm(HcfKey *self) { if (self == NULL) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return NULL; } if (!HcfIsClassMatch((HcfObjectBase *)self, GetDsaPubKeyClass())) { @@ -154,7 +154,7 @@ static const char *GetDsaPubKeyAlgorithm(HcfKey *self) static const char *GetDsaPriKeyAlgorithm(HcfKey *self) { if (self == NULL) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return NULL; } if (!HcfIsClassMatch((HcfObjectBase *)self, GetDsaPriKeyClass())) { @@ -166,7 +166,7 @@ static const char *GetDsaPriKeyAlgorithm(HcfKey *self) static HcfResult GetDsaPubKeyEncoded(HcfKey *self, HcfBlob *returnBlob) { if ((self == NULL) || (returnBlob == NULL)) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return HCF_INVALID_PARAMS; } if (!HcfIsClassMatch((HcfObjectBase *)self, GetDsaPubKeyClass())) { @@ -176,7 +176,7 @@ static HcfResult GetDsaPubKeyEncoded(HcfKey *self, HcfBlob *returnBlob) unsigned char *returnData = NULL; int len = OpensslI2dDsaPubkey(impl->pk, &returnData); if (len <= 0) { - LOGD("[error] Call i2d_DSA_PUBKEY failed"); + LOGD_ONE_STR("[error] Call i2d_DSA_PUBKEY failed"); HcfPrintOpensslError(); return HCF_ERR_CRYPTO_OPERATION; } @@ -196,7 +196,7 @@ static HcfResult GetDsaPubKeyEncodedPem(HcfKey *self, const char *format, char * static HcfResult GetDsaPriKeyEncoded(HcfKey *self, HcfBlob *returnBlob) { if ((self == NULL) || (returnBlob == NULL)) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return HCF_INVALID_PARAMS; } if (!HcfIsClassMatch((HcfObjectBase *)self, GetDsaPriKeyClass())) { @@ -206,7 +206,7 @@ static HcfResult GetDsaPriKeyEncoded(HcfKey *self, HcfBlob *returnBlob) unsigned char *returnData = NULL; int len = OpensslI2dDsaPrivateKey(impl->sk, &returnData); if (len <= 0) { - LOGD("[error] Call i2d_DSAPrivateKey failed."); + LOGD_ONE_STR("[error] Call i2d_DSAPrivateKey failed."); HcfPrintOpensslError(); return HCF_ERR_CRYPTO_OPERATION; } @@ -228,7 +228,7 @@ static HcfResult GetDsaPriKeyEncodedPem(const HcfPriKey *self, HcfParamsSpec *pa static const char *GetDsaPubKeyFormat(HcfKey *self) { if (self == NULL) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return NULL; } if (!HcfIsClassMatch((HcfObjectBase *)self, GetDsaPubKeyClass())) { @@ -240,7 +240,7 @@ static const char *GetDsaPubKeyFormat(HcfKey *self) static const char *GetDsaPriKeyFormat(HcfKey *self) { if (self == NULL) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return NULL; } if (!HcfIsClassMatch((HcfObjectBase *)self, GetDsaPriKeyClass())) { @@ -253,11 +253,11 @@ static HcfResult GetBigIntegerSpecFromDsaPubKey(const HcfPubKey *self, const Asy HcfBigInteger *returnBigInteger) { if (self == NULL || returnBigInteger == NULL) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return HCF_INVALID_PARAMS; } if (!HcfIsClassMatch((HcfObjectBase *)self, GetDsaPubKeyClass())) { - LOGE("Invalid class of self."); + LOGE_ONE_STR("Invalid class of self."); return HCF_INVALID_PARAMS; } HcfResult ret = HCF_SUCCESS; @@ -280,7 +280,7 @@ static HcfResult GetBigIntegerSpecFromDsaPubKey(const HcfPubKey *self, const Asy ret = BigNumToBigInteger(OpensslDsaGet0PubKey(dsaPk), returnBigInteger); break; default: - LOGE("Input item is invalid"); + LOGE_ONE_STR("Input item is invalid"); ret = HCF_INVALID_PARAMS; break; } @@ -291,11 +291,11 @@ static HcfResult GetBigIntegerSpecFromDsaPriKey(const HcfPriKey *self, const Asy HcfBigInteger *returnBigInteger) { if (self == NULL || returnBigInteger == NULL) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return HCF_INVALID_PARAMS; } if (!HcfIsClassMatch((HcfObjectBase *)self, GetDsaPriKeyClass())) { - LOGE("Invalid class of self."); + LOGE_ONE_STR("Invalid class of self."); return HCF_INVALID_PARAMS; } HcfResult ret = HCF_SUCCESS; @@ -318,7 +318,7 @@ static HcfResult GetBigIntegerSpecFromDsaPriKey(const HcfPriKey *self, const Asy ret = BigNumToBigInteger(OpensslDsaGet0PrivKey(dsaSk), returnBigInteger); break; default: - LOGE("Input item is invalid"); + LOGE_ONE_STR("Input item is invalid"); ret = HCF_INVALID_PARAMS; break; } @@ -383,38 +383,38 @@ static HcfResult GenerateDsaEvpKey(int32_t keyLen, EVP_PKEY **ppkey) do { paramsCtx = OpensslEvpPkeyCtxNewId(EVP_PKEY_DSA, NULL); if (paramsCtx == NULL) { - LOGE("Create params ctx failed."); + LOGE_ONE_STR("Create params ctx failed."); ret = HCF_ERR_MALLOC; break; } if (OpensslEvpPkeyParamGenInit(paramsCtx) != HCF_OPENSSL_SUCCESS) { - LOGD("[error] Params ctx generate init failed."); + LOGD_ONE_STR("[error] Params ctx generate init failed."); ret = HCF_ERR_CRYPTO_OPERATION; break; } if (OpensslEvpPkeyCtxSetDsaParamgenBits(paramsCtx, keyLen) <= 0) { - LOGD("[error] Set length of bits to params ctx failed."); + LOGD_ONE_STR("[error] Set length of bits to params ctx failed."); ret = HCF_ERR_CRYPTO_OPERATION; break; } if (OpensslEvpPkeyParamGen(paramsCtx, ¶msPkey) != HCF_OPENSSL_SUCCESS) { - LOGD("[error] Generate params pkey failed."); + LOGD_ONE_STR("[error] Generate params pkey failed."); ret = HCF_ERR_CRYPTO_OPERATION; break; } pkeyCtx = OpensslEvpPkeyCtxNew(paramsPkey, NULL); if (pkeyCtx == NULL) { - LOGD("[error] Create pkey ctx failed."); + LOGD_ONE_STR("[error] Create pkey ctx failed."); ret = HCF_ERR_CRYPTO_OPERATION; break; } if (OpensslEvpPkeyKeyGenInit(pkeyCtx) != HCF_OPENSSL_SUCCESS) { - LOGD("[error] Key ctx generate init failed."); + LOGD_ONE_STR("[error] Key ctx generate init failed."); ret = HCF_ERR_CRYPTO_OPERATION; break; } if (OpensslEvpPkeyKeyGen(pkeyCtx, ppkey) != HCF_OPENSSL_SUCCESS) { - LOGD("[error] Generate pkey failed."); + LOGD_ONE_STR("[error] Generate pkey failed."); ret = HCF_ERR_CRYPTO_OPERATION; break; } @@ -464,7 +464,7 @@ static HcfResult CreateDsaPubKey(DSA *pk, HcfOpensslDsaPubKey **returnPubKey) { HcfOpensslDsaPubKey *dsaPubKey = (HcfOpensslDsaPubKey *)HcfMalloc(sizeof(HcfOpensslDsaPubKey), 0); if (dsaPubKey == NULL) { - LOGE("Failed to allocate DSA public key memory."); + LOGE_ONE_STR("Failed to allocate DSA public key memory."); return HCF_ERR_MALLOC; } FillOpensslDsaPubKeyFunc(dsaPubKey); @@ -478,7 +478,7 @@ static HcfResult CreateDsaPriKey(DSA *sk, HcfOpensslDsaPriKey **returnPriKey) { HcfOpensslDsaPriKey *dsaPriKey = (HcfOpensslDsaPriKey *)HcfMalloc(sizeof(HcfOpensslDsaPriKey), 0); if (dsaPriKey == NULL) { - LOGE("Failed to allocate DSA private key memory."); + LOGE_ONE_STR("Failed to allocate DSA private key memory."); return HCF_ERR_MALLOC; } FillOpensslDsaPriKeyFunc(dsaPriKey); @@ -493,7 +493,7 @@ static HcfResult CreateDsaKeyPair(const HcfOpensslDsaPubKey *pubKey, const HcfOp { HcfOpensslDsaKeyPair *keyPair = (HcfOpensslDsaKeyPair *)HcfMalloc(sizeof(HcfOpensslDsaKeyPair), 0); if (keyPair == NULL) { - LOGE("Failed to allocate keyPair memory."); + LOGE_ONE_STR("Failed to allocate keyPair memory."); return HCF_ERR_MALLOC; } keyPair->base.base.getClass = GetDsaKeyPairClass; @@ -509,13 +509,13 @@ static HcfResult GeneratePubKeyByPkey(EVP_PKEY *pkey, HcfOpensslDsaPubKey **retu { DSA *pk = OpensslEvpPkeyGet1Dsa(pkey); if (pk == NULL) { - LOGD("[error] Get das public key from pkey failed"); + LOGD_ONE_STR("[error] Get das public key from pkey failed"); HcfPrintOpensslError(); return HCF_ERR_CRYPTO_OPERATION; } HcfResult ret = CreateDsaPubKey(pk, returnPubKey); if (ret != HCF_SUCCESS) { - LOGD("[error] Create DSA public key failed"); + LOGD_ONE_STR("[error] Create DSA public key failed"); OpensslDsaFree(pk); } return ret; @@ -525,13 +525,13 @@ static HcfResult GeneratePriKeyByPkey(EVP_PKEY *pkey, HcfOpensslDsaPriKey **retu { DSA *sk = OpensslEvpPkeyGet1Dsa(pkey); if (sk == NULL) { - LOGD("[error] Get DSA private key from pkey failed"); + LOGD_ONE_STR("[error] Get DSA private key from pkey failed"); HcfPrintOpensslError(); return HCF_ERR_CRYPTO_OPERATION; } HcfResult ret = CreateDsaPriKey(sk, returnPriKey); if (ret != HCF_SUCCESS) { - LOGD("[error] Create DSA private key failed"); + LOGD_ONE_STR("[error] Create DSA private key failed"); OpensslDsaFree(sk); } return ret; @@ -543,7 +543,7 @@ static HcfResult GenerateDsaPubAndPriKey(int32_t keyLen, HcfOpensslDsaPubKey **r EVP_PKEY *pkey = NULL; HcfResult ret = GenerateDsaEvpKey(keyLen, &pkey); if (ret != HCF_SUCCESS) { - LOGD("[error] Generate DSA EVP_PKEY failed."); + LOGD_ONE_STR("[error] Generate DSA EVP_PKEY failed."); return ret; } @@ -568,17 +568,17 @@ static HcfResult GenerateDsaPubAndPriKey(int32_t keyLen, HcfOpensslDsaPubKey **r static HcfResult ConvertCommSpec2Bn(const HcfDsaCommParamsSpec *paramsSpec, BIGNUM **p, BIGNUM **q, BIGNUM **g) { if (BigIntegerToBigNum(&(paramsSpec->p), p) != HCF_SUCCESS) { - LOGD("[error] Get openssl BN p failed"); + LOGD_ONE_STR("[error] Get openssl BN p failed"); return HCF_ERR_CRYPTO_OPERATION; } if (BigIntegerToBigNum(&(paramsSpec->q), q) != HCF_SUCCESS) { - LOGD("[error] Get openssl BN q failed"); + LOGD_ONE_STR("[error] Get openssl BN q failed"); OpensslBnFree(*p); *p = NULL; return HCF_ERR_CRYPTO_OPERATION; } if (BigIntegerToBigNum(&(paramsSpec->g), g) != HCF_SUCCESS) { - LOGD("[error] Get openssl BN g failed"); + LOGD_ONE_STR("[error] Get openssl BN g failed"); OpensslBnFree(*p); *p = NULL; OpensslBnFree(*q); @@ -599,12 +599,12 @@ static HcfResult CreateOpensslDsaKey(const HcfDsaCommParamsSpec *paramsSpec, BIG DSA *dsa = OpensslDsaNew(); if (dsa == NULL) { FreeCommSpecBn(p, q, g); - LOGD("[error] Openssl DSA new failed"); + LOGD_ONE_STR("[error] Openssl DSA new failed"); HcfPrintOpensslError(); return HCF_ERR_CRYPTO_OPERATION; } if (OpensslDsaSet0Pqg(dsa, p, q, g) != HCF_OPENSSL_SUCCESS) { - LOGD("[error] Openssl DSA set pqg failed"); + LOGD_ONE_STR("[error] Openssl DSA set pqg failed"); FreeCommSpecBn(p, q, g); HcfPrintOpensslError(); OpensslDsaFree(dsa); @@ -615,7 +615,7 @@ static HcfResult CreateOpensslDsaKey(const HcfDsaCommParamsSpec *paramsSpec, BIG return HCF_SUCCESS; } if (OpensslDsaSet0Key(dsa, pk, sk) != HCF_OPENSSL_SUCCESS) { - LOGD("[error] Openssl DSA set pqg failed"); + LOGD_ONE_STR("[error] Openssl DSA set pqg failed"); HcfPrintOpensslError(); OpensslDsaFree(dsa); return HCF_ERR_CRYPTO_OPERATION; @@ -631,7 +631,7 @@ static HcfResult GenerateOpensslDsaKeyByCommSpec(const HcfDsaCommParamsSpec *par } if (OpensslDsaGenerateKey(*returnDsa) != HCF_OPENSSL_SUCCESS) { - LOGD("[error] Openssl DSA generate key failed"); + LOGD_ONE_STR("[error] Openssl DSA generate key failed"); HcfPrintOpensslError(); OpensslDsaFree(*returnDsa); *returnDsa = NULL; @@ -644,7 +644,7 @@ static HcfResult GenerateOpensslDsaKeyByPubKeySpec(const HcfDsaPubKeyParamsSpec { BIGNUM *pubKey = NULL; if (BigIntegerToBigNum(&(paramsSpec->pk), &pubKey) != HCF_SUCCESS) { - LOGD("[error] Get openssl BN pk failed"); + LOGD_ONE_STR("[error] Get openssl BN pk failed"); return HCF_ERR_CRYPTO_OPERATION; } @@ -660,11 +660,11 @@ static HcfResult GenerateOpensslDsaKeyByKeyPairSpec(const HcfDsaKeyPairParamsSpe BIGNUM *pubKey = NULL; BIGNUM *priKey = NULL; if (BigIntegerToBigNum(&(paramsSpec->pk), &pubKey) != HCF_SUCCESS) { - LOGD("[error] Get openssl BN pk failed"); + LOGD_ONE_STR("[error] Get openssl BN pk failed"); return HCF_ERR_CRYPTO_OPERATION; } if (BigIntegerToBigNum(&(paramsSpec->sk), &priKey) != HCF_SUCCESS) { - LOGD("[error] Get openssl BN sk failed"); + LOGD_ONE_STR("[error] Get openssl BN sk failed"); OpensslBnFree(pubKey); return HCF_ERR_CRYPTO_OPERATION; } @@ -689,7 +689,7 @@ static HcfResult CreateDsaKeyPairByCommSpec(const HcfDsaCommParamsSpec *paramsSp } if (OpensslDsaUpRef(dsa) != HCF_OPENSSL_SUCCESS) { - LOGE("Dup DSA failed."); + LOGE_ONE_STR("Dup DSA failed."); HcfPrintOpensslError(); HcfObjDestroy(pubKey); return HCF_ERR_CRYPTO_OPERATION; @@ -791,13 +791,13 @@ static HcfResult ConvertDsaPubKey(const HcfBlob *pubKeyBlob, HcfOpensslDsaPubKey const unsigned char *tmpData = (const unsigned char *)(pubKeyBlob->data); DSA *dsa = OpensslD2iDsaPubKey(NULL, &tmpData, pubKeyBlob->len); if (dsa == NULL) { - LOGD("[error] D2i_DSA_PUBKEY fail."); + LOGD_ONE_STR("[error] D2i_DSA_PUBKEY fail."); HcfPrintOpensslError(); return HCF_ERR_CRYPTO_OPERATION; } HcfResult ret = CreateDsaPubKey(dsa, returnPubKey); if (ret != HCF_SUCCESS) { - LOGD("[error] Create DSA public key failed"); + LOGD_ONE_STR("[error] Create DSA public key failed"); OpensslDsaFree(dsa); } return ret; @@ -808,13 +808,13 @@ static HcfResult ConvertDsaPriKey(const HcfBlob *priKeyBlob, HcfOpensslDsaPriKey const unsigned char *tmpData = (const unsigned char *)(priKeyBlob->data); DSA *dsa = OpensslD2iDsaPrivateKey(NULL, &tmpData, priKeyBlob->len); if (dsa == NULL) { - LOGD("[error] D2i_DSADSAPrivateKey fail."); + LOGD_ONE_STR("[error] D2i_DSADSAPrivateKey fail."); HcfPrintOpensslError(); return HCF_ERR_CRYPTO_OPERATION; } HcfResult ret = CreateDsaPriKey(dsa, returnPriKey); if (ret != HCF_SUCCESS) { - LOGD("[error] Create DSA private key failed"); + LOGD_ONE_STR("[error] Create DSA private key failed"); OpensslDsaFree(dsa); } return ret; @@ -825,13 +825,13 @@ static HcfResult ConvertDsaPubAndPriKey(const HcfBlob *pubKeyBlob, const HcfBlob { if (pubKeyBlob != NULL) { if (ConvertDsaPubKey(pubKeyBlob, returnPubKey) != HCF_SUCCESS) { - LOGD("[error] Convert DSA public key failed."); + LOGD_ONE_STR("[error] Convert DSA public key failed."); return HCF_ERR_CRYPTO_OPERATION; } } if (priKeyBlob != NULL) { if (ConvertDsaPriKey(priKeyBlob, returnPriKey) != HCF_SUCCESS) { - LOGD("[error] Convert DSA private key failed."); + LOGD_ONE_STR("[error] Convert DSA private key failed."); HcfObjDestroy(*returnPubKey); *returnPubKey = NULL; return HCF_ERR_CRYPTO_OPERATION; @@ -843,11 +843,11 @@ static HcfResult ConvertDsaPubAndPriKey(const HcfBlob *pubKeyBlob, const HcfBlob static HcfResult EngineGenerateDsaKeyPair(HcfAsyKeyGeneratorSpi *self, HcfKeyPair **returnKeyPair) { if (self == NULL || returnKeyPair == NULL) { - LOGE("Invalid params."); + LOGE_ONE_STR("Invalid params."); return HCF_INVALID_PARAMS; } if (!HcfIsClassMatch((HcfObjectBase *)self, GetDsaKeyGeneratorSpiClass())) { - LOGE("Class not match."); + LOGE_ONE_STR("Class not match."); return HCF_INVALID_PARAMS; } HcfAsyKeyGeneratorSpiDsaOpensslImpl *impl = (HcfAsyKeyGeneratorSpiDsaOpensslImpl *)self; @@ -856,7 +856,7 @@ static HcfResult EngineGenerateDsaKeyPair(HcfAsyKeyGeneratorSpi *self, HcfKeyPai HcfOpensslDsaPriKey *priKey = NULL; HcfResult ret = GenerateDsaPubAndPriKey(impl->bits, &pubKey, &priKey); if (ret != HCF_SUCCESS) { - LOGE("Generate DSA pk and sk by openssl failed."); + LOGE_ONE_STR("Generate DSA pk and sk by openssl failed."); return ret; } @@ -874,17 +874,17 @@ static HcfResult EngineConvertDsaKey(HcfAsyKeyGeneratorSpi *self, HcfParamsSpec { (void)params; if ((self == NULL) || (returnKeyPair == NULL)) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return HCF_INVALID_PARAMS; } if (!HcfIsClassMatch((HcfObjectBase *)self, GetDsaKeyGeneratorSpiClass())) { - LOGE("Class not match."); + LOGE_ONE_STR("Class not match."); return HCF_INVALID_PARAMS; } bool pubKeyValid = HcfIsBlobValid(pubKeyBlob); bool priKeyValid = HcfIsBlobValid(priKeyBlob); if ((!pubKeyValid) && (!priKeyValid)) { - LOGE("The private key and public key cannot both be NULL."); + LOGE_ONE_STR("The private key and public key cannot both be NULL."); return HCF_INVALID_PARAMS; } @@ -910,21 +910,21 @@ static HcfResult ConvertDsaPemPubKey(const char *pubKeyStr, HcfOpensslDsaPubKey const char *keyType = "DSA"; HcfResult ret = ConvertPubPemStrToKey(&pkey, keyType, EVP_PKEY_PUBLIC_KEY, pubKeyStr); if (ret != HCF_SUCCESS) { - LOGE("Convert dsa pem public key failed."); + LOGE_ONE_STR("Convert dsa pem public key failed."); return ret; } DSA *dsa = OpensslEvpPkeyGet1Dsa(pkey); OpensslEvpPkeyFree(pkey); if (dsa == NULL) { - LOGE("Pkey to dsa key failed."); + LOGE_ONE_STR("Pkey to dsa key failed."); HcfPrintOpensslError(); return HCF_ERR_CRYPTO_OPERATION; } ret = CreateDsaPubKey(dsa, returnPubKey); if (ret != HCF_SUCCESS) { - LOGE("Create dsa public key failed"); + LOGE_ONE_STR("Create dsa public key failed"); OpensslDsaFree(dsa); } return ret; @@ -936,21 +936,21 @@ static HcfResult ConvertDsaPemPriKey(const char *priKeyStr, HcfOpensslDsaPriKey const char *keyType = "DSA"; HcfResult ret = ConvertPriPemStrToKey(priKeyStr, &pkey, keyType); if (ret != HCF_SUCCESS) { - LOGE("Convert dsa pem private key failed."); + LOGE_ONE_STR("Convert dsa pem private key failed."); return ret; } DSA *dsa = OpensslEvpPkeyGet1Dsa(pkey); OpensslEvpPkeyFree(pkey); if (dsa == NULL) { - LOGE("Pkey to dsa key failed."); + LOGE_ONE_STR("Pkey to dsa key failed."); HcfPrintOpensslError(); return HCF_ERR_CRYPTO_OPERATION; } ret = CreateDsaPriKey(dsa, returnPriKey); if (ret != HCF_SUCCESS) { - LOGE("Create dsa private key failed"); + LOGE_ONE_STR("Create dsa private key failed"); OpensslDsaFree(dsa); } @@ -962,14 +962,14 @@ static HcfResult ConvertDsaPemPubAndPriKey(const char *pubKeyStr, const char *pr { if (pubKeyStr != NULL && strlen(pubKeyStr) != 0) { if (ConvertDsaPemPubKey(pubKeyStr, returnPubKey) != HCF_SUCCESS) { - LOGE("Convert dsa pem public key failed."); + LOGE_ONE_STR("Convert dsa pem public key failed."); return HCF_ERR_CRYPTO_OPERATION; } } if (priKeyStr != NULL && strlen(priKeyStr) != 0) { if (ConvertDsaPemPriKey(priKeyStr, returnPriKey) != HCF_SUCCESS) { - LOGE("Convert dsa pem private key failed."); + LOGE_ONE_STR("Convert dsa pem private key failed."); HcfObjDestroy(*returnPubKey); *returnPubKey = NULL; return HCF_ERR_CRYPTO_OPERATION; @@ -983,11 +983,11 @@ static HcfResult EngineConvertDsaPemKey(HcfAsyKeyGeneratorSpi *self, HcfParamsSp { (void)params; if ((self == NULL) || (returnKeyPair == NULL) || ((pubKeyStr == NULL) && (priKeyStr == NULL))) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return HCF_INVALID_PARAMS; } if (!HcfIsClassMatch((HcfObjectBase *)self, GetDsaKeyGeneratorSpiClass())) { - LOGE("Class not match."); + LOGE_ONE_STR("Class not match."); return HCF_INVALID_PARAMS; } @@ -1012,7 +1012,7 @@ static HcfResult EngineGenerateDsaKeyPairBySpec(const HcfAsyKeyGeneratorSpi *sel const HcfAsyKeyParamsSpec *paramsSpec, HcfKeyPair **returnKeyPair) { if ((self == NULL) || (paramsSpec == NULL) || (paramsSpec->algName == NULL) || (returnKeyPair == NULL)) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return HCF_INVALID_PARAMS; } @@ -1022,12 +1022,12 @@ static HcfResult EngineGenerateDsaKeyPairBySpec(const HcfAsyKeyGeneratorSpi *sel if ((strcmp(paramsSpec->algName, ALGORITHM_NAME_DSA) != 0) || ((paramsSpec->specType != HCF_COMMON_PARAMS_SPEC) && (paramsSpec->specType != HCF_KEY_PAIR_SPEC))) { - LOGE("Invalid params spec."); + LOGE_ONE_STR("Invalid params spec."); return HCF_INVALID_PARAMS; } HcfResult ret = CreateDsaKeyPairBySpec(paramsSpec, returnKeyPair); if (ret != HCF_SUCCESS) { - LOGE("Create DSA key pair by spec failed."); + LOGE_ONE_STR("Create DSA key pair by spec failed."); } return ret; } @@ -1036,7 +1036,7 @@ static HcfResult EngineGenerateDsaPubKeyBySpec(const HcfAsyKeyGeneratorSpi *self const HcfAsyKeyParamsSpec *paramsSpec, HcfPubKey **returnPubKey) { if ((self == NULL) || (paramsSpec == NULL) || (paramsSpec->algName == NULL) || (returnPubKey == NULL)) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return HCF_INVALID_PARAMS; } @@ -1046,13 +1046,13 @@ static HcfResult EngineGenerateDsaPubKeyBySpec(const HcfAsyKeyGeneratorSpi *self if ((strcmp(paramsSpec->algName, ALGORITHM_NAME_DSA) != 0) || ((paramsSpec->specType != HCF_PUBLIC_KEY_SPEC) && (paramsSpec->specType != HCF_KEY_PAIR_SPEC))) { - LOGE("Invalid params spec."); + LOGE_ONE_STR("Invalid params spec."); return HCF_INVALID_PARAMS; } HcfResult ret = CreateDsaPubKeyByPubKeySpec((const HcfDsaPubKeyParamsSpec *)paramsSpec, returnPubKey); if (ret != HCF_SUCCESS) { - LOGE("Create DSA public key by spec failed."); + LOGE_ONE_STR("Create DSA public key by spec failed."); } return ret; } @@ -1061,21 +1061,21 @@ static HcfResult EngineGenerateDsaPriKeyBySpec(const HcfAsyKeyGeneratorSpi *self const HcfAsyKeyParamsSpec *paramsSpec, HcfPriKey **returnPriKey) { if ((self == NULL) || (paramsSpec == NULL) || (paramsSpec->algName == NULL) || (returnPriKey == NULL)) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return HCF_INVALID_PARAMS; } if (!HcfIsClassMatch((HcfObjectBase *)self, GetDsaKeyGeneratorSpiClass())) { return HCF_INVALID_PARAMS; } if ((strcmp(paramsSpec->algName, ALGORITHM_NAME_DSA) != 0) || (paramsSpec->specType != HCF_KEY_PAIR_SPEC)) { - LOGE("Invalid params spec."); + LOGE_ONE_STR("Invalid params spec."); return HCF_INVALID_PARAMS; } HcfOpensslDsaPriKey *dsaSk = NULL; HcfResult ret = CreateDsaPriKeyByKeyPairSpec((const HcfDsaKeyPairParamsSpec *)paramsSpec, &dsaSk); if (ret != HCF_SUCCESS) { - LOGE("Create DSA private key by spec failed."); + LOGE_ONE_STR("Create DSA private key by spec failed."); } else { *returnPriKey = (HcfPriKey *)dsaSk; } @@ -1085,13 +1085,13 @@ static HcfResult EngineGenerateDsaPriKeyBySpec(const HcfAsyKeyGeneratorSpi *self HcfResult HcfAsyKeyGeneratorSpiDsaCreate(HcfAsyKeyGenParams *params, HcfAsyKeyGeneratorSpi **returnObj) { if (params == NULL || returnObj == NULL) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return HCF_INVALID_PARAMS; } HcfAsyKeyGeneratorSpiDsaOpensslImpl *impl = (HcfAsyKeyGeneratorSpiDsaOpensslImpl *)HcfMalloc( sizeof(HcfAsyKeyGeneratorSpiDsaOpensslImpl), 0); if (impl == NULL) { - LOGE("Failed to allocate generator impl memroy."); + LOGE_ONE_STR("Failed to allocate generator impl memroy."); return HCF_ERR_MALLOC; } impl->bits = params->bits; diff --git a/plugin/openssl_plugin/key/asy_key_generator/src/ecc_asy_key_generator_openssl.c b/plugin/openssl_plugin/key/asy_key_generator/src/ecc_asy_key_generator_openssl.c index b2a29ab75cdb3c94c1fdb18a7cceb47b1ffd8463..5565e0a3ac0a310a5089ebe7d2e8954f06b8f9cb 100644 --- a/plugin/openssl_plugin/key/asy_key_generator/src/ecc_asy_key_generator_openssl.c +++ b/plugin/openssl_plugin/key/asy_key_generator/src/ecc_asy_key_generator_openssl.c @@ -63,7 +63,7 @@ static HcfResult CheckEc224CurveId(BIGNUM *p, BIGNUM *b, BIGNUM *x, BIGNUM *y) BIGNUM *xStd = OpensslBin2Bn(g_ecc224CorrectBigGX, NID_secp224r1_len, NULL); BIGNUM *yStd = OpensslBin2Bn(g_ecc224CorrectBigGY, NID_secp224r1_len, NULL); if ((pStd == NULL) || (bStd == NULL) || (xStd == NULL) || (yStd == NULL)) { - LOGD("[error] EC 224 Curve convert to BN fail"); + LOGD_ONE_STR("[error] EC 224 Curve convert to BN fail"); FreeCurveBigNum(pStd, bStd, xStd, yStd); return HCF_ERR_CRYPTO_OPERATION; } @@ -72,7 +72,7 @@ static HcfResult CheckEc224CurveId(BIGNUM *p, BIGNUM *b, BIGNUM *x, BIGNUM *y) FreeCurveBigNum(pStd, bStd, xStd, yStd); return HCF_SUCCESS; } - LOGD("[error] EC 224 compare fail"); + LOGD_ONE_STR("[error] EC 224 compare fail"); FreeCurveBigNum(pStd, bStd, xStd, yStd); return HCF_INVALID_PARAMS; } @@ -84,7 +84,7 @@ static HcfResult CheckEc256CurveId(BIGNUM *p, BIGNUM *b, BIGNUM *x, BIGNUM *y) BIGNUM *xStd = OpensslBin2Bn(g_ecc256CorrectBigGX, NID_X9_62_prime256v1_len, NULL); BIGNUM *yStd = OpensslBin2Bn(g_ecc256CorrectBigGY, NID_X9_62_prime256v1_len, NULL); if ((pStd == NULL) || (bStd == NULL) || (xStd == NULL) || (yStd == NULL)) { - LOGD("[error] EC 256 Curve convert to BN fail"); + LOGD_ONE_STR("[error] EC 256 Curve convert to BN fail"); FreeCurveBigNum(pStd, bStd, xStd, yStd); return HCF_ERR_CRYPTO_OPERATION; } @@ -93,7 +93,7 @@ static HcfResult CheckEc256CurveId(BIGNUM *p, BIGNUM *b, BIGNUM *x, BIGNUM *y) FreeCurveBigNum(pStd, bStd, xStd, yStd); return HCF_SUCCESS; } - LOGD("[error] EC 256 compare fail"); + LOGD_ONE_STR("[error] EC 256 compare fail"); FreeCurveBigNum(pStd, bStd, xStd, yStd); return HCF_INVALID_PARAMS; } @@ -105,7 +105,7 @@ static HcfResult CheckEc384CurveId(BIGNUM *p, BIGNUM *b, BIGNUM *x, BIGNUM *y) BIGNUM *xStd = OpensslBin2Bn(g_ecc384CorrectBigGX, NID_secp384r1_len, NULL); BIGNUM *yStd = OpensslBin2Bn(g_ecc384CorrectBigGY, NID_secp384r1_len, NULL); if ((pStd == NULL) || (bStd == NULL) || (xStd == NULL) || (yStd == NULL)) { - LOGD("[error] EC 384 Curve convert to BN fail"); + LOGD_ONE_STR("[error] EC 384 Curve convert to BN fail"); FreeCurveBigNum(pStd, bStd, xStd, yStd); return HCF_ERR_CRYPTO_OPERATION; } @@ -114,7 +114,7 @@ static HcfResult CheckEc384CurveId(BIGNUM *p, BIGNUM *b, BIGNUM *x, BIGNUM *y) FreeCurveBigNum(pStd, bStd, xStd, yStd); return HCF_SUCCESS; } - LOGD("[error] EC 384 compare fail"); + LOGD_ONE_STR("[error] EC 384 compare fail"); FreeCurveBigNum(pStd, bStd, xStd, yStd); return HCF_INVALID_PARAMS; } @@ -126,7 +126,7 @@ static HcfResult CheckEc521CurveId(BIGNUM *p, BIGNUM *b, BIGNUM *x, BIGNUM *y) BIGNUM *xStd = OpensslBin2Bn(g_ecc521CorrectBigGX, NID_secp521r1_len, NULL); BIGNUM *yStd = OpensslBin2Bn(g_ecc521CorrectBigGY, NID_secp521r1_len, NULL); if ((pStd == NULL) || (bStd == NULL) || (xStd == NULL) || (yStd == NULL)) { - LOGD("[error] EC 521 Curve convert to BN fail"); + LOGD_ONE_STR("[error] EC 521 Curve convert to BN fail"); FreeCurveBigNum(pStd, bStd, xStd, yStd); return HCF_ERR_CRYPTO_OPERATION; } @@ -135,7 +135,7 @@ static HcfResult CheckEc521CurveId(BIGNUM *p, BIGNUM *b, BIGNUM *x, BIGNUM *y) FreeCurveBigNum(pStd, bStd, xStd, yStd); return HCF_SUCCESS; } - LOGD("[error] EC 521 compare fail"); + LOGD_ONE_STR("[error] EC 521 compare fail"); FreeCurveBigNum(pStd, bStd, xStd, yStd); return HCF_INVALID_PARAMS; } @@ -147,7 +147,7 @@ static HcfResult CheckBP160r1CurveId(BIGNUM *p, BIGNUM *b, BIGNUM *x, BIGNUM *y) BIGNUM *xStd = OpensslBin2Bn(g_bp160r1CorrectBigGX, NID_brainpoolP160r1_len, NULL); BIGNUM *yStd = OpensslBin2Bn(g_bp160r1CorrectBigGY, NID_brainpoolP160r1_len, NULL); if ((pStd == NULL) || (bStd == NULL) || (xStd == NULL) || (yStd == NULL)) { - LOGD("[error] BP 160r1 Curve convert to BN fail"); + LOGD_ONE_STR("[error] BP 160r1 Curve convert to BN fail"); FreeCurveBigNum(pStd, bStd, xStd, yStd); return HCF_ERR_CRYPTO_OPERATION; } @@ -156,7 +156,7 @@ static HcfResult CheckBP160r1CurveId(BIGNUM *p, BIGNUM *b, BIGNUM *x, BIGNUM *y) FreeCurveBigNum(pStd, bStd, xStd, yStd); return HCF_SUCCESS; } - LOGD("[error] BP 160r1 compare fail"); + LOGD_ONE_STR("[error] BP 160r1 compare fail"); FreeCurveBigNum(pStd, bStd, xStd, yStd); return HCF_INVALID_PARAMS; } @@ -168,7 +168,7 @@ static HcfResult CheckBP160t1CurveId(BIGNUM *p, BIGNUM *b, BIGNUM *x, BIGNUM *y) BIGNUM *xStd = OpensslBin2Bn(g_bp160t1CorrectBigGX, NID_brainpoolP160t1_len, NULL); BIGNUM *yStd = OpensslBin2Bn(g_bp160t1CorrectBigGY, NID_brainpoolP160t1_len, NULL); if ((pStd == NULL) || (bStd == NULL) || (xStd == NULL) || (yStd == NULL)) { - LOGD("[error] BP 160t1 Curve convert to BN fail"); + LOGD_ONE_STR("[error] BP 160t1 Curve convert to BN fail"); FreeCurveBigNum(pStd, bStd, xStd, yStd); return HCF_ERR_CRYPTO_OPERATION; } @@ -177,7 +177,7 @@ static HcfResult CheckBP160t1CurveId(BIGNUM *p, BIGNUM *b, BIGNUM *x, BIGNUM *y) FreeCurveBigNum(pStd, bStd, xStd, yStd); return HCF_SUCCESS; } - LOGD("[error] BP 160t1 compare fail"); + LOGD_ONE_STR("[error] BP 160t1 compare fail"); FreeCurveBigNum(pStd, bStd, xStd, yStd); return HCF_INVALID_PARAMS; } @@ -189,7 +189,7 @@ static HcfResult CheckBP192r1CurveId(BIGNUM *p, BIGNUM *b, BIGNUM *x, BIGNUM *y) BIGNUM *xStd = OpensslBin2Bn(g_bp192r1CorrectBigGX, NID_brainpoolP192r1_len, NULL); BIGNUM *yStd = OpensslBin2Bn(g_bp192r1CorrectBigGY, NID_brainpoolP192r1_len, NULL); if ((pStd == NULL) || (bStd == NULL) || (xStd == NULL) || (yStd == NULL)) { - LOGD("[error] BP 192r1 Curve convert to BN fail"); + LOGD_ONE_STR("[error] BP 192r1 Curve convert to BN fail"); FreeCurveBigNum(pStd, bStd, xStd, yStd); return HCF_ERR_CRYPTO_OPERATION; } @@ -198,7 +198,7 @@ static HcfResult CheckBP192r1CurveId(BIGNUM *p, BIGNUM *b, BIGNUM *x, BIGNUM *y) FreeCurveBigNum(pStd, bStd, xStd, yStd); return HCF_SUCCESS; } - LOGD("[error] BP 192r1 compare fail"); + LOGD_ONE_STR("[error] BP 192r1 compare fail"); FreeCurveBigNum(pStd, bStd, xStd, yStd); return HCF_INVALID_PARAMS; } @@ -210,7 +210,7 @@ static HcfResult CheckBP192t1CurveId(BIGNUM *p, BIGNUM *b, BIGNUM *x, BIGNUM *y) BIGNUM *xStd = OpensslBin2Bn(g_bp192t1CorrectBigGX, NID_brainpoolP192t1_len, NULL); BIGNUM *yStd = OpensslBin2Bn(g_bp192t1CorrectBigGY, NID_brainpoolP192t1_len, NULL); if ((pStd == NULL) || (bStd == NULL) || (xStd == NULL) || (yStd == NULL)) { - LOGD("[error] BP 192t1 Curve convert to BN fail"); + LOGD_ONE_STR("[error] BP 192t1 Curve convert to BN fail"); FreeCurveBigNum(pStd, bStd, xStd, yStd); return HCF_ERR_CRYPTO_OPERATION; } @@ -219,7 +219,7 @@ static HcfResult CheckBP192t1CurveId(BIGNUM *p, BIGNUM *b, BIGNUM *x, BIGNUM *y) FreeCurveBigNum(pStd, bStd, xStd, yStd); return HCF_SUCCESS; } - LOGD("[error] BP 192t1 compare fail"); + LOGD_ONE_STR("[error] BP 192t1 compare fail"); FreeCurveBigNum(pStd, bStd, xStd, yStd); return HCF_INVALID_PARAMS; } @@ -231,7 +231,7 @@ static HcfResult CheckBP224r1CurveId(BIGNUM *p, BIGNUM *b, BIGNUM *x, BIGNUM *y) BIGNUM *xStd = OpensslBin2Bn(g_bp224r1CorrectBigGX, NID_brainpoolP224r1_len, NULL); BIGNUM *yStd = OpensslBin2Bn(g_bp224r1CorrectBigGY, NID_brainpoolP224r1_len, NULL); if ((pStd == NULL) || (bStd == NULL) || (xStd == NULL) || (yStd == NULL)) { - LOGD("[error] BP 224r1 Curve convert to BN fail"); + LOGD_ONE_STR("[error] BP 224r1 Curve convert to BN fail"); FreeCurveBigNum(pStd, bStd, xStd, yStd); return HCF_ERR_CRYPTO_OPERATION; } @@ -240,7 +240,7 @@ static HcfResult CheckBP224r1CurveId(BIGNUM *p, BIGNUM *b, BIGNUM *x, BIGNUM *y) FreeCurveBigNum(pStd, bStd, xStd, yStd); return HCF_SUCCESS; } - LOGD("[error] BP 224r1 compare fail"); + LOGD_ONE_STR("[error] BP 224r1 compare fail"); FreeCurveBigNum(pStd, bStd, xStd, yStd); return HCF_INVALID_PARAMS; } @@ -252,7 +252,7 @@ static HcfResult CheckBP224t1CurveId(BIGNUM *p, BIGNUM *b, BIGNUM *x, BIGNUM *y) BIGNUM *xStd = OpensslBin2Bn(g_bp224t1CorrectBigGX, NID_brainpoolP224t1_len, NULL); BIGNUM *yStd = OpensslBin2Bn(g_bp224t1CorrectBigGY, NID_brainpoolP224t1_len, NULL); if ((pStd == NULL) || (bStd == NULL) || (xStd == NULL) || (yStd == NULL)) { - LOGD("[error] BP 224t1 Curve convert to BN fail"); + LOGD_ONE_STR("[error] BP 224t1 Curve convert to BN fail"); FreeCurveBigNum(pStd, bStd, xStd, yStd); return HCF_ERR_CRYPTO_OPERATION; } @@ -261,7 +261,7 @@ static HcfResult CheckBP224t1CurveId(BIGNUM *p, BIGNUM *b, BIGNUM *x, BIGNUM *y) FreeCurveBigNum(pStd, bStd, xStd, yStd); return HCF_SUCCESS; } - LOGD("[error] BP 224t1 compare fail"); + LOGD_ONE_STR("[error] BP 224t1 compare fail"); FreeCurveBigNum(pStd, bStd, xStd, yStd); return HCF_INVALID_PARAMS; } @@ -273,7 +273,7 @@ static HcfResult CheckBP256r1CurveId(BIGNUM *p, BIGNUM *b, BIGNUM *x, BIGNUM *y) BIGNUM *xStd = OpensslBin2Bn(g_bp256r1CorrectBigGX, NID_brainpoolP256r1_len, NULL); BIGNUM *yStd = OpensslBin2Bn(g_bp256r1CorrectBigGY, NID_brainpoolP256r1_len, NULL); if ((pStd == NULL) || (bStd == NULL) || (xStd == NULL) || (yStd == NULL)) { - LOGD("[error] BP 256r1 Curve convert to BN fail"); + LOGD_ONE_STR("[error] BP 256r1 Curve convert to BN fail"); FreeCurveBigNum(pStd, bStd, xStd, yStd); return HCF_ERR_CRYPTO_OPERATION; } @@ -282,7 +282,7 @@ static HcfResult CheckBP256r1CurveId(BIGNUM *p, BIGNUM *b, BIGNUM *x, BIGNUM *y) FreeCurveBigNum(pStd, bStd, xStd, yStd); return HCF_SUCCESS; } - LOGD("[error] BP 256r1 compare fail"); + LOGD_ONE_STR("[error] BP 256r1 compare fail"); FreeCurveBigNum(pStd, bStd, xStd, yStd); return HCF_INVALID_PARAMS; } @@ -294,7 +294,7 @@ static HcfResult CheckBP256t1CurveId(BIGNUM *p, BIGNUM *b, BIGNUM *x, BIGNUM *y) BIGNUM *xStd = OpensslBin2Bn(g_bp256t1CorrectBigGX, NID_brainpoolP256t1_len, NULL); BIGNUM *yStd = OpensslBin2Bn(g_bp256t1CorrectBigGY, NID_brainpoolP256t1_len, NULL); if ((pStd == NULL) || (bStd == NULL) || (xStd == NULL) || (yStd == NULL)) { - LOGD("[error] BP 256t1 Curve convert to BN fail"); + LOGD_ONE_STR("[error] BP 256t1 Curve convert to BN fail"); FreeCurveBigNum(pStd, bStd, xStd, yStd); return HCF_ERR_CRYPTO_OPERATION; } @@ -314,7 +314,7 @@ static HcfResult CheckSecp256k1CurveId(BIGNUM *p, BIGNUM *b, BIGNUM *x, BIGNUM * BIGNUM *xStd = OpensslBin2Bn(g_secp256k1CorrectBigGX, NID_secp256k1_len, NULL); BIGNUM *yStd = OpensslBin2Bn(g_secp256k1CorrectBigGY, NID_secp256k1_len, NULL); if ((pStd == NULL) || (bStd == NULL) || (xStd == NULL) || (yStd == NULL)) { - LOGD("[error] Secp256k1 Curve convert to BN fail"); + LOGD_ONE_STR("[error] Secp256k1 Curve convert to BN fail"); FreeCurveBigNum(pStd, bStd, xStd, yStd); return HCF_ERR_CRYPTO_OPERATION; } @@ -334,7 +334,7 @@ static HcfResult CheckBP320r1CurveId(BIGNUM *p, BIGNUM *b, BIGNUM *x, BIGNUM *y) BIGNUM *xStd = OpensslBin2Bn(g_bp320r1CorrectBigGX, NID_brainpoolP320r1_len, NULL); BIGNUM *yStd = OpensslBin2Bn(g_bp320r1CorrectBigGY, NID_brainpoolP320r1_len, NULL); if ((pStd == NULL) || (bStd == NULL) || (xStd == NULL) || (yStd == NULL)) { - LOGD("[error] BP 320r1 Curve convert to BN fail"); + LOGD_ONE_STR("[error] BP 320r1 Curve convert to BN fail"); FreeCurveBigNum(pStd, bStd, xStd, yStd); return HCF_ERR_CRYPTO_OPERATION; } @@ -354,7 +354,7 @@ static HcfResult CheckBP320t1CurveId(BIGNUM *p, BIGNUM *b, BIGNUM *x, BIGNUM *y) BIGNUM *xStd = OpensslBin2Bn(g_bp320t1CorrectBigGX, NID_brainpoolP320t1_len, NULL); BIGNUM *yStd = OpensslBin2Bn(g_bp320t1CorrectBigGY, NID_brainpoolP320t1_len, NULL); if ((pStd == NULL) || (bStd == NULL) || (xStd == NULL) || (yStd == NULL)) { - LOGD("[error] BP 320t1 Curve convert to BN fail"); + LOGD_ONE_STR("[error] BP 320t1 Curve convert to BN fail"); FreeCurveBigNum(pStd, bStd, xStd, yStd); return HCF_ERR_CRYPTO_OPERATION; } @@ -374,7 +374,7 @@ static HcfResult CheckBP384r1CurveId(BIGNUM *p, BIGNUM *b, BIGNUM *x, BIGNUM *y) BIGNUM *xStd = OpensslBin2Bn(g_bp384r1CorrectBigGX, NID_brainpoolP384r1_len, NULL); BIGNUM *yStd = OpensslBin2Bn(g_bp384r1CorrectBigGY, NID_brainpoolP384r1_len, NULL); if ((pStd == NULL) || (bStd == NULL) || (xStd == NULL) || (yStd == NULL)) { - LOGD("[error] BP 384r1 Curve convert to BN fail"); + LOGD_ONE_STR("[error] BP 384r1 Curve convert to BN fail"); FreeCurveBigNum(pStd, bStd, xStd, yStd); return HCF_ERR_CRYPTO_OPERATION; } @@ -394,7 +394,7 @@ static HcfResult CheckBP384t1CurveId(BIGNUM *p, BIGNUM *b, BIGNUM *x, BIGNUM *y) BIGNUM *xStd = OpensslBin2Bn(g_bp384t1CorrectBigGX, NID_brainpoolP384t1_len, NULL); BIGNUM *yStd = OpensslBin2Bn(g_bp384t1CorrectBigGY, NID_brainpoolP384t1_len, NULL); if ((pStd == NULL) || (bStd == NULL) || (xStd == NULL) || (yStd == NULL)) { - LOGD("[error] BP 384t1 Curve convert to BN fail"); + LOGD_ONE_STR("[error] BP 384t1 Curve convert to BN fail"); FreeCurveBigNum(pStd, bStd, xStd, yStd); return HCF_ERR_CRYPTO_OPERATION; } @@ -414,7 +414,7 @@ static HcfResult CheckBP512r1CurveId(BIGNUM *p, BIGNUM *b, BIGNUM *x, BIGNUM *y) BIGNUM *xStd = OpensslBin2Bn(g_bp512r1CorrectBigGX, NID_brainpoolP512r1_len, NULL); BIGNUM *yStd = OpensslBin2Bn(g_bp512r1CorrectBigGY, NID_brainpoolP512r1_len, NULL); if ((pStd == NULL) || (bStd == NULL) || (xStd == NULL) || (yStd == NULL)) { - LOGD("[error] BP 512r1 Curve convert to BN fail"); + LOGD_ONE_STR("[error] BP 512r1 Curve convert to BN fail"); FreeCurveBigNum(pStd, bStd, xStd, yStd); return HCF_ERR_CRYPTO_OPERATION; } @@ -434,7 +434,7 @@ static HcfResult CheckBP512t1CurveId(BIGNUM *p, BIGNUM *b, BIGNUM *x, BIGNUM *y) BIGNUM *xStd = OpensslBin2Bn(g_bp512t1CorrectBigGX, NID_brainpoolP512t1_len, NULL); BIGNUM *yStd = OpensslBin2Bn(g_bp512t1CorrectBigGY, NID_brainpoolP512t1_len, NULL); if ((pStd == NULL) || (bStd == NULL) || (xStd == NULL) || (yStd == NULL)) { - LOGD("[error] BP 512t1 Curve convert to BN fail"); + LOGD_ONE_STR("[error] BP 512t1 Curve convert to BN fail"); FreeCurveBigNum(pStd, bStd, xStd, yStd); return HCF_ERR_CRYPTO_OPERATION; } @@ -595,7 +595,7 @@ static HcfResult CheckParamsSpecToGetCurveId(const HcfEccCommParamsSpec *ecParam BigIntegerToBigNum(&(ecParams->b), &(bigIntegerParams.b)) != HCF_SUCCESS || BigIntegerToBigNum(&(ecParams->g.x), &(bigIntegerParams.x)) != HCF_SUCCESS || BigIntegerToBigNum(&(ecParams->g.y), &(bigIntegerParams.y)) != HCF_SUCCESS) { - LOGD("[error] BigIntegerToBigNum failed."); + LOGD_ONE_STR("[error] BigIntegerToBigNum failed."); FreeCurveBigNum(bigIntegerParams.p, bigIntegerParams.b, bigIntegerParams.x, bigIntegerParams.y); return HCF_ERR_CRYPTO_OPERATION; } @@ -638,7 +638,7 @@ static HcfResult CheckParamsSpecToGetCurveId(const HcfEccCommParamsSpec *ecParam static HcfResult GenerateEcKeyWithParamsSpec(const HcfEccCommParamsSpec *ecParams, EC_KEY **returnKey) { if (ecParams == NULL || returnKey == NULL) { - LOGE("Invalid input parameters."); + LOGE_ONE_STR("Invalid input parameters."); return HCF_INVALID_PARAMS; } EC_KEY *ecKey = NULL; @@ -646,32 +646,32 @@ static HcfResult GenerateEcKeyWithParamsSpec(const HcfEccCommParamsSpec *ecParam HcfResult ret = CheckParamsSpecToGetCurveId(ecParams, &curveId); if (ret == HCF_SUCCESS && curveId != 0) { ecKey = OpensslEcKeyNewByCurveName(curveId); - LOGD("generate EC_KEY by curve name"); + LOGD_ONE_STR("generate EC_KEY by curve name"); if (ecKey == NULL) { - LOGD("[error] new ec key failed."); + LOGD_ONE_STR("[error] new ec key failed."); return HCF_ERR_CRYPTO_OPERATION; } } else { EC_GROUP *group = NULL; ret = GenerateEcGroupWithParamsSpec(ecParams, &group); if (ret != HCF_SUCCESS) { - LOGD("[error] GenerateEcGroupWithParamsSpec failed."); + LOGD_ONE_STR("[error] GenerateEcGroupWithParamsSpec failed."); return ret; } ecKey = OpensslEcKeyNew(); if (ecKey == NULL) { - LOGD("[error] OpensslEcKeyNew failed."); + LOGD_ONE_STR("[error] OpensslEcKeyNew failed."); OpensslEcGroupFree(group); return HCF_ERR_CRYPTO_OPERATION; } if (OpensslEcKeySetGroup(ecKey, group) != HCF_OPENSSL_SUCCESS) { - LOGD("[error] OpensslEcKeySetGroup failed."); + LOGD_ONE_STR("[error] OpensslEcKeySetGroup failed."); OpensslEcGroupFree(group); OpensslEcKeyFree(ecKey); return HCF_ERR_CRYPTO_OPERATION; } OpensslEcGroupFree(group); - LOGD("generate EC_KEY by group spec parmas"); + LOGD_ONE_STR("generate EC_KEY by group spec parmas"); } // all exceptions have been returned above. *returnKey = ecKey; @@ -681,23 +681,23 @@ static HcfResult GenerateEcKeyWithParamsSpec(const HcfEccCommParamsSpec *ecParam static HcfResult NewEcKeyPairWithCommSpec(const HcfEccCommParamsSpec *ecParams, EC_KEY **returnEckey) { if (ecParams == NULL || returnEckey == NULL) { - LOGE("Invalid input parameters."); + LOGE_ONE_STR("Invalid input parameters."); return HCF_INVALID_PARAMS; } EC_KEY *ecKey = NULL; HcfResult ret = GenerateEcKeyWithParamsSpec(ecParams, &ecKey); if (ret != HCF_SUCCESS) { - LOGE("generate EC key fails"); + LOGE_ONE_STR("generate EC key fails"); return ret; } if (OpensslEcKeyGenerateKey(ecKey) != HCF_OPENSSL_SUCCESS) { - LOGD("[error] OpensslEcKeyGenerateKey failed."); + LOGD_ONE_STR("[error] OpensslEcKeyGenerateKey failed."); OpensslEcKeyFree(ecKey); return HCF_ERR_CRYPTO_OPERATION; } if (OpensslEcKeyCheckKey(ecKey) <= 0) { - LOGD("[error] Check key fail."); + LOGD_ONE_STR("[error] Check key fail."); OpensslEcKeyFree(ecKey); return HCF_ERR_CRYPTO_OPERATION; } @@ -708,24 +708,24 @@ static HcfResult NewEcKeyPairWithCommSpec(const HcfEccCommParamsSpec *ecParams, static HcfResult NewEcPubKeyWithPubSpec(const HcfEccPubKeyParamsSpec *ecParams, EC_KEY **returnEcKey) { if (ecParams == NULL || returnEcKey == NULL) { - LOGE("Invalid input parameters."); + LOGE_ONE_STR("Invalid input parameters."); return HCF_INVALID_PARAMS; } EC_KEY *ecKey = NULL; HcfResult ret = GenerateEcKeyWithParamsSpec((HcfEccCommParamsSpec *)ecParams, &ecKey); if (ret != HCF_SUCCESS) { - LOGE("generate EC key fails"); + LOGE_ONE_STR("generate EC key fails"); return ret; } ret = SetEcKey(&(ecParams->pk), NULL, ecKey); if (ret != HCF_SUCCESS) { - LOGD("[error] Set pub ecKey failed."); + LOGD_ONE_STR("[error] Set pub ecKey failed."); OpensslEcKeyFree(ecKey); return HCF_ERR_CRYPTO_OPERATION; } if (OpensslEcKeyCheckKey(ecKey) <= 0) { - LOGD("[error] Check key fail."); + LOGD_ONE_STR("[error] Check key fail."); OpensslEcKeyFree(ecKey); return HCF_ERR_CRYPTO_OPERATION; } @@ -736,24 +736,24 @@ static HcfResult NewEcPubKeyWithPubSpec(const HcfEccPubKeyParamsSpec *ecParams, static HcfResult NewEcPriKeyWithPriSpec(const HcfEccPriKeyParamsSpec *ecParams, EC_KEY **returnEcKey) { if (ecParams == NULL || returnEcKey == NULL) { - LOGE("Invalid input parameters."); + LOGE_ONE_STR("Invalid input parameters."); return HCF_INVALID_PARAMS; } EC_KEY *ecKey = NULL; HcfResult ret = GenerateEcKeyWithParamsSpec((HcfEccCommParamsSpec *)ecParams, &ecKey); if (ret != HCF_SUCCESS) { - LOGE("generate EC key fails"); + LOGE_ONE_STR("generate EC key fails"); return ret; } ret = SetEcKey(NULL, &(ecParams->sk), ecKey); if (ret != HCF_SUCCESS) { - LOGD("[error] Set pri ecKey failed."); + LOGD_ONE_STR("[error] Set pri ecKey failed."); OpensslEcKeyFree(ecKey); return HCF_ERR_CRYPTO_OPERATION; } if (OpensslEcKeyCheckKey(ecKey) <= 0) { - LOGD("[error] Check key fail."); + LOGD_ONE_STR("[error] Check key fail."); OpensslEcKeyFree(ecKey); return HCF_ERR_CRYPTO_OPERATION; } @@ -765,13 +765,13 @@ static HcfResult NewEcKeyWithKeyPairSpec(const HcfEccKeyPairParamsSpec *ecParams bool needPrivate) { if (ecParams == NULL || returnEcKey == NULL) { - LOGE("Invalid input parameters."); + LOGE_ONE_STR("Invalid input parameters."); return HCF_INVALID_PARAMS; } EC_KEY *ecKey = NULL; HcfResult ret = GenerateEcKeyWithParamsSpec((HcfEccCommParamsSpec *)ecParams, &ecKey); if (ret != HCF_SUCCESS) { - LOGE("generate EC key fails"); + LOGE_ONE_STR("generate EC key fails"); return ret; } if (needPrivate) { @@ -780,13 +780,13 @@ static HcfResult NewEcKeyWithKeyPairSpec(const HcfEccKeyPairParamsSpec *ecParams ret = SetEcKey(&(ecParams->pk), NULL, ecKey); } if (ret != HCF_SUCCESS) { - LOGD("[error] SetEcKey failed."); + LOGD_ONE_STR("[error] SetEcKey failed."); OpensslEcKeyFree(ecKey); return HCF_ERR_CRYPTO_OPERATION; } if (OpensslEcKeyCheckKey(ecKey) <= 0) { - LOGD("[error] Check key fail."); + LOGD_ONE_STR("[error] Check key fail."); OpensslEcKeyFree(ecKey); return HCF_ERR_CRYPTO_OPERATION; } @@ -805,7 +805,7 @@ static HcfResult GenKeyPairEcKeyBySpec(const HcfAsyKeyParamsSpec *params, EC_KEY ret = NewEcKeyWithKeyPairSpec((HcfEccKeyPairParamsSpec *)params, ecKey, true); break; default: - LOGE("Invaild input spec to gen key pair."); + LOGE_ONE_STR("Invaild input spec to gen key pair."); break; } return ret; @@ -822,7 +822,7 @@ static HcfResult GenPubKeyEcKeyBySpec(const HcfAsyKeyParamsSpec *params, EC_KEY ret = NewEcKeyWithKeyPairSpec((HcfEccKeyPairParamsSpec *)params, ecKey, false); break; default: - LOGE("Invaild input spec to gen pub key"); + LOGE_ONE_STR("Invaild input spec to gen pub key"); break; } return ret; @@ -839,7 +839,7 @@ static HcfResult GenPriKeyEcKeyBySpec(const HcfAsyKeyParamsSpec *params, EC_KEY ret = NewEcKeyWithKeyPairSpec((HcfEccKeyPairParamsSpec *)params, ecKey, true); break; default: - LOGE("Invaild input spec to gen pri key"); + LOGE_ONE_STR("Invaild input spec to gen pri key"); break; } return ret; @@ -931,7 +931,7 @@ static void DestroyEccKeyPair(HcfObjectBase *self) static const char *GetEccPubKeyAlgorithm(HcfKey *self) { if (self == NULL) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return NULL; } if (!HcfIsClassMatch((HcfObjectBase *)self, HCF_OPENSSL_ECC_PUB_KEY_CLASS)) { @@ -943,7 +943,7 @@ static const char *GetEccPubKeyAlgorithm(HcfKey *self) static const char *GetEccPriKeyAlgorithm(HcfKey *self) { if (self == NULL) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return NULL; } if (!HcfIsClassMatch((HcfObjectBase *)self, HCF_OPENSSL_ECC_PRI_KEY_CLASS)) { @@ -955,7 +955,7 @@ static const char *GetEccPriKeyAlgorithm(HcfKey *self) static const char *GetEccPubKeyFormat(HcfKey *self) { if (self == NULL) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return NULL; } if (!HcfIsClassMatch((HcfObjectBase *)self, HCF_OPENSSL_ECC_PUB_KEY_CLASS)) { @@ -967,7 +967,7 @@ static const char *GetEccPubKeyFormat(HcfKey *self) static const char *GetEccPriKeyFormat(HcfKey *self) { if (self == NULL) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return NULL; } if (!HcfIsClassMatch((HcfObjectBase *)self, HCF_OPENSSL_ECC_PRI_KEY_CLASS)) { @@ -979,14 +979,14 @@ static const char *GetEccPriKeyFormat(HcfKey *self) static HcfResult CheckAndUpdateEccPubKeyFormat(const char **format) { if (format == NULL || *format == NULL) { - LOGE("Invalid format parameter"); + LOGE_ONE_STR("Invalid format parameter"); return HCF_INVALID_PARAMS; } const char *x509Str = "X509|"; if (strncmp(*format, x509Str, HcfStrlen(x509Str)) != 0) { - LOGE("Invalid x509Str parameter"); + LOGE_ONE_STR("Invalid x509Str parameter"); return HCF_INVALID_PARAMS; } @@ -996,7 +996,7 @@ static HcfResult CheckAndUpdateEccPubKeyFormat(const char **format) *format = formatPtr; return HCF_SUCCESS; } else { - LOGE("Invalid formatPtr parameter"); + LOGE_ONE_STR("Invalid formatPtr parameter"); return HCF_INVALID_PARAMS; } } @@ -1005,27 +1005,27 @@ static OSSL_PARAM *ConvertHcfBlobToOsslParams(const char *groupName, HcfBlob *po { OSSL_PARAM_BLD *paramBld = OpensslOsslParamBldNew(); if (paramBld == NULL) { - LOGE("paramBld is null"); + LOGE_ONE_STR("paramBld is null"); return NULL; } if (OpensslOsslParamBldPushUtf8String(paramBld, "group", groupName, 0) != HCF_OPENSSL_SUCCESS) { - LOGE("Invalid groupName parameter."); + LOGE_ONE_STR("Invalid groupName parameter."); OpensslOsslParamBldFree(paramBld); return NULL; } if (OpensslOsslParamBldPushUtf8String(paramBld, "point-format", format, 0) != HCF_OPENSSL_SUCCESS) { - LOGE("Invalid format parameter."); + LOGE_ONE_STR("Invalid format parameter."); OpensslOsslParamBldFree(paramBld); return NULL; } if (OpensslOsslParamBldPushOctetString(paramBld, "pub", pointBlob->data, pointBlob->len) != HCF_OPENSSL_SUCCESS) { - LOGE("Invalid pointBlob parameter."); + LOGE_ONE_STR("Invalid pointBlob parameter."); OpensslOsslParamBldFree(paramBld); return NULL; } OSSL_PARAM *params = OpensslOsslParamBldToParam(paramBld); if (params == NULL) { - LOGE("Failed to convert OSSL_PARAM_BLD to OSSL_PARAM"); + LOGE_ONE_STR("Failed to convert OSSL_PARAM_BLD to OSSL_PARAM"); HcfPrintOpensslError(); OpensslOsslParamBldFree(paramBld); return NULL; @@ -1039,7 +1039,7 @@ static EC_KEY *ConvertOsslParamsToEccPubKey(const char *groupName, int32_t curve { OSSL_PARAM *params = ConvertHcfBlobToOsslParams(groupName, pointBlob, format); if (params == NULL) { - LOGE("Failed to convert OSSL_PARAM_BLD to OSSL_PARAM"); + LOGE_ONE_STR("Failed to convert OSSL_PARAM_BLD to OSSL_PARAM"); return NULL; } EVP_PKEY_CTX *ctx = NULL; @@ -1048,7 +1048,7 @@ static EC_KEY *ConvertOsslParamsToEccPubKey(const char *groupName, int32_t curve do { ctx = OpensslEvpPkeyCtxNewId(EVP_PKEY_EC, NULL); if (ctx == NULL) { - LOGE("Failed to create EVP_PKEY_CTX"); + LOGE_ONE_STR("Failed to create EVP_PKEY_CTX"); break; } if (OpensslEvpPkeyParamGenInit(ctx) <= 0) { @@ -1056,22 +1056,22 @@ static EC_KEY *ConvertOsslParamsToEccPubKey(const char *groupName, int32_t curve break; } if (OpensslEvpPkeyCtxSetEcParamgenCurveNid(ctx, curveId) <= 0) { - LOGE("EVP init curveId fail"); + LOGE_ONE_STR("EVP init curveId fail"); HcfPrintOpensslError(); break; } if (OpensslEvpPkeyFromDataInit(ctx) != HCF_OPENSSL_SUCCESS) { - LOGE("EVP init fail"); + LOGE_ONE_STR("EVP init fail"); break; } if (OpensslEvpPkeyFromData(ctx, &pkey, EVP_PKEY_PUBLIC_KEY, params) != HCF_OPENSSL_SUCCESS) { - LOGE("EVP get pkey fail"); + LOGE_ONE_STR("EVP get pkey fail"); HcfPrintOpensslError(); break; } returnKey = OpensslEvpPkeyGet1EcKey(pkey); if (returnKey == NULL) { - LOGE("Return key is NULL"); + LOGE_ONE_STR("Return key is NULL"); break; } } while (0); @@ -1085,34 +1085,34 @@ static HcfResult GetCompressedEccPointEncoded(HcfOpensslEccPubKey *impl, HcfBlob { EC_KEY *ecKey = impl->ecKey; if (ecKey == NULL) { - LOGE("EcKey is NULL."); + LOGE_ONE_STR("EcKey is NULL."); return HCF_INVALID_PARAMS; } const EC_GROUP *group = OpensslEcKeyGet0Group(ecKey); if (group == NULL) { - LOGE("Failed to get group."); + LOGE_ONE_STR("Failed to get group."); return HCF_ERR_CRYPTO_OPERATION; } const EC_POINT *point = OpensslEcKeyGet0PublicKey(ecKey); if (point == NULL) { - LOGE("Failed to get point."); + LOGE_ONE_STR("Failed to get point."); return HCF_ERR_CRYPTO_OPERATION; } size_t returnDataLen = EC_POINT_point2oct(group, point, POINT_CONVERSION_COMPRESSED, NULL, 0, NULL); if (returnDataLen == 0) { - LOGE("Failed to get compressed key length."); + LOGE_ONE_STR("Failed to get compressed key length."); HcfPrintOpensslError(); return HCF_ERR_CRYPTO_OPERATION; } uint8_t *returnData = (uint8_t *)HcfMalloc(returnDataLen, 0); if (returnData == NULL) { - LOGE("Failed to allocate memory for returnBlob data."); + LOGE_ONE_STR("Failed to allocate memory for returnBlob data."); return HCF_ERR_MALLOC; } size_t result = EC_POINT_point2oct(group, point, POINT_CONVERSION_COMPRESSED, returnData, returnDataLen, NULL); if (result != returnDataLen) { - LOGE("Failed to convert public key to compressed format."); + LOGE_ONE_STR("Failed to convert public key to compressed format."); HcfPrintOpensslError(); HcfFree(returnData); return HCF_ERR_CRYPTO_OPERATION; @@ -1127,7 +1127,7 @@ static HcfResult GetDerEccPubKeyEncoded(EC_KEY *ecKey, HcfBlob *returnBlob) unsigned char *returnData = NULL; int returnDataLen = OpensslI2dEcPubKey(ecKey, &returnData); if (returnDataLen <= 0) { - LOGE("i2d_EC_PUBKEY fail"); + LOGE_ONE_STR("i2d_EC_PUBKEY fail"); HcfPrintOpensslError(); return HCF_ERR_CRYPTO_OPERATION; } @@ -1139,7 +1139,7 @@ static HcfResult GetDerEccPubKeyEncoded(EC_KEY *ecKey, HcfBlob *returnBlob) static void SetEccKeyAsn1Flag(HcfOpensslEccPubKey *impl) { if (impl->curveId != 0) { - LOGD("have a curveId"); + LOGD_ONE_STR("have a curveId"); OpensslEcKeySetAsn1Flag(impl->ecKey, OPENSSL_EC_NAMED_CURVE); } else { OpensslEcKeySetAsn1Flag(impl->ecKey, OPENSSL_EC_EXPLICIT_CURVE); @@ -1149,17 +1149,17 @@ static void SetEccKeyAsn1Flag(HcfOpensslEccPubKey *impl) static HcfResult GetEccPubKeyEncodedDer(const HcfPubKey *self, const char *format, HcfBlob *returnBlob) { if ((self == NULL) || (returnBlob == NULL)) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return HCF_INVALID_PARAMS; } if (CheckAndUpdateEccPubKeyFormat(&format) != HCF_SUCCESS) { - LOGE("Invalid format."); + LOGE_ONE_STR("Invalid format."); return HCF_INVALID_PARAMS; } if (!HcfIsClassMatch((HcfObjectBase *)self, HCF_OPENSSL_ECC_PUB_KEY_CLASS)) { - LOGE("Invalid input parameter type."); + LOGE_ONE_STR("Invalid input parameter type."); return HCF_INVALID_PARAMS; } HcfOpensslEccPubKey *impl = (HcfOpensslEccPubKey *)self; @@ -1168,18 +1168,18 @@ static HcfResult GetEccPubKeyEncodedDer(const HcfPubKey *self, const char *forma char *groupName = NULL; HcfResult ret = GetGroupNameByNid(impl->curveId, &groupName); if (ret != HCF_SUCCESS) { - LOGE("Failed to get group name."); + LOGE_ONE_STR("Failed to get group name."); return ret; } HcfBlob tmpBlob = { .data = NULL, .len = 0 }; ret = GetCompressedEccPointEncoded(impl, &tmpBlob); if (ret != HCF_SUCCESS) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return ret; } EC_KEY *tmpEcKey = ConvertOsslParamsToEccPubKey(groupName, impl->curveId, &tmpBlob, format); if (tmpEcKey == NULL) { - LOGE("Failed to convert ECC parameters to EC public key."); + LOGE_ONE_STR("Failed to convert ECC parameters to EC public key."); HcfBlobDataFree(&tmpBlob); return HCF_ERR_CRYPTO_OPERATION; } @@ -1192,7 +1192,7 @@ static HcfResult GetEccPubKeyEncodedDer(const HcfPubKey *self, const char *forma static HcfResult GetEccPubKeyEncoded(HcfKey *self, HcfBlob *returnBlob) { if ((self == NULL) || (returnBlob == NULL)) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return HCF_INVALID_PARAMS; } if (!HcfIsClassMatch((HcfObjectBase *)self, HCF_OPENSSL_ECC_PUB_KEY_CLASS)) { @@ -1205,11 +1205,11 @@ static HcfResult GetEccPubKeyEncoded(HcfKey *self, HcfBlob *returnBlob) unsigned char *returnData = NULL; int returnDataLen = OpensslI2dEcPubKey(impl->ecKey, &returnData); if (returnDataLen <= 0) { - LOGD("[error] i2d_EC_PUBKEY fail"); + LOGD_ONE_STR("[error] i2d_EC_PUBKEY fail"); HcfPrintOpensslError(); return HCF_ERR_CRYPTO_OPERATION; } - LOGD("ECC pubKey i2d success"); + LOGD_ONE_STR("ECC pubKey i2d success"); returnBlob->data = returnData; returnBlob->len = returnDataLen; return HCF_SUCCESS; @@ -1226,7 +1226,7 @@ static HcfResult GetEccPubKeyEncodedPem(HcfKey *self, const char *format, char * static HcfResult GetEccPriKeyEncoded(HcfKey *self, HcfBlob *returnBlob) { if ((self == NULL) || (returnBlob == NULL)) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return HCF_INVALID_PARAMS; } if (!HcfIsClassMatch((HcfObjectBase *)self, HCF_OPENSSL_ECC_PRI_KEY_CLASS)) { @@ -1235,7 +1235,7 @@ static HcfResult GetEccPriKeyEncoded(HcfKey *self, HcfBlob *returnBlob) HcfOpensslEccPriKey *impl = (HcfOpensslEccPriKey *)self; if (impl->curveId != 0) { - LOGD("have a curveId"); + LOGD_ONE_STR("have a curveId"); OpensslEcKeySetAsn1Flag(impl->ecKey, OPENSSL_EC_NAMED_CURVE); } else { OpensslEcKeySetAsn1Flag(impl->ecKey, OPENSSL_EC_EXPLICIT_CURVE); @@ -1247,11 +1247,11 @@ static HcfResult GetEccPriKeyEncoded(HcfKey *self, HcfBlob *returnBlob) unsigned char *returnData = NULL; int returnDataLen = OpensslI2dEcPrivateKey(impl->ecKey, &returnData); if (returnDataLen <= 0) { - LOGD("[error] i2d_ECPrivateKey fail."); + LOGD_ONE_STR("[error] i2d_ECPrivateKey fail."); HcfPrintOpensslError(); return HCF_ERR_CRYPTO_OPERATION; } - LOGD("ECC priKey i2d success"); + LOGD_ONE_STR("ECC priKey i2d success"); returnBlob->data = returnData; returnBlob->len = returnDataLen; return HCF_SUCCESS; @@ -1270,15 +1270,15 @@ static HcfResult GetEccPriKeyEncodedPem(const HcfPriKey *self, HcfParamsSpec *pa static HcfResult ParamCheck(const HcfPriKey *self, const char *format, const HcfBlob *returnBlob) { if ((self == NULL) || (format == NULL) || (returnBlob == NULL)) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return HCF_INVALID_PARAMS; } if (!HcfIsClassMatch((HcfObjectBase *)self, HCF_OPENSSL_ECC_PRI_KEY_CLASS)) { - LOGE("Invalid ecc params."); + LOGE_ONE_STR("Invalid ecc params."); return HCF_INVALID_PARAMS; } if (strcmp(format, "PKCS8") != 0) { - LOGE("Invalid point format."); + LOGE_ONE_STR("Invalid point format."); return HCF_INVALID_PARAMS; } return HCF_SUCCESS; @@ -1288,18 +1288,18 @@ static HcfResult CopyMemFromBIO(BIO *bio, HcfBlob *returnBlob) { int len = BIO_pending(bio); if (len <= 0) { - LOGE("Bio len less than 0."); + LOGE_ONE_STR("Bio len less than 0."); return HCF_INVALID_PARAMS; } HcfBlob tmpBlob; tmpBlob.len = len; tmpBlob.data = (uint8_t *)HcfMalloc(sizeof(uint8_t) * len, 0); if (tmpBlob.data == NULL) { - LOGE("Malloc mem for blob fail."); + LOGE_ONE_STR("Malloc mem for blob fail."); return HCF_ERR_MALLOC; } if (OpensslBioRead(bio, tmpBlob.data, tmpBlob.len) <= 0) { - LOGE("Bio read fail"); + LOGE_ONE_STR("Bio read fail"); HcfPrintOpensslError(); HcfFree(tmpBlob.data); return HCF_ERR_CRYPTO_OPERATION; @@ -1326,31 +1326,31 @@ static HcfResult GetECPriKeyEncodedDer(const HcfPriKey *self, const char *format EVP_PKEY *pkey = OpensslEvpPkeyNew(); if (pkey == NULL) { HcfPrintOpensslError(); - LOGE("New pKey failed."); + LOGE_ONE_STR("New pKey failed."); return HCF_ERR_CRYPTO_OPERATION; } if (OpensslEvpPkeySet1EcKey(pkey, impl->ecKey) != HCF_OPENSSL_SUCCESS) { OpensslEvpPkeyFree(pkey); HcfPrintOpensslError(); - LOGE("set ec key failed."); + LOGE_ONE_STR("set ec key failed."); return HCF_ERR_CRYPTO_OPERATION; } BIO *bio = OpensslBioNew(OpensslBioSMem()); if (bio == NULL) { - LOGE("BIO new fail."); + LOGE_ONE_STR("BIO new fail."); HcfPrintOpensslError(); ret = HCF_ERR_CRYPTO_OPERATION; goto ERR2; } if (i2d_PKCS8PrivateKey_bio(bio, pkey, NULL, NULL, 0, NULL, NULL) != HCF_OPENSSL_SUCCESS) { - LOGE("i2d privateKey bio fail."); + LOGE_ONE_STR("i2d privateKey bio fail."); HcfPrintOpensslError(); ret = HCF_ERR_CRYPTO_OPERATION; goto ERR1; } ret = CopyMemFromBIO(bio, returnBlob); if (ret != HCF_SUCCESS) { - LOGE("Copy mem from BIO fail."); + LOGE_ONE_STR("Copy mem from BIO fail."); } ERR1: OpensslBioFreeAll(bio); @@ -1383,23 +1383,23 @@ static HcfResult GetCurveName(const HcfKey *self, const bool isPriavte, char **r char *tmp = NULL; if (GetCurveNameByCurveId(curveId, &tmp) != HCF_SUCCESS) { - LOGE("get vurveName by curveId failed."); + LOGE_ONE_STR("get vurveName by curveId failed."); return HCF_INVALID_PARAMS; } if (tmp == NULL) { - LOGE("tmp is null."); + LOGE_ONE_STR("tmp is null."); return HCF_INVALID_PARAMS; } size_t len = HcfStrlen(tmp); if (len == 0) { - LOGE("fieldType is empty!"); + LOGE_ONE_STR("fieldType is empty!"); return HCF_INVALID_PARAMS; } *returnString = (char *)HcfMalloc(len + 1, 0); if (*returnString == NULL) { - LOGE("Alloc returnString memory failed."); + LOGE_ONE_STR("Alloc returnString memory failed."); return HCF_ERR_MALLOC; } (void)memcpy_s(*returnString, len, tmp, len); @@ -1413,7 +1413,7 @@ static HcfResult CheckEcKeySelf(const HcfKey *self, bool *isPrivate) return HCF_SUCCESS; } else if (HcfIsClassMatch((HcfObjectBase *)self, GetEccPriKeyClass())) { if (((HcfOpensslEccPriKey *)self)->ecKey == NULL) { - LOGE("Cannot use priKey after free"); + LOGE_ONE_STR("Cannot use priKey after free"); return HCF_INVALID_PARAMS; } *isPrivate = true; @@ -1427,13 +1427,13 @@ static HcfResult GetEcKeySpecBigInteger(const HcfKey *self, const AsyKeySpecItem HcfBigInteger *returnBigInteger) { if (self == NULL || returnBigInteger == NULL) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return HCF_INVALID_PARAMS; } bool isPrivate = false; HcfResult res = CheckEcKeySelf(self, &isPrivate); if (res != HCF_SUCCESS) { - LOGE("Invalid input key"); + LOGE_ONE_STR("Invalid input key"); return HCF_INVALID_PARAMS; } const EC_GROUP *group = NULL; @@ -1461,7 +1461,7 @@ static HcfResult GetEcKeySpecBigInteger(const HcfKey *self, const AsyKeySpecItem res = GetPkSkBigInteger(self, isPrivate, item, returnBigInteger); break; default: - LOGE("Invalid ecc key big number spec!"); + LOGE_ONE_STR("Invalid ecc key big number spec!"); res = HCF_INVALID_PARAMS; break; } @@ -1471,13 +1471,13 @@ static HcfResult GetEcKeySpecBigInteger(const HcfKey *self, const AsyKeySpecItem static HcfResult GetEcKeySpecString(const HcfKey *self, const AsyKeySpecItem item, char **returnString) { if (self == NULL || returnString == NULL) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return HCF_INVALID_PARAMS; } bool isPrivate = false; HcfResult res = CheckEcKeySelf(self, &isPrivate); if (res != HCF_SUCCESS) { - LOGE("Invalid input key"); + LOGE_ONE_STR("Invalid input key"); return HCF_INVALID_PARAMS; } @@ -1490,7 +1490,7 @@ static HcfResult GetEcKeySpecString(const HcfKey *self, const AsyKeySpecItem ite break; default: res = HCF_INVALID_PARAMS; - LOGE("Invalid spec of ec string"); + LOGE_ONE_STR("Invalid spec of ec string"); break; } return res; @@ -1499,13 +1499,13 @@ static HcfResult GetEcKeySpecString(const HcfKey *self, const AsyKeySpecItem ite static HcfResult GetEcKeySpecInt(const HcfKey *self, const AsyKeySpecItem item, int *returnInt) { if (self == NULL || returnInt == NULL) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return HCF_INVALID_PARAMS; } bool isPrivate = false; HcfResult res = CheckEcKeySelf(self, &isPrivate); if (res != HCF_SUCCESS) { - LOGE("Invalid input key"); + LOGE_ONE_STR("Invalid input key"); return HCF_INVALID_PARAMS; } const EC_GROUP *group = NULL; @@ -1523,7 +1523,7 @@ static HcfResult GetEcKeySpecInt(const HcfKey *self, const AsyKeySpecItem item, break; default: res = HCF_INVALID_PARAMS; - LOGE("invalid ec key int spec"); + LOGE_ONE_STR("invalid ec key int spec"); break; } return res; @@ -1566,20 +1566,20 @@ static HcfResult PackEccPubKey(int32_t curveId, EC_KEY *ecKey, const char *field { HcfOpensslEccPubKey *returnPubKey = (HcfOpensslEccPubKey *)HcfMalloc(sizeof(HcfOpensslEccPubKey), 0); if (returnPubKey == NULL) { - LOGE("Failed to allocate returnPubKey memory!"); + LOGE_ONE_STR("Failed to allocate returnPubKey memory!"); return HCF_ERR_MALLOC; } char *tmpFieldType = NULL; if (fieldType != NULL) { size_t len = HcfStrlen(fieldType); if (len == 0) { - LOGE("fieldType is empty!"); + LOGE_ONE_STR("fieldType is empty!"); HcfFree(returnPubKey); return HCF_INVALID_PARAMS; } tmpFieldType = (char *)HcfMalloc(len + 1, 0); if (tmpFieldType == NULL) { - LOGE("Alloc tmpFieldType memory failed."); + LOGE_ONE_STR("Alloc tmpFieldType memory failed."); HcfFree(returnPubKey); return HCF_ERR_MALLOC; } @@ -1609,20 +1609,20 @@ static HcfResult PackEccPriKey(int32_t curveId, EC_KEY *ecKey, const char *field { HcfOpensslEccPriKey *returnPriKey = (HcfOpensslEccPriKey *)HcfMalloc(sizeof(HcfOpensslEccPriKey), 0); if (returnPriKey == NULL) { - LOGE("Failed to allocate returnPriKey memory!"); + LOGE_ONE_STR("Failed to allocate returnPriKey memory!"); return HCF_ERR_MALLOC; } char *tmpFieldType = NULL; if (fieldType != NULL) { size_t len = HcfStrlen(fieldType); if (len == 0) { - LOGE("fieldType is empty!"); + LOGE_ONE_STR("fieldType is empty!"); HcfFree(returnPriKey); return HCF_INVALID_PARAMS; } tmpFieldType = (char *)HcfMalloc(len + 1, 0); if (tmpFieldType == NULL) { - LOGE("Alloc tmpFieldType memory failed."); + LOGE_ONE_STR("Alloc tmpFieldType memory failed."); HcfFree(returnPriKey); return HCF_ERR_MALLOC; } @@ -1653,7 +1653,7 @@ static HcfResult PackEccKeyPair(HcfOpensslEccPubKey *pubKey, HcfOpensslEccPriKey { HcfOpensslEccKeyPair *returnKeyPair = (HcfOpensslEccKeyPair *)HcfMalloc(sizeof(HcfOpensslEccKeyPair), 0); if (returnKeyPair == NULL) { - LOGE("Failed to allocate returnKeyPair memory!"); + LOGE_ONE_STR("Failed to allocate returnKeyPair memory!"); return HCF_ERR_MALLOC; } returnKeyPair->base.base.getClass = GetEccKeyPairClass; @@ -1670,13 +1670,13 @@ static HcfResult ConvertEcPubKey(int32_t curveId, HcfBlob *pubKeyBlob, HcfOpenss const unsigned char *tmpData = (const unsigned char *)(pubKeyBlob->data); EC_KEY *ecKey = OpensslD2iEcPubKey(NULL, &tmpData, pubKeyBlob->len); if (ecKey == NULL) { - LOGE("d2i_EC_PUBKEY fail."); + LOGE_ONE_STR("d2i_EC_PUBKEY fail."); HcfPrintOpensslError(); return HCF_ERR_CRYPTO_OPERATION; } HcfResult res = PackEccPubKey(curveId, ecKey, g_eccGenerateFieldType, returnPubKey); if (res != HCF_SUCCESS) { - LOGE("PackEccPubKey failed."); + LOGE_ONE_STR("PackEccPubKey failed."); OpensslEcKeyFree(ecKey); return res; } @@ -1689,13 +1689,13 @@ static HcfResult ConvertPriFromEncoded(EC_KEY **eckey, HcfBlob *priKeyBlob) EVP_PKEY *pkey = OpensslD2iPrivateKey(EVP_PKEY_EC, NULL, &tmpData, priKeyBlob->len); if (pkey == NULL) { HcfPrintOpensslError(); - LOGE("d2i pri key failed."); + LOGE_ONE_STR("d2i pri key failed."); return HCF_ERR_CRYPTO_OPERATION; } *eckey = EVP_PKEY_get1_EC_KEY(pkey); OpensslEvpPkeyFree(pkey); if (*eckey == NULL) { - LOGE("Get eckey failed"); + LOGE_ONE_STR("Get eckey failed"); HcfPrintOpensslError(); return HCF_ERR_CRYPTO_OPERATION; } @@ -1707,18 +1707,18 @@ static HcfResult ConvertEcPriKey(int32_t curveId, HcfBlob *priKeyBlob, HcfOpenss EC_KEY *ecKey = NULL; HcfResult res = ConvertPriFromEncoded(&ecKey, priKeyBlob); if (res != HCF_SUCCESS) { - LOGE("i2d for private key failed"); + LOGE_ONE_STR("i2d for private key failed"); HcfPrintOpensslError(); return HCF_ERR_CRYPTO_OPERATION; } if (ecKey == NULL) { - LOGE("d2i ec private key fail"); + LOGE_ONE_STR("d2i ec private key fail"); HcfPrintOpensslError(); return HCF_ERR_CRYPTO_OPERATION; } res = PackEccPriKey(curveId, ecKey, g_eccGenerateFieldType, returnPriKey); if (res != HCF_SUCCESS) { - LOGE("Pack ec pri key failed."); + LOGE_ONE_STR("Pack ec pri key failed."); OpensslEcKeyFree(ecKey); return res; } @@ -1730,7 +1730,7 @@ static HcfResult EngineConvertEccKey(HcfAsyKeyGeneratorSpi *self, HcfParamsSpec { (void)params; if ((self == NULL) || (returnKeyPair == NULL)) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return HCF_INVALID_PARAMS; } if (!HcfIsClassMatch((HcfObjectBase *)self, GetEccKeyPairGeneratorClass())) { @@ -1739,7 +1739,7 @@ static HcfResult EngineConvertEccKey(HcfAsyKeyGeneratorSpi *self, HcfParamsSpec bool pubKeyValid = HcfIsBlobValid(pubKeyBlob); bool priKeyValid = HcfIsBlobValid(priKeyBlob); if ((!pubKeyValid) && (!priKeyValid)) { - LOGE("The private key and public key cannot both be NULL."); + LOGE_ONE_STR("The private key and public key cannot both be NULL."); return HCF_INVALID_PARAMS; } @@ -1779,21 +1779,21 @@ static HcfResult ConvertEcPemPubKey(int32_t curveId, const char *pubKeyStr, HcfO const char *keyType = "EC"; HcfResult ret = ConvertPubPemStrToKey(&pkey, keyType, EVP_PKEY_PUBLIC_KEY, pubKeyStr); if (ret != HCF_SUCCESS) { - LOGE("Convert ecc pem public key failed."); + LOGE_ONE_STR("Convert ecc pem public key failed."); return ret; } EC_KEY *ecKey = OpensslEvpPkeyGet1EcKey(pkey); OpensslEvpPkeyFree(pkey); if (ecKey == NULL) { - LOGE("Pkey to ec key failed."); + LOGE_ONE_STR("Pkey to ec key failed."); HcfPrintOpensslError(); return HCF_ERR_CRYPTO_OPERATION; } HcfResult res = PackEccPubKey(curveId, ecKey, g_eccGenerateFieldType, returnPubKey); if (res != HCF_SUCCESS) { - LOGE("Pack ec public key failed."); + LOGE_ONE_STR("Pack ec public key failed."); OpensslEcKeyFree(ecKey); return res; } @@ -1807,21 +1807,21 @@ static HcfResult ConvertEcPemPriKey(int32_t curveId, const char *priKeyStr, HcfO const char *keyType = "EC"; HcfResult ret = ConvertPriPemStrToKey(priKeyStr, &pkey, keyType); if (ret != HCF_SUCCESS) { - LOGE("Convert ecc pem private key failed."); + LOGE_ONE_STR("Convert ecc pem private key failed."); return ret; } EC_KEY *ecKey = OpensslEvpPkeyGet1EcKey(pkey); OpensslEvpPkeyFree(pkey); if (ecKey == NULL) { - LOGE("Pkey to ec key failed."); + LOGE_ONE_STR("Pkey to ec key failed."); HcfPrintOpensslError(); return HCF_ERR_CRYPTO_OPERATION; } ret = PackEccPriKey(curveId, ecKey, g_eccGenerateFieldType, returnPriKey); if (ret != HCF_SUCCESS) { - LOGE("Pack ec private key failed."); + LOGE_ONE_STR("Pack ec private key failed."); OpensslEcKeyFree(ecKey); return ret; } @@ -1834,7 +1834,7 @@ static HcfResult EngineConvertEccPemKey(HcfAsyKeyGeneratorSpi *self, HcfParamsSp { (void)params; if ((self == NULL) || (returnKeyPair == NULL) || ((pubKeyStr == NULL) && (priKeyStr == NULL))) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return HCF_INVALID_PARAMS; } if (!HcfIsClassMatch((HcfObjectBase *)self, GetEccKeyPairGeneratorClass())) { @@ -1863,7 +1863,7 @@ static HcfResult EngineConvertEccPemKey(HcfAsyKeyGeneratorSpi *self, HcfParamsSp res = PackEccKeyPair(pubKey, priKey, &keyPair); } while (0); if (res != HCF_SUCCESS) { - LOGE("Convert ec keyPair failed."); + LOGE_ONE_STR("Convert ec keyPair failed."); HcfObjDestroy(pubKey); HcfObjDestroy(priKey); return res; @@ -1902,7 +1902,7 @@ static HcfResult CreateAndAssignKeyPair(const HcfAsyKeyGeneratorSpiOpensslEccImp { EC_KEY *ecPriKey = EC_KEY_dup(ecKey); if (ecPriKey == NULL) { - LOGD("[error] copy ecKey fail."); + LOGD_ONE_STR("[error] copy ecKey fail."); return HCF_ERR_CRYPTO_OPERATION; } HcfOpensslEccPriKey *priKey = NULL; @@ -1914,7 +1914,7 @@ static HcfResult CreateAndAssignKeyPair(const HcfAsyKeyGeneratorSpiOpensslEccImp HcfOpensslEccPubKey *pubKey = NULL; EC_KEY *ecPubKey = EC_KEY_dup(ecKey); if (ecPubKey == NULL) { - LOGD("[error] copy ecKey fail."); + LOGD_ONE_STR("[error] copy ecKey fail."); HcfObjDestroy(priKey); return HCF_ERR_CRYPTO_OPERATION; } @@ -1927,7 +1927,7 @@ static HcfResult CreateAndAssignKeyPair(const HcfAsyKeyGeneratorSpiOpensslEccImp HcfOpensslEccKeyPair *returnKeyPair = (HcfOpensslEccKeyPair *)HcfMalloc(sizeof(HcfOpensslEccKeyPair), 0); if (returnKeyPair == NULL) { - LOGE("Failed to allocate returnKeyPair memory!"); + LOGE_ONE_STR("Failed to allocate returnKeyPair memory!"); HcfObjDestroy(pubKey); HcfObjDestroy(priKey); return HCF_ERR_MALLOC; @@ -1944,7 +1944,7 @@ static HcfResult CreateAndAssignKeyPair(const HcfAsyKeyGeneratorSpiOpensslEccImp static HcfResult EngineGenerateKeyPair(HcfAsyKeyGeneratorSpi *self, HcfKeyPair **returnObj) { if ((self == NULL) || (returnObj == NULL)) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return HCF_INVALID_PARAMS; } if (!HcfIsClassMatch((HcfObjectBase *)self, GetEccKeyPairGeneratorClass())) { @@ -1960,7 +1960,7 @@ static HcfResult EngineGenerateKeyPair(HcfAsyKeyGeneratorSpi *self, HcfKeyPair * res = CreateAndAssignKeyPair(impl, g_eccGenerateFieldType, ecKey, returnObj); OpensslEcKeyFree(ecKey); if (res != HCF_SUCCESS) { - LOGE("CreateAndAssignKeyPair failed."); + LOGE_ONE_STR("CreateAndAssignKeyPair failed."); return res; } return HCF_SUCCESS; @@ -1971,7 +1971,7 @@ static HcfResult EngineGenerateKeyPairBySpec(const HcfAsyKeyGeneratorSpi *self, { if ((self == NULL) || (returnKeyPair == NULL) || (params == NULL) || (((HcfEccCommParamsSpec *)params)->field == NULL)) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return HCF_INVALID_PARAMS; } if (!HcfIsClassMatch((HcfObjectBase *)self, GetEccKeyPairGeneratorClass())) { @@ -1982,7 +1982,7 @@ static HcfResult EngineGenerateKeyPairBySpec(const HcfAsyKeyGeneratorSpi *self, EC_KEY *ecKey = NULL; HcfResult res = GenKeyPairEcKeyBySpec(params, &ecKey); if (res != HCF_SUCCESS) { - LOGE("Gen ec key pair with spec failed."); + LOGE_ONE_STR("Gen ec key pair with spec failed."); return res; } @@ -1995,7 +1995,7 @@ static HcfResult EngineGenerateKeyPairBySpec(const HcfAsyKeyGeneratorSpi *self, res = CreateAndAssignKeyPair(impl, ((HcfEccCommParamsSpec *)params)->field->fieldType, ecKey, returnKeyPair); OpensslEcKeyFree(ecKey); if (res != HCF_SUCCESS) { - LOGE("CreateAndAssignKeyPair failed."); + LOGE_ONE_STR("CreateAndAssignKeyPair failed."); return res; } @@ -2007,7 +2007,7 @@ static HcfResult EngineGeneratePubKeyBySpec(const HcfAsyKeyGeneratorSpi *self, c { if ((self == NULL) || (returnPubKey == NULL) || (params == NULL) || (((HcfEccCommParamsSpec *)params)->field == NULL)) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return HCF_INVALID_PARAMS; } if (!HcfIsClassMatch((HcfObjectBase *)self, GetEccKeyPairGeneratorClass())) { @@ -2018,7 +2018,7 @@ static HcfResult EngineGeneratePubKeyBySpec(const HcfAsyKeyGeneratorSpi *self, c EC_KEY *ecKey = NULL; HcfResult res = GenPubKeyEcKeyBySpec(params, &ecKey); if (res != HCF_SUCCESS) { - LOGE("Gen ec pubKey with spec failed."); + LOGE_ONE_STR("Gen ec pubKey with spec failed."); return res; } int32_t curveId = (int32_t)OpensslEcGroupGetCurveName(OpensslEcKeyGet0Group(ecKey)); @@ -2027,7 +2027,7 @@ static HcfResult EngineGeneratePubKeyBySpec(const HcfAsyKeyGeneratorSpi *self, c } res = PackAndAssignPubKey(impl, ((HcfEccCommParamsSpec *)params)->field->fieldType, ecKey, returnPubKey); if (res != HCF_SUCCESS) { - LOGE("PackAndAssignPubKey failed."); + LOGE_ONE_STR("PackAndAssignPubKey failed."); OpensslEcKeyFree(ecKey); return res; } @@ -2040,7 +2040,7 @@ static HcfResult EngineGeneratePriKeyBySpec(const HcfAsyKeyGeneratorSpi *self, c { if ((self == NULL) || (returnPriKey == NULL) || (params == NULL) || (((HcfEccCommParamsSpec *)params)->field == NULL)) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return HCF_INVALID_PARAMS; } if (!HcfIsClassMatch((HcfObjectBase *)self, GetEccKeyPairGeneratorClass())) { @@ -2051,7 +2051,7 @@ static HcfResult EngineGeneratePriKeyBySpec(const HcfAsyKeyGeneratorSpi *self, c EC_KEY *ecKey = NULL; HcfResult res = GenPriKeyEcKeyBySpec(params, &ecKey); if (res != HCF_SUCCESS) { - LOGE("Gen ec pubKey with spec failed."); + LOGE_ONE_STR("Gen ec pubKey with spec failed."); return res; } @@ -2062,7 +2062,7 @@ static HcfResult EngineGeneratePriKeyBySpec(const HcfAsyKeyGeneratorSpi *self, c res = PackAndAssignPriKey(impl, ((HcfEccCommParamsSpec *)params)->field->fieldType, ecKey, returnPriKey); if (res != HCF_SUCCESS) { - LOGE("PackAndAssignPriKey failed."); + LOGE_ONE_STR("PackAndAssignPriKey failed."); OpensslEcKeyFree(ecKey); return res; } @@ -2073,7 +2073,7 @@ static HcfResult EngineGeneratePriKeyBySpec(const HcfAsyKeyGeneratorSpi *self, c HcfResult HcfAsyKeyGeneratorSpiEccCreate(HcfAsyKeyGenParams *params, HcfAsyKeyGeneratorSpi **returnObj) { if (params == NULL || returnObj == NULL) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return HCF_INVALID_PARAMS; } int32_t curveId = 0; @@ -2086,7 +2086,7 @@ HcfResult HcfAsyKeyGeneratorSpiEccCreate(HcfAsyKeyGenParams *params, HcfAsyKeyGe HcfAsyKeyGeneratorSpiOpensslEccImpl *returnImpl = (HcfAsyKeyGeneratorSpiOpensslEccImpl *)HcfMalloc( sizeof(HcfAsyKeyGeneratorSpiOpensslEccImpl), 0); if (returnImpl == NULL) { - LOGE("Failed to allocate returnImpl memroy!"); + LOGE_ONE_STR("Failed to allocate returnImpl memroy!"); return HCF_ERR_MALLOC; } returnImpl->base.base.getClass = GetEccKeyPairGeneratorClass; 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 8021e765527877a2d3fb8a052f8d5521b664fc68..74d298a0077433d8cddf1fbb5072a695bc7beca4 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 @@ -29,17 +29,17 @@ static EC_POINT *BuildEcPoint(const EC_GROUP *ecGroup) { EC_POINT *point = OpensslEcPointNew(ecGroup); if (point == NULL) { - LOGE("new ec point failed."); + LOGE_ONE_STR("new ec point failed."); return NULL; } const EC_POINT *tmpPoint = OpensslEcGroupGet0Generator(ecGroup); if (tmpPoint == NULL) { - LOGE("Get ec generator failed."); + LOGE_ONE_STR("Get ec generator failed."); OpensslEcPointFree(point); return NULL; } if (!OpensslEcPointCopy(point, tmpPoint)) { - LOGE("Ec point copy failed."); + LOGE_ONE_STR("Ec point copy failed."); OpensslEcPointFree(point); return NULL; } @@ -52,18 +52,18 @@ static HcfResult BuildCommonParamPart(const EC_GROUP *ecGroup, HcfEccCommParamsS EC_POINT *point = NULL; point = BuildEcPoint(ecGroup); if (point == NULL) { - LOGE("Build ec point failed."); + LOGE_ONE_STR("Build ec point failed."); return HCF_ERR_MALLOC; } BIGNUM *x = OpensslBnNew(); if (x == NULL) { - LOGE("New x failed."); + LOGE_ONE_STR("New x failed."); OpensslEcPointFree(point); return HCF_ERR_MALLOC; } BIGNUM *y = OpensslBnNew(); if (y == NULL) { - LOGE("New y failed."); + LOGE_ONE_STR("New y failed."); OpensslBnFree(x); OpensslEcPointFree(point); return HCF_ERR_MALLOC; @@ -71,17 +71,17 @@ static HcfResult BuildCommonParamPart(const EC_GROUP *ecGroup, HcfEccCommParamsS HcfResult ret = HCF_SUCCESS; do { if (!OpensslEcPointGetAffineCoordinatesGfp(ecGroup, point, x, y, NULL)) { - LOGE("EC_POINT_get_affine_coordinates_GFp failed."); + LOGE_ONE_STR("EC_POINT_get_affine_coordinates_GFp failed."); ret = HCF_ERR_CRYPTO_OPERATION; break; } if (BigNumToBigInteger(x, &(returnCommonParamSpec->paramsSpec.g.x)) != HCF_SUCCESS) { - LOGE("Build commonParamSpec x failed."); + LOGE_ONE_STR("Build commonParamSpec x failed."); ret = HCF_ERR_CRYPTO_OPERATION; break; } if (BigNumToBigInteger(y, &(returnCommonParamSpec->paramsSpec.g.y)) != HCF_SUCCESS) { - LOGE("Build commonParamSpec y failed."); + LOGE_ONE_STR("Build commonParamSpec y failed."); ret = HCF_ERR_CRYPTO_OPERATION; break; } @@ -98,14 +98,14 @@ static HcfResult BuildCommonParamGFp(const EC_GROUP *ecGroup, HcfEccCommParamsSp BIGNUM *a = OpensslBnNew(); BIGNUM *b = OpensslBnNew(); if (p == NULL || a == NULL || b == NULL) { - LOGD("[error] new BN failed."); + LOGD_ONE_STR("[error] new BN failed."); OpensslBnFree(p); OpensslBnFree(a); OpensslBnFree(b); return HCF_ERR_CRYPTO_OPERATION; } if (!OpensslEcGroupGetCurveGfp(ecGroup, p, a, b, NULL)) { - LOGE("EC_GROUP_get_curve_GFp failed."); + LOGE_ONE_STR("EC_GROUP_get_curve_GFp failed."); OpensslBnFree(p); OpensslBnFree(a); OpensslBnFree(b); @@ -115,25 +115,25 @@ static HcfResult BuildCommonParamGFp(const EC_GROUP *ecGroup, HcfEccCommParamsSp do { if (OpensslEcGroupGetCurveName(ecGroup) == NID_secp256k1) { if (BigNumToBigIntegerSecp256k1(a, &(returnCommonParamSpec->paramsSpec.a)) != HCF_SUCCESS) { - LOGE("Build Secp256k1CommonParamSpec a failed."); + LOGE_ONE_STR("Build Secp256k1CommonParamSpec a failed."); ret = HCF_ERR_CRYPTO_OPERATION; break; } } else { if (BigNumToBigInteger(a, &(returnCommonParamSpec->paramsSpec.a)) != HCF_SUCCESS) { - LOGE("Build commonParamSpec a failed."); + LOGE_ONE_STR("Build commonParamSpec a failed."); ret = HCF_ERR_CRYPTO_OPERATION; break; } } if (BigNumToBigInteger(b, &(returnCommonParamSpec->paramsSpec.b)) != HCF_SUCCESS) { - LOGE("Build commonParamSpec b failed."); + LOGE_ONE_STR("Build commonParamSpec b failed."); ret = HCF_ERR_CRYPTO_OPERATION; break; } HcfECFieldFp *tmpField = (HcfECFieldFp *)(returnCommonParamSpec->paramsSpec.field); if (BigNumToBigInteger(p, &(tmpField->p)) != HCF_SUCCESS) { - LOGE("Build commonParamSpec p failed."); + LOGE_ONE_STR("Build commonParamSpec p failed."); ret = HCF_ERR_CRYPTO_OPERATION; break; } @@ -148,20 +148,20 @@ static HcfResult BuildCommonParamGFp(const EC_GROUP *ecGroup, HcfEccCommParamsSp static HcfResult BuildCommonParam(const EC_GROUP *ecGroup, HcfEccCommParamsSpecSpi *returnCommonParamSpec) { if (BuildCommonParamPart(ecGroup, returnCommonParamSpec)!= HCF_SUCCESS) { - LOGE("BuildCommonParamPartOne failed."); + LOGE_ONE_STR("BuildCommonParamPartOne failed."); return HCF_ERR_CRYPTO_OPERATION; } if (BuildCommonParamGFp(ecGroup, returnCommonParamSpec)!= HCF_SUCCESS) { - LOGE("BuildCommonParamGFp failed."); + LOGE_ONE_STR("BuildCommonParamGFp failed."); return HCF_ERR_CRYPTO_OPERATION; } if (GetOrder(ecGroup, &(returnCommonParamSpec->paramsSpec.n)) != HCF_SUCCESS) { - LOGE("Failed to get curve order data."); + LOGE_ONE_STR("Failed to get curve order data."); return HCF_ERR_CRYPTO_OPERATION; } if (GetCofactor(ecGroup, &(returnCommonParamSpec->paramsSpec.h)) != HCF_SUCCESS) { - LOGE("Failed to get curve cofactor data."); + LOGE_ONE_STR("Failed to get curve cofactor data."); return HCF_ERR_CRYPTO_OPERATION; } return HCF_SUCCESS; @@ -171,33 +171,33 @@ static HcfEccCommParamsSpecSpi *BuildEccCommonParamObject(void) { HcfEccCommParamsSpecSpi *spi = (HcfEccCommParamsSpecSpi*)HcfMalloc(sizeof(HcfEccCommParamsSpecSpi), 0); if (spi == NULL) { - LOGE("failed to build ecc commonParam object."); + LOGE_ONE_STR("failed to build ecc commonParam object."); return NULL; } spi->paramsSpec.field = (HcfECField *)HcfMalloc(sizeof(HcfECFieldFp), 0); if (spi->paramsSpec.field == NULL) { - LOGE("field malloc failed."); + LOGE_ONE_STR("field malloc failed."); HcfFree(spi); return NULL; } char *fieldType = "Fp"; size_t srcFieldTypeLen = HcfStrlen(fieldType); if (srcFieldTypeLen == 0) { - LOGE("fieldType is empty!"); + LOGE_ONE_STR("fieldType is empty!"); HcfFree(spi->paramsSpec.field); HcfFree(spi); return NULL; } spi->paramsSpec.field->fieldType = (char *)HcfMalloc(srcFieldTypeLen + 1, 0); if (spi->paramsSpec.field->fieldType == NULL) { - LOGE("fieldType malloc failed."); + LOGE_ONE_STR("fieldType malloc failed."); HcfFree(spi->paramsSpec.field); HcfFree(spi); return NULL; } if (memcpy_s(spi->paramsSpec.field->fieldType, srcFieldTypeLen, fieldType, srcFieldTypeLen) != EOK) { - LOGE("memcpy fieldType failed."); + LOGE_ONE_STR("memcpy fieldType failed."); HcfFree(spi->paramsSpec.field->fieldType); HcfFree(spi->paramsSpec.field); HcfFree(spi); @@ -209,7 +209,7 @@ static HcfEccCommParamsSpecSpi *BuildEccCommonParamObject(void) static void FreeEccCommParamObject(HcfEccCommParamsSpecSpi *spec) { if (spec == NULL) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return; } HcfFree(spec->paramsSpec.base.algName); @@ -239,37 +239,37 @@ static void FreeEccCommParamObject(HcfEccCommParamsSpecSpi *spec) HcfResult HcfECCCommonParamSpecCreate(HcfAsyKeyGenParams *params, HcfEccCommParamsSpecSpi **returnCommonParamSpec) { if ((params == NULL) || (returnCommonParamSpec == NULL)) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return HCF_INVALID_PARAMS; } int32_t curveId = 0; if (params->bits != 0) { if (GetOpensslCurveId(params->bits, &curveId) != HCF_SUCCESS) { - LOGE("Get curveId parameter failed."); + LOGE_ONE_STR("Get curveId parameter failed."); return HCF_INVALID_PARAMS; } } EC_GROUP *ecGroup = OpensslEcGroupNewByCurveName(curveId); if (ecGroup == NULL) { - LOGE("Create ecGroup failed."); + LOGE_ONE_STR("Create ecGroup failed."); return HCF_ERR_CRYPTO_OPERATION; } HcfEccCommParamsSpecSpi *object = BuildEccCommonParamObject(); if (object == NULL) { - LOGE("Build ecc common params object failed."); + LOGE_ONE_STR("Build ecc common params object failed."); OpensslEcGroupFree(ecGroup); return HCF_ERR_MALLOC; } object->paramsSpec.base.specType = HCF_COMMON_PARAMS_SPEC; if (GetAlgNameByBits(params->bits, &(object->paramsSpec.base.algName)) != HCF_SUCCESS) { - LOGE("Get algName parameter by bits failed."); + LOGE_ONE_STR("Get algName parameter by bits failed."); FreeEccCommParamObject(object); object = NULL; OpensslEcGroupFree(ecGroup); return HCF_INVALID_PARAMS; } if (BuildCommonParam(ecGroup, object)!= HCF_SUCCESS) { - LOGE("Get common params failed."); + LOGE_ONE_STR("Get common params failed."); FreeEccCommParamObject(object); object = NULL; OpensslEcGroupFree(ecGroup); @@ -285,7 +285,7 @@ static HcfResult InitEccPoint(const int32_t curveNameValue, EC_GROUP **ecGroup, { int32_t nid = 0; if (GetNidByCurveNameValue(curveNameValue, &nid) != HCF_SUCCESS) { - LOGE("Failed to get curveNameValue."); + LOGE_ONE_STR("Failed to get curveNameValue."); return HCF_INVALID_PARAMS; } *ecGroup = OpensslEcGroupNewByCurveName(nid); @@ -295,7 +295,7 @@ static HcfResult InitEccPoint(const int32_t curveNameValue, EC_GROUP **ecGroup, } *ecPoint = OpensslEcPointNew(*ecGroup); if (*ecPoint == NULL) { - LOGE("Failed to allocate memory for EC_POINT."); + LOGE_ONE_STR("Failed to allocate memory for EC_POINT."); OpensslEcGroupFree(*ecGroup); *ecGroup = NULL; return HCF_ERR_CRYPTO_OPERATION; @@ -303,7 +303,7 @@ static HcfResult InitEccPoint(const int32_t curveNameValue, EC_GROUP **ecGroup, if (x != NULL) { *x = OpensslBnNew(); if (*x == NULL) { - LOGE("Failed to allocate memory for BIGNUM x."); + LOGE_ONE_STR("Failed to allocate memory for BIGNUM x."); OpensslEcGroupFree(*ecGroup); *ecGroup = NULL; OpensslEcPointFree(*ecPoint); @@ -314,7 +314,7 @@ static HcfResult InitEccPoint(const int32_t curveNameValue, EC_GROUP **ecGroup, if (y != NULL) { *y = OpensslBnNew(); if (*y == NULL) { - LOGE("Failed to allocate memory for BIGNUM y."); + LOGE_ONE_STR("Failed to allocate memory for BIGNUM y."); OpensslBnFree(*x); *x = NULL; OpensslEcGroupFree(*ecGroup); @@ -339,12 +339,12 @@ static HcfResult ConvertBigNumToEccPoint(const BIGNUM *x, const BIGNUM *y, { HcfResult ret = BigNumToBigInteger(x, bigIntX); if (ret != HCF_SUCCESS) { - LOGE("Failed to convert XBIGNUM to HcfBigInteger."); + LOGE_ONE_STR("Failed to convert XBIGNUM to HcfBigInteger."); return ret; } ret = BigNumToBigInteger(y, bigIntY); if (ret != HCF_SUCCESS) { - LOGE("Failed to convert YBIGNUM to HcfBigInteger."); + LOGE_ONE_STR("Failed to convert YBIGNUM to HcfBigInteger."); FreeHcfBigInteger(bigIntX); return ret; } @@ -356,25 +356,25 @@ static HcfResult GetECCPointEncoded(const int32_t formatValue, EC_GROUP *ecGroup { int32_t formatType = 0; if (GetFormatTypeByFormatValue(formatValue, &formatType) != HCF_SUCCESS) { - LOGE("Failed to get formatType."); + LOGE_ONE_STR("Failed to get formatType."); return HCF_INVALID_PARAMS; } size_t returnDataLen = EC_POINT_point2oct(ecGroup, ecPoint, formatType, NULL, 0, NULL); if (returnDataLen == 0) { - LOGE("Failed to get encoded point length."); + LOGE_ONE_STR("Failed to get encoded point length."); HcfPrintOpensslError(); return HCF_ERR_CRYPTO_OPERATION; } uint8_t *returnData = (uint8_t *)HcfMalloc(returnDataLen, 0); if (returnData == NULL) { - LOGE("Failed to allocate memory for encoded point data."); + LOGE_ONE_STR("Failed to allocate memory for encoded point data."); return HCF_ERR_MALLOC; } size_t result = EC_POINT_point2oct(ecGroup, ecPoint, formatType, returnData, returnDataLen, NULL); if (result != returnDataLen) { - LOGE("Failed to get ECC point encoding."); + LOGE_ONE_STR("Failed to get ECC point encoding."); HcfPrintOpensslError(); HcfFree(returnData); return HCF_ERR_CRYPTO_OPERATION; @@ -387,7 +387,7 @@ static HcfResult GetECCPointEncoded(const int32_t formatValue, EC_GROUP *ecGroup HcfResult HcfEngineConvertPoint(const int32_t curveNameValue, HcfBlob *pointBlob, HcfPoint *returnPoint) { if ((curveNameValue == 0) || !HcfIsBlobValid(pointBlob) || (returnPoint == NULL)) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return HCF_INVALID_PARAMS; } EC_GROUP *ecGroup = NULL; @@ -400,23 +400,23 @@ HcfResult HcfEngineConvertPoint(const int32_t curveNameValue, HcfBlob *pointBlob do { ret = InitEccPoint(curveNameValue, &ecGroup, &ecPoint, &x, &y); if (ret != HCF_SUCCESS) { - LOGE("Failed to get EccPoint."); + LOGE_ONE_STR("Failed to get EccPoint."); break; } if (!OpensslEcOct2Point(ecGroup, ecPoint, pointBlob->data, pointBlob->len, NULL)) { - LOGE("Failed to convert pointBlob data to EC_POINT."); + LOGE_ONE_STR("Failed to convert pointBlob data to EC_POINT."); HcfPrintOpensslError(); ret = HCF_ERR_CRYPTO_OPERATION; break; } if (!OpensslEcPointGetAffineCoordinates(ecGroup, ecPoint, x, y, NULL)) { - LOGE("Failed to get affine coordinates from EC_POINT."); + LOGE_ONE_STR("Failed to get affine coordinates from EC_POINT."); ret = HCF_ERR_CRYPTO_OPERATION; break; } ret = ConvertBigNumToEccPoint(x, y, &tmpBigIntX, &tmpBigIntY); if (ret != HCF_SUCCESS) { - LOGE("Failed to convert BIGNUMs to HcfBigIntegers."); + LOGE_ONE_STR("Failed to convert BIGNUMs to HcfBigIntegers."); break; } returnPoint->x = tmpBigIntX; @@ -433,7 +433,7 @@ HcfResult HcfEngineGetEncodedPoint(const int32_t curveNameValue, HcfPoint *point const int32_t formatValue, HcfBlob *returnBlob) { if ((curveNameValue == 0) || (point == NULL) || (formatValue == 0) || (returnBlob == NULL)) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return HCF_INVALID_PARAMS; } EC_GROUP *ecGroup = NULL; @@ -444,28 +444,28 @@ HcfResult HcfEngineGetEncodedPoint(const int32_t curveNameValue, HcfPoint *point do { ret = InitEccPoint(curveNameValue, &ecGroup, &ecPoint, NULL, NULL); if (ret != HCF_SUCCESS) { - LOGE("Failed to get EccPoint."); + LOGE_ONE_STR("Failed to get EccPoint."); break; } ret = BigIntegerToBigNum(&(point->x), &bnX); if (ret != HCF_SUCCESS) { - LOGE("Failed to convert HcfBigInteger to XBIGNUMs."); + LOGE_ONE_STR("Failed to convert HcfBigInteger to XBIGNUMs."); break; } ret = BigIntegerToBigNum(&(point->y), &bnY); if (ret != HCF_SUCCESS) { - LOGE("Failed to convert HcfBigInteger to YBIGNUMs."); + LOGE_ONE_STR("Failed to convert HcfBigInteger to YBIGNUMs."); break; } if (OpensslEcPointSetAffineCoordinates(ecGroup, ecPoint, bnX, bnY, NULL) != HCF_OPENSSL_SUCCESS) { - LOGE("Failed to set point coordinates."); + LOGE_ONE_STR("Failed to set point coordinates."); HcfPrintOpensslError(); ret = HCF_ERR_CRYPTO_OPERATION; break; } ret = GetECCPointEncoded(formatValue, ecGroup, ecPoint, returnBlob); if (ret != HCF_SUCCESS) { - LOGE("Failed to get EccPointEncoded."); + LOGE_ONE_STR("Failed to get EccPointEncoded."); break; } } while (0); diff --git a/plugin/openssl_plugin/key/asy_key_generator/src/rsa_asy_key_generator_openssl.c b/plugin/openssl_plugin/key/asy_key_generator/src/rsa_asy_key_generator_openssl.c index 7087ca018b8b74ba1559ad5b07a5170e2927c15c..d8b20fc146418224eaeef68ef8a1582c7a0f593e 100644 --- a/plugin/openssl_plugin/key/asy_key_generator/src/rsa_asy_key_generator_openssl.c +++ b/plugin/openssl_plugin/key/asy_key_generator/src/rsa_asy_key_generator_openssl.c @@ -150,7 +150,7 @@ static HcfResult GetRsaPubKeySpecString(const HcfPubKey *self, const AsyKeySpecI { (void)self; (void)returnString; - LOGE("Rsa has no string attribute"); + LOGE_ONE_STR("Rsa has no string attribute"); return HCF_NOT_SUPPORT; } @@ -159,7 +159,7 @@ static HcfResult GetRsaPubKeySpecInt(const HcfPubKey *self, const AsyKeySpecItem { (void)self; (void)returnInt; - LOGE("Rsa has no integer attribute"); + LOGE_ONE_STR("Rsa has no integer attribute"); return HCF_NOT_SUPPORT; } @@ -168,7 +168,7 @@ static HcfResult GetRsaPriKeySpecString(const HcfPriKey *self, const AsyKeySpecI { (void)self; (void)returnString; - LOGE("Rsa has no string attribute"); + LOGE_ONE_STR("Rsa has no string attribute"); return HCF_NOT_SUPPORT; } @@ -177,7 +177,7 @@ static HcfResult GetRsaPriKeySpecInt(const HcfPriKey *self, const AsyKeySpecItem { (void)self; (void)returnInt; - LOGE("Rsa has no integer attribute"); + LOGE_ONE_STR("Rsa has no integer attribute"); return HCF_NOT_SUPPORT; } static HcfResult GetRsaPriKeyEncodedDer(const HcfPriKey *self, const char *format, HcfBlob *returnBlob) @@ -192,43 +192,43 @@ static HcfResult GetRsaPriKeySpecBigInteger(const HcfPriKey *self, const AsyKeyS HcfBigInteger *returnBigInteger) { if (self == NULL || returnBigInteger == NULL) { - LOGE("Input params is invalid."); + LOGE_ONE_STR("Input params is invalid."); return HCF_INVALID_PARAMS; } if (!HcfIsClassMatch((HcfObjectBase *)self, OPENSSL_RSA_PRIKEY_CLASS)) { - LOGE("Class not match"); + LOGE_ONE_STR("Class not match"); return HCF_INVALID_PARAMS; } HcfOpensslRsaPriKey *impl = (HcfOpensslRsaPriKey *)self; if (impl->sk == NULL) { - LOGE("Cannot use priKey after free"); + LOGE_ONE_STR("Cannot use priKey after free"); return HCF_INVALID_PARAMS; } HcfResult ret = HCF_INVALID_PARAMS; if (item == RSA_N_BN) { const BIGNUM *n = OpensslRsaGet0N(impl->sk); if (n == NULL) { - LOGD("[error] fail to get n"); + LOGD_ONE_STR("[error] fail to get n"); return HCF_ERR_CRYPTO_OPERATION; } ret = BigNumToBigInteger(n, returnBigInteger); if (ret != HCF_SUCCESS) { - LOGD("[error] fail get RSA Big Integer n"); + LOGD_ONE_STR("[error] fail get RSA Big Integer n"); return ret; } } else if (item == RSA_SK_BN) { const BIGNUM *d = OpensslRsaGet0D(impl->sk); if (d == NULL) { - LOGD("[error] fail to get sk"); + LOGD_ONE_STR("[error] fail to get sk"); return HCF_ERR_CRYPTO_OPERATION; } ret = BigNumToBigInteger(d, returnBigInteger); if (ret != HCF_SUCCESS) { - LOGE("fail get RSA Big Integer d"); + LOGE_ONE_STR("fail get RSA Big Integer d"); return ret; } } else { - LOGE("Invalid RSA pri key spec"); + LOGE_ONE_STR("Invalid RSA pri key spec"); return HCF_INVALID_PARAMS; } return ret; @@ -238,11 +238,11 @@ static HcfResult GetRsaPubKeySpecBigInteger(const HcfPubKey *self, const AsyKeyS HcfBigInteger *returnBigInteger) { if (self == NULL || returnBigInteger == NULL) { - LOGE("Input params is invalid."); + LOGE_ONE_STR("Input params is invalid."); return HCF_INVALID_PARAMS; } if (!HcfIsClassMatch((HcfObjectBase *)self, OPENSSL_RSA_PUBKEY_CLASS)) { - LOGE("Class not match"); + LOGE_ONE_STR("Class not match"); return HCF_INVALID_PARAMS; } HcfOpensslRsaPubKey *impl = (HcfOpensslRsaPubKey *)self; @@ -250,27 +250,27 @@ static HcfResult GetRsaPubKeySpecBigInteger(const HcfPubKey *self, const AsyKeyS if (item == RSA_N_BN) { const BIGNUM *n = OpensslRsaGet0N(impl->pk); if (n == NULL) { - LOGD("[error] fail to get n"); + LOGD_ONE_STR("[error] fail to get n"); return HCF_ERR_CRYPTO_OPERATION; } ret = BigNumToBigInteger(n, returnBigInteger); if (ret != HCF_SUCCESS) { - LOGE("fail get RSA Big Integer n"); + LOGE_ONE_STR("fail get RSA Big Integer n"); return ret; } } else if (item == RSA_PK_BN) { const BIGNUM *e = OpensslRsaGet0E(impl->pk); if (e == NULL) { - LOGD("[error] fail to get pk"); + LOGD_ONE_STR("[error] fail to get pk"); return HCF_ERR_CRYPTO_OPERATION; } ret = BigNumToBigInteger(e, returnBigInteger); if (ret != HCF_SUCCESS) { - LOGE("fail get RSA Big Integer e"); + LOGE_ONE_STR("fail get RSA Big Integer e"); return ret; } } else { - LOGE("Invalid RSA pub key spec"); + LOGE_ONE_STR("Invalid RSA pub key spec"); return HCF_INVALID_PARAMS; } return ret; @@ -279,11 +279,11 @@ static HcfResult GetRsaPubKeySpecBigInteger(const HcfPubKey *self, const AsyKeyS static void DestroyPubKey(HcfObjectBase *self) { if (self == NULL) { - LOGE("PubKey is NULL."); + LOGE_ONE_STR("PubKey is NULL."); return; } if (!HcfIsClassMatch(self, OPENSSL_RSA_PUBKEY_CLASS)) { - LOGE("Class not match"); + LOGE_ONE_STR("Class not match"); return; } HcfOpensslRsaPubKey *impl = (HcfOpensslRsaPubKey *)self; @@ -295,11 +295,11 @@ static void DestroyPubKey(HcfObjectBase *self) static void DestroyPriKey(HcfObjectBase *self) { if (self == NULL) { - LOGE("PubKey is NULL."); + LOGE_ONE_STR("PubKey is NULL."); return; } if (!HcfIsClassMatch(self, OPENSSL_RSA_PRIKEY_CLASS)) { - LOGE("Class not match"); + LOGE_ONE_STR("Class not match"); return; } HcfOpensslRsaPriKey *impl = (HcfOpensslRsaPriKey*)self; @@ -312,11 +312,11 @@ static void DestroyPriKey(HcfObjectBase *self) static void DestroyKeyPair(HcfObjectBase *self) { if (self == NULL) { - LOGE("PubKey is NULL."); + LOGE_ONE_STR("PubKey is NULL."); return; } if (!HcfIsClassMatch(self, OPENSSL_RSA_KEYPAIR_CLASS)) { - LOGE("Class not match"); + LOGE_ONE_STR("Class not match"); return; } HcfOpensslRsaKeyPair *impl = (HcfOpensslRsaKeyPair*)self; @@ -334,23 +334,23 @@ static void DestroyKeyPair(HcfObjectBase *self) static HcfResult CopyMemFromBIO(BIO *bio, HcfBlob *outBlob) { if (bio == NULL || outBlob == NULL) { - LOGE("Invalid input."); + LOGE_ONE_STR("Invalid input."); return HCF_INVALID_PARAMS; } int len = BIO_pending(bio); if (len < 0) { - LOGE("Bio len less than 0."); + LOGE_ONE_STR("Bio len less than 0."); return HCF_INVALID_PARAMS; } HcfBlob blob; blob.len = len; blob.data = (uint8_t *)HcfMalloc(sizeof(uint8_t) * len, 0); if (blob.data == NULL) { - LOGE("Malloc mem for blob fail."); + LOGE_ONE_STR("Malloc mem for blob fail."); return HCF_ERR_MALLOC; } if (OpensslBioRead(bio, blob.data, blob.len) <= 0) { - LOGD("[error] Bio read fail"); + LOGD_ONE_STR("[error] Bio read fail"); HcfPrintOpensslError(); HcfFree(blob.data); return HCF_ERR_CRYPTO_OPERATION; @@ -363,21 +363,21 @@ static HcfResult CopyMemFromBIO(BIO *bio, HcfBlob *outBlob) static HcfResult CopyStrFromBIO(BIO *bio, char **returnString) { if (bio == NULL || returnString == NULL) { - LOGE("Invalid input."); + LOGE_ONE_STR("Invalid input."); return HCF_INVALID_PARAMS; } int len = BIO_pending(bio); if (len < 0) { - LOGE("Bio len less than 0."); + LOGE_ONE_STR("Bio len less than 0."); return HCF_INVALID_PARAMS; } *returnString = (char *)HcfMalloc(len + 1, 0); if (*returnString == NULL) { - LOGE("Malloc mem for blob fail."); + LOGE_ONE_STR("Malloc mem for blob fail."); return HCF_ERR_MALLOC; } if (OpensslBioRead(bio, *returnString, len) <= 0) { - LOGE("Bio read fail"); + LOGE_ONE_STR("Bio read fail"); HcfPrintOpensslError(); HcfFree(*returnString); *returnString = NULL; @@ -391,7 +391,7 @@ static HcfResult ConvertPubKeyFromX509(HcfBlob *x509Blob, RSA **rsa) uint8_t *temp = x509Blob->data; RSA *tempRsa = OpensslD2iRsaPubKey(NULL, (const unsigned char **)&temp, x509Blob->len); if (tempRsa == NULL) { - LOGD("[error] d2i_RSA_PUBKEY fail."); + LOGD_ONE_STR("[error] d2i_RSA_PUBKEY fail."); return HCF_ERR_CRYPTO_OPERATION; } *rsa = tempRsa; @@ -403,13 +403,13 @@ static HcfResult ConvertPriKeyFromPKCS8(HcfBlob *pkcs8Blob, RSA **rsa) const unsigned char *temp = (const unsigned char *)pkcs8Blob->data; EVP_PKEY *pKey = OpensslD2iAutoPrivateKey(NULL, &temp, pkcs8Blob->len); if (pKey == NULL) { - LOGD("[error] d2i_AutoPrivateKey fail."); + LOGD_ONE_STR("[error] d2i_AutoPrivateKey fail."); HcfPrintOpensslError(); return HCF_ERR_CRYPTO_OPERATION; } RSA *tmpRsa = OpensslEvpPkeyGet1Rsa(pKey); if (tmpRsa == NULL) { - LOGD("[error] EVP_PKEY_get1_RSA fail"); + LOGD_ONE_STR("[error] EVP_PKEY_get1_RSA fail"); HcfPrintOpensslError(); OpensslEvpPkeyFree(pKey); return HCF_ERR_CRYPTO_OPERATION; @@ -424,7 +424,7 @@ static HcfResult EncodePubKeyToX509(RSA *rsa, HcfBlob *returnBlob) unsigned char *tempData = NULL; int len = OpensslI2dRsaPubKey(rsa, &tempData); if (len <= 0) { - LOGD("[error] i2d_RSA_PUBKEY fail"); + LOGD_ONE_STR("[error] i2d_RSA_PUBKEY fail"); HcfPrintOpensslError(); return HCF_ERR_CRYPTO_OPERATION; } @@ -437,25 +437,25 @@ static HcfResult EncodePriKeyToPKCS8(RSA *rsa, HcfBlob *returnBlob) { EVP_PKEY *pKey = NewEvpPkeyByRsa(rsa, true); if (pKey == NULL) { - LOGD("[error] NewEvpPkeyByRsa fail."); + LOGD_ONE_STR("[error] NewEvpPkeyByRsa fail."); return HCF_ERR_CRYPTO_OPERATION; } HcfResult ret = HCF_SUCCESS; BIO *bio = OpensslBioNew(OpensslBioSMem()); if (bio == NULL) { - LOGD("[error] BIO new fail."); + LOGD_ONE_STR("[error] BIO new fail."); HcfPrintOpensslError(); ret = HCF_ERR_CRYPTO_OPERATION; goto ERR2; } if (i2d_PKCS8PrivateKey_bio(bio, pKey, NULL, NULL, 0, NULL, NULL) != HCF_OPENSSL_SUCCESS) { - LOGD("[error] i2b_PrivateKey_bio fail."); + LOGD_ONE_STR("[error] i2b_PrivateKey_bio fail."); HcfPrintOpensslError(); ret = HCF_ERR_CRYPTO_OPERATION; goto ERR1; } if (CopyMemFromBIO(bio, returnBlob) != HCF_SUCCESS) { - LOGD("[error] CopyMemFromBIO fail."); + LOGD_ONE_STR("[error] CopyMemFromBIO fail."); ret = HCF_ERR_CRYPTO_OPERATION; goto ERR1; } @@ -469,11 +469,11 @@ ERR2: static HcfResult GetPubKeyEncoded(HcfKey *self, HcfBlob *returnBlob) { if (self == NULL || returnBlob == NULL) { - LOGE("Input params is invalid."); + LOGE_ONE_STR("Input params is invalid."); return HCF_INVALID_PARAMS; } if (!HcfIsClassMatch((HcfObjectBase *)self, OPENSSL_RSA_PUBKEY_CLASS)) { - LOGE("Class not match."); + LOGE_ONE_STR("Class not match."); return HCF_INVALID_PARAMS; } HcfOpensslRsaPubKey *impl = (HcfOpensslRsaPubKey *)self; @@ -484,19 +484,19 @@ static HcfResult GetPubKeyPkcs1Pem(RSA *pk, char **returnString) { BIO *bio = OpensslBioNew(OpensslBioSMem()); if (bio == NULL) { - LOGE("BIO new fail."); + LOGE_ONE_STR("BIO new fail."); HcfPrintOpensslError(); return HCF_ERR_CRYPTO_OPERATION; } int ret = OpensslPemWriteBioRsaPublicKey(bio, pk); if (ret != HCF_OPENSSL_SUCCESS) { - LOGE("OpensslPemWriteBioRsaPublicKey fail."); + LOGE_ONE_STR("OpensslPemWriteBioRsaPublicKey fail."); HcfPrintOpensslError(); OpensslBioFreeAll(bio); return HCF_ERR_CRYPTO_OPERATION; } if (CopyStrFromBIO(bio, returnString) != HCF_SUCCESS) { - LOGE("CopyMemFromBIO fail."); + LOGE_ONE_STR("CopyMemFromBIO fail."); OpensslBioFreeAll(bio); return HCF_ERR_CRYPTO_OPERATION; } @@ -508,19 +508,19 @@ static HcfResult GetPubKeyX509Pem(RSA *pk, char **returnString) { BIO *bio = OpensslBioNew(OpensslBioSMem()); if (bio == NULL) { - LOGE("BIO new fail."); + LOGE_ONE_STR("BIO new fail."); HcfPrintOpensslError(); return HCF_ERR_CRYPTO_OPERATION; } int ret = OpensslPemWriteBioRsaPubKey(bio, pk); if (ret != HCF_OPENSSL_SUCCESS) { - LOGE("OpensslPemWriteBioRsaPubKey fail."); + LOGE_ONE_STR("OpensslPemWriteBioRsaPubKey fail."); HcfPrintOpensslError(); OpensslBioFreeAll(bio); return HCF_ERR_CRYPTO_OPERATION; } if (CopyStrFromBIO(bio, returnString) != HCF_SUCCESS) { - LOGE("CopyMemFromBIO fail."); + LOGE_ONE_STR("CopyMemFromBIO fail."); OpensslBioFreeAll(bio); return HCF_ERR_CRYPTO_OPERATION; } @@ -550,11 +550,11 @@ static HcfResult GetPubKeyPem(const char *format, RSA *pk, char **returnString) static HcfResult GetPubKeyEncodedPem(HcfKey *self, const char *format, char **returnString) { if (self == NULL || format == NULL|| returnString == NULL) { - LOGE("param is null."); + LOGE_ONE_STR("param is null."); return HCF_INVALID_PARAMS; } if (!HcfIsClassMatch((HcfObjectBase *)self, OPENSSL_RSA_PUBKEY_CLASS)) { - LOGE("Class not match."); + LOGE_ONE_STR("Class not match."); return HCF_INVALID_PARAMS; } const char *outPutStruct = NULL; @@ -563,20 +563,20 @@ static HcfResult GetPubKeyEncodedPem(HcfKey *self, const char *format, char **re } else if (strcmp(format, "X509") == 0) { outPutStruct = "subjectPublicKeyInfo"; } else { - LOGE("format is invalid."); + LOGE_ONE_STR("format is invalid."); return HCF_INVALID_PARAMS; } HcfOpensslRsaPubKey *impl = (HcfOpensslRsaPubKey *)self; EVP_PKEY *pkey = NewEvpPkeyByRsa(impl->pk, true); if (pkey == NULL) { - LOGE("NewEvpPkeyByRsa failed."); + LOGE_ONE_STR("NewEvpPkeyByRsa failed."); return HCF_ERR_CRYPTO_OPERATION; } HcfResult result = GetKeyEncodedPem(pkey, outPutStruct, EVP_PKEY_PUBLIC_KEY, returnString); OpensslEvpPkeyFree(pkey); if (result != HCF_SUCCESS) { if (GetPubKeyPem(format, impl->pk, returnString) != HCF_SUCCESS) { - LOGE("GetPubKeyPem failed."); + LOGE_ONE_STR("GetPubKeyPem failed."); return HCF_ERR_CRYPTO_OPERATION; } } @@ -586,12 +586,12 @@ static HcfResult GetPubKeyEncodedPem(HcfKey *self, const char *format, char **re static HcfResult GetPriKeyEncoded(HcfKey *self, HcfBlob *returnBlob) { if (self == NULL || returnBlob == NULL) { - LOGE("Key is null."); + LOGE_ONE_STR("Key is null."); return HCF_INVALID_PARAMS; } if (!HcfIsClassMatch((HcfObjectBase *)self, OPENSSL_RSA_PRIKEY_CLASS)) { - LOGE("Class not match."); + LOGE_ONE_STR("Class not match."); return HCF_INVALID_PARAMS; } HcfOpensslRsaPriKey *impl = (HcfOpensslRsaPriKey *)self; @@ -599,7 +599,7 @@ static HcfResult GetPriKeyEncoded(HcfKey *self, HcfBlob *returnBlob) const BIGNUM *q = NULL; OpensslRsaGet0Factors(impl->sk, &p, &q); if (p == NULL || q == NULL) { - LOGD("[error] RSA private key missing p, q, not support to get encoded PK"); + LOGD_ONE_STR("[error] RSA private key missing p, q, not support to get encoded PK"); return HCF_NOT_SUPPORT; } return EncodePriKeyToPKCS8(impl->sk, returnBlob); @@ -609,7 +609,7 @@ static HcfResult GetPrikeyPkcs8Pem(EVP_PKEY *pkey, const EVP_CIPHER *cipher, con { BIO *bio = OpensslBioNew(OpensslBioSMem()); if (bio == NULL) { - LOGE("BIO new fail."); + LOGE_ONE_STR("BIO new fail."); HcfPrintOpensslError(); return HCF_ERR_CRYPTO_OPERATION; } @@ -621,13 +621,13 @@ static HcfResult GetPrikeyPkcs8Pem(EVP_PKEY *pkey, const EVP_CIPHER *cipher, con int ret = PEM_write_bio_PKCS8PrivateKey(bio, pkey, cipher, passWord, passLen, NULL, NULL); if (ret != HCF_OPENSSL_SUCCESS) { - LOGE("OpensslPemWriteBioPkcs8PrivateKey fail."); + LOGE_ONE_STR("OpensslPemWriteBioPkcs8PrivateKey fail."); HcfPrintOpensslError(); OpensslBioFreeAll(bio); return HCF_ERR_CRYPTO_OPERATION; } if (CopyStrFromBIO(bio, returnString) != HCF_SUCCESS) { - LOGE("CopyMemFromBIO fail."); + LOGE_ONE_STR("CopyMemFromBIO fail."); OpensslBioFreeAll(bio); return HCF_ERR_CRYPTO_OPERATION; } @@ -639,7 +639,7 @@ static HcfResult GetPrikeyPkcs1Pem(EVP_PKEY *pkey, const EVP_CIPHER *cipher, con { BIO *bio = OpensslBioNew(OpensslBioSMem()); if (bio == NULL) { - LOGE("BIO new fail."); + LOGE_ONE_STR("BIO new fail."); HcfPrintOpensslError(); return HCF_ERR_CRYPTO_OPERATION; } @@ -651,13 +651,13 @@ static HcfResult GetPrikeyPkcs1Pem(EVP_PKEY *pkey, const EVP_CIPHER *cipher, con int ret = PEM_write_bio_PrivateKey_traditional(bio, pkey, cipher, (unsigned char *)passWord, passLen, NULL, NULL); if (ret != HCF_OPENSSL_SUCCESS) { - LOGE("OpensslPemWriteBioRsaPrivateKey fail."); + LOGE_ONE_STR("OpensslPemWriteBioRsaPrivateKey fail."); HcfPrintOpensslError(); OpensslBioFreeAll(bio); return HCF_ERR_CRYPTO_OPERATION; } if (CopyStrFromBIO(bio, returnString) != HCF_SUCCESS) { - LOGE("CopyStrFromBIO fail."); + LOGE_ONE_STR("CopyStrFromBIO fail."); OpensslBioFreeAll(bio); return HCF_ERR_CRYPTO_OPERATION; } @@ -680,7 +680,7 @@ static HcfResult GetPriKeyPem(const char *format, EVP_PKEY *pkey, const EVP_CIPH return result; } } else { - LOGE("format is invalid."); + LOGE_ONE_STR("format is invalid."); return HCF_INVALID_PARAMS; } return HCF_SUCCESS; @@ -689,11 +689,11 @@ static HcfResult GetPriKeyPem(const char *format, EVP_PKEY *pkey, const EVP_CIPH static HcfResult ValidateInputParams(const HcfPriKey *self, const char *format, char **returnString) { if (self == NULL || format == NULL || returnString == NULL) { - LOGE("param is null."); + LOGE_ONE_STR("param is null."); return HCF_INVALID_PARAMS; } if (!HcfIsClassMatch((HcfObjectBase *)self, OPENSSL_RSA_PRIKEY_CLASS)) { - LOGE("Class not match."); + LOGE_ONE_STR("Class not match."); return HCF_INVALID_PARAMS; } return HCF_SUCCESS; @@ -710,7 +710,7 @@ static HcfResult GetPriKeyEncodedPem(const HcfPriKey *self, HcfParamsSpec *param HcfOpensslRsaPriKey *impl = (HcfOpensslRsaPriKey *)self; EVP_PKEY *pkey = NewEvpPkeyByRsa(impl->sk, true); if (pkey == NULL) { - LOGE("NewEvpPkeyByRsa failed."); + LOGE_ONE_STR("NewEvpPkeyByRsa failed."); return HCF_ERR_CRYPTO_OPERATION; } @@ -733,7 +733,7 @@ static HcfResult GetPriKeyEncodedPem(const HcfPriKey *self, HcfParamsSpec *param } if (result != HCF_SUCCESS) { - LOGE("GetPriKeyPem failed."); + LOGE_ONE_STR("GetPriKeyPem failed."); OpensslEvpPkeyFree(pkey); return result; } @@ -744,7 +744,7 @@ static HcfResult GetPriKeyEncodedPem(const HcfPriKey *self, HcfParamsSpec *param static const char *GetPubKeyFormat(HcfKey *self) { if (self == NULL) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return NULL; } if (!HcfIsClassMatch((HcfObjectBase *)self, OPENSSL_RSA_PUBKEY_CLASS)) { @@ -756,7 +756,7 @@ static const char *GetPubKeyFormat(HcfKey *self) static const char *GetPriKeyFormat(HcfKey *self) { if (self == NULL) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return NULL; } if (!HcfIsClassMatch((HcfObjectBase *)self, OPENSSL_RSA_PRIKEY_CLASS)) { @@ -768,7 +768,7 @@ static const char *GetPriKeyFormat(HcfKey *self) static const char *GetPriKeyAlgorithm(HcfKey *self) { if (self == NULL) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return NULL; } if (!HcfIsClassMatch((HcfObjectBase *)self, OPENSSL_RSA_PRIKEY_CLASS)) { @@ -780,7 +780,7 @@ static const char *GetPriKeyAlgorithm(HcfKey *self) static const char *GetPubKeyAlgorithm(HcfKey *self) { if (self == NULL) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return NULL; } if (!HcfIsClassMatch((HcfObjectBase *)self, OPENSSL_RSA_PUBKEY_CLASS)) { @@ -792,11 +792,11 @@ static const char *GetPubKeyAlgorithm(HcfKey *self) static void ClearPriKeyMem(HcfPriKey *self) { if (self == NULL) { - LOGE("PriKey is NULL."); + LOGE_ONE_STR("PriKey is NULL."); return; } if (!HcfIsClassMatch((HcfObjectBase *)self, OPENSSL_RSA_PRIKEY_CLASS)) { - LOGE("Class not match"); + LOGE_ONE_STR("Class not match"); return; } HcfOpensslRsaPriKey *impl = (HcfOpensslRsaPriKey *)self; @@ -815,12 +815,12 @@ static HcfResult GetRsaPubKeyEncodedDer(const HcfPubKey *self, const char *forma static HcfResult PackPubKey(RSA *rsaPubKey, HcfOpensslRsaPubKey **retPubKey) { if (retPubKey == NULL || rsaPubKey == NULL) { - LOGE("Invalid params"); + LOGE_ONE_STR("Invalid params"); return HCF_INVALID_PARAMS; } *retPubKey = (HcfOpensslRsaPubKey *)HcfMalloc(sizeof(HcfOpensslRsaPubKey), 0); if (*retPubKey == NULL) { - LOGE("Malloc retPubKey fail"); + LOGE_ONE_STR("Malloc retPubKey fail"); return HCF_ERR_MALLOC; } (*retPubKey)->pk = rsaPubKey; @@ -842,12 +842,12 @@ static HcfResult PackPubKey(RSA *rsaPubKey, HcfOpensslRsaPubKey **retPubKey) static HcfResult PackPriKey(RSA *rsaPriKey, HcfOpensslRsaPriKey **retPriKey) { if (retPriKey == NULL || rsaPriKey == NULL) { - LOGE("Invalid params"); + LOGE_ONE_STR("Invalid params"); return HCF_INVALID_PARAMS; } *retPriKey = (HcfOpensslRsaPriKey *)HcfMalloc(sizeof(HcfOpensslRsaPriKey), 0); if (*retPriKey == NULL) { - LOGE("Malloc retPriKey fail"); + LOGE_ONE_STR("Malloc retPriKey fail"); return HCF_ERR_MALLOC; } (*retPriKey)->sk = rsaPriKey; @@ -869,15 +869,15 @@ static HcfResult PackPriKey(RSA *rsaPriKey, HcfOpensslRsaPriKey **retPriKey) static HcfResult DuplicatePkAndSkFromRSA(RSA *rsa, RSA **pubKey, RSA **priKey) { if (rsa == NULL) { - LOGE("Rsa is NULL."); + LOGE_ONE_STR("Rsa is NULL."); return HCF_INVALID_PARAMS; } if (DuplicateRsa(rsa, false, pubKey) != HCF_SUCCESS) { - LOGD("[error] Duplicate pubkey rsa fail"); + LOGD_ONE_STR("[error] Duplicate pubkey rsa fail"); return HCF_ERR_CRYPTO_OPERATION; } if (DuplicateRsa(rsa, true, priKey) != HCF_SUCCESS) { - LOGD("[error] Duplicate prikey rsa fail"); + LOGD_ONE_STR("[error] Duplicate prikey rsa fail"); OpensslRsaFree(*pubKey); *pubKey = NULL; return HCF_ERR_CRYPTO_OPERATION; @@ -888,19 +888,19 @@ static HcfResult DuplicatePkAndSkFromRSA(RSA *rsa, RSA **pubKey, RSA **priKey) static HcfResult PackKeyPair(RSA *rsa, uint32_t realBits, HcfOpensslRsaKeyPair **retKeyPair) { if (retKeyPair == NULL || rsa == NULL) { - LOGE("Invalid params"); + LOGE_ONE_STR("Invalid params"); return HCF_INVALID_PARAMS; } RSA *pubKey = NULL; RSA *priKey = NULL; if (DuplicatePkAndSkFromRSA(rsa, &pubKey, &priKey) != HCF_SUCCESS) { - LOGD("[error] DuplicatePkAndSkFromRSA fail"); + LOGD_ONE_STR("[error] DuplicatePkAndSkFromRSA fail"); return HCF_ERR_CRYPTO_OPERATION; } HcfResult ret = HCF_SUCCESS; *retKeyPair = (HcfOpensslRsaKeyPair *)HcfMalloc(sizeof(HcfOpensslRsaKeyPair), 0); if (*retKeyPair == NULL) { - LOGE("Malloc keypair fail"); + LOGE_ONE_STR("Malloc keypair fail"); OpensslRsaFree(pubKey); OpensslRsaFree(priKey); return HCF_ERR_MALLOC; @@ -909,12 +909,12 @@ static HcfResult PackKeyPair(RSA *rsa, uint32_t realBits, HcfOpensslRsaKeyPair * HcfOpensslRsaPubKey *pubKeyImpl = NULL; ret = PackPubKey(pubKey, &pubKeyImpl); if (ret != HCF_SUCCESS) { - LOGE("Pack pubKey fail."); + LOGE_ONE_STR("Pack pubKey fail."); goto ERR2; } ret = PackPriKey(priKey, &priKeyImpl); if (ret != HCF_SUCCESS) { - LOGE("Pack priKey fail."); + LOGE_ONE_STR("Pack priKey fail."); goto ERR1; } (*retKeyPair)->base.priKey = (HcfPriKey *)priKeyImpl; @@ -944,7 +944,7 @@ static int32_t GetRealPrimes(int32_t primesFlag) case OPENSSL_RSA_PRIMES_SIZE_5: return PRIMES_5; default: - LOGD("set default primes 2"); + LOGD_ONE_STR("set default primes 2"); return PRIMES_2; } } @@ -954,27 +954,27 @@ static HcfResult GenerateKeyPair(HcfAsyKeyGenSpiRsaParams *params, HcfKeyPair ** // check input params is valid HcfResult res = CheckRsaKeyGenParams(params); if (res != HCF_SUCCESS) { - LOGE("Rsa CheckRsaKeyGenParams fail."); + LOGE_ONE_STR("Rsa CheckRsaKeyGenParams fail."); return HCF_INVALID_PARAMS; } // Generate keyPair RSA RSA *rsa = OpensslRsaNew(); if (rsa == NULL) { - LOGE("new RSA fail."); + LOGE_ONE_STR("new RSA fail."); return HCF_ERR_MALLOC; } LOGD("keygen bits is %d, primes is %d", params->bits, GetRealPrimes(params->primes)); if (GetRealPrimes(params->primes) != OPENSSL_RSA_KEYGEN_DEFAULT_PRIMES) { if (RSA_generate_multi_prime_key(rsa, params->bits, GetRealPrimes(params->primes), params->pubExp, NULL) != HCF_OPENSSL_SUCCESS) { - LOGD("[error] Generate multi-primes rsa key fail"); + LOGD_ONE_STR("[error] Generate multi-primes rsa key fail"); HcfPrintOpensslError(); OpensslRsaFree(rsa); return HCF_ERR_CRYPTO_OPERATION; } } else { if (RSA_generate_key_ex(rsa, params->bits, params->pubExp, NULL) != HCF_OPENSSL_SUCCESS) { - LOGD("[error] Generate rsa key fail"); + LOGD_ONE_STR("[error] Generate rsa key fail"); HcfPrintOpensslError(); OpensslRsaFree(rsa); return HCF_ERR_CRYPTO_OPERATION; @@ -985,24 +985,24 @@ static HcfResult GenerateKeyPair(HcfAsyKeyGenSpiRsaParams *params, HcfKeyPair ** HcfOpensslRsaKeyPair *keyPairImpl = NULL; res = PackKeyPair(rsa, params->bits, &keyPairImpl); if (res != HCF_SUCCESS) { - LOGE("Generate keyPair fail."); + LOGE_ONE_STR("Generate keyPair fail."); OpensslRsaFree(rsa); return res; } *keyPair = (HcfKeyPair *)keyPairImpl; OpensslRsaFree(rsa); - LOGD("Generate keypair success."); + LOGD_ONE_STR("Generate keypair success."); return res; } static HcfResult EngineGenerateKeyPair(HcfAsyKeyGeneratorSpi *self, HcfKeyPair **keyPair) { if (self == NULL || keyPair == NULL) { - LOGE("Invalid params."); + LOGE_ONE_STR("Invalid params."); return HCF_INVALID_PARAMS; } if (!HcfIsClassMatch((HcfObjectBase *)self, OPENSSL_RSA_GENERATOR_CLASS)) { - LOGE("Class not match."); + LOGE_ONE_STR("Class not match."); return HCF_INVALID_PARAMS; } HcfAsyKeyGeneratorSpiRsaOpensslImpl *impl = (HcfAsyKeyGeneratorSpiRsaOpensslImpl *)self; @@ -1017,11 +1017,11 @@ static const char *GetKeyGeneratorClass(void) static void DestroyKeyGeneratorSpiImpl(HcfObjectBase *self) { if (self == NULL) { - LOGE("DestroyKeyGeneratorSpiImpl is null"); + LOGE_ONE_STR("DestroyKeyGeneratorSpiImpl is null"); return; } if (!HcfIsClassMatch(self, OPENSSL_RSA_GENERATOR_CLASS)) { - LOGE("Class not match."); + LOGE_ONE_STR("Class not match."); return; } // destroy pubExp first. @@ -1038,13 +1038,13 @@ static HcfResult ConvertPubKey(HcfBlob *pubKeyBlob, HcfOpensslRsaPubKey **pubkey { RSA *rsaPk = NULL; if (ConvertPubKeyFromX509(pubKeyBlob, &rsaPk) != HCF_SUCCESS) { - LOGD("[error] Convert pubKey from X509 fail."); + LOGD_ONE_STR("[error] Convert pubKey from X509 fail."); return HCF_ERR_CRYPTO_OPERATION; } HcfOpensslRsaPubKey *pubKey = NULL; HcfResult ret = PackPubKey(rsaPk, &pubKey); if (ret != HCF_SUCCESS) { - LOGD("[error] PackPubKey fail"); + LOGD_ONE_STR("[error] PackPubKey fail"); goto ERR; } *pubkeyRet = pubKey; @@ -1059,7 +1059,7 @@ static HcfResult ConvertPemKeyToKey(const char *keyStr, HcfParamsSpec *params, i EVP_PKEY *pkey = NULL; OSSL_DECODER_CTX *ctx = OpensslOsslDecoderCtxNewForPkey(&pkey, "PEM", NULL, "RSA", selection, NULL, NULL); if (ctx == NULL) { - LOGE("OpensslOsslDecoderCtxNewForPkey fail."); + LOGE_ONE_STR("OpensslOsslDecoderCtxNewForPkey fail."); HcfPrintOpensslError(); return HCF_ERR_CRYPTO_OPERATION; } @@ -1078,7 +1078,7 @@ static HcfResult ConvertPemKeyToKey(const char *keyStr, HcfParamsSpec *params, i int ret = OpensslOsslDecoderFromData(ctx, &pdata, &pdataLen); OpensslOsslDecoderCtxFree(ctx); if (ret != HCF_OPENSSL_SUCCESS) { - LOGE("OpensslOsslDecoderFromData failed."); + LOGE_ONE_STR("OpensslOsslDecoderFromData failed."); HcfPrintOpensslError(); OpensslEvpPkeyFree(pkey); return HCF_ERR_CRYPTO_OPERATION; @@ -1086,7 +1086,7 @@ static HcfResult ConvertPemKeyToKey(const char *keyStr, HcfParamsSpec *params, i *rsa = OpensslEvpPkeyGet1Rsa(pkey); OpensslEvpPkeyFree(pkey); if (*rsa == NULL) { - LOGE("OpensslEvpPkeyGet1Rsa fail."); + LOGE_ONE_STR("OpensslEvpPkeyGet1Rsa fail."); HcfPrintOpensslError(); return HCF_ERR_CRYPTO_OPERATION; } @@ -1099,14 +1099,14 @@ static HcfResult ConvertPemPubKey(const char *pubKeyStr, int selection, HcfOpens HcfResult ret; ret = ConvertPemKeyToKey(pubKeyStr, NULL, selection, &rsaPk); if (ret != HCF_SUCCESS) { - LOGE("ConvertPemKeyToKey failed."); + LOGE_ONE_STR("ConvertPemKeyToKey failed."); return ret; } HcfOpensslRsaPubKey *pubKey = NULL; HcfResult result = PackPubKey(rsaPk, &pubKey); if (result != HCF_SUCCESS) { - LOGE("PackPubKey fail."); + LOGE_ONE_STR("PackPubKey fail."); OpensslRsaFree(rsaPk); return result; } @@ -1118,13 +1118,13 @@ static HcfResult ConvertPriKey(HcfBlob *priKeyBlob, HcfOpensslRsaPriKey **priKey { RSA *rsaSk = NULL; if (ConvertPriKeyFromPKCS8(priKeyBlob, &rsaSk) != HCF_SUCCESS) { - LOGE("ConvertPriKeyFromPKCS8 fail."); + LOGE_ONE_STR("ConvertPriKeyFromPKCS8 fail."); return HCF_ERR_MALLOC; } HcfOpensslRsaPriKey *priKey = NULL; HcfResult ret = PackPriKey(rsaSk, &priKey); if (ret != HCF_SUCCESS) { - LOGD("[error] PackPriKey fail"); + LOGD_ONE_STR("[error] PackPriKey fail"); goto ERR; } *priKeyRet = priKey; @@ -1141,13 +1141,13 @@ static HcfResult ConvertPemPriKey(const char *priKeyStr, HcfParamsSpec *params, HcfResult ret; ret = ConvertPemKeyToKey(priKeyStr, params, selection, &rsaSk); if (ret != HCF_SUCCESS) { - LOGE("ConvertPemKeyToKey failed."); + LOGE_ONE_STR("ConvertPemKeyToKey failed."); return ret; } HcfOpensslRsaPriKey *priKey = NULL; HcfResult result = PackPriKey(rsaSk, &priKey); if (result != HCF_SUCCESS) { - LOGE("PackPriKey fail."); + LOGE_ONE_STR("PackPriKey fail."); OpensslRsaFree(rsaSk); return result; } @@ -1160,18 +1160,18 @@ static HcfResult EngineConvertKey(HcfAsyKeyGeneratorSpi *self, HcfParamsSpec *pa { (void)params; if ((self == NULL) || (returnKeyPair == NULL) || ((pubKeyBlob == NULL) && (priKeyBlob == NULL))) { - LOGE("ConvertKeyParams is invalid."); + LOGE_ONE_STR("ConvertKeyParams is invalid."); return HCF_INVALID_PARAMS; } if (!HcfIsClassMatch((HcfObjectBase *)self, OPENSSL_RSA_GENERATOR_CLASS)) { - LOGE("Class not match."); + LOGE_ONE_STR("Class not match."); return HCF_INVALID_PARAMS; } HcfOpensslRsaPubKey *pubKey = NULL; if ((pubKeyBlob != NULL) && (pubKeyBlob->len != 0) && (pubKeyBlob->data != NULL)) { if (ConvertPubKey(pubKeyBlob, &pubKey) != HCF_SUCCESS) { - LOGE("convert pubkey fail."); + LOGE_ONE_STR("convert pubkey fail."); return HCF_INVALID_PARAMS; } } @@ -1179,20 +1179,20 @@ static HcfResult EngineConvertKey(HcfAsyKeyGeneratorSpi *self, HcfParamsSpec *pa HcfOpensslRsaPriKey *priKey = NULL; if ((priKeyBlob != NULL) && (priKeyBlob->len != 0) && (priKeyBlob->data != NULL)) { if (ConvertPriKey(priKeyBlob, &priKey) != HCF_SUCCESS) { - LOGE("convert prikey fail."); + LOGE_ONE_STR("convert prikey fail."); HcfObjDestroy((HcfObjectBase *)pubKey); return HCF_INVALID_PARAMS; } } if (pubKey == NULL && priKey == NULL) { - LOGE("Convert key failed with invalid blob"); + LOGE_ONE_STR("Convert key failed with invalid blob"); return HCF_INVALID_PARAMS; } HcfOpensslRsaKeyPair *keyPair = (HcfOpensslRsaKeyPair *)HcfMalloc(sizeof(HcfOpensslRsaKeyPair), 0); if (keyPair == NULL) { - LOGE("Malloc keyPair fail."); + LOGE_ONE_STR("Malloc keyPair fail."); HcfObjDestroy((HcfObjectBase *)pubKey); HcfObjDestroy((HcfObjectBase *)priKey); return HCF_ERR_MALLOC; @@ -1210,24 +1210,24 @@ static HcfResult EngineConvertPemKey(HcfAsyKeyGeneratorSpi *self, HcfParamsSpec const char *priKeyStr, HcfKeyPair **returnKeyPair) { if ((self == NULL) || (returnKeyPair == NULL) || ((pubKeyStr == NULL) && (priKeyStr == NULL))) { - LOGE("ConvertPemKeyParams is invalid."); + LOGE_ONE_STR("ConvertPemKeyParams is invalid."); return HCF_INVALID_PARAMS; } if (!HcfIsClassMatch((HcfObjectBase *)self, OPENSSL_RSA_GENERATOR_CLASS)) { - LOGE("Class not match."); + LOGE_ONE_STR("Class not match."); return HCF_INVALID_PARAMS; } HcfOpensslRsaPubKey *pubKey = NULL; if (pubKeyStr != NULL && strlen(pubKeyStr) != 0) { if (ConvertPemPubKey(pubKeyStr, EVP_PKEY_PUBLIC_KEY, &pubKey) != HCF_SUCCESS) { - LOGE("convert pubkey fail."); + LOGE_ONE_STR("convert pubkey fail."); return HCF_ERR_CRYPTO_OPERATION; } } HcfOpensslRsaPriKey *priKey = NULL; if (priKeyStr != NULL && strlen(priKeyStr) != 0) { if (ConvertPemPriKey(priKeyStr, params, EVP_PKEY_KEYPAIR, &priKey) != HCF_SUCCESS) { - LOGE("convert prikey fail."); + LOGE_ONE_STR("convert prikey fail."); HcfObjDestroy((HcfObjectBase *)pubKey); return HCF_ERR_CRYPTO_OPERATION; } @@ -1235,7 +1235,7 @@ static HcfResult EngineConvertPemKey(HcfAsyKeyGeneratorSpi *self, HcfParamsSpec HcfOpensslRsaKeyPair *keyPair = (HcfOpensslRsaKeyPair *)HcfMalloc(sizeof(HcfOpensslRsaKeyPair), 0); if (keyPair == NULL) { - LOGE("Malloc keyPair fail."); + LOGE_ONE_STR("Malloc keyPair fail."); HcfObjDestroy((HcfObjectBase *)pubKey); HcfObjDestroy((HcfObjectBase *)priKey); return HCF_ERR_MALLOC; @@ -1253,18 +1253,18 @@ static HcfResult ParseRsaBnFromBin(const HcfAsyKeyParamsSpec *paramsSpec, BIGNUM { // when meeting the fail situation, the BIGNUM will be NULL and other BIGNUM will be freeed in InitRsaStructByBin(); if (BigIntegerToBigNum(&((HcfRsaCommParamsSpec *)paramsSpec)->n, n) != HCF_SUCCESS) { - LOGD("[error] Rsa new BN n fail."); + LOGD_ONE_STR("[error] Rsa new BN n fail."); return HCF_ERR_CRYPTO_OPERATION; } if (paramsSpec->specType == HCF_KEY_PAIR_SPEC) { if (BigIntegerToBigNum(&((HcfRsaKeyPairParamsSpec *)paramsSpec)->pk, e) != HCF_SUCCESS) { - LOGD("[error] Rsa new BN e fail."); + LOGD_ONE_STR("[error] Rsa new BN e fail."); OpensslBnFree(*n); *n = NULL; return HCF_ERR_CRYPTO_OPERATION; } if (BigIntegerToBigNum(&((HcfRsaKeyPairParamsSpec *)paramsSpec)->sk, d) != HCF_SUCCESS) { - LOGD("[error] Rsa new BN d fail."); + LOGD_ONE_STR("[error] Rsa new BN d fail."); OpensslBnFree(*n); *n = NULL; OpensslBnFree(*e); @@ -1274,7 +1274,7 @@ static HcfResult ParseRsaBnFromBin(const HcfAsyKeyParamsSpec *paramsSpec, BIGNUM } if (paramsSpec->specType == HCF_PUBLIC_KEY_SPEC) { if (BigIntegerToBigNum(&((HcfRsaPubKeyParamsSpec *)paramsSpec)->pk, e) != HCF_SUCCESS) { - LOGD("[error] Rsa new BN e fail."); + LOGD_ONE_STR("[error] Rsa new BN e fail."); OpensslBnFree(*n); *n = NULL; return HCF_ERR_CRYPTO_OPERATION; @@ -1291,7 +1291,7 @@ static RSA *InitRsaStructByBin(const HcfAsyKeyParamsSpec *paramsSpec) RSA *rsa = NULL; if (ParseRsaBnFromBin(paramsSpec, &n, &e, &d) != HCF_SUCCESS) { - LOGD("[error] ParseRsaBnFromBin fail"); + LOGD_ONE_STR("[error] ParseRsaBnFromBin fail"); return rsa; } rsa = OpensslRsaNew(); @@ -1299,13 +1299,13 @@ static RSA *InitRsaStructByBin(const HcfAsyKeyParamsSpec *paramsSpec) OpensslBnFree(n); OpensslBnFree(e); OpensslBnClearFree(d); - LOGD("[error] new RSA fail"); + LOGD_ONE_STR("[error] new RSA fail"); return rsa; } // if set0 success, RSA object will take the owner of n, e, d and will free them. // as a new RSA object, in RSA_set0_key(), n and e cannot be NULL. if (OpensslRsaSet0Key(rsa, n, e, d) != HCF_OPENSSL_SUCCESS) { - LOGD("[error] set RSA fail"); + LOGD_ONE_STR("[error] set RSA fail"); HcfPrintOpensslError(); OpensslBnFree(n); OpensslBnFree(e); @@ -1322,12 +1322,12 @@ static HcfResult GenerateKeyPairBySpec(const HcfAsyKeyParamsSpec *paramsSpec, Hc // Generate keyPair RSA by spec RSA *rsa = InitRsaStructByBin(paramsSpec); if (rsa == NULL) { - LOGD("[error] Generate RSA fail."); + LOGD_ONE_STR("[error] Generate RSA fail."); return HCF_ERR_CRYPTO_OPERATION; } HcfOpensslRsaKeyPair *keyPairImpl = (HcfOpensslRsaKeyPair *)HcfMalloc(sizeof(HcfOpensslRsaKeyPair), 0); if (keyPairImpl == NULL) { - LOGE("Malloc keyPair fail."); + LOGE_ONE_STR("Malloc keyPair fail."); OpensslRsaFree(rsa); return HCF_ERR_MALLOC; } @@ -1337,7 +1337,7 @@ static HcfResult GenerateKeyPairBySpec(const HcfAsyKeyParamsSpec *paramsSpec, Hc RSA *pubKeyRsa = NULL; if (DuplicateRsa(rsa, false, &pubKeyRsa) != HCF_SUCCESS) { - LOGD("[error] Duplicate pubKey rsa fail"); + LOGD_ONE_STR("[error] Duplicate pubKey rsa fail"); OpensslRsaFree(rsa); HcfFree(keyPairImpl); return HCF_ERR_CRYPTO_OPERATION; @@ -1345,7 +1345,7 @@ static HcfResult GenerateKeyPairBySpec(const HcfAsyKeyParamsSpec *paramsSpec, Hc HcfResult res = PackPubKey(pubKeyRsa, &pubKeyImpl); if (res != HCF_SUCCESS) { - LOGE("pack pup key fail."); + LOGE_ONE_STR("pack pup key fail."); OpensslRsaFree(rsa); OpensslRsaFree(pubKeyRsa); HcfFree(keyPairImpl); @@ -1354,7 +1354,7 @@ static HcfResult GenerateKeyPairBySpec(const HcfAsyKeyParamsSpec *paramsSpec, Hc res = PackPriKey(rsa, &priKeyImpl); if (res != HCF_SUCCESS) { - LOGE("pack pri key fail."); + LOGE_ONE_STR("pack pri key fail."); OpensslRsaFree(rsa); OpensslRsaFree(pubKeyRsa); HcfFree(keyPairImpl); @@ -1366,7 +1366,7 @@ static HcfResult GenerateKeyPairBySpec(const HcfAsyKeyParamsSpec *paramsSpec, Hc keyPairImpl->base.base.getClass = GetOpensslKeyPairClass; keyPairImpl->base.base.destroy = DestroyKeyPair; *keyPair = (HcfKeyPair *)keyPairImpl; - LOGD("Generate keypair success."); + LOGD_ONE_STR("Generate keypair success."); return res; } @@ -1374,26 +1374,26 @@ static HcfResult GeneratePubKeyBySpec(const HcfAsyKeyParamsSpec *paramsSpec, Hcf { RSA *rsa = InitRsaStructByBin(paramsSpec); if (rsa == NULL) { - LOGD("[error] Generate RSA fail."); + LOGD_ONE_STR("[error] Generate RSA fail."); return HCF_ERR_CRYPTO_OPERATION; } RSA *pubKeyRsa = NULL; if (DuplicateRsa(rsa, false, &pubKeyRsa) != HCF_SUCCESS) { - LOGD("[error] Duplicate pubKey rsa fail"); + LOGD_ONE_STR("[error] Duplicate pubKey rsa fail"); OpensslRsaFree(rsa); return HCF_ERR_CRYPTO_OPERATION; } HcfOpensslRsaPubKey *pubKeyImpl = NULL; HcfResult res = PackPubKey(pubKeyRsa, &pubKeyImpl); if (res != HCF_SUCCESS) { - LOGD("[error] pack pup key fail."); + LOGD_ONE_STR("[error] pack pup key fail."); OpensslRsaFree(rsa); OpensslRsaFree(pubKeyRsa); return res; } *pubKey = (HcfPubKey *)pubKeyImpl; OpensslRsaFree(rsa); - LOGD("Generate pub key success."); + LOGD_ONE_STR("Generate pub key success."); return res; } @@ -1401,18 +1401,18 @@ static HcfResult GeneratePriKeyBySpec(const HcfAsyKeyParamsSpec *paramsSpec, Hcf { RSA *rsa = InitRsaStructByBin(paramsSpec); if (rsa == NULL) { - LOGD("[error] Generate RSA fail."); + LOGD_ONE_STR("[error] Generate RSA fail."); return HCF_ERR_CRYPTO_OPERATION; } HcfOpensslRsaPriKey *priKeyImpl = NULL; HcfResult res = PackPriKey(rsa, &priKeyImpl); if (res != HCF_SUCCESS) { - LOGD("[error] pack pri key fail."); + LOGD_ONE_STR("[error] pack pri key fail."); OpensslRsaFree(rsa); return res; } *priKey = (HcfPriKey *)priKeyImpl; - LOGD("Generate pri key success."); + LOGD_ONE_STR("Generate pri key success."); return res; } @@ -1420,19 +1420,19 @@ static HcfResult EngineGenerateKeyPairBySpec(const HcfAsyKeyGeneratorSpi *self, const HcfAsyKeyParamsSpec *paramsSpec, HcfKeyPair **returnKeyPair) { if ((self == NULL) || (returnKeyPair == NULL) || (paramsSpec == NULL) || (paramsSpec->algName == NULL)) { - LOGE("GenerateKeyPairBySpec Params is invalid."); + LOGE_ONE_STR("GenerateKeyPairBySpec Params is invalid."); return HCF_INVALID_PARAMS; } if (!HcfIsClassMatch((HcfObjectBase *)self, OPENSSL_RSA_GENERATOR_CLASS)) { - LOGE("Class not match."); + LOGE_ONE_STR("Class not match."); return HCF_INVALID_PARAMS; } if (strcmp(paramsSpec->algName, RSA_ALG_NAME) != 0) { - LOGE("Spec alg not match."); + LOGE_ONE_STR("Spec alg not match."); return HCF_INVALID_PARAMS; } if (paramsSpec->specType != HCF_KEY_PAIR_SPEC) { - LOGE("Spec type not match."); + LOGE_ONE_STR("Spec type not match."); return HCF_INVALID_PARAMS; } return GenerateKeyPairBySpec(paramsSpec, returnKeyPair); @@ -1442,19 +1442,19 @@ static HcfResult EngineGeneratePubKeyBySpec(const HcfAsyKeyGeneratorSpi *self, const HcfAsyKeyParamsSpec *paramsSpec, HcfPubKey **returnPubKey) { if ((self == NULL) || (returnPubKey == NULL) || (paramsSpec == NULL) || (paramsSpec->algName == NULL)) { - LOGE("GeneratePubKeyBySpec Params is invalid."); + LOGE_ONE_STR("GeneratePubKeyBySpec Params is invalid."); return HCF_INVALID_PARAMS; } if (!HcfIsClassMatch((HcfObjectBase *)self, OPENSSL_RSA_GENERATOR_CLASS)) { - LOGE("Class not match."); + LOGE_ONE_STR("Class not match."); return HCF_INVALID_PARAMS; } if (strcmp(paramsSpec->algName, RSA_ALG_NAME) != 0) { - LOGE("Spec alg not match."); + LOGE_ONE_STR("Spec alg not match."); return HCF_INVALID_PARAMS; } if (paramsSpec->specType != HCF_PUBLIC_KEY_SPEC && paramsSpec->specType != HCF_KEY_PAIR_SPEC) { - LOGE("Spec not match."); + LOGE_ONE_STR("Spec not match."); return HCF_INVALID_PARAMS; } return GeneratePubKeyBySpec(paramsSpec, returnPubKey); @@ -1464,19 +1464,19 @@ static HcfResult EngineGeneratePriKeyBySpec(const HcfAsyKeyGeneratorSpi *self, const HcfAsyKeyParamsSpec *paramsSpec, HcfPriKey **returnPriKey) { if ((self == NULL) || (returnPriKey == NULL) || (paramsSpec == NULL) || (paramsSpec->algName == NULL)) { - LOGE("GeneratePriKeyBySpec Params is invalid."); + LOGE_ONE_STR("GeneratePriKeyBySpec Params is invalid."); return HCF_INVALID_PARAMS; } if (!HcfIsClassMatch((HcfObjectBase *)self, OPENSSL_RSA_GENERATOR_CLASS)) { - LOGE("Class not match."); + LOGE_ONE_STR("Class not match."); return HCF_INVALID_PARAMS; } if (strcmp(paramsSpec->algName, RSA_ALG_NAME) != 0) { - LOGE("Spec alg not match."); + LOGE_ONE_STR("Spec alg not match."); return HCF_INVALID_PARAMS; } if (paramsSpec->specType != HCF_KEY_PAIR_SPEC) { - LOGE("Spec not match."); + LOGE_ONE_STR("Spec not match."); return HCF_INVALID_PARAMS; } return GeneratePriKeyBySpec(paramsSpec, returnPriKey); @@ -1485,20 +1485,20 @@ static HcfResult EngineGeneratePriKeyBySpec(const HcfAsyKeyGeneratorSpi *self, static HcfResult SetDefaultValue(HcfAsyKeyGenSpiRsaParams *params) { if (params->primes == 0) { - LOGD("set default primes 2"); + LOGD_ONE_STR("set default primes 2"); params->primes = OPENSSL_RSA_PRIMES_SIZE_2; } if (params->pubExp != NULL) { - LOGE("RSA has pubKey default unexpectedly."); + LOGE_ONE_STR("RSA has pubKey default unexpectedly."); return HCF_SUCCESS; } BIGNUM *e = OpensslBnNew(); if (e == NULL) { - LOGD("[error] RSA new BN fail."); + LOGD_ONE_STR("[error] RSA new BN fail."); return HCF_ERR_CRYPTO_OPERATION; } if (OpensslBnSetWord(e, RSA_F4) != HCF_OPENSSL_SUCCESS) { - LOGD("[error] RSA keygen Bn_set_word fail."); + LOGD_ONE_STR("[error] RSA keygen Bn_set_word fail."); OpensslBnFree(e); return HCF_ERR_CRYPTO_OPERATION; } @@ -1510,7 +1510,7 @@ static HcfResult DecodeParams(HcfAsyKeyGenParams *from, HcfAsyKeyGenSpiRsaParams { *to = (HcfAsyKeyGenSpiRsaParams *)HcfMalloc(sizeof(HcfAsyKeyGenSpiRsaParams), 0); if (*to == NULL) { - LOGE("Malloc HcfAsyKeyGenSpiRsaParams fail"); + LOGE_ONE_STR("Malloc HcfAsyKeyGenSpiRsaParams fail"); return HCF_ERR_MALLOC; } @@ -1519,13 +1519,13 @@ static HcfResult DecodeParams(HcfAsyKeyGenParams *from, HcfAsyKeyGenSpiRsaParams // set 2 as default primes, RSA_F4 as default pubExp if (SetDefaultValue(*to) != HCF_SUCCESS) { - LOGE("Set default value fail."); + LOGE_ONE_STR("Set default value fail."); HcfFree(*to); *to = NULL; return HCF_INVALID_PARAMS; } if (CheckRsaKeyGenParams(*to) != HCF_SUCCESS) { - LOGE("Invalid keyGen params"); + LOGE_ONE_STR("Invalid keyGen params"); OpensslBnFree((*to)->pubExp); HcfFree(*to); *to = NULL; @@ -1537,17 +1537,17 @@ static HcfResult DecodeParams(HcfAsyKeyGenParams *from, HcfAsyKeyGenSpiRsaParams HcfResult HcfAsyKeyGeneratorSpiRsaCreate(HcfAsyKeyGenParams *params, HcfAsyKeyGeneratorSpi **generator) { if (params == NULL || generator == NULL) { - LOGE("Invalid input, params is invalid or generator is null."); + LOGE_ONE_STR("Invalid input, params is invalid or generator is null."); return HCF_INVALID_PARAMS; } HcfAsyKeyGeneratorSpiRsaOpensslImpl *impl = (HcfAsyKeyGeneratorSpiRsaOpensslImpl *) HcfMalloc(sizeof(HcfAsyKeyGeneratorSpiRsaOpensslImpl), 0); if (impl == NULL) { - LOGE("Failed to allocate returnImpl memroy!"); + LOGE_ONE_STR("Failed to allocate returnImpl memroy!"); return HCF_ERR_MALLOC; } if (DecodeParams(params, &impl->params) != HCF_SUCCESS) { - LOGE("Keygen params is invalid."); + LOGE_ONE_STR("Keygen params is invalid."); HcfFree(impl); return HCF_INVALID_PARAMS; } diff --git a/plugin/openssl_plugin/key/asy_key_generator/src/sm2_asy_key_generator_openssl.c b/plugin/openssl_plugin/key/asy_key_generator/src/sm2_asy_key_generator_openssl.c index 174221daaaa1ccf816d8e95c29d6ebb8bae083f2..6a3e2bb3856a2d1c2acb99bbd8199a39e4aa63fc 100644 --- a/plugin/openssl_plugin/key/asy_key_generator/src/sm2_asy_key_generator_openssl.c +++ b/plugin/openssl_plugin/key/asy_key_generator/src/sm2_asy_key_generator_openssl.c @@ -49,7 +49,7 @@ static HcfResult CheckSm256CurveId(BIGNUM *p, BIGNUM *b, BIGNUM *x, BIGNUM *y) xStd = OpensslBin2Bn(g_sm256CorrectBigGX, NID_X9_62_prime256v1_len, NULL); yStd = OpensslBin2Bn(g_sm256CorrectBigGY, NID_X9_62_prime256v1_len, NULL); if ((pStd == NULL) || (bStd == NULL) || (xStd == NULL) || (yStd == NULL)) { - LOGD("[error] EC 256 Curve convert to BN fail"); + LOGD_ONE_STR("[error] EC 256 Curve convert to BN fail"); FreeCurveBigNum(pStd, bStd, xStd, yStd); return HCF_ERR_CRYPTO_OPERATION; } @@ -58,7 +58,7 @@ static HcfResult CheckSm256CurveId(BIGNUM *p, BIGNUM *b, BIGNUM *x, BIGNUM *y) FreeCurveBigNum(pStd, bStd, xStd, yStd); return HCF_SUCCESS; } - LOGD("[error] EC 256 compare fail"); + LOGD_ONE_STR("[error] EC 256 compare fail"); FreeCurveBigNum(pStd, bStd, xStd, yStd); return HCF_INVALID_PARAMS; } @@ -74,7 +74,7 @@ static HcfResult CheckParamsSpecToGetCurveId(const HcfEccCommParamsSpec *ecParam BigIntegerToBigNum(&(ecParams->b), &b) != HCF_SUCCESS || BigIntegerToBigNum(&(ecParams->g.x), &x) != HCF_SUCCESS || BigIntegerToBigNum(&(ecParams->g.y), &y) != HCF_SUCCESS) { - LOGD("[error] BigIntegerToBigNum failed."); + LOGD_ONE_STR("[error] BigIntegerToBigNum failed."); FreeCurveBigNum(p, b, x, y); return HCF_ERR_CRYPTO_OPERATION; } @@ -82,7 +82,7 @@ static HcfResult CheckParamsSpecToGetCurveId(const HcfEccCommParamsSpec *ecParam int32_t bitLenP = (int32_t)OpensslBnNumBits(p); HcfResult ret = HCF_INVALID_PARAMS; if (bitLenP != OPENSSL_SM2_256_BITS) { - LOGE("Find no bit len"); + LOGE_ONE_STR("Find no bit len"); FreeCurveBigNum(p, b, x, y); return ret; } @@ -97,7 +97,7 @@ static HcfResult CheckParamsSpecToGetCurveId(const HcfEccCommParamsSpec *ecParam static HcfResult GenerateSm2KeyWithParamsSpec(const HcfEccCommParamsSpec *ecParams, EC_KEY **returnKey) { if (ecParams == NULL || returnKey == NULL) { - LOGE("Invalid input parameters."); + LOGE_ONE_STR("Invalid input parameters."); return HCF_INVALID_PARAMS; } EC_KEY *ecKey = NULL; @@ -105,32 +105,32 @@ static HcfResult GenerateSm2KeyWithParamsSpec(const HcfEccCommParamsSpec *ecPara HcfResult ret = CheckParamsSpecToGetCurveId(ecParams, &curveId); if (ret == HCF_SUCCESS && curveId != 0) { ecKey = OpensslEcKeyNewByCurveName(curveId); - LOGD("Generate EC_KEY by curve name"); + LOGD_ONE_STR("Generate EC_KEY by curve name"); if (ecKey == NULL) { - LOGD("[error] New ec key failed."); + LOGD_ONE_STR("[error] New ec key failed."); return HCF_ERR_CRYPTO_OPERATION; } } else { EC_GROUP *group = NULL; ret = GenerateEcGroupWithParamsSpec(ecParams, &group); if (ret != HCF_SUCCESS) { - LOGE("GenerateEcGroupWithParamsSpec failed."); + LOGE_ONE_STR("GenerateEcGroupWithParamsSpec failed."); return ret; } ecKey = OpensslEcKeyNew(); if (ecKey == NULL) { - LOGD("[error] OpensslEcKeyNew failed."); + LOGD_ONE_STR("[error] OpensslEcKeyNew failed."); OpensslEcGroupFree(group); return HCF_ERR_CRYPTO_OPERATION; } if (OpensslEcKeySetGroup(ecKey, group) != HCF_OPENSSL_SUCCESS) { - LOGD("[error] OpensslEcKeySetGroup failed."); + LOGD_ONE_STR("[error] OpensslEcKeySetGroup failed."); OpensslEcGroupFree(group); OpensslEcKeyFree(ecKey); return HCF_ERR_CRYPTO_OPERATION; } OpensslEcGroupFree(group); - LOGD("Generate EC_KEY by group spec parmas"); + LOGD_ONE_STR("Generate EC_KEY by group spec parmas"); } // all exceptions have been returned above. *returnKey = ecKey; @@ -140,23 +140,23 @@ static HcfResult GenerateSm2KeyWithParamsSpec(const HcfEccCommParamsSpec *ecPara static HcfResult NewSm2KeyPairWithCommSpec(const HcfEccCommParamsSpec *ecParams, EC_KEY **returnEckey) { if (ecParams == NULL || returnEckey == NULL) { - LOGE("Invalid input parameters."); + LOGE_ONE_STR("Invalid input parameters."); return HCF_INVALID_PARAMS; } EC_KEY *ecKey = NULL; HcfResult ret = GenerateSm2KeyWithParamsSpec(ecParams, &ecKey); if (ret != HCF_SUCCESS) { - LOGE("Generate EC key failed"); + LOGE_ONE_STR("Generate EC key failed"); return ret; } if (OpensslEcKeyGenerateKey(ecKey) != HCF_OPENSSL_SUCCESS) { - LOGD("[error] OpensslEcKeyGenerateKey failed."); + LOGD_ONE_STR("[error] OpensslEcKeyGenerateKey failed."); OpensslEcKeyFree(ecKey); return HCF_ERR_CRYPTO_OPERATION; } if (OpensslEcKeyCheckKey(ecKey) <= 0) { - LOGD("[error] Check ecKey fail."); + LOGD_ONE_STR("[error] Check ecKey fail."); OpensslEcKeyFree(ecKey); return HCF_ERR_CRYPTO_OPERATION; } @@ -167,24 +167,24 @@ static HcfResult NewSm2KeyPairWithCommSpec(const HcfEccCommParamsSpec *ecParams, static HcfResult NewSm2PubKeyWithPubSpec(const HcfEccPubKeyParamsSpec *ecParams, EC_KEY **returnEcKey) { if (ecParams == NULL || returnEcKey == NULL) { - LOGE("Invalid input parameters."); + LOGE_ONE_STR("Invalid input parameters."); return HCF_INVALID_PARAMS; } EC_KEY *ecKey = NULL; HcfResult ret = GenerateSm2KeyWithParamsSpec((HcfEccCommParamsSpec *)ecParams, &ecKey); if (ret != HCF_SUCCESS) { - LOGE("Generate EC key failed"); + LOGE_ONE_STR("Generate EC key failed"); return ret; } ret = SetEcKey(&(ecParams->pk), NULL, ecKey); if (ret != HCF_SUCCESS) { - LOGD("[error] Set public ecKey failed."); + LOGD_ONE_STR("[error] Set public ecKey failed."); OpensslEcKeyFree(ecKey); return HCF_ERR_CRYPTO_OPERATION; } if (OpensslEcKeyCheckKey(ecKey) <= 0) { - LOGD("[error] Check ecKey fail."); + LOGD_ONE_STR("[error] Check ecKey fail."); OpensslEcKeyFree(ecKey); return HCF_ERR_CRYPTO_OPERATION; } @@ -195,24 +195,24 @@ static HcfResult NewSm2PubKeyWithPubSpec(const HcfEccPubKeyParamsSpec *ecParams, static HcfResult NewSm2PriKeyWithPriSpec(const HcfEccPriKeyParamsSpec *ecParams, EC_KEY **returnEcKey) { if (ecParams == NULL || returnEcKey == NULL) { - LOGE("Invalid input parameters."); + LOGE_ONE_STR("Invalid input parameters."); return HCF_INVALID_PARAMS; } EC_KEY *ecKey = NULL; HcfResult ret = GenerateSm2KeyWithParamsSpec((HcfEccCommParamsSpec *)ecParams, &ecKey); if (ret != HCF_SUCCESS) { - LOGE("Generate EC key failed"); + LOGE_ONE_STR("Generate EC key failed"); return ret; } ret = SetEcKey(NULL, &(ecParams->sk), ecKey); if (ret != HCF_SUCCESS) { - LOGD("[error] Set private ecKey failed."); + LOGD_ONE_STR("[error] Set private ecKey failed."); OpensslEcKeyFree(ecKey); return HCF_ERR_CRYPTO_OPERATION; } if (OpensslEcKeyCheckKey(ecKey) <= 0) { - LOGD("[error] Check ecKey failed."); + LOGD_ONE_STR("[error] Check ecKey failed."); OpensslEcKeyFree(ecKey); return HCF_ERR_CRYPTO_OPERATION; } @@ -224,13 +224,13 @@ static HcfResult NewSm2KeyWithKeyPairSpec(const HcfEccKeyPairParamsSpec *ecParam bool needPrivate) { if (ecParams == NULL || returnEcKey == NULL) { - LOGE("Invalid input parameters."); + LOGE_ONE_STR("Invalid input parameters."); return HCF_INVALID_PARAMS; } EC_KEY *ecKey = NULL; HcfResult ret = GenerateSm2KeyWithParamsSpec((HcfEccCommParamsSpec *)ecParams, &ecKey); if (ret != HCF_SUCCESS) { - LOGD("[error] Generate EC key failed"); + LOGD_ONE_STR("[error] Generate EC key failed"); return ret; } if (needPrivate) { @@ -239,13 +239,13 @@ static HcfResult NewSm2KeyWithKeyPairSpec(const HcfEccKeyPairParamsSpec *ecParam ret = SetEcKey(&(ecParams->pk), NULL, ecKey); } if (ret != HCF_SUCCESS) { - LOGD("[error] SetEcKey failed."); + LOGD_ONE_STR("[error] SetEcKey failed."); OpensslEcKeyFree(ecKey); return HCF_ERR_CRYPTO_OPERATION; } if (OpensslEcKeyCheckKey(ecKey) <= 0) { - LOGE("Check ecKey failed."); + LOGE_ONE_STR("Check ecKey failed."); OpensslEcKeyFree(ecKey); return HCF_ERR_CRYPTO_OPERATION; } @@ -264,7 +264,7 @@ static HcfResult GenKeyPairSm2KeyBySpec(const HcfAsyKeyParamsSpec *params, EC_KE ret = NewSm2KeyWithKeyPairSpec((HcfEccKeyPairParamsSpec *)params, ecKey, true); break; default: - LOGE("Invaild input spec to gen key pair."); + LOGE_ONE_STR("Invaild input spec to gen key pair."); break; } return ret; @@ -281,7 +281,7 @@ static HcfResult GenPubKeySm2KeyBySpec(const HcfAsyKeyParamsSpec *params, EC_KEY ret = NewSm2KeyWithKeyPairSpec((HcfEccKeyPairParamsSpec *)params, ecKey, false); break; default: - LOGE("Invaild input spec to gen pub key"); + LOGE_ONE_STR("Invaild input spec to gen pub key"); break; } return ret; @@ -298,7 +298,7 @@ static HcfResult GenPriKeySm2KeyBySpec(const HcfAsyKeyParamsSpec *params, EC_KEY ret = NewSm2KeyWithKeyPairSpec((HcfEccKeyPairParamsSpec *)params, ecKey, true); break; default: - LOGE("Invaild input spec to gen pri key"); + LOGE_ONE_STR("Invaild input spec to gen pri key"); break; } return ret; @@ -327,11 +327,11 @@ static const char *GetSm2PriKeyClass(void) static void DestroySm2KeyPairGenerator(HcfObjectBase *self) { if (self == NULL) { - LOGE("Class is null."); + LOGE_ONE_STR("Class is null."); return; } if (!HcfIsClassMatch(self, GetSm2KeyPairGeneratorClass())) { - LOGE("Class not match."); + LOGE_ONE_STR("Class not match."); return; } HcfFree(self); @@ -340,11 +340,11 @@ static void DestroySm2KeyPairGenerator(HcfObjectBase *self) static void DestroySm2PubKey(HcfObjectBase *self) { if (self == NULL) { - LOGE("Class is null."); + LOGE_ONE_STR("Class is null."); return; } if (!HcfIsClassMatch(self, GetSm2PubKeyClass())) { - LOGE("Class not match."); + LOGE_ONE_STR("Class not match."); return; } HcfOpensslSm2PubKey *impl = (HcfOpensslSm2PubKey *)self; @@ -358,11 +358,11 @@ static void DestroySm2PubKey(HcfObjectBase *self) static void DestroySm2PriKey(HcfObjectBase *self) { if (self == NULL) { - LOGE("Class is null."); + LOGE_ONE_STR("Class is null."); return; } if (!HcfIsClassMatch(self, GetSm2PriKeyClass())) { - LOGE("Class not match."); + LOGE_ONE_STR("Class not match."); return; } HcfOpensslSm2PriKey *impl = (HcfOpensslSm2PriKey *)self; @@ -376,11 +376,11 @@ static void DestroySm2PriKey(HcfObjectBase *self) static void DestroySm2KeyPair(HcfObjectBase *self) { if (self == NULL) { - LOGE("Class is null."); + LOGE_ONE_STR("Class is null."); return; } if (!HcfIsClassMatch(self, GetSm2KeyPairClass())) { - LOGE("Class not match."); + LOGE_ONE_STR("Class not match."); return; } HcfOpensslSm2KeyPair *impl = (HcfOpensslSm2KeyPair *)self; @@ -398,11 +398,11 @@ static void DestroySm2KeyPair(HcfObjectBase *self) static const char *GetSm2PubKeyAlgorithm(HcfKey *self) { if (self == NULL) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return NULL; } if (!HcfIsClassMatch((HcfObjectBase *)self, HCF_OPENSSL_SM2_PUB_KEY_CLASS)) { - LOGE("Invalid SM2 public key class for algorithm"); + LOGE_ONE_STR("Invalid SM2 public key class for algorithm"); return NULL; } return OPENSSL_SM2_ALGORITHM; @@ -411,11 +411,11 @@ static const char *GetSm2PubKeyAlgorithm(HcfKey *self) static const char *GetSm2PriKeyAlgorithm(HcfKey *self) { if (self == NULL) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return NULL; } if (!HcfIsClassMatch((HcfObjectBase *)self, HCF_OPENSSL_SM2_PRI_KEY_CLASS)) { - LOGE("Invalid SM2 private key class for algorithm"); + LOGE_ONE_STR("Invalid SM2 private key class for algorithm"); return NULL; } return OPENSSL_SM2_ALGORITHM; @@ -424,11 +424,11 @@ static const char *GetSm2PriKeyAlgorithm(HcfKey *self) static const char *GetSm2PubKeyFormat(HcfKey *self) { if (self == NULL) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return NULL; } if (!HcfIsClassMatch((HcfObjectBase *)self, HCF_OPENSSL_SM2_PUB_KEY_CLASS)) { - LOGE("Invalid SM2 public key class for format"); + LOGE_ONE_STR("Invalid SM2 public key class for format"); return NULL; } return OPENSSL_SM2_PUB_KEY_FORMAT; @@ -437,11 +437,11 @@ static const char *GetSm2PubKeyFormat(HcfKey *self) static const char *GetSm2PriKeyFormat(HcfKey *self) { if (self == NULL) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return NULL; } if (!HcfIsClassMatch((HcfObjectBase *)self, HCF_OPENSSL_SM2_PRI_KEY_CLASS)) { - LOGE("Invalid SM2 private key class for format"); + LOGE_ONE_STR("Invalid SM2 private key class for format"); return NULL; } return OPENSSL_SM2_PRI_KEY_FORMAT; @@ -450,17 +450,17 @@ static const char *GetSm2PriKeyFormat(HcfKey *self) static HcfResult GetSm2PubKeyEncoded(HcfKey *self, HcfBlob *returnBlob) { if ((self == NULL) || (returnBlob == NULL)) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return HCF_INVALID_PARAMS; } if (!HcfIsClassMatch((HcfObjectBase *)self, HCF_OPENSSL_SM2_PUB_KEY_CLASS)) { - LOGE("Invalid SM2 public key class for encode"); + LOGE_ONE_STR("Invalid SM2 public key class for encode"); return HCF_INVALID_PARAMS; } HcfOpensslSm2PubKey *impl = (HcfOpensslSm2PubKey *)self; if (impl->curveId != 0) { - LOGD("Have a curveId"); + LOGD_ONE_STR("Have a curveId"); OpensslEcKeySetAsn1Flag(impl->ecKey, OPENSSL_EC_NAMED_CURVE); } else { OpensslEcKeySetAsn1Flag(impl->ecKey, OPENSSL_EC_EXPLICIT_CURVE); @@ -469,7 +469,7 @@ static HcfResult GetSm2PubKeyEncoded(HcfKey *self, HcfBlob *returnBlob) unsigned char *returnData = NULL; int returnDataLen = OpensslI2dEcPubKey(impl->ecKey, &returnData); if (returnDataLen <= 0) { - LOGD("[error] Call i2d_EC_PUBKEY fail"); + LOGD_ONE_STR("[error] Call i2d_EC_PUBKEY fail"); HcfPrintOpensslError(); return HCF_ERR_CRYPTO_OPERATION; } @@ -489,17 +489,17 @@ static HcfResult GetSm2PubKeyEncodedPem(HcfKey *self, const char *format, char * static HcfResult GetSm2PriKeyEncoded(HcfKey *self, HcfBlob *returnBlob) { if ((self == NULL) || (returnBlob == NULL)) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return HCF_INVALID_PARAMS; } if (!HcfIsClassMatch((HcfObjectBase *)self, HCF_OPENSSL_SM2_PRI_KEY_CLASS)) { - LOGE("Invalid SM2 private key class for encode"); + LOGE_ONE_STR("Invalid SM2 private key class for encode"); return HCF_INVALID_PARAMS; } HcfOpensslSm2PriKey *impl = (HcfOpensslSm2PriKey *)self; if (impl->curveId != 0) { - LOGD("Have a curveId"); + LOGD_ONE_STR("Have a curveId"); OpensslEcKeySetAsn1Flag(impl->ecKey, OPENSSL_EC_NAMED_CURVE); } else { OpensslEcKeySetAsn1Flag(impl->ecKey, OPENSSL_EC_EXPLICIT_CURVE); @@ -511,7 +511,7 @@ static HcfResult GetSm2PriKeyEncoded(HcfKey *self, HcfBlob *returnBlob) unsigned char *returnData = NULL; int returnDataLen = OpensslI2dEcPrivateKey(impl->ecKey, &returnData); if (returnDataLen <= 0) { - LOGD("[error] Call i2d_ECPrivateKey fail."); + LOGD_ONE_STR("[error] Call i2d_ECPrivateKey fail."); HcfPrintOpensslError(); return HCF_ERR_CRYPTO_OPERATION; } @@ -533,11 +533,11 @@ static HcfResult GetSm2PriKeyEncodedPem(const HcfPriKey *self, HcfParamsSpec *pa static void Sm2PriKeyClearMem(HcfPriKey *self) { if (self == NULL) { - LOGE("Class is null."); + LOGE_ONE_STR("Class is null."); return; } if (!HcfIsClassMatch((HcfObjectBase *)self, GetSm2PriKeyClass())) { - LOGE("Class not match."); + LOGE_ONE_STR("Class not match."); return; } HcfOpensslSm2PriKey *impl = (HcfOpensslSm2PriKey *)self; @@ -555,19 +555,19 @@ static HcfResult GetCurveName(const HcfKey *self, bool isPriavte, char **returnS } if (curveId != NID_sm2) { - LOGD("[error] Invalid curve name."); + LOGD_ONE_STR("[error] Invalid curve name."); return HCF_ERR_CRYPTO_OPERATION; } char *curveIdStr = "NID_sm2"; size_t len = HcfStrlen(curveIdStr); if (len == 0) { - LOGE("CurveIdStr is empty!"); + LOGE_ONE_STR("CurveIdStr is empty!"); return HCF_INVALID_PARAMS; } *returnString = (char *)HcfMalloc(len + 1, 0); if (*returnString == NULL) { - LOGE("Allocate returnString memory failed."); + LOGE_ONE_STR("Allocate returnString memory failed."); return HCF_ERR_MALLOC; } (void)memcpy_s(*returnString, len, curveIdStr, len); @@ -581,7 +581,7 @@ static HcfResult CheckSm2KeySelf(const HcfKey *self, bool *isPrivate) return HCF_SUCCESS; } else if (HcfIsClassMatch((HcfObjectBase *)self, GetSm2PriKeyClass())) { if (((HcfOpensslSm2PriKey *)self)->ecKey == NULL) { - LOGE("Cannot use priKey after free"); + LOGE_ONE_STR("Cannot use priKey after free"); return HCF_INVALID_PARAMS; } *isPrivate = true; @@ -595,13 +595,13 @@ static HcfResult GetSm2KeySpecBigInteger(const HcfKey *self, const AsyKeySpecIte HcfBigInteger *returnBigInteger) { if (self == NULL || returnBigInteger == NULL) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return HCF_INVALID_PARAMS; } bool isPrivate = false; HcfResult ret = CheckSm2KeySelf(self, &isPrivate); if (ret != HCF_SUCCESS) { - LOGE("Invalid input key"); + LOGE_ONE_STR("Invalid input key"); return HCF_INVALID_PARAMS; } const EC_GROUP *group = NULL; @@ -611,7 +611,7 @@ static HcfResult GetSm2KeySpecBigInteger(const HcfKey *self, const AsyKeySpecIte group = OpensslEcKeyGet0Group(((HcfOpensslSm2PubKey *)self)->ecKey); } if (group == NULL) { - LOGE("Get group failed"); + LOGE_ONE_STR("Get group failed"); return HCF_INVALID_PARAMS; } switch (item) { @@ -633,7 +633,7 @@ static HcfResult GetSm2KeySpecBigInteger(const HcfKey *self, const AsyKeySpecIte ret = GetPkSkBigInteger(self, isPrivate, item, returnBigInteger); break; default: - LOGE("Invalid ecc key big number spec!"); + LOGE_ONE_STR("Invalid ecc key big number spec!"); ret = HCF_INVALID_PARAMS; break; } @@ -643,13 +643,13 @@ static HcfResult GetSm2KeySpecBigInteger(const HcfKey *self, const AsyKeySpecIte static HcfResult GetSm2KeySpecString(const HcfKey *self, const AsyKeySpecItem item, char **returnString) { if (self == NULL || returnString == NULL) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return HCF_INVALID_PARAMS; } bool isPrivate = false; HcfResult ret = CheckSm2KeySelf(self, &isPrivate); if (ret != HCF_SUCCESS) { - LOGE("Invalid input key"); + LOGE_ONE_STR("Invalid input key"); return HCF_INVALID_PARAMS; } @@ -662,7 +662,7 @@ static HcfResult GetSm2KeySpecString(const HcfKey *self, const AsyKeySpecItem it break; default: ret = HCF_INVALID_PARAMS; - LOGE("Invalid spec of ec string"); + LOGE_ONE_STR("Invalid spec of ec string"); break; } return ret; @@ -671,13 +671,13 @@ static HcfResult GetSm2KeySpecString(const HcfKey *self, const AsyKeySpecItem it static HcfResult GetSm2KeySpecInt(const HcfKey *self, const AsyKeySpecItem item, int *returnInt) { if (self == NULL || returnInt == NULL) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return HCF_INVALID_PARAMS; } bool isPrivate = false; HcfResult ret = CheckSm2KeySelf(self, &isPrivate); if (ret != HCF_SUCCESS) { - LOGE("Invalid input key"); + LOGE_ONE_STR("Invalid input key"); return HCF_INVALID_PARAMS; } const EC_GROUP *group = NULL; @@ -687,7 +687,7 @@ static HcfResult GetSm2KeySpecInt(const HcfKey *self, const AsyKeySpecItem item, group = OpensslEcKeyGet0Group(((HcfOpensslSm2PubKey *)self)->ecKey); } if (group == NULL) { - LOGE("Get group failed"); + LOGE_ONE_STR("Get group failed"); return HCF_INVALID_PARAMS; } switch (item) { @@ -699,7 +699,7 @@ static HcfResult GetSm2KeySpecInt(const HcfKey *self, const AsyKeySpecItem item, break; default: ret = HCF_INVALID_PARAMS; - LOGE("Invalid ec key int spec"); + LOGE_ONE_STR("Invalid ec key int spec"); break; } return ret; @@ -750,7 +750,7 @@ static HcfResult PackSm2PubKey(int32_t curveId, EC_KEY *ecKey, const char *field { HcfOpensslSm2PubKey *returnPubKey = (HcfOpensslSm2PubKey *)HcfMalloc(sizeof(HcfOpensslSm2PubKey), 0); if (returnPubKey == NULL) { - LOGE("Failed to allocate returnPubKey memory!"); + LOGE_ONE_STR("Failed to allocate returnPubKey memory!"); return HCF_ERR_MALLOC; } @@ -758,13 +758,13 @@ static HcfResult PackSm2PubKey(int32_t curveId, EC_KEY *ecKey, const char *field if (fieldType != NULL) { size_t len = HcfStrlen(fieldType); if (len == 0) { - LOGE("FieldType is empty!"); + LOGE_ONE_STR("FieldType is empty!"); HcfFree(returnPubKey); return HCF_INVALID_PARAMS; } tmpFieldType = (char *)HcfMalloc(len + 1, 0); if (tmpFieldType == NULL) { - LOGE("Allocate tmpFieldType memory failed."); + LOGE_ONE_STR("Allocate tmpFieldType memory failed."); HcfFree(returnPubKey); return HCF_ERR_MALLOC; } @@ -801,7 +801,7 @@ static HcfResult PackSm2PriKey(int32_t curveId, EC_KEY *ecKey, const char *field { HcfOpensslSm2PriKey *returnPriKey = (HcfOpensslSm2PriKey *)HcfMalloc(sizeof(HcfOpensslSm2PriKey), 0); if (returnPriKey == NULL) { - LOGE("Failed to allocate returnPriKey memory!"); + LOGE_ONE_STR("Failed to allocate returnPriKey memory!"); return HCF_ERR_MALLOC; } @@ -809,13 +809,13 @@ static HcfResult PackSm2PriKey(int32_t curveId, EC_KEY *ecKey, const char *field if (fieldType != NULL) { size_t len = HcfStrlen(fieldType); if (len == 0) { - LOGE("FieldType is empty!"); + LOGE_ONE_STR("FieldType is empty!"); HcfFree(returnPriKey); return HCF_INVALID_PARAMS; } tmpFieldType = (char *)HcfMalloc(len + 1, 0); if (tmpFieldType == NULL) { - LOGE("Allocate tmpFieldType memory failed."); + LOGE_ONE_STR("Allocate tmpFieldType memory failed."); HcfFree(returnPriKey); return HCF_ERR_MALLOC; } @@ -845,7 +845,7 @@ static HcfResult PackSm2KeyPair(HcfOpensslSm2PubKey *pubKey, HcfOpensslSm2PriKey { HcfOpensslSm2KeyPair *returnKeyPair = (HcfOpensslSm2KeyPair *)HcfMalloc(sizeof(HcfOpensslSm2KeyPair), 0); if (returnKeyPair == NULL) { - LOGE("Failed to allocate returnKeyPair memory!"); + LOGE_ONE_STR("Failed to allocate returnKeyPair memory!"); return HCF_ERR_MALLOC; } returnKeyPair->base.base.getClass = GetSm2KeyPairClass; @@ -862,13 +862,13 @@ static HcfResult ConvertEcPubKey(int32_t curveId, HcfBlob *pubKeyBlob, HcfOpenss const unsigned char *tmpData = (const unsigned char *)(pubKeyBlob->data); EC_KEY *ecKey = OpensslD2iEcPubKey(NULL, &tmpData, pubKeyBlob->len); if (ecKey == NULL) { - LOGD("[error] Call d2i_EC_PUBKEY fail."); + LOGD_ONE_STR("[error] Call d2i_EC_PUBKEY fail."); HcfPrintOpensslError(); return HCF_ERR_CRYPTO_OPERATION; } HcfResult ret = PackSm2PubKey(curveId, ecKey, g_sm2GenerateFieldType, returnPubKey); if (ret != HCF_SUCCESS) { - LOGE("CreateSm2PubKey failed."); + LOGE_ONE_STR("CreateSm2PubKey failed."); OpensslEcKeyFree(ecKey); return ret; } @@ -880,13 +880,13 @@ static HcfResult ConvertEcPriKey(int32_t curveId, HcfBlob *priKeyBlob, HcfOpenss const unsigned char *tmpData = (const unsigned char *)(priKeyBlob->data); EC_KEY *ecKey = OpensslD2iEcPrivateKey(NULL, &tmpData, priKeyBlob->len); if (ecKey == NULL) { - LOGD("[error] Call d2i_ECPrivateKey fail"); + LOGD_ONE_STR("[error] Call d2i_ECPrivateKey fail"); HcfPrintOpensslError(); return HCF_ERR_CRYPTO_OPERATION; } HcfResult ret = PackSm2PriKey(curveId, ecKey, g_sm2GenerateFieldType, returnPriKey); if (ret != HCF_SUCCESS) { - LOGE("CreateSm2PriKey failed."); + LOGE_ONE_STR("CreateSm2PriKey failed."); OpensslEcKeyFree(ecKey); return ret; } @@ -898,17 +898,17 @@ static HcfResult EngineConvertSm2Key(HcfAsyKeyGeneratorSpi *self, HcfParamsSpec { (void)params; if ((self == NULL) || (returnKeyPair == NULL)) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return HCF_INVALID_PARAMS; } if (!HcfIsClassMatch((HcfObjectBase *)self, self->base.getClass())) { - LOGE("Class not match."); + LOGE_ONE_STR("Class not match."); return HCF_INVALID_PARAMS; } bool pubKeyValid = HcfIsBlobValid(pubKeyBlob); bool priKeyValid = HcfIsBlobValid(priKeyBlob); if ((!pubKeyValid) && (!priKeyValid)) { - LOGE("The private key and public key cannot both be NULL."); + LOGE_ONE_STR("The private key and public key cannot both be NULL."); return HCF_INVALID_PARAMS; } @@ -921,21 +921,21 @@ static HcfResult EngineConvertSm2Key(HcfAsyKeyGeneratorSpi *self, HcfParamsSpec if (pubKeyValid) { ret = ConvertEcPubKey(impl->curveId, pubKeyBlob, &pubKey); if (ret != HCF_SUCCESS) { - LOGD("[error] Convert ec pubKey failed."); + LOGD_ONE_STR("[error] Convert ec pubKey failed."); break; } } if (priKeyValid) { ret = ConvertEcPriKey(impl->curveId, priKeyBlob, &priKey); if (ret != HCF_SUCCESS) { - LOGD("[error] Convert ec priKey failed."); + LOGD_ONE_STR("[error] Convert ec priKey failed."); break; } } ret = PackSm2KeyPair(pubKey, priKey, &keyPair); } while (0); if (ret != HCF_SUCCESS) { - LOGD("[error] Convert sm2 keyPair failed."); + LOGD_ONE_STR("[error] Convert sm2 keyPair failed."); HcfObjDestroy(pubKey); HcfObjDestroy(priKey); return ret; @@ -955,34 +955,34 @@ static EC_KEY *GetSm2EckeyformPubKey(const EVP_PKEY *pkey) ecKey = OpensslEcKeyNewbyCurveNameEx(NULL, NULL, NID_sm2); if (ecKey == NULL) { - LOGE("Failed to init ec key."); + LOGE_ONE_STR("Failed to init ec key."); return NULL; } group = OpensslEcKeyGet0Group(ecKey); if (group == NULL) { - LOGE("Failed to get group while get ec key."); + LOGE_ONE_STR("Failed to get group while get ec key."); OpensslEcKeyFree(ecKey); return NULL; } pubPoint = OpensslEcPointNew(group); if (pubPoint == NULL) { - LOGE("Failed to init ec point while get ec key."); + LOGE_ONE_STR("Failed to init ec point while get ec key."); OpensslEcKeyFree(ecKey); return NULL; } if (!OpensslEvpPkeyGetOctetStringParam(pkey, OSSL_PKEY_PARAM_PUB_KEY, octetKey, sizeof(octetKey), &octetKeyLen)) { - LOGE("Failed to get octet string param while get ec key."); + LOGE_ONE_STR("Failed to get octet string param while get ec key."); OpensslEcKeyFree(ecKey); OpensslEcPointFree(pubPoint); return NULL; } if (!OpensslEcOct2Point(group, pubPoint, octetKey, octetKeyLen, NULL)) { - LOGE("Failed to convert oct to point while get ec key."); + LOGE_ONE_STR("Failed to convert oct to point while get ec key."); OpensslEcKeyFree(ecKey); OpensslEcPointFree(pubPoint); return NULL; @@ -990,7 +990,7 @@ static EC_KEY *GetSm2EckeyformPubKey(const EVP_PKEY *pkey) OpensslEcKeySetFlags(ecKey, EC_FLAG_SM2_RANGE); if (!OpensslEcKeySetPublicKey(ecKey, pubPoint)) { - LOGE("Failed to set public key while get ec key."); + LOGE_ONE_STR("Failed to set public key while get ec key."); OpensslEcKeyFree(ecKey); OpensslEcPointFree(pubPoint); return NULL; @@ -1007,19 +1007,19 @@ static EC_KEY *GetSm2EckeyformPriKey(const EVP_PKEY *pkey) ecKey = OpensslEcKeyNewbyCurveNameEx(NULL, NULL, NID_sm2); if (ecKey == NULL) { - LOGE("Failed to init ec key."); + LOGE_ONE_STR("Failed to init ec key."); return NULL; } if (OpensslEvpPkeyGetBnParam(pkey, OSSL_PKEY_PARAM_PRIV_KEY, &outPriv) != HCF_OPENSSL_SUCCESS) { - LOGE("Failed to get bn param while get ec key."); + LOGE_ONE_STR("Failed to get bn param while get ec key."); OpensslEcKeyFree(ecKey); return NULL; } OpensslEcKeySetFlags(ecKey, EC_FLAG_SM2_RANGE); if (OpensslEcKeySetPrivateKey(ecKey, outPriv) != HCF_OPENSSL_SUCCESS) { - LOGE("Failed to set private key while get ec key."); + LOGE_ONE_STR("Failed to set private key while get ec key."); OpensslEcKeyFree(ecKey); OpensslBnClearFree(outPriv); return NULL; @@ -1035,21 +1035,21 @@ static HcfResult ConvertSM2PemPubKey(int32_t curveId, const char *pubKeyStr, Hcf const char *keyType = "SM2"; HcfResult ret = ConvertPubPemStrToKey(&pkey, keyType, EVP_PKEY_PUBLIC_KEY, pubKeyStr); if (ret != HCF_SUCCESS) { - LOGE("Convert sm2 pem public key failed."); + LOGE_ONE_STR("Convert sm2 pem public key failed."); return ret; } EC_KEY *ecKey = GetSm2EckeyformPubKey(pkey); OpensslEvpPkeyFree(pkey); if (ecKey == NULL) { - LOGE("Get sm2 ec pkey fail."); + LOGE_ONE_STR("Get sm2 ec pkey fail."); HcfPrintOpensslError(); return HCF_ERR_CRYPTO_OPERATION; } ret = PackSm2PubKey(curveId, ecKey, g_sm2GenerateFieldType, returnPubKey); if (ret != HCF_SUCCESS) { - LOGE("Create sm2 public key failed."); + LOGE_ONE_STR("Create sm2 public key failed."); OpensslEcKeyFree(ecKey); return ret; } @@ -1063,21 +1063,21 @@ static HcfResult ConvertSM2PemPriKey(int32_t curveId, const char *priKeyStr, Hcf const char *keyType = "SM2"; HcfResult ret = ConvertPriPemStrToKey(priKeyStr, &pkey, keyType); if (ret != HCF_SUCCESS) { - LOGE("Convert sm2 pem private key failed."); + LOGE_ONE_STR("Convert sm2 pem private key failed."); return ret; } EC_KEY *ecKey = GetSm2EckeyformPriKey(pkey); OpensslEvpPkeyFree(pkey); if (ecKey == NULL) { - LOGE("Get sm2 ec pkey fail."); + LOGE_ONE_STR("Get sm2 ec pkey fail."); HcfPrintOpensslError(); return HCF_ERR_CRYPTO_OPERATION; } ret = PackSm2PriKey(curveId, ecKey, g_sm2GenerateFieldType, returnPriKey); if (ret != HCF_SUCCESS) { - LOGE("Create sm2 private key failed."); + LOGE_ONE_STR("Create sm2 private key failed."); OpensslEcKeyFree(ecKey); return ret; } @@ -1090,11 +1090,11 @@ static HcfResult EngineConvertSm2PemKey(HcfAsyKeyGeneratorSpi *self, HcfParamsSp { (void)params; if ((self == NULL) || (returnKeyPair == NULL) || ((pubKeyStr == NULL) && (priKeyStr == NULL))) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return HCF_INVALID_PARAMS; } if (!HcfIsClassMatch((HcfObjectBase *)self, self->base.getClass())) { - LOGE("Class not match."); + LOGE_ONE_STR("Class not match."); return HCF_INVALID_PARAMS; } @@ -1120,7 +1120,7 @@ static HcfResult EngineConvertSm2PemKey(HcfAsyKeyGeneratorSpi *self, HcfParamsSp ret = PackSm2KeyPair(pubKey, priKey, &keyPair); } while (0); if (ret != HCF_SUCCESS) { - LOGE("Convert sm2 keyPair failed."); + LOGE_ONE_STR("Convert sm2 keyPair failed."); HcfObjDestroy(pubKey); HcfObjDestroy(priKey); return ret; @@ -1136,7 +1136,7 @@ static HcfResult PackAndAssignPubKey(const HcfAsyKeyGeneratorSpiOpensslSm2Impl * HcfOpensslSm2PubKey *pubKey = NULL; HcfResult ret = PackSm2PubKey(impl->curveId, ecKey, fieldType, &pubKey); if (ret != HCF_SUCCESS) { - LOGD("[error] Create sm2 pubKey failed."); + LOGD_ONE_STR("[error] Create sm2 pubKey failed."); return ret; } *returnObj = (HcfPubKey *)pubKey; @@ -1149,7 +1149,7 @@ static HcfResult PackAndAssignPriKey(const HcfAsyKeyGeneratorSpiOpensslSm2Impl * HcfOpensslSm2PriKey *priKey = NULL; HcfResult ret = PackSm2PriKey(impl->curveId, ecKey, fieldType, &priKey); if (ret != HCF_SUCCESS) { - LOGD("[error] Create sm2 priKey failed."); + LOGD_ONE_STR("[error] Create sm2 priKey failed."); return ret; } *returnObj = (HcfPriKey *)priKey; @@ -1161,26 +1161,26 @@ static HcfResult CreateAndAssignKeyPair(const HcfAsyKeyGeneratorSpiOpensslSm2Imp { EC_KEY *ecPriKey = EC_KEY_dup(ecKey); if (ecPriKey == NULL) { - LOGD("[error] Dup ecKey fail."); + LOGD_ONE_STR("[error] Dup ecKey fail."); return HCF_ERR_CRYPTO_OPERATION; } HcfOpensslSm2PriKey *priKey = NULL; HcfResult ret = PackSm2PriKey(impl->curveId, ecPriKey, fieldType, &priKey); if (ret != HCF_SUCCESS) { - LOGD("[error] Create sm2 priKey failed."); + LOGD_ONE_STR("[error] Create sm2 priKey failed."); OpensslEcKeyFree(ecPriKey); return ret; } HcfOpensslSm2PubKey *pubKey = NULL; EC_KEY *ecPubKey = EC_KEY_dup(ecKey); if (ecPubKey == NULL) { - LOGD("[error] Dup ecKey fail."); + LOGD_ONE_STR("[error] Dup ecKey fail."); HcfObjDestroy(priKey); return HCF_ERR_CRYPTO_OPERATION; } ret = PackSm2PubKey(impl->curveId, ecPubKey, fieldType, &pubKey); if (ret != HCF_SUCCESS) { - LOGD("[error] Create sm2 pubKey failed."); + LOGD_ONE_STR("[error] Create sm2 pubKey failed."); HcfObjDestroy(priKey); OpensslEcKeyFree(ecPubKey); return ret; @@ -1189,7 +1189,7 @@ static HcfResult CreateAndAssignKeyPair(const HcfAsyKeyGeneratorSpiOpensslSm2Imp HcfOpensslSm2KeyPair *returnKeyPair = NULL; ret = PackSm2KeyPair(pubKey, priKey, &returnKeyPair); if (ret != HCF_SUCCESS) { - LOGE("Create sm2 keyPair failed."); + LOGE_ONE_STR("Create sm2 keyPair failed."); HcfObjDestroy(pubKey); HcfObjDestroy(priKey); } @@ -1200,11 +1200,11 @@ static HcfResult CreateAndAssignKeyPair(const HcfAsyKeyGeneratorSpiOpensslSm2Imp static HcfResult EngineGenerateKeyPair(HcfAsyKeyGeneratorSpi *self, HcfKeyPair **returnObj) { if ((self == NULL) || (returnObj == NULL)) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return HCF_INVALID_PARAMS; } if (!HcfIsClassMatch((HcfObjectBase *)self, self->base.getClass())) { - LOGE("Class not match."); + LOGE_ONE_STR("Class not match."); return HCF_INVALID_PARAMS; } @@ -1214,7 +1214,7 @@ static HcfResult EngineGenerateKeyPair(HcfAsyKeyGeneratorSpi *self, HcfKeyPair * if (ret == HCF_SUCCESS) { ret = CreateAndAssignKeyPair(impl, g_sm2GenerateFieldType, ecKey, returnObj); if (ret != HCF_SUCCESS) { - LOGD("[error] CreateAndAssignKeyPair failed."); + LOGD_ONE_STR("[error] CreateAndAssignKeyPair failed."); } OpensslEcKeyFree(ecKey); } @@ -1226,11 +1226,11 @@ static HcfResult EngineGenerateKeyPairBySpec(const HcfAsyKeyGeneratorSpi *self, { if ((self == NULL) || (returnKeyPair == NULL) || (params == NULL) || (((HcfEccCommParamsSpec *)params)->field == NULL)) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return HCF_INVALID_PARAMS; } if (!HcfIsClassMatch((HcfObjectBase *)self, GetSm2KeyPairGeneratorClass())) { - LOGE("Class not match."); + LOGE_ONE_STR("Class not match."); return HCF_INVALID_PARAMS; } @@ -1238,7 +1238,7 @@ static HcfResult EngineGenerateKeyPairBySpec(const HcfAsyKeyGeneratorSpi *self, EC_KEY *ecKey = NULL; HcfResult ret = GenKeyPairSm2KeyBySpec(params, &ecKey); if (ret != HCF_SUCCESS) { - LOGD("[error] Gen ec key pair with spec failed."); + LOGD_ONE_STR("[error] Gen ec key pair with spec failed."); return ret; } @@ -1251,7 +1251,7 @@ static HcfResult EngineGenerateKeyPairBySpec(const HcfAsyKeyGeneratorSpi *self, ret = CreateAndAssignKeyPair(impl, ((HcfEccCommParamsSpec *)params)->field->fieldType, ecKey, returnKeyPair); OpensslEcKeyFree(ecKey); if (ret != HCF_SUCCESS) { - LOGD("[error] CreateAndAssignKeyPair failed."); + LOGD_ONE_STR("[error] CreateAndAssignKeyPair failed."); return ret; } return HCF_SUCCESS; @@ -1262,11 +1262,11 @@ static HcfResult EngineGeneratePubKeyBySpec(const HcfAsyKeyGeneratorSpi *self, c { if ((self == NULL) || (returnPubKey == NULL) || (params == NULL) || (((HcfEccCommParamsSpec *)params)->field == NULL)) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return HCF_INVALID_PARAMS; } if (!HcfIsClassMatch((HcfObjectBase *)self, GetSm2KeyPairGeneratorClass())) { - LOGE("Class not match."); + LOGE_ONE_STR("Class not match."); return HCF_INVALID_PARAMS; } @@ -1274,7 +1274,7 @@ static HcfResult EngineGeneratePubKeyBySpec(const HcfAsyKeyGeneratorSpi *self, c EC_KEY *ecKey = NULL; HcfResult ret = GenPubKeySm2KeyBySpec(params, &ecKey); if (ret != HCF_SUCCESS) { - LOGD("[error] Gen ec pubKey with spec failed."); + LOGD_ONE_STR("[error] Gen ec pubKey with spec failed."); return ret; } int32_t curveId = (int32_t)OpensslEcGroupGetCurveName(OpensslEcKeyGet0Group(ecKey)); @@ -1283,7 +1283,7 @@ static HcfResult EngineGeneratePubKeyBySpec(const HcfAsyKeyGeneratorSpi *self, c } ret = PackAndAssignPubKey(impl, ((HcfEccCommParamsSpec *)params)->field->fieldType, ecKey, returnPubKey); if (ret != HCF_SUCCESS) { - LOGD("[error] PackAndAssignPubKey failed."); + LOGD_ONE_STR("[error] PackAndAssignPubKey failed."); OpensslEcKeyFree(ecKey); return ret; } @@ -1295,11 +1295,11 @@ static HcfResult EngineGeneratePriKeyBySpec(const HcfAsyKeyGeneratorSpi *self, c { if ((self == NULL) || (returnPriKey == NULL) || (params == NULL) || (((HcfEccCommParamsSpec *)params)->field == NULL)) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return HCF_INVALID_PARAMS; } if (!HcfIsClassMatch((HcfObjectBase *)self, GetSm2KeyPairGeneratorClass())) { - LOGE("Class not match."); + LOGE_ONE_STR("Class not match."); return HCF_INVALID_PARAMS; } @@ -1307,7 +1307,7 @@ static HcfResult EngineGeneratePriKeyBySpec(const HcfAsyKeyGeneratorSpi *self, c EC_KEY *ecKey = NULL; HcfResult ret = GenPriKeySm2KeyBySpec(params, &ecKey); if (ret != HCF_SUCCESS) { - LOGD("[error] Gen ec priKey with spec failed."); + LOGD_ONE_STR("[error] Gen ec priKey with spec failed."); return ret; } @@ -1318,7 +1318,7 @@ static HcfResult EngineGeneratePriKeyBySpec(const HcfAsyKeyGeneratorSpi *self, c ret = PackAndAssignPriKey(impl, ((HcfEccCommParamsSpec *)params)->field->fieldType, ecKey, returnPriKey); if (ret != HCF_SUCCESS) { - LOGD("[error] PackAndAssignPriKey failed."); + LOGD_ONE_STR("[error] PackAndAssignPriKey failed."); OpensslEcKeyFree(ecKey); return ret; } @@ -1328,13 +1328,13 @@ static HcfResult EngineGeneratePriKeyBySpec(const HcfAsyKeyGeneratorSpi *self, c HcfResult HcfAsyKeyGeneratorSpiSm2Create(HcfAsyKeyGenParams *params, HcfAsyKeyGeneratorSpi **returnObj) { if (params == NULL || returnObj == NULL) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return HCF_INVALID_PARAMS; } int32_t curveId = 0; if (params->bits != 0) { if (GetOpensslCurveId(params->bits, &curveId) != HCF_SUCCESS) { - LOGE("Get curve id failed."); + LOGE_ONE_STR("Get curve id failed."); return HCF_INVALID_PARAMS; } } @@ -1342,7 +1342,7 @@ HcfResult HcfAsyKeyGeneratorSpiSm2Create(HcfAsyKeyGenParams *params, HcfAsyKeyGe HcfAsyKeyGeneratorSpiOpensslSm2Impl *returnImpl = (HcfAsyKeyGeneratorSpiOpensslSm2Impl *)HcfMalloc( sizeof(HcfAsyKeyGeneratorSpiOpensslSm2Impl), 0); if (returnImpl == NULL) { - LOGE("Failed to allocate returnImpl memroy!"); + LOGE_ONE_STR("Failed to allocate returnImpl memroy!"); return HCF_ERR_MALLOC; } returnImpl->base.base.getClass = GetSm2KeyPairGeneratorClass; diff --git a/plugin/openssl_plugin/key/sym_key_generator/src/sym_key_openssl.c b/plugin/openssl_plugin/key/sym_key_generator/src/sym_key_openssl.c index dc7391ba6910da0058822cc33a4d44cdc82a3dfd..d9b09369a3d40fee17f92ce4099584c1d4a51639 100644 --- a/plugin/openssl_plugin/key/sym_key_generator/src/sym_key_openssl.c +++ b/plugin/openssl_plugin/key/sym_key_generator/src/sym_key_openssl.c @@ -38,21 +38,21 @@ typedef struct { static HcfResult GetEncoded(HcfKey *self, HcfBlob *key) { if ((self == NULL) || (key == NULL)) { - LOGE("Invalid input parameter!"); + LOGE_ONE_STR("Invalid input parameter!"); return HCF_INVALID_PARAMS; } if (!HcfIsClassMatch((const HcfObjectBase *)self, OPENSSL_SYM_KEY_CLASS)) { - LOGE("Class is not match."); + LOGE_ONE_STR("Class is not match."); return HCF_INVALID_PARAMS; } SymKeyImpl *impl = (SymKeyImpl *)self; if ((impl->keyMaterial.data == NULL) || (impl->keyMaterial.len == 0)) { - LOGE("Invalid SymKeyImpl parameter!"); + LOGE_ONE_STR("Invalid SymKeyImpl parameter!"); return HCF_INVALID_PARAMS; } key->data = (uint8_t *)HcfMalloc(impl->keyMaterial.len, 0); if (key->data == NULL) { - LOGE("malloc keyMaterial failed!"); + LOGE_ONE_STR("malloc keyMaterial failed!"); return HCF_ERR_MALLOC; } (void)memcpy_s(key->data, impl->keyMaterial.len, impl->keyMaterial.data, impl->keyMaterial.len); @@ -63,11 +63,11 @@ static HcfResult GetEncoded(HcfKey *self, HcfBlob *key) static void ClearMem(HcfSymKey *self) { if (self == NULL) { - LOGE("symKey is NULL."); + LOGE_ONE_STR("symKey is NULL."); return; } if (!HcfIsClassMatch((const HcfObjectBase *)self, OPENSSL_SYM_KEY_CLASS)) { - LOGE("Class is not match."); + LOGE_ONE_STR("Class is not match."); return; } SymKeyImpl *impl = (SymKeyImpl *)self; @@ -79,11 +79,11 @@ static void ClearMem(HcfSymKey *self) static const char *GetFormat(HcfKey *self) { if (self == NULL) { - LOGE("Invalid input parameter!"); + LOGE_ONE_STR("Invalid input parameter!"); return NULL; } if (!HcfIsClassMatch((const HcfObjectBase *)self, OPENSSL_SYM_KEY_CLASS)) { - LOGE("Class is not match."); + LOGE_ONE_STR("Class is not match."); return NULL; } @@ -103,11 +103,11 @@ static const char *GetSymKeyClass(void) static const char *GetAlgorithm(HcfKey *self) { if (self == NULL) { - LOGE("Invalid input parameter!"); + LOGE_ONE_STR("Invalid input parameter!"); return NULL; } if (!HcfIsClassMatch((const HcfObjectBase *)self, OPENSSL_SYM_KEY_CLASS)) { - LOGE("Class is not match."); + LOGE_ONE_STR("Class is not match."); return NULL; } SymKeyImpl *impl = (SymKeyImpl *)self; @@ -118,12 +118,12 @@ static HcfResult RandomSymmKey(int32_t keyLen, HcfBlob *symmKey) { uint8_t *keyMaterial = (uint8_t *)HcfMalloc(keyLen, 0); if (keyMaterial == NULL) { - LOGE("keyMaterial malloc failed!"); + LOGE_ONE_STR("keyMaterial malloc failed!"); return HCF_ERR_MALLOC; } int ret = OpensslRandPrivBytes(keyMaterial, keyLen); if (ret != HCF_OPENSSL_SUCCESS) { - LOGD("[error] RAND_bytes failed!"); + LOGD_ONE_STR("[error] RAND_bytes failed!"); HcfPrintOpensslError(); HcfFree(keyMaterial); return HCF_ERR_CRYPTO_OPERATION; @@ -136,12 +136,12 @@ static HcfResult RandomSymmKey(int32_t keyLen, HcfBlob *symmKey) static HcfResult HcfSymmKeySpiCreate(int32_t keyLen, SymKeyImpl *symKey) { if ((keyLen == 0) || (symKey == NULL)) { - LOGE("Invalid input parameter!"); + LOGE_ONE_STR("Invalid input parameter!"); return HCF_INVALID_PARAMS; } HcfResult res = RandomSymmKey(keyLen, &symKey->keyMaterial); if (res != HCF_SUCCESS) { - LOGD("[error] RandomSymmKey failed!"); + LOGD_ONE_STR("[error] RandomSymmKey failed!"); return res; } return res; @@ -150,11 +150,11 @@ static HcfResult HcfSymmKeySpiCreate(int32_t keyLen, SymKeyImpl *symKey) static void DestroySymKeyGeneratorSpi(HcfObjectBase *base) { if (base == NULL) { - LOGE("Invalid input parameter!"); + LOGE_ONE_STR("Invalid input parameter!"); return; } if (!HcfIsClassMatch(base, GetSymKeyGeneratorClass())) { - LOGE("Class is not match!"); + LOGE_ONE_STR("Class is not match!"); return; } HcfFree(base); @@ -163,11 +163,11 @@ static void DestroySymKeyGeneratorSpi(HcfObjectBase *base) static void DestroySymKeySpi(HcfObjectBase *base) { if (base == NULL) { - LOGE("Invalid input parameter!"); + LOGE_ONE_STR("Invalid input parameter!"); return; } if (!HcfIsClassMatch(base, OPENSSL_SYM_KEY_CLASS)) { - LOGE("Class is not match."); + LOGE_ONE_STR("Class is not match."); return; } SymKeyImpl *impl = (SymKeyImpl *)base; @@ -196,7 +196,7 @@ static char *GetAlgoNameType(HcfAlgValue type) case HCF_ALG_HMAC: return HMAC_ALG_NAME; default: - LOGE("unsupport type!"); + LOGE_ONE_STR("unsupport type!"); break; } return NULL; @@ -206,26 +206,26 @@ static char *GetAlgoName(HcfSymKeyGeneratorSpiOpensslImpl *impl, int keySize) { char keySizeChar[MAX_KEY_STR_SIZE] = { 0 }; if (sprintf_s(keySizeChar, MAX_KEY_STR_SIZE, "%d", keySize) < 0) { - LOGE("Invalid input parameter!"); + LOGE_ONE_STR("Invalid input parameter!"); return NULL; } char *nameType = GetAlgoNameType(impl->attr.algo); if (nameType == NULL) { - LOGE("get algo name type failed!"); + LOGE_ONE_STR("get algo name type failed!"); return NULL; } int32_t nameSize = strlen(nameType); char *algoName = (char *)HcfMalloc(MAX_KEY_STR_SIZE, 0); if (algoName == NULL) { - LOGE("algoName malloc failed!"); + LOGE_ONE_STR("algoName malloc failed!"); return NULL; } if (strcpy_s(algoName, MAX_KEY_STR_SIZE, nameType) != EOK) { - LOGE("algoName strcpy_s failed!"); + LOGE_ONE_STR("algoName strcpy_s failed!"); goto clearup; } if (strcpy_s(algoName + nameSize, MAX_KEY_STR_SIZE - nameSize, keySizeChar) != EOK) { - LOGE("algoName size strcpy_s failed!"); + LOGE_ONE_STR("algoName size strcpy_s failed!"); goto clearup; } return algoName; @@ -237,12 +237,12 @@ clearup: static HcfResult CopySymmKey(const HcfBlob *srcKey, HcfBlob *dstKey) { if ((srcKey->data == NULL) || (srcKey->len == 0)) { - LOGE("Invalid input parameter!"); + LOGE_ONE_STR("Invalid input parameter!"); return HCF_INVALID_PARAMS; } uint8_t *keyMaterial = (uint8_t *)HcfMalloc(srcKey->len, 0); if (keyMaterial == NULL) { - LOGE("keyMaterial malloc failed!"); + LOGE_ONE_STR("keyMaterial malloc failed!"); return HCF_ERR_MALLOC; } (void)memcpy_s(keyMaterial, srcKey->len, srcKey->data, srcKey->len); @@ -254,16 +254,16 @@ static HcfResult CopySymmKey(const HcfBlob *srcKey, HcfBlob *dstKey) static HcfResult GenerateSymmKey(HcfSymKeyGeneratorSpi *self, HcfSymKey **symmKey) { if ((self == NULL) || (symmKey == NULL)) { - LOGE("Invalid input parameter!"); + LOGE_ONE_STR("Invalid input parameter!"); return HCF_INVALID_PARAMS; } if (!HcfIsClassMatch((const HcfObjectBase *)self, GetSymKeyGeneratorClass())) { - LOGE("Class is not match!"); + LOGE_ONE_STR("Class is not match!"); return HCF_INVALID_PARAMS; } SymKeyImpl *returnSymmKey = (SymKeyImpl *)HcfMalloc(sizeof(SymKeyImpl), 0); if (returnSymmKey == NULL) { - LOGE("Failed to allocate returnKeyPair memory!"); + LOGE_ONE_STR("Failed to allocate returnKeyPair memory!"); return HCF_ERR_MALLOC; } HcfSymKeyGeneratorSpiOpensslImpl *impl = (HcfSymKeyGeneratorSpiOpensslImpl *)self; @@ -303,23 +303,23 @@ static bool IsBlobKeyLenValid(SymKeyAttr attr, const HcfBlob *key) static HcfResult ConvertSymmKey(HcfSymKeyGeneratorSpi *self, const HcfBlob *key, HcfSymKey **symmKey) { if ((self == NULL) || (symmKey == NULL) || !HcfIsBlobValid(key)) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return HCF_INVALID_PARAMS; } if (!HcfIsClassMatch((const HcfObjectBase *)self, GetSymKeyGeneratorClass())) { - LOGE("Class is not match."); + LOGE_ONE_STR("Class is not match."); return HCF_INVALID_PARAMS; } HcfSymKeyGeneratorSpiOpensslImpl *impl = (HcfSymKeyGeneratorSpiOpensslImpl *)self; if (!IsBlobKeyLenValid(impl->attr, key)) { - LOGE("Invalid param: input key length is invalid!"); + LOGE_ONE_STR("Invalid param: input key length is invalid!"); return HCF_INVALID_PARAMS; } SymKeyImpl *returnSymmKey = (SymKeyImpl *)HcfMalloc(sizeof(SymKeyImpl), 0); if (returnSymmKey == NULL) { - LOGE("Failed to allocate returnKeyPair memory!"); + LOGE_ONE_STR("Failed to allocate returnKeyPair memory!"); return HCF_ERR_MALLOC; } HcfResult res = CopySymmKey(key, &returnSymmKey->keyMaterial); @@ -345,13 +345,13 @@ static HcfResult ConvertSymmKey(HcfSymKeyGeneratorSpi *self, const HcfBlob *key, HcfResult HcfSymKeyGeneratorSpiCreate(SymKeyAttr *attr, HcfSymKeyGeneratorSpi **generator) { if ((attr == NULL) || (generator == NULL)) { - LOGE("Invalid input parameter."); + LOGE_ONE_STR("Invalid input parameter."); return HCF_INVALID_PARAMS; } HcfSymKeyGeneratorSpiOpensslImpl *returnGenerator = (HcfSymKeyGeneratorSpiOpensslImpl *)HcfMalloc( sizeof(HcfSymKeyGeneratorSpiOpensslImpl), 0); if (returnGenerator == NULL) { - LOGE("Failed to allocate returnGenerator memory!"); + LOGE_ONE_STR("Failed to allocate returnGenerator memory!"); return HCF_ERR_MALLOC; } (void)memcpy_s(&returnGenerator->attr, sizeof(SymKeyAttr), attr, sizeof(SymKeyAttr)); diff --git a/test/unittest/src/aes_cipher/aes_common.cpp b/test/unittest/src/aes_cipher/aes_common.cpp index 22dfc4f676e3b62a60be1e08690ed5fea2412b3e..8881d17122e73bdc58c91f189676f22194d97803 100644 --- a/test/unittest/src/aes_cipher/aes_common.cpp +++ b/test/unittest/src/aes_cipher/aes_common.cpp @@ -49,13 +49,13 @@ int32_t GenerateSymKey(const char *algoName, HcfSymKey **key) int32_t ret = HcfSymKeyGeneratorCreate(algoName, &generator); if (ret != 0) { - LOGE("HcfSymKeyGeneratorCreate failed!"); + LOGE_ONE_STR("HcfSymKeyGeneratorCreate failed!"); return ret; } ret = generator->generateSymKey(generator, key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); } HcfObjDestroy(reinterpret_cast(generator)); return ret; @@ -78,7 +78,7 @@ int32_t ConvertSymKey(const char *algoName, HcfSymKey **key) ret = generator->convertSymKey(generator, &keyTmpBlob, key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); } PrintfHex("keybinary", keyTmpBlob.data, keyTmpBlob.len); HcfObjDestroy(reinterpret_cast(generator)); @@ -168,7 +168,7 @@ int32_t AesMultiBlockEncrypt(HcfCipher *cipher, HcfSymKey *key, HcfParamsSpec *p infile.read(reinterpret_cast(buffer), FILE_BLOCK_SIZE); ret = cipher->update(cipher, &input, &output); if (ret != 0) { - LOGE("update failed!"); + LOGE_ONE_STR("update failed!"); goto CLEAR_UP; } if (output.data != nullptr && output.len > 0) { @@ -181,7 +181,7 @@ int32_t AesMultiBlockEncrypt(HcfCipher *cipher, HcfSymKey *key, HcfParamsSpec *p } ret = cipher->doFinal(cipher, nullptr, &output); if (ret != 0) { - LOGE("doFinal failed!"); + LOGE_ONE_STR("doFinal failed!"); goto CLEAR_UP; } if (output.data != nullptr && output.len > 0) { @@ -222,7 +222,7 @@ int32_t AesMultiBlockDecrypt(HcfCipher *cipher, HcfSymKey *key, HcfParamsSpec *p infile.read(reinterpret_cast(buffer), FILE_BLOCK_SIZE); ret = cipher->update(cipher, &input, &output); if (ret != 0) { - LOGE("update failed!"); + LOGE_ONE_STR("update failed!"); goto CLEAR_UP; } if (output.data != nullptr && output.len > 0) { @@ -235,7 +235,7 @@ int32_t AesMultiBlockDecrypt(HcfCipher *cipher, HcfSymKey *key, HcfParamsSpec *p } ret = cipher->doFinal(cipher, nullptr, &output); if (ret != 0) { - LOGE("doFinal failed!"); + LOGE_ONE_STR("doFinal failed!"); goto CLEAR_UP; } if (output.data != nullptr && output.len > 0) { @@ -267,7 +267,7 @@ int32_t AesEncryptWithInput(HcfCipher *cipher, HcfSymKey *key, HcfBlob *input, ret = cipher->update(cipher, input, &output); if (ret != 0) { - LOGE("update failed!"); + LOGE_ONE_STR("update failed!"); return ret; } *cipherTextLen = output.len; @@ -281,7 +281,7 @@ int32_t AesEncryptWithInput(HcfCipher *cipher, HcfSymKey *key, HcfBlob *input, ret = cipher->doFinal(cipher, nullptr, &output); if (ret != 0) { - LOGE("doFinal failed!"); + LOGE_ONE_STR("doFinal failed!"); return ret; } if (output.data != nullptr) { @@ -312,7 +312,7 @@ int32_t AesEncrypt(HcfCipher *cipher, HcfSymKey *key, HcfParamsSpec *params, ret = cipher->update(cipher, &input, &output); if (ret != 0) { - LOGE("update failed!"); + LOGE_ONE_STR("update failed!"); return ret; } *cipherTextLen = output.len; @@ -326,7 +326,7 @@ int32_t AesEncrypt(HcfCipher *cipher, HcfSymKey *key, HcfParamsSpec *params, ret = cipher->doFinal(cipher, nullptr, &output); if (ret != 0) { - LOGE("doFinal failed!"); + LOGE_ONE_STR("doFinal failed!"); return ret; } if (output.data != nullptr) { @@ -357,7 +357,7 @@ int32_t AesDecrypt(HcfCipher *cipher, HcfSymKey *key, HcfParamsSpec *params, ret = cipher->update(cipher, &input, &output); if (ret != 0) { - LOGE("update failed!"); + LOGE_ONE_STR("update failed!"); return ret; } cipherTextLen = output.len; @@ -371,7 +371,7 @@ int32_t AesDecrypt(HcfCipher *cipher, HcfSymKey *key, HcfParamsSpec *params, ret = cipher->doFinal(cipher, nullptr, &output); if (ret != 0) { - LOGE("doFinal failed!"); + LOGE_ONE_STR("doFinal failed!"); return ret; } if (output.data != nullptr) { @@ -404,7 +404,7 @@ int32_t AesNoUpdateEncWithInput(HcfCipher *cipher, HcfSymKey *key, HcfBlob *inpu *cipherTextLen = 0; ret = cipher->doFinal(cipher, input, &output); if (ret != 0) { - LOGE("doFinal failed!"); + LOGE_ONE_STR("doFinal failed!"); return ret; } if (output.data != nullptr) { @@ -434,7 +434,7 @@ int32_t AesDecryptEmptyMsg(HcfCipher *cipher, HcfSymKey *key, HcfParamsSpec *par ret = cipher->doFinal(cipher, &input, &output); if (ret != 0) { - LOGE("doFinal failed!"); + LOGE_ONE_STR("doFinal failed!"); return ret; } if (output.len == 0 && output.data == nullptr) { @@ -462,7 +462,7 @@ int32_t AesNoUpdateEncrypt(HcfCipher *cipher, HcfSymKey *key, HcfParamsSpec *par *cipherTextLen = 0; ret = cipher->doFinal(cipher, &input, &output); if (ret != 0) { - LOGE("doFinal failed!"); + LOGE_ONE_STR("doFinal failed!"); return ret; } if (output.data != nullptr) { @@ -494,7 +494,7 @@ int32_t AesNoUpdateDecrypt(HcfCipher *cipher, HcfSymKey *key, HcfParamsSpec *par cipherTextLen = 0; ret = cipher->doFinal(cipher, &input, &output); if (ret != 0) { - LOGE("doFinal failed!"); + LOGE_ONE_STR("doFinal failed!"); return ret; } if (output.data != nullptr) { diff --git a/test/unittest/src/aes_cipher/crypto_aes_cbc_cipher_test.cpp b/test/unittest/src/aes_cipher/crypto_aes_cbc_cipher_test.cpp index 084b004ccce8d3297a4209f4342cb7da610da9c6..6f46ba0b9a8db1fb80d9d3704d4da72aea12e82b 100644 --- a/test/unittest/src/aes_cipher/crypto_aes_cbc_cipher_test.cpp +++ b/test/unittest/src/aes_cipher/crypto_aes_cbc_cipher_test.cpp @@ -64,13 +64,13 @@ HWTEST_F(CryptoAesCbcCipherTest, CryptoAesCbcCipherTest001, TestSize.Level0) ret = generator->generateSymKey(generator, &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); goto CLEAR_UP; } ret = HcfCipherCreate("AES128|CBC|NoPadding", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto CLEAR_UP; } @@ -115,13 +115,13 @@ HWTEST_F(CryptoAesCbcCipherTest, CryptoAesCbcCipherTest002, TestSize.Level0) ret = generator->generateSymKey(generator, &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); goto CLEAR_UP; } ret = HcfCipherCreate("AES128|CBC|PKCS5", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto CLEAR_UP; } @@ -166,13 +166,13 @@ HWTEST_F(CryptoAesCbcCipherTest, CryptoAesCbcCipherTest003, TestSize.Level0) ret = generator->generateSymKey(generator, &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); goto CLEAR_UP; } ret = HcfCipherCreate("AES128|CBC|PKCS7", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto CLEAR_UP; } @@ -217,13 +217,13 @@ HWTEST_F(CryptoAesCbcCipherTest, CryptoAesCbcCipherTest004, TestSize.Level0) ret = generator->generateSymKey(generator, &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); goto CLEAR_UP; } ret = HcfCipherCreate("AES128|CBC|NoPadding", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto CLEAR_UP; } @@ -268,13 +268,13 @@ HWTEST_F(CryptoAesCbcCipherTest, CryptoAesCbcCipherTest005, TestSize.Level0) ret = generator->generateSymKey(generator, &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); goto CLEAR_UP; } ret = HcfCipherCreate("AES128|CBC|PKCS5", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto CLEAR_UP; } @@ -319,13 +319,13 @@ HWTEST_F(CryptoAesCbcCipherTest, CryptoAesCbcCipherTest006, TestSize.Level0) ret = generator->generateSymKey(generator, &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); goto CLEAR_UP; } ret = HcfCipherCreate("AES128|CBC|PKCS7", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto CLEAR_UP; } @@ -361,19 +361,19 @@ HWTEST_F(CryptoAesCbcCipherTest, CryptoAesCbcCipherTest007, TestSize.Level0) ret = GeneratorFile("/data/test_aes.txt", 10 * FILE_BLOCK_SIZE); if (ret != 0) { - LOGE("GeneratorFile failed!"); + LOGE_ONE_STR("GeneratorFile failed!"); goto CLEAR_UP; } ret = ConvertSymKey("AES128", &key); if (ret != 0) { - LOGE("ConvertSymKey failed!"); + LOGE_ONE_STR("ConvertSymKey failed!"); goto CLEAR_UP; } ret = HcfCipherCreate("AES128|CBC|NoPadding", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto CLEAR_UP; } @@ -390,7 +390,7 @@ HWTEST_F(CryptoAesCbcCipherTest, CryptoAesCbcCipherTest007, TestSize.Level0) } ret = CompareFileContent(); if (ret != 0) { - LOGE("CompareFileContent failed!"); + LOGE_ONE_STR("CompareFileContent failed!"); goto CLEAR_UP; } @@ -415,13 +415,13 @@ HWTEST_F(CryptoAesCbcCipherTest, CryptoAesCbcCipherTest008, TestSize.Level0) ret = GenerateSymKey("AES192", &key); if (ret != 0) { - LOGE("GenerateSymKey failed!"); + LOGE_ONE_STR("GenerateSymKey failed!"); goto CLEAR_UP; } ret = HcfCipherCreate("AES192|CBC|PKCS5", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto CLEAR_UP; } @@ -457,13 +457,13 @@ HWTEST_F(CryptoAesCbcCipherTest, CryptoAesCbcCipherTest009, TestSize.Level0) ret = GenerateSymKey("AES256", &key); if (ret != 0) { - LOGE("GenerateSymKey failed!"); + LOGE_ONE_STR("GenerateSymKey failed!"); goto CLEAR_UP; } ret = HcfCipherCreate("AES256|CBC|PKCS5", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto CLEAR_UP; } diff --git a/test/unittest/src/aes_cipher/crypto_aes_ccm_cipher_test.cpp b/test/unittest/src/aes_cipher/crypto_aes_ccm_cipher_test.cpp index 4a91822e0ef3f66de3f69fba2347dad52a8c1fef..17d6e51d131fbce2b02c0b6ee2c712a44cf9827c 100644 --- a/test/unittest/src/aes_cipher/crypto_aes_ccm_cipher_test.cpp +++ b/test/unittest/src/aes_cipher/crypto_aes_ccm_cipher_test.cpp @@ -63,19 +63,19 @@ HWTEST_F(CryptoAesCcmCipherTest, CryptoAesCcmCipherTest001, TestSize.Level0) ret = GenerateSymKey("AES128", &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); goto CLEAR_UP; } ret = HcfCipherCreate("AES128|CCM|NoPadding", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto CLEAR_UP; } ret = AesEncrypt(cipher, key, (HcfParamsSpec *)&spec, cipherText, &cipherTextLen); if (ret != 0) { - LOGE("AesEncrypt failed!"); + LOGE_ONE_STR("AesEncrypt failed!"); goto CLEAR_UP; } @@ -85,7 +85,7 @@ HWTEST_F(CryptoAesCcmCipherTest, CryptoAesCcmCipherTest001, TestSize.Level0) ret = AesDecrypt(cipher, key, (HcfParamsSpec *)&spec, cipherText, cipherTextLen); if (ret != 0) { - LOGE("AesDecrypt failed!"); + LOGE_ONE_STR("AesDecrypt failed!"); goto CLEAR_UP; } @@ -116,19 +116,19 @@ HWTEST_F(CryptoAesCcmCipherTest, CryptoAesCcmCipherTest002, TestSize.Level0) ret = GenerateSymKey("AES128", &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); goto CLEAR_UP; } ret = HcfCipherCreate("AES128|CCM|PKCS5", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto CLEAR_UP; } ret = AesEncrypt(cipher, key, (HcfParamsSpec *)&spec, cipherText, &cipherTextLen); if (ret != 0) { - LOGE("AesEncrypt failed!"); + LOGE_ONE_STR("AesEncrypt failed!"); goto CLEAR_UP; } @@ -138,7 +138,7 @@ HWTEST_F(CryptoAesCcmCipherTest, CryptoAesCcmCipherTest002, TestSize.Level0) ret = AesDecrypt(cipher, key, (HcfParamsSpec *)&spec, cipherText, cipherTextLen); if (ret != 0) { - LOGE("AesDecrypt failed!"); + LOGE_ONE_STR("AesDecrypt failed!"); goto CLEAR_UP; } @@ -169,19 +169,19 @@ HWTEST_F(CryptoAesCcmCipherTest, CryptoAesCcmCipherTest003, TestSize.Level0) ret = GenerateSymKey("AES128", &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); goto CLEAR_UP; } ret = HcfCipherCreate("AES128|CCM|PKCS7", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto CLEAR_UP; } ret = AesEncrypt(cipher, key, (HcfParamsSpec *)&spec, cipherText, &cipherTextLen); if (ret != 0) { - LOGE("AesEncrypt failed!"); + LOGE_ONE_STR("AesEncrypt failed!"); goto CLEAR_UP; } @@ -191,7 +191,7 @@ HWTEST_F(CryptoAesCcmCipherTest, CryptoAesCcmCipherTest003, TestSize.Level0) ret = AesDecrypt(cipher, key, (HcfParamsSpec *)&spec, cipherText, cipherTextLen); if (ret != 0) { - LOGE("AesDecrypt failed!"); + LOGE_ONE_STR("AesDecrypt failed!"); goto CLEAR_UP; } @@ -222,19 +222,19 @@ HWTEST_F(CryptoAesCcmCipherTest, CryptoAesCcmCipherTest004, TestSize.Level0) ret = GenerateSymKey("AES128", &key); if (ret != 0) { - LOGE("GenerateSymKey failed!"); + LOGE_ONE_STR("GenerateSymKey failed!"); goto CLEAR_UP; } ret = HcfCipherCreate("AES128|CCM|NoPadding", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto CLEAR_UP; } ret = AesNoUpdateEncrypt(cipher, key, (HcfParamsSpec *)&spec, cipherText, &cipherTextLen); if (ret != 0) { - LOGE("AesNoUpdateEncrypt failed!"); + LOGE_ONE_STR("AesNoUpdateEncrypt failed!"); goto CLEAR_UP; } @@ -244,7 +244,7 @@ HWTEST_F(CryptoAesCcmCipherTest, CryptoAesCcmCipherTest004, TestSize.Level0) ret = AesNoUpdateDecrypt(cipher, key, (HcfParamsSpec *)&spec, cipherText, cipherTextLen); if (ret != 0) { - LOGE("AesNoUpdateDecrypt failed!"); + LOGE_ONE_STR("AesNoUpdateDecrypt failed!"); goto CLEAR_UP; } @@ -275,19 +275,19 @@ HWTEST_F(CryptoAesCcmCipherTest, CryptoAesCcmCipherTest005, TestSize.Level0) ret = GenerateSymKey("AES128", &key); if (ret != 0) { - LOGE("GenerateSymKey failed!"); + LOGE_ONE_STR("GenerateSymKey failed!"); goto CLEAR_UP; } ret = HcfCipherCreate("AES128|CCM|PKCS5", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto CLEAR_UP; } ret = AesNoUpdateEncrypt(cipher, key, (HcfParamsSpec *)&spec, cipherText, &cipherTextLen); if (ret != 0) { - LOGE("AesNoUpdateEncrypt failed!"); + LOGE_ONE_STR("AesNoUpdateEncrypt failed!"); goto CLEAR_UP; } @@ -297,7 +297,7 @@ HWTEST_F(CryptoAesCcmCipherTest, CryptoAesCcmCipherTest005, TestSize.Level0) ret = AesNoUpdateDecrypt(cipher, key, (HcfParamsSpec *)&spec, cipherText, cipherTextLen); if (ret != 0) { - LOGE("AesNoUpdateDecrypt failed!"); + LOGE_ONE_STR("AesNoUpdateDecrypt failed!"); goto CLEAR_UP; } @@ -329,19 +329,19 @@ HWTEST_F(CryptoAesCcmCipherTest, CryptoAesCcmCipherTest006, TestSize.Level0) ret = GenerateSymKey("AES128", &key); if (ret != 0) { - LOGE("GenerateSymKey failed!"); + LOGE_ONE_STR("GenerateSymKey failed!"); goto CLEAR_UP; } ret = HcfCipherCreate("AES128|CCM|PKCS7", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto CLEAR_UP; } ret = AesNoUpdateEncrypt(cipher, key, (HcfParamsSpec *)&spec, cipherText, &cipherTextLen); if (ret != 0) { - LOGE("AesNoUpdateEncrypt failed!"); + LOGE_ONE_STR("AesNoUpdateEncrypt failed!"); goto CLEAR_UP; } @@ -351,7 +351,7 @@ HWTEST_F(CryptoAesCcmCipherTest, CryptoAesCcmCipherTest006, TestSize.Level0) ret = AesNoUpdateDecrypt(cipher, key, (HcfParamsSpec *)&spec, cipherText, cipherTextLen); if (ret != 0) { - LOGE("AesNoUpdateDecrypt failed!"); + LOGE_ONE_STR("AesNoUpdateDecrypt failed!"); goto CLEAR_UP; } @@ -382,19 +382,19 @@ HWTEST_F(CryptoAesCcmCipherTest, CryptoAesCcmCipherTest007, TestSize.Level0) ret = GenerateSymKey("AES192", &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); goto CLEAR_UP; } ret = HcfCipherCreate("AES192|CCM|PKCS5", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto CLEAR_UP; } ret = AesEncrypt(cipher, key, &(spec.base), cipherText, &cipherTextLen); if (ret != 0) { - LOGE("AesEncrypt failed!"); + LOGE_ONE_STR("AesEncrypt failed!"); goto CLEAR_UP; } @@ -404,7 +404,7 @@ HWTEST_F(CryptoAesCcmCipherTest, CryptoAesCcmCipherTest007, TestSize.Level0) ret = AesDecrypt(cipher, key, &(spec.base), cipherText, cipherTextLen); if (ret != 0) { - LOGE("AesDecrypt failed!"); + LOGE_ONE_STR("AesDecrypt failed!"); } CLEAR_UP: @@ -434,19 +434,19 @@ HWTEST_F(CryptoAesCcmCipherTest, CryptoAesCcmCipherTest008, TestSize.Level0) ret = GenerateSymKey("AES256", &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); goto CLEAR_UP; } ret = HcfCipherCreate("AES256|CCM|PKCS5", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto CLEAR_UP; } ret = AesEncrypt(cipher, key, &(spec.base), cipherText, &cipherTextLen); if (ret != 0) { - LOGE("AesEncrypt failed!"); + LOGE_ONE_STR("AesEncrypt failed!"); goto CLEAR_UP; } @@ -456,7 +456,7 @@ HWTEST_F(CryptoAesCcmCipherTest, CryptoAesCcmCipherTest008, TestSize.Level0) ret = AesDecrypt(cipher, key, &(spec.base), cipherText, cipherTextLen); if (ret != 0) { - LOGE("AesDecrypt failed!"); + LOGE_ONE_STR("AesDecrypt failed!"); } CLEAR_UP: @@ -476,19 +476,19 @@ HWTEST_F(CryptoAesCcmCipherTest, CryptoAesCcmCipherTest009, TestSize.Level0) ret = GenerateSymKey("AES128", &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); goto CLEAR_UP; } ret = HcfCipherCreate("AES128|CCM|NoPadding", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto CLEAR_UP; } ret = AesEncrypt(cipher, key, nullptr, cipherText, &cipherTextLen); if (ret != 0) { - LOGE("AesEncrypt failed!"); + LOGE_ONE_STR("AesEncrypt failed!"); } CLEAR_UP: @@ -518,19 +518,19 @@ HWTEST_F(CryptoAesCcmCipherTest, CryptoAesCcmCipherTest010, TestSize.Level0) ret = GenerateSymKey("AES128", &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); goto CLEAR_UP; } ret = HcfCipherCreate("AES128|CCM|NoPadding", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto CLEAR_UP; } ret = AesEncrypt(cipher, key, &(spec.base), cipherText, &cipherTextLen); if (ret != 0) { - LOGE("AesEncrypt failed!"); + LOGE_ONE_STR("AesEncrypt failed!"); } CLEAR_UP: @@ -560,19 +560,19 @@ HWTEST_F(CryptoAesCcmCipherTest, CryptoAesCcmCipherTest011, TestSize.Level0) ret = GenerateSymKey("AES128", &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); goto CLEAR_UP; } ret = HcfCipherCreate("AES128|CCM|NoPadding", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto CLEAR_UP; } ret = AesEncrypt(cipher, key, &(spec.base), cipherText, &cipherTextLen); if (ret != 0) { - LOGE("AesEncrypt failed!"); + LOGE_ONE_STR("AesEncrypt failed!"); } CLEAR_UP: @@ -602,19 +602,19 @@ HWTEST_F(CryptoAesCcmCipherTest, CryptoAesCcmCipherTest012, TestSize.Level0) ret = GenerateSymKey("AES128", &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); goto CLEAR_UP; } ret = HcfCipherCreate("AES128|CCM|NoPadding", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto CLEAR_UP; } ret = AesEncrypt(cipher, key, &(spec.base), cipherText, &cipherTextLen); if (ret != 0) { - LOGE("AesEncrypt failed!"); + LOGE_ONE_STR("AesEncrypt failed!"); } CLEAR_UP: @@ -632,13 +632,13 @@ HWTEST_F(CryptoAesCcmCipherTest, CryptoAesCcmCipherTest013, TestSize.Level0) ret = HcfSymKeyGeneratorCreate("AES128", &generator); if (ret != 0) { - LOGE("HcfSymKeyGeneratorCreate failed!"); + LOGE_ONE_STR("HcfSymKeyGeneratorCreate failed!"); goto CLEAR_UP; } EXPECT_EQ(ret, HCF_SUCCESS); ret = generator->generateSymKey(generator, &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); goto CLEAR_UP; } generator->base.destroy(nullptr); diff --git a/test/unittest/src/aes_cipher/crypto_aes_cfb_cipher_test.cpp b/test/unittest/src/aes_cipher/crypto_aes_cfb_cipher_test.cpp index b9bfbbf17e265f006a11112c1b10a411fecbebc9..451fcd4b68d0ab034e61210c3f712389d8b898b6 100644 --- a/test/unittest/src/aes_cipher/crypto_aes_cfb_cipher_test.cpp +++ b/test/unittest/src/aes_cipher/crypto_aes_cfb_cipher_test.cpp @@ -64,13 +64,13 @@ HWTEST_F(CryptoAesCfbCipherTest, CryptoAesCfbCipherTest001, TestSize.Level0) ret = generator->generateSymKey(generator, &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); goto CLEAR_UP; } ret = HcfCipherCreate("AES128|CFB|NoPadding", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto CLEAR_UP; } @@ -115,13 +115,13 @@ HWTEST_F(CryptoAesCfbCipherTest, CryptoAesCfbCipherTest002, TestSize.Level0) ret = generator->generateSymKey(generator, &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); goto CLEAR_UP; } ret = HcfCipherCreate("AES128|CFB|PKCS5", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto CLEAR_UP; } @@ -166,13 +166,13 @@ HWTEST_F(CryptoAesCfbCipherTest, CryptoAesCfbCipherTest003, TestSize.Level0) ret = generator->generateSymKey(generator, &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); goto CLEAR_UP; } ret = HcfCipherCreate("AES128|CFB|PKCS7", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto CLEAR_UP; } @@ -218,13 +218,13 @@ HWTEST_F(CryptoAesCfbCipherTest, CryptoAesCfbCipherTest004, TestSize.Level0) ret = generator->generateSymKey(generator, &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); goto CLEAR_UP; } ret = HcfCipherCreate("AES128|CFB1|NoPadding", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto CLEAR_UP; } @@ -269,13 +269,13 @@ HWTEST_F(CryptoAesCfbCipherTest, CryptoAesCfbCipherTest005, TestSize.Level0) ret = generator->generateSymKey(generator, &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); goto CLEAR_UP; } ret = HcfCipherCreate("AES128|CFB1|PKCS5", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto CLEAR_UP; } @@ -320,12 +320,12 @@ HWTEST_F(CryptoAesCfbCipherTest, CryptoAesCfbCipherTest006, TestSize.Level0) ret = generator->generateSymKey(generator, &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); } ret = HcfCipherCreate("AES128|CFB1|PKCS7", &cipher); // CFB1/CFB8/CFB128 bit if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto CLEAR_UP; } @@ -370,12 +370,12 @@ HWTEST_F(CryptoAesCfbCipherTest, CryptoAesCfbCipherTest007, TestSize.Level0) ret = generator->generateSymKey(generator, &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); } ret = HcfCipherCreate("AES128|CFB8|NoPadding", &cipher); // CFB1/CFB8/CFB128 bit if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto CLEAR_UP; } @@ -420,12 +420,12 @@ HWTEST_F(CryptoAesCfbCipherTest, CryptoAesCfbCipherTest008, TestSize.Level0) ret = generator->generateSymKey(generator, &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); } ret = HcfCipherCreate("AES128|CFB8|PKCS5", &cipher); // CFB1/CFB8/CFB128 bit if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto CLEAR_UP; } @@ -470,12 +470,12 @@ HWTEST_F(CryptoAesCfbCipherTest, CryptoAesCfbCipherTest009, TestSize.Level0) ret = generator->generateSymKey(generator, &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); } ret = HcfCipherCreate("AES128|CFB8|PKCS7", &cipher); // CFB1/CFB8/CFB128 bit if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto CLEAR_UP; } @@ -520,12 +520,12 @@ HWTEST_F(CryptoAesCfbCipherTest, CryptoAesCfbCipherTest010, TestSize.Level0) ret = generator->generateSymKey(generator, &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); } ret = HcfCipherCreate("AES128|CFB128|NoPadding", &cipher); // CFB1/CFB8/CFB128 bit if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto CLEAR_UP; } @@ -570,12 +570,12 @@ HWTEST_F(CryptoAesCfbCipherTest, CryptoAesCfbCipherTest011, TestSize.Level0) ret = generator->generateSymKey(generator, &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); } ret = HcfCipherCreate("AES128|CFB128|PKCS5", &cipher); // CFB1/CFB8/CFB128 bit if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto CLEAR_UP; } @@ -620,12 +620,12 @@ HWTEST_F(CryptoAesCfbCipherTest, CryptoAesCfbCipherTest012, TestSize.Level0) ret = generator->generateSymKey(generator, &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); } ret = HcfCipherCreate("AES128|CFB128|PKCS7", &cipher); // CFB1/CFB8/CFB128 bit if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto CLEAR_UP; } @@ -670,13 +670,13 @@ HWTEST_F(CryptoAesCfbCipherTest, CryptoAesCfbCipherTest013, TestSize.Level0) ret = generator->generateSymKey(generator, &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); goto CLEAR_UP; } ret = HcfCipherCreate("AES128|CFB|NoPadding", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto CLEAR_UP; } @@ -721,13 +721,13 @@ HWTEST_F(CryptoAesCfbCipherTest, CryptoAesCfbCipherTest014, TestSize.Level0) ret = generator->generateSymKey(generator, &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); goto CLEAR_UP; } ret = HcfCipherCreate("AES128|CFB|PKCS5", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto CLEAR_UP; } @@ -772,13 +772,13 @@ HWTEST_F(CryptoAesCfbCipherTest, CryptoAesCfbCipherTest015, TestSize.Level0) ret = generator->generateSymKey(generator, &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); goto CLEAR_UP; } ret = HcfCipherCreate("AES128|CFB|PKCS7", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto CLEAR_UP; } @@ -824,13 +824,13 @@ HWTEST_F(CryptoAesCfbCipherTest, CryptoAesCfbCipherTest016, TestSize.Level0) ret = generator->generateSymKey(generator, &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); goto CLEAR_UP; } ret = HcfCipherCreate("AES128|CFB1|NoPadding", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto CLEAR_UP; } @@ -875,13 +875,13 @@ HWTEST_F(CryptoAesCfbCipherTest, CryptoAesCfbCipherTest017, TestSize.Level0) ret = generator->generateSymKey(generator, &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); goto CLEAR_UP; } ret = HcfCipherCreate("AES128|CFB1|PKCS5", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto CLEAR_UP; } @@ -926,12 +926,12 @@ HWTEST_F(CryptoAesCfbCipherTest, CryptoAesCfbCipherTest018, TestSize.Level0) ret = generator->generateSymKey(generator, &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); } ret = HcfCipherCreate("AES128|CFB1|PKCS7", &cipher); // CFB1/CFB8/CFB128 bit if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto CLEAR_UP; } @@ -976,12 +976,12 @@ HWTEST_F(CryptoAesCfbCipherTest, CryptoAesCfbCipherTest019, TestSize.Level0) ret = generator->generateSymKey(generator, &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); } ret = HcfCipherCreate("AES128|CFB8|NoPadding", &cipher); // CFB1/CFB8/CFB128 bit if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto CLEAR_UP; } @@ -1026,12 +1026,12 @@ HWTEST_F(CryptoAesCfbCipherTest, CryptoAesCfbCipherTest020, TestSize.Level0) ret = generator->generateSymKey(generator, &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); } ret = HcfCipherCreate("AES128|CFB8|PKCS5", &cipher); // CFB1/CFB8/CFB128 bit if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto CLEAR_UP; } @@ -1076,12 +1076,12 @@ HWTEST_F(CryptoAesCfbCipherTest, CryptoAesCfbCipherTest021, TestSize.Level0) ret = generator->generateSymKey(generator, &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); } ret = HcfCipherCreate("AES128|CFB8|PKCS7", &cipher); // CFB1/CFB8/CFB128 bit if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto CLEAR_UP; } ret = AesNoUpdateEncrypt(cipher, key, (HcfParamsSpec *)&ivSpec, cipherText, &cipherTextLen); @@ -1125,12 +1125,12 @@ HWTEST_F(CryptoAesCfbCipherTest, CryptoAesCfbCipherTest022, TestSize.Level0) ret = generator->generateSymKey(generator, &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); } ret = HcfCipherCreate("AES128|CFB128|NoPadding", &cipher); // CFB1/CFB8/CFB128 bit if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto CLEAR_UP; } ret = AesNoUpdateEncrypt(cipher, key, (HcfParamsSpec *)&ivSpec, cipherText, &cipherTextLen); @@ -1174,12 +1174,12 @@ HWTEST_F(CryptoAesCfbCipherTest, CryptoAesCfbCipherTest023, TestSize.Level0) ret = generator->generateSymKey(generator, &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); } ret = HcfCipherCreate("AES128|CFB128|PKCS5", &cipher); // CFB1/CFB8/CFB128 bit if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto CLEAR_UP; } ret = AesNoUpdateEncrypt(cipher, key, (HcfParamsSpec *)&ivSpec, cipherText, &cipherTextLen); @@ -1223,12 +1223,12 @@ HWTEST_F(CryptoAesCfbCipherTest, CryptoAesCfbCipherTest024, TestSize.Level0) ret = generator->generateSymKey(generator, &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); } ret = HcfCipherCreate("AES128|CFB128|PKCS7", &cipher); // CFB1/CFB8/CFB128 bit if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto CLEAR_UP; } ret = AesNoUpdateEncrypt(cipher, key, (HcfParamsSpec *)&ivSpec, cipherText, &cipherTextLen); @@ -1263,18 +1263,18 @@ HWTEST_F(CryptoAesCfbCipherTest, CryptoAesCfbCipherTest025, TestSize.Level0) ret = GenerateSymKey("AES128", &key); if (ret != 0) { - LOGE("GenerateSymKey failed!"); + LOGE_ONE_STR("GenerateSymKey failed!"); goto CLEAR_UP; } ret = HcfCipherCreate("AES128|CFB|NoPadding", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto CLEAR_UP; } ret = GeneratorFile("/data/test_aes.txt", 10 * FILE_BLOCK_SIZE); if (ret != 0) { - LOGE("GeneratorFile failed!"); + LOGE_ONE_STR("GeneratorFile failed!"); goto CLEAR_UP; } @@ -1291,7 +1291,7 @@ HWTEST_F(CryptoAesCfbCipherTest, CryptoAesCfbCipherTest025, TestSize.Level0) } ret = CompareFileContent(); if (ret != 0) { - LOGE("CompareFileContent failed!"); + LOGE_ONE_STR("CompareFileContent failed!"); goto CLEAR_UP; } @@ -1316,13 +1316,13 @@ HWTEST_F(CryptoAesCfbCipherTest, CryptoAesCfbCipherTest026, TestSize.Level0) ret = GenerateSymKey("AES192", &key); if (ret != 0) { - LOGE("GenerateSymKey failed!"); + LOGE_ONE_STR("GenerateSymKey failed!"); goto CLEAR_UP; } ret = HcfCipherCreate("AES192|CFB|PKCS5", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto CLEAR_UP; } @@ -1358,13 +1358,13 @@ HWTEST_F(CryptoAesCfbCipherTest, CryptoAesCfbCipherTest027, TestSize.Level0) ret = GenerateSymKey("AES256", &key); if (ret != 0) { - LOGE("GenerateSymKey failed!"); + LOGE_ONE_STR("GenerateSymKey failed!"); goto CLEAR_UP; } ret = HcfCipherCreate("AES256|CFB|PKCS5", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto CLEAR_UP; } @@ -1400,13 +1400,13 @@ HWTEST_F(CryptoAesCfbCipherTest, CryptoAesCfbCipherTest028, TestSize.Level0) ret = GenerateSymKey("AES192", &key); if (ret != 0) { - LOGE("GenerateSymKey failed!"); + LOGE_ONE_STR("GenerateSymKey failed!"); goto CLEAR_UP; } ret = HcfCipherCreate("AES192|CFB1|PKCS5", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto CLEAR_UP; } @@ -1443,13 +1443,13 @@ HWTEST_F(CryptoAesCfbCipherTest, CryptoAesCfbCipherTest029, TestSize.Level0) ret = GenerateSymKey("AES256", &key); if (ret != 0) { - LOGE("GenerateSymKey failed!"); + LOGE_ONE_STR("GenerateSymKey failed!"); goto CLEAR_UP; } ret = HcfCipherCreate("AES256|CFB1|PKCS5", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto CLEAR_UP; } @@ -1485,13 +1485,13 @@ HWTEST_F(CryptoAesCfbCipherTest, CryptoAesCfbCipherTest030, TestSize.Level0) ret = GenerateSymKey("AES192", &key); if (ret != 0) { - LOGE("GenerateSymKey failed!"); + LOGE_ONE_STR("GenerateSymKey failed!"); goto CLEAR_UP; } ret = HcfCipherCreate("AES192|CFB8|PKCS5", &cipher); // CFB1/CFB8/CFB128 bit if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto CLEAR_UP; } @@ -1527,13 +1527,13 @@ HWTEST_F(CryptoAesCfbCipherTest, CryptoAesCfbCipherTest031, TestSize.Level0) ret = GenerateSymKey("AES256", &key); if (ret != 0) { - LOGE("GenerateSymKey failed!"); + LOGE_ONE_STR("GenerateSymKey failed!"); goto CLEAR_UP; } ret = HcfCipherCreate("AES256|CFB8|PKCS5", &cipher); // CFB1/CFB8/CFB128 bit if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto CLEAR_UP; } @@ -1569,13 +1569,13 @@ HWTEST_F(CryptoAesCfbCipherTest, CryptoAesCfbCipherTest032, TestSize.Level0) ret = GenerateSymKey("AES192", &key); if (ret != 0) { - LOGE("GenerateSymKey failed!"); + LOGE_ONE_STR("GenerateSymKey failed!"); goto CLEAR_UP; } ret = HcfCipherCreate("AES192|CFB128|PKCS5", &cipher); // CFB1/CFB8/CFB128 bit if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto CLEAR_UP; } @@ -1611,13 +1611,13 @@ HWTEST_F(CryptoAesCfbCipherTest, CryptoAesCfbCipherTest033, TestSize.Level0) ret = GenerateSymKey("AES256", &key); if (ret != 0) { - LOGE("GenerateSymKey failed!"); + LOGE_ONE_STR("GenerateSymKey failed!"); goto CLEAR_UP; } ret = HcfCipherCreate("AES256|CFB128|PKCS5", &cipher); // CFB1/CFB8/CFB128 bit if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto CLEAR_UP; } @@ -1646,20 +1646,20 @@ HWTEST_F(CryptoAesCfbCipherTest, CryptoAesCfbCipherTest034, TestSize.Level0) const char *retAlgo = nullptr; ret = HcfCipherCreate(cipherName, &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto CLEAR_UP; } retAlgo = cipher->getAlgorithm(cipher); if (retAlgo == nullptr) { - LOGE("cipher getAlgorithm failed!"); + LOGE_ONE_STR("cipher getAlgorithm failed!"); ret = HCF_ERR_CRYPTO_OPERATION; goto CLEAR_UP; } ret = strcmp(retAlgo, cipherName); if (ret != 0) { - LOGE("cipher getAlgorithm failed!"); + LOGE_ONE_STR("cipher getAlgorithm failed!"); } CLEAR_UP: HcfObjDestroy(cipher); @@ -1674,13 +1674,13 @@ HWTEST_F(CryptoAesCfbCipherTest, CryptoAesCfbCipherTest035, TestSize.Level0) const char *retAlgo = nullptr; ret = HcfCipherCreate(cipherName, &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto CLEAR_UP; } retAlgo = cipher->getAlgorithm(nullptr); if (retAlgo == nullptr) { - LOGE("cipher getAlgorithm failed!"); + LOGE_ONE_STR("cipher getAlgorithm failed!"); ret = HCF_ERR_CRYPTO_OPERATION; } @@ -1705,13 +1705,13 @@ HWTEST_F(CryptoAesCfbCipherTest, CryptoAesCfbCipherTest036, TestSize.Level0) ret = HcfCipherCreate(cipherName, &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto CLEAR_UP; } retAlgo = cipher->getAlgorithm(reinterpret_cast(generator)); if (retAlgo == nullptr) { - LOGE("cipher getAlgorithm failed!"); + LOGE_ONE_STR("cipher getAlgorithm failed!"); ret = HCF_ERR_CRYPTO_OPERATION; } @@ -1731,13 +1731,13 @@ HWTEST_F(CryptoAesCfbCipherTest, CryptoAesCfbCipherTest037, TestSize.Level0) ret = GenerateSymKey("AES256", &key); if (ret != 0) { - LOGE("GenerateSymKey failed!"); + LOGE_ONE_STR("GenerateSymKey failed!"); goto CLEAR_UP; } ret = HcfCipherCreate("AES256|CFB128|PKCS5", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto CLEAR_UP; } diff --git a/test/unittest/src/aes_cipher/crypto_aes_cipher_test.cpp b/test/unittest/src/aes_cipher/crypto_aes_cipher_test.cpp index 07d80f2ef0af88b0300e8d6cdacef0a7b89de665..51870cb7a16de8ee5e0e561e9e4e3905be393655 100644 --- a/test/unittest/src/aes_cipher/crypto_aes_cipher_test.cpp +++ b/test/unittest/src/aes_cipher/crypto_aes_cipher_test.cpp @@ -57,21 +57,21 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest001, TestSize.Level0) } ret = generator->generateSymKey(generator, &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); goto CLEAR_UP; } // generator getAlgoName generatorAlgoName = generator->getAlgoName(generator); if (generatorAlgoName == nullptr) { - LOGE("generator getAlgoName returns nullptr."); + LOGE_ONE_STR("generator getAlgoName returns nullptr."); ret = HCF_ERR_CRYPTO_OPERATION; goto CLEAR_UP; } ret = strcmp(generatorAlgoName, inputAlgoName); if (ret != 0) { - LOGE("generator getAlgoName failed!"); + LOGE_ONE_STR("generator getAlgoName failed!"); } CLEAR_UP: HcfObjDestroy(key); @@ -95,7 +95,7 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest002, TestSize.Level0) // generator getAlgoName generatorAlgoName = generator->getAlgoName(nullptr); if (generatorAlgoName == nullptr) { - LOGE("generator getAlgoName failed!"); + LOGE_ONE_STR("generator getAlgoName failed!"); ret = HCF_ERR_CRYPTO_OPERATION; } @@ -119,14 +119,14 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest003, TestSize.Level0) } ret = generator->generateSymKey(generator, &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); goto CLEAR_UP; } // generator getAlgoName generatorAlgoName = generator->getAlgoName(reinterpret_cast(key)); if (generatorAlgoName == nullptr) { - LOGE("generator getAlgoName failed!"); + LOGE_ONE_STR("generator getAlgoName failed!"); ret = HCF_ERR_CRYPTO_OPERATION; } @@ -145,21 +145,21 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest004, TestSize.Level0) ret = GenerateSymKey(inputAlgoName, &key); if (ret != 0) { - LOGE("GenerateSymKey failed!"); + LOGE_ONE_STR("GenerateSymKey failed!"); goto CLEAR_UP; } // key getAlgorithm keyAlgoName = key->key.getAlgorithm(&(key->key)); if (keyAlgoName == nullptr) { - LOGE("key getAlgorithm returns nullptr."); + LOGE_ONE_STR("key getAlgorithm returns nullptr."); ret = HCF_ERR_CRYPTO_OPERATION; goto CLEAR_UP; } ret = strcmp(keyAlgoName, inputAlgoName); if (ret != 0) { - LOGE("key getAlgorithm failed!"); + LOGE_ONE_STR("key getAlgorithm failed!"); } CLEAR_UP: HcfObjDestroy(key); @@ -175,14 +175,14 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest005, TestSize.Level0) ret = GenerateSymKey(inputAlgoName, &key); if (ret != 0) { - LOGE("GenerateSymKey failed!"); + LOGE_ONE_STR("GenerateSymKey failed!"); goto CLEAR_UP; } // key getAlgorithm keyAlgoName = key->key.getAlgorithm(nullptr); if (keyAlgoName == nullptr) { - LOGE("key getAlgorithm returns nullptr."); + LOGE_ONE_STR("key getAlgorithm returns nullptr."); ret = HCF_ERR_CRYPTO_OPERATION; } @@ -206,14 +206,14 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest006, TestSize.Level0) } ret = generator->generateSymKey(generator, &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); goto CLEAR_UP; } // key getAlgorithm keyAlgoName = key->key.getAlgorithm(reinterpret_cast(generator)); if (keyAlgoName == nullptr) { - LOGE("key getAlgorithm returns nullptr."); + LOGE_ONE_STR("key getAlgorithm returns nullptr."); ret = HCF_ERR_CRYPTO_OPERATION; } @@ -232,21 +232,21 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest007, TestSize.Level0) ret = GenerateSymKey("AES128", &key); if (ret != 0) { - LOGE("GenerateSymKey failed!"); + LOGE_ONE_STR("GenerateSymKey failed!"); goto CLEAR_UP; } // key GetFormat retFormat = key->key.getFormat(&(key->key)); if (retFormat == nullptr) { - LOGE("key GetFormat returns nullptr."); + LOGE_ONE_STR("key GetFormat returns nullptr."); ret = HCF_ERR_CRYPTO_OPERATION; goto CLEAR_UP; } ret = strcmp(retFormat, keyFormat); if (ret != 0) { - LOGE("key GetFormat failed!"); + LOGE_ONE_STR("key GetFormat failed!"); } CLEAR_UP: @@ -262,14 +262,14 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest008, TestSize.Level0) ret = GenerateSymKey("AES128", &key); if (ret != 0) { - LOGE("GenerateSymKey failed!"); + LOGE_ONE_STR("GenerateSymKey failed!"); goto CLEAR_UP; } // key getFormat retFormat = key->key.getFormat(nullptr); if (retFormat == nullptr) { - LOGE("key GetFormat returns nullptr."); + LOGE_ONE_STR("key GetFormat returns nullptr."); ret = HCF_ERR_CRYPTO_OPERATION; } @@ -292,14 +292,14 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest009, TestSize.Level0) } ret = generator->generateSymKey(generator, &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); goto CLEAR_UP; } // key getFormat retFormat = key->key.getFormat(reinterpret_cast(generator)); if (retFormat == nullptr) { - LOGE("key GetFormat returns nullptr."); + LOGE_ONE_STR("key GetFormat returns nullptr."); ret = HCF_ERR_CRYPTO_OPERATION; } @@ -328,19 +328,19 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest010, TestSize.Level0) } ret = generator->convertSymKey(generator, &keyTmpBlob, &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); goto CLEAR_UP; } // key getEncoded ret = key->key.getEncoded(&(key->key), &encodedBlob); if (ret != 0) { - LOGE("key GetEncoded failed."); + LOGE_ONE_STR("key GetEncoded failed."); goto CLEAR_UP; } if (encodedBlob.len != keyTmpBlob.len) { - LOGE("key GetEncoded failed!"); + LOGE_ONE_STR("key GetEncoded failed!"); ret = HCF_ERR_CRYPTO_OPERATION; goto CLEAR_UP; } @@ -375,14 +375,14 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest011, TestSize.Level0) } ret = generator->convertSymKey(generator, &keyTmpBlob, &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); goto CLEAR_UP; } // key getEncoded ret = key->key.getEncoded(nullptr, &encodedBlob); if (ret != 0) { - LOGE("key GetEncoded failed."); + LOGE_ONE_STR("key GetEncoded failed."); } CLEAR_UP: @@ -414,14 +414,14 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest012, TestSize.Level0) } ret = generator->convertSymKey(generator, &keyTmpBlob, &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); goto CLEAR_UP; } // key getEncoded ret = key->key.getEncoded(reinterpret_cast(generator), &encodedBlob); if (ret != 0) { - LOGE("key GetEncoded failed."); + LOGE_ONE_STR("key GetEncoded failed."); } CLEAR_UP: @@ -455,7 +455,7 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest013, TestSize.Level0) } ret = generator->convertSymKey(generator, &keyTmpBlob, &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); goto CLEAR_UP; } impl = reinterpret_cast(key); @@ -466,7 +466,7 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest013, TestSize.Level0) ret = key->key.getEncoded(&(key->key), &encodedBlob); impl->keyMaterial.len = tmpLen; if (ret != 0) { - LOGE("key GetEncoded failed."); + LOGE_ONE_STR("key GetEncoded failed."); } CLEAR_UP: @@ -498,7 +498,7 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest014, TestSize.Level0) } ret = generator->convertSymKey(generator, &keyTmpBlob, &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); goto CLEAR_UP; } @@ -506,11 +506,11 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest014, TestSize.Level0) ret = key->key.getEncoded(&(key->key), &encodedBlob); if (ret != 0) { - LOGE("key GetEncoded failed."); + LOGE_ONE_STR("key GetEncoded failed."); goto CLEAR_UP; } if ((encodedBlob.data != nullptr) && (encodedBlob.data[0] != '\0')) { - LOGE("clearMem failed!"); + LOGE_ONE_STR("clearMem failed!"); ret = HCF_ERR_CRYPTO_OPERATION; } @@ -531,7 +531,7 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest015, TestSize.Level0) ret = HcfSymKeyGeneratorCreate("RSA128", &generator); if (ret != 0) { - LOGE("HcfSymKeyGeneratorCreate failed! Should not select RSA for symKey generator."); + LOGE_ONE_STR("HcfSymKeyGeneratorCreate failed! Should not select RSA for symKey generator."); } HcfObjDestroy(generator); @@ -545,7 +545,7 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest016, TestSize.Level0) ret = HcfSymKeyGeneratorCreate("RSA512", &generator); if (ret != 0) { - LOGE("HcfSymKeyGeneratorCreate failed! Should not select RSA for symKey generator."); + LOGE_ONE_STR("HcfSymKeyGeneratorCreate failed! Should not select RSA for symKey generator."); } HcfObjDestroy(generator); @@ -559,7 +559,7 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest017, TestSize.Level0) ret = HcfSymKeyGeneratorCreate("", &generator); if (ret != 0) { - LOGE("HcfSymKeyGeneratorCreate failed! Should not select empty string for symKey generator."); + LOGE_ONE_STR("HcfSymKeyGeneratorCreate failed! Should not select empty string for symKey generator."); } HcfObjDestroy(generator); @@ -573,7 +573,7 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest018, TestSize.Level0) ret = HcfSymKeyGeneratorCreate(nullptr, &generator); if (ret != 0) { - LOGE("HcfSymKeyGeneratorCreate failed! Should not select nullptr for symKey generator."); + LOGE_ONE_STR("HcfSymKeyGeneratorCreate failed! Should not select nullptr for symKey generator."); } HcfObjDestroy(generator); @@ -587,7 +587,7 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest019, TestSize.Level0) ret = HcfSymKeyGeneratorSpiCreate(nullptr, nullptr); if (ret != 0) { - LOGE("HcfSymKeyGeneratorSpiCreate failed!"); + LOGE_ONE_STR("HcfSymKeyGeneratorSpiCreate failed!"); } HcfObjDestroy(generator); @@ -607,7 +607,7 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest020, TestSize.Level0) } ret = generator->generateSymKey(nullptr, &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); } CLEAR_UP: @@ -635,7 +635,7 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest021, TestSize.Level0) ret = generator->convertSymKey(nullptr, &keyTmpBlob, &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); } CLEAR_UP: @@ -663,7 +663,7 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest022, TestSize.Level0) ret = generator->convertSymKey(generator, &keyTmpBlob, &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); } CLEAR_UP: @@ -682,14 +682,14 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest023, TestSize.Level0) ret = GenerateSymKey("AES128", &key); if (ret != 0) { - LOGE("GenerateSymKey failed!"); + LOGE_ONE_STR("GenerateSymKey failed!"); goto CLEAR_UP; } // allow input without encryption mode. It will pick the last PKCS5, and use default aes128ecb. ret = HcfCipherCreate("AES128|NoPadding|PKCS5", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto CLEAR_UP; } @@ -719,14 +719,14 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest024, TestSize.Level0) ret = GenerateSymKey("AES128", &key); if (ret != 0) { - LOGE("GenerateSymKey failed!"); + LOGE_ONE_STR("GenerateSymKey failed!"); goto CLEAR_UP; } // allow input without encryption mode. It will use default aes128ecb. ret = HcfCipherCreate("AES128|PKCS5", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto CLEAR_UP; } @@ -756,14 +756,14 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest025, TestSize.Level0) ret = GenerateSymKey("AES128", &key); if (ret != 0) { - LOGE("GenerateSymKey failed!"); + LOGE_ONE_STR("GenerateSymKey failed!"); goto CLEAR_UP; } // allow input without encryption mode. It will use default aes128ecb. ret = HcfCipherCreate("AES128", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto CLEAR_UP; } @@ -790,7 +790,7 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest026, TestSize.Level0) ret = HcfCipherCreate("", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); } HcfObjDestroy(cipher); @@ -804,7 +804,7 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest027, TestSize.Level0) ret = HcfCipherCreate(nullptr, &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); } HcfObjDestroy(cipher); @@ -815,7 +815,7 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest028, TestSize.Level0) { int ret = HcfCipherAesGeneratorSpiCreate(nullptr, nullptr); if (ret != 0) { - LOGE("HcfCipherAesGeneratorSpiCreate failed!"); + LOGE_ONE_STR("HcfCipherAesGeneratorSpiCreate failed!"); } EXPECT_NE(ret, 0); @@ -868,7 +868,7 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest029, TestSize.Level0) } ret = generator->engineGenerateSymmKey(nullptr, &key); if (ret != 0) { - LOGE("engineGenerateSymmKey failed!"); + LOGE_ONE_STR("engineGenerateSymmKey failed!"); } CLEAR_UP: @@ -896,7 +896,7 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest030, TestSize.Level0) } ret = generator->engineConvertSymmKey(nullptr, &keyTmpBlob, &key); if (ret != 0) { - LOGE("engineConvertSymmKey failed!"); + LOGE_ONE_STR("engineConvertSymmKey failed!"); } CLEAR_UP: diff --git a/test/unittest/src/aes_cipher/crypto_aes_ctr_cipher_test.cpp b/test/unittest/src/aes_cipher/crypto_aes_ctr_cipher_test.cpp index c8f0d5b828e38814bb906d54913c2a3ee88cc93f..83d75ac498fe072beddc66684e3b28eff6181f78 100644 --- a/test/unittest/src/aes_cipher/crypto_aes_ctr_cipher_test.cpp +++ b/test/unittest/src/aes_cipher/crypto_aes_ctr_cipher_test.cpp @@ -64,13 +64,13 @@ HWTEST_F(CryptoAesCtrCipherTest, CryptoAesCtrCipherTest001, TestSize.Level0) ret = generator->generateSymKey(generator, &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); goto CLEAR_UP; } ret = HcfCipherCreate("AES128|CTR|NoPadding", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto CLEAR_UP; } @@ -115,13 +115,13 @@ HWTEST_F(CryptoAesCtrCipherTest, CryptoAesCtrCipherTest002, TestSize.Level0) ret = generator->generateSymKey(generator, &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); goto CLEAR_UP; } ret = HcfCipherCreate("AES128|CTR|PKCS5", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto CLEAR_UP; } @@ -166,13 +166,13 @@ HWTEST_F(CryptoAesCtrCipherTest, CryptoAesCtrCipherTest003, TestSize.Level0) ret = generator->generateSymKey(generator, &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); goto CLEAR_UP; } ret = HcfCipherCreate("AES128|CTR|PKCS7", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto CLEAR_UP; } @@ -217,13 +217,13 @@ HWTEST_F(CryptoAesCtrCipherTest, CryptoAesCtrCipherTest004, TestSize.Level0) ret = generator->generateSymKey(generator, &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); goto CLEAR_UP; } ret = HcfCipherCreate("AES128|CTR|NoPadding", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto CLEAR_UP; } @@ -268,13 +268,13 @@ HWTEST_F(CryptoAesCtrCipherTest, CryptoAesCtrCipherTest005, TestSize.Level0) ret = generator->generateSymKey(generator, &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); goto CLEAR_UP; } ret = HcfCipherCreate("AES128|CTR|PKCS5", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto CLEAR_UP; } @@ -319,13 +319,13 @@ HWTEST_F(CryptoAesCtrCipherTest, CryptoAesCtrCipherTest006, TestSize.Level0) ret = generator->generateSymKey(generator, &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); goto CLEAR_UP; } ret = HcfCipherCreate("AES128|CTR|PKCS7", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto CLEAR_UP; } @@ -361,18 +361,18 @@ HWTEST_F(CryptoAesCtrCipherTest, CryptoAesCtrCipherTest007, TestSize.Level0) ret = ConvertSymKey("AES128", &key); if (ret != 0) { - LOGE("ConvertSymKey failed!"); + LOGE_ONE_STR("ConvertSymKey failed!"); goto CLEAR_UP; } ret = HcfCipherCreate("AES128|CTR|NoPadding", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto CLEAR_UP; } ret = GeneratorFile("/data/test_aes.txt", 10 * FILE_BLOCK_SIZE); if (ret != 0) { - LOGE("GeneratorFile failed!"); + LOGE_ONE_STR("GeneratorFile failed!"); goto CLEAR_UP; } @@ -389,7 +389,7 @@ HWTEST_F(CryptoAesCtrCipherTest, CryptoAesCtrCipherTest007, TestSize.Level0) } ret = CompareFileContent(); if (ret != 0) { - LOGE("CompareFileContent failed!"); + LOGE_ONE_STR("CompareFileContent failed!"); goto CLEAR_UP; } @@ -414,13 +414,13 @@ HWTEST_F(CryptoAesCtrCipherTest, CryptoAesCtrCipherTest008, TestSize.Level0) ret = GenerateSymKey("AES192", &key); if (ret != 0) { - LOGE("GenerateSymKey failed!"); + LOGE_ONE_STR("GenerateSymKey failed!"); goto CLEAR_UP; } ret = HcfCipherCreate("AES192|CTR|PKCS5", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto CLEAR_UP; } @@ -456,13 +456,13 @@ HWTEST_F(CryptoAesCtrCipherTest, CryptoAesCtrCipherTest009, TestSize.Level0) ret = GenerateSymKey("AES256", &key); if (ret != 0) { - LOGE("GenerateSymKey failed!"); + LOGE_ONE_STR("GenerateSymKey failed!"); goto CLEAR_UP; } ret = HcfCipherCreate("AES256|CTR|PKCS5", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto CLEAR_UP; } diff --git a/test/unittest/src/aes_cipher/crypto_aes_ecb_cipher_test.cpp b/test/unittest/src/aes_cipher/crypto_aes_ecb_cipher_test.cpp index 71d96b4a987df1f3df8e8eee7c401d33a6a769a0..ccd6c5d468ef6f2615137a3430b08d67131522cf 100644 --- a/test/unittest/src/aes_cipher/crypto_aes_ecb_cipher_test.cpp +++ b/test/unittest/src/aes_cipher/crypto_aes_ecb_cipher_test.cpp @@ -66,13 +66,13 @@ HWTEST_F(CryptoAesEcbCipherTest, CryptoAesEcbCipherTest001, TestSize.Level0) ret = generator->generateSymKey(generator, &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); goto CLEAR_UP; } ret = HcfCipherCreate("AES128|ECB|NoPadding", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto CLEAR_UP; } @@ -117,13 +117,13 @@ HWTEST_F(CryptoAesEcbCipherTest, CryptoAesEcbCipherTest002, TestSize.Level0) ret = generator->generateSymKey(generator, &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); goto CLEAR_UP; } ret = HcfCipherCreate("AES128|ECB|PKCS5", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto CLEAR_UP; } @@ -162,13 +162,13 @@ HWTEST_F(CryptoAesEcbCipherTest, CryptoAesEcbCipherTest003, TestSize.Level0) ret = generator->generateSymKey(generator, &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); goto CLEAR_UP; } ret = HcfCipherCreate("AES128|ECB|PKCS7", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto CLEAR_UP; } @@ -206,13 +206,13 @@ HWTEST_F(CryptoAesEcbCipherTest, CryptoAesEcbCipherTest004, TestSize.Level0) ret = ConvertSymKey("AES128", &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); goto CLEAR_UP; } ret = HcfCipherCreate("AES128|ECB|PKCS7", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto CLEAR_UP; } @@ -224,7 +224,7 @@ HWTEST_F(CryptoAesEcbCipherTest, CryptoAesEcbCipherTest004, TestSize.Level0) ret = memcmp(cipherText, codeCipherText, cipherTextLen); if (ret != 0) { - LOGE("cipherText compare failed!"); + LOGE_ONE_STR("cipherText compare failed!"); goto CLEAR_UP; } @@ -258,13 +258,13 @@ HWTEST_F(CryptoAesEcbCipherTest, CryptoAesEcbCipherTest005, TestSize.Level0) ret = generator->generateSymKey(generator, &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); goto CLEAR_UP; } ret = HcfCipherCreate("AES128|ECB|NoPadding", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto CLEAR_UP; } @@ -303,13 +303,13 @@ HWTEST_F(CryptoAesEcbCipherTest, CryptoAesEcbCipherTest006, TestSize.Level0) ret = generator->generateSymKey(generator, &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); goto CLEAR_UP; } ret = HcfCipherCreate("AES128|ECB|PKCS5", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto CLEAR_UP; } @@ -348,13 +348,13 @@ HWTEST_F(CryptoAesEcbCipherTest, CryptoAesEcbCipherTest007, TestSize.Level0) ret = generator->generateSymKey(generator, &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); goto CLEAR_UP; } ret = HcfCipherCreate("AES128|ECB|PKCS7", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto CLEAR_UP; } @@ -392,13 +392,13 @@ HWTEST_F(CryptoAesEcbCipherTest, CryptoAesEcbCipherTest008, TestSize.Level0) ret = ConvertSymKey("AES128", &key); if (ret != 0) { - LOGE("ConvertSymKey failed!"); + LOGE_ONE_STR("ConvertSymKey failed!"); goto CLEAR_UP; } ret = HcfCipherCreate("AES128|ECB|PKCS7", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto CLEAR_UP; } @@ -410,7 +410,7 @@ HWTEST_F(CryptoAesEcbCipherTest, CryptoAesEcbCipherTest008, TestSize.Level0) ret = memcmp(cipherText, codeCipherText, cipherTextLen); if (ret != 0) { - LOGE("cipherText compare failed!"); + LOGE_ONE_STR("cipherText compare failed!"); goto CLEAR_UP; } @@ -434,18 +434,18 @@ HWTEST_F(CryptoAesEcbCipherTest, CryptoAesEcbCipherTest009, TestSize.Level0) ret = GeneratorFile("/data/test_aes.txt", 10 * FILE_BLOCK_SIZE); if (ret != 0) { - LOGE("GeneratorFile failed!"); + LOGE_ONE_STR("GeneratorFile failed!"); goto CLEAR_UP; } ret = ConvertSymKey("AES128", &key); if (ret != 0) { - LOGE("ConvertSymKey failed!"); + LOGE_ONE_STR("ConvertSymKey failed!"); goto CLEAR_UP; } ret = HcfCipherCreate("AES128|ECB|NoPadding", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto CLEAR_UP; } @@ -462,7 +462,7 @@ HWTEST_F(CryptoAesEcbCipherTest, CryptoAesEcbCipherTest009, TestSize.Level0) } ret = CompareFileContent(); if (ret != 0) { - LOGE("CompareFileContent failed!"); + LOGE_ONE_STR("CompareFileContent failed!"); goto CLEAR_UP; } @@ -482,13 +482,13 @@ HWTEST_F(CryptoAesEcbCipherTest, CryptoAesEcbCipherTest010, TestSize.Level0) ret = GenerateSymKey("AES192", &key); if (ret != 0) { - LOGE("GenerateSymKey failed!"); + LOGE_ONE_STR("GenerateSymKey failed!"); goto CLEAR_UP; } ret = HcfCipherCreate("AES192|ECB|NoPadding", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto CLEAR_UP; } @@ -518,13 +518,13 @@ HWTEST_F(CryptoAesEcbCipherTest, CryptoAesEcbCipherTest011, TestSize.Level0) ret = GenerateSymKey("AES192", &key); if (ret != 0) { - LOGE("GenerateSymKey failed!"); + LOGE_ONE_STR("GenerateSymKey failed!"); goto CLEAR_UP; } ret = HcfCipherCreate("AES192|ECB|PKCS5", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto CLEAR_UP; } @@ -555,13 +555,13 @@ HWTEST_F(CryptoAesEcbCipherTest, CryptoAesEcbCipherTest012, TestSize.Level0) ret = GenerateSymKey("AES256", &key); if (ret != 0) { - LOGE("GenerateSymKey failed!"); + LOGE_ONE_STR("GenerateSymKey failed!"); goto CLEAR_UP; } ret = HcfCipherCreate("AES256|ECB|PKCS7", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto CLEAR_UP; } @@ -591,7 +591,7 @@ HWTEST_F(CryptoAesEcbCipherTest, CryptoAesEcbCipherTest013, TestSize.Level0) ret = HcfCipherCreate("AES128|ECB|PKCS5", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto CLEAR_UP; } ret = HcfSymKeyGeneratorCreate("AES128", &generator); @@ -601,7 +601,7 @@ HWTEST_F(CryptoAesEcbCipherTest, CryptoAesEcbCipherTest013, TestSize.Level0) } ret = generator->generateSymKey(reinterpret_cast(cipher), &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); } CLEAR_UP: @@ -625,7 +625,7 @@ HWTEST_F(CryptoAesEcbCipherTest, CryptoAesEcbCipherTest014, TestSize.Level0) ret = HcfCipherCreate("AES128|ECB|PKCS5", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto CLEAR_UP; } ret = HcfSymKeyGeneratorCreate("AES128", &generator); @@ -636,7 +636,7 @@ HWTEST_F(CryptoAesEcbCipherTest, CryptoAesEcbCipherTest014, TestSize.Level0) ret = generator->convertSymKey(reinterpret_cast(cipher), &keyTmpBlob, &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); } CLEAR_UP: @@ -656,14 +656,14 @@ HWTEST_F(CryptoAesEcbCipherTest, CryptoAesEcbCipherTest015, TestSize.Level0) ret = GenerateSymKey("AES128", &key); if (ret != 0) { - LOGE("GenerateSymKey failed!"); + LOGE_ONE_STR("GenerateSymKey failed!"); goto CLEAR_UP; } // allow input with more than one padding mode. It will pick the last PKCS5. ret = HcfCipherCreate("AES128|ECB|NoPadding|PKCS5", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto CLEAR_UP; } @@ -693,13 +693,13 @@ HWTEST_F(CryptoAesEcbCipherTest, CryptoAesEcbCipherTest016, TestSize.Level0) ret = GenerateSymKey("AES128", &key); if (ret != 0) { - LOGE("GenerateSymKey failed!"); + LOGE_ONE_STR("GenerateSymKey failed!"); goto CLEAR_UP; } ret = HcfCipherCreate("AES256|ECB|PKCS5", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto CLEAR_UP; } @@ -731,13 +731,13 @@ HWTEST_F(CryptoAesEcbCipherTest, CryptoAesEcbCipherTest017, TestSize.Level0) ret = GenerateSymKey("AES256", &key); if (ret != 0) { - LOGE("GenerateSymKey failed!"); + LOGE_ONE_STR("GenerateSymKey failed!"); goto CLEAR_UP; } ret = HcfCipherCreate("AES128|ECB|PKCS5", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto CLEAR_UP; } @@ -766,19 +766,19 @@ HWTEST_F(CryptoAesEcbCipherTest, CryptoAesEcbCipherTest018, TestSize.Level0) ret = GenerateSymKey("AES128", &key); if (ret != 0) { - LOGE("GenerateSymKey failed!"); + LOGE_ONE_STR("GenerateSymKey failed!"); goto CLEAR_UP; } ret = HcfCipherCreate("AES128|ECB|PKCS5", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto CLEAR_UP; } ret = cipher->init(nullptr, ENCRYPT_MODE, &(key->key), nullptr); if (ret != 0) { - LOGE("init failed! Should input cipher when init."); + LOGE_ONE_STR("init failed! Should input cipher when init."); } CLEAR_UP: @@ -795,13 +795,13 @@ HWTEST_F(CryptoAesEcbCipherTest, CryptoAesEcbCipherTest019, TestSize.Level0) ret = HcfCipherCreate("AES128|ECB|PKCS5", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto CLEAR_UP; } ret = cipher->init(cipher, ENCRYPT_MODE, nullptr, nullptr); if (ret != 0) { - LOGE("init failed! Should input key when init."); + LOGE_ONE_STR("init failed! Should input key when init."); } CLEAR_UP: @@ -824,19 +824,19 @@ HWTEST_F(CryptoAesEcbCipherTest, CryptoAesEcbCipherTest020, TestSize.Level0) } ret = generator->generateSymKey(generator, &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); goto CLEAR_UP; } ret = HcfCipherCreate("AES128|ECB|PKCS5", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto CLEAR_UP; } ret = cipher->init(reinterpret_cast(generator), ENCRYPT_MODE, &(key->key), nullptr); if (ret != 0) { - LOGE("init failed! Should input key when init."); + LOGE_ONE_STR("init failed! Should input key when init."); } CLEAR_UP: @@ -858,12 +858,12 @@ HWTEST_F(CryptoAesEcbCipherTest, CryptoAesEcbCipherTest021, TestSize.Level0) ret = GenerateSymKey("AES128", &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); goto CLEAR_UP; } ret = HcfCipherCreate("AES128|ECB|PKCS5", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto CLEAR_UP; } @@ -895,12 +895,12 @@ HWTEST_F(CryptoAesEcbCipherTest, CryptoAesEcbCipherTest022, TestSize.Level0) ret = GenerateSymKey("AES128", &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); goto CLEAR_UP; } ret = HcfCipherCreate("AES128|ECB|PKCS5", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto CLEAR_UP; } @@ -931,25 +931,25 @@ HWTEST_F(CryptoAesEcbCipherTest, CryptoAesEcbCipherTest023, TestSize.Level0) ret = GenerateSymKey("AES128", &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); goto CLEAR_UP; } ret = HcfCipherCreate("AES128|ECB|PKCS5", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto CLEAR_UP; } ret = cipher->init(cipher, ENCRYPT_MODE, &(key->key), nullptr); if (ret != 0) { - LOGE("init failed!"); + LOGE_ONE_STR("init failed!"); goto CLEAR_UP; } ret = cipher->update(nullptr, &input, &output); if (ret != 0) { - LOGE("update failed! Blob data should not be nullptr."); + LOGE_ONE_STR("update failed! Blob data should not be nullptr."); } CLEAR_UP: @@ -972,25 +972,25 @@ HWTEST_F(CryptoAesEcbCipherTest, CryptoAesEcbCipherTest024, TestSize.Level0) ret = GenerateSymKey("AES128", &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); goto CLEAR_UP; } ret = HcfCipherCreate("AES128|ECB|PKCS5", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto CLEAR_UP; } ret = cipher->init(cipher, ENCRYPT_MODE, &(key->key), nullptr); if (ret != 0) { - LOGE("init failed!"); + LOGE_ONE_STR("init failed!"); goto CLEAR_UP; } ret = cipher->update(reinterpret_cast(key), &input, &output); if (ret != 0) { - LOGE("update failed! Blob data should not be nullptr."); + LOGE_ONE_STR("update failed! Blob data should not be nullptr."); } CLEAR_UP: @@ -1013,13 +1013,13 @@ HWTEST_F(CryptoAesEcbCipherTest, CryptoAesEcbCipherTest025, TestSize.Level0) ret = GenerateSymKey("AES128", &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); goto CLEAR_UP; } ret = HcfCipherCreate("AES128|ECB|PKCS5", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto CLEAR_UP; } @@ -1050,25 +1050,25 @@ HWTEST_F(CryptoAesEcbCipherTest, CryptoAesEcbCipherTest026, TestSize.Level0) ret = GenerateSymKey("AES128", &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); goto CLEAR_UP; } ret = HcfCipherCreate("AES128|ECB|PKCS5", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto CLEAR_UP; } ret = cipher->init(cipher, ENCRYPT_MODE, &(key->key), nullptr); if (ret != 0) { - LOGE("init failed!"); + LOGE_ONE_STR("init failed!"); goto CLEAR_UP; } ret = cipher->doFinal(cipher, &input, nullptr); if (ret != 0) { - LOGE("update failed! Blob data should not be nullptr."); + LOGE_ONE_STR("update failed! Blob data should not be nullptr."); } CLEAR_UP: @@ -1088,25 +1088,25 @@ HWTEST_F(CryptoAesEcbCipherTest, CryptoAesEcbCipherTest027, TestSize.Level0) ret = GenerateSymKey("AES128", &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); goto CLEAR_UP; } ret = HcfCipherCreate("AES128|ECB|PKCS5", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto CLEAR_UP; } ret = cipher->init(cipher, ENCRYPT_MODE, &(key->key), nullptr); if (ret != 0) { - LOGE("init failed!"); + LOGE_ONE_STR("init failed!"); goto CLEAR_UP; } ret = cipher->doFinal(reinterpret_cast(key), &input, &output); if (ret != 0) { - LOGE("update failed! Blob data should not be nullptr."); + LOGE_ONE_STR("update failed! Blob data should not be nullptr."); } CLEAR_UP: @@ -1129,7 +1129,7 @@ HWTEST_F(CryptoAesEcbCipherTest, CryptoAesEcbCipherTest028, TestSize.Level0) ret = HcfCipherCreate("AES128|ECB|PKCS5", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto CLEAR_UP; } ret = HcfSymKeyGeneratorSpiCreate(&attr, &generator); @@ -1139,7 +1139,7 @@ HWTEST_F(CryptoAesEcbCipherTest, CryptoAesEcbCipherTest028, TestSize.Level0) } ret = generator->engineGenerateSymmKey(reinterpret_cast(cipher), &key); if (ret != 0) { - LOGE("engineGenerateSymmKey failed!"); + LOGE_ONE_STR("engineGenerateSymmKey failed!"); } CLEAR_UP: @@ -1164,7 +1164,7 @@ HWTEST_F(CryptoAesEcbCipherTest, CryptoAesEcbCipherTest029, TestSize.Level0) ret = HcfCipherCreate("AES128|ECB|PKCS5", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto CLEAR_UP; } ret = HcfSymKeyGeneratorSpiCreate(&attr, &generator); @@ -1174,7 +1174,7 @@ HWTEST_F(CryptoAesEcbCipherTest, CryptoAesEcbCipherTest029, TestSize.Level0) } ret = generator->engineConvertSymmKey(reinterpret_cast(cipher), &keyTmpBlob, &key); if (ret != 0) { - LOGE("engineConvertSymmKey failed!"); + LOGE_ONE_STR("engineConvertSymmKey failed!"); } CLEAR_UP: diff --git a/test/unittest/src/aes_cipher/crypto_aes_gcm_cipher_test.cpp b/test/unittest/src/aes_cipher/crypto_aes_gcm_cipher_test.cpp index 77f7ec3c88bfedda498fd519a95aa801cb02267b..491a48bea3073f56537f7869b45332937ad4c352 100644 --- a/test/unittest/src/aes_cipher/crypto_aes_gcm_cipher_test.cpp +++ b/test/unittest/src/aes_cipher/crypto_aes_gcm_cipher_test.cpp @@ -64,13 +64,13 @@ HWTEST_F(CryptoAesGcmCipherTest, CryptoAesGcmCipherTest001, TestSize.Level0) ret = GenerateSymKey("AES128", &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); goto CLEAR_UP; } ret = HcfCipherCreate("AES128|GCM|NoPadding", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto CLEAR_UP; } @@ -118,13 +118,13 @@ HWTEST_F(CryptoAesGcmCipherTest, CryptoAesGcmCipherTest002, TestSize.Level0) ret = GenerateSymKey("AES128", &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); goto CLEAR_UP; } ret = HcfCipherCreate("AES128|GCM|PKCS5", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto CLEAR_UP; } @@ -172,13 +172,13 @@ HWTEST_F(CryptoAesGcmCipherTest, CryptoAesGcmCipherTest003, TestSize.Level0) ret = GenerateSymKey("AES128", &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); goto CLEAR_UP; } ret = HcfCipherCreate("AES128|GCM|PKCS7", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto CLEAR_UP; } @@ -226,13 +226,13 @@ HWTEST_F(CryptoAesGcmCipherTest, CryptoAesGcmCipherTest004, TestSize.Level0) ret = GenerateSymKey("AES128", &key); if (ret != 0) { - LOGE("GenerateSymKey failed!"); + LOGE_ONE_STR("GenerateSymKey failed!"); goto CLEAR_UP; } ret = HcfCipherCreate("AES128|GCM|NoPadding", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto CLEAR_UP; } @@ -280,13 +280,13 @@ HWTEST_F(CryptoAesGcmCipherTest, CryptoAesGcmCipherTest005, TestSize.Level0) ret = GenerateSymKey("AES128", &key); if (ret != 0) { - LOGE("GenerateSymKey failed!"); + LOGE_ONE_STR("GenerateSymKey failed!"); goto CLEAR_UP; } ret = HcfCipherCreate("AES128|GCM|PKCS5", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto CLEAR_UP; } @@ -334,13 +334,13 @@ HWTEST_F(CryptoAesGcmCipherTest, CryptoAesGcmCipherTest006, TestSize.Level0) ret = GenerateSymKey("AES128", &key); if (ret != 0) { - LOGE("GenerateSymKey failed!"); + LOGE_ONE_STR("GenerateSymKey failed!"); goto CLEAR_UP; } ret = HcfCipherCreate("AES128|GCM|PKCS7", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto CLEAR_UP; } @@ -388,13 +388,13 @@ HWTEST_F(CryptoAesGcmCipherTest, CryptoAesGcmCipherTest007, TestSize.Level0) ret = GenerateSymKey("AES192", &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); goto CLEAR_UP; } ret = HcfCipherCreate("AES192|GCM|PKCS5", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto CLEAR_UP; } @@ -441,13 +441,13 @@ HWTEST_F(CryptoAesGcmCipherTest, CryptoAesGcmCipherTest008, TestSize.Level0) ret = GenerateSymKey("AES256", &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); goto CLEAR_UP; } ret = HcfCipherCreate("AES256|GCM|PKCS5", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto CLEAR_UP; } @@ -479,7 +479,7 @@ HWTEST_F(CryptoAesGcmCipherTest, CryptoAesGcmCipherTest009, TestSize.Level0) ret = HcfCipherCreate("RSA128|GCM|NoPadding", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed! Should not select RSA for GCM generator."); + LOGE_ONE_STR("HcfCipherCreate failed! Should not select RSA for GCM generator."); } HcfObjDestroy(cipher); @@ -494,7 +494,7 @@ HWTEST_F(CryptoAesGcmCipherTest, CryptoAesGcmCipherTest010, TestSize.Level0) // not allow '|' without content, because findAbility will fail for "" input ret = HcfCipherCreate("AES128|GCM|", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed! Should select padding mode for AES generator."); + LOGE_ONE_STR("HcfCipherCreate failed! Should select padding mode for AES generator."); } HcfObjDestroy(cipher); @@ -511,7 +511,7 @@ HWTEST_F(CryptoAesGcmCipherTest, CryptoAesGcmCipherTest011, TestSize.Level0) ret = GenerateSymKey("AES128", &key); if (ret != 0) { - LOGE("GenerateSymKey failed!"); + LOGE_ONE_STR("GenerateSymKey failed!"); goto CLEAR_UP; } @@ -519,7 +519,7 @@ HWTEST_F(CryptoAesGcmCipherTest, CryptoAesGcmCipherTest011, TestSize.Level0) // GCM, CCM enc/dec failed with params set to nullptr. ret = HcfCipherCreate("AES128|GCM|PKCS5", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto CLEAR_UP; } @@ -562,13 +562,13 @@ HWTEST_F(CryptoAesGcmCipherTest, CryptoAesGcmCipherTest012, TestSize.Level0) ret = GenerateSymKey("AES128", &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); goto CLEAR_UP; } ret = HcfCipherCreate("AES128|GCM|NoPadding", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto CLEAR_UP; } @@ -606,13 +606,13 @@ HWTEST_F(CryptoAesGcmCipherTest, CryptoAesGcmCipherTest013, TestSize.Level0) ret = GenerateSymKey("AES128", &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); goto CLEAR_UP; } ret = HcfCipherCreate("AES128|GCM|NoPadding", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto CLEAR_UP; } @@ -649,13 +649,13 @@ HWTEST_F(CryptoAesGcmCipherTest, CryptoAesGcmCipherTest014, TestSize.Level0) ret = GenerateSymKey("AES128", &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); goto CLEAR_UP; } ret = HcfCipherCreate("AES128|GCM|NoPadding", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto CLEAR_UP; } @@ -691,13 +691,13 @@ HWTEST_F(CryptoAesGcmCipherTest, CryptoAesGcmCipherTest015, TestSize.Level0) ret = GenerateSymKey("AES128", &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); goto CLEAR_UP; } ret = HcfCipherCreate("AES128|GCM|NoPadding", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto CLEAR_UP; } @@ -745,13 +745,13 @@ HWTEST_F(CryptoAesGcmCipherTest, CryptoAesGcmCipherTest016, TestSize.Level0) ret = GenerateSymKey("AES128", &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); goto CLEAR_UP; } ret = HcfCipherCreate("AES128|GCM|NoPadding", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto CLEAR_UP; } @@ -799,13 +799,13 @@ HWTEST_F(CryptoAesGcmCipherTest, CryptoAesGcmCipherTest017, TestSize.Level0) ret = GenerateSymKey("AES128", &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); goto CLEAR_UP; } ret = HcfCipherCreate("AES128|GCM|NoPadding", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto CLEAR_UP; } @@ -854,13 +854,13 @@ HWTEST_F(CryptoAesGcmCipherTest, CryptoAesGcmCipherTest018, TestSize.Level0) ret = GenerateSymKey("AES128", &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); goto CLEAR_UP; } ret = HcfCipherCreate("AES128|GCM|NoPadding", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto CLEAR_UP; } @@ -907,13 +907,13 @@ HWTEST_F(CryptoAesGcmCipherTest, CryptoAesGcmCipherTest019, TestSize.Level0) ret = GenerateSymKey("AES128", &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); goto CLEAR_UP; } ret = HcfCipherCreate("AES128|GCM|NoPadding", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto CLEAR_UP; } @@ -961,13 +961,13 @@ HWTEST_F(CryptoAesGcmCipherTest, CryptoAesGcmCipherTest020, TestSize.Level0) ret = GenerateSymKey("AES128", &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); HcfObjDestroy((HcfObjectBase *)key); } ret = HcfCipherCreate("AES128|GCM|NoPadding", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); HcfObjDestroy((HcfObjectBase *)key); HcfObjDestroy((HcfObjectBase *)cipher); } @@ -1007,13 +1007,13 @@ HWTEST_F(CryptoAesGcmCipherTest, CryptoAesGcmCipherTest021, TestSize.Level0) ret = GenerateSymKey("AES128", &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); HcfObjDestroy((HcfObjectBase *)key); } ret = HcfCipherCreate("AES128|GCM|NoPadding", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); HcfObjDestroy((HcfObjectBase *)key); HcfObjDestroy((HcfObjectBase *)cipher); } diff --git a/test/unittest/src/aes_cipher/crypto_aes_ofb_cipher_test.cpp b/test/unittest/src/aes_cipher/crypto_aes_ofb_cipher_test.cpp index d9d60e47f2bd4aaa24e302b4bb18ac27517337f8..bde29980529943fda6ac52db374e1ba0b80f0725 100644 --- a/test/unittest/src/aes_cipher/crypto_aes_ofb_cipher_test.cpp +++ b/test/unittest/src/aes_cipher/crypto_aes_ofb_cipher_test.cpp @@ -64,13 +64,13 @@ HWTEST_F(CryptoAesOfbCipherTest, CryptoAesOfbCipherTest001, TestSize.Level0) ret = generator->generateSymKey(generator, &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); goto CLEAR_UP; } ret = HcfCipherCreate("AES128|OFB|NoPadding", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto CLEAR_UP; } @@ -115,13 +115,13 @@ HWTEST_F(CryptoAesOfbCipherTest, CryptoAesOfbCipherTest002, TestSize.Level0) ret = generator->generateSymKey(generator, &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); goto CLEAR_UP; } ret = HcfCipherCreate("AES128|OFB|PKCS5", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto CLEAR_UP; } @@ -166,13 +166,13 @@ HWTEST_F(CryptoAesOfbCipherTest, CryptoAesOfbCipherTest003, TestSize.Level0) ret = generator->generateSymKey(generator, &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); goto CLEAR_UP; } ret = HcfCipherCreate("AES128|OFB|PKCS7", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto CLEAR_UP; } @@ -216,13 +216,13 @@ HWTEST_F(CryptoAesOfbCipherTest, CryptoAesOfbCipherTest004, TestSize.Level0) ret = generator->generateSymKey(generator, &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); goto CLEAR_UP; } ret = HcfCipherCreate("AES128|OFB|NoPadding", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto CLEAR_UP; } @@ -267,13 +267,13 @@ HWTEST_F(CryptoAesOfbCipherTest, CryptoAesOfbCipherTest005, TestSize.Level0) ret = generator->generateSymKey(generator, &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); goto CLEAR_UP; } ret = HcfCipherCreate("AES128|OFB|PKCS5", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto CLEAR_UP; } @@ -318,13 +318,13 @@ HWTEST_F(CryptoAesOfbCipherTest, CryptoAesOfbCipherTest006, TestSize.Level0) ret = generator->generateSymKey(generator, &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); goto CLEAR_UP; } ret = HcfCipherCreate("AES128|OFB|PKCS7", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto CLEAR_UP; } @@ -359,18 +359,18 @@ HWTEST_F(CryptoAesOfbCipherTest, CryptoAesOfbCipherTest007, TestSize.Level0) ret = GenerateSymKey("AES128", &key); if (ret != 0) { - LOGE("GenerateSymKey failed!"); + LOGE_ONE_STR("GenerateSymKey failed!"); goto CLEAR_UP; } ret = HcfCipherCreate("AES128|OFB|NoPadding", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto CLEAR_UP; } ret = GeneratorFile("/data/test_aes.txt", 10 * FILE_BLOCK_SIZE); if (ret != 0) { - LOGE("GeneratorFile failed!"); + LOGE_ONE_STR("GeneratorFile failed!"); goto CLEAR_UP; } @@ -387,7 +387,7 @@ HWTEST_F(CryptoAesOfbCipherTest, CryptoAesOfbCipherTest007, TestSize.Level0) } ret = CompareFileContent(); if (ret != 0) { - LOGE("CompareFileContent failed!"); + LOGE_ONE_STR("CompareFileContent failed!"); goto CLEAR_UP; } @@ -412,13 +412,13 @@ HWTEST_F(CryptoAesOfbCipherTest, CryptoAesOfbCipherTest008, TestSize.Level0) ret = GenerateSymKey("AES192", &key); if (ret != 0) { - LOGE("GenerateSymKey failed!"); + LOGE_ONE_STR("GenerateSymKey failed!"); goto CLEAR_UP; } ret = HcfCipherCreate("AES192|OFB|PKCS5", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto CLEAR_UP; } @@ -454,13 +454,13 @@ HWTEST_F(CryptoAesOfbCipherTest, CryptoAesOfbCipherTest009, TestSize.Level0) ret = GenerateSymKey("AES256", &key); if (ret != 0) { - LOGE("GenerateSymKey failed!"); + LOGE_ONE_STR("GenerateSymKey failed!"); goto CLEAR_UP; } ret = HcfCipherCreate("AES256|OFB|PKCS5", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto CLEAR_UP; } diff --git a/test/unittest/src/crypto_3des_cipher_test.cpp b/test/unittest/src/crypto_3des_cipher_test.cpp index e2a51d56d005b6fa9ea20c85433aa547fb237c6d..9e0e79f7bf772b58cb7da39d2d39b1a64126cb65 100644 --- a/test/unittest/src/crypto_3des_cipher_test.cpp +++ b/test/unittest/src/crypto_3des_cipher_test.cpp @@ -58,13 +58,13 @@ static HcfResult GenerateDesSymKey(HcfSymKey **key) HcfResult ret = HcfSymKeyGeneratorCreate("3DES192", &generator); if (ret != HCF_SUCCESS) { - LOGE("HcfSymKeyGeneratorCreate failed!"); + LOGE_ONE_STR("HcfSymKeyGeneratorCreate failed!"); return ret; } ret = generator->generateSymKey(generator, key); if (ret != HCF_SUCCESS) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); } HcfObjDestroy(generator); return ret; @@ -85,7 +85,7 @@ static int32_t DesEncrypt(HcfCipher *cipher, HcfSymKey *key, HcfParamsSpec *para ret = cipher->update(cipher, &input, &output); if (ret != 0) { - LOGE("update failed!"); + LOGE_ONE_STR("update failed!"); return ret; } *cipherTextLen = output.len; @@ -99,7 +99,7 @@ static int32_t DesEncrypt(HcfCipher *cipher, HcfSymKey *key, HcfParamsSpec *para ret = cipher->doFinal(cipher, nullptr, &output); if (ret != 0) { - LOGE("doFinal failed!"); + LOGE_ONE_STR("doFinal failed!"); return ret; } if (output.data != nullptr) { @@ -128,7 +128,7 @@ static int32_t DesDecrypt(HcfCipher *cipher, HcfSymKey *key, HcfParamsSpec *para ret = cipher->update(cipher, &input, &output); if (ret != 0) { - LOGE("update failed!"); + LOGE_ONE_STR("update failed!"); return ret; } cipherTextLen = output.len; @@ -142,7 +142,7 @@ static int32_t DesDecrypt(HcfCipher *cipher, HcfSymKey *key, HcfParamsSpec *para ret = cipher->doFinal(cipher, nullptr, &output); if (ret != 0) { - LOGE("doFinal failed!"); + LOGE_ONE_STR("doFinal failed!"); return ret; } if (output.data != nullptr) { @@ -176,7 +176,7 @@ static int32_t DesNoUpdateEncrypt(HcfCipher *cipher, HcfSymKey *key, HcfParamsSp *cipherTextLen = 0; ret = cipher->doFinal(cipher, &input, &output); if (ret != 0) { - LOGE("doFinal failed!"); + LOGE_ONE_STR("doFinal failed!"); return ret; } if (output.data != nullptr) { @@ -206,7 +206,7 @@ static int32_t DesNoUpdateDecrypt(HcfCipher *cipher, HcfSymKey *key, HcfParamsSp cipherTextLen = 0; ret = cipher->doFinal(cipher, &input, &output); if (ret != 0) { - LOGE("doFinal failed!"); + LOGE_ONE_STR("doFinal failed!"); return ret; } if (output.data != nullptr) { @@ -236,19 +236,19 @@ HWTEST_F(Crypto3DesCipherTest, Crypto3DesCipherTest001, TestSize.Level0) ret = HcfSymKeyGeneratorCreate("3DES192", &generator); if (ret != 0) { - LOGE("HcfSymKeyGeneratorCreate failed!"); + LOGE_ONE_STR("HcfSymKeyGeneratorCreate failed!"); goto clearup; } ret = generator->generateSymKey(generator, &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); goto clearup; } ret = HcfCipherCreate("3DES192|ECB|NoPadding", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto clearup; } @@ -283,19 +283,19 @@ HWTEST_F(Crypto3DesCipherTest, Crypto3DesCipherTest002, TestSize.Level0) ret = HcfSymKeyGeneratorCreate("3DES192", &generator); if (ret != 0) { - LOGE("HcfSymKeyGeneratorCreate failed!"); + LOGE_ONE_STR("HcfSymKeyGeneratorCreate failed!"); goto clearup; } ret = generator->generateSymKey(generator, &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); goto clearup; } ret = HcfCipherCreate("3DES192|ECB|PKCS5", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto clearup; } @@ -331,19 +331,19 @@ HWTEST_F(Crypto3DesCipherTest, Crypto3DesCipherTest003, TestSize.Level0) ret = HcfSymKeyGeneratorCreate("3DES192", &generator); if (ret != 0) { - LOGE("HcfSymKeyGeneratorCreate failed!"); + LOGE_ONE_STR("HcfSymKeyGeneratorCreate failed!"); goto clearup; } ret = generator->generateSymKey(generator, &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); goto clearup; } ret = HcfCipherCreate("3DES192|ECB|PKCS7", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto clearup; } @@ -383,19 +383,19 @@ HWTEST_F(Crypto3DesCipherTest, Crypto3DesCipherTest004, TestSize.Level0) ret = HcfSymKeyGeneratorCreate("3DES192", &generator); if (ret != 0) { - LOGE("HcfSymKeyGeneratorCreate failed!"); + LOGE_ONE_STR("HcfSymKeyGeneratorCreate failed!"); goto clearup; } ret = generator->generateSymKey(generator, &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); goto clearup; } ret = HcfCipherCreate("3DES192|CBC|NoPadding", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto clearup; } @@ -434,19 +434,19 @@ HWTEST_F(Crypto3DesCipherTest, Crypto3DesCipherTest005, TestSize.Level0) ret = HcfSymKeyGeneratorCreate("3DES192", &generator); if (ret != 0) { - LOGE("HcfSymKeyGeneratorCreate failed!"); + LOGE_ONE_STR("HcfSymKeyGeneratorCreate failed!"); goto clearup; } ret = generator->generateSymKey(generator, &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); goto clearup; } ret = HcfCipherCreate("3DES192|CBC|PKCS5", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto clearup; } @@ -484,19 +484,19 @@ HWTEST_F(Crypto3DesCipherTest, Crypto3DesCipherTest006, TestSize.Level0) ret = HcfSymKeyGeneratorCreate("3DES192", &generator); if (ret != 0) { - LOGE("HcfSymKeyGeneratorCreate failed!"); + LOGE_ONE_STR("HcfSymKeyGeneratorCreate failed!"); goto clearup; } ret = generator->generateSymKey(generator, &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); goto clearup; } ret = HcfCipherCreate("3DES192|CBC|PKCS7", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto clearup; } ret = DesEncrypt(cipher, key, (HcfParamsSpec *)&ivSpec, cipherText, &cipherTextLen); @@ -534,19 +534,19 @@ HWTEST_F(Crypto3DesCipherTest, Crypto3DesCipherTest007, TestSize.Level0) ret = HcfSymKeyGeneratorCreate("3DES192", &generator); if (ret != 0) { - LOGE("HcfSymKeyGeneratorCreate failed!"); + LOGE_ONE_STR("HcfSymKeyGeneratorCreate failed!"); goto clearup; } ret = generator->generateSymKey(generator, &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); goto clearup; } ret = HcfCipherCreate("3DES192|OFB|NoPadding", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto clearup; } @@ -586,19 +586,19 @@ HWTEST_F(Crypto3DesCipherTest, Crypto3DesCipherTest008, TestSize.Level0) ret = HcfSymKeyGeneratorCreate("3DES192", &generator); if (ret != 0) { - LOGE("HcfSymKeyGeneratorCreate failed!"); + LOGE_ONE_STR("HcfSymKeyGeneratorCreate failed!"); goto clearup; } ret = generator->generateSymKey(generator, &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); goto clearup; } ret = HcfCipherCreate("3DES192|OFB|PKCS5", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto clearup; } ret = DesEncrypt(cipher, key, (HcfParamsSpec *)&ivSpec, cipherText, &cipherTextLen); @@ -636,19 +636,19 @@ HWTEST_F(Crypto3DesCipherTest, Crypto3DesCipherTest009, TestSize.Level0) ret = HcfSymKeyGeneratorCreate("3DES192", &generator); if (ret != 0) { - LOGE("HcfSymKeyGeneratorCreate failed!"); + LOGE_ONE_STR("HcfSymKeyGeneratorCreate failed!"); goto clearup; } ret = generator->generateSymKey(generator, &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); goto clearup; } ret = HcfCipherCreate("3DES192|OFB|PKCS7", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto clearup; } @@ -688,19 +688,19 @@ HWTEST_F(Crypto3DesCipherTest, Crypto3DesCipherTest010, TestSize.Level0) ret = HcfSymKeyGeneratorCreate("3DES192", &generator); if (ret != 0) { - LOGE("HcfSymKeyGeneratorCreate failed!"); + LOGE_ONE_STR("HcfSymKeyGeneratorCreate failed!"); goto clearup; } ret = generator->generateSymKey(generator, &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); goto clearup; } ret = HcfCipherCreate("3DES192|CFB|NoPadding", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto clearup; } @@ -739,19 +739,19 @@ HWTEST_F(Crypto3DesCipherTest, Crypto3DesCipherTest011, TestSize.Level0) ret = HcfSymKeyGeneratorCreate("3DES192", &generator); if (ret != 0) { - LOGE("HcfSymKeyGeneratorCreate failed!"); + LOGE_ONE_STR("HcfSymKeyGeneratorCreate failed!"); goto clearup; } ret = generator->generateSymKey(generator, &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); goto clearup; } ret = HcfCipherCreate("3DES192|CFB|PKCS5", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto clearup; } @@ -790,19 +790,19 @@ HWTEST_F(Crypto3DesCipherTest, Crypto3DesCipherTest012, TestSize.Level0) ret = HcfSymKeyGeneratorCreate("3DES192", &generator); if (ret != 0) { - LOGE("HcfSymKeyGeneratorCreate failed!"); + LOGE_ONE_STR("HcfSymKeyGeneratorCreate failed!"); goto clearup; } ret = generator->generateSymKey(generator, &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); goto clearup; } ret = HcfCipherCreate("3DES192|CFB|PKCS7", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto clearup; } @@ -837,19 +837,19 @@ HWTEST_F(Crypto3DesCipherTest, Crypto3DesCipherTest013, TestSize.Level0) ret = HcfSymKeyGeneratorCreate("3DES192", &generator); if (ret != 0) { - LOGE("HcfSymKeyGeneratorCreate failed!"); + LOGE_ONE_STR("HcfSymKeyGeneratorCreate failed!"); goto clearup; } ret = generator->generateSymKey(generator, &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); goto clearup; } ret = HcfCipherCreate("3DES192|ECB|NoPadding", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto clearup; } @@ -884,19 +884,19 @@ HWTEST_F(Crypto3DesCipherTest, Crypto3DesCipherTest014, TestSize.Level0) ret = HcfSymKeyGeneratorCreate("3DES192", &generator); if (ret != 0) { - LOGE("HcfSymKeyGeneratorCreate failed!"); + LOGE_ONE_STR("HcfSymKeyGeneratorCreate failed!"); goto clearup; } ret = generator->generateSymKey(generator, &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); goto clearup; } ret = HcfCipherCreate("3DES192|ECB|PKCS5", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto clearup; } @@ -932,19 +932,19 @@ HWTEST_F(Crypto3DesCipherTest, Crypto3DesCipherTest015, TestSize.Level0) ret = HcfSymKeyGeneratorCreate("3DES192", &generator); if (ret != 0) { - LOGE("HcfSymKeyGeneratorCreate failed!"); + LOGE_ONE_STR("HcfSymKeyGeneratorCreate failed!"); goto clearup; } ret = generator->generateSymKey(generator, &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); goto clearup; } ret = HcfCipherCreate("3DES192|ECB|PKCS7", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto clearup; } @@ -984,19 +984,19 @@ HWTEST_F(Crypto3DesCipherTest, Crypto3DesCipherTest016, TestSize.Level0) ret = HcfSymKeyGeneratorCreate("3DES192", &generator); if (ret != 0) { - LOGE("HcfSymKeyGeneratorCreate failed!"); + LOGE_ONE_STR("HcfSymKeyGeneratorCreate failed!"); goto clearup; } ret = generator->generateSymKey(generator, &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); goto clearup; } ret = HcfCipherCreate("3DES192|CBC|NoPadding", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto clearup; } @@ -1035,19 +1035,19 @@ HWTEST_F(Crypto3DesCipherTest, Crypto3DesCipherTest017, TestSize.Level0) ret = HcfSymKeyGeneratorCreate("3DES192", &generator); if (ret != 0) { - LOGE("HcfSymKeyGeneratorCreate failed!"); + LOGE_ONE_STR("HcfSymKeyGeneratorCreate failed!"); goto clearup; } ret = generator->generateSymKey(generator, &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); goto clearup; } ret = HcfCipherCreate("3DES192|CBC|PKCS5", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto clearup; } @@ -1086,19 +1086,19 @@ HWTEST_F(Crypto3DesCipherTest, Crypto3DesCipherTest018, TestSize.Level0) ret = HcfSymKeyGeneratorCreate("3DES192", &generator); if (ret != 0) { - LOGE("HcfSymKeyGeneratorCreate failed!"); + LOGE_ONE_STR("HcfSymKeyGeneratorCreate failed!"); goto clearup; } ret = generator->generateSymKey(generator, &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); goto clearup; } ret = HcfCipherCreate("3DES192|CBC|PKCS7", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto clearup; } @@ -1137,19 +1137,19 @@ HWTEST_F(Crypto3DesCipherTest, Crypto3DesCipherTest019, TestSize.Level0) ret = HcfSymKeyGeneratorCreate("3DES192", &generator); if (ret != 0) { - LOGE("HcfSymKeyGeneratorCreate failed!"); + LOGE_ONE_STR("HcfSymKeyGeneratorCreate failed!"); goto clearup; } ret = generator->generateSymKey(generator, &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); goto clearup; } ret = HcfCipherCreate("3DES192|OFB|NoPadding", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto clearup; } @@ -1189,19 +1189,19 @@ HWTEST_F(Crypto3DesCipherTest, Crypto3DesCipherTest020, TestSize.Level0) ret = HcfSymKeyGeneratorCreate("3DES192", &generator); if (ret != 0) { - LOGE("HcfSymKeyGeneratorCreate failed!"); + LOGE_ONE_STR("HcfSymKeyGeneratorCreate failed!"); goto clearup; } ret = generator->generateSymKey(generator, &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); goto clearup; } ret = HcfCipherCreate("3DES192|OFB|PKCS5", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto clearup; } @@ -1240,19 +1240,19 @@ HWTEST_F(Crypto3DesCipherTest, Crypto3DesCipherTest021, TestSize.Level0) ret = HcfSymKeyGeneratorCreate("3DES192", &generator); if (ret != 0) { - LOGE("HcfSymKeyGeneratorCreate failed!"); + LOGE_ONE_STR("HcfSymKeyGeneratorCreate failed!"); goto clearup; } ret = generator->generateSymKey(generator, &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); goto clearup; } ret = HcfCipherCreate("3DES192|OFB|PKCS7", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto clearup; } @@ -1292,19 +1292,19 @@ HWTEST_F(Crypto3DesCipherTest, Crypto3DesCipherTest022, TestSize.Level0) ret = HcfSymKeyGeneratorCreate("3DES192", &generator); if (ret != 0) { - LOGE("HcfSymKeyGeneratorCreate failed!"); + LOGE_ONE_STR("HcfSymKeyGeneratorCreate failed!"); goto clearup; } ret = generator->generateSymKey(generator, &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); goto clearup; } ret = HcfCipherCreate("3DES192|CFB|NoPadding", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto clearup; } @@ -1343,19 +1343,19 @@ HWTEST_F(Crypto3DesCipherTest, Crypto3DesCipherTest023, TestSize.Level0) ret = HcfSymKeyGeneratorCreate("3DES192", &generator); if (ret != 0) { - LOGE("HcfSymKeyGeneratorCreate failed!"); + LOGE_ONE_STR("HcfSymKeyGeneratorCreate failed!"); goto clearup; } ret = generator->generateSymKey(generator, &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); goto clearup; } ret = HcfCipherCreate("3DES192|CFB|PKCS5", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto clearup; } @@ -1394,19 +1394,19 @@ HWTEST_F(Crypto3DesCipherTest, Crypto3DesCipherTest024, TestSize.Level0) ret = HcfSymKeyGeneratorCreate("3DES192", &generator); if (ret != 0) { - LOGE("HcfSymKeyGeneratorCreate failed!"); + LOGE_ONE_STR("HcfSymKeyGeneratorCreate failed!"); goto clearup; } ret = generator->generateSymKey(generator, &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); goto clearup; } ret = HcfCipherCreate("3DES192|CFB|PKCS7", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto clearup; } @@ -1443,13 +1443,13 @@ HWTEST_F(Crypto3DesCipherTest, Crypto3DesCipherTest025, TestSize.Level0) ret = GenerateDesSymKey(&key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); goto clearup; } ret = HcfCipherCreate("3DES192|CFB1|NoPadding", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto clearup; } @@ -1484,13 +1484,13 @@ HWTEST_F(Crypto3DesCipherTest, Crypto3DesCipherTest026, TestSize.Level0) ret = GenerateDesSymKey(&key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); goto clearup; } ret = HcfCipherCreate("3DES192|CFB8|NoPadding", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto clearup; } @@ -1525,13 +1525,13 @@ HWTEST_F(Crypto3DesCipherTest, Crypto3DesCipherTest027, TestSize.Level0) ret = GenerateDesSymKey(&key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); goto clearup; } ret = HcfCipherCreate("3DES192|PKCS5", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto clearup; } @@ -1560,13 +1560,13 @@ HWTEST_F(Crypto3DesCipherTest, Crypto3DesCipherTest028, TestSize.Level0) ret = GenerateDesSymKey(&key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); goto clearup; } ret = HcfCipherCreate("3DES192|ECB|PKCS5", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto clearup; } @@ -1588,19 +1588,19 @@ HWTEST_F(Crypto3DesCipherTest, Crypto3DesCipherTest029, TestSize.Level0) ret = HcfSymKeyGeneratorCreate("3DES192", &generator); if (ret != 0) { - LOGE("HcfSymKeyGeneratorCreate failed!"); + LOGE_ONE_STR("HcfSymKeyGeneratorCreate failed!"); goto clearup; } ret = generator->generateSymKey(generator, &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); goto clearup; } ret = HcfCipherCreate("3DES192|ECB|PKCS5", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto clearup; } @@ -1624,13 +1624,13 @@ HWTEST_F(Crypto3DesCipherTest, Crypto3DesCipherTest030, TestSize.Level0) ret = GenerateDesSymKey(&key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); goto clearup; } ret = HcfCipherCreate("3DES192|ECB|PKCS5", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto clearup; } @@ -1656,13 +1656,13 @@ HWTEST_F(Crypto3DesCipherTest, Crypto3DesCipherTest031, TestSize.Level0) ret = GenerateDesSymKey(&key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); goto clearup; } ret = HcfCipherCreate("3DES192|ECB|PKCS5", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto clearup; } @@ -1674,7 +1674,7 @@ HWTEST_F(Crypto3DesCipherTest, Crypto3DesCipherTest031, TestSize.Level0) ret = cipher->update(nullptr, &input, &output); EXPECT_EQ(ret, HCF_INVALID_PARAMS); if (ret != 0) { - LOGE("update failed!"); + LOGE_ONE_STR("update failed!"); } clearup: HcfObjDestroy(key); @@ -1697,13 +1697,13 @@ HWTEST_F(Crypto3DesCipherTest, Crypto3DesCipherTest032, TestSize.Level0) ret = GenerateDesSymKey(&key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); goto clearup; } ret = HcfCipherCreate("3DES192|ECB|PKCS5", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto clearup; } @@ -1714,7 +1714,7 @@ HWTEST_F(Crypto3DesCipherTest, Crypto3DesCipherTest032, TestSize.Level0) } ret = cipher->update(reinterpret_cast(key), &input, &output); if (ret != 0) { - LOGE("update failed!"); + LOGE_ONE_STR("update failed!"); } clearup: HcfObjDestroy(key); @@ -1772,13 +1772,13 @@ HWTEST_F(Crypto3DesCipherTest, Crypto3DesCipherTest034, TestSize.Level0) ret = GenerateDesSymKey(&key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); goto clearup; } ret = HcfCipherCreate("3DES192|ECB|PKCS5", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto clearup; } @@ -1789,7 +1789,7 @@ HWTEST_F(Crypto3DesCipherTest, Crypto3DesCipherTest034, TestSize.Level0) } ret = cipher->doFinal(reinterpret_cast(key), &input, &output); if (ret != 0) { - LOGE("doFinal failed!"); + LOGE_ONE_STR("doFinal failed!"); } clearup: HcfObjDestroy(key); @@ -1805,7 +1805,7 @@ HWTEST_F(Crypto3DesCipherTest, Crypto3DesCipherTest035, TestSize.Level0) { HcfResult ret = HcfCipherDesGeneratorSpiCreate(nullptr, nullptr); if (ret != 0) { - LOGE("HcfCipherDesGeneratorSpiCreate failed!"); + LOGE_ONE_STR("HcfCipherDesGeneratorSpiCreate failed!"); } EXPECT_NE(ret, 0); diff --git a/test/unittest/src/crypto_sm4_cfb_cipher_test.cpp b/test/unittest/src/crypto_sm4_cfb_cipher_test.cpp index 342de192ca0add10b8758331856cc3e693b36cd0..e92e110beb6859cbd11b2e9229df85631a969b0a 100644 --- a/test/unittest/src/crypto_sm4_cfb_cipher_test.cpp +++ b/test/unittest/src/crypto_sm4_cfb_cipher_test.cpp @@ -56,31 +56,31 @@ HWTEST_F(CryptoSM4CfbCipherTest, CryptoSm4CipherTest010, TestSize.Level0) ret = HcfSymKeyGeneratorCreate("SM4_128", &generator); if (ret != 0) { - LOGE("HcfSymKeyGeneratorCreate failed!"); + LOGE_ONE_STR("HcfSymKeyGeneratorCreate failed!"); goto clearup; } ret = generator->generateSymKey(generator, &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); goto clearup; } ret = HcfCipherCreate("SM4_128|CFB|NoPadding", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto clearup; } ret = Sm4Encrypt(cipher, key, nullptr, cipherText, &cipherTextLen); if (ret != 0) { - LOGE("Sm4Encrypt failed! "); + LOGE_ONE_STR("Sm4Encrypt failed! "); goto clearup; } ret = Sm4Decrypt(cipher, key, nullptr, cipherText, cipherTextLen); if (ret != 0) { - LOGE("Sm4Decrypt failed! "); + LOGE_ONE_STR("Sm4Decrypt failed! "); goto clearup; } @@ -104,31 +104,31 @@ HWTEST_F(CryptoSM4CfbCipherTest, CryptoSm4CipherTest011, TestSize.Level0) ret = HcfSymKeyGeneratorCreate("SM4_128", &generator); if (ret != 0) { - LOGE("HcfSymKeyGeneratorCreate failed!"); + LOGE_ONE_STR("HcfSymKeyGeneratorCreate failed!"); goto clearup; } ret = generator->generateSymKey(generator, &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); goto clearup; } ret = HcfCipherCreate("SM4_128|CFB|PKCS5", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto clearup; } ret = Sm4Encrypt(cipher, key, nullptr, cipherText, &cipherTextLen); if (ret != 0) { - LOGE("Sm4Encrypt failed! "); + LOGE_ONE_STR("Sm4Encrypt failed! "); goto clearup; } ret = Sm4Decrypt(cipher, key, nullptr, cipherText, cipherTextLen); if (ret != 0) { - LOGE("Sm4Decrypt failed! "); + LOGE_ONE_STR("Sm4Decrypt failed! "); goto clearup; } @@ -152,31 +152,31 @@ HWTEST_F(CryptoSM4CfbCipherTest, CryptoSm4CipherTest012, TestSize.Level0) ret = HcfSymKeyGeneratorCreate("SM4_128", &generator); if (ret != 0) { - LOGE("HcfSymKeyGeneratorCreate failed!"); + LOGE_ONE_STR("HcfSymKeyGeneratorCreate failed!"); goto clearup; } ret = generator->generateSymKey(generator, &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); goto clearup; } ret = HcfCipherCreate("SM4_128|CFB|PKCS7", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto clearup; } ret = Sm4Encrypt(cipher, key, nullptr, cipherText, &cipherTextLen); if (ret != 0) { - LOGE("Sm4Encrypt failed! "); + LOGE_ONE_STR("Sm4Encrypt failed! "); goto clearup; } ret = Sm4Decrypt(cipher, key, nullptr, cipherText, cipherTextLen); if (ret != 0) { - LOGE("Sm4Decrypt failed! "); + LOGE_ONE_STR("Sm4Decrypt failed! "); goto clearup; } @@ -200,31 +200,31 @@ HWTEST_F(CryptoSM4CfbCipherTest, CryptoSm4CipherTest013, TestSize.Level0) ret = HcfSymKeyGeneratorCreate("SM4_128", &generator); if (ret != 0) { - LOGE("HcfSymKeyGeneratorCreate failed!"); + LOGE_ONE_STR("HcfSymKeyGeneratorCreate failed!"); goto clearup; } ret = generator->generateSymKey(generator, &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); goto clearup; } ret = HcfCipherCreate("SM4_128|CFB128|NoPadding", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto clearup; } ret = Sm4Encrypt(cipher, key, nullptr, cipherText, &cipherTextLen); if (ret != 0) { - LOGE("Sm4Encrypt failed! "); + LOGE_ONE_STR("Sm4Encrypt failed! "); goto clearup; } ret = Sm4Decrypt(cipher, key, nullptr, cipherText, cipherTextLen); if (ret != 0) { - LOGE("Sm4Decrypt failed! "); + LOGE_ONE_STR("Sm4Decrypt failed! "); goto clearup; } @@ -248,31 +248,31 @@ HWTEST_F(CryptoSM4CfbCipherTest, CryptoSm4CipherTest014, TestSize.Level0) ret = HcfSymKeyGeneratorCreate("SM4_128", &generator); if (ret != 0) { - LOGE("HcfSymKeyGeneratorCreate failed!"); + LOGE_ONE_STR("HcfSymKeyGeneratorCreate failed!"); goto clearup; } ret = generator->generateSymKey(generator, &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); goto clearup; } ret = HcfCipherCreate("SM4_128|CFB128|PKCS5", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto clearup; } ret = Sm4Encrypt(cipher, key, nullptr, cipherText, &cipherTextLen); if (ret != 0) { - LOGE("Sm4Encrypt failed! "); + LOGE_ONE_STR("Sm4Encrypt failed! "); goto clearup; } ret = Sm4Decrypt(cipher, key, nullptr, cipherText, cipherTextLen); if (ret != 0) { - LOGE("Sm4Decrypt failed! "); + LOGE_ONE_STR("Sm4Decrypt failed! "); goto clearup; } @@ -296,31 +296,31 @@ HWTEST_F(CryptoSM4CfbCipherTest, CryptoSm4CipherTest015, TestSize.Level0) ret = HcfSymKeyGeneratorCreate("SM4_128", &generator); if (ret != 0) { - LOGE("HcfSymKeyGeneratorCreate failed!"); + LOGE_ONE_STR("HcfSymKeyGeneratorCreate failed!"); goto clearup; } ret = generator->generateSymKey(generator, &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); goto clearup; } ret = HcfCipherCreate("SM4_128|CFB128|PKCS7", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto clearup; } ret = Sm4Encrypt(cipher, key, nullptr, cipherText, &cipherTextLen); if (ret != 0) { - LOGE("Sm4Encrypt failed! "); + LOGE_ONE_STR("Sm4Encrypt failed! "); goto clearup; } ret = Sm4Decrypt(cipher, key, nullptr, cipherText, cipherTextLen); if (ret != 0) { - LOGE("Sm4Decrypt failed! "); + LOGE_ONE_STR("Sm4Decrypt failed! "); goto clearup; } @@ -343,31 +343,31 @@ HWTEST_F(CryptoSM4CfbCipherTest, CryptoSm4CipherTest028, TestSize.Level0) ret = HcfSymKeyGeneratorCreate("SM4_128", &generator); if (ret != 0) { - LOGE("HcfSymKeyGeneratorCreate failed!"); + LOGE_ONE_STR("HcfSymKeyGeneratorCreate failed!"); goto clearup; } ret = generator->generateSymKey(generator, &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); goto clearup; } ret = HcfCipherCreate("SM4_128|CFB|NoPadding", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto clearup; } ret = Sm4NoUpdateEncrypt(cipher, key, nullptr, cipherText, &cipherTextLen); if (ret != 0) { - LOGE("Sm4NoUpdateEncrypt failed! "); + LOGE_ONE_STR("Sm4NoUpdateEncrypt failed! "); goto clearup; } ret = Sm4NoUpdateDecrypt(cipher, key, nullptr, cipherText, cipherTextLen); if (ret != 0) { - LOGE("Sm4NoUpdateDecrypt failed! "); + LOGE_ONE_STR("Sm4NoUpdateDecrypt failed! "); goto clearup; } @@ -391,31 +391,31 @@ HWTEST_F(CryptoSM4CfbCipherTest, CryptoSm4CipherTest029, TestSize.Level0) ret = HcfSymKeyGeneratorCreate("SM4_128", &generator); if (ret != 0) { - LOGE("HcfSymKeyGeneratorCreate failed!"); + LOGE_ONE_STR("HcfSymKeyGeneratorCreate failed!"); goto clearup; } ret = generator->generateSymKey(generator, &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); goto clearup; } ret = HcfCipherCreate("SM4_128|CFB|PKCS5", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto clearup; } ret = Sm4NoUpdateEncrypt(cipher, key, nullptr, cipherText, &cipherTextLen); if (ret != 0) { - LOGE("Sm4NoUpdateEncrypt failed! "); + LOGE_ONE_STR("Sm4NoUpdateEncrypt failed! "); goto clearup; } ret = Sm4NoUpdateDecrypt(cipher, key, nullptr, cipherText, cipherTextLen); if (ret != 0) { - LOGE("Sm4NoUpdateDecrypt failed! "); + LOGE_ONE_STR("Sm4NoUpdateDecrypt failed! "); goto clearup; } @@ -439,31 +439,31 @@ HWTEST_F(CryptoSM4CfbCipherTest, CryptoSm4CipherTest030, TestSize.Level0) ret = HcfSymKeyGeneratorCreate("SM4_128", &generator); if (ret != 0) { - LOGE("HcfSymKeyGeneratorCreate failed!"); + LOGE_ONE_STR("HcfSymKeyGeneratorCreate failed!"); goto clearup; } ret = generator->generateSymKey(generator, &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); goto clearup; } ret = HcfCipherCreate("SM4_128|CFB|PKCS7", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto clearup; } ret = Sm4NoUpdateEncrypt(cipher, key, nullptr, cipherText, &cipherTextLen); if (ret != 0) { - LOGE("Sm4NoUpdateEncrypt failed! "); + LOGE_ONE_STR("Sm4NoUpdateEncrypt failed! "); goto clearup; } ret = Sm4NoUpdateDecrypt(cipher, key, nullptr, cipherText, cipherTextLen); if (ret != 0) { - LOGE("Sm4NoUpdateDecrypt failed! "); + LOGE_ONE_STR("Sm4NoUpdateDecrypt failed! "); goto clearup; } @@ -487,31 +487,31 @@ HWTEST_F(CryptoSM4CfbCipherTest, CryptoSm4CipherTest031, TestSize.Level0) ret = HcfSymKeyGeneratorCreate("SM4_128", &generator); if (ret != 0) { - LOGE("HcfSymKeyGeneratorCreate failed!"); + LOGE_ONE_STR("HcfSymKeyGeneratorCreate failed!"); goto clearup; } ret = generator->generateSymKey(generator, &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); goto clearup; } ret = HcfCipherCreate("SM4_128|CFB128|NoPadding", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto clearup; } ret = Sm4NoUpdateEncrypt(cipher, key, nullptr, cipherText, &cipherTextLen); if (ret != 0) { - LOGE("Sm4NoUpdateEncrypt failed! "); + LOGE_ONE_STR("Sm4NoUpdateEncrypt failed! "); goto clearup; } ret = Sm4NoUpdateDecrypt(cipher, key, nullptr, cipherText, cipherTextLen); if (ret != 0) { - LOGE("Sm4NoUpdateDecrypt failed! "); + LOGE_ONE_STR("Sm4NoUpdateDecrypt failed! "); goto clearup; } @@ -535,31 +535,31 @@ HWTEST_F(CryptoSM4CfbCipherTest, CryptoSm4CipherTest032, TestSize.Level0) ret = HcfSymKeyGeneratorCreate("SM4_128", &generator); if (ret != 0) { - LOGE("HcfSymKeyGeneratorCreate failed!"); + LOGE_ONE_STR("HcfSymKeyGeneratorCreate failed!"); goto clearup; } ret = generator->generateSymKey(generator, &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); goto clearup; } ret = HcfCipherCreate("SM4_128|CFB128|PKCS5", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto clearup; } ret = Sm4NoUpdateEncrypt(cipher, key, nullptr, cipherText, &cipherTextLen); if (ret != 0) { - LOGE("Sm4NoUpdateEncrypt failed! "); + LOGE_ONE_STR("Sm4NoUpdateEncrypt failed! "); goto clearup; } ret = Sm4NoUpdateDecrypt(cipher, key, nullptr, cipherText, cipherTextLen); if (ret != 0) { - LOGE("Sm4NoUpdateDecrypt failed! "); + LOGE_ONE_STR("Sm4NoUpdateDecrypt failed! "); goto clearup; } @@ -582,31 +582,31 @@ HWTEST_F(CryptoSM4CfbCipherTest, CryptoSm4CipherTest033, TestSize.Level0) ret = HcfSymKeyGeneratorCreate("SM4_128", &generator); if (ret != 0) { - LOGE("HcfSymKeyGeneratorCreate failed!"); + LOGE_ONE_STR("HcfSymKeyGeneratorCreate failed!"); goto clearup; } ret = generator->generateSymKey(generator, &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); goto clearup; } ret = HcfCipherCreate("SM4_128|CFB128|PKCS7", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto clearup; } ret = Sm4NoUpdateEncrypt(cipher, key, nullptr, cipherText, &cipherTextLen); if (ret != 0) { - LOGE("Sm4NoUpdateEncrypt failed! "); + LOGE_ONE_STR("Sm4NoUpdateEncrypt failed! "); goto clearup; } ret = Sm4NoUpdateDecrypt(cipher, key, nullptr, cipherText, cipherTextLen); if (ret != 0) { - LOGE("Sm4NoUpdateDecrypt failed! "); + LOGE_ONE_STR("Sm4NoUpdateDecrypt failed! "); goto clearup; } @@ -625,13 +625,13 @@ HWTEST_F(CryptoSM4CfbCipherTest, CryptoSm4CipherTest040, TestSize.Level0) const char *retAlgo = nullptr; ret = HcfCipherCreate(cipherName, &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto CLEAR_UP; } retAlgo = cipher->getAlgorithm(nullptr); if (retAlgo == nullptr) { - LOGE("cipher getAlgorithm failed!"); + LOGE_ONE_STR("cipher getAlgorithm failed!"); ret = HCF_ERR_CRYPTO_OPERATION; } @@ -650,19 +650,19 @@ HWTEST_F(CryptoSM4CfbCipherTest, CryptoSm4CipherTest041, TestSize.Level0) ret = HcfSymKeyGeneratorCreate("SM4_128", &generator); if (ret != 0) { - LOGE("HcfSymKeyGeneratorCreate failed!"); + LOGE_ONE_STR("HcfSymKeyGeneratorCreate failed!"); goto CLEAR_UP; } ret = HcfCipherCreate(cipherName, &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto CLEAR_UP; } retAlgo = cipher->getAlgorithm(reinterpret_cast(generator)); if (retAlgo == nullptr) { - LOGE("cipher getAlgorithm failed!"); + LOGE_ONE_STR("cipher getAlgorithm failed!"); ret = HCF_ERR_CRYPTO_OPERATION; } @@ -679,7 +679,7 @@ HWTEST_F(CryptoSM4CfbCipherTest, CryptoSm4CipherTest042, TestSize.Level0) ret = HcfCipherCreate("SM3|CFB|NoPadding", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed! Should not select SM3 for CFB generator."); + LOGE_ONE_STR("HcfCipherCreate failed! Should not select SM3 for CFB generator."); } HcfObjDestroy(cipher); @@ -694,7 +694,7 @@ HWTEST_F(CryptoSM4CfbCipherTest, CryptoSm4CipherTest043, TestSize.Level0) // not allow '|' without content, because findAbility will fail for "" input ret = HcfCipherCreate("SM4_128|CFB|", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed! Should select padding mode for SM4_128 generator."); + LOGE_ONE_STR("HcfCipherCreate failed! Should select padding mode for SM4_128 generator."); } HcfObjDestroy(cipher); @@ -707,7 +707,7 @@ HWTEST_F(CryptoSM4CfbCipherTest, CryptoSm4CipherTest047, TestSize.Level0) ret = HcfCipherCreate(nullptr, nullptr); if (ret != 0) { - LOGE("HcfCipherCreate failed! Should not select SM3 for CFB generator."); + LOGE_ONE_STR("HcfCipherCreate failed! Should not select SM3 for CFB generator."); } EXPECT_NE(ret, 0); @@ -734,19 +734,19 @@ HWTEST_F(CryptoSM4CfbCipherTest, CryptoAesCipherTest050, TestSize.Level0) ret = GenerateSymKeyForSm4("SM4_128", &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); goto CLEAR_UP; } ret = HcfCipherCreate("SM4_128|CFB|PKCS5", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto CLEAR_UP; } ret = Sm4Encrypt(cipher, key, (HcfParamsSpec *)&spec, cipherText, &cipherTextLen); if (ret != 0) { - LOGE("Sm4Encrypt failed!"); + LOGE_ONE_STR("Sm4Encrypt failed!"); goto CLEAR_UP; } @@ -756,7 +756,7 @@ HWTEST_F(CryptoSM4CfbCipherTest, CryptoAesCipherTest050, TestSize.Level0) ret = Sm4Decrypt(cipher, key, (HcfParamsSpec *)&spec, cipherText, cipherTextLen); if (ret != 0) { - LOGE("Sm4Decrypt failed!"); + LOGE_ONE_STR("Sm4Decrypt failed!"); goto CLEAR_UP; } @@ -774,20 +774,20 @@ HWTEST_F(CryptoSM4CfbCipherTest, CryptoAesCipherTest051, TestSize.Level0) const char *retAlgo = nullptr; ret = HcfCipherCreate(cipherName, &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto CLEAR_UP; } retAlgo = cipher->getAlgorithm(cipher); if (retAlgo == nullptr) { - LOGE("cipher getAlgorithm failed!"); + LOGE_ONE_STR("cipher getAlgorithm failed!"); ret = HCF_ERR_CRYPTO_OPERATION; goto CLEAR_UP; } ret = strcmp(retAlgo, cipherName); if (ret != 0) { - LOGE("cipher getAlgorithm failed!"); + LOGE_ONE_STR("cipher getAlgorithm failed!"); } CLEAR_UP: HcfObjDestroy(cipher); @@ -804,13 +804,13 @@ HWTEST_F(CryptoSM4CfbCipherTest, CryptoSm4CipherTest082, TestSize.Level0) ret = GenerateSymKeyForSm4("AES256", &key); if (ret != 0) { - LOGE("GenerateSymKey failed!"); + LOGE_ONE_STR("GenerateSymKey failed!"); goto CLEAR_UP; } ret = HcfCipherCreate("SM4_128|CFB|PKCS5", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto CLEAR_UP; } @@ -842,13 +842,13 @@ HWTEST_F(CryptoSM4CfbCipherTest, CryptoSm4CipherTest083, TestSize.Level0) ret = GenerateSymKeyForSm4("AES256", &key); if (ret != 0) { - LOGE("GenerateSymKey failed!"); + LOGE_ONE_STR("GenerateSymKey failed!"); goto CLEAR_UP; } ret = HcfCipherCreate("SM4_128|CFB128|PKCS5", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto CLEAR_UP; } diff --git a/test/unittest/src/crypto_sm4_cipher_test.cpp b/test/unittest/src/crypto_sm4_cipher_test.cpp index 9baa8807ad290b94634bcd589950d7b164a58ca7..a6ae02d27f2b4e6acf6c1b35c490f8d512a1d228 100644 --- a/test/unittest/src/crypto_sm4_cipher_test.cpp +++ b/test/unittest/src/crypto_sm4_cipher_test.cpp @@ -56,31 +56,31 @@ HWTEST_F(CryptoSM4CipherTest, CryptoSm4CipherTest004, TestSize.Level0) ret = HcfSymKeyGeneratorCreate("SM4_128", &generator); if (ret != 0) { - LOGE("HcfSymKeyGeneratorCreate failed!"); + LOGE_ONE_STR("HcfSymKeyGeneratorCreate failed!"); goto clearup; } ret = generator->generateSymKey(generator, &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); goto clearup; } ret = HcfCipherCreate("SM4_128|CBC|NoPadding", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto clearup; } ret = Sm4Encrypt(cipher, key, nullptr, cipherText, &cipherTextLen); if (ret != 0) { - LOGE("Sm4Encrypt failed! "); + LOGE_ONE_STR("Sm4Encrypt failed! "); goto clearup; } ret = Sm4Decrypt(cipher, key, nullptr, cipherText, cipherTextLen); if (ret != 0) { - LOGE("Sm4Decrypt failed! "); + LOGE_ONE_STR("Sm4Decrypt failed! "); goto clearup; } @@ -104,30 +104,30 @@ HWTEST_F(CryptoSM4CipherTest, CryptoSm4CipherTest005, TestSize.Level0) ret = HcfSymKeyGeneratorCreate("SM4_128", &generator); if (ret != 0) { - LOGE("HcfSymKeyGeneratorCreate failed!"); + LOGE_ONE_STR("HcfSymKeyGeneratorCreate failed!"); goto clearup; } ret = generator->generateSymKey(generator, &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); goto clearup; } ret = HcfCipherCreate("SM4_128|CBC|PKCS5", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto clearup; } ret = Sm4Encrypt(cipher, key, nullptr, cipherText, &cipherTextLen); if (ret != 0) { - LOGE("Sm4Encrypt failed! "); + LOGE_ONE_STR("Sm4Encrypt failed! "); goto clearup; } ret = Sm4Decrypt(cipher, key, nullptr, cipherText, cipherTextLen); if (ret != 0) { - LOGE("Sm4Decrypt failed! "); + LOGE_ONE_STR("Sm4Decrypt failed! "); goto clearup; } @@ -150,30 +150,30 @@ HWTEST_F(CryptoSM4CipherTest, CryptoSm4CipherTest006, TestSize.Level0) ret = HcfSymKeyGeneratorCreate("SM4_128", &generator); if (ret != 0) { - LOGE("HcfSymKeyGeneratorCreate failed!"); + LOGE_ONE_STR("HcfSymKeyGeneratorCreate failed!"); goto clearup; } ret = generator->generateSymKey(generator, &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); goto clearup; } ret = HcfCipherCreate("SM4_128|CBC|PKCS7", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto clearup; } ret = Sm4Encrypt(cipher, key, nullptr, cipherText, &cipherTextLen); if (ret != 0) { - LOGE("Sm4Encrypt failed! "); + LOGE_ONE_STR("Sm4Encrypt failed! "); goto clearup; } ret = Sm4Decrypt(cipher, key, nullptr, cipherText, cipherTextLen); if (ret != 0) { - LOGE("Sm4Decrypt failed! "); + LOGE_ONE_STR("Sm4Decrypt failed! "); goto clearup; } @@ -197,31 +197,31 @@ HWTEST_F(CryptoSM4CipherTest, CryptoSm4CipherTest007, TestSize.Level0) ret = HcfSymKeyGeneratorCreate("SM4_128", &generator); if (ret != 0) { - LOGE("HcfSymKeyGeneratorCreate failed!"); + LOGE_ONE_STR("HcfSymKeyGeneratorCreate failed!"); goto clearup; } ret = generator->generateSymKey(generator, &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); goto clearup; } ret = HcfCipherCreate("SM4_128|OFB|NoPadding", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto clearup; } ret = Sm4Encrypt(cipher, key, nullptr, cipherText, &cipherTextLen); if (ret != 0) { - LOGE("Sm4Encrypt failed! "); + LOGE_ONE_STR("Sm4Encrypt failed! "); goto clearup; } ret = Sm4Decrypt(cipher, key, nullptr, cipherText, cipherTextLen); if (ret != 0) { - LOGE("Sm4Decrypt failed! "); + LOGE_ONE_STR("Sm4Decrypt failed! "); goto clearup; } @@ -245,30 +245,30 @@ HWTEST_F(CryptoSM4CipherTest, CryptoSm4CipherTest008, TestSize.Level0) ret = HcfSymKeyGeneratorCreate("SM4_128", &generator); if (ret != 0) { - LOGE("HcfSymKeyGeneratorCreate failed!"); + LOGE_ONE_STR("HcfSymKeyGeneratorCreate failed!"); goto clearup; } ret = generator->generateSymKey(generator, &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); goto clearup; } ret = HcfCipherCreate("SM4_128|OFB|PKCS5", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto clearup; } ret = Sm4Encrypt(cipher, key, nullptr, cipherText, &cipherTextLen); if (ret != 0) { - LOGE("Sm4Encrypt failed! "); + LOGE_ONE_STR("Sm4Encrypt failed! "); goto clearup; } ret = Sm4Decrypt(cipher, key, nullptr, cipherText, cipherTextLen); if (ret != 0) { - LOGE("Sm4Decrypt failed! "); + LOGE_ONE_STR("Sm4Decrypt failed! "); goto clearup; } @@ -291,31 +291,31 @@ HWTEST_F(CryptoSM4CipherTest, CryptoSm4CipherTest009, TestSize.Level0) ret = HcfSymKeyGeneratorCreate("SM4_128", &generator); if (ret != 0) { - LOGE("HcfSymKeyGeneratorCreate failed!"); + LOGE_ONE_STR("HcfSymKeyGeneratorCreate failed!"); goto clearup; } ret = generator->generateSymKey(generator, &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); goto clearup; } ret = HcfCipherCreate("SM4_128|OFB|PKCS7", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto clearup; } ret = Sm4Encrypt(cipher, key, nullptr, cipherText, &cipherTextLen); if (ret != 0) { - LOGE("Sm4Encrypt failed! "); + LOGE_ONE_STR("Sm4Encrypt failed! "); goto clearup; } ret = Sm4Decrypt(cipher, key, nullptr, cipherText, cipherTextLen); if (ret != 0) { - LOGE("Sm4Decrypt failed! "); + LOGE_ONE_STR("Sm4Decrypt failed! "); goto clearup; } @@ -340,31 +340,31 @@ HWTEST_F(CryptoSM4CipherTest, CryptoSm4CipherTest016, TestSize.Level0) ret = HcfSymKeyGeneratorCreate("SM4_128", &generator); if (ret != 0) { - LOGE("HcfSymKeyGeneratorCreate failed!"); + LOGE_ONE_STR("HcfSymKeyGeneratorCreate failed!"); goto clearup; } ret = generator->generateSymKey(generator, &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); goto clearup; } ret = HcfCipherCreate("SM4_128|CTR|NoPadding", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto clearup; } ret = Sm4Encrypt(cipher, key, nullptr, cipherText, &cipherTextLen); if (ret != 0) { - LOGE("Sm4Encrypt failed! "); + LOGE_ONE_STR("Sm4Encrypt failed! "); goto clearup; } ret = Sm4Decrypt(cipher, key, nullptr, cipherText, cipherTextLen); if (ret != 0) { - LOGE("Sm4Decrypt failed! "); + LOGE_ONE_STR("Sm4Decrypt failed! "); goto clearup; } @@ -387,31 +387,31 @@ HWTEST_F(CryptoSM4CipherTest, CryptoSm4CipherTest017, TestSize.Level0) ret = HcfSymKeyGeneratorCreate("SM4_128", &generator); if (ret != 0) { - LOGE("HcfSymKeyGeneratorCreate failed!"); + LOGE_ONE_STR("HcfSymKeyGeneratorCreate failed!"); goto clearup; } ret = generator->generateSymKey(generator, &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); goto clearup; } ret = HcfCipherCreate("SM4_128|CTR|PKCS5", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto clearup; } ret = Sm4Encrypt(cipher, key, nullptr, cipherText, &cipherTextLen); if (ret != 0) { - LOGE("Sm4Encrypt failed! "); + LOGE_ONE_STR("Sm4Encrypt failed! "); goto clearup; } ret = Sm4Decrypt(cipher, key, nullptr, cipherText, cipherTextLen); if (ret != 0) { - LOGE("Sm4Decrypt failed! "); + LOGE_ONE_STR("Sm4Decrypt failed! "); goto clearup; } @@ -434,31 +434,31 @@ HWTEST_F(CryptoSM4CipherTest, CryptoSm4CipherTest018, TestSize.Level0) ret = HcfSymKeyGeneratorCreate("SM4_128", &generator); if (ret != 0) { - LOGE("HcfSymKeyGeneratorCreate failed!"); + LOGE_ONE_STR("HcfSymKeyGeneratorCreate failed!"); goto clearup; } ret = generator->generateSymKey(generator, &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); goto clearup; } ret = HcfCipherCreate("SM4_128|CTR|PKCS7", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto clearup; } ret = Sm4Encrypt(cipher, key, nullptr, cipherText, &cipherTextLen); if (ret != 0) { - LOGE("Sm4Encrypt failed! "); + LOGE_ONE_STR("Sm4Encrypt failed! "); goto clearup; } ret = Sm4Decrypt(cipher, key, nullptr, cipherText, cipherTextLen); if (ret != 0) { - LOGE("Sm4Decrypt failed! "); + LOGE_ONE_STR("Sm4Decrypt failed! "); goto clearup; } @@ -482,31 +482,31 @@ HWTEST_F(CryptoSM4CipherTest, CryptoSm4CipherTest022, TestSize.Level0) ret = HcfSymKeyGeneratorCreate("SM4_128", &generator); if (ret != 0) { - LOGE("HcfSymKeyGeneratorCreate failed!"); + LOGE_ONE_STR("HcfSymKeyGeneratorCreate failed!"); goto clearup; } ret = generator->generateSymKey(generator, &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); goto clearup; } ret = HcfCipherCreate("SM4_128|CBC|NoPadding", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto clearup; } ret = Sm4NoUpdateEncrypt(cipher, key, nullptr, cipherText, &cipherTextLen); if (ret != 0) { - LOGE("Sm4NoUpdateEncrypt failed! "); + LOGE_ONE_STR("Sm4NoUpdateEncrypt failed! "); goto clearup; } ret = Sm4NoUpdateDecrypt(cipher, key, nullptr, cipherText, cipherTextLen); if (ret != 0) { - LOGE("Sm4NoUpdateDecrypt failed! "); + LOGE_ONE_STR("Sm4NoUpdateDecrypt failed! "); goto clearup; } @@ -529,31 +529,31 @@ HWTEST_F(CryptoSM4CipherTest, CryptoSm4CipherTest023, TestSize.Level0) ret = HcfSymKeyGeneratorCreate("SM4_128", &generator); if (ret != 0) { - LOGE("HcfSymKeyGeneratorCreate failed!"); + LOGE_ONE_STR("HcfSymKeyGeneratorCreate failed!"); goto clearup; } ret = generator->generateSymKey(generator, &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); goto clearup; } ret = HcfCipherCreate("SM4_128|CBC|PKCS5", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto clearup; } ret = Sm4NoUpdateEncrypt(cipher, key, nullptr, cipherText, &cipherTextLen); if (ret != 0) { - LOGE("Sm4NoUpdateEncrypt failed! "); + LOGE_ONE_STR("Sm4NoUpdateEncrypt failed! "); goto clearup; } ret = Sm4NoUpdateDecrypt(cipher, key, nullptr, cipherText, cipherTextLen); if (ret != 0) { - LOGE("Sm4NoUpdateDecrypt failed! "); + LOGE_ONE_STR("Sm4NoUpdateDecrypt failed! "); goto clearup; } @@ -577,31 +577,31 @@ HWTEST_F(CryptoSM4CipherTest, CryptoSm4CipherTest024, TestSize.Level0) ret = HcfSymKeyGeneratorCreate("SM4_128", &generator); if (ret != 0) { - LOGE("HcfSymKeyGeneratorCreate failed!"); + LOGE_ONE_STR("HcfSymKeyGeneratorCreate failed!"); goto clearup; } ret = generator->generateSymKey(generator, &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); goto clearup; } ret = HcfCipherCreate("SM4_128|CBC|PKCS7", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto clearup; } ret = Sm4NoUpdateEncrypt(cipher, key, nullptr, cipherText, &cipherTextLen); if (ret != 0) { - LOGE("Sm4NoUpdateEncrypt failed! "); + LOGE_ONE_STR("Sm4NoUpdateEncrypt failed! "); goto clearup; } ret = Sm4NoUpdateDecrypt(cipher, key, nullptr, cipherText, cipherTextLen); if (ret != 0) { - LOGE("Sm4NoUpdateDecrypt failed! "); + LOGE_ONE_STR("Sm4NoUpdateDecrypt failed! "); goto clearup; } @@ -625,31 +625,31 @@ HWTEST_F(CryptoSM4CipherTest, CryptoSm4CipherTest025, TestSize.Level0) ret = HcfSymKeyGeneratorCreate("SM4_128", &generator); if (ret != 0) { - LOGE("HcfSymKeyGeneratorCreate failed!"); + LOGE_ONE_STR("HcfSymKeyGeneratorCreate failed!"); goto clearup; } ret = generator->generateSymKey(generator, &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); goto clearup; } ret = HcfCipherCreate("SM4_128|OFB|NoPadding", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto clearup; } ret = Sm4NoUpdateEncrypt(cipher, key, nullptr, cipherText, &cipherTextLen); if (ret != 0) { - LOGE("Sm4NoUpdateEncrypt failed! "); + LOGE_ONE_STR("Sm4NoUpdateEncrypt failed! "); goto clearup; } ret = Sm4NoUpdateDecrypt(cipher, key, nullptr, cipherText, cipherTextLen); if (ret != 0) { - LOGE("Sm4NoUpdateDecrypt failed! "); + LOGE_ONE_STR("Sm4NoUpdateDecrypt failed! "); goto clearup; } @@ -674,31 +674,31 @@ HWTEST_F(CryptoSM4CipherTest, CryptoSm4CipherTest026, TestSize.Level0) ret = HcfSymKeyGeneratorCreate("SM4_128", &generator); if (ret != 0) { - LOGE("HcfSymKeyGeneratorCreate failed!"); + LOGE_ONE_STR("HcfSymKeyGeneratorCreate failed!"); goto clearup; } ret = generator->generateSymKey(generator, &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); goto clearup; } ret = HcfCipherCreate("SM4_128|OFB|PKCS5", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto clearup; } ret = Sm4NoUpdateEncrypt(cipher, key, nullptr, cipherText, &cipherTextLen); if (ret != 0) { - LOGE("Sm4NoUpdateEncrypt failed! "); + LOGE_ONE_STR("Sm4NoUpdateEncrypt failed! "); goto clearup; } ret = Sm4NoUpdateDecrypt(cipher, key, nullptr, cipherText, cipherTextLen); if (ret != 0) { - LOGE("Sm4NoUpdateDecrypt failed! "); + LOGE_ONE_STR("Sm4NoUpdateDecrypt failed! "); goto clearup; } @@ -721,31 +721,31 @@ HWTEST_F(CryptoSM4CipherTest, CryptoSm4CipherTest027, TestSize.Level0) ret = HcfSymKeyGeneratorCreate("SM4_128", &generator); if (ret != 0) { - LOGE("HcfSymKeyGeneratorCreate failed!"); + LOGE_ONE_STR("HcfSymKeyGeneratorCreate failed!"); goto clearup; } ret = generator->generateSymKey(generator, &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); goto clearup; } ret = HcfCipherCreate("SM4_128|OFB|PKCS7", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto clearup; } ret = Sm4NoUpdateEncrypt(cipher, key, nullptr, cipherText, &cipherTextLen); if (ret != 0) { - LOGE("Sm4NoUpdateEncrypt failed! "); + LOGE_ONE_STR("Sm4NoUpdateEncrypt failed! "); goto clearup; } ret = Sm4NoUpdateDecrypt(cipher, key, nullptr, cipherText, cipherTextLen); if (ret != 0) { - LOGE("Sm4NoUpdateDecrypt failed! "); + LOGE_ONE_STR("Sm4NoUpdateDecrypt failed! "); goto clearup; } @@ -764,7 +764,7 @@ HWTEST_F(CryptoSM4CipherTest, CryptoSm4CipherTest044, TestSize.Level0) ret = HcfCipherCreate("", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); } HcfObjDestroy(cipher); @@ -778,7 +778,7 @@ HWTEST_F(CryptoSM4CipherTest, CryptoSm4CipherTest045, TestSize.Level0) ret = HcfCipherCreate(nullptr, &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); } HcfObjDestroy(cipher); @@ -792,7 +792,7 @@ HWTEST_F(CryptoSM4CipherTest, CryptoSm4CipherTest052, TestSize.Level0) ret = HcfCipherCreate("SM4_128|CCC|NoPadding", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed! Should not select CCC for SM4 generator."); + LOGE_ONE_STR("HcfCipherCreate failed! Should not select CCC for SM4 generator."); } HcfObjDestroy(cipher); @@ -814,13 +814,13 @@ HWTEST_F(CryptoSM4CipherTest, CryptoSm4CipherTest055, TestSize.Level0) ret = GenerateSymKeyForSm4("SM4_128", &key); if (ret != 0) { - LOGE("GenerateSymKeyForSm4 failed!"); + LOGE_ONE_STR("GenerateSymKeyForSm4 failed!"); goto CLEAR_UP; } ret = HcfCipherCreate("SM4_128|CBC|PKCS5", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto CLEAR_UP; } @@ -851,14 +851,14 @@ HWTEST_F(CryptoSM4CipherTest, CryptoSm4CipherTest057, TestSize.Level0) ret = GenerateSymKeyForSm4("SM4_128", &key); if (ret != 0) { - LOGE("GenerateSymKeyForSm4 failed!"); + LOGE_ONE_STR("GenerateSymKeyForSm4 failed!"); goto CLEAR_UP; } // allow input without encryption mode. It will use default aes128ecb. ret = HcfCipherCreate("SM4_128|PKCS5", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto CLEAR_UP; } @@ -888,14 +888,14 @@ HWTEST_F(CryptoSM4CipherTest, CryptoSm4CipherTest060, TestSize.Level0) ret = GenerateSymKeyForSm4("SM4_128", &key); if (ret != 0) { - LOGE("GenerateSymKeyForSm4 failed!"); + LOGE_ONE_STR("GenerateSymKeyForSm4 failed!"); goto CLEAR_UP; } // allow input without encryption mode. It will pick the last PKCS5, and use default aes128ecb. ret = HcfCipherCreate("SM4_128|NoPadding|PKCS5", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto CLEAR_UP; } @@ -1213,13 +1213,13 @@ HWTEST_F(CryptoSM4CipherTest, CryptoSm4CipherTest079, TestSize.Level0) ret = GenerateSymKeyForSm4("AES256", &key); if (ret != 0) { - LOGE("GenerateSymKeyForSm4 failed!"); + LOGE_ONE_STR("GenerateSymKeyForSm4 failed!"); goto CLEAR_UP; } ret = HcfCipherCreate("SM4_128|CBC|PKCS5", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto CLEAR_UP; } @@ -1251,13 +1251,13 @@ HWTEST_F(CryptoSM4CipherTest, CryptoSm4CipherTest080, TestSize.Level0) ret = GenerateSymKeyForSm4("AES256", &key); if (ret != 0) { - LOGE("GenerateSymKeyForSm4 failed!"); + LOGE_ONE_STR("GenerateSymKeyForSm4 failed!"); goto CLEAR_UP; } ret = HcfCipherCreate("SM4_128|CTR|PKCS5", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto CLEAR_UP; } @@ -1289,13 +1289,13 @@ HWTEST_F(CryptoSM4CipherTest, CryptoSm4CipherTest081, TestSize.Level0) ret = GenerateSymKeyForSm4("AES256", &key); if (ret != 0) { - LOGE("GenerateSymKeyForSm4 failed!"); + LOGE_ONE_STR("GenerateSymKeyForSm4 failed!"); goto CLEAR_UP; } ret = HcfCipherCreate("SM4_128|OFB|PKCS5", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto CLEAR_UP; } diff --git a/test/unittest/src/crypto_sm4_ecb_cipher_test.cpp b/test/unittest/src/crypto_sm4_ecb_cipher_test.cpp index 09f5399f6158ec05e3a940b1da11ecc1d85a0c84..003a22fe7df5eff596388124a54c6441e068cbbe 100644 --- a/test/unittest/src/crypto_sm4_ecb_cipher_test.cpp +++ b/test/unittest/src/crypto_sm4_ecb_cipher_test.cpp @@ -55,31 +55,31 @@ HWTEST_F(CryptoSM4EcbCipherTest, CryptoSm4CipherTest001, TestSize.Level0) ret = HcfSymKeyGeneratorCreate("SM4_128", &generator); if (ret != 0) { - LOGE("HcfSymKeyGeneratorCreate failed!"); + LOGE_ONE_STR("HcfSymKeyGeneratorCreate failed!"); goto clearup; } ret = generator->generateSymKey(generator, &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); goto clearup; } ret = HcfCipherCreate("SM4_128|ECB|NoPadding", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto clearup; } ret = Sm4Encrypt(cipher, key, nullptr, cipherText, &cipherTextLen); if (ret != 0) { - LOGE("Sm4Encrypt failed! "); + LOGE_ONE_STR("Sm4Encrypt failed! "); goto clearup; } ret = Sm4Decrypt(cipher, key, nullptr, cipherText, cipherTextLen); if (ret != 0) { - LOGE("Sm4Decrypt failed! "); + LOGE_ONE_STR("Sm4Decrypt failed! "); goto clearup; } @@ -102,31 +102,31 @@ HWTEST_F(CryptoSM4EcbCipherTest, CryptoSm4CipherTest002, TestSize.Level0) ret = HcfSymKeyGeneratorCreate("SM4_128", &generator); if (ret != 0) { - LOGE("HcfSymKeyGeneratorCreate failed!"); + LOGE_ONE_STR("HcfSymKeyGeneratorCreate failed!"); goto clearup; } ret = generator->generateSymKey(generator, &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); goto clearup; } ret = HcfCipherCreate("SM4_128|ECB|PKCS5", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto clearup; } ret = Sm4Encrypt(cipher, key, nullptr, cipherText, &cipherTextLen); if (ret != 0) { - LOGE("Sm4Encrypt failed! "); + LOGE_ONE_STR("Sm4Encrypt failed! "); goto clearup; } ret = Sm4Decrypt(cipher, key, nullptr, cipherText, cipherTextLen); if (ret != 0) { - LOGE("Sm4Decrypt failed! "); + LOGE_ONE_STR("Sm4Decrypt failed! "); goto clearup; } @@ -150,31 +150,31 @@ HWTEST_F(CryptoSM4EcbCipherTest, CryptoSm4CipherTest003, TestSize.Level0) ret = HcfSymKeyGeneratorCreate("SM4_128", &generator); if (ret != 0) { - LOGE("HcfSymKeyGeneratorCreate failed!"); + LOGE_ONE_STR("HcfSymKeyGeneratorCreate failed!"); goto clearup; } ret = generator->generateSymKey(generator, &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); goto clearup; } ret = HcfCipherCreate("SM4_128|ECB|PKCS7", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto clearup; } ret = Sm4Encrypt(cipher, key, nullptr, cipherText, &cipherTextLen); if (ret != 0) { - LOGE("Sm4Encrypt failed! "); + LOGE_ONE_STR("Sm4Encrypt failed! "); goto clearup; } ret = Sm4Decrypt(cipher, key, nullptr, cipherText, cipherTextLen); if (ret != 0) { - LOGE("Sm4Decrypt failed! "); + LOGE_ONE_STR("Sm4Decrypt failed! "); goto clearup; } @@ -197,31 +197,31 @@ HWTEST_F(CryptoSM4EcbCipherTest, CryptoSm4CipherTest019, TestSize.Level0) ret = HcfSymKeyGeneratorCreate("SM4_128", &generator); if (ret != 0) { - LOGE("HcfSymKeyGeneratorCreate failed!"); + LOGE_ONE_STR("HcfSymKeyGeneratorCreate failed!"); goto clearup; } ret = generator->generateSymKey(generator, &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); goto clearup; } ret = HcfCipherCreate("SM4_128|ECB|NoPadding", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto clearup; } ret = Sm4NoUpdateEncrypt(cipher, key, nullptr, cipherText, &cipherTextLen); if (ret != 0) { - LOGE("Sm4NoUpdateEncrypt failed! "); + LOGE_ONE_STR("Sm4NoUpdateEncrypt failed! "); goto clearup; } ret = Sm4NoUpdateDecrypt(cipher, key, nullptr, cipherText, cipherTextLen); if (ret != 0) { - LOGE("Sm4NoUpdateDecrypt failed! "); + LOGE_ONE_STR("Sm4NoUpdateDecrypt failed! "); goto clearup; } @@ -244,31 +244,31 @@ HWTEST_F(CryptoSM4EcbCipherTest, CryptoSm4CipherTest020, TestSize.Level0) ret = HcfSymKeyGeneratorCreate("SM4_128", &generator); if (ret != 0) { - LOGE("HcfSymKeyGeneratorCreate failed!"); + LOGE_ONE_STR("HcfSymKeyGeneratorCreate failed!"); goto clearup; } ret = generator->generateSymKey(generator, &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); goto clearup; } ret = HcfCipherCreate("SM4_128|ECB|PKCS5", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto clearup; } ret = Sm4NoUpdateEncrypt(cipher, key, nullptr, cipherText, &cipherTextLen); if (ret != 0) { - LOGE("Sm4NoUpdateEncrypt failed! "); + LOGE_ONE_STR("Sm4NoUpdateEncrypt failed! "); goto clearup; } ret = Sm4NoUpdateDecrypt(cipher, key, nullptr, cipherText, cipherTextLen); if (ret != 0) { - LOGE("Sm4NoUpdateDecrypt failed! "); + LOGE_ONE_STR("Sm4NoUpdateDecrypt failed! "); goto clearup; } @@ -292,31 +292,31 @@ HWTEST_F(CryptoSM4EcbCipherTest, CryptoSm4CipherTest021, TestSize.Level0) ret = HcfSymKeyGeneratorCreate("SM4_128", &generator); if (ret != 0) { - LOGE("HcfSymKeyGeneratorCreate failed!"); + LOGE_ONE_STR("HcfSymKeyGeneratorCreate failed!"); goto clearup; } ret = generator->generateSymKey(generator, &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); goto clearup; } ret = HcfCipherCreate("SM4_128|ECB|PKCS7", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto clearup; } ret = Sm4NoUpdateEncrypt(cipher, key, nullptr, cipherText, &cipherTextLen); if (ret != 0) { - LOGE("Sm4NoUpdateEncrypt failed! "); + LOGE_ONE_STR("Sm4NoUpdateEncrypt failed! "); goto clearup; } ret = Sm4NoUpdateDecrypt(cipher, key, nullptr, cipherText, cipherTextLen); if (ret != 0) { - LOGE("Sm4NoUpdateDecrypt failed! "); + LOGE_ONE_STR("Sm4NoUpdateDecrypt failed! "); goto clearup; } @@ -335,19 +335,19 @@ HWTEST_F(CryptoSM4EcbCipherTest, CryptoSm4CipherTest034, TestSize.Level0) ret = GenerateSm4SymKey(&key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); goto clearup; } ret = HcfCipherCreate("SM4_128|ECB|PKCS5", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto clearup; } ret = cipher->init(nullptr, ENCRYPT_MODE, &(key->key), nullptr); if (ret != 0) { - LOGE("init failed! "); + LOGE_ONE_STR("init failed! "); } clearup: @@ -364,19 +364,19 @@ HWTEST_F(CryptoSM4EcbCipherTest, CryptoSm4CipherTest035, TestSize.Level0) ret = GenerateSm4SymKey(&key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); goto clearup; } ret = HcfCipherCreate("SM4_128|ECB|PKCS5", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto clearup; } ret = cipher->init(cipher, ENCRYPT_MODE, reinterpret_cast(cipher), nullptr); if (ret != 0) { - LOGE("init failed! "); + LOGE_ONE_STR("init failed! "); } clearup: @@ -396,24 +396,24 @@ HWTEST_F(CryptoSM4EcbCipherTest, CryptoSm4CipherTest036, TestSize.Level0) ret = GenerateSm4SymKey(&key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); goto clearup; } ret = HcfCipherCreate("SM4_128|ECB|PKCS5", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto clearup; } ret = cipher->init(cipher, ENCRYPT_MODE, &(key->key), nullptr); if (ret != 0) { - LOGE("init failed! "); + LOGE_ONE_STR("init failed! "); goto clearup; } ret = cipher->update(nullptr, &input, &output); if (ret != 0) { - LOGE("update failed!"); + LOGE_ONE_STR("update failed!"); } clearup: HcfObjDestroy(key); @@ -436,24 +436,24 @@ HWTEST_F(CryptoSM4EcbCipherTest, CryptoSm4CipherTest037, TestSize.Level0) ret = GenerateSm4SymKey(&key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); goto clearup; } ret = HcfCipherCreate("SM4_128|ECB|PKCS5", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto clearup; } ret = cipher->init(cipher, ENCRYPT_MODE, &(key->key), nullptr); if (ret != 0) { - LOGE("init failed! "); + LOGE_ONE_STR("init failed! "); goto clearup; } ret = cipher->update(reinterpret_cast(key), &input, &output); if (ret != 0) { - LOGE("update failed!"); + LOGE_ONE_STR("update failed!"); } clearup: HcfObjDestroy(key); @@ -476,24 +476,24 @@ HWTEST_F(CryptoSM4EcbCipherTest, CryptoSm4CipherTest038, TestSize.Level0) ret = GenerateSm4SymKey(&key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); goto clearup; } ret = HcfCipherCreate("SM4_128|ECB|PKCS5", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto clearup; } ret = cipher->init(cipher, ENCRYPT_MODE, &(key->key), nullptr); if (ret != 0) { - LOGE("init failed! "); + LOGE_ONE_STR("init failed! "); goto clearup; } ret = cipher->doFinal(nullptr, &input, &output); if (ret != 0) { - LOGE("doFinal failed!"); + LOGE_ONE_STR("doFinal failed!"); } clearup: HcfObjDestroy(key); @@ -516,24 +516,24 @@ HWTEST_F(CryptoSM4EcbCipherTest, CryptoSm4CipherTest039, TestSize.Level0) ret = GenerateSm4SymKey(&key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); goto clearup; } ret = HcfCipherCreate("SM4_128|ECB|PKCS5", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto clearup; } ret = cipher->init(cipher, ENCRYPT_MODE, &(key->key), nullptr); if (ret != 0) { - LOGE("init failed! "); + LOGE_ONE_STR("init failed! "); goto clearup; } ret = cipher->doFinal(reinterpret_cast(key), &input, &output); if (ret != 0) { - LOGE("doFinal failed!"); + LOGE_ONE_STR("doFinal failed!"); } clearup: HcfObjDestroy(key); @@ -553,13 +553,13 @@ HWTEST_F(CryptoSM4EcbCipherTest, CryptoSm4CipherTest046, TestSize.Level0) ret = HcfCipherCreate("SM4_128|ECB|PKCS5", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto CLEAR_UP; } ret = cipher->init(cipher, ENCRYPT_MODE, nullptr, nullptr); if (ret != 0) { - LOGE("init failed! Should input key when init."); + LOGE_ONE_STR("init failed! Should input key when init."); } CLEAR_UP: @@ -580,12 +580,12 @@ HWTEST_F(CryptoSM4EcbCipherTest, CryptoAesCipherTest048, TestSize.Level0) ret = GenerateSymKeyForSm4("SM4_128", &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); goto CLEAR_UP; } ret = HcfCipherCreate("SM4_128|ECB|PKCS5", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto CLEAR_UP; } @@ -617,12 +617,12 @@ HWTEST_F(CryptoSM4EcbCipherTest, CryptoAesCipherTest049, TestSize.Level0) ret = GenerateSymKeyForSm4("SM4_128", &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); goto CLEAR_UP; } ret = HcfCipherCreate("SM4_128|ECB|PKCS5", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto CLEAR_UP; } @@ -657,19 +657,19 @@ HWTEST_F(CryptoSM4EcbCipherTest, CryptoSm4CipherTest053, TestSize.Level0) } ret = generator->generateSymKey(generator, &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); goto CLEAR_UP; } ret = HcfCipherCreate("SM4_128|ECB|PKCS5", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto CLEAR_UP; } ret = cipher->init(reinterpret_cast(generator), ENCRYPT_MODE, &(key->key), nullptr); if (ret != 0) { - LOGE("init failed! Should input key when init."); + LOGE_ONE_STR("init failed! Should input key when init."); } CLEAR_UP: @@ -689,25 +689,25 @@ HWTEST_F(CryptoSM4EcbCipherTest, CryptoSm4CipherTest054, TestSize.Level0) ret = GenerateSymKeyForSm4("SM4_128", &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); goto CLEAR_UP; } ret = HcfCipherCreate("SM4_128|ECB|PKCS5", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto CLEAR_UP; } ret = cipher->init(cipher, ENCRYPT_MODE, &(key->key), nullptr); if (ret != 0) { - LOGE("init failed!"); + LOGE_ONE_STR("init failed!"); goto CLEAR_UP; } ret = cipher->doFinal(cipher, &input, nullptr); if (ret != 0) { - LOGE("update failed! Blob data should not be nullptr."); + LOGE_ONE_STR("update failed! Blob data should not be nullptr."); } CLEAR_UP: @@ -726,14 +726,14 @@ HWTEST_F(CryptoSM4EcbCipherTest, CryptoSm4CipherTest058, TestSize.Level0) ret = GenerateSymKeyForSm4("SM4_128", &key); if (ret != 0) { - LOGE("GenerateSymKeyForSm4 failed!"); + LOGE_ONE_STR("GenerateSymKeyForSm4 failed!"); goto CLEAR_UP; } // allow input with more than one padding mode. It will pick the last PKCS5. ret = HcfCipherCreate("SM4_128|ECB|NoPadding|PKCS5", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto CLEAR_UP; } @@ -762,7 +762,7 @@ HWTEST_F(CryptoSM4EcbCipherTest, CryptoSm4CipherTest059, TestSize.Level0) ret = HcfCipherCreate("SM4_128|ECB|PKCS5", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto CLEAR_UP; } ret = HcfSymKeyGeneratorCreate("SM4_128", &generator); @@ -772,7 +772,7 @@ HWTEST_F(CryptoSM4EcbCipherTest, CryptoSm4CipherTest059, TestSize.Level0) } ret = generator->generateSymKey(reinterpret_cast(cipher), &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); } CLEAR_UP: @@ -792,13 +792,13 @@ HWTEST_F(CryptoSM4EcbCipherTest, CryptoSm4CipherTest061, TestSize.Level0) ret = GenerateSymKeyForSm4("AES256", &key); if (ret != 0) { - LOGE("GenerateSymKeyForSm4 failed!"); + LOGE_ONE_STR("GenerateSymKeyForSm4 failed!"); goto CLEAR_UP; } ret = HcfCipherCreate("SM4_128|ECB|PKCS5", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto CLEAR_UP; } diff --git a/test/unittest/src/crypto_sm4_gcm_cipher_test.cpp b/test/unittest/src/crypto_sm4_gcm_cipher_test.cpp index f58cef6d2684732f2e0de5b50bddb69fcc31bdf3..33678c694d6b91c4bea6c1026f794a017377a119 100644 --- a/test/unittest/src/crypto_sm4_gcm_cipher_test.cpp +++ b/test/unittest/src/crypto_sm4_gcm_cipher_test.cpp @@ -66,13 +66,13 @@ HWTEST_F(CryptoSM4GcmCipherTest, CryptoSM4GcmCipherTest001, TestSize.Level0) ret = GenerateSymKey("SM4_128", &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); goto CLEAR_UP; } ret = HcfCipherCreate("SM4_128|GCM|NoPadding", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto CLEAR_UP; } @@ -120,13 +120,13 @@ HWTEST_F(CryptoSM4GcmCipherTest, CryptoSM4GcmCipherTest002, TestSize.Level0) ret = GenerateSymKey("SM4_128", &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); goto CLEAR_UP; } ret = HcfCipherCreate("SM4_128|GCM|PKCS5", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto CLEAR_UP; } @@ -174,13 +174,13 @@ HWTEST_F(CryptoSM4GcmCipherTest, CryptoSM4GcmCipherTest003, TestSize.Level0) ret = GenerateSymKey("SM4_128", &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); goto CLEAR_UP; } ret = HcfCipherCreate("SM4_128|GCM|PKCS7", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto CLEAR_UP; } @@ -228,13 +228,13 @@ HWTEST_F(CryptoSM4GcmCipherTest, CryptoSM4GcmCipherTest004, TestSize.Level0) ret = GenerateSymKey("SM4_128", &key); if (ret != 0) { - LOGE("GenerateSymKey failed!"); + LOGE_ONE_STR("GenerateSymKey failed!"); goto CLEAR_UP; } ret = HcfCipherCreate("SM4_128|GCM|NoPadding", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto CLEAR_UP; } @@ -282,13 +282,13 @@ HWTEST_F(CryptoSM4GcmCipherTest, CryptoSM4GcmCipherTest005, TestSize.Level0) ret = GenerateSymKey("SM4_128", &key); if (ret != 0) { - LOGE("GenerateSymKey failed!"); + LOGE_ONE_STR("GenerateSymKey failed!"); goto CLEAR_UP; } ret = HcfCipherCreate("SM4_128|GCM|PKCS5", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto CLEAR_UP; } @@ -336,13 +336,13 @@ HWTEST_F(CryptoSM4GcmCipherTest, CryptoSM4GcmCipherTest006, TestSize.Level0) ret = GenerateSymKey("SM4_128", &key); if (ret != 0) { - LOGE("GenerateSymKey failed!"); + LOGE_ONE_STR("GenerateSymKey failed!"); goto CLEAR_UP; } ret = HcfCipherCreate("SM4_128|GCM|PKCS7", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto CLEAR_UP; } @@ -375,7 +375,7 @@ HWTEST_F(CryptoSM4GcmCipherTest, CryptoSM4GcmCipherTest009, TestSize.Level0) ret = HcfCipherCreate("RSA128|GCM|NoPadding", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed! Should not select RSA for GCM generator."); + LOGE_ONE_STR("HcfCipherCreate failed! Should not select RSA for GCM generator."); } HcfObjDestroy(cipher); @@ -390,7 +390,7 @@ HWTEST_F(CryptoSM4GcmCipherTest, CryptoSM4GcmCipherTest010, TestSize.Level0) // not allow '|' without content, because findAbility will fail for "" input ret = HcfCipherCreate("SM4_128|GCM|", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed! Should select padding mode for SM4_128 generator."); + LOGE_ONE_STR("HcfCipherCreate failed! Should select padding mode for SM4_128 generator."); } HcfObjDestroy(cipher); @@ -407,7 +407,7 @@ HWTEST_F(CryptoSM4GcmCipherTest, CryptoSM4GcmCipherTest011, TestSize.Level0) ret = GenerateSymKey("SM4_128", &key); if (ret != 0) { - LOGE("GenerateSymKey failed!"); + LOGE_ONE_STR("GenerateSymKey failed!"); goto CLEAR_UP; } @@ -415,7 +415,7 @@ HWTEST_F(CryptoSM4GcmCipherTest, CryptoSM4GcmCipherTest011, TestSize.Level0) // GCM, CCM enc/dec failed with params set to nullptr. ret = HcfCipherCreate("SM4_128|GCM|PKCS5", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto CLEAR_UP; } @@ -458,13 +458,13 @@ HWTEST_F(CryptoSM4GcmCipherTest, CryptoSM4GcmCipherTest012, TestSize.Level0) ret = GenerateSymKey("SM4_128", &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); goto CLEAR_UP; } ret = HcfCipherCreate("SM4_128|GCM|NoPadding", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto CLEAR_UP; } @@ -502,13 +502,13 @@ HWTEST_F(CryptoSM4GcmCipherTest, CryptoSM4GcmCipherTest013, TestSize.Level0) ret = GenerateSymKey("SM4_128", &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); goto CLEAR_UP; } ret = HcfCipherCreate("SM4_128|GCM|NoPadding", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto CLEAR_UP; } @@ -545,13 +545,13 @@ HWTEST_F(CryptoSM4GcmCipherTest, CryptoSM4GcmCipherTest014, TestSize.Level0) ret = GenerateSymKey("SM4_128", &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); goto CLEAR_UP; } ret = HcfCipherCreate("SM4_128|GCM|NoPadding", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto CLEAR_UP; } @@ -587,13 +587,13 @@ HWTEST_F(CryptoSM4GcmCipherTest, CryptoSM4GcmCipherTest015, TestSize.Level0) ret = GenerateSymKey("SM4_128", &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); goto CLEAR_UP; } ret = HcfCipherCreate("SM4_128|GCM|NoPadding", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto CLEAR_UP; } @@ -641,13 +641,13 @@ HWTEST_F(CryptoSM4GcmCipherTest, CryptoSM4GcmCipherTest016, TestSize.Level0) ret = GenerateSymKey("SM4_128", &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); goto CLEAR_UP; } ret = HcfCipherCreate("SM4_128|GCM|NoPadding", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto CLEAR_UP; } @@ -695,13 +695,13 @@ HWTEST_F(CryptoSM4GcmCipherTest, CryptoSM4GcmCipherTest017, TestSize.Level0) ret = GenerateSymKey("SM4_128", &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); goto CLEAR_UP; } ret = HcfCipherCreate("SM4_128|GCM|NoPadding", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto CLEAR_UP; } @@ -750,13 +750,13 @@ HWTEST_F(CryptoSM4GcmCipherTest, CryptoSM4GcmCipherTest018, TestSize.Level0) ret = GenerateSymKey("SM4_128", &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); goto CLEAR_UP; } ret = HcfCipherCreate("SM4_128|GCM|NoPadding", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto CLEAR_UP; } @@ -803,13 +803,13 @@ HWTEST_F(CryptoSM4GcmCipherTest, CryptoSM4GcmCipherTest019, TestSize.Level0) ret = GenerateSymKey("SM4_128", &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); goto CLEAR_UP; } ret = HcfCipherCreate("SM4_128|GCM|NoPadding", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto CLEAR_UP; } @@ -857,13 +857,13 @@ HWTEST_F(CryptoSM4GcmCipherTest, CryptoSM4GcmCipherTest020, TestSize.Level0) ret = GenerateSymKey("SM4_128", &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); HcfObjDestroy((HcfObjectBase *)key); } ret = HcfCipherCreate("SM4_128|GCM|NoPadding", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); HcfObjDestroy((HcfObjectBase *)key); HcfObjDestroy((HcfObjectBase *)cipher); } @@ -903,13 +903,13 @@ HWTEST_F(CryptoSM4GcmCipherTest, CryptoSM4GcmCipherTest021, TestSize.Level0) ret = GenerateSymKey("SM4_128", &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); HcfObjDestroy((HcfObjectBase *)key); } ret = HcfCipherCreate("SM4_128|GCM|NoPadding", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); HcfObjDestroy((HcfObjectBase *)key); HcfObjDestroy((HcfObjectBase *)cipher); } diff --git a/test/unittest/src/crypto_sm4_generator_test.cpp b/test/unittest/src/crypto_sm4_generator_test.cpp index 264622904209a75ca73e9852a5d3cda102cc9af7..ea3377f18a10d3dc5e67079ad74027ab5b3967ca 100644 --- a/test/unittest/src/crypto_sm4_generator_test.cpp +++ b/test/unittest/src/crypto_sm4_generator_test.cpp @@ -59,13 +59,13 @@ static int32_t GenerateSymKey(const char *algoName, HcfSymKey **key) int32_t ret = HcfSymKeyGeneratorCreate(algoName, &generator); if (ret != 0) { - LOGE("HcfSymKeyGeneratorCreate failed!"); + LOGE_ONE_STR("HcfSymKeyGeneratorCreate failed!"); return ret; } ret = generator->generateSymKey(generator, key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); } HcfObjDestroy((HcfObjectBase *)generator); return ret; @@ -81,26 +81,26 @@ HWTEST_F(CryptoSM4GeneratorTest, CryptoSm4GeneratorTest001, TestSize.Level0) ret = HcfSymKeyGeneratorCreate(inputAlgoName, &generator); if (ret != 0) { - LOGE("HcfSymKeyGeneratorCreate failed!"); + LOGE_ONE_STR("HcfSymKeyGeneratorCreate failed!"); goto CLEAR_UP; } ret = generator->generateSymKey(generator, &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); goto CLEAR_UP; } // generator getAlgoName generatorAlgoName = generator->getAlgoName(generator); if (generatorAlgoName == nullptr) { - LOGE("generator getAlgoName returns nullptr."); + LOGE_ONE_STR("generator getAlgoName returns nullptr."); ret = HCF_ERR_CRYPTO_OPERATION; goto CLEAR_UP; } ret = strcmp(generatorAlgoName, inputAlgoName); if (ret != 0) { - LOGE("generator getAlgoName failed!"); + LOGE_ONE_STR("generator getAlgoName failed!"); } CLEAR_UP: HcfObjDestroy(key); @@ -117,14 +117,14 @@ HWTEST_F(CryptoSM4GeneratorTest, CryptoSm4GeneratorTest002, TestSize.Level0) ret = HcfSymKeyGeneratorCreate(inputAlgoName, &generator); if (ret != 0) { - LOGE("HcfSymKeyGeneratorCreate failed!"); + LOGE_ONE_STR("HcfSymKeyGeneratorCreate failed!"); goto CLEAR_UP; } // generator getAlgoName generatorAlgoName = generator->getAlgoName(nullptr); if (generatorAlgoName == nullptr) { - LOGE("generator getAlgoName failed!"); + LOGE_ONE_STR("generator getAlgoName failed!"); ret = HCF_ERR_CRYPTO_OPERATION; } @@ -143,19 +143,19 @@ HWTEST_F(CryptoSM4GeneratorTest, CryptoSm4GeneratorTest003, TestSize.Level0) ret = HcfSymKeyGeneratorCreate(inputAlgoName, &generator); if (ret != 0) { - LOGE("HcfSymKeyGeneratorCreate failed!"); + LOGE_ONE_STR("HcfSymKeyGeneratorCreate failed!"); goto CLEAR_UP; } ret = generator->generateSymKey(generator, &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); goto CLEAR_UP; } // generator getAlgoName generatorAlgoName = generator->getAlgoName(reinterpret_cast(key)); if (generatorAlgoName == nullptr) { - LOGE("generator getAlgoName failed!"); + LOGE_ONE_STR("generator getAlgoName failed!"); ret = HCF_ERR_CRYPTO_OPERATION; } @@ -174,14 +174,14 @@ HWTEST_F(CryptoSM4GeneratorTest, CryptoSm4GeneratorTest004, TestSize.Level0) ret = GenerateSymKey(inputAlgoName, &key); if (ret != 0) { - LOGE("GenerateSymKey failed!"); + LOGE_ONE_STR("GenerateSymKey failed!"); goto CLEAR_UP; } // key getAlgorithm keyAlgoName = key->key.getAlgorithm(nullptr); if (keyAlgoName == nullptr) { - LOGE("key getAlgorithm returns nullptr."); + LOGE_ONE_STR("key getAlgorithm returns nullptr."); ret = HCF_ERR_CRYPTO_OPERATION; } @@ -200,19 +200,19 @@ HWTEST_F(CryptoSM4GeneratorTest, CryptoSm4GeneratorTest005, TestSize.Level0) ret = HcfSymKeyGeneratorCreate(inputAlgoName, &generator); if (ret != 0) { - LOGE("HcfSymKeyGeneratorCreate failed!"); + LOGE_ONE_STR("HcfSymKeyGeneratorCreate failed!"); goto CLEAR_UP; } ret = generator->generateSymKey(generator, &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); goto CLEAR_UP; } // key getAlgorithm keyAlgoName = key->key.getAlgorithm(reinterpret_cast(generator)); if (keyAlgoName == nullptr) { - LOGE("key getAlgorithm returns nullptr."); + LOGE_ONE_STR("key getAlgorithm returns nullptr."); ret = HCF_ERR_CRYPTO_OPERATION; } @@ -230,14 +230,14 @@ HWTEST_F(CryptoSM4GeneratorTest, CryptoSm4GeneratorTest006, TestSize.Level0) ret = GenerateSymKey("SM4_128", &key); if (ret != 0) { - LOGE("GenerateSymKey failed!"); + LOGE_ONE_STR("GenerateSymKey failed!"); goto CLEAR_UP; } // key getFormat retFormat = key->key.getFormat(nullptr); if (retFormat == nullptr) { - LOGE("key GetFormat returns nullptr."); + LOGE_ONE_STR("key GetFormat returns nullptr."); ret = HCF_ERR_CRYPTO_OPERATION; } @@ -255,19 +255,19 @@ HWTEST_F(CryptoSM4GeneratorTest, CryptoSm4GeneratorTest007, TestSize.Level0) ret = HcfSymKeyGeneratorCreate("SM4_128", &generator); if (ret != 0) { - LOGE("HcfSymKeyGeneratorCreate failed!"); + LOGE_ONE_STR("HcfSymKeyGeneratorCreate failed!"); goto CLEAR_UP; } ret = generator->generateSymKey(generator, &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); goto CLEAR_UP; } // key getFormat retFormat = key->key.getFormat(reinterpret_cast(generator)); if (retFormat == nullptr) { - LOGE("key GetFormat returns nullptr."); + LOGE_ONE_STR("key GetFormat returns nullptr."); ret = HCF_ERR_CRYPTO_OPERATION; } @@ -291,19 +291,19 @@ HWTEST_F(CryptoSM4GeneratorTest, CryptoSm4GeneratorTest008, TestSize.Level0) ret = HcfSymKeyGeneratorCreate("SM4_128", &generator); if (ret != 0) { - LOGE("HcfSymKeyGeneratorCreate failed!"); + LOGE_ONE_STR("HcfSymKeyGeneratorCreate failed!"); goto CLEAR_UP; } ret = generator->convertSymKey(generator, &keyTmpBlob, &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); goto CLEAR_UP; } // key getEncoded ret = key->key.getEncoded(nullptr, &encodedBlob); if (ret != 0) { - LOGE("key GetEncoded failed."); + LOGE_ONE_STR("key GetEncoded failed."); } CLEAR_UP: @@ -330,19 +330,19 @@ HWTEST_F(CryptoSM4GeneratorTest, CryptoSm4GeneratorTest009, TestSize.Level0) ret = HcfSymKeyGeneratorCreate("SM4_128", &generator); if (ret != 0) { - LOGE("HcfSymKeyGeneratorCreate failed!"); + LOGE_ONE_STR("HcfSymKeyGeneratorCreate failed!"); goto CLEAR_UP; } ret = generator->convertSymKey(generator, &keyTmpBlob, &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); goto CLEAR_UP; } // key getEncoded ret = key->key.getEncoded(reinterpret_cast(generator), &encodedBlob); if (ret != 0) { - LOGE("key GetEncoded failed."); + LOGE_ONE_STR("key GetEncoded failed."); } CLEAR_UP: @@ -371,12 +371,12 @@ HWTEST_F(CryptoSM4GeneratorTest, CryptoSm4GeneratorTest010, TestSize.Level0) ret = HcfSymKeyGeneratorCreate("SM4_128", &generator); if (ret != 0) { - LOGE("HcfSymKeyGeneratorCreate failed!"); + LOGE_ONE_STR("HcfSymKeyGeneratorCreate failed!"); goto CLEAR_UP; } ret = generator->convertSymKey(generator, &keyTmpBlob, &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); goto CLEAR_UP; } impl = reinterpret_cast(key); @@ -387,7 +387,7 @@ HWTEST_F(CryptoSM4GeneratorTest, CryptoSm4GeneratorTest010, TestSize.Level0) ret = key->key.getEncoded(&(key->key), &encodedBlob); impl->keyMaterial.len = tmpLen; if (ret != 0) { - LOGE("key GetEncoded failed."); + LOGE_ONE_STR("key GetEncoded failed."); } CLEAR_UP: @@ -414,12 +414,12 @@ HWTEST_F(CryptoSM4GeneratorTest, CryptoSm4GeneratorTest011, TestSize.Level0) ret = HcfSymKeyGeneratorCreate("SM4_128", &generator); if (ret != 0) { - LOGE("HcfSymKeyGeneratorCreate failed!"); + LOGE_ONE_STR("HcfSymKeyGeneratorCreate failed!"); goto CLEAR_UP; } ret = generator->convertSymKey(generator, &keyTmpBlob, &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); goto CLEAR_UP; } @@ -427,11 +427,11 @@ HWTEST_F(CryptoSM4GeneratorTest, CryptoSm4GeneratorTest011, TestSize.Level0) ret = key->key.getEncoded(&(key->key), &encodedBlob); if (ret != 0) { - LOGE("key GetEncoded failed."); + LOGE_ONE_STR("key GetEncoded failed."); goto CLEAR_UP; } if ((encodedBlob.data != nullptr) && (encodedBlob.data[0] != '\0')) { - LOGE("clearMem failed!"); + LOGE_ONE_STR("clearMem failed!"); ret = HCF_ERR_CRYPTO_OPERATION; } @@ -452,7 +452,7 @@ HWTEST_F(CryptoSM4GeneratorTest, CryptoSm4GeneratorTest012, TestSize.Level0) ret = HcfSymKeyGeneratorCreate("SM4_128", &generator); if (ret != 0) { - LOGE("HcfSymKeyGeneratorCreate failed! Should not select RSA for symKey generator."); + LOGE_ONE_STR("HcfSymKeyGeneratorCreate failed! Should not select RSA for symKey generator."); } HcfObjDestroy(generator); @@ -466,7 +466,7 @@ HWTEST_F(CryptoSM4GeneratorTest, CryptoSm4GeneratorTest013, TestSize.Level0) ret = HcfSymKeyGeneratorCreate("", &generator); if (ret != 0) { - LOGE("HcfSymKeyGeneratorCreate failed! Should not select empty string for symKey generator."); + LOGE_ONE_STR("HcfSymKeyGeneratorCreate failed! Should not select empty string for symKey generator."); } HcfObjDestroy(generator); @@ -480,7 +480,7 @@ HWTEST_F(CryptoSM4GeneratorTest, CryptoSm4GeneratorTest014, TestSize.Level0) ret = HcfSymKeyGeneratorCreate(nullptr, &generator); if (ret != 0) { - LOGE("HcfSymKeyGeneratorCreate failed! Should not select nullptr for symKey generator."); + LOGE_ONE_STR("HcfSymKeyGeneratorCreate failed! Should not select nullptr for symKey generator."); } HcfObjDestroy(generator); @@ -494,7 +494,7 @@ HWTEST_F(CryptoSM4GeneratorTest, CryptoSm4GeneratorTest015, TestSize.Level0) ret = HcfSymKeyGeneratorSpiCreate(nullptr, nullptr); if (ret != 0) { - LOGE("HcfSymKeyGeneratorSpiCreate failed!"); + LOGE_ONE_STR("HcfSymKeyGeneratorSpiCreate failed!"); } HcfObjDestroy(generator); @@ -509,12 +509,12 @@ HWTEST_F(CryptoSM4GeneratorTest, CryptoSm4GeneratorTest016, TestSize.Level0) ret = HcfSymKeyGeneratorCreate("SM4_128", &generator); if (ret != 0) { - LOGE("HcfSymKeyGeneratorCreate failed!"); + LOGE_ONE_STR("HcfSymKeyGeneratorCreate failed!"); goto CLEAR_UP; } ret = generator->generateSymKey(nullptr, &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); } CLEAR_UP: @@ -532,17 +532,17 @@ HWTEST_F(CryptoSM4GeneratorTest, CryptoSm4GeneratorTest017, TestSize.Level0) ret = HcfCipherCreate("SM4_128|ECB|PKCS5", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto CLEAR_UP; } ret = HcfSymKeyGeneratorCreate("SM4_128", &generator); if (ret != 0) { - LOGE("HcfSymKeyGeneratorCreate failed!"); + LOGE_ONE_STR("HcfSymKeyGeneratorCreate failed!"); goto CLEAR_UP; } ret = generator->generateSymKey(reinterpret_cast(cipher), &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); } CLEAR_UP: @@ -565,13 +565,13 @@ HWTEST_F(CryptoSM4GeneratorTest, CryptoSm4GeneratorTest018, TestSize.Level0) ret = HcfSymKeyGeneratorCreate("SM4_128", &generator); if (ret != 0) { - LOGE("HcfSymKeyGeneratorCreate failed!"); + LOGE_ONE_STR("HcfSymKeyGeneratorCreate failed!"); goto CLEAR_UP; } ret = generator->convertSymKey(nullptr, &keyTmpBlob, &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); } CLEAR_UP: @@ -594,18 +594,18 @@ HWTEST_F(CryptoSM4GeneratorTest, CryptoSm4GeneratorTest019, TestSize.Level0) ret = HcfCipherCreate("SM4_128|ECB|PKCS5", &cipher); if (ret != 0) { - LOGE("HcfCipherCreate failed!"); + LOGE_ONE_STR("HcfCipherCreate failed!"); goto CLEAR_UP; } ret = HcfSymKeyGeneratorCreate("SM4_128", &generator); if (ret != 0) { - LOGE("HcfSymKeyGeneratorCreate failed!"); + LOGE_ONE_STR("HcfSymKeyGeneratorCreate failed!"); goto CLEAR_UP; } ret = generator->convertSymKey(reinterpret_cast(cipher), &keyTmpBlob, &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); } CLEAR_UP: @@ -628,13 +628,13 @@ HWTEST_F(CryptoSM4GeneratorTest, CryptoSm4GeneratorTest020, TestSize.Level0) ret = HcfSymKeyGeneratorCreate("SM4_128", &generator); if (ret != 0) { - LOGE("HcfSymKeyGeneratorCreate failed!"); + LOGE_ONE_STR("HcfSymKeyGeneratorCreate failed!"); goto CLEAR_UP; } ret = generator->convertSymKey(generator, &keyTmpBlob, &key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); } CLEAR_UP: diff --git a/test/unittest/src/memory_mock.c b/test/unittest/src/memory_mock.c index dec9502665a673bb3fe913f3426e939b0194c1a2..255956670c7bc06803a7f46c7abef35d56c7040f 100755 --- a/test/unittest/src/memory_mock.c +++ b/test/unittest/src/memory_mock.c @@ -31,7 +31,7 @@ void *HcfMalloc(uint32_t size, char val) } if (g_isRecordMallocNum) { if (g_mallocNum == g_mallocMockIndex) { - LOGD("mock malloc return NULL."); + LOGD_ONE_STR("mock malloc return NULL."); return NULL; } g_mallocNum++; diff --git a/test/unittest/src/native/native_sym_cipher_test.cpp b/test/unittest/src/native/native_sym_cipher_test.cpp index 607652bf1c91d132bd103cfc82ab1d2bcf034f7c..618a76ceb8a8058b11f8a728917f1361c4a72334 100644 --- a/test/unittest/src/native/native_sym_cipher_test.cpp +++ b/test/unittest/src/native/native_sym_cipher_test.cpp @@ -64,7 +64,7 @@ OH_Crypto_ErrCode AesEncrypt(OH_CryptoSymCipher *cipher, OH_CryptoSymKey *key, O ret = OH_CryptoSymCipher_Update(cipher, &input, &output); if (ret != CRYPTO_SUCCESS) { - LOGE("update failed!"); + LOGE_ONE_STR("update failed!"); return ret; } *cipherTextLen = output.len; @@ -78,7 +78,7 @@ OH_Crypto_ErrCode AesEncrypt(OH_CryptoSymCipher *cipher, OH_CryptoSymKey *key, O ret = OH_CryptoSymCipher_Final(cipher, nullptr, &output); if (ret != CRYPTO_SUCCESS) { - LOGE("doFinal failed!"); + LOGE_ONE_STR("doFinal failed!"); return ret; } if (output.data != nullptr) { @@ -108,7 +108,7 @@ OH_Crypto_ErrCode AesDecrypt(OH_CryptoSymCipher *cipher, OH_CryptoSymKey *key, O ret = OH_CryptoSymCipher_Update(cipher, &input, &output); if (ret != CRYPTO_SUCCESS) { - LOGE("update failed!"); + LOGE_ONE_STR("update failed!"); return ret; } cipherTextLen = output.len; @@ -122,7 +122,7 @@ OH_Crypto_ErrCode AesDecrypt(OH_CryptoSymCipher *cipher, OH_CryptoSymKey *key, O ret = OH_CryptoSymCipher_Final(cipher, nullptr, &output); if (ret != CRYPTO_SUCCESS) { - LOGE("doFinal failed!"); + LOGE_ONE_STR("doFinal failed!"); return ret; } if (output.data != nullptr) { diff --git a/test/unittest/src/openssl_adapter_mock.c b/test/unittest/src/openssl_adapter_mock.c index 10e8ed9b5c198fb841fea77355de1501d27104fe..7c949a399b1fd3cfa69c19f26c3873c905e94a0e 100644 --- a/test/unittest/src/openssl_adapter_mock.c +++ b/test/unittest/src/openssl_adapter_mock.c @@ -34,7 +34,7 @@ static bool IsNeedMock(void) } g_callNum++; if (g_callNum == g_mockIndex) { - LOGD("mock malloc return NULL."); + LOGD_ONE_STR("mock malloc return NULL."); return true; } return false; diff --git a/test/unittest/src/sm4_common.cpp b/test/unittest/src/sm4_common.cpp index bba4858eff69a4cefb972224375ce293a62b932b..8087dee4e972028e4ec36a57f8c0a1815574548e 100644 --- a/test/unittest/src/sm4_common.cpp +++ b/test/unittest/src/sm4_common.cpp @@ -38,13 +38,13 @@ HcfResult GenerateSm4SymKey(HcfSymKey **key) HcfResult ret = HcfSymKeyGeneratorCreate("SM4_128", &generator); if (ret != HCF_SUCCESS || generator == nullptr) { - LOGE("HcfSymKeyGeneratorCreate failed!"); + LOGE_ONE_STR("HcfSymKeyGeneratorCreate failed!"); return ret; } ret = generator->generateSymKey(generator, key); if (ret != HCF_SUCCESS) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); } HcfObjDestroy(generator); return ret; @@ -56,13 +56,13 @@ int32_t GenerateSymKeyForSm4(const char *algoName, HcfSymKey **key) int32_t ret = HcfSymKeyGeneratorCreate(algoName, &generator); if (ret != 0 || generator == nullptr) { - LOGE("HcfSymKeyGeneratorCreate failed!"); + LOGE_ONE_STR("HcfSymKeyGeneratorCreate failed!"); return ret; } ret = generator->generateSymKey(generator, key); if (ret != 0) { - LOGE("generateSymKey failed!"); + LOGE_ONE_STR("generateSymKey failed!"); } HcfObjDestroy(reinterpret_cast(generator)); return ret; @@ -83,7 +83,7 @@ int32_t Sm4EncryptWithInput(HcfCipher *cipher, HcfSymKey *key, HcfBlob *input, ret = cipher->update(cipher, input, &output); if (ret != 0) { - LOGE("update failed!"); + LOGE_ONE_STR("update failed!"); return ret; } *cipherTextLen = output.len; @@ -97,7 +97,7 @@ int32_t Sm4EncryptWithInput(HcfCipher *cipher, HcfSymKey *key, HcfBlob *input, ret = cipher->doFinal(cipher, nullptr, &output); if (ret != 0) { - LOGE("doFinal failed!"); + LOGE_ONE_STR("doFinal failed!"); return ret; } if (output.data != nullptr) { @@ -126,7 +126,7 @@ int32_t Sm4DecryptEmptyMsg(HcfCipher *cipher, HcfSymKey *key, HcfParamsSpec *par ret = cipher->doFinal(cipher, &input, &output); if (ret != 0) { - LOGE("doFinal failed!"); + LOGE_ONE_STR("doFinal failed!"); return ret; } if (output.len == 0 && output.data == nullptr) { @@ -148,13 +148,13 @@ int32_t Sm4Encrypt(HcfCipher *cipher, HcfSymKey *key, HcfParamsSpec *params, int32_t maxLen = *cipherTextLen; int32_t ret = cipher->init(cipher, ENCRYPT_MODE, reinterpret_cast(key), params); if (ret != 0) { - LOGE("init failed! "); + LOGE_ONE_STR("init failed! "); return ret; } ret = cipher->update(cipher, &input, &output); if (ret != 0) { - LOGE("update failed!"); + LOGE_ONE_STR("update failed!"); return ret; } *cipherTextLen = output.len; @@ -168,7 +168,7 @@ int32_t Sm4Encrypt(HcfCipher *cipher, HcfSymKey *key, HcfParamsSpec *params, ret = cipher->doFinal(cipher, nullptr, &output); if (ret != 0) { - LOGE("doFinal failed!"); + LOGE_ONE_STR("doFinal failed!"); return ret; } if (output.data != nullptr) { @@ -191,13 +191,13 @@ int32_t Sm4Decrypt(HcfCipher *cipher, HcfSymKey *key, HcfParamsSpec *params, int32_t maxLen = cipherTextLen; int32_t ret = cipher->init(cipher, DECRYPT_MODE, reinterpret_cast(key), params); if (ret != 0) { - LOGE("init failed! "); + LOGE_ONE_STR("init failed! "); return ret; } ret = cipher->update(cipher, &input, &output); if (ret != 0) { - LOGE("update failed!"); + LOGE_ONE_STR("update failed!"); return ret; } cipherTextLen = output.len; @@ -211,7 +211,7 @@ int32_t Sm4Decrypt(HcfCipher *cipher, HcfSymKey *key, HcfParamsSpec *params, ret = cipher->doFinal(cipher, nullptr, &output); if (ret != 0) { - LOGE("doFinal failed!"); + LOGE_ONE_STR("doFinal failed!"); return ret; } if (output.data != nullptr) { @@ -238,14 +238,14 @@ int32_t Sm4NoUpdateEncrypt(HcfCipher *cipher, HcfSymKey *key, HcfParamsSpec *par int32_t maxLen = *cipherTextLen; int32_t ret = cipher->init(cipher, ENCRYPT_MODE, reinterpret_cast(key), params); if (ret != 0) { - LOGE("init failed! "); + LOGE_ONE_STR("init failed! "); return ret; } *cipherTextLen = 0; ret = cipher->doFinal(cipher, &input, &output); if (ret != 0) { - LOGE("doFinal failed!"); + LOGE_ONE_STR("doFinal failed!"); return ret; } if (output.data != nullptr) { @@ -268,14 +268,14 @@ int32_t Sm4NoUpdateDecrypt(HcfCipher *cipher, HcfSymKey *key, HcfParamsSpec *par int32_t maxLen = cipherTextLen; int32_t ret = cipher->init(cipher, DECRYPT_MODE, reinterpret_cast(key), params); if (ret != 0) { - LOGE("init failed! "); + LOGE_ONE_STR("init failed! "); return ret; } cipherTextLen = 0; ret = cipher->doFinal(cipher, &input, &output); if (ret != 0) { - LOGE("doFinal failed!"); + LOGE_ONE_STR("doFinal failed!"); return ret; } if (output.data != nullptr) {