mirror of
https://github.com/openharmony/security_device_auth.git
synced 2026-08-25 09:19:33 -04:00
@@ -25,7 +25,6 @@
|
||||
#define OUT_OF_HEX 16
|
||||
#define NUMBER_9_IN_DECIMAL 9
|
||||
#define ASCII_CASE_DIFFERENCE_VALUE 32
|
||||
#define DESENSITIZATION_LEN 4
|
||||
|
||||
static const char * const g_base64CharacterTable =
|
||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
||||
@@ -109,32 +108,6 @@ int64_t StringToInt64(const char *cp)
|
||||
return strtoll(cp, NULL, DEC);
|
||||
}
|
||||
|
||||
void ConvertToAnonymousStr(const char *originalStr, char **anonymousStr)
|
||||
{
|
||||
if ((originalStr == NULL) || (anonymousStr == NULL)) {
|
||||
return;
|
||||
}
|
||||
uint32_t desensitizationLen = DESENSITIZATION_LEN;
|
||||
uint32_t len = strlen(originalStr);
|
||||
if (len <= desensitizationLen) {
|
||||
return;
|
||||
}
|
||||
*anonymousStr = (char *)ClibMalloc(len + 1, 0);
|
||||
if ((*anonymousStr) == NULL) {
|
||||
return;
|
||||
}
|
||||
if (memset_s(*anonymousStr, len + 1, '*', len) != EOK) {
|
||||
ClibFree(*anonymousStr);
|
||||
*anonymousStr = NULL;
|
||||
return;
|
||||
}
|
||||
if (memcpy_s(*anonymousStr, len + 1, originalStr, len - desensitizationLen) != EOK) {
|
||||
ClibFree(*anonymousStr);
|
||||
*anonymousStr = NULL;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
static bool IsInvalidBase64Character(char c)
|
||||
{
|
||||
if (('A' <= c && c <= 'Z') || ('a' <= c && c <= 'z')) {
|
||||
|
||||
@@ -58,13 +58,6 @@ int32_t ByteToHexString(const uint8_t *byte, uint32_t byteLen, char *hexStr, uin
|
||||
*/
|
||||
int64_t StringToInt64(const char *cp);
|
||||
|
||||
/*
|
||||
* Convert string to anonymous string.
|
||||
* @param originalStr: string to be converted
|
||||
* @param anonymousStr: the converted result
|
||||
*/
|
||||
void ConvertToAnonymousStr(const char *originalStr, char **anonymousStr);
|
||||
|
||||
/*
|
||||
* Convert base64 string to byte.
|
||||
* @param base64Str: base64 string
|
||||
|
||||
@@ -46,22 +46,22 @@ static int32_t ConstructParamSet(struct HksParamSet **out, const struct HksParam
|
||||
const uint32_t inParamNum)
|
||||
{
|
||||
struct HksParamSet *paramSet = NULL;
|
||||
int32_t ret = HksInitParamSet(¶mSet);
|
||||
if (ret != HKS_SUCCESS) {
|
||||
LOGE("init param set failed, ret = %d", ret);
|
||||
int32_t res = HksInitParamSet(¶mSet);
|
||||
if (res != HKS_SUCCESS) {
|
||||
LOGE("init param set failed, res = %d", res);
|
||||
return HAL_ERR_INIT_PARAM_SET_FAILED;
|
||||
}
|
||||
|
||||
ret = HksAddParams(paramSet, inParam, inParamNum);
|
||||
if (ret != HKS_SUCCESS) {
|
||||
LOGE("add param failed, ret = %d", ret);
|
||||
res = HksAddParams(paramSet, inParam, inParamNum);
|
||||
if (res != HKS_SUCCESS) {
|
||||
LOGE("add param failed, res = %d", res);
|
||||
HksFreeParamSet(¶mSet);
|
||||
return HAL_ERR_ADD_PARAM_FAILED;
|
||||
}
|
||||
|
||||
ret = HksBuildParamSet(¶mSet);
|
||||
if (ret != HKS_SUCCESS) {
|
||||
LOGE("build param set failed, ret = %d", ret);
|
||||
res = HksBuildParamSet(¶mSet);
|
||||
if (res != HKS_SUCCESS) {
|
||||
LOGE("build param set failed, res = %d", res);
|
||||
HksFreeParamSet(¶mSet);
|
||||
return HAL_ERR_BUILD_PARAM_SET_FAILED;
|
||||
}
|
||||
@@ -72,29 +72,34 @@ static int32_t ConstructParamSet(struct HksParamSet **out, const struct HksParam
|
||||
|
||||
static int32_t InitHks(void)
|
||||
{
|
||||
LOGI("[HUKS]: HksInitialize enter.");
|
||||
int32_t res = HksInitialize();
|
||||
LOGI("[HUKS]: HksInitialize quit. [Res]: %d", res);
|
||||
if (res == HKS_SUCCESS) {
|
||||
return HAL_SUCCESS;
|
||||
}
|
||||
|
||||
if ((res != HKS_ERROR_INVALID_KEY_FILE) && (res != HKS_ERROR_CRYPTO_ENGINE_ERROR) &&
|
||||
(res != HKS_ERROR_UPDATE_ROOT_KEY_MATERIAL_FAIL)) {
|
||||
LOGE("Hks: Init hks failed, res: %d.", res);
|
||||
LOGE("[HUKS]: HksInitialize fail. [Res]: %d", res);
|
||||
return HAL_ERR_INIT_FAILED;
|
||||
}
|
||||
|
||||
LOGD("Hks: The local hks file needs to be refreshed!");
|
||||
LOGI("Start to delete local database file!");
|
||||
HcFileRemove(GetStoragePath());
|
||||
LOGI("Delete local database file successfully!");
|
||||
LOGI("[HUKS]: HksRefreshKeyInfo enter.");
|
||||
res = HksRefreshKeyInfo();
|
||||
LOGI("[HUKS]: HksRefreshKeyInfo quit. [Res]: %d", res);
|
||||
if (res != HKS_SUCCESS) {
|
||||
LOGE("Hks: HksRefreshKeyInfo failed, res: %d.", res);
|
||||
LOGE("[HUKS]: HksRefreshKeyInfo failed, res: %d", res);
|
||||
return HAL_ERR_INIT_FAILED;
|
||||
}
|
||||
LOGI("[HUKS]: HksInitialize enter.");
|
||||
res = HksInitialize();
|
||||
LOGI("[HUKS]: HksInitialize quit. [Res]: %d", res);
|
||||
if (res != HKS_SUCCESS) {
|
||||
LOGE("Hks: Init hks failed, res: %d.", res);
|
||||
LOGE("[HUKS]: HksInitialize fail. [Res]: %d", res);
|
||||
return HAL_ERR_INIT_FAILED;
|
||||
}
|
||||
|
||||
@@ -120,14 +125,15 @@ static int32_t Sha256(const Uint8Buff *message, Uint8Buff *hash)
|
||||
.uint32Param = HKS_DIGEST_SHA256
|
||||
}
|
||||
};
|
||||
int32_t ret = ConstructParamSet(¶mSet, digestParam, CAL_ARRAY_SIZE(digestParam));
|
||||
if (ret != HAL_SUCCESS) {
|
||||
LOGE("construct param set failed, ret = %d", ret);
|
||||
return ret;
|
||||
int32_t res = ConstructParamSet(¶mSet, digestParam, CAL_ARRAY_SIZE(digestParam));
|
||||
if (res != HAL_SUCCESS) {
|
||||
LOGE("construct param set failed, res = %d", res);
|
||||
return res;
|
||||
}
|
||||
|
||||
ret = HksHash(paramSet, &srcBlob, &hashBlob);
|
||||
if (ret != HKS_SUCCESS || hashBlob.size != SHA256_LEN) {
|
||||
res = HksHash(paramSet, &srcBlob, &hashBlob);
|
||||
if (res != HKS_SUCCESS || hashBlob.size != SHA256_LEN) {
|
||||
LOGE("[HUKS]: HksHash fail. [Res]: %d", res);
|
||||
HksFreeParamSet(¶mSet);
|
||||
return HAL_FAILED;
|
||||
}
|
||||
@@ -143,9 +149,9 @@ static int32_t GenerateRandom(Uint8Buff *rand)
|
||||
CHECK_LEN_ZERO_RETURN_ERROR_CODE(rand->length, "rand->length");
|
||||
|
||||
struct HksBlob randBlob = { rand->length, rand->val };
|
||||
int32_t ret = HksGenerateRandom(NULL, &randBlob);
|
||||
if (ret != HKS_SUCCESS) {
|
||||
LOGE("Generate random failed, ret: %d", ret);
|
||||
int32_t res = HksGenerateRandom(NULL, &randBlob);
|
||||
if (res != HKS_SUCCESS) {
|
||||
LOGE("[HUKS]: HksGenerateRandom fail. [Res]: %d", res);
|
||||
return HAL_FAILED;
|
||||
}
|
||||
|
||||
@@ -159,9 +165,9 @@ static int32_t CheckKeyExist(const Uint8Buff *keyAlias)
|
||||
CHECK_LEN_ZERO_RETURN_ERROR_CODE(keyAlias->length, "keyAlias->length");
|
||||
|
||||
struct HksBlob keyAliasBlob = { keyAlias->length, keyAlias->val };
|
||||
int32_t ret = HksKeyExist(&keyAliasBlob, NULL);
|
||||
if (ret != HKS_SUCCESS) {
|
||||
LOGE("Check key exist failed, ret = %d", ret);
|
||||
int32_t res = HksKeyExist(&keyAliasBlob, NULL);
|
||||
if (res != HKS_SUCCESS) {
|
||||
LOGI("[HUKS]: HksKeyExist fail. [Res]: %d", res);
|
||||
return HAL_FAILED;
|
||||
}
|
||||
|
||||
@@ -175,13 +181,15 @@ static int32_t DeleteKey(const Uint8Buff *keyAlias)
|
||||
CHECK_LEN_ZERO_RETURN_ERROR_CODE(keyAlias->length, "keyAlias->length");
|
||||
|
||||
struct HksBlob keyAliasBlob = { keyAlias->length, keyAlias->val };
|
||||
int32_t ret = HksDeleteKey(&keyAliasBlob, NULL);
|
||||
if (ret == HKS_ERROR_NOT_EXIST) {
|
||||
LOGI("[HUKS]: HksDeleteKey enter.");
|
||||
int32_t res = HksDeleteKey(&keyAliasBlob, NULL);
|
||||
LOGI("[HUKS]: HksDeleteKey quit. [Res]: %d", res);
|
||||
if (res == HKS_ERROR_NOT_EXIST) {
|
||||
LOGI("Key not exists.");
|
||||
return HAL_SUCCESS;
|
||||
}
|
||||
if (ret != HKS_SUCCESS) {
|
||||
LOGE("Delete key failed, ret = %d", ret);
|
||||
if (res != HKS_SUCCESS) {
|
||||
LOGE("[HUKS]: HksDeleteKey fail. [Res]: %d", res);
|
||||
return HAL_FAILED;
|
||||
}
|
||||
|
||||
@@ -192,9 +200,9 @@ static int32_t ComputeHmac(const Uint8Buff *key, const Uint8Buff *message, Uint8
|
||||
{
|
||||
const Uint8Buff *inParams[] = { key, message, outHmac };
|
||||
const char *paramTags[] = {"key", "message", "outHmac"};
|
||||
int32_t ret = BaseCheckParams(inParams, paramTags, CAL_ARRAY_SIZE(inParams));
|
||||
if (ret != HAL_SUCCESS) {
|
||||
return ret;
|
||||
int32_t res = BaseCheckParams(inParams, paramTags, CAL_ARRAY_SIZE(inParams));
|
||||
if (res != HAL_SUCCESS) {
|
||||
return res;
|
||||
}
|
||||
CHECK_LEN_EQUAL_RETURN(outHmac->length, HMAC_LEN, "outHmac->length");
|
||||
|
||||
@@ -214,15 +222,17 @@ static int32_t ComputeHmac(const Uint8Buff *key, const Uint8Buff *message, Uint8
|
||||
.boolParam = isAlias
|
||||
}
|
||||
};
|
||||
ret = ConstructParamSet(¶mSet, hmacParam, CAL_ARRAY_SIZE(hmacParam));
|
||||
if (ret != HAL_SUCCESS) {
|
||||
LOGE("construct param set failed, ret = %d", ret);
|
||||
return ret;
|
||||
res = ConstructParamSet(¶mSet, hmacParam, CAL_ARRAY_SIZE(hmacParam));
|
||||
if (res != HAL_SUCCESS) {
|
||||
LOGE("construct param set failed, res = %d", res);
|
||||
return res;
|
||||
}
|
||||
|
||||
ret = HksMac(&keyBlob, paramSet, &srcBlob, &hmacBlob);
|
||||
if (ret != HKS_SUCCESS || hmacBlob.size != HMAC_LEN) {
|
||||
LOGE("Hmac failed, ret: %d", ret);
|
||||
LOGI("[HUKS]: HksMac enter.");
|
||||
res = HksMac(&keyBlob, paramSet, &srcBlob, &hmacBlob);
|
||||
LOGI("[HUKS]: HksMac quit. [Res]: %d", res);
|
||||
if (res != HKS_SUCCESS || hmacBlob.size != HMAC_LEN) {
|
||||
LOGE("[HUKS]: HksMac fail. [Res]: %d", res);
|
||||
HksFreeParamSet(¶mSet);
|
||||
return HAL_FAILED;
|
||||
}
|
||||
@@ -236,9 +246,9 @@ static int32_t ComputeHkdf(const Uint8Buff *baseKey, const Uint8Buff *salt, cons
|
||||
{
|
||||
const Uint8Buff *inParams[] = { baseKey, salt, outHkdf };
|
||||
const char *paramTags[] = { "baseKey", "salt", "outHkdf" };
|
||||
int32_t ret = BaseCheckParams(inParams, paramTags, CAL_ARRAY_SIZE(inParams));
|
||||
if (ret != HAL_SUCCESS) {
|
||||
return ret;
|
||||
int32_t res = BaseCheckParams(inParams, paramTags, CAL_ARRAY_SIZE(inParams));
|
||||
if (res != HAL_SUCCESS) {
|
||||
return res;
|
||||
}
|
||||
|
||||
struct HksBlob srcKeyBlob = { baseKey->length, baseKey->val };
|
||||
@@ -252,35 +262,24 @@ static int32_t ComputeHkdf(const Uint8Buff *baseKey, const Uint8Buff *salt, cons
|
||||
|
||||
struct HksParamSet *paramSet = NULL;
|
||||
struct HksParam hkdfParam[] = {
|
||||
{
|
||||
.tag = HKS_TAG_PURPOSE,
|
||||
.uint32Param = HKS_KEY_PURPOSE_DERIVE
|
||||
}, {
|
||||
.tag = HKS_TAG_ALGORITHM,
|
||||
.uint32Param = HKS_ALG_HKDF
|
||||
}, {
|
||||
.tag = HKS_TAG_DIGEST,
|
||||
.uint32Param = HKS_DIGEST_SHA256
|
||||
}, {
|
||||
.tag = HKS_TAG_SALT,
|
||||
.blob = saltBlob
|
||||
}, {
|
||||
.tag = HKS_TAG_INFO,
|
||||
.blob = keyInfoBlob
|
||||
}, {
|
||||
.tag = HKS_TAG_IS_KEY_ALIAS,
|
||||
.boolParam = isAlias
|
||||
}
|
||||
{ .tag = HKS_TAG_PURPOSE, .uint32Param = HKS_KEY_PURPOSE_DERIVE },
|
||||
{ .tag = HKS_TAG_ALGORITHM, .uint32Param = HKS_ALG_HKDF },
|
||||
{ .tag = HKS_TAG_DIGEST, .uint32Param = HKS_DIGEST_SHA256 },
|
||||
{ .tag = HKS_TAG_SALT, .blob = saltBlob },
|
||||
{ .tag = HKS_TAG_INFO, .blob = keyInfoBlob },
|
||||
{ .tag = HKS_TAG_IS_KEY_ALIAS, .boolParam = isAlias }
|
||||
};
|
||||
|
||||
ret = ConstructParamSet(¶mSet, hkdfParam, CAL_ARRAY_SIZE(hkdfParam));
|
||||
if (ret != HAL_SUCCESS) {
|
||||
return ret;
|
||||
res = ConstructParamSet(¶mSet, hkdfParam, CAL_ARRAY_SIZE(hkdfParam));
|
||||
if (res != HAL_SUCCESS) {
|
||||
return res;
|
||||
}
|
||||
|
||||
ret = HksDeriveKey(paramSet, &srcKeyBlob, &derivedKeyBlob);
|
||||
if (ret != HKS_SUCCESS) {
|
||||
LOGE("Key derivation failed, ret: %d", ret);
|
||||
LOGI("[HUKS]: HksDeriveKey enter.");
|
||||
res = HksDeriveKey(paramSet, &srcKeyBlob, &derivedKeyBlob);
|
||||
LOGI("[HUKS]: HksDeriveKey quit. [Res]: %d", res);
|
||||
if (res != HKS_SUCCESS) {
|
||||
LOGE("[HUKS]: HksDeriveKey fail. [Res]: %d", res);
|
||||
HksFreeParamSet(¶mSet);
|
||||
return HAL_FAILED;
|
||||
}
|
||||
@@ -294,9 +293,9 @@ static int32_t CheckAesGcmEncryptParam(const Uint8Buff *key, const Uint8Buff *pl
|
||||
{
|
||||
const Uint8Buff *inParams[] = { key, plain, outCipher };
|
||||
const char* paramTags[] = { "key", "plain", "outCipher" };
|
||||
int32_t ret = BaseCheckParams(inParams, paramTags, CAL_ARRAY_SIZE(inParams));
|
||||
if (ret != HAL_SUCCESS) {
|
||||
return ret;
|
||||
int32_t res = BaseCheckParams(inParams, paramTags, CAL_ARRAY_SIZE(inParams));
|
||||
if (res != HAL_SUCCESS) {
|
||||
return res;
|
||||
}
|
||||
|
||||
CHECK_PTR_RETURN_HAL_ERROR_CODE(encryptInfo, "encryptInfo");
|
||||
@@ -312,9 +311,9 @@ static int32_t CheckAesGcmEncryptParam(const Uint8Buff *key, const Uint8Buff *pl
|
||||
static int32_t AesGcmEncrypt(const Uint8Buff *key, const Uint8Buff *plain,
|
||||
const GcmParam *encryptInfo, bool isAlias, Uint8Buff *outCipher)
|
||||
{
|
||||
int32_t ret = CheckAesGcmEncryptParam(key, plain, encryptInfo, outCipher);
|
||||
if (ret != HAL_SUCCESS) {
|
||||
return ret;
|
||||
int32_t res = CheckAesGcmEncryptParam(key, plain, encryptInfo, outCipher);
|
||||
if (res != HAL_SUCCESS) {
|
||||
return res;
|
||||
}
|
||||
|
||||
struct HksBlob keyBlob = { key->length, key->val };
|
||||
@@ -347,15 +346,17 @@ static int32_t AesGcmEncrypt(const Uint8Buff *key, const Uint8Buff *plain,
|
||||
}
|
||||
};
|
||||
|
||||
ret = ConstructParamSet(¶mSet, encryptParam, CAL_ARRAY_SIZE(encryptParam));
|
||||
if (ret != HAL_SUCCESS) {
|
||||
LOGE("construct param set failed, ret = %d", ret);
|
||||
return ret;
|
||||
res = ConstructParamSet(¶mSet, encryptParam, CAL_ARRAY_SIZE(encryptParam));
|
||||
if (res != HAL_SUCCESS) {
|
||||
LOGE("construct param set failed, res = %d", res);
|
||||
return res;
|
||||
}
|
||||
|
||||
ret = HksEncrypt(&keyBlob, paramSet, &plainBlob, &cipherBlob);
|
||||
if (ret != HKS_SUCCESS) {
|
||||
LOGE("Aes-gcm encrypt failed, ret: %d", ret);
|
||||
LOGI("[HUKS]: HksEncrypt enter.");
|
||||
res = HksEncrypt(&keyBlob, paramSet, &plainBlob, &cipherBlob);
|
||||
LOGI("[HUKS]: HksEncrypt quit. [Res]: %d", res);
|
||||
if (res != HKS_SUCCESS) {
|
||||
LOGE("[HUKS]: HksEncrypt fail. [Res]: %d", res);
|
||||
HksFreeParamSet(¶mSet);
|
||||
return HAL_FAILED;
|
||||
}
|
||||
@@ -369,9 +370,9 @@ static int32_t CheckAesGcmDecryptParam(const Uint8Buff *key, const Uint8Buff *ci
|
||||
{
|
||||
const Uint8Buff *inParams[] = { key, cipher, outPlain };
|
||||
const char *paramTags[] = { "key", "cipher", "outPlain" };
|
||||
int32_t ret = BaseCheckParams(inParams, paramTags, CAL_ARRAY_SIZE(inParams));
|
||||
if (ret != HAL_SUCCESS) {
|
||||
return ret;
|
||||
int32_t res = BaseCheckParams(inParams, paramTags, CAL_ARRAY_SIZE(inParams));
|
||||
if (res != HAL_SUCCESS) {
|
||||
return res;
|
||||
}
|
||||
|
||||
CHECK_PTR_RETURN_HAL_ERROR_CODE(decryptInfo, "decryptInfo");
|
||||
@@ -387,9 +388,9 @@ static int32_t CheckAesGcmDecryptParam(const Uint8Buff *key, const Uint8Buff *ci
|
||||
static int32_t AesGcmDecrypt(const Uint8Buff *key, const Uint8Buff *cipher,
|
||||
const GcmParam *decryptInfo, bool isAlias, Uint8Buff *outPlain)
|
||||
{
|
||||
int32_t ret = CheckAesGcmDecryptParam(key, cipher, decryptInfo, outPlain);
|
||||
if (ret != HAL_SUCCESS) {
|
||||
return ret;
|
||||
int32_t res = CheckAesGcmDecryptParam(key, cipher, decryptInfo, outPlain);
|
||||
if (res != HAL_SUCCESS) {
|
||||
return res;
|
||||
}
|
||||
|
||||
struct HksBlob keyBlob = { key->length, key->val };
|
||||
@@ -422,15 +423,17 @@ static int32_t AesGcmDecrypt(const Uint8Buff *key, const Uint8Buff *cipher,
|
||||
}
|
||||
};
|
||||
|
||||
ret = ConstructParamSet(¶mSet, decryptParam, CAL_ARRAY_SIZE(decryptParam));
|
||||
if (ret != HAL_SUCCESS) {
|
||||
LOGE("construct param set failed, ret = %d", ret);
|
||||
return ret;
|
||||
res = ConstructParamSet(¶mSet, decryptParam, CAL_ARRAY_SIZE(decryptParam));
|
||||
if (res != HAL_SUCCESS) {
|
||||
LOGE("construct param set failed, res = %d", res);
|
||||
return res;
|
||||
}
|
||||
|
||||
ret = HksDecrypt(&keyBlob, paramSet, &cipherBlob, &plainBlob);
|
||||
if (ret != HKS_SUCCESS) {
|
||||
LOGE("Aes-gcm decrypt failed, ret: %d", ret);
|
||||
LOGI("[HUKS]: HksDecrypt enter.");
|
||||
res = HksDecrypt(&keyBlob, paramSet, &cipherBlob, &plainBlob);
|
||||
LOGI("[HUKS]: HksDecrypt quit. [Res]: %d", res);
|
||||
if (res != HKS_SUCCESS) {
|
||||
LOGE("[HUKS]: HksDecrypt fail. [Res]: %d", res);
|
||||
HksFreeParamSet(¶mSet);
|
||||
return HAL_FAILED;
|
||||
}
|
||||
@@ -495,37 +498,39 @@ static int32_t ConstructImportSymmetricKeyParam(struct HksParamSet **paramSet, u
|
||||
importParam[idx].tag = HKS_TAG_DIGEST;
|
||||
importParam[idx++].uint32Param = HKS_DIGEST_SHA256;
|
||||
|
||||
int ret = ConstructParamSet(paramSet, importParam, idx);
|
||||
if (ret != HAL_SUCCESS) {
|
||||
LOGE("Construct decrypt param set failed, ret = %d.", ret);
|
||||
int res = ConstructParamSet(paramSet, importParam, idx);
|
||||
if (res != HAL_SUCCESS) {
|
||||
LOGE("Construct decrypt param set failed, res = %d.", res);
|
||||
}
|
||||
|
||||
HcFree(importParam);
|
||||
return ret;
|
||||
return res;
|
||||
}
|
||||
|
||||
static int32_t ImportSymmetricKey(const Uint8Buff *keyAlias, const Uint8Buff *authToken, KeyPurpose purpose,
|
||||
const ExtraInfo *exInfo)
|
||||
{
|
||||
int32_t ret = CheckImportSymmetricKeyParam(keyAlias, authToken);
|
||||
if (ret != HAL_SUCCESS) {
|
||||
return ret;
|
||||
int32_t res = CheckImportSymmetricKeyParam(keyAlias, authToken);
|
||||
if (res != HAL_SUCCESS) {
|
||||
return res;
|
||||
}
|
||||
|
||||
struct HksBlob keyAliasBlob = { keyAlias->length, keyAlias->val };
|
||||
struct HksBlob symKeyBlob = { authToken->length, authToken->val };
|
||||
struct HksParamSet *paramSet = NULL;
|
||||
ret = ConstructImportSymmetricKeyParam(¶mSet, authToken->length, purpose, exInfo);
|
||||
if (ret != HAL_SUCCESS) {
|
||||
LOGE("construct param set failed, ret = %d", ret);
|
||||
return ret;
|
||||
res = ConstructImportSymmetricKeyParam(¶mSet, authToken->length, purpose, exInfo);
|
||||
if (res != HAL_SUCCESS) {
|
||||
LOGE("construct param set failed, res = %d", res);
|
||||
return res;
|
||||
}
|
||||
|
||||
ret = HksImportKey(&keyAliasBlob, paramSet, &symKeyBlob);
|
||||
if (ret != HKS_SUCCESS) {
|
||||
LOGE("HksImportKey failed, ret: %d", ret);
|
||||
LOGI("[HUKS]: HksImportKey enter.");
|
||||
res = HksImportKey(&keyAliasBlob, paramSet, &symKeyBlob);
|
||||
LOGI("[HUKS]: HksImportKey quit. [Res]: %d", res);
|
||||
if (res != HKS_SUCCESS) {
|
||||
LOGE("[HUKS]: HksImportKey fail. [Res]: %d", res);
|
||||
HksFreeParamSet(¶mSet);
|
||||
return ret;
|
||||
return res;
|
||||
}
|
||||
|
||||
HksFreeParamSet(¶mSet);
|
||||
@@ -536,9 +541,9 @@ static int32_t BigNumExpMod(const Uint8Buff *base, const Uint8Buff *exp, const c
|
||||
{
|
||||
const Uint8Buff *inParams[] = { base, exp, outNum };
|
||||
const char *paramTags[] = { "base", "exp", "outNum" };
|
||||
int32_t ret = BaseCheckParams(inParams, paramTags, CAL_ARRAY_SIZE(inParams));
|
||||
if (ret != HAL_SUCCESS) {
|
||||
return ret;
|
||||
int32_t res = BaseCheckParams(inParams, paramTags, CAL_ARRAY_SIZE(inParams));
|
||||
if (res != HAL_SUCCESS) {
|
||||
return res;
|
||||
}
|
||||
|
||||
CHECK_PTR_RETURN_HAL_ERROR_CODE(bigNumHex, "bigNumHex");
|
||||
@@ -559,16 +564,18 @@ static int32_t BigNumExpMod(const Uint8Buff *base, const Uint8Buff *exp, const c
|
||||
LOGE("malloc bigNumBlob.data failed.");
|
||||
return HAL_ERR_BAD_ALLOC;
|
||||
}
|
||||
ret = HexStringToByte(bigNumHex, bigNumBlob.data, bigNumBlob.size);
|
||||
if (ret != HAL_SUCCESS) {
|
||||
res = HexStringToByte(bigNumHex, bigNumBlob.data, bigNumBlob.size);
|
||||
if (res != HAL_SUCCESS) {
|
||||
LOGE("HexStringToByte for bigNumHex failed.");
|
||||
HcFree(bigNumBlob.data);
|
||||
return ret;
|
||||
return res;
|
||||
}
|
||||
|
||||
ret = HksBnExpMod(&outNumBlob, &baseBlob, &expBlob, &bigNumBlob);
|
||||
if (ret != HKS_SUCCESS) {
|
||||
LOGE("Huks calculate big number exp mod failed, ret = %d", ret);
|
||||
LOGI("[HUKS]: HksBnExpMod enter.");
|
||||
res = HksBnExpMod(&outNumBlob, &baseBlob, &expBlob, &bigNumBlob);
|
||||
LOGI("[HUKS]: HksBnExpMod quit. [Res]: %d", res);
|
||||
if (res != HKS_SUCCESS) {
|
||||
LOGE("[HUKS]: HksBnExpMod fail. [Res]: %d", res);
|
||||
HcFree(bigNumBlob.data);
|
||||
return HAL_FAILED;
|
||||
}
|
||||
|
||||
@@ -41,22 +41,22 @@ static int32_t ConstructParamSet(struct HksParamSet **out, const struct HksParam
|
||||
const uint32_t inParamNum)
|
||||
{
|
||||
struct HksParamSet *paramSet = NULL;
|
||||
int32_t ret = HksInitParamSet(¶mSet);
|
||||
if (ret != HKS_SUCCESS) {
|
||||
LOGE("init param set failed, ret = %d", ret);
|
||||
int32_t res = HksInitParamSet(¶mSet);
|
||||
if (res != HKS_SUCCESS) {
|
||||
LOGE("init param set failed, res = %d", res);
|
||||
return HAL_ERR_INIT_PARAM_SET_FAILED;
|
||||
}
|
||||
|
||||
ret = HksAddParams(paramSet, inParam, inParamNum);
|
||||
if (ret != HKS_SUCCESS) {
|
||||
LOGE("add param failed, ret = %d", ret);
|
||||
res = HksAddParams(paramSet, inParam, inParamNum);
|
||||
if (res != HKS_SUCCESS) {
|
||||
LOGE("add param failed, res = %d", res);
|
||||
HksFreeParamSet(¶mSet);
|
||||
return HAL_ERR_ADD_PARAM_FAILED;
|
||||
}
|
||||
|
||||
ret = HksBuildParamSet(¶mSet);
|
||||
if (ret != HKS_SUCCESS) {
|
||||
LOGE("build param set failed, ret = %d", ret);
|
||||
res = HksBuildParamSet(¶mSet);
|
||||
if (res != HKS_SUCCESS) {
|
||||
LOGE("build param set failed, res = %d", res);
|
||||
HksFreeParamSet(¶mSet);
|
||||
return HAL_ERR_BUILD_PARAM_SET_FAILED;
|
||||
}
|
||||
@@ -67,7 +67,13 @@ static int32_t ConstructParamSet(struct HksParamSet **out, const struct HksParam
|
||||
|
||||
static int32_t InitHks(void)
|
||||
{
|
||||
return HksInitialize();
|
||||
LOGI("[HUKS]: HksInitialize enter.");
|
||||
int32_t res = HksInitialize();
|
||||
LOGI("[HUKS]: HksInitialize quit. [Res]: %d", res);
|
||||
if (res != HKS_SUCCESS) {
|
||||
LOGE("[HUKS]: HksInitialize fail. [Res]: %d", res);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
static int32_t Sha256(const Uint8Buff *message, Uint8Buff *hash)
|
||||
@@ -89,14 +95,15 @@ static int32_t Sha256(const Uint8Buff *message, Uint8Buff *hash)
|
||||
.uint32Param = HKS_DIGEST_SHA256
|
||||
}
|
||||
};
|
||||
int32_t ret = ConstructParamSet(¶mSet, digestParam, CAL_ARRAY_SIZE(digestParam));
|
||||
if (ret != HAL_SUCCESS) {
|
||||
LOGE("construct param set failed, ret = %d", ret);
|
||||
return ret;
|
||||
int32_t res = ConstructParamSet(¶mSet, digestParam, CAL_ARRAY_SIZE(digestParam));
|
||||
if (res != HAL_SUCCESS) {
|
||||
LOGE("construct param set failed, res = %d", res);
|
||||
return res;
|
||||
}
|
||||
|
||||
ret = HksHash(paramSet, &srcBlob, &hashBlob);
|
||||
if (ret != HKS_SUCCESS || hashBlob.size != SHA256_LEN) {
|
||||
res = HksHash(paramSet, &srcBlob, &hashBlob);
|
||||
if (res != HKS_SUCCESS || hashBlob.size != SHA256_LEN) {
|
||||
LOGE("[HUKS]: HksHash fail. [Res]: %d", res);
|
||||
HksFreeParamSet(¶mSet);
|
||||
return HAL_FAILED;
|
||||
}
|
||||
@@ -112,9 +119,9 @@ static int32_t GenerateRandom(Uint8Buff *rand)
|
||||
CHECK_LEN_ZERO_RETURN_ERROR_CODE(rand->length, "rand->length");
|
||||
|
||||
struct HksBlob randBlob = { rand->length, rand->val };
|
||||
int32_t ret = HksGenerateRandom(NULL, &randBlob);
|
||||
if (ret != HKS_SUCCESS) {
|
||||
LOGE("Generate random failed, ret: %d", ret);
|
||||
int32_t res = HksGenerateRandom(NULL, &randBlob);
|
||||
if (res != HKS_SUCCESS) {
|
||||
LOGE("[HUKS]: HksGenerateRandom fail. [Res]: %d", res);
|
||||
return HAL_FAILED;
|
||||
}
|
||||
|
||||
@@ -128,9 +135,9 @@ static int32_t CheckKeyExist(const Uint8Buff *keyAlias)
|
||||
CHECK_LEN_ZERO_RETURN_ERROR_CODE(keyAlias->length, "keyAlias->length");
|
||||
|
||||
struct HksBlob keyAliasBlob = { keyAlias->length, keyAlias->val };
|
||||
int32_t ret = HksKeyExist(&keyAliasBlob, NULL);
|
||||
if (ret != HKS_SUCCESS) {
|
||||
LOGI("Hks check key exist or not, ret = %d", ret);
|
||||
int32_t res = HksKeyExist(&keyAliasBlob, NULL);
|
||||
if (res != HKS_SUCCESS) {
|
||||
LOGI("[HUKS]: HksKeyExist fail. [Res]: %d", res);
|
||||
return HAL_FAILED;
|
||||
}
|
||||
|
||||
@@ -144,13 +151,15 @@ static int32_t DeleteKey(const Uint8Buff *keyAlias)
|
||||
CHECK_LEN_ZERO_RETURN_ERROR_CODE(keyAlias->length, "keyAlias->length");
|
||||
|
||||
struct HksBlob keyAliasBlob = { keyAlias->length, keyAlias->val };
|
||||
int32_t ret = HksDeleteKey(&keyAliasBlob, NULL);
|
||||
if (ret == HKS_ERROR_NOT_EXIST) {
|
||||
LOGI("[HUKS]: HksDeleteKey enter.");
|
||||
int32_t res = HksDeleteKey(&keyAliasBlob, NULL);
|
||||
LOGI("[HUKS]: HksDeleteKey quit. [Res]: %d", res);
|
||||
if (res == HKS_ERROR_NOT_EXIST) {
|
||||
LOGI("Key not exists.");
|
||||
return HAL_SUCCESS;
|
||||
}
|
||||
if (ret != HKS_SUCCESS) {
|
||||
LOGE("Delete key failed, ret = %d", ret);
|
||||
if (res != HKS_SUCCESS) {
|
||||
LOGE("[HUKS]: HksDeleteKey fail. [Res]: %d", res);
|
||||
return HAL_FAILED;
|
||||
}
|
||||
|
||||
@@ -161,9 +170,9 @@ static int32_t ComputeHmac(const Uint8Buff *key, const Uint8Buff *message, Uint8
|
||||
{
|
||||
const Uint8Buff *inParams[] = { key, message, outHmac };
|
||||
const char *paramTags[] = {"key", "message", "outHmac"};
|
||||
int32_t ret = BaseCheckParams(inParams, paramTags, CAL_ARRAY_SIZE(inParams));
|
||||
if (ret != HAL_SUCCESS) {
|
||||
return ret;
|
||||
int32_t res = BaseCheckParams(inParams, paramTags, CAL_ARRAY_SIZE(inParams));
|
||||
if (res != HAL_SUCCESS) {
|
||||
return res;
|
||||
}
|
||||
CHECK_LEN_EQUAL_RETURN(outHmac->length, HMAC_LEN, "outHmac->length");
|
||||
|
||||
@@ -183,15 +192,17 @@ static int32_t ComputeHmac(const Uint8Buff *key, const Uint8Buff *message, Uint8
|
||||
.boolParam = isAlias
|
||||
}
|
||||
};
|
||||
ret = ConstructParamSet(¶mSet, hmacParam, CAL_ARRAY_SIZE(hmacParam));
|
||||
if (ret != HAL_SUCCESS) {
|
||||
LOGE("construct param set failed, ret = %d", ret);
|
||||
return ret;
|
||||
res = ConstructParamSet(¶mSet, hmacParam, CAL_ARRAY_SIZE(hmacParam));
|
||||
if (res != HAL_SUCCESS) {
|
||||
LOGE("construct param set failed, res = %d", res);
|
||||
return res;
|
||||
}
|
||||
|
||||
ret = HksMac(&keyBlob, paramSet, &srcBlob, &hmacBlob);
|
||||
if (ret != HKS_SUCCESS || hmacBlob.size != HMAC_LEN) {
|
||||
LOGE("Hmac failed, ret: %d", ret);
|
||||
LOGI("[HUKS]: HksMac enter.");
|
||||
res = HksMac(&keyBlob, paramSet, &srcBlob, &hmacBlob);
|
||||
LOGI("[HUKS]: HksMac quit. [Res]: %d", res);
|
||||
if (res != HKS_SUCCESS || hmacBlob.size != HMAC_LEN) {
|
||||
LOGE("[HUKS]: HksMac fail. [Res]: %d", res);
|
||||
HksFreeParamSet(¶mSet);
|
||||
return HAL_FAILED;
|
||||
}
|
||||
@@ -205,9 +216,9 @@ static int32_t ComputeHkdf(const Uint8Buff *baseKey, const Uint8Buff *salt, cons
|
||||
{
|
||||
const Uint8Buff *inParams[] = { baseKey, salt, outHkdf };
|
||||
const char *paramTags[] = { "baseKey", "salt", "outHkdf" };
|
||||
int32_t ret = BaseCheckParams(inParams, paramTags, CAL_ARRAY_SIZE(inParams));
|
||||
if (ret != HAL_SUCCESS) {
|
||||
return ret;
|
||||
int32_t res = BaseCheckParams(inParams, paramTags, CAL_ARRAY_SIZE(inParams));
|
||||
if (res != HAL_SUCCESS) {
|
||||
return res;
|
||||
}
|
||||
|
||||
struct HksBlob srcKeyBlob = { baseKey->length, baseKey->val };
|
||||
@@ -221,35 +232,24 @@ static int32_t ComputeHkdf(const Uint8Buff *baseKey, const Uint8Buff *salt, cons
|
||||
|
||||
struct HksParamSet *paramSet = NULL;
|
||||
struct HksParam hkdfParam[] = {
|
||||
{
|
||||
.tag = HKS_TAG_PURPOSE,
|
||||
.uint32Param = HKS_KEY_PURPOSE_DERIVE
|
||||
}, {
|
||||
.tag = HKS_TAG_ALGORITHM,
|
||||
.uint32Param = HKS_ALG_HKDF
|
||||
}, {
|
||||
.tag = HKS_TAG_DIGEST,
|
||||
.uint32Param = HKS_DIGEST_SHA256
|
||||
}, {
|
||||
.tag = HKS_TAG_SALT,
|
||||
.blob = saltBlob
|
||||
}, {
|
||||
.tag = HKS_TAG_INFO,
|
||||
.blob = keyInfoBlob
|
||||
}, {
|
||||
.tag = HKS_TAG_IS_KEY_ALIAS,
|
||||
.boolParam = isAlias
|
||||
}
|
||||
{ .tag = HKS_TAG_PURPOSE, .uint32Param = HKS_KEY_PURPOSE_DERIVE },
|
||||
{ .tag = HKS_TAG_ALGORITHM, .uint32Param = HKS_ALG_HKDF },
|
||||
{ .tag = HKS_TAG_DIGEST, .uint32Param = HKS_DIGEST_SHA256 },
|
||||
{ .tag = HKS_TAG_SALT, .blob = saltBlob },
|
||||
{ .tag = HKS_TAG_INFO, .blob = keyInfoBlob },
|
||||
{ .tag = HKS_TAG_IS_KEY_ALIAS, .boolParam = isAlias }
|
||||
};
|
||||
|
||||
ret = ConstructParamSet(¶mSet, hkdfParam, CAL_ARRAY_SIZE(hkdfParam));
|
||||
if (ret != HAL_SUCCESS) {
|
||||
return ret;
|
||||
res = ConstructParamSet(¶mSet, hkdfParam, CAL_ARRAY_SIZE(hkdfParam));
|
||||
if (res != HAL_SUCCESS) {
|
||||
return res;
|
||||
}
|
||||
|
||||
ret = HksDeriveKey(paramSet, &srcKeyBlob, &derivedKeyBlob);
|
||||
if (ret != HKS_SUCCESS) {
|
||||
LOGE("Key derivation failed, ret: %d", ret);
|
||||
LOGI("[HUKS]: HksDeriveKey enter.");
|
||||
res = HksDeriveKey(paramSet, &srcKeyBlob, &derivedKeyBlob);
|
||||
LOGI("[HUKS]: HksDeriveKey quit. [Res]: %d", res);
|
||||
if (res != HKS_SUCCESS) {
|
||||
LOGE("[HUKS]: HksDeriveKey fail. [Res]: %d", res);
|
||||
HksFreeParamSet(¶mSet);
|
||||
return HAL_FAILED;
|
||||
}
|
||||
@@ -263,9 +263,9 @@ static int32_t CheckAesGcmEncryptParam(const Uint8Buff *key, const Uint8Buff *pl
|
||||
{
|
||||
const Uint8Buff *inParams[] = { key, plain, outCipher };
|
||||
const char* paramTags[] = { "key", "plain", "outCipher" };
|
||||
int32_t ret = BaseCheckParams(inParams, paramTags, CAL_ARRAY_SIZE(inParams));
|
||||
if (ret != HAL_SUCCESS) {
|
||||
return ret;
|
||||
int32_t res = BaseCheckParams(inParams, paramTags, CAL_ARRAY_SIZE(inParams));
|
||||
if (res != HAL_SUCCESS) {
|
||||
return res;
|
||||
}
|
||||
|
||||
CHECK_PTR_RETURN_HAL_ERROR_CODE(encryptInfo, "encryptInfo");
|
||||
@@ -281,9 +281,9 @@ static int32_t CheckAesGcmEncryptParam(const Uint8Buff *key, const Uint8Buff *pl
|
||||
static int32_t AesGcmEncrypt(const Uint8Buff *key, const Uint8Buff *plain,
|
||||
const GcmParam *encryptInfo, bool isAlias, Uint8Buff *outCipher)
|
||||
{
|
||||
int32_t ret = CheckAesGcmEncryptParam(key, plain, encryptInfo, outCipher);
|
||||
if (ret != HAL_SUCCESS) {
|
||||
return ret;
|
||||
int32_t res = CheckAesGcmEncryptParam(key, plain, encryptInfo, outCipher);
|
||||
if (res != HAL_SUCCESS) {
|
||||
return res;
|
||||
}
|
||||
|
||||
struct HksBlob keyBlob = { key->length, key->val };
|
||||
@@ -316,15 +316,17 @@ static int32_t AesGcmEncrypt(const Uint8Buff *key, const Uint8Buff *plain,
|
||||
}
|
||||
};
|
||||
|
||||
ret = ConstructParamSet(¶mSet, encryptParam, CAL_ARRAY_SIZE(encryptParam));
|
||||
if (ret != HAL_SUCCESS) {
|
||||
LOGE("construct param set failed, ret = %d", ret);
|
||||
return ret;
|
||||
res = ConstructParamSet(¶mSet, encryptParam, CAL_ARRAY_SIZE(encryptParam));
|
||||
if (res != HAL_SUCCESS) {
|
||||
LOGE("construct param set failed, res = %d", res);
|
||||
return res;
|
||||
}
|
||||
|
||||
ret = HksEncrypt(&keyBlob, paramSet, &plainBlob, &cipherBlob);
|
||||
if (ret != HKS_SUCCESS) {
|
||||
LOGE("Aes-gcm encrypt failed, ret: %d", ret);
|
||||
LOGI("[HUKS]: HksEncrypt enter.");
|
||||
res = HksEncrypt(&keyBlob, paramSet, &plainBlob, &cipherBlob);
|
||||
LOGI("[HUKS]: HksEncrypt quit. [Res]: %d", res);
|
||||
if (res != HKS_SUCCESS) {
|
||||
LOGE("[HUKS]: HksEncrypt fail. [Res]: %d", res);
|
||||
HksFreeParamSet(¶mSet);
|
||||
return HAL_FAILED;
|
||||
}
|
||||
@@ -338,9 +340,9 @@ static int32_t CheckAesGcmDecryptParam(const Uint8Buff *key, const Uint8Buff *ci
|
||||
{
|
||||
const Uint8Buff *inParams[] = { key, cipher, outPlain };
|
||||
const char *paramTags[] = { "key", "cipher", "outPlain" };
|
||||
int32_t ret = BaseCheckParams(inParams, paramTags, CAL_ARRAY_SIZE(inParams));
|
||||
if (ret != HAL_SUCCESS) {
|
||||
return ret;
|
||||
int32_t res = BaseCheckParams(inParams, paramTags, CAL_ARRAY_SIZE(inParams));
|
||||
if (res != HAL_SUCCESS) {
|
||||
return res;
|
||||
}
|
||||
|
||||
CHECK_PTR_RETURN_HAL_ERROR_CODE(decryptInfo, "decryptInfo");
|
||||
@@ -356,9 +358,9 @@ static int32_t CheckAesGcmDecryptParam(const Uint8Buff *key, const Uint8Buff *ci
|
||||
static int32_t AesGcmDecrypt(const Uint8Buff *key, const Uint8Buff *cipher,
|
||||
const GcmParam *decryptInfo, bool isAlias, Uint8Buff *outPlain)
|
||||
{
|
||||
int32_t ret = CheckAesGcmDecryptParam(key, cipher, decryptInfo, outPlain);
|
||||
if (ret != HAL_SUCCESS) {
|
||||
return ret;
|
||||
int32_t res = CheckAesGcmDecryptParam(key, cipher, decryptInfo, outPlain);
|
||||
if (res != HAL_SUCCESS) {
|
||||
return res;
|
||||
}
|
||||
|
||||
struct HksBlob keyBlob = { key->length, key->val };
|
||||
@@ -391,15 +393,17 @@ static int32_t AesGcmDecrypt(const Uint8Buff *key, const Uint8Buff *cipher,
|
||||
}
|
||||
};
|
||||
|
||||
ret = ConstructParamSet(¶mSet, decryptParam, CAL_ARRAY_SIZE(decryptParam));
|
||||
if (ret != HAL_SUCCESS) {
|
||||
LOGE("construct param set failed, ret = %d", ret);
|
||||
return ret;
|
||||
res = ConstructParamSet(¶mSet, decryptParam, CAL_ARRAY_SIZE(decryptParam));
|
||||
if (res != HAL_SUCCESS) {
|
||||
LOGE("construct param set failed, res = %d", res);
|
||||
return res;
|
||||
}
|
||||
|
||||
ret = HksDecrypt(&keyBlob, paramSet, &cipherBlob, &plainBlob);
|
||||
if (ret != HKS_SUCCESS) {
|
||||
LOGE("Aes-gcm decrypt failed, ret: %d", ret);
|
||||
LOGI("[HUKS]: HksDecrypt enter.");
|
||||
res = HksDecrypt(&keyBlob, paramSet, &cipherBlob, &plainBlob);
|
||||
LOGI("[HUKS]: HksDecrypt quit. [Res]: %d", res);
|
||||
if (res != HKS_SUCCESS) {
|
||||
LOGE("[HUKS]: HksDecrypt fail. [Res]: %d", res);
|
||||
HksFreeParamSet(¶mSet);
|
||||
return HAL_FAILED;
|
||||
}
|
||||
@@ -422,9 +426,9 @@ static int32_t HashToPoint(const Uint8Buff *hash, Algorithm algo, Uint8Buff *out
|
||||
return HAL_ERR_INVALID_PARAM;
|
||||
}
|
||||
|
||||
int32_t ret = MbedtlsHashToPoint(hash, outEcPoint);
|
||||
if (ret != 0) {
|
||||
LOGE("Hks hashToPoint failed, ret: %d", ret);
|
||||
int32_t res = MbedtlsHashToPoint(hash, outEcPoint);
|
||||
if (res != 0) {
|
||||
LOGE("Hks hashToPoint failed, res: %d", res);
|
||||
return HAL_FAILED;
|
||||
}
|
||||
|
||||
@@ -467,12 +471,12 @@ static int32_t ConstructAgreeWithStorageParams(struct HksParamSet **paramSet, ui
|
||||
}
|
||||
};
|
||||
|
||||
int32_t ret = ConstructParamSet(paramSet, agreeParam, CAL_ARRAY_SIZE(agreeParam));
|
||||
if (ret != HAL_SUCCESS) {
|
||||
LOGE("Construct param set failed, ret = %d", ret);
|
||||
return ret;
|
||||
int32_t res = ConstructParamSet(paramSet, agreeParam, CAL_ARRAY_SIZE(agreeParam));
|
||||
if (res != HAL_SUCCESS) {
|
||||
LOGE("Construct param set failed, res = %d", res);
|
||||
return res;
|
||||
}
|
||||
return ret;
|
||||
return res;
|
||||
}
|
||||
|
||||
static int32_t AgreeSharedSecretWithStorage(const KeyBuff *priKey, const KeyBuff *pubKey, Algorithm algo,
|
||||
@@ -491,14 +495,16 @@ static int32_t AgreeSharedSecretWithStorage(const KeyBuff *priKey, const KeyBuff
|
||||
|
||||
struct HksBlob sharedKeyAliasBlob = { sharedKeyAlias->length, sharedKeyAlias->val };
|
||||
struct HksParamSet *paramSet = NULL;
|
||||
int32_t ret = ConstructAgreeWithStorageParams(¶mSet, sharedKeyLen, algo, priKey, pubKey);
|
||||
if (ret != HAL_SUCCESS) {
|
||||
return ret;
|
||||
int32_t res = ConstructAgreeWithStorageParams(¶mSet, sharedKeyLen, algo, priKey, pubKey);
|
||||
if (res != HAL_SUCCESS) {
|
||||
return res;
|
||||
}
|
||||
|
||||
ret = HksGenerateKey(&sharedKeyAliasBlob, paramSet, NULL);
|
||||
if (ret != HKS_SUCCESS) {
|
||||
LOGE("Hks agree key with storage failed, ret = %d", ret);
|
||||
LOGI("[HUKS]: HksGenerateKey enter.");
|
||||
res = HksGenerateKey(&sharedKeyAliasBlob, paramSet, NULL);
|
||||
LOGI("[HUKS]: HksGenerateKey quit. [Res]: %d", res);
|
||||
if (res != HKS_SUCCESS) {
|
||||
LOGE("[HUKS]: HksGenerateKey fail. [Res]: %d", res);
|
||||
HksFreeParamSet(¶mSet);
|
||||
return HAL_FAILED;
|
||||
}
|
||||
@@ -537,15 +543,17 @@ static int32_t AgreeSharedSecret(const KeyBuff *priKey, const KeyBuff *pubKey, A
|
||||
}
|
||||
};
|
||||
|
||||
int32_t ret = ConstructParamSet(¶mSet, agreeParam, CAL_ARRAY_SIZE(agreeParam));
|
||||
if (ret != HAL_SUCCESS) {
|
||||
LOGE("Construct param set failed, ret = %d", ret);
|
||||
return ret;
|
||||
int32_t res = ConstructParamSet(¶mSet, agreeParam, CAL_ARRAY_SIZE(agreeParam));
|
||||
if (res != HAL_SUCCESS) {
|
||||
LOGE("Construct param set failed, res = %d", res);
|
||||
return res;
|
||||
}
|
||||
|
||||
ret = HksAgreeKey(paramSet, &priKeyBlob, &pubKeyBlob, &sharedKeyBlob);
|
||||
if (ret != HKS_SUCCESS) {
|
||||
LOGE("Agree key failed, ret = %d", ret);
|
||||
LOGI("[HUKS]: HksAgreeKey enter.");
|
||||
res = HksAgreeKey(paramSet, &priKeyBlob, &pubKeyBlob, &sharedKeyBlob);
|
||||
LOGI("[HUKS]: HksAgreeKey quit. [Res]: %d");
|
||||
if (res != HKS_SUCCESS) {
|
||||
LOGE("[HUKS]: HksAgreeKey fail. [Res]: %d");
|
||||
HksFreeParamSet(¶mSet);
|
||||
return HAL_FAILED;
|
||||
}
|
||||
@@ -558,9 +566,9 @@ static int32_t BigNumExpMod(const Uint8Buff *base, const Uint8Buff *exp, const c
|
||||
{
|
||||
const Uint8Buff *inParams[] = { base, exp, outNum };
|
||||
const char *paramTags[] = { "base", "exp", "outNum" };
|
||||
int32_t ret = BaseCheckParams(inParams, paramTags, CAL_ARRAY_SIZE(inParams));
|
||||
if (ret != HAL_SUCCESS) {
|
||||
return ret;
|
||||
int32_t res = BaseCheckParams(inParams, paramTags, CAL_ARRAY_SIZE(inParams));
|
||||
if (res != HAL_SUCCESS) {
|
||||
return res;
|
||||
}
|
||||
|
||||
CHECK_PTR_RETURN_HAL_ERROR_CODE(bigNumHex, "bigNumHex");
|
||||
@@ -581,16 +589,16 @@ static int32_t BigNumExpMod(const Uint8Buff *base, const Uint8Buff *exp, const c
|
||||
LOGE("malloc bigNumBlob.data failed.");
|
||||
return HAL_ERR_BAD_ALLOC;
|
||||
}
|
||||
ret = HexStringToByte(bigNumHex, bigNumBlob.data, bigNumBlob.size);
|
||||
if (ret != HAL_SUCCESS) {
|
||||
res = HexStringToByte(bigNumHex, bigNumBlob.data, bigNumBlob.size);
|
||||
if (res != HAL_SUCCESS) {
|
||||
LOGE("HexStringToByte for bigNumHex failed.");
|
||||
HcFree(bigNumBlob.data);
|
||||
return ret;
|
||||
return res;
|
||||
}
|
||||
|
||||
ret = HksBnExpMod(&outNumBlob, &baseBlob, &expBlob, &bigNumBlob);
|
||||
if (ret != HKS_SUCCESS) {
|
||||
LOGE("Huks calculate big number exp mod failed, ret = %d", ret);
|
||||
res = HksBnExpMod(&outNumBlob, &baseBlob, &expBlob, &bigNumBlob);
|
||||
if (res != HKS_SUCCESS) {
|
||||
LOGE("Huks calculate big number exp mod failed, res = %d", res);
|
||||
HcFree(bigNumBlob.data);
|
||||
return HAL_FAILED;
|
||||
}
|
||||
@@ -625,12 +633,12 @@ static int32_t ConstructGenerateKeyPairWithStorageParams(struct HksParamSet **pa
|
||||
}
|
||||
};
|
||||
|
||||
int32_t ret = ConstructParamSet(paramSet, keyParam, CAL_ARRAY_SIZE(keyParam));
|
||||
if (ret != HAL_SUCCESS) {
|
||||
LOGE("Construct param set failed, ret = %d", ret);
|
||||
return ret;
|
||||
int32_t res = ConstructParamSet(paramSet, keyParam, CAL_ARRAY_SIZE(keyParam));
|
||||
if (res != HAL_SUCCESS) {
|
||||
LOGE("Construct param set failed, res = %d", res);
|
||||
return res;
|
||||
}
|
||||
return ret;
|
||||
return res;
|
||||
}
|
||||
|
||||
static int32_t GenerateKeyPairWithStorage(const Uint8Buff *keyAlias, uint32_t keyLen, Algorithm algo,
|
||||
@@ -648,14 +656,16 @@ static int32_t GenerateKeyPairWithStorage(const Uint8Buff *keyAlias, uint32_t ke
|
||||
struct HksBlob keyAliasBlob = { keyAlias->length, keyAlias->val };
|
||||
struct HksBlob authIdBlob = { exInfo->authId.length, exInfo->authId.val };
|
||||
struct HksParamSet *paramSet = NULL;
|
||||
int32_t ret = ConstructGenerateKeyPairWithStorageParams(¶mSet, algo, keyLen, &authIdBlob);
|
||||
if (ret != HAL_SUCCESS) {
|
||||
return ret;
|
||||
int32_t res = ConstructGenerateKeyPairWithStorageParams(¶mSet, algo, keyLen, &authIdBlob);
|
||||
if (res != HAL_SUCCESS) {
|
||||
return res;
|
||||
}
|
||||
|
||||
ret = HksGenerateKey(&keyAliasBlob, paramSet, NULL);
|
||||
if (ret != HKS_SUCCESS) {
|
||||
LOGE("Hks generate failed, ret=%d", ret);
|
||||
LOGI("[HUKS]: HksGenerateKey enter.");
|
||||
res = HksGenerateKey(&keyAliasBlob, paramSet, NULL);
|
||||
LOGI("[HUKS]: HksGenerateKey quit. [Res]: %d", res);
|
||||
if (res != HKS_SUCCESS) {
|
||||
LOGE("[HUKS]: HksGenerateKey fail. [Res]: %d", res);
|
||||
HksFreeParamSet(¶mSet);
|
||||
return HAL_FAILED;
|
||||
}
|
||||
@@ -666,23 +676,23 @@ static int32_t GenerateKeyPairWithStorage(const Uint8Buff *keyAlias, uint32_t ke
|
||||
|
||||
static int32_t GetKeyPair(struct HksParamSet *outParamSet, Uint8Buff *outPriKey, Uint8Buff *outPubKey)
|
||||
{
|
||||
int32_t ret = HksFreshParamSet(outParamSet, false); /* false means fresh by local, not through IPC */
|
||||
if (ret != HKS_SUCCESS) {
|
||||
LOGE("fresh param set failed, ret:%d", ret);
|
||||
int32_t res = HksFreshParamSet(outParamSet, false); /* false means fresh by local, not through IPC */
|
||||
if (res != HKS_SUCCESS) {
|
||||
LOGE("fresh param set failed, res:%d", res);
|
||||
return HAL_ERR_FRESH_PARAM_SET_FAILED;
|
||||
}
|
||||
|
||||
struct HksParam *pubKeyParam = NULL;
|
||||
ret = HksGetParam(outParamSet, HKS_TAG_ASYMMETRIC_PUBLIC_KEY_DATA, &pubKeyParam);
|
||||
if (ret != HKS_SUCCESS) {
|
||||
LOGE("get pub key from param set failed, ret:%d", ret);
|
||||
res = HksGetParam(outParamSet, HKS_TAG_ASYMMETRIC_PUBLIC_KEY_DATA, &pubKeyParam);
|
||||
if (res != HKS_SUCCESS) {
|
||||
LOGE("get pub key from param set failed, res:%d", res);
|
||||
return HAL_ERR_GET_PARAM_FAILED;
|
||||
}
|
||||
|
||||
struct HksParam *priKeyParam = NULL;
|
||||
ret = HksGetParam(outParamSet, HKS_TAG_ASYMMETRIC_PRIVATE_KEY_DATA, &priKeyParam);
|
||||
if (ret != HKS_SUCCESS) {
|
||||
LOGE("get priv key from param set failed, ret:%d", ret);
|
||||
res = HksGetParam(outParamSet, HKS_TAG_ASYMMETRIC_PRIVATE_KEY_DATA, &priKeyParam);
|
||||
if (res != HKS_SUCCESS) {
|
||||
LOGE("get priv key from param set failed, res:%d", res);
|
||||
return HAL_ERR_GET_PARAM_FAILED;
|
||||
}
|
||||
|
||||
@@ -719,12 +729,12 @@ static int32_t ConstructGenerateKeyPairParams(struct HksParamSet **paramSet, Alg
|
||||
}
|
||||
};
|
||||
|
||||
int32_t ret = ConstructParamSet(paramSet, keyParam, CAL_ARRAY_SIZE(keyParam));
|
||||
if (ret != HAL_SUCCESS) {
|
||||
LOGE("Construct param set failed, ret = %d", ret);
|
||||
return ret;
|
||||
int32_t res = ConstructParamSet(paramSet, keyParam, CAL_ARRAY_SIZE(keyParam));
|
||||
if (res != HAL_SUCCESS) {
|
||||
LOGE("Construct param set failed, res = %d", res);
|
||||
return res;
|
||||
}
|
||||
return ret;
|
||||
return res;
|
||||
}
|
||||
|
||||
static int32_t GenerateKeyPair(Algorithm algo, Uint8Buff *outPriKey, Uint8Buff *outPubKey)
|
||||
@@ -744,9 +754,9 @@ static int32_t GenerateKeyPair(Algorithm algo, Uint8Buff *outPriKey, Uint8Buff *
|
||||
|
||||
struct HksParamSet *paramSet = NULL;
|
||||
struct HksParamSet *outParamSet = NULL;
|
||||
int32_t ret = ConstructGenerateKeyPairParams(¶mSet, algo, keyLen);
|
||||
if (ret != HAL_SUCCESS) {
|
||||
return ret;
|
||||
int32_t res = ConstructGenerateKeyPairParams(¶mSet, algo, keyLen);
|
||||
if (res != HAL_SUCCESS) {
|
||||
return res;
|
||||
}
|
||||
|
||||
/* need 2 HksParam struct for outPriKey and outPubKey */
|
||||
@@ -755,27 +765,29 @@ static int32_t GenerateKeyPair(Algorithm algo, Uint8Buff *outPriKey, Uint8Buff *
|
||||
outParamSet = (struct HksParamSet *)HcMalloc(outParamSetSize, 0);
|
||||
if (outParamSet == NULL) {
|
||||
LOGE("allocate buffer for output param set failed");
|
||||
ret = HAL_ERR_BAD_ALLOC;
|
||||
res = HAL_ERR_BAD_ALLOC;
|
||||
goto ERR;
|
||||
}
|
||||
outParamSet->paramSetSize = outParamSetSize;
|
||||
|
||||
ret = HksGenerateKey(NULL, paramSet, outParamSet);
|
||||
if (ret != HKS_SUCCESS) {
|
||||
LOGE("generate x25519 key failed, ret:%d", ret);
|
||||
ret = HAL_FAILED;
|
||||
LOGI("[HUKS]: HksGenerateKey enter.");
|
||||
res = HksGenerateKey(NULL, paramSet, outParamSet);
|
||||
LOGI("[HUKS]: HksGenerateKey quit. [Res]: %d", res);
|
||||
if (res != HKS_SUCCESS) {
|
||||
LOGI("[HUKS]: HksGenerateKey quit. [Res]: %d", res);
|
||||
res = HAL_FAILED;
|
||||
goto ERR;
|
||||
}
|
||||
|
||||
ret = GetKeyPair(outParamSet, outPriKey, outPubKey);
|
||||
if (ret != HAL_SUCCESS) {
|
||||
LOGE("parse x25519 output param set failed, ret:%d", ret);
|
||||
res = GetKeyPair(outParamSet, outPriKey, outPubKey);
|
||||
if (res != HAL_SUCCESS) {
|
||||
LOGE("parse x25519 output param set failed, res:%d", res);
|
||||
goto ERR;
|
||||
}
|
||||
ERR:
|
||||
HksFreeParamSet(¶mSet);
|
||||
HcFree(outParamSet);
|
||||
return ret;
|
||||
return res;
|
||||
}
|
||||
|
||||
static int32_t ExportPublicKey(const Uint8Buff *keyAlias, Uint8Buff *outPubKey)
|
||||
@@ -790,9 +802,11 @@ static int32_t ExportPublicKey(const Uint8Buff *keyAlias, Uint8Buff *outPubKey)
|
||||
struct HksBlob keyAliasBlob = { keyAlias->length, keyAlias->val };
|
||||
struct HksBlob keyBlob = { outPubKey->length, outPubKey->val };
|
||||
|
||||
int32_t ret = HksExportPublicKey(&keyAliasBlob, NULL, &keyBlob);
|
||||
if (ret != HKS_SUCCESS) {
|
||||
LOGE("Export public key failed, ret=%d", ret);
|
||||
LOGI("[HUKS]: HksExportPublicKey enter.");
|
||||
int32_t res = HksExportPublicKey(&keyAliasBlob, NULL, &keyBlob);
|
||||
LOGI("[HUKS]: HksExportPublicKey quit. [Res]: %d", res);
|
||||
if (res != HKS_SUCCESS) {
|
||||
LOGE("[HUKS]: HksExportPublicKey failed. [Res]: %d", res);
|
||||
return HAL_FAILED;
|
||||
}
|
||||
outPubKey->length = keyBlob.size;
|
||||
@@ -815,12 +829,12 @@ static int32_t ConstructSignParams(struct HksParamSet **paramSet, Algorithm algo
|
||||
}
|
||||
};
|
||||
|
||||
int32_t ret = ConstructParamSet(paramSet, signParam, CAL_ARRAY_SIZE(signParam));
|
||||
if (ret != HAL_SUCCESS) {
|
||||
LOGE("Construct param set failed, ret = %d", ret);
|
||||
return ret;
|
||||
int32_t res = ConstructParamSet(paramSet, signParam, CAL_ARRAY_SIZE(signParam));
|
||||
if (res != HAL_SUCCESS) {
|
||||
LOGE("Construct param set failed, res = %d", res);
|
||||
return res;
|
||||
}
|
||||
return ret;
|
||||
return res;
|
||||
}
|
||||
|
||||
static int32_t Sign(const Uint8Buff *keyAlias, const Uint8Buff *message, Algorithm algo,
|
||||
@@ -829,9 +843,9 @@ static int32_t Sign(const Uint8Buff *keyAlias, const Uint8Buff *message, Algorit
|
||||
struct HksParamSet *paramSet = NULL;
|
||||
const Uint8Buff *inParams[] = { keyAlias, message, outSignature };
|
||||
const char *paramTags[] = { "keyAlias", "message", "outSignature" };
|
||||
int32_t ret = BaseCheckParams(inParams, paramTags, CAL_ARRAY_SIZE(inParams));
|
||||
if (ret != HAL_SUCCESS) {
|
||||
return ret;
|
||||
int32_t res = BaseCheckParams(inParams, paramTags, CAL_ARRAY_SIZE(inParams));
|
||||
if (res != HAL_SUCCESS) {
|
||||
return res;
|
||||
}
|
||||
|
||||
struct HksBlob keyAliasBlob = { keyAlias->length, keyAlias->val };
|
||||
@@ -840,34 +854,36 @@ static int32_t Sign(const Uint8Buff *keyAlias, const Uint8Buff *message, Algorit
|
||||
messageHash.val = (uint8_t *)HcMalloc(messageHash.length, 0);
|
||||
if (messageHash.val == NULL) {
|
||||
LOGE("malloc messageHash.data failed.");
|
||||
ret = HAL_ERR_BAD_ALLOC;
|
||||
res = HAL_ERR_BAD_ALLOC;
|
||||
goto ERR;
|
||||
}
|
||||
ret = Sha256(message, &messageHash);
|
||||
if (ret != HAL_SUCCESS) {
|
||||
res = Sha256(message, &messageHash);
|
||||
if (res != HAL_SUCCESS) {
|
||||
LOGE("Sha256 failed.");
|
||||
goto ERR;
|
||||
}
|
||||
struct HksBlob messageBlob = { messageHash.length, messageHash.val };
|
||||
struct HksBlob signatureBlob = { outSignature->length, outSignature->val };
|
||||
|
||||
ret = ConstructSignParams(¶mSet, algo);
|
||||
if (ret != HAL_SUCCESS) {
|
||||
res = ConstructSignParams(¶mSet, algo);
|
||||
if (res != HAL_SUCCESS) {
|
||||
goto ERR;
|
||||
}
|
||||
|
||||
ret = HksSign(&keyAliasBlob, paramSet, &messageBlob, &signatureBlob);
|
||||
if (ret != HKS_SUCCESS) {
|
||||
LOGE("Hks sign failed.");
|
||||
ret = HAL_FAILED;
|
||||
LOGI("[HUKS]: HksSign enter.");
|
||||
res = HksSign(&keyAliasBlob, paramSet, &messageBlob, &signatureBlob);
|
||||
LOGI("[HUKS]: HksSign quit. [Res]: %d", res);
|
||||
if (res != HKS_SUCCESS) {
|
||||
LOGE("[HUKS]: HksSign fail. [Res]: %d", res);
|
||||
res = HAL_FAILED;
|
||||
goto ERR;
|
||||
}
|
||||
outSignature->length = signatureBlob.size;
|
||||
ret = HAL_SUCCESS;
|
||||
res = HAL_SUCCESS;
|
||||
ERR:
|
||||
HksFreeParamSet(¶mSet);
|
||||
HcFree(messageHash.val);
|
||||
return ret;
|
||||
return res;
|
||||
}
|
||||
|
||||
static int32_t ConstructVerifyParams(struct HksParamSet **paramSet, Algorithm algo, bool isAlias)
|
||||
@@ -888,12 +904,12 @@ static int32_t ConstructVerifyParams(struct HksParamSet **paramSet, Algorithm al
|
||||
}
|
||||
};
|
||||
|
||||
int32_t ret = ConstructParamSet(paramSet, verifyParam, CAL_ARRAY_SIZE(verifyParam));
|
||||
if (ret != HAL_SUCCESS) {
|
||||
LOGE("Construct param set failed, ret = %d", ret);
|
||||
return ret;
|
||||
int32_t res = ConstructParamSet(paramSet, verifyParam, CAL_ARRAY_SIZE(verifyParam));
|
||||
if (res != HAL_SUCCESS) {
|
||||
LOGE("Construct param set failed, res = %d", res);
|
||||
return res;
|
||||
}
|
||||
return ret;
|
||||
return res;
|
||||
}
|
||||
|
||||
static int32_t Verify(const Uint8Buff *key, const Uint8Buff *message, Algorithm algo,
|
||||
@@ -902,9 +918,9 @@ static int32_t Verify(const Uint8Buff *key, const Uint8Buff *message, Algorithm
|
||||
struct HksParamSet *paramSet = NULL;
|
||||
const Uint8Buff *inParams[] = { key, message, signature };
|
||||
const char *paramTags[] = { "key", "message", "signature" };
|
||||
int32_t ret = BaseCheckParams(inParams, paramTags, CAL_ARRAY_SIZE(inParams));
|
||||
if (ret != HAL_SUCCESS) {
|
||||
return ret;
|
||||
int32_t res = BaseCheckParams(inParams, paramTags, CAL_ARRAY_SIZE(inParams));
|
||||
if (res != HAL_SUCCESS) {
|
||||
return res;
|
||||
}
|
||||
|
||||
struct HksBlob keyAliasBlob = { key->length, key->val };
|
||||
@@ -913,33 +929,35 @@ static int32_t Verify(const Uint8Buff *key, const Uint8Buff *message, Algorithm
|
||||
messageHash.val = (uint8_t *)HcMalloc(messageHash.length, 0);
|
||||
if (messageHash.val == NULL) {
|
||||
LOGE("malloc messageHash.data failed.");
|
||||
ret = HAL_ERR_BAD_ALLOC;
|
||||
res = HAL_ERR_BAD_ALLOC;
|
||||
goto ERR;
|
||||
}
|
||||
ret = Sha256(message, &messageHash);
|
||||
if (ret != HAL_SUCCESS) {
|
||||
res = Sha256(message, &messageHash);
|
||||
if (res != HAL_SUCCESS) {
|
||||
LOGE("Sha256 failed.");
|
||||
goto ERR;
|
||||
}
|
||||
struct HksBlob messageBlob = { messageHash.length, messageHash.val };
|
||||
struct HksBlob signatureBlob = { signature->length, signature->val };
|
||||
|
||||
ret = ConstructVerifyParams(¶mSet, algo, isAlias);
|
||||
if (ret != HAL_SUCCESS) {
|
||||
res = ConstructVerifyParams(¶mSet, algo, isAlias);
|
||||
if (res != HAL_SUCCESS) {
|
||||
goto ERR;
|
||||
}
|
||||
|
||||
ret = HksVerify(&keyAliasBlob, paramSet, &messageBlob, &signatureBlob);
|
||||
if ((ret != HKS_SUCCESS)) {
|
||||
LOGE("HksVerify failed, ret: %d", ret);
|
||||
ret = HAL_FAILED;
|
||||
LOGI("[HUKS]: HksVerify enter.");
|
||||
res = HksVerify(&keyAliasBlob, paramSet, &messageBlob, &signatureBlob);
|
||||
LOGI("[HUKS]: HksVerify quit. [Res]: %d", res);
|
||||
if ((res != HKS_SUCCESS)) {
|
||||
LOGE("[HUKS]: HksVerify fail. [Res]: %d", res);
|
||||
res = HAL_FAILED;
|
||||
goto ERR;
|
||||
}
|
||||
ret = HAL_SUCCESS;
|
||||
res = HAL_SUCCESS;
|
||||
ERR:
|
||||
HksFreeParamSet(¶mSet);
|
||||
HcFree(messageHash.val);
|
||||
return ret;
|
||||
return res;
|
||||
}
|
||||
|
||||
static int32_t ConstructImportPublicKeyParams(struct HksParamSet **paramSet, Algorithm algo, uint32_t keyLen,
|
||||
@@ -976,12 +994,12 @@ static int32_t ConstructImportPublicKeyParams(struct HksParamSet **paramSet, Alg
|
||||
}
|
||||
};
|
||||
|
||||
int32_t ret = ConstructParamSet(paramSet, importParam, CAL_ARRAY_SIZE(importParam));
|
||||
if (ret != HAL_SUCCESS) {
|
||||
LOGE("Construct param set failed, ret = %d", ret);
|
||||
return ret;
|
||||
int32_t res = ConstructParamSet(paramSet, importParam, CAL_ARRAY_SIZE(importParam));
|
||||
if (res != HAL_SUCCESS) {
|
||||
LOGE("Construct param set failed, res = %d", res);
|
||||
return res;
|
||||
}
|
||||
return ret;
|
||||
return res;
|
||||
}
|
||||
|
||||
static int32_t ImportPublicKey(const Uint8Buff *keyAlias, const Uint8Buff *pubKey, Algorithm algo,
|
||||
@@ -1010,14 +1028,16 @@ static int32_t ImportPublicKey(const Uint8Buff *keyAlias, const Uint8Buff *pubKe
|
||||
|
||||
struct HksParamSet *paramSet = NULL;
|
||||
|
||||
int32_t ret = ConstructImportPublicKeyParams(¶mSet, algo, pubKey->length, &authIdBlob, &roleInfoUnion);
|
||||
if (ret != HAL_SUCCESS) {
|
||||
return ret;
|
||||
int32_t res = ConstructImportPublicKeyParams(¶mSet, algo, pubKey->length, &authIdBlob, &roleInfoUnion);
|
||||
if (res != HAL_SUCCESS) {
|
||||
return res;
|
||||
}
|
||||
|
||||
ret = HksImportKey(&keyAliasBlob, paramSet, &pubKeyBlob);
|
||||
if (ret != HKS_SUCCESS) {
|
||||
LOGE("Hks importKey failed, ret: %d", ret);
|
||||
LOGI("[HUKS]: HksImportKey enter.");
|
||||
res = HksImportKey(&keyAliasBlob, paramSet, &pubKeyBlob);
|
||||
LOGI("[HUKS]: HksImportKey quit. [Res]: %d", res);
|
||||
if (res != HKS_SUCCESS) {
|
||||
LOGE("[HUKS]: HksImportKey fail. [Res]: %d", res);
|
||||
HksFreeParamSet(¶mSet);
|
||||
return HAL_FAILED;
|
||||
}
|
||||
|
||||
@@ -53,22 +53,22 @@ static int32_t ConstructParamSet(struct HksParamSet **out, const struct HksParam
|
||||
const uint32_t inParamNum)
|
||||
{
|
||||
struct HksParamSet *paramSet = NULL;
|
||||
int32_t ret = HksInitParamSet(¶mSet);
|
||||
if (ret != HKS_SUCCESS) {
|
||||
LOGE("init param set failed, ret = %d", ret);
|
||||
int32_t res = HksInitParamSet(¶mSet);
|
||||
if (res != HKS_SUCCESS) {
|
||||
LOGE("init param set failed, res = %d", res);
|
||||
return HAL_ERR_INIT_PARAM_SET_FAILED;
|
||||
}
|
||||
|
||||
ret = HksAddParams(paramSet, inParam, inParamNum);
|
||||
if (ret != HKS_SUCCESS) {
|
||||
LOGE("add param failed, ret = %d", ret);
|
||||
res = HksAddParams(paramSet, inParam, inParamNum);
|
||||
if (res != HKS_SUCCESS) {
|
||||
LOGE("add param failed, res = %d", res);
|
||||
HksFreeParamSet(¶mSet);
|
||||
return HAL_ERR_ADD_PARAM_FAILED;
|
||||
}
|
||||
|
||||
ret = HksBuildParamSet(¶mSet);
|
||||
if (ret != HKS_SUCCESS) {
|
||||
LOGE("build param set failed, ret = %d", ret);
|
||||
res = HksBuildParamSet(¶mSet);
|
||||
if (res != HKS_SUCCESS) {
|
||||
LOGE("build param set failed, res = %d", res);
|
||||
HksFreeParamSet(¶mSet);
|
||||
return HAL_ERR_BUILD_PARAM_SET_FAILED;
|
||||
}
|
||||
@@ -79,7 +79,13 @@ static int32_t ConstructParamSet(struct HksParamSet **out, const struct HksParam
|
||||
|
||||
static int32_t InitHks(void)
|
||||
{
|
||||
return HksInitialize();
|
||||
LOGI("[HUKS]: HksInitialize enter.");
|
||||
int32_t res = HksInitialize();
|
||||
LOGI("[HUKS]: HksInitialize quit. [Res]: %d", res);
|
||||
if (res != HKS_SUCCESS) {
|
||||
LOGE("[HUKS]: HksInitialize fail. [Res]: %d", res);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
static int32_t Sha256(const Uint8Buff *message, Uint8Buff *hash)
|
||||
@@ -101,14 +107,15 @@ static int32_t Sha256(const Uint8Buff *message, Uint8Buff *hash)
|
||||
.uint32Param = HKS_DIGEST_SHA256
|
||||
}
|
||||
};
|
||||
int32_t ret = ConstructParamSet(¶mSet, digestParam, CAL_ARRAY_SIZE(digestParam));
|
||||
if (ret != HAL_SUCCESS) {
|
||||
LOGE("construct param set failed, ret = %d", ret);
|
||||
return ret;
|
||||
int32_t res = ConstructParamSet(¶mSet, digestParam, CAL_ARRAY_SIZE(digestParam));
|
||||
if (res != HAL_SUCCESS) {
|
||||
LOGE("construct param set failed, res = %d", res);
|
||||
return res;
|
||||
}
|
||||
|
||||
ret = HksHash(paramSet, &srcBlob, &hashBlob);
|
||||
if (ret != HKS_SUCCESS || hashBlob.size != SHA256_LEN) {
|
||||
res = HksHash(paramSet, &srcBlob, &hashBlob);
|
||||
if (res != HKS_SUCCESS || hashBlob.size != SHA256_LEN) {
|
||||
LOGE("[HUKS]: HksHash fail. [Res]: %d", res);
|
||||
HksFreeParamSet(¶mSet);
|
||||
return HAL_FAILED;
|
||||
}
|
||||
@@ -124,9 +131,9 @@ static int32_t GenerateRandom(Uint8Buff *rand)
|
||||
CHECK_LEN_ZERO_RETURN_ERROR_CODE(rand->length, "rand->length");
|
||||
|
||||
struct HksBlob randBlob = { rand->length, rand->val };
|
||||
int32_t ret = HksGenerateRandom(NULL, &randBlob);
|
||||
if (ret != HKS_SUCCESS) {
|
||||
LOGE("Generate random failed, ret: %d", ret);
|
||||
int32_t res = HksGenerateRandom(NULL, &randBlob);
|
||||
if (res != HKS_SUCCESS) {
|
||||
LOGE("[HUKS]: HksGenerateRandom fail. [Res]: %d", res);
|
||||
return HAL_FAILED;
|
||||
}
|
||||
|
||||
@@ -140,9 +147,9 @@ static int32_t CheckKeyExist(const Uint8Buff *keyAlias)
|
||||
CHECK_LEN_ZERO_RETURN_ERROR_CODE(keyAlias->length, "keyAlias->length");
|
||||
|
||||
struct HksBlob keyAliasBlob = { keyAlias->length, keyAlias->val };
|
||||
int32_t ret = HksKeyExist(&keyAliasBlob, NULL);
|
||||
if (ret != HKS_SUCCESS) {
|
||||
LOGI("Hks check key exist or not, ret = %d", ret);
|
||||
int32_t res = HksKeyExist(&keyAliasBlob, NULL);
|
||||
if (res != HKS_SUCCESS) {
|
||||
LOGI("[HUKS]: HksKeyExist fail. [Res]: %d", res);
|
||||
return HAL_FAILED;
|
||||
}
|
||||
|
||||
@@ -156,13 +163,15 @@ static int32_t DeleteKey(const Uint8Buff *keyAlias)
|
||||
CHECK_LEN_ZERO_RETURN_ERROR_CODE(keyAlias->length, "keyAlias->length");
|
||||
|
||||
struct HksBlob keyAliasBlob = { keyAlias->length, keyAlias->val };
|
||||
int32_t ret = HksDeleteKey(&keyAliasBlob, NULL);
|
||||
if (ret == HKS_ERROR_NOT_EXIST) {
|
||||
LOGI("[HUKS]: HksDeleteKey enter.");
|
||||
int32_t res = HksDeleteKey(&keyAliasBlob, NULL);
|
||||
LOGI("[HUKS]: HksDeleteKey quit. [Res]: %d", res);
|
||||
if (res == HKS_ERROR_NOT_EXIST) {
|
||||
LOGI("Key not exists.");
|
||||
return HAL_SUCCESS;
|
||||
}
|
||||
if (ret != HKS_SUCCESS) {
|
||||
LOGE("Delete key failed, ret = %d", ret);
|
||||
if (res != HKS_SUCCESS) {
|
||||
LOGE("[HUKS]: HksDeleteKey fail. [Res]: %d", res);
|
||||
return HAL_FAILED;
|
||||
}
|
||||
|
||||
@@ -173,9 +182,9 @@ static int32_t ComputeHmac(const Uint8Buff *key, const Uint8Buff *message, Uint8
|
||||
{
|
||||
const Uint8Buff *inParams[] = { key, message, outHmac };
|
||||
const char *paramTags[] = {"key", "message", "outHmac"};
|
||||
int32_t ret = BaseCheckParams(inParams, paramTags, CAL_ARRAY_SIZE(inParams));
|
||||
if (ret != HAL_SUCCESS) {
|
||||
return ret;
|
||||
int32_t res = BaseCheckParams(inParams, paramTags, CAL_ARRAY_SIZE(inParams));
|
||||
if (res != HAL_SUCCESS) {
|
||||
return res;
|
||||
}
|
||||
CHECK_LEN_EQUAL_RETURN(outHmac->length, HMAC_LEN, "outHmac->length");
|
||||
|
||||
@@ -195,15 +204,17 @@ static int32_t ComputeHmac(const Uint8Buff *key, const Uint8Buff *message, Uint8
|
||||
.boolParam = isAlias
|
||||
}
|
||||
};
|
||||
ret = ConstructParamSet(¶mSet, hmacParam, CAL_ARRAY_SIZE(hmacParam));
|
||||
if (ret != HAL_SUCCESS) {
|
||||
LOGE("construct param set failed, ret = %d", ret);
|
||||
return ret;
|
||||
res = ConstructParamSet(¶mSet, hmacParam, CAL_ARRAY_SIZE(hmacParam));
|
||||
if (res != HAL_SUCCESS) {
|
||||
LOGE("construct param set failed, res = %d", res);
|
||||
return res;
|
||||
}
|
||||
|
||||
ret = HksMac(&keyBlob, paramSet, &srcBlob, &hmacBlob);
|
||||
if (ret != HKS_SUCCESS || hmacBlob.size != HMAC_LEN) {
|
||||
LOGE("Hmac failed, ret: %d", ret);
|
||||
LOGI("[HUKS]: HksMac enter.");
|
||||
res = HksMac(&keyBlob, paramSet, &srcBlob, &hmacBlob);
|
||||
LOGI("[HUKS]: HksMac quit. [Res]: %d", res);
|
||||
if (res != HKS_SUCCESS || hmacBlob.size != HMAC_LEN) {
|
||||
LOGE("[HUKS]: HksMac fail. [Res]: %d", res);
|
||||
HksFreeParamSet(¶mSet);
|
||||
return HAL_FAILED;
|
||||
}
|
||||
@@ -217,9 +228,9 @@ static int32_t ComputeHkdf(const Uint8Buff *baseKey, const Uint8Buff *salt, cons
|
||||
{
|
||||
const Uint8Buff *inParams[] = { baseKey, salt, outHkdf };
|
||||
const char *paramTags[] = { "baseKey", "salt", "outHkdf" };
|
||||
int32_t ret = BaseCheckParams(inParams, paramTags, CAL_ARRAY_SIZE(inParams));
|
||||
if (ret != HAL_SUCCESS) {
|
||||
return ret;
|
||||
int32_t res = BaseCheckParams(inParams, paramTags, CAL_ARRAY_SIZE(inParams));
|
||||
if (res != HAL_SUCCESS) {
|
||||
return res;
|
||||
}
|
||||
|
||||
struct HksBlob srcKeyBlob = { baseKey->length, baseKey->val };
|
||||
@@ -233,35 +244,24 @@ static int32_t ComputeHkdf(const Uint8Buff *baseKey, const Uint8Buff *salt, cons
|
||||
|
||||
struct HksParamSet *paramSet = NULL;
|
||||
struct HksParam hkdfParam[] = {
|
||||
{
|
||||
.tag = HKS_TAG_PURPOSE,
|
||||
.uint32Param = HKS_KEY_PURPOSE_DERIVE
|
||||
}, {
|
||||
.tag = HKS_TAG_ALGORITHM,
|
||||
.uint32Param = HKS_ALG_HKDF
|
||||
}, {
|
||||
.tag = HKS_TAG_DIGEST,
|
||||
.uint32Param = HKS_DIGEST_SHA256
|
||||
}, {
|
||||
.tag = HKS_TAG_SALT,
|
||||
.blob = saltBlob
|
||||
}, {
|
||||
.tag = HKS_TAG_INFO,
|
||||
.blob = keyInfoBlob
|
||||
}, {
|
||||
.tag = HKS_TAG_IS_KEY_ALIAS,
|
||||
.boolParam = isAlias
|
||||
}
|
||||
{ .tag = HKS_TAG_PURPOSE, .uint32Param = HKS_KEY_PURPOSE_DERIVE },
|
||||
{ .tag = HKS_TAG_ALGORITHM, .uint32Param = HKS_ALG_HKDF },
|
||||
{ .tag = HKS_TAG_DIGEST, .uint32Param = HKS_DIGEST_SHA256 },
|
||||
{ .tag = HKS_TAG_SALT, .blob = saltBlob },
|
||||
{ .tag = HKS_TAG_INFO, .blob = keyInfoBlob },
|
||||
{ .tag = HKS_TAG_IS_KEY_ALIAS, .boolParam = isAlias }
|
||||
};
|
||||
|
||||
ret = ConstructParamSet(¶mSet, hkdfParam, CAL_ARRAY_SIZE(hkdfParam));
|
||||
if (ret != HAL_SUCCESS) {
|
||||
return ret;
|
||||
res = ConstructParamSet(¶mSet, hkdfParam, CAL_ARRAY_SIZE(hkdfParam));
|
||||
if (res != HAL_SUCCESS) {
|
||||
return res;
|
||||
}
|
||||
|
||||
ret = HksDeriveKey(paramSet, &srcKeyBlob, &derivedKeyBlob);
|
||||
if (ret != HKS_SUCCESS) {
|
||||
LOGE("Key derivation failed, ret: %d", ret);
|
||||
LOGI("[HUKS]: HksDeriveKey enter.");
|
||||
res = HksDeriveKey(paramSet, &srcKeyBlob, &derivedKeyBlob);
|
||||
LOGI("[HUKS]: HksDeriveKey quit. [Res]: %d", res);
|
||||
if (res != HKS_SUCCESS) {
|
||||
LOGE("[HUKS]: HksDeriveKey fail. [Res]: %d", res);
|
||||
HksFreeParamSet(¶mSet);
|
||||
return HAL_FAILED;
|
||||
}
|
||||
@@ -275,9 +275,9 @@ static int32_t CheckAesGcmEncryptParam(const Uint8Buff *key, const Uint8Buff *pl
|
||||
{
|
||||
const Uint8Buff *inParams[] = { key, plain, outCipher };
|
||||
const char* paramTags[] = { "key", "plain", "outCipher" };
|
||||
int32_t ret = BaseCheckParams(inParams, paramTags, CAL_ARRAY_SIZE(inParams));
|
||||
if (ret != HAL_SUCCESS) {
|
||||
return ret;
|
||||
int32_t res = BaseCheckParams(inParams, paramTags, CAL_ARRAY_SIZE(inParams));
|
||||
if (res != HAL_SUCCESS) {
|
||||
return res;
|
||||
}
|
||||
|
||||
CHECK_PTR_RETURN_HAL_ERROR_CODE(encryptInfo, "encryptInfo");
|
||||
@@ -293,9 +293,9 @@ static int32_t CheckAesGcmEncryptParam(const Uint8Buff *key, const Uint8Buff *pl
|
||||
static int32_t AesGcmEncrypt(const Uint8Buff *key, const Uint8Buff *plain,
|
||||
const GcmParam *encryptInfo, bool isAlias, Uint8Buff *outCipher)
|
||||
{
|
||||
int32_t ret = CheckAesGcmEncryptParam(key, plain, encryptInfo, outCipher);
|
||||
if (ret != HAL_SUCCESS) {
|
||||
return ret;
|
||||
int32_t res = CheckAesGcmEncryptParam(key, plain, encryptInfo, outCipher);
|
||||
if (res != HAL_SUCCESS) {
|
||||
return res;
|
||||
}
|
||||
|
||||
struct HksBlob keyBlob = { key->length, key->val };
|
||||
@@ -328,15 +328,17 @@ static int32_t AesGcmEncrypt(const Uint8Buff *key, const Uint8Buff *plain,
|
||||
}
|
||||
};
|
||||
|
||||
ret = ConstructParamSet(¶mSet, encryptParam, CAL_ARRAY_SIZE(encryptParam));
|
||||
if (ret != HAL_SUCCESS) {
|
||||
LOGE("construct param set failed, ret = %d", ret);
|
||||
return ret;
|
||||
res = ConstructParamSet(¶mSet, encryptParam, CAL_ARRAY_SIZE(encryptParam));
|
||||
if (res != HAL_SUCCESS) {
|
||||
LOGE("construct param set failed, res = %d", res);
|
||||
return res;
|
||||
}
|
||||
|
||||
ret = HksEncrypt(&keyBlob, paramSet, &plainBlob, &cipherBlob);
|
||||
if (ret != HKS_SUCCESS) {
|
||||
LOGE("Aes-gcm encrypt failed, ret: %d", ret);
|
||||
LOGI("[HUKS]: HksEncrypt enter.");
|
||||
res = HksEncrypt(&keyBlob, paramSet, &plainBlob, &cipherBlob);
|
||||
LOGI("[HUKS]: HksEncrypt quit. [Res]: %d", res);
|
||||
if (res != HKS_SUCCESS) {
|
||||
LOGE("[HUKS]: HksEncrypt fail. [Res]: %d", res);
|
||||
HksFreeParamSet(¶mSet);
|
||||
return HAL_FAILED;
|
||||
}
|
||||
@@ -350,9 +352,9 @@ static int32_t CheckAesGcmDecryptParam(const Uint8Buff *key, const Uint8Buff *ci
|
||||
{
|
||||
const Uint8Buff *inParams[] = { key, cipher, outPlain };
|
||||
const char *paramTags[] = { "key", "cipher", "outPlain" };
|
||||
int32_t ret = BaseCheckParams(inParams, paramTags, CAL_ARRAY_SIZE(inParams));
|
||||
if (ret != HAL_SUCCESS) {
|
||||
return ret;
|
||||
int32_t res = BaseCheckParams(inParams, paramTags, CAL_ARRAY_SIZE(inParams));
|
||||
if (res != HAL_SUCCESS) {
|
||||
return res;
|
||||
}
|
||||
|
||||
CHECK_PTR_RETURN_HAL_ERROR_CODE(decryptInfo, "decryptInfo");
|
||||
@@ -368,9 +370,9 @@ static int32_t CheckAesGcmDecryptParam(const Uint8Buff *key, const Uint8Buff *ci
|
||||
static int32_t AesGcmDecrypt(const Uint8Buff *key, const Uint8Buff *cipher,
|
||||
const GcmParam *decryptInfo, bool isAlias, Uint8Buff *outPlain)
|
||||
{
|
||||
int32_t ret = CheckAesGcmDecryptParam(key, cipher, decryptInfo, outPlain);
|
||||
if (ret != HAL_SUCCESS) {
|
||||
return ret;
|
||||
int32_t res = CheckAesGcmDecryptParam(key, cipher, decryptInfo, outPlain);
|
||||
if (res != HAL_SUCCESS) {
|
||||
return res;
|
||||
}
|
||||
|
||||
struct HksBlob keyBlob = { key->length, key->val };
|
||||
@@ -403,15 +405,17 @@ static int32_t AesGcmDecrypt(const Uint8Buff *key, const Uint8Buff *cipher,
|
||||
}
|
||||
};
|
||||
|
||||
ret = ConstructParamSet(¶mSet, decryptParam, CAL_ARRAY_SIZE(decryptParam));
|
||||
if (ret != HAL_SUCCESS) {
|
||||
LOGE("construct param set failed, ret = %d", ret);
|
||||
return ret;
|
||||
res = ConstructParamSet(¶mSet, decryptParam, CAL_ARRAY_SIZE(decryptParam));
|
||||
if (res != HAL_SUCCESS) {
|
||||
LOGE("construct param set failed, res = %d", res);
|
||||
return res;
|
||||
}
|
||||
|
||||
ret = HksDecrypt(&keyBlob, paramSet, &cipherBlob, &plainBlob);
|
||||
if (ret != HKS_SUCCESS) {
|
||||
LOGE("Aes-gcm decrypt failed, ret: %d", ret);
|
||||
LOGI("[HUKS]: HksDecrypt enter.");
|
||||
res = HksDecrypt(&keyBlob, paramSet, &cipherBlob, &plainBlob);
|
||||
LOGI("[HUKS]: HksDecrypt quit. [Res]: %d", res);
|
||||
if (res != HKS_SUCCESS) {
|
||||
LOGE("[HUKS]: HksDecrypt fail. [Res]: %d", res);
|
||||
HksFreeParamSet(¶mSet);
|
||||
return HAL_FAILED;
|
||||
}
|
||||
@@ -441,9 +445,9 @@ static int32_t HashToPoint(const Uint8Buff *hash, Algorithm algo, Uint8Buff *out
|
||||
struct HksBlob hashBlob = { hash->length, hash->val };
|
||||
struct HksBlob pointBlob = { outEcPoint->length, outEcPoint->val };
|
||||
|
||||
int32_t ret = OpensslHashToPoint(&hashBlob, &pointBlob);
|
||||
if (ret != HAL_SUCCESS || pointBlob.size != SHA256_LEN) {
|
||||
LOGE("HashToPoint for x25519 failed, ret: %d", ret);
|
||||
int32_t res = OpensslHashToPoint(&hashBlob, &pointBlob);
|
||||
if (res != HAL_SUCCESS || pointBlob.size != SHA256_LEN) {
|
||||
LOGE("HashToPoint for x25519 failed, res: %d", res);
|
||||
return HAL_FAILED;
|
||||
}
|
||||
|
||||
@@ -464,11 +468,11 @@ static int32_t ConstructInitParamsP256(struct HksParamSet **initParamSet)
|
||||
.uint32Param = HKS_ECC_KEY_SIZE_256
|
||||
}
|
||||
};
|
||||
int32_t ret = ConstructParamSet(initParamSet, agreeParamInit, CAL_ARRAY_SIZE(agreeParamInit));
|
||||
if (ret != HAL_SUCCESS) {
|
||||
LOGE("Construct init param set failed for P256, ret = %d", ret);
|
||||
int32_t res = ConstructParamSet(initParamSet, agreeParamInit, CAL_ARRAY_SIZE(agreeParamInit));
|
||||
if (res != HAL_SUCCESS) {
|
||||
LOGE("Construct init param set failed for P256, res = %d", res);
|
||||
}
|
||||
return ret;
|
||||
return res;
|
||||
}
|
||||
|
||||
static int32_t ConstructFinishParamsP256(struct HksParamSet **finishParamSet,
|
||||
@@ -498,11 +502,11 @@ static int32_t ConstructFinishParamsP256(struct HksParamSet **finishParamSet,
|
||||
.blob = *sharedKeyAliasBlob
|
||||
}
|
||||
};
|
||||
int32_t ret = ConstructParamSet(finishParamSet, agreeParamFinish, CAL_ARRAY_SIZE(agreeParamFinish));
|
||||
if (ret != HAL_SUCCESS) {
|
||||
LOGE("Construct finish param set failed for P256, ret = %d", ret);
|
||||
int32_t res = ConstructParamSet(finishParamSet, agreeParamFinish, CAL_ARRAY_SIZE(agreeParamFinish));
|
||||
if (res != HAL_SUCCESS) {
|
||||
LOGE("Construct finish param set failed for P256, res = %d", res);
|
||||
}
|
||||
return ret;
|
||||
return res;
|
||||
}
|
||||
|
||||
static int32_t AgreeSharedSecretWithStorageP256(const KeyBuff *priKeyAlias, const KeyBuff *pubKey,
|
||||
@@ -510,14 +514,14 @@ static int32_t AgreeSharedSecretWithStorageP256(const KeyBuff *priKeyAlias, cons
|
||||
{
|
||||
struct HksParamSet *initParamSet = NULL;
|
||||
struct HksParamSet *finishParamSet = NULL;
|
||||
int32_t ret = ConstructInitParamsP256(&initParamSet);
|
||||
if (ret != HAL_SUCCESS) {
|
||||
return ret;
|
||||
int32_t res = ConstructInitParamsP256(&initParamSet);
|
||||
if (res != HAL_SUCCESS) {
|
||||
return res;
|
||||
}
|
||||
ret = ConstructFinishParamsP256(&finishParamSet, sharedKeyAliasBlob);
|
||||
if (ret != HAL_SUCCESS) {
|
||||
res = ConstructFinishParamsP256(&finishParamSet, sharedKeyAliasBlob);
|
||||
if (res != HAL_SUCCESS) {
|
||||
HksFreeParamSet(&initParamSet);
|
||||
return ret;
|
||||
return res;
|
||||
}
|
||||
struct HksBlob priKeyAliasBlob = { priKeyAlias->keyLen, priKeyAlias->key };
|
||||
struct HksBlob pubKeyBlob = { pubKey->keyLen, pubKey->key };
|
||||
@@ -528,28 +532,30 @@ static int32_t AgreeSharedSecretWithStorageP256(const KeyBuff *priKeyAlias, cons
|
||||
uint8_t outDataFinish[ECDH_COMMON_SIZE_P256] = { 0 };
|
||||
struct HksBlob outDataFinishBlob = { ECDH_COMMON_SIZE_P256, outDataFinish };
|
||||
do {
|
||||
ret = HksInit(&priKeyAliasBlob, initParamSet, &handleBlob, NULL);
|
||||
if (ret != HKS_SUCCESS) {
|
||||
LOGE("Huks agree P256 key: HksInit failed, ret = %d", ret);
|
||||
ret = HAL_ERR_HUKS;
|
||||
res = HksInit(&priKeyAliasBlob, initParamSet, &handleBlob, NULL);
|
||||
if (res != HKS_SUCCESS) {
|
||||
LOGE("Huks agree P256 key: HksInit failed, res = %d", res);
|
||||
res = HAL_ERR_HUKS;
|
||||
break;
|
||||
}
|
||||
ret = HksUpdate(&handleBlob, initParamSet, &pubKeyBlob, &outDataUpdateBlob);
|
||||
if (ret != HKS_SUCCESS) {
|
||||
LOGE("Huks agree P256 key: HksUpdate failed, ret = %d", ret);
|
||||
ret = HAL_ERR_HUKS;
|
||||
res = HksUpdate(&handleBlob, initParamSet, &pubKeyBlob, &outDataUpdateBlob);
|
||||
if (res != HKS_SUCCESS) {
|
||||
LOGE("Huks agree P256 key: HksUpdate failed, res = %d", res);
|
||||
res = HAL_ERR_HUKS;
|
||||
break;
|
||||
}
|
||||
ret = HksFinish(&handleBlob, finishParamSet, &pubKeyBlob, &outDataFinishBlob);
|
||||
if (ret != HKS_SUCCESS) {
|
||||
LOGE("Huks agree P256 key: HksFinish failed, ret = %d", ret);
|
||||
ret = HAL_ERR_HUKS;
|
||||
LOGI("[HUKS]: HksFinish enter.");
|
||||
res = HksFinish(&handleBlob, finishParamSet, &pubKeyBlob, &outDataFinishBlob);
|
||||
LOGI("[HUKS]: HksFinish quit. [Res]: %d", res);
|
||||
if (res != HKS_SUCCESS) {
|
||||
LOGE("[HUKS]: HksFinish fail. [Res]: %d", res);
|
||||
res = HAL_ERR_HUKS;
|
||||
break;
|
||||
}
|
||||
} while (0);
|
||||
HksFreeParamSet(&initParamSet);
|
||||
HksFreeParamSet(&finishParamSet);
|
||||
return ret;
|
||||
return res;
|
||||
}
|
||||
|
||||
static int32_t ConstructAgreeWithStorageParams(struct HksParamSet **paramSet, uint32_t keyLen, Algorithm algo,
|
||||
@@ -588,11 +594,11 @@ static int32_t ConstructAgreeWithStorageParams(struct HksParamSet **paramSet, ui
|
||||
}
|
||||
};
|
||||
|
||||
int32_t ret = ConstructParamSet(paramSet, agreeParam, CAL_ARRAY_SIZE(agreeParam));
|
||||
if (ret != HAL_SUCCESS) {
|
||||
LOGE("Construct param set failed, ret = %d", ret);
|
||||
int32_t res = ConstructParamSet(paramSet, agreeParam, CAL_ARRAY_SIZE(agreeParam));
|
||||
if (res != HAL_SUCCESS) {
|
||||
LOGE("Construct param set failed, res = %d", res);
|
||||
}
|
||||
return ret;
|
||||
return res;
|
||||
}
|
||||
|
||||
static int32_t AgreeSharedSecretWithStorage(const KeyBuff *priKey, const KeyBuff *pubKey, Algorithm algo,
|
||||
@@ -615,14 +621,16 @@ static int32_t AgreeSharedSecretWithStorage(const KeyBuff *priKey, const KeyBuff
|
||||
return AgreeSharedSecretWithStorageP256(priKey, pubKey, &sharedKeyAliasBlob);
|
||||
}
|
||||
struct HksParamSet *paramSet = NULL;
|
||||
int32_t ret = ConstructAgreeWithStorageParams(¶mSet, sharedKeyLen, algo, priKey, pubKey);
|
||||
if (ret != HAL_SUCCESS) {
|
||||
return ret;
|
||||
int32_t res = ConstructAgreeWithStorageParams(¶mSet, sharedKeyLen, algo, priKey, pubKey);
|
||||
if (res != HAL_SUCCESS) {
|
||||
return res;
|
||||
}
|
||||
|
||||
ret = HksGenerateKey(&sharedKeyAliasBlob, paramSet, NULL);
|
||||
if (ret != HKS_SUCCESS) {
|
||||
LOGE("Hks agree key with storage failed, ret = %d", ret);
|
||||
LOGI("[HUKS]: HksGenerateKey enter.");
|
||||
res = HksGenerateKey(&sharedKeyAliasBlob, paramSet, NULL);
|
||||
LOGI("[HUKS]: HksGenerateKey quit. [Res]: %d", res);
|
||||
if (res != HKS_SUCCESS) {
|
||||
LOGE("[HUKS]: HksGenerateKey fail. [Res]: %d", res);
|
||||
HksFreeParamSet(¶mSet);
|
||||
return HAL_FAILED;
|
||||
}
|
||||
@@ -666,15 +674,17 @@ static int32_t AgreeSharedSecret(const KeyBuff *priKey, const KeyBuff *pubKey, A
|
||||
}
|
||||
};
|
||||
|
||||
int32_t ret = ConstructParamSet(¶mSet, agreeParam, CAL_ARRAY_SIZE(agreeParam));
|
||||
if (ret != HAL_SUCCESS) {
|
||||
LOGE("Construct param set failed, ret = %d", ret);
|
||||
return ret;
|
||||
int32_t res = ConstructParamSet(¶mSet, agreeParam, CAL_ARRAY_SIZE(agreeParam));
|
||||
if (res != HAL_SUCCESS) {
|
||||
LOGE("Construct param set failed, res = %d", res);
|
||||
return res;
|
||||
}
|
||||
|
||||
ret = HksAgreeKey(paramSet, &priKeyBlob, &pubKeyBlob, &sharedKeyBlob);
|
||||
if (ret != HKS_SUCCESS) {
|
||||
LOGE("Agree key failed, ret = %d", ret);
|
||||
LOGI("[HUKS]: HksAgreeKey enter.");
|
||||
res = HksAgreeKey(paramSet, &priKeyBlob, &pubKeyBlob, &sharedKeyBlob);
|
||||
LOGI("[HUKS]: HksAgreeKey quit. [Res]: %d");
|
||||
if (res != HKS_SUCCESS) {
|
||||
LOGE("[HUKS]: HksAgreeKey fail. [Res]: %d");
|
||||
HksFreeParamSet(¶mSet);
|
||||
return HAL_FAILED;
|
||||
}
|
||||
@@ -687,9 +697,9 @@ static int32_t BigNumExpMod(const Uint8Buff *base, const Uint8Buff *exp, const c
|
||||
{
|
||||
const Uint8Buff *inParams[] = { base, exp, outNum };
|
||||
const char *paramTags[] = { "base", "exp", "outNum" };
|
||||
int32_t ret = BaseCheckParams(inParams, paramTags, CAL_ARRAY_SIZE(inParams));
|
||||
if (ret != HAL_SUCCESS) {
|
||||
return ret;
|
||||
int32_t res = BaseCheckParams(inParams, paramTags, CAL_ARRAY_SIZE(inParams));
|
||||
if (res != HAL_SUCCESS) {
|
||||
return res;
|
||||
}
|
||||
|
||||
CHECK_PTR_RETURN_HAL_ERROR_CODE(bigNumHex, "bigNumHex");
|
||||
@@ -710,16 +720,16 @@ static int32_t BigNumExpMod(const Uint8Buff *base, const Uint8Buff *exp, const c
|
||||
LOGE("malloc bigNumBlob.data failed.");
|
||||
return HAL_ERR_BAD_ALLOC;
|
||||
}
|
||||
ret = HexStringToByte(bigNumHex, bigNumBlob.data, bigNumBlob.size);
|
||||
if (ret != HAL_SUCCESS) {
|
||||
res = HexStringToByte(bigNumHex, bigNumBlob.data, bigNumBlob.size);
|
||||
if (res != HAL_SUCCESS) {
|
||||
LOGE("HexStringToByte for bigNumHex failed.");
|
||||
HcFree(bigNumBlob.data);
|
||||
return ret;
|
||||
return res;
|
||||
}
|
||||
|
||||
ret = HksBnExpMod(&outNumBlob, &baseBlob, &expBlob, &bigNumBlob);
|
||||
if (ret != HKS_SUCCESS) {
|
||||
LOGE("Huks calculate big number exp mod failed, ret = %d", ret);
|
||||
res = HksBnExpMod(&outNumBlob, &baseBlob, &expBlob, &bigNumBlob);
|
||||
if (res != HKS_SUCCESS) {
|
||||
LOGE("Huks calculate big number exp mod failed, res = %d", res);
|
||||
HcFree(bigNumBlob.data);
|
||||
return HAL_FAILED;
|
||||
}
|
||||
@@ -754,12 +764,12 @@ static int32_t ConstructGenerateKeyPairWithStorageParams(struct HksParamSet **pa
|
||||
}
|
||||
};
|
||||
|
||||
int32_t ret = ConstructParamSet(paramSet, keyParam, CAL_ARRAY_SIZE(keyParam));
|
||||
if (ret != HAL_SUCCESS) {
|
||||
LOGE("Construct param set failed, ret = %d", ret);
|
||||
return ret;
|
||||
int32_t res = ConstructParamSet(paramSet, keyParam, CAL_ARRAY_SIZE(keyParam));
|
||||
if (res != HAL_SUCCESS) {
|
||||
LOGE("Construct param set failed, res = %d", res);
|
||||
return res;
|
||||
}
|
||||
return ret;
|
||||
return res;
|
||||
}
|
||||
|
||||
static int32_t GenerateKeyPairWithStorage(const Uint8Buff *keyAlias, uint32_t keyLen, Algorithm algo,
|
||||
@@ -776,14 +786,16 @@ static int32_t GenerateKeyPairWithStorage(const Uint8Buff *keyAlias, uint32_t ke
|
||||
struct HksBlob keyAliasBlob = { keyAlias->length, keyAlias->val };
|
||||
struct HksBlob authIdBlob = { exInfo->authId.length, exInfo->authId.val };
|
||||
struct HksParamSet *paramSet = NULL;
|
||||
int32_t ret = ConstructGenerateKeyPairWithStorageParams(¶mSet, algo, keyLen, purpose, &authIdBlob);
|
||||
if (ret != HAL_SUCCESS) {
|
||||
return ret;
|
||||
int32_t res = ConstructGenerateKeyPairWithStorageParams(¶mSet, algo, keyLen, purpose, &authIdBlob);
|
||||
if (res != HAL_SUCCESS) {
|
||||
return res;
|
||||
}
|
||||
|
||||
ret = HksGenerateKey(&keyAliasBlob, paramSet, NULL);
|
||||
if (ret != HKS_SUCCESS) {
|
||||
LOGE("Hks generate failed, ret=%d", ret);
|
||||
LOGI("[HUKS]: HksGenerateKey enter.");
|
||||
res = HksGenerateKey(&keyAliasBlob, paramSet, NULL);
|
||||
LOGI("[HUKS]: HksGenerateKey quit. [Res]: %d", res);
|
||||
if (res != HKS_SUCCESS) {
|
||||
LOGE("[HUKS]: HksGenerateKey fail. [Res]: %d", res);
|
||||
HksFreeParamSet(¶mSet);
|
||||
return HAL_FAILED;
|
||||
}
|
||||
@@ -794,23 +806,23 @@ static int32_t GenerateKeyPairWithStorage(const Uint8Buff *keyAlias, uint32_t ke
|
||||
|
||||
static int32_t GetKeyPair(struct HksParamSet *outParamSet, Uint8Buff *outPriKey, Uint8Buff *outPubKey)
|
||||
{
|
||||
int32_t ret = HksFreshParamSet(outParamSet, false); /* false means fresh by local, not through IPC */
|
||||
if (ret != HKS_SUCCESS) {
|
||||
LOGE("fresh param set failed, ret:%d", ret);
|
||||
int32_t res = HksFreshParamSet(outParamSet, false); /* false means fresh by local, not through IPC */
|
||||
if (res != HKS_SUCCESS) {
|
||||
LOGE("fresh param set failed, res:%d", res);
|
||||
return HAL_ERR_FRESH_PARAM_SET_FAILED;
|
||||
}
|
||||
|
||||
struct HksParam *pubKeyParam = NULL;
|
||||
ret = HksGetParam(outParamSet, HKS_TAG_ASYMMETRIC_PUBLIC_KEY_DATA, &pubKeyParam);
|
||||
if (ret != HKS_SUCCESS) {
|
||||
LOGE("get pub key from param set failed, ret:%d", ret);
|
||||
res = HksGetParam(outParamSet, HKS_TAG_ASYMMETRIC_PUBLIC_KEY_DATA, &pubKeyParam);
|
||||
if (res != HKS_SUCCESS) {
|
||||
LOGE("get pub key from param set failed, res:%d", res);
|
||||
return HAL_ERR_GET_PARAM_FAILED;
|
||||
}
|
||||
|
||||
struct HksParam *priKeyParam = NULL;
|
||||
ret = HksGetParam(outParamSet, HKS_TAG_ASYMMETRIC_PRIVATE_KEY_DATA, &priKeyParam);
|
||||
if (ret != HKS_SUCCESS) {
|
||||
LOGE("get priv key from param set failed, ret:%d", ret);
|
||||
res = HksGetParam(outParamSet, HKS_TAG_ASYMMETRIC_PRIVATE_KEY_DATA, &priKeyParam);
|
||||
if (res != HKS_SUCCESS) {
|
||||
LOGE("get priv key from param set failed, res:%d", res);
|
||||
return HAL_ERR_GET_PARAM_FAILED;
|
||||
}
|
||||
|
||||
@@ -847,12 +859,12 @@ static int32_t ConstructGenerateKeyPairParams(struct HksParamSet **paramSet, Alg
|
||||
}
|
||||
};
|
||||
|
||||
int32_t ret = ConstructParamSet(paramSet, keyParam, CAL_ARRAY_SIZE(keyParam));
|
||||
if (ret != HAL_SUCCESS) {
|
||||
LOGE("Construct param set failed, ret = %d", ret);
|
||||
return ret;
|
||||
int32_t res = ConstructParamSet(paramSet, keyParam, CAL_ARRAY_SIZE(keyParam));
|
||||
if (res != HAL_SUCCESS) {
|
||||
LOGE("Construct param set failed, res = %d", res);
|
||||
return res;
|
||||
}
|
||||
return ret;
|
||||
return res;
|
||||
}
|
||||
|
||||
static int32_t GenerateKeyPair(Algorithm algo, Uint8Buff *outPriKey, Uint8Buff *outPubKey)
|
||||
@@ -872,9 +884,9 @@ static int32_t GenerateKeyPair(Algorithm algo, Uint8Buff *outPriKey, Uint8Buff *
|
||||
|
||||
struct HksParamSet *paramSet = NULL;
|
||||
struct HksParamSet *outParamSet = NULL;
|
||||
int32_t ret = ConstructGenerateKeyPairParams(¶mSet, algo, keyLen);
|
||||
if (ret != HAL_SUCCESS) {
|
||||
return ret;
|
||||
int32_t res = ConstructGenerateKeyPairParams(¶mSet, algo, keyLen);
|
||||
if (res != HAL_SUCCESS) {
|
||||
return res;
|
||||
}
|
||||
|
||||
/* need 2 HksParam struct for outPriKey and outPubKey */
|
||||
@@ -883,27 +895,29 @@ static int32_t GenerateKeyPair(Algorithm algo, Uint8Buff *outPriKey, Uint8Buff *
|
||||
outParamSet = (struct HksParamSet *)HcMalloc(outParamSetSize, 0);
|
||||
if (outParamSet == NULL) {
|
||||
LOGE("allocate buffer for output param set failed");
|
||||
ret = HAL_ERR_BAD_ALLOC;
|
||||
res = HAL_ERR_BAD_ALLOC;
|
||||
goto ERR;
|
||||
}
|
||||
outParamSet->paramSetSize = outParamSetSize;
|
||||
|
||||
ret = HksGenerateKey(NULL, paramSet, outParamSet);
|
||||
if (ret != HKS_SUCCESS) {
|
||||
LOGE("generate x25519 key failed, ret:%d", ret);
|
||||
ret = HAL_FAILED;
|
||||
LOGI("[HUKS]: HksGenerateKey enter.");
|
||||
res = HksGenerateKey(NULL, paramSet, outParamSet);
|
||||
LOGI("[HUKS]: HksGenerateKey quit. [Res]: %d", res);
|
||||
if (res != HKS_SUCCESS) {
|
||||
LOGI("[HUKS]: HksGenerateKey quit. [Res]: %d", res);
|
||||
res = HAL_FAILED;
|
||||
goto ERR;
|
||||
}
|
||||
|
||||
ret = GetKeyPair(outParamSet, outPriKey, outPubKey);
|
||||
if (ret != HAL_SUCCESS) {
|
||||
LOGE("parse x25519 output param set failed, ret:%d", ret);
|
||||
res = GetKeyPair(outParamSet, outPriKey, outPubKey);
|
||||
if (res != HAL_SUCCESS) {
|
||||
LOGE("parse x25519 output param set failed, res:%d", res);
|
||||
goto ERR;
|
||||
}
|
||||
ERR:
|
||||
HksFreeParamSet(¶mSet);
|
||||
HcFree(outParamSet);
|
||||
return ret;
|
||||
return res;
|
||||
}
|
||||
|
||||
static int32_t ExportPublicKey(const Uint8Buff *keyAlias, Uint8Buff *outPubKey)
|
||||
@@ -918,9 +932,11 @@ static int32_t ExportPublicKey(const Uint8Buff *keyAlias, Uint8Buff *outPubKey)
|
||||
struct HksBlob keyAliasBlob = { keyAlias->length, keyAlias->val };
|
||||
struct HksBlob keyBlob = { outPubKey->length, outPubKey->val };
|
||||
|
||||
int32_t ret = HksExportPublicKey(&keyAliasBlob, NULL, &keyBlob);
|
||||
if (ret != HKS_SUCCESS) {
|
||||
LOGE("Export public key failed, ret=%d", ret);
|
||||
LOGI("[HUKS]: HksExportPublicKey enter.");
|
||||
int32_t res = HksExportPublicKey(&keyAliasBlob, NULL, &keyBlob);
|
||||
LOGI("[HUKS]: HksExportPublicKey quit. [Res]: %d", res);
|
||||
if (res != HKS_SUCCESS) {
|
||||
LOGE("[HUKS]: HksExportPublicKey failed. [Res]: %d", res);
|
||||
return HAL_FAILED;
|
||||
}
|
||||
outPubKey->length = keyBlob.size;
|
||||
@@ -943,12 +959,12 @@ static int32_t ConstructSignParams(struct HksParamSet **paramSet, Algorithm algo
|
||||
}
|
||||
};
|
||||
|
||||
int32_t ret = ConstructParamSet(paramSet, signParam, CAL_ARRAY_SIZE(signParam));
|
||||
if (ret != HAL_SUCCESS) {
|
||||
LOGE("Construct param set failed, ret = %d", ret);
|
||||
return ret;
|
||||
int32_t res = ConstructParamSet(paramSet, signParam, CAL_ARRAY_SIZE(signParam));
|
||||
if (res != HAL_SUCCESS) {
|
||||
LOGE("Construct param set failed, res = %d", res);
|
||||
return res;
|
||||
}
|
||||
return ret;
|
||||
return res;
|
||||
}
|
||||
|
||||
static int32_t Sign(const Uint8Buff *keyAlias, const Uint8Buff *message, Algorithm algo,
|
||||
@@ -957,9 +973,9 @@ static int32_t Sign(const Uint8Buff *keyAlias, const Uint8Buff *message, Algorit
|
||||
struct HksParamSet *paramSet = NULL;
|
||||
const Uint8Buff *inParams[] = { keyAlias, message, outSignature };
|
||||
const char *paramTags[] = { "keyAlias", "message", "outSignature" };
|
||||
int32_t ret = BaseCheckParams(inParams, paramTags, CAL_ARRAY_SIZE(inParams));
|
||||
if (ret != HAL_SUCCESS) {
|
||||
return ret;
|
||||
int32_t res = BaseCheckParams(inParams, paramTags, CAL_ARRAY_SIZE(inParams));
|
||||
if (res != HAL_SUCCESS) {
|
||||
return res;
|
||||
}
|
||||
|
||||
struct HksBlob keyAliasBlob = { keyAlias->length, keyAlias->val };
|
||||
@@ -968,34 +984,36 @@ static int32_t Sign(const Uint8Buff *keyAlias, const Uint8Buff *message, Algorit
|
||||
messageHash.val = (uint8_t *)HcMalloc(messageHash.length, 0);
|
||||
if (messageHash.val == NULL) {
|
||||
LOGE("malloc messageHash.data failed.");
|
||||
ret = HAL_ERR_BAD_ALLOC;
|
||||
res = HAL_ERR_BAD_ALLOC;
|
||||
goto ERR;
|
||||
}
|
||||
ret = Sha256(message, &messageHash);
|
||||
if (ret != HAL_SUCCESS) {
|
||||
res = Sha256(message, &messageHash);
|
||||
if (res != HAL_SUCCESS) {
|
||||
LOGE("Sha256 failed.");
|
||||
goto ERR;
|
||||
}
|
||||
struct HksBlob messageBlob = { messageHash.length, messageHash.val };
|
||||
struct HksBlob signatureBlob = { outSignature->length, outSignature->val };
|
||||
|
||||
ret = ConstructSignParams(¶mSet, algo);
|
||||
if (ret != HAL_SUCCESS) {
|
||||
res = ConstructSignParams(¶mSet, algo);
|
||||
if (res != HAL_SUCCESS) {
|
||||
goto ERR;
|
||||
}
|
||||
|
||||
ret = HksSign(&keyAliasBlob, paramSet, &messageBlob, &signatureBlob);
|
||||
if (ret != HKS_SUCCESS) {
|
||||
LOGE("Hks sign failed, ret:%d", ret);
|
||||
ret = HAL_FAILED;
|
||||
LOGI("[HUKS]: HksSign enter.");
|
||||
res = HksSign(&keyAliasBlob, paramSet, &messageBlob, &signatureBlob);
|
||||
LOGI("[HUKS]: HksSign quit. [Res]: %d", res);
|
||||
if (res != HKS_SUCCESS) {
|
||||
LOGE("[HUKS]: HksSign fail. [Res]: %d", res);
|
||||
res = HAL_FAILED;
|
||||
goto ERR;
|
||||
}
|
||||
outSignature->length = signatureBlob.size;
|
||||
ret = HAL_SUCCESS;
|
||||
res = HAL_SUCCESS;
|
||||
ERR:
|
||||
HksFreeParamSet(¶mSet);
|
||||
HcFree(messageHash.val);
|
||||
return ret;
|
||||
return res;
|
||||
}
|
||||
|
||||
static int32_t ConstructVerifyParams(struct HksParamSet **paramSet, Algorithm algo, bool isAlias)
|
||||
@@ -1016,12 +1034,12 @@ static int32_t ConstructVerifyParams(struct HksParamSet **paramSet, Algorithm al
|
||||
}
|
||||
};
|
||||
|
||||
int32_t ret = ConstructParamSet(paramSet, verifyParam, CAL_ARRAY_SIZE(verifyParam));
|
||||
if (ret != HAL_SUCCESS) {
|
||||
LOGE("Construct param set failed, ret = %d", ret);
|
||||
return ret;
|
||||
int32_t res = ConstructParamSet(paramSet, verifyParam, CAL_ARRAY_SIZE(verifyParam));
|
||||
if (res != HAL_SUCCESS) {
|
||||
LOGE("Construct param set failed, res = %d", res);
|
||||
return res;
|
||||
}
|
||||
return ret;
|
||||
return res;
|
||||
}
|
||||
|
||||
static int32_t Verify(const Uint8Buff *key, const Uint8Buff *message, Algorithm algo,
|
||||
@@ -1030,9 +1048,9 @@ static int32_t Verify(const Uint8Buff *key, const Uint8Buff *message, Algorithm
|
||||
struct HksParamSet *paramSet = NULL;
|
||||
const Uint8Buff *inParams[] = { key, message, signature };
|
||||
const char *paramTags[] = { "key", "message", "signature" };
|
||||
int32_t ret = BaseCheckParams(inParams, paramTags, CAL_ARRAY_SIZE(inParams));
|
||||
if (ret != HAL_SUCCESS) {
|
||||
return ret;
|
||||
int32_t res = BaseCheckParams(inParams, paramTags, CAL_ARRAY_SIZE(inParams));
|
||||
if (res != HAL_SUCCESS) {
|
||||
return res;
|
||||
}
|
||||
|
||||
struct HksBlob keyAliasBlob = { key->length, key->val };
|
||||
@@ -1041,33 +1059,35 @@ static int32_t Verify(const Uint8Buff *key, const Uint8Buff *message, Algorithm
|
||||
messageHash.val = (uint8_t *)HcMalloc(messageHash.length, 0);
|
||||
if (messageHash.val == NULL) {
|
||||
LOGE("malloc messageHash.data failed.");
|
||||
ret = HAL_ERR_BAD_ALLOC;
|
||||
res = HAL_ERR_BAD_ALLOC;
|
||||
goto ERR;
|
||||
}
|
||||
ret = Sha256(message, &messageHash);
|
||||
if (ret != HAL_SUCCESS) {
|
||||
res = Sha256(message, &messageHash);
|
||||
if (res != HAL_SUCCESS) {
|
||||
LOGE("Sha256 failed.");
|
||||
goto ERR;
|
||||
}
|
||||
struct HksBlob messageBlob = { messageHash.length, messageHash.val };
|
||||
struct HksBlob signatureBlob = { signature->length, signature->val };
|
||||
|
||||
ret = ConstructVerifyParams(¶mSet, algo, isAlias);
|
||||
if (ret != HAL_SUCCESS) {
|
||||
res = ConstructVerifyParams(¶mSet, algo, isAlias);
|
||||
if (res != HAL_SUCCESS) {
|
||||
goto ERR;
|
||||
}
|
||||
|
||||
ret = HksVerify(&keyAliasBlob, paramSet, &messageBlob, &signatureBlob);
|
||||
if ((ret != HKS_SUCCESS)) {
|
||||
LOGE("HksVerify failed, ret: %d", ret);
|
||||
ret = HAL_FAILED;
|
||||
LOGI("[HUKS]: HksVerify enter.");
|
||||
res = HksVerify(&keyAliasBlob, paramSet, &messageBlob, &signatureBlob);
|
||||
LOGI("[HUKS]: HksVerify quit. [Res]: %d", res);
|
||||
if ((res != HKS_SUCCESS)) {
|
||||
LOGE("[HUKS]: HksVerify fail. [Res]: %d", res);
|
||||
res = HAL_FAILED;
|
||||
goto ERR;
|
||||
}
|
||||
ret = HAL_SUCCESS;
|
||||
res = HAL_SUCCESS;
|
||||
ERR:
|
||||
HksFreeParamSet(¶mSet);
|
||||
HcFree(messageHash.val);
|
||||
return ret;
|
||||
return res;
|
||||
}
|
||||
|
||||
static int32_t ConstructImportPublicKeyParams(struct HksParamSet **paramSet, Algorithm algo, uint32_t keyLen,
|
||||
@@ -1104,12 +1124,12 @@ static int32_t ConstructImportPublicKeyParams(struct HksParamSet **paramSet, Alg
|
||||
}
|
||||
};
|
||||
|
||||
int32_t ret = ConstructParamSet(paramSet, importParam, CAL_ARRAY_SIZE(importParam));
|
||||
if (ret != HAL_SUCCESS) {
|
||||
LOGE("Construct param set failed, ret = %d", ret);
|
||||
return ret;
|
||||
int32_t res = ConstructParamSet(paramSet, importParam, CAL_ARRAY_SIZE(importParam));
|
||||
if (res != HAL_SUCCESS) {
|
||||
LOGE("Construct param set failed, res = %d", res);
|
||||
return res;
|
||||
}
|
||||
return ret;
|
||||
return res;
|
||||
}
|
||||
|
||||
static int32_t ImportPublicKey(const Uint8Buff *keyAlias, const Uint8Buff *pubKey, Algorithm algo,
|
||||
@@ -1138,14 +1158,16 @@ static int32_t ImportPublicKey(const Uint8Buff *keyAlias, const Uint8Buff *pubKe
|
||||
|
||||
struct HksParamSet *paramSet = NULL;
|
||||
|
||||
int32_t ret = ConstructImportPublicKeyParams(¶mSet, algo, pubKey->length, &authIdBlob, &roleInfoUnion);
|
||||
if (ret != HAL_SUCCESS) {
|
||||
return ret;
|
||||
int32_t res = ConstructImportPublicKeyParams(¶mSet, algo, pubKey->length, &authIdBlob, &roleInfoUnion);
|
||||
if (res != HAL_SUCCESS) {
|
||||
return res;
|
||||
}
|
||||
|
||||
ret = HksImportKey(&keyAliasBlob, paramSet, &pubKeyBlob);
|
||||
if (ret != HKS_SUCCESS) {
|
||||
LOGE("Hks importKey failed, ret: %d", ret);
|
||||
LOGI("[HUKS]: HksImportKey enter.");
|
||||
res = HksImportKey(&keyAliasBlob, paramSet, &pubKeyBlob);
|
||||
LOGI("[HUKS]: HksImportKey quit. [Res]: %d", res);
|
||||
if (res != HKS_SUCCESS) {
|
||||
LOGE("[HUKS]: HksImportKey fail. [Res]: %d", res);
|
||||
HksFreeParamSet(¶mSet);
|
||||
return HAL_FAILED;
|
||||
}
|
||||
@@ -1321,37 +1343,39 @@ static int32_t ConstructImportSymmetricKeyParam(struct HksParamSet **paramSet, u
|
||||
importParam[idx].tag = HKS_TAG_DIGEST;
|
||||
importParam[idx++].uint32Param = HKS_DIGEST_SHA256;
|
||||
|
||||
int ret = ConstructParamSet(paramSet, importParam, idx);
|
||||
if (ret != HAL_SUCCESS) {
|
||||
LOGE("Construct decrypt param set failed, ret = %d.", ret);
|
||||
int res = ConstructParamSet(paramSet, importParam, idx);
|
||||
if (res != HAL_SUCCESS) {
|
||||
LOGE("Construct decrypt param set failed, res = %d.", res);
|
||||
}
|
||||
|
||||
HcFree(importParam);
|
||||
return ret;
|
||||
return res;
|
||||
}
|
||||
|
||||
static int32_t ImportSymmetricKey(const Uint8Buff *keyAlias, const Uint8Buff *authToken, KeyPurpose purpose,
|
||||
const ExtraInfo *exInfo)
|
||||
{
|
||||
int32_t ret = CheckImportSymmetricKeyParam(keyAlias, authToken);
|
||||
if (ret != HAL_SUCCESS) {
|
||||
return ret;
|
||||
int32_t res = CheckImportSymmetricKeyParam(keyAlias, authToken);
|
||||
if (res != HAL_SUCCESS) {
|
||||
return res;
|
||||
}
|
||||
|
||||
struct HksBlob keyAliasBlob = { keyAlias->length, keyAlias->val };
|
||||
struct HksBlob symKeyBlob = { authToken->length, authToken->val };
|
||||
struct HksParamSet *paramSet = NULL;
|
||||
ret = ConstructImportSymmetricKeyParam(¶mSet, authToken->length, purpose, exInfo);
|
||||
if (ret != HAL_SUCCESS) {
|
||||
LOGE("construct param set failed, ret = %d", ret);
|
||||
return ret;
|
||||
res = ConstructImportSymmetricKeyParam(¶mSet, authToken->length, purpose, exInfo);
|
||||
if (res != HAL_SUCCESS) {
|
||||
LOGE("construct param set failed, res = %d", res);
|
||||
return res;
|
||||
}
|
||||
|
||||
ret = HksImportKey(&keyAliasBlob, paramSet, &symKeyBlob);
|
||||
if (ret != HKS_SUCCESS) {
|
||||
LOGE("HksImportKey failed, ret: %d", ret);
|
||||
LOGI("[HUKS]: HksImportKey enter.");
|
||||
res = HksImportKey(&keyAliasBlob, paramSet, &symKeyBlob);
|
||||
LOGI("[HUKS]: HksImportKey quit. [Res]: %d", res);
|
||||
if (res != HKS_SUCCESS) {
|
||||
LOGE("[HUKS]: HksImportKey fail. [Res]: %d", res);
|
||||
HksFreeParamSet(¶mSet);
|
||||
return ret;
|
||||
return res;
|
||||
}
|
||||
|
||||
HksFreeParamSet(¶mSet);
|
||||
|
||||
@@ -15,6 +15,8 @@
|
||||
|
||||
#include "hc_mutex.h"
|
||||
|
||||
#include "hc_log.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
@@ -24,7 +26,11 @@ static int HcMutexLock(HcMutex *mutex)
|
||||
if (mutex == NULL) {
|
||||
return -1;
|
||||
}
|
||||
return -pthread_mutex_lock(&mutex->mutex);
|
||||
int res = pthread_mutex_lock(&mutex->mutex);
|
||||
if (res != 0) {
|
||||
LOGW("[OS]: pthread_mutex_lock fail. [Res]: %d");
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
static void HcMutexUnlock(HcMutex *mutex)
|
||||
@@ -32,7 +38,10 @@ static void HcMutexUnlock(HcMutex *mutex)
|
||||
if (mutex == NULL) {
|
||||
return;
|
||||
}
|
||||
pthread_mutex_unlock(&mutex->mutex);
|
||||
int res = pthread_mutex_unlock(&mutex->mutex);
|
||||
if (res != 0) {
|
||||
LOGW("[OS]: pthread_mutex_unlock fail. [Res]: %d");
|
||||
}
|
||||
}
|
||||
|
||||
int32_t InitHcMutex(struct HcMutexT *mutex)
|
||||
@@ -40,8 +49,11 @@ int32_t InitHcMutex(struct HcMutexT *mutex)
|
||||
if (mutex == NULL) {
|
||||
return -1;
|
||||
}
|
||||
LOGI("[OS]: pthread_mutex_init enter.");
|
||||
int res = pthread_mutex_init(&mutex->mutex, NULL);
|
||||
LOGI("[OS]: pthread_mutex_init quit. [Res]: %d");
|
||||
if (res != 0) {
|
||||
LOGE("[OS]: pthread_mutex_init fail. [Res]: %d", res);
|
||||
return res;
|
||||
}
|
||||
mutex->lock = HcMutexLock;
|
||||
@@ -54,7 +66,12 @@ void DestroyHcMutex(struct HcMutexT *mutex)
|
||||
if (mutex == NULL) {
|
||||
return;
|
||||
}
|
||||
pthread_mutex_destroy(&mutex->mutex);
|
||||
LOGI("[OS]: pthread_mutex_destroy enter.");
|
||||
int res = pthread_mutex_destroy(&mutex->mutex);
|
||||
LOGI("[OS]: pthread_mutex_destroy quit. [Res]: %d", res);
|
||||
if (res != 0) {
|
||||
LOGW("[OS]: pthread_mutex_destroy fail. [Res]: %d", res);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
@@ -27,7 +27,7 @@ int64_t HcGetCurTime(void)
|
||||
struct timespec start;
|
||||
int res = clock_gettime(CLOCK_MONOTONIC, &start);
|
||||
if (res != 0) {
|
||||
LOGE("clock_gettime failed, res:%d", res);
|
||||
LOGE("[TIMER]: clock_gettime fail. [Res] :%d", res);
|
||||
return -1;
|
||||
}
|
||||
return start.tv_sec;
|
||||
@@ -42,7 +42,7 @@ int64_t HcGetIntervalTime(int64_t startTime)
|
||||
struct timespec end;
|
||||
int res = clock_gettime(CLOCK_MONOTONIC, &end);
|
||||
if (res != 0) {
|
||||
LOGE("clock_gettime failed, res:%d", res);
|
||||
LOGE("[TIMER]: clock_gettime fail. [Res] :%d", res);
|
||||
return -1;
|
||||
}
|
||||
if (end.tv_sec < startTime) {
|
||||
|
||||
@@ -15,6 +15,8 @@
|
||||
|
||||
#include "hc_condition.h"
|
||||
|
||||
#include "hc_log.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
@@ -24,7 +26,11 @@ int Wait(pthread_cond_t* cond, HcMutex* mutex)
|
||||
if (cond == NULL || mutex == NULL) {
|
||||
return -1;
|
||||
}
|
||||
return -pthread_cond_wait(cond, &mutex->mutex);
|
||||
int res = pthread_cond_wait(cond, &mutex->mutex);
|
||||
if (res != 0) {
|
||||
LOGE("[OS]: pthread_cond_wait fail. [Res]: %d", res);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
void Notify(pthread_cond_t* cond)
|
||||
@@ -32,7 +38,10 @@ void Notify(pthread_cond_t* cond)
|
||||
if (cond == NULL) {
|
||||
return;
|
||||
}
|
||||
pthread_cond_signal(cond);
|
||||
int res = pthread_cond_signal(cond);
|
||||
if (res != 0) {
|
||||
LOGW("[OS]: pthread_cond_wait fail. [Res]: %d", res);
|
||||
}
|
||||
}
|
||||
|
||||
int HcCondWaitWithoutLock(struct HcConditionT* hcCond)
|
||||
@@ -123,8 +132,14 @@ int32_t InitHcCond(HcCondition* hcCond, HcMutex* mutex)
|
||||
|
||||
pthread_condattr_t attr;
|
||||
pthread_condattr_init(&attr);
|
||||
pthread_cond_init(&hcCond->cond, &attr);
|
||||
LOGI("[OS]: pthread_cond_init enter.");
|
||||
int res = pthread_cond_init(&hcCond->cond, &attr);
|
||||
LOGI("[OS]: pthread_cond_init quit. [Res]: %d", res);
|
||||
pthread_condattr_destroy(&attr);
|
||||
if (res != 0) {
|
||||
LOGE("[OS]: pthread_cond_init fail. [Res]: %d", res);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (mutex != NULL) {
|
||||
hcCond->mutex = mutex;
|
||||
@@ -132,7 +147,7 @@ int32_t InitHcCond(HcCondition* hcCond, HcMutex* mutex)
|
||||
} else {
|
||||
hcCond->mutex = (HcMutex*)HcMalloc(sizeof(HcMutex), 0);
|
||||
if (hcCond->mutex != NULL) {
|
||||
int32_t res = InitHcMutex(hcCond->mutex);
|
||||
res = InitHcMutex(hcCond->mutex);
|
||||
if (res != 0) {
|
||||
HcFree(hcCond->mutex);
|
||||
hcCond->mutex = NULL;
|
||||
@@ -157,7 +172,10 @@ void DestroyHcCond(HcCondition* hcCond)
|
||||
HcFree(hcCond->mutex);
|
||||
hcCond->mutex = NULL;
|
||||
}
|
||||
pthread_cond_destroy(&hcCond->cond);
|
||||
int res = pthread_cond_destroy(&hcCond->cond);
|
||||
if (res != 0) {
|
||||
LOGW("[OS]: pthread_cond_destroy fail. [Res]: %d", res);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
@@ -28,9 +28,11 @@ int32_t HcGetUdid(uint8_t *udid, int32_t udidLen)
|
||||
if (udid == NULL || udidLen < INPUT_UDID_LEN || udidLen > MAX_INPUT_UDID_LEN) {
|
||||
return HAL_ERR_INVALID_PARAM;
|
||||
}
|
||||
LOGI("[UDID]: GetDevUdid enter.");
|
||||
int32_t res = GetDevUdid((char *)udid, udidLen);
|
||||
LOGI("[UDID]: GetDevUdid quit. [Res]: %d", res);
|
||||
if (res != 0) {
|
||||
LOGE("[OS]: GetDevUdid fail! res: %d", res);
|
||||
LOGE("[UDID]: GetDevUdid fail. [Res]: %d", res);
|
||||
return HAL_FAILED;
|
||||
}
|
||||
return HAL_SUCCESS;
|
||||
@@ -43,7 +45,6 @@ const char *GetStoragePath(void)
|
||||
#else
|
||||
const char *storageFile = "/storage/deviceauth/hcgroup.dat";
|
||||
#endif
|
||||
LOGI("[OS]: storageFile: %s", storageFile);
|
||||
return storageFile;
|
||||
}
|
||||
|
||||
@@ -54,7 +55,6 @@ const char *GetStorageDirPath(void)
|
||||
#else
|
||||
const char *storageFile = "/storage/deviceauth";
|
||||
#endif
|
||||
LOGI("[OS]: storageDirFile: %s", storageFile);
|
||||
return storageFile;
|
||||
}
|
||||
|
||||
@@ -65,7 +65,6 @@ const char *GetAccountStoragePath(void)
|
||||
#else
|
||||
const char *storageFile = "/storage/deviceauth/account";
|
||||
#endif
|
||||
LOGI("[OS]: Account storage dir: %s", storageFile);
|
||||
return storageFile;
|
||||
}
|
||||
|
||||
|
||||
@@ -31,8 +31,7 @@ extern "C" {
|
||||
|
||||
static int32_t CreateDirectory(const char *filePath)
|
||||
{
|
||||
int32_t ret;
|
||||
errno_t eno;
|
||||
int32_t res;
|
||||
char *chPtr = NULL;
|
||||
char dirCache[MAX_FOLDER_NAME_SIZE];
|
||||
|
||||
@@ -43,16 +42,15 @@ static int32_t CreateDirectory(const char *filePath)
|
||||
chPtr++;
|
||||
continue;
|
||||
}
|
||||
eno = memcpy_s(dirCache, sizeof(dirCache), filePath, len);
|
||||
if (eno != EOK) {
|
||||
if (memcpy_s(dirCache, sizeof(dirCache), filePath, len) != EOK) {
|
||||
LOGE("memory copy failed");
|
||||
return -1;
|
||||
}
|
||||
dirCache[len] = 0;
|
||||
if (access(dirCache, F_OK) != 0) {
|
||||
ret = mkdir(dirCache, S_IRWXU);
|
||||
if (ret != 0) {
|
||||
LOGE("make dir failed, err code %d", ret);
|
||||
res = mkdir(dirCache, S_IRWXU);
|
||||
if (res != 0) {
|
||||
LOGE("[OS]: mkdir fail. [Res]: %d, [errno]: %d", res, errno);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
@@ -120,6 +118,7 @@ int HcFileRead(FileHandle file, void *dst, int dstSize)
|
||||
|
||||
char *dstBuffer = (char *)dst;
|
||||
int total = 0;
|
||||
LOGI("[OS]: file read enter. [OriSize]: %d", dstSize);
|
||||
while (total < dstSize) {
|
||||
int readCount = fread(dstBuffer + total, 1, dstSize - total, fp);
|
||||
if (ferror(fp) != 0) {
|
||||
@@ -130,7 +129,7 @@ int HcFileRead(FileHandle file, void *dst, int dstSize)
|
||||
}
|
||||
total += readCount;
|
||||
}
|
||||
|
||||
LOGI("[OS]: file read quit. [ReadSize]: %d", total);
|
||||
return total;
|
||||
}
|
||||
|
||||
@@ -143,6 +142,7 @@ int HcFileWrite(FileHandle file, const void *src, int srcSize)
|
||||
|
||||
const char *srcBuffer = (const char *)src;
|
||||
int total = 0;
|
||||
LOGI("[OS]: file write enter. [OriSize]: %d", srcSize);
|
||||
while (total < srcSize) {
|
||||
int writeCount = fwrite(srcBuffer + total, 1, srcSize - total, fp);
|
||||
if (ferror(fp) != 0) {
|
||||
@@ -150,6 +150,7 @@ int HcFileWrite(FileHandle file, const void *src, int srcSize)
|
||||
}
|
||||
total += writeCount;
|
||||
}
|
||||
LOGI("[OS]: file write quit. [WriteSize]: %d", total);
|
||||
return total;
|
||||
}
|
||||
|
||||
|
||||
@@ -23,14 +23,17 @@ extern "C" {
|
||||
|
||||
#define MAX_THREAD_STACK_SIZE (8 * 1024 * 1024)
|
||||
|
||||
void* StaticThreadFunc(void* args)
|
||||
void *StaticThreadFunc(void *args)
|
||||
{
|
||||
HcThread* thread = (HcThread*)args;
|
||||
if (thread == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
(void)pthread_setname_np(pthread_self(), StringGet(&thread->name));
|
||||
int res = pthread_setname_np(pthread_self(), StringGet(&thread->name));
|
||||
if (res != 0) {
|
||||
LOGW("[OS]: pthread_setname_np fail. [Res]: %d", res);
|
||||
}
|
||||
|
||||
if (thread->threadFunc) {
|
||||
thread->threadFunc(args);
|
||||
@@ -39,10 +42,10 @@ void* StaticThreadFunc(void* args)
|
||||
thread->running = HC_FALSE;
|
||||
thread->threadWaitObj.notifyWithoutLock(&thread->threadWaitObj);
|
||||
thread->threadLock.unlock(&thread->threadLock);
|
||||
return 0;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int Start(struct HcThreadT* thread)
|
||||
int Start(struct HcThreadT *thread)
|
||||
{
|
||||
if (thread == NULL) {
|
||||
return HAL_ERR_NULL_PTR;
|
||||
@@ -62,18 +65,19 @@ int Start(struct HcThreadT* thread)
|
||||
pthread_attr_setstacksize(&attr, thread->stackSize);
|
||||
}
|
||||
|
||||
int result = pthread_create(&thread->thread, &attr, StaticThreadFunc, thread);
|
||||
LOGI("[OS]: pthread_create enter.");
|
||||
int res = pthread_create(&thread->thread, &attr, StaticThreadFunc, thread);
|
||||
LOGI("[OS]: pthread_create quit. [Res]: %d", res);
|
||||
pthread_attr_destroy(&attr);
|
||||
|
||||
if (result != 0) {
|
||||
LOGE("pthread_create failed.");
|
||||
if (res != 0) {
|
||||
LOGE("[OS]: pthread_create fail. [Res]: %d", res);
|
||||
thread->running = HC_FALSE;
|
||||
}
|
||||
thread->threadLock.unlock(&thread->threadLock);
|
||||
return result;
|
||||
return res;
|
||||
}
|
||||
|
||||
void Join(struct HcThreadT* thread)
|
||||
void Join(struct HcThreadT *thread)
|
||||
{
|
||||
if (thread == NULL) {
|
||||
return;
|
||||
@@ -85,7 +89,7 @@ void Join(struct HcThreadT* thread)
|
||||
thread->threadLock.unlock(&thread->threadLock);
|
||||
}
|
||||
|
||||
void BizWait(struct HcThreadT* thread)
|
||||
void BizWait(struct HcThreadT *thread)
|
||||
{
|
||||
if (thread == NULL) {
|
||||
return;
|
||||
@@ -93,7 +97,7 @@ void BizWait(struct HcThreadT* thread)
|
||||
thread->bizWaitObj.wait(&thread->bizWaitObj);
|
||||
}
|
||||
|
||||
void BizNotify(struct HcThreadT* thread)
|
||||
void BizNotify(struct HcThreadT *thread)
|
||||
{
|
||||
if (thread == NULL) {
|
||||
return;
|
||||
@@ -101,7 +105,7 @@ void BizNotify(struct HcThreadT* thread)
|
||||
thread->bizWaitObj.notify(&thread->bizWaitObj);
|
||||
}
|
||||
|
||||
int32_t InitThread(HcThread* thread, ThreadFunc func, size_t stackSize, const char* threadName)
|
||||
int32_t InitThread(HcThread *thread, ThreadFunc func, size_t stackSize, const char *threadName)
|
||||
{
|
||||
if (thread == NULL) {
|
||||
return -1;
|
||||
@@ -139,7 +143,7 @@ int32_t InitThread(HcThread* thread, ThreadFunc func, size_t stackSize, const ch
|
||||
return res;
|
||||
}
|
||||
|
||||
void DestroyThread(HcThread* thread)
|
||||
void DestroyThread(HcThread *thread)
|
||||
{
|
||||
if (thread == NULL) {
|
||||
return;
|
||||
|
||||
@@ -28,9 +28,11 @@ void* HcMalloc(uint32_t size, char val)
|
||||
return NULL;
|
||||
}
|
||||
void* addr = malloc(size);
|
||||
if (addr != NULL) {
|
||||
(void)memset_s(addr, size, val, size);
|
||||
if (addr == NULL) {
|
||||
LOGE("[OS]: malloc fail. [Size]: %u", size);
|
||||
return NULL;
|
||||
}
|
||||
(void)memset_s(addr, size, val, size);
|
||||
return addr;
|
||||
}
|
||||
|
||||
|
||||
@@ -15,13 +15,19 @@
|
||||
|
||||
#include "hc_condition.h"
|
||||
|
||||
#include "hc_log.h"
|
||||
|
||||
int HcCondWait(struct HcConditionT* hcCond)
|
||||
{
|
||||
if (hcCond == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return sem_wait(&hcCond->sem);
|
||||
int res = sem_wait(&hcCond->sem);
|
||||
if (res != 0) {
|
||||
LOGE("[OS]: sem_wait fail. [Res]: %d", res);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
void HcCondNotify(struct HcConditionT* hcCond)
|
||||
@@ -30,7 +36,10 @@ void HcCondNotify(struct HcConditionT* hcCond)
|
||||
return;
|
||||
}
|
||||
|
||||
sem_post(&hcCond->sem);
|
||||
int res = sem_post(&hcCond->sem);
|
||||
if (res != 0) {
|
||||
LOGW("[OS]: sem_post fail. [Res]: %d", res);
|
||||
}
|
||||
}
|
||||
|
||||
int32_t InitHcCond(HcCondition* hcCond, HcMutex* mutex)
|
||||
@@ -45,7 +54,13 @@ int32_t InitHcCond(HcCondition* hcCond, HcMutex* mutex)
|
||||
hcCond->notifyWithoutLock = HcCondNotify;
|
||||
|
||||
// init the signal value to zero
|
||||
return sem_init(&hcCond->sem, 0, 0);
|
||||
LOGI("[OS]: sem_init enter.");
|
||||
int res = sem_init(&hcCond->sem, 0, 0);
|
||||
LOGI("[OS]: sem_init quit. [Res]: %d", res);
|
||||
if (res != 0) {
|
||||
LOGE("[OS]: sem_init fail. [Res]: %d", res);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
void DestroyHcCond(HcCondition* hcCond)
|
||||
@@ -54,5 +69,8 @@ void DestroyHcCond(HcCondition* hcCond)
|
||||
return;
|
||||
}
|
||||
|
||||
sem_destroy(&hcCond->sem);
|
||||
int res = sem_destroy(&hcCond->sem);
|
||||
if (res != 0) {
|
||||
LOGW("[OS]: sem_destroy fail. [Res]: %d", res);
|
||||
}
|
||||
}
|
||||
@@ -28,9 +28,11 @@ int32_t HcGetUdid(uint8_t *udid, int32_t udidLen)
|
||||
if (udid == NULL || udidLen < INPUT_UDID_LEN || udidLen > MAX_INPUT_UDID_LEN) {
|
||||
return HAL_ERR_INVALID_PARAM;
|
||||
}
|
||||
int32_t ret = GetDevUdid((char *)udid, udidLen);
|
||||
if (ret != 0) {
|
||||
LOGE("Failed to get dev udid, ret = %d", ret);
|
||||
LOGI("[UDID]: GetDevUdid enter.");
|
||||
int32_t res = GetDevUdid((char *)udid, udidLen);
|
||||
LOGI("[UDID]: GetDevUdid quit. [Res]: %d", res);
|
||||
if (res != 0) {
|
||||
LOGE("[UDID]: GetDevUdid fail. [Res]: %d", res);
|
||||
return HAL_FAILED;
|
||||
}
|
||||
return HAL_SUCCESS;
|
||||
|
||||
@@ -14,6 +14,8 @@
|
||||
*/
|
||||
|
||||
#include "hc_thread.h"
|
||||
#include "hal_error.h"
|
||||
#include "hc_log.h"
|
||||
|
||||
#define MAX_THREAD_STACK_SIZE (8 * 1024 * 1024)
|
||||
|
||||
@@ -24,7 +26,10 @@ void *StaticThreadFunc(void *args)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
(void)pthread_setname_np(pthread_self(), StringGet(&thread->name));
|
||||
int res = pthread_setname_np(pthread_self(), StringGet(&thread->name));
|
||||
if (res != 0) {
|
||||
LOGW("[OS]: pthread_setname_np fail. [Res]: %d", res);
|
||||
}
|
||||
|
||||
if (thread->threadFunc) {
|
||||
thread->threadFunc(args);
|
||||
@@ -39,7 +44,7 @@ void *StaticThreadFunc(void *args)
|
||||
int Start(struct HcThreadT *thread)
|
||||
{
|
||||
if (thread == NULL) {
|
||||
return -1;
|
||||
return HAL_ERR_NULL_PTR;
|
||||
}
|
||||
thread->threadLock.lock(&thread->threadLock);
|
||||
if (thread->running) {
|
||||
@@ -56,13 +61,16 @@ int Start(struct HcThreadT *thread)
|
||||
pthread_attr_setstacksize(&attr, thread->stackSize);
|
||||
}
|
||||
|
||||
int result = pthread_create(&thread->thread, &attr, StaticThreadFunc, thread);
|
||||
LOGI("[OS]: pthread_create enter.");
|
||||
int res = pthread_create(&thread->thread, &attr, StaticThreadFunc, thread);
|
||||
LOGI("[OS]: pthread_create quit. [Res]: %d", res);
|
||||
pthread_attr_destroy(&attr);
|
||||
if (result != 0) {
|
||||
if (res != 0) {
|
||||
LOGE("[OS]: pthread_create fail. [Res]: %d", res);
|
||||
thread->running = HC_FALSE;
|
||||
}
|
||||
thread->threadLock.unlock(&thread->threadLock);
|
||||
return result;
|
||||
return res;
|
||||
}
|
||||
|
||||
void Join(struct HcThreadT *thread)
|
||||
@@ -75,7 +83,12 @@ void Join(struct HcThreadT *thread)
|
||||
thread->threadWaitObj.waitWithoutLock(&thread->threadWaitObj);
|
||||
}
|
||||
void *status = NULL;
|
||||
pthread_join(thread->thread, &status);
|
||||
LOGI("[OS]: pthread_join enter.");
|
||||
int res = pthread_join(thread->thread, &status);
|
||||
LOGI("[OS]: pthread_join quit. [Res]: %d");
|
||||
if (res != 0) {
|
||||
LOGE("[OS]: pthread_join fail. [Res]: %d", res);
|
||||
}
|
||||
}
|
||||
|
||||
void BizWait(struct HcThreadT *thread)
|
||||
|
||||
@@ -30,9 +30,11 @@ void *HcMalloc(uint32_t size, char val)
|
||||
#else
|
||||
void *addr = malloc(size);
|
||||
#endif
|
||||
if (addr != NULL) {
|
||||
(void)memset_s(addr, size, val, size);
|
||||
if (addr == NULL) {
|
||||
LOGE("[OS]: malloc fail. [Size]: %u", size);
|
||||
return NULL;
|
||||
}
|
||||
(void)memset_s(addr, size, val, size);
|
||||
return addr;
|
||||
}
|
||||
|
||||
|
||||
@@ -28,8 +28,7 @@
|
||||
|
||||
static int32_t CreateDirectory(const char *filePath)
|
||||
{
|
||||
int32_t ret;
|
||||
errno_t eno;
|
||||
int32_t res;
|
||||
char *chPtr = NULL;
|
||||
char dirCache[MAX_FOLDER_NAME_SIZE];
|
||||
|
||||
@@ -40,8 +39,7 @@ static int32_t CreateDirectory(const char *filePath)
|
||||
chPtr++;
|
||||
continue;
|
||||
}
|
||||
eno = memcpy_s(dirCache, sizeof(dirCache), filePath, len);
|
||||
if (eno != EOK) {
|
||||
if (memcpy_s(dirCache, sizeof(dirCache), filePath, len) != EOK) {
|
||||
LOGE("memory copy failed");
|
||||
return -1;
|
||||
}
|
||||
@@ -52,9 +50,9 @@ static int32_t CreateDirectory(const char *filePath)
|
||||
}
|
||||
DIR *dir = opendir(dirCache);
|
||||
if (dir == NULL) {
|
||||
ret = mkdir(dirCache, DEFAULT_FILE_PERMISSION);
|
||||
if (ret != 0) {
|
||||
LOGE("make dir failed, err code %d, errno = %d", ret, errno);
|
||||
res = mkdir(dirCache, DEFAULT_FILE_PERMISSION);
|
||||
if (res != 0) {
|
||||
LOGE("[OS]: mkdir fail. [Res]: %d, [errno]: %d", res, errno);
|
||||
return -1;
|
||||
}
|
||||
} else {
|
||||
@@ -67,18 +65,29 @@ static int32_t CreateDirectory(const char *filePath)
|
||||
|
||||
static int HcFileOpenRead(const char *path)
|
||||
{
|
||||
return open(path, O_RDONLY);
|
||||
LOGI("[OS]: file open enter.");
|
||||
int res = open(path, O_RDONLY);
|
||||
LOGI("[OS]: file open quit.");
|
||||
if (res == -1) {
|
||||
LOGE("[OS]: file open fail. [Errno]: %d", errno);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
static int HcFileOpenWrite(const char *path)
|
||||
{
|
||||
if (access(path, F_OK) != 0) {
|
||||
int32_t ret = CreateDirectory(path);
|
||||
if (ret != 0) {
|
||||
if (CreateDirectory(path) != 0) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
return open(path, O_RDWR | O_CREAT | O_TRUNC);
|
||||
LOGI("[OS]: file open enter.");
|
||||
int res = open(path, O_RDWR | O_CREAT | O_TRUNC);
|
||||
LOGI("[OS]: file open quit.");
|
||||
if (res == -1) {
|
||||
LOGE("[OS]: file open fail. [Errno]: %d", errno);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
int HcFileOpen(const char *path, int mode, FileHandle *file)
|
||||
@@ -92,7 +101,6 @@ int HcFileOpen(const char *path, int mode, FileHandle *file)
|
||||
file->fileHandle.fd = HcFileOpenWrite(path);
|
||||
}
|
||||
if (file->fileHandle.fd == -1) {
|
||||
LOGE("[OS]: file open failed, errno = %d", errno);
|
||||
return -1;
|
||||
} else {
|
||||
return 0;
|
||||
@@ -116,10 +124,11 @@ int HcFileRead(FileHandle file, void *dst, int dstSize)
|
||||
|
||||
char *dstBuffer = (char *)dst;
|
||||
int total = 0;
|
||||
LOGI("[OS]: file read enter. [OriSize]: %d", dstSize);
|
||||
while (total < dstSize) {
|
||||
int readCount = read(fp, dstBuffer + total, dstSize - total);
|
||||
if (readCount < 0 || readCount > (dstSize - total)) {
|
||||
LOGE("read size error, errno = %d", errno);
|
||||
LOGE("[OS]: read size error. [Errno]: %d", errno);
|
||||
return -1;
|
||||
}
|
||||
if (readCount == 0) {
|
||||
@@ -128,7 +137,7 @@ int HcFileRead(FileHandle file, void *dst, int dstSize)
|
||||
}
|
||||
total += readCount;
|
||||
}
|
||||
|
||||
LOGI("[OS]: file read quit. [ReadSize]: %d", total);
|
||||
return total;
|
||||
}
|
||||
|
||||
@@ -141,14 +150,16 @@ int HcFileWrite(FileHandle file, const void *src, int srcSize)
|
||||
|
||||
const char *srcBuffer = (const char *)src;
|
||||
int total = 0;
|
||||
LOGI("[OS]: file write enter. [OriSize]: %d", srcSize);
|
||||
while (total < srcSize) {
|
||||
int writeCount = write(fp, srcBuffer + total, srcSize - total);
|
||||
if (writeCount < 0 || writeCount > (srcSize - total)) {
|
||||
LOGE("write size error, errno = %d", errno);
|
||||
LOGE("[OS]: write size error. [Errno]: %d", errno);
|
||||
return -1;
|
||||
}
|
||||
total += writeCount;
|
||||
}
|
||||
LOGI("[OS]: file write quit. [WriteSize]: %d", total);
|
||||
return total;
|
||||
}
|
||||
|
||||
@@ -173,7 +184,7 @@ void HcFileRemove(const char *path)
|
||||
}
|
||||
int res = unlink(path);
|
||||
if (res != 0) {
|
||||
LOGW("delete file failed, res = %d", res);
|
||||
LOGW("[OS]: delete file fail. [Res]: %d", res);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -253,7 +253,7 @@ void DeleteAuthCode(const IsoParams *params)
|
||||
LOGE("GenerateKeyAliasInIso failed, res:%d", res);
|
||||
goto ERR;
|
||||
}
|
||||
LOGI("AuthCode alias: %x%x%x%x****.", keyAlias[0], keyAlias[1], keyAlias[2], keyAlias[3]);
|
||||
LOGI("AuthCode alias(HEX): %x%x%x%x****.", keyAlias[0], keyAlias[1], keyAlias[2], keyAlias[3]);
|
||||
Uint8Buff outKeyAlias = { keyAlias, ISO_KEY_ALIAS_LEN };
|
||||
params->baseParams.loader->deleteKey(&outKeyAlias);
|
||||
ERR:
|
||||
@@ -508,7 +508,7 @@ static int AuthGeneratePsk(const Uint8Buff *seed, IsoParams *params)
|
||||
return res;
|
||||
}
|
||||
|
||||
LOGI("AuthCode alias: %x%x%x%x****.", keyAlias[0], keyAlias[1], keyAlias[2], keyAlias[3]);
|
||||
LOGI("AuthCode alias(HEX): %x%x%x%x****.", keyAlias[0], keyAlias[1], keyAlias[2], keyAlias[3]);
|
||||
Uint8Buff keyAliasBuf = { keyAlias, sizeof(keyAlias) };
|
||||
Uint8Buff pskBuf = { params->baseParams.psk, sizeof(params->baseParams.psk) };
|
||||
return params->baseParams.loader->computeHmac(&keyAliasBuf, seed, &pskBuf, true);
|
||||
|
||||
+4
-2
@@ -33,7 +33,8 @@ static int32_t UnregisterLocalIdentity(const char *pkgName, const char *serviceT
|
||||
LOGE("Failed to generate authtoken alias!");
|
||||
return res;
|
||||
}
|
||||
LOGI("AuthCode alias: %x%x%x%x****.", isoKeyAliasVal[0], isoKeyAliasVal[1], isoKeyAliasVal[2], isoKeyAliasVal[3]);
|
||||
LOGI("AuthCode alias(HEX): %x%x%x%x****.", isoKeyAliasVal[0], isoKeyAliasVal[1],
|
||||
isoKeyAliasVal[2], isoKeyAliasVal[3]);
|
||||
res = loader->deleteKey(&isoKeyAliasBuff);
|
||||
if (res != HC_SUCCESS) {
|
||||
LOGE("Failed to delete authtoken!");
|
||||
@@ -58,7 +59,8 @@ static int32_t DeletePeerAuthInfo(const char *pkgName, const char *serviceType,
|
||||
LOGE("Failed to generate authtoken alias!");
|
||||
return res;
|
||||
}
|
||||
LOGI("AuthCode alias: %x%x%x%x****.", isoKeyAliasVal[0], isoKeyAliasVal[1], isoKeyAliasVal[2], isoKeyAliasVal[3]);
|
||||
LOGI("AuthCode alias(HEX): %x%x%x%x****.", isoKeyAliasVal[0], isoKeyAliasVal[1],
|
||||
isoKeyAliasVal[2], isoKeyAliasVal[3]);
|
||||
res = loader->deleteKey(&isoKeyAliasBuff);
|
||||
if (res != HC_SUCCESS) {
|
||||
LOGE("Failed to delete authtoken!");
|
||||
|
||||
+1
-1
@@ -65,7 +65,7 @@ static int DecAndImportInner(IsoClientBindExchangeTask *realTask, const IsoParam
|
||||
goto ERR;
|
||||
}
|
||||
|
||||
LOGI("AuthCode alias: %x%x%x%x****.", keyAlias[0], keyAlias[1], keyAlias[2], keyAlias[3]);
|
||||
LOGI("AuthCode alias(HEX): %x%x%x%x****.", keyAlias[0], keyAlias[1], keyAlias[2], keyAlias[3]);
|
||||
ExtraInfo exInfo = { { params->baseParams.authIdPeer.val, params->baseParams.authIdPeer.length },
|
||||
params->peerUserType, PAIR_TYPE_BIND };
|
||||
res = params->baseParams.loader->importSymmetricKey(&keyAliasBuf, authCodeBuf, KEY_PURPOSE_MAC, &exInfo);
|
||||
|
||||
+1
-1
@@ -68,7 +68,7 @@ static int Process(struct SymBaseCurTaskT *task, IsoParams *params, const CJson
|
||||
LOGE("GenerateKeyAliasInIso failed, res:%d", res);
|
||||
goto ERR;
|
||||
}
|
||||
LOGI("AuthCode alias: %x%x%x%x****.", keyAlias[0], keyAlias[1], keyAlias[2], keyAlias[3]);
|
||||
LOGI("AuthCode alias(HEX): %x%x%x%x****.", keyAlias[0], keyAlias[1], keyAlias[2], keyAlias[3]);
|
||||
Uint8Buff outKeyAlias = { (uint8_t *)keyAlias, ISO_KEY_ALIAS_LEN };
|
||||
res = params->baseParams.loader->deleteKey(&outKeyAlias);
|
||||
if (res != 0) {
|
||||
|
||||
+1
-1
@@ -152,7 +152,7 @@ static int GenAndEncAuthCode(const IsoParams *params, Uint8Buff *nonceBuf, const
|
||||
goto ERR;
|
||||
}
|
||||
|
||||
LOGI("AuthCode alias: %x%x%x%x****.", keyAlias[0], keyAlias[1], keyAlias[2], keyAlias[3]);
|
||||
LOGI("AuthCode alias(HEX): %x%x%x%x****.", keyAlias[0], keyAlias[1], keyAlias[2], keyAlias[3]);
|
||||
Uint8Buff keyAliasBuf = { keyAlias, ISO_KEY_ALIAS_LEN };
|
||||
ExtraInfo exInfo = { { params->baseParams.authIdPeer.val, params->baseParams.authIdPeer.length },
|
||||
params->peerUserType, PAIR_TYPE_BIND };
|
||||
|
||||
+1
-1
@@ -144,7 +144,7 @@ int32_t FillPskWithDerivedKeyHex(PakeParams *params)
|
||||
return res;
|
||||
}
|
||||
|
||||
LOGI("Psk alias: %x%x%x%x****.", pskKeyAliasVal[0], pskKeyAliasVal[1], pskKeyAliasVal[2], pskKeyAliasVal[3]);
|
||||
LOGI("Psk alias(HEX): %x%x%x%x****.", pskKeyAliasVal[0], pskKeyAliasVal[1], pskKeyAliasVal[2], pskKeyAliasVal[3]);
|
||||
if (params->baseParams.loader->checkKeyExist(&pskKeyAlias) != HC_SUCCESS) {
|
||||
res = GetStandardTokenManagerInstance()->computeAndSavePsk(params);
|
||||
if (res != HC_SUCCESS) {
|
||||
|
||||
+2
-1
@@ -368,7 +368,8 @@ static int32_t SaveAuthInfo(const PakeParams *pakeParams, const StandardBindExch
|
||||
LOGE("generateKeyAlias failed");
|
||||
return res;
|
||||
}
|
||||
LOGI("PubKey alias: %x%x%x%x****.", keyAliasPeerVal[0], keyAliasPeerVal[1], keyAliasPeerVal[2], keyAliasPeerVal[3]);
|
||||
LOGI("PubKey alias(HEX): %x%x%x%x****.", keyAliasPeerVal[0], keyAliasPeerVal[1],
|
||||
keyAliasPeerVal[2], keyAliasPeerVal[3]);
|
||||
Algorithm alg = (pakeParams->baseParams.curveType == CURVE_256) ? P256 : ED25519;
|
||||
ExtraInfo exInfo = { pakeParams->baseParams.idPeer, pakeParams->userType, PAIR_TYPE_BIND };
|
||||
res = pakeParams->baseParams.loader->importPublicKey(&keyAliasPeer, &(exchangeParams->pubKeyPeer), alg, &exInfo);
|
||||
|
||||
+2
-2
@@ -190,7 +190,7 @@ static int32_t DeleteAuthInfo(PakeParams *pakeParams)
|
||||
LOGE("generate pubKey alias failed");
|
||||
return res;
|
||||
}
|
||||
LOGI("PubKey alias: %x%x%x%x****.", keyAliasVal[0], keyAliasVal[1], keyAliasVal[2], keyAliasVal[3]);
|
||||
LOGI("PubKey alias(HEX): %x%x%x%x****.", keyAliasVal[0], keyAliasVal[1], keyAliasVal[2], keyAliasVal[3]);
|
||||
res = pakeParams->baseParams.loader->deleteKey(&keyAlias);
|
||||
if (res != HC_SUCCESS) {
|
||||
LOGE("deleteKey failed");
|
||||
@@ -203,7 +203,7 @@ static int32_t DeleteAuthInfo(PakeParams *pakeParams)
|
||||
LOGE("generate pskKey alias failed");
|
||||
return res;
|
||||
}
|
||||
LOGI("Psk alias: %x%x%x%x****.", keyAliasVal[0], keyAliasVal[1], keyAliasVal[2], keyAliasVal[3]);
|
||||
LOGI("Psk alias(HEX): %x%x%x%x****.", keyAliasVal[0], keyAliasVal[1], keyAliasVal[2], keyAliasVal[3]);
|
||||
res = pakeParams->baseParams.loader->deleteKey(&keyAlias);
|
||||
if (res != HC_SUCCESS) {
|
||||
LOGE("delete pskKey failed");
|
||||
|
||||
+6
-4
@@ -62,7 +62,7 @@ static int32_t UnregisterLocalIdentity(const char *pkgName, const char *serviceT
|
||||
LOGE("Failed to generate identity keyPair alias!");
|
||||
return res;
|
||||
}
|
||||
LOGI("KeyPair alias: %x%x%x%x****.", pakeKeyAliasVal[0], pakeKeyAliasVal[1],
|
||||
LOGI("KeyPair alias(HEX): %x%x%x%x****.", pakeKeyAliasVal[0], pakeKeyAliasVal[1],
|
||||
pakeKeyAliasVal[2], pakeKeyAliasVal[3]);
|
||||
res = loader->deleteKey(&pakeKeyAliasBuff);
|
||||
if (res != HC_SUCCESS) {
|
||||
@@ -87,7 +87,8 @@ static int32_t DeletePeerAuthInfo(const char *pkgName, const char *serviceType,
|
||||
LOGE("Failed to generate identity keyPair alias!");
|
||||
return res;
|
||||
}
|
||||
LOGI("PubKey alias: %x%x%x%x****.", pakeKeyAliasVal[0], pakeKeyAliasVal[1], pakeKeyAliasVal[2], pakeKeyAliasVal[3]);
|
||||
LOGI("PubKey alias(HEX): %x%x%x%x****.", pakeKeyAliasVal[0], pakeKeyAliasVal[1],
|
||||
pakeKeyAliasVal[2], pakeKeyAliasVal[3]);
|
||||
res = loader->deleteKey(&pakeKeyAliasBuff);
|
||||
if (res != HC_SUCCESS) {
|
||||
LOGE("Failed to delete key pair!");
|
||||
@@ -100,7 +101,8 @@ static int32_t DeletePeerAuthInfo(const char *pkgName, const char *serviceType,
|
||||
LOGE("Failed to generate psk alias!");
|
||||
return res;
|
||||
}
|
||||
LOGI("Psk alias: %x%x%x%x****.", pakeKeyAliasVal[0], pakeKeyAliasVal[1], pakeKeyAliasVal[2], pakeKeyAliasVal[3]);
|
||||
LOGI("Psk alias(HEX): %x%x%x%x****.", pakeKeyAliasVal[0], pakeKeyAliasVal[1],
|
||||
pakeKeyAliasVal[2], pakeKeyAliasVal[3]);
|
||||
res = loader->deleteKey(&pakeKeyAliasBuff);
|
||||
if (res != HC_SUCCESS) {
|
||||
LOGE("Failed to delete psk!");
|
||||
@@ -151,7 +153,7 @@ static int32_t ComputeAndSavePsk(const PakeParams *params)
|
||||
return res;
|
||||
}
|
||||
|
||||
LOGI("PubKey alias: %x%x%x%x****, priKey alias: %x%x%x%x****, psk alias: %x%x%x%x****.",
|
||||
LOGI("PubKey alias(HEX): %x%x%x%x****, priKey alias(HEX): %x%x%x%x****, psk alias(HEX): %x%x%x%x****.",
|
||||
peerKeyAliasVal[0], peerKeyAliasVal[1], peerKeyAliasVal[2], peerKeyAliasVal[3],
|
||||
selfKeyAliasVal[0], selfKeyAliasVal[1], selfKeyAliasVal[2], selfKeyAliasVal[3],
|
||||
sharedKeyAliasVal[0], sharedKeyAliasVal[1], sharedKeyAliasVal[2], sharedKeyAliasVal[3]);
|
||||
|
||||
@@ -1086,7 +1086,6 @@ int32_t QueryGroups(int32_t osAccountId, const QueryGroupParams *params, GroupEn
|
||||
}
|
||||
}
|
||||
g_databaseMutex->unlock(g_databaseMutex);
|
||||
LOGI("[DB]: Number of groups queried: %d", vec->size(vec));
|
||||
return HC_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -1118,7 +1117,6 @@ int32_t QueryDevices(int32_t osAccountId, const QueryDeviceParams *params, Devic
|
||||
}
|
||||
}
|
||||
g_databaseMutex->unlock(g_databaseMutex);
|
||||
LOGI("[DB]: Number of trusted devices queried: %d", vec->size(vec));
|
||||
return HC_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
@@ -120,6 +120,11 @@
|
||||
#define FIELD_AUTH_RESULT_MAC "authResultMac"
|
||||
#define FIELD_LOCAL_DEVICE_TYPE "localDeviceType"
|
||||
|
||||
#define DEV_AUTH_ZERO 0
|
||||
#define DEV_AUTH_ONE 1
|
||||
#define DEV_AUTH_TWO 2
|
||||
#define DEV_AUTH_THREE 3
|
||||
|
||||
#define INVALID_MODULE_TYPE (-1)
|
||||
#define GROUP_ERR_MSG 0x8080
|
||||
|
||||
@@ -147,6 +152,7 @@
|
||||
#define ALL_GROUP_VISIBILITY (-2)
|
||||
#define INVALID_CRED 0
|
||||
#define PUBLIC_KEY_MAX_LENGTH 128
|
||||
#define DESENSITIZATION_LEN 12
|
||||
|
||||
typedef enum {
|
||||
NO_CHANNEL = 1,
|
||||
|
||||
@@ -41,7 +41,7 @@ int32_t CheckMsgRepeatability(const CJson *in, int moduleType)
|
||||
case ACCOUNT_MODULE:
|
||||
return CheckAccountMsgRepeatability(in);
|
||||
default:
|
||||
LOGE("Unsupported module type: %d.", moduleType);
|
||||
LOGE("Unsupported module type: %d", moduleType);
|
||||
return HC_ERR_MODULE_NOT_FOUNT;
|
||||
}
|
||||
return HC_ERROR;
|
||||
@@ -56,7 +56,7 @@ static AuthModuleBase *GetModule(int moduleType)
|
||||
return *module;
|
||||
}
|
||||
}
|
||||
LOGE("There is no matched module, moduleType: %d.", moduleType);
|
||||
LOGE("There is no matched module, moduleType: %d", moduleType);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -64,7 +64,7 @@ static bool IsParamsForDasTokenManagerValid(const char *pkgName, const char *ser
|
||||
int userType, int moduleType)
|
||||
{
|
||||
if (moduleType != DAS_MODULE) {
|
||||
LOGE("Unsupported method in the module, moduleType: %d.", moduleType);
|
||||
LOGE("Unsupported method in the module, moduleType: %d", moduleType);
|
||||
return false;
|
||||
}
|
||||
if (pkgName == NULL || serviceType == NULL || authId == NULL || authId->val == NULL) {
|
||||
@@ -77,7 +77,7 @@ static bool IsParamsForDasTokenManagerValid(const char *pkgName, const char *ser
|
||||
return false;
|
||||
}
|
||||
if (userType < DEVICE_TYPE_ACCESSORY || userType > DEVICE_TYPE_PROXY) {
|
||||
LOGE("Invalid userType, userType: %d.", userType);
|
||||
LOGE("Invalid userType, userType: %d", userType);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@@ -98,7 +98,7 @@ int32_t RegisterLocalIdentity(const char *pkgName, const char *serviceType, Uint
|
||||
DasAuthModule *dasModule = (DasAuthModule *)module;
|
||||
int32_t res = dasModule->registerLocalIdentity(pkgName, serviceType, authId, userType);
|
||||
if (res != HC_SUCCESS) {
|
||||
LOGE("Register local identity failed, res: %x.", res);
|
||||
LOGE("Register local identity failed, res: %x", res);
|
||||
return res;
|
||||
}
|
||||
return HC_SUCCESS;
|
||||
@@ -119,7 +119,7 @@ int32_t UnregisterLocalIdentity(const char *pkgName, const char *serviceType, Ui
|
||||
DasAuthModule *dasModule = (DasAuthModule *)module;
|
||||
int32_t res = dasModule->unregisterLocalIdentity(pkgName, serviceType, authId, userType);
|
||||
if (res != HC_SUCCESS) {
|
||||
LOGE("Unregister local identity failed, res: %x.", res);
|
||||
LOGE("Unregister local identity failed, res: %x", res);
|
||||
return res;
|
||||
}
|
||||
return HC_SUCCESS;
|
||||
@@ -140,7 +140,7 @@ int32_t DeletePeerAuthInfo(const char *pkgName, const char *serviceType, Uint8Bu
|
||||
DasAuthModule *dasModule = (DasAuthModule *)module;
|
||||
int32_t res = dasModule->deletePeerAuthInfo(pkgName, serviceType, authId, userType);
|
||||
if (res != HC_SUCCESS) {
|
||||
LOGE("Delete peer authInfo failed, res: %x.", res);
|
||||
LOGE("Delete peer authInfo failed, res: %x", res);
|
||||
return res;
|
||||
}
|
||||
return HC_SUCCESS;
|
||||
@@ -175,26 +175,27 @@ int32_t ProcessTask(int taskId, const CJson *in, CJson *out, int32_t *status, in
|
||||
LOGE("Params is null.");
|
||||
return HC_ERR_NULL_PTR;
|
||||
}
|
||||
LOGI("Start to process task, taskId: %d, moduleType: %d.", taskId, moduleType);
|
||||
AuthModuleBase *module = GetModule(moduleType);
|
||||
if (module == NULL) {
|
||||
LOGE("Failed to get module!");
|
||||
return HC_ERR_MODULE_NOT_FOUNT;
|
||||
}
|
||||
if (module->processTask == NULL) {
|
||||
LOGE("Unsupported method in the module, moduleType: %d.", moduleType);
|
||||
LOGE("Unsupported method in the module, moduleType: %d", moduleType);
|
||||
return HC_ERR_UNSUPPORTED_METHOD;
|
||||
}
|
||||
int32_t res = module->processTask(taskId, in, out, status);
|
||||
if (res != HC_SUCCESS) {
|
||||
LOGE("Process task failed, taskId: %d, moduleType: %d, res: %d.", taskId, moduleType, res);
|
||||
LOGE("Process task failed, taskId: %d, moduleType: %d, res: %d", taskId, moduleType, res);
|
||||
return res;
|
||||
}
|
||||
res = AddSingleVersionToJson(out, &g_version);
|
||||
if (res != HC_SUCCESS) {
|
||||
LOGE("AddSingleVersionToJson failed, res: %x.", res);
|
||||
LOGE("AddSingleVersionToJson failed, res: %x", res);
|
||||
return res;
|
||||
}
|
||||
LOGI("Process task success, taskId: %d, moduleType: %d.", taskId, moduleType);
|
||||
LOGI("Process task success, taskId: %d, moduleType: %d", taskId, moduleType);
|
||||
return res;
|
||||
}
|
||||
|
||||
@@ -204,21 +205,22 @@ int32_t CreateTask(int32_t *taskId, const CJson *in, CJson *out, int moduleType)
|
||||
LOGE("Params is null.");
|
||||
return HC_ERR_NULL_PTR;
|
||||
}
|
||||
LOGI("Start to create task, moduleType: %d", moduleType);
|
||||
AuthModuleBase *module = GetModule(moduleType);
|
||||
if (module == NULL) {
|
||||
LOGE("Failed to get module!");
|
||||
return HC_ERR_MODULE_NOT_FOUNT;
|
||||
}
|
||||
if (module->createTask == NULL) {
|
||||
LOGE("Unsupported method in the module, moduleType: %d.", moduleType);
|
||||
LOGE("Unsupported method in the module, moduleType: %d", moduleType);
|
||||
return HC_ERR_UNSUPPORTED_METHOD;
|
||||
}
|
||||
int32_t res = module->createTask(taskId, in, out);
|
||||
if (res != HC_SUCCESS) {
|
||||
LOGE("Create task failed, taskId: %d, moduleType: %d, res: %d.", *taskId, moduleType, res);
|
||||
LOGE("Create task failed, taskId: %d, moduleType: %d, res: %d", *taskId, moduleType, res);
|
||||
return res;
|
||||
}
|
||||
LOGI("Create task success, taskId: %d, moduleType: %d.", *taskId, moduleType);
|
||||
LOGI("Create task success, taskId: %d, moduleType: %d", *taskId, moduleType);
|
||||
return HC_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -229,7 +231,7 @@ void DestroyTask(int taskId, int moduleType)
|
||||
return;
|
||||
}
|
||||
if (module->destroyTask == NULL) {
|
||||
LOGE("Unsupported method in the module, moduleType: %d.", moduleType);
|
||||
LOGE("Unsupported method in the module, moduleType: %d", moduleType);
|
||||
return;
|
||||
}
|
||||
module->destroyTask(taskId);
|
||||
@@ -261,7 +263,7 @@ static int32_t ProcessCredentials(int32_t osAccountId, int32_t credentialOpCode,
|
||||
CJson *in, CJson *out, int moduleType)
|
||||
{
|
||||
if (moduleType != ACCOUNT_MODULE) {
|
||||
LOGE("Unsupported method in the module, moduleType: %d.", moduleType);
|
||||
LOGE("Unsupported method in the module, moduleType: %d", moduleType);
|
||||
return HC_ERR_NOT_SUPPORT;
|
||||
}
|
||||
|
||||
@@ -276,7 +278,7 @@ int32_t InitModules(void)
|
||||
if (IsDasSupported()) {
|
||||
res = InitDasModule();
|
||||
if (res != HC_SUCCESS) {
|
||||
LOGE("Init das module failed, res: %x.", res);
|
||||
LOGE("Init das module failed, res: %x", res);
|
||||
DestroyModules();
|
||||
return res;
|
||||
}
|
||||
@@ -285,7 +287,7 @@ int32_t InitModules(void)
|
||||
if (IsAccountSupported()) {
|
||||
res = InitAccountModule();
|
||||
if (res != HC_SUCCESS) {
|
||||
LOGE("Init account module failed, res: %x.", res);
|
||||
LOGE("Init account module failed, res: %x", res);
|
||||
DestroyModules();
|
||||
return res;
|
||||
}
|
||||
|
||||
@@ -28,11 +28,11 @@ int32_t DevAuthGetRealOsAccountLocalId(int32_t inputId)
|
||||
if (inputId == ANY_OS_ACCOUNT) {
|
||||
#ifdef SUPPORT_OS_ACCOUNT
|
||||
std::vector<int> activatedOsAccountIds;
|
||||
LOGI("[OsAccountManager][In]: QueryActiveOsAccountIds!");
|
||||
LOGI("[OsAccountManager]: QueryActiveOsAccountIds enter.");
|
||||
OHOS::ErrCode res = OHOS::AccountSA::OsAccountManager::QueryActiveOsAccountIds(activatedOsAccountIds);
|
||||
LOGI("[OsAccountManager][Out]: QueryActiveOsAccountIds! res: %d", res);
|
||||
LOGI("[OsAccountManager]: QueryActiveOsAccountIds quit. [Res]: %d", res);
|
||||
if ((res != OHOS::ERR_OK) || (activatedOsAccountIds.size() <= 0)) {
|
||||
LOGE("[Account]: QueryActiveOsAccountIds fail! res: %d", res);
|
||||
LOGE("[OsAccountManager]: QueryActiveOsAccountIds fail. [Res]: %d", res);
|
||||
return INVALID_OS_ACCOUNT;
|
||||
}
|
||||
int osAccountId = activatedOsAccountIds[0];
|
||||
|
||||
+2
-2
@@ -98,7 +98,7 @@ static bool IsPeerInAccountRelatedGroup(const TrustedGroupEntry *groupEntry, con
|
||||
return false;
|
||||
}
|
||||
if (IsUserIdEqual(userIdInDb, peerUserId)) {
|
||||
LOGI("[Account auth]: the input peer-userId is in one across group, add across-group auth!");
|
||||
LOGI("[Account auth]: The input peer-userId is in one account group, add account-group auth!");
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@@ -160,7 +160,7 @@ static void GaGetAccountGroup(int32_t osAccountId, GroupType type, const char *p
|
||||
HC_VECTOR_POPELEMENT(vec, &tempEntry, index);
|
||||
DestroyGroupEntry((TrustedGroupEntry *)tempEntry);
|
||||
}
|
||||
LOGI("The candidate account group size is:%d.", vec->size(vec));
|
||||
LOGI("The candidate account group size is: %u", vec->size(vec));
|
||||
}
|
||||
|
||||
static void GetAccountCandidateGroup(int32_t osAccountId, const CJson *param,
|
||||
|
||||
@@ -120,15 +120,19 @@ static int32_t DealPeerGroupAuthError(AuthSession *session)
|
||||
static void PrintErrorInputInfo(const CJson *param)
|
||||
{
|
||||
const char *peerUdid = GetStringFromJson(param, FIELD_PEER_CONN_DEVICE_ID);
|
||||
if ((peerUdid != NULL) && (HcStrlen(peerUdid) >= DESENSITIZATION_LEN)) {
|
||||
LOGE("Auth failed! [PeerUdid]: %c%c%c%c****", peerUdid[DEV_AUTH_ZERO], peerUdid[DEV_AUTH_ONE],
|
||||
peerUdid[DEV_AUTH_TWO], peerUdid[DEV_AUTH_THREE]);
|
||||
} else {
|
||||
LOGE("Auth failed! [peerUdid]: Unknown");
|
||||
}
|
||||
const char *peerAuthId = GetStringFromJson(param, FIELD_PEER_AUTH_ID);
|
||||
char *anonyPeerUdid = NULL;
|
||||
char *anonyPeerAuthId = NULL;
|
||||
ConvertToAnonymousStr(peerUdid, &anonyPeerUdid);
|
||||
ConvertToAnonymousStr(peerAuthId, &anonyPeerAuthId);
|
||||
LOGE("[PrintErrorInputInfo] [peerUdid]: %s", ((anonyPeerUdid == NULL) ? "NULL" : anonyPeerUdid));
|
||||
LOGE("[PrintErrorInputInfo] [peerAuthId]: %s", ((anonyPeerAuthId == NULL) ? "NULL" : anonyPeerAuthId));
|
||||
HcFree(anonyPeerUdid);
|
||||
HcFree(anonyPeerAuthId);
|
||||
if ((peerAuthId != NULL) && (HcStrlen(peerAuthId) >= DESENSITIZATION_LEN)) {
|
||||
LOGE("Auth failed! [peerAuthId]: %c%c%c%c****", peerAuthId[DEV_AUTH_ZERO], peerAuthId[DEV_AUTH_ONE],
|
||||
peerAuthId[DEV_AUTH_TWO], peerAuthId[DEV_AUTH_THREE]);
|
||||
} else {
|
||||
LOGE("Auth failed! [peerAuthId]: Unknown");
|
||||
}
|
||||
}
|
||||
|
||||
static int32_t ProcessClientAuthSession(Session *session, CJson *in)
|
||||
|
||||
@@ -141,6 +141,7 @@ static int32_t FillAuthParams(int32_t osAccountId, const CJson *param,
|
||||
}
|
||||
paramsVec->pushBack(paramsVec, (const void **)¶msData);
|
||||
}
|
||||
LOGI("The candidate group size is: %u", paramsVec->size(paramsVec));
|
||||
return HC_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -160,7 +161,6 @@ static void GetCandidateGroupByOrder(int32_t osAccountId, const CJson *param,
|
||||
|
||||
static void GetCandidateGroupInfo(int32_t osAccountId, const CJson *param, GroupEntryVec *vec)
|
||||
{
|
||||
LOGI("No input of groupId, extract group info without groupId.");
|
||||
bool deviceLevelFlag = false;
|
||||
bool isClient = true;
|
||||
(void)GetBoolFromJson(param, FIELD_IS_DEVICE_LEVEL, &deviceLevelFlag);
|
||||
@@ -197,8 +197,10 @@ static int32_t GetCandidateAuthInfo(int32_t osAccountId, const char *groupId,
|
||||
{
|
||||
GroupEntryVec vec = CreateGroupEntryVec();
|
||||
if (groupId == NULL) {
|
||||
LOGI("No groupId specified, extract group info without groupId.");
|
||||
GetCandidateGroupInfo(osAccountId, param, &vec);
|
||||
} else {
|
||||
LOGI("GroupId specified, extract group info through the groupId.");
|
||||
GetGroupInfoByGroupId(osAccountId, groupId, &vec);
|
||||
}
|
||||
if (vec.size(&vec) == 0) {
|
||||
|
||||
@@ -720,7 +720,7 @@ static int32_t RequestProcessBindData(int64_t requestId, const uint8_t *data, ui
|
||||
LOGE("The input data is invalid!");
|
||||
return HC_ERR_INVALID_PARAMS;
|
||||
}
|
||||
LOGI("[Start]: RequestProcessBindData! [RequestId]: %" PRId64, requestId);
|
||||
LOGI("[Start]: RequestProcessBindData! [ReqId]: %" PRId64, requestId);
|
||||
CJson *params = CreateJsonFromString((const char *)data);
|
||||
if (params == NULL) {
|
||||
LOGE("Failed to create json from string!");
|
||||
|
||||
@@ -298,7 +298,6 @@ int32_t GetTrustedDevInfoById(int32_t osAccountId, const char *deviceId, bool is
|
||||
LOGE("The input parameters contain NULL value!");
|
||||
return HC_ERR_INVALID_PARAMS;
|
||||
}
|
||||
LOGI("Start to get device information of a specified group!");
|
||||
TrustedDeviceEntry *deviceEntry = GetTrustedDeviceEntryById(osAccountId, deviceId, isUdid, groupId);
|
||||
if (deviceEntry == NULL) {
|
||||
LOGE("The trusted device is not found!");
|
||||
@@ -987,15 +986,14 @@ int32_t GenerateBindSuccessData(const char *peerAuthId, const char *groupId, cha
|
||||
LOGE("The input params contains NULL value!");
|
||||
return HC_ERR_NULL_PTR;
|
||||
}
|
||||
char *tempGroupId = NULL;
|
||||
char *tempAuthId = NULL;
|
||||
ConvertToAnonymousStr(groupId, &tempGroupId);
|
||||
ConvertToAnonymousStr(peerAuthId, &tempAuthId);
|
||||
LOGI("Bind successfully! [GroupId]: %s, [AddId]: %s",
|
||||
tempGroupId == NULL ? "NULL" : tempGroupId,
|
||||
tempAuthId == NULL ? "NULL" : tempAuthId);
|
||||
HcFree(tempGroupId);
|
||||
HcFree(tempAuthId);
|
||||
LOGI("Bind successfully! [GroupId]: %c%c%c%c****", groupId[DEV_AUTH_ZERO], groupId[DEV_AUTH_ONE],
|
||||
groupId[DEV_AUTH_TWO], groupId[DEV_AUTH_THREE]);
|
||||
if (HcStrlen(peerAuthId) >= DESENSITIZATION_LEN) {
|
||||
LOGI("Bind successfully! [PeerAuthId]: %c%c%c%c****", peerAuthId[DEV_AUTH_ZERO], peerAuthId[DEV_AUTH_ONE],
|
||||
peerAuthId[DEV_AUTH_TWO], peerAuthId[DEV_AUTH_THREE]);
|
||||
} else {
|
||||
LOGI("Bind successfully! [PeerAuthId]: too short");
|
||||
}
|
||||
CJson *jsonData = CreateJson();
|
||||
if (jsonData == NULL) {
|
||||
LOGE("Failed to allocate jsonData memory!");
|
||||
@@ -1027,15 +1025,14 @@ int32_t GenerateUnbindSuccessData(const char *peerAuthId, const char *groupId, c
|
||||
LOGE("The input params contains NULL value!");
|
||||
return HC_ERR_NULL_PTR;
|
||||
}
|
||||
char *tempGroupId = NULL;
|
||||
char *tempAuthId = NULL;
|
||||
ConvertToAnonymousStr(groupId, &tempGroupId);
|
||||
ConvertToAnonymousStr(peerAuthId, &tempAuthId);
|
||||
LOGI("Unbind successfully! [GroupId]: %s, [DeleteId]: %s",
|
||||
tempGroupId == NULL ? "NULL" : tempGroupId,
|
||||
tempAuthId == NULL ? "NULL" : tempAuthId);
|
||||
HcFree(tempGroupId);
|
||||
HcFree(tempAuthId);
|
||||
LOGI("Unbind successfully! [GroupId]: %c%c%c%c****", groupId[DEV_AUTH_ZERO], groupId[DEV_AUTH_ONE],
|
||||
groupId[DEV_AUTH_TWO], groupId[DEV_AUTH_THREE]);
|
||||
if (HcStrlen(peerAuthId) >= DESENSITIZATION_LEN) {
|
||||
LOGI("Unbind successfully! [PeerAuthId]: %c%c%c%c****", peerAuthId[DEV_AUTH_ZERO], peerAuthId[DEV_AUTH_ONE],
|
||||
peerAuthId[DEV_AUTH_TWO], peerAuthId[DEV_AUTH_THREE]);
|
||||
} else {
|
||||
LOGI("Unbind successfully! [PeerAuthId]: too short");
|
||||
}
|
||||
CJson *jsonData = CreateJson();
|
||||
if (jsonData == NULL) {
|
||||
LOGE("Failed to allocate jsonData memory!");
|
||||
|
||||
@@ -521,14 +521,6 @@ HWTEST_F(CommonLibTest, HcStringUtilTest001, TestSize.Level0)
|
||||
EXPECT_EQ(ret, 0);
|
||||
int64Res = StringToInt64(intStr);
|
||||
EXPECT_EQ(ret, 0);
|
||||
char *anonymousStr = nullptr;
|
||||
ConvertToAnonymousStr(nullptr, &anonymousStr);
|
||||
EXPECT_EQ(anonymousStr, nullptr);
|
||||
ConvertToAnonymousStr("abc", &anonymousStr);
|
||||
EXPECT_EQ(anonymousStr, nullptr);
|
||||
ConvertToAnonymousStr("abcde", &anonymousStr);
|
||||
EXPECT_NE(anonymousStr, nullptr);
|
||||
ClibFree(anonymousStr);
|
||||
}
|
||||
|
||||
HWTEST_F(CommonLibTest, HcStringUtilTest002, TestSize.Level0)
|
||||
|
||||
Reference in New Issue
Block a user