diff --git a/hals/src/common/common_util.c b/common_lib/impl/src/common_util.c similarity index 100% rename from hals/src/common/common_util.c rename to common_lib/impl/src/common_util.c diff --git a/hals/src/common/hc_parcel.c b/common_lib/impl/src/hc_parcel.c similarity index 100% rename from hals/src/common/hc_parcel.c rename to common_lib/impl/src/hc_parcel.c diff --git a/hals/src/common/hc_string.c b/common_lib/impl/src/hc_string.c similarity index 100% rename from hals/src/common/hc_string.c rename to common_lib/impl/src/hc_string.c diff --git a/hals/src/common/hc_tlv_parser.c b/common_lib/impl/src/hc_tlv_parser.c similarity index 100% rename from hals/src/common/hc_tlv_parser.c rename to common_lib/impl/src/hc_tlv_parser.c diff --git a/hals/src/common/json_utils.c b/common_lib/impl/src/json_utils.c similarity index 100% rename from hals/src/common/json_utils.c rename to common_lib/impl/src/json_utils.c diff --git a/hals/inc/common/common_util.h b/common_lib/interfaces/common_util.h similarity index 95% rename from hals/inc/common/common_util.h rename to common_lib/interfaces/common_util.h index 8eed5f9..3af85f0 100644 --- a/hals/inc/common/common_util.h +++ b/common_lib/interfaces/common_util.h @@ -17,7 +17,6 @@ #define COMMON_UTIL_H #include -#include "hc_error.h" #define BYTE_TO_HEX_OPER_LENGTH 2 #define DEC 10 diff --git a/hals/inc/common/hc_error.h b/common_lib/interfaces/hc_error.h similarity index 100% rename from hals/inc/common/hc_error.h rename to common_lib/interfaces/hc_error.h diff --git a/hals/inc/common/hc_parcel.h b/common_lib/interfaces/hc_parcel.h similarity index 100% rename from hals/inc/common/hc_parcel.h rename to common_lib/interfaces/hc_parcel.h diff --git a/hals/inc/common/hc_string.h b/common_lib/interfaces/hc_string.h similarity index 100% rename from hals/inc/common/hc_string.h rename to common_lib/interfaces/hc_string.h diff --git a/hals/inc/common/hc_tlv_parser.h b/common_lib/interfaces/hc_tlv_parser.h similarity index 100% rename from hals/inc/common/hc_tlv_parser.h rename to common_lib/interfaces/hc_tlv_parser.h diff --git a/hals/inc/common/hc_vector.h b/common_lib/interfaces/hc_vector.h similarity index 100% rename from hals/inc/common/hc_vector.h rename to common_lib/interfaces/hc_vector.h diff --git a/hals/inc/common/json_utils.h b/common_lib/interfaces/json_utils.h similarity index 100% rename from hals/inc/common/json_utils.h rename to common_lib/interfaces/json_utils.h diff --git a/hals/BUILD.gn b/deps_adapter/BUILD.gn similarity index 67% rename from hals/BUILD.gn rename to deps_adapter/BUILD.gn index 715c6f8..63961dc 100644 --- a/hals/BUILD.gn +++ b/deps_adapter/BUILD.gn @@ -24,7 +24,6 @@ if (defined(ohos_lite)) { include_dirs = hals_inc_path include_dirs += [ "//base/security/deviceauth/interfaces/innerkits", - "//base/security/deviceauth/services/common/inc", "//third_party/cJSON", "//utils/native/lite/include", "//base/hiviewdfx/hilog_lite/interfaces/native/kits/hilog_lite", @@ -34,15 +33,15 @@ if (defined(ohos_lite)) { sources = hal_common_files sources += [ - "src/dev_info/3861/hc_dev_info.c", - "src/liteos/L0/hc_file.c", - "src/liteos/L0/hc_init_protection.c", - "src/liteos/L0/huks_adapter.c", - "src/liteos/hc_condition.c", - "src/liteos/hc_mutex.c", - "src/liteos/hc_thread.c", - "src/liteos/hc_time.c", - "src/liteos/hc_types.c", + "${key_management_adapter_path}/impl/src/mini/huks_adapter.c", + "${os_adapter_path}/impl/src/dev_info/3861/hc_dev_info.c", + "${os_adapter_path}/impl/src/liteos/hc_condition.c", + "${os_adapter_path}/impl/src/liteos/hc_mutex.c", + "${os_adapter_path}/impl/src/liteos/hc_thread.c", + "${os_adapter_path}/impl/src/liteos/hc_time.c", + "${os_adapter_path}/impl/src/liteos/hc_types.c", + "${os_adapter_path}/impl/src/liteos/mini/hc_file.c", + "${os_adapter_path}/impl/src/liteos/mini/hc_init_protection.c", ] cflags = [ "-DHILOG_ENABLE" ] @@ -59,7 +58,6 @@ if (defined(ohos_lite)) { include_dirs = hals_inc_path include_dirs += [ "//base/security/deviceauth/interfaces/innerkits", - "//base/security/deviceauth/services/common/inc", "//third_party/cJSON", "//utils/native/lite/include", "//base/security/huks/interfaces/innerkits/huks_standard/main/include", @@ -70,16 +68,16 @@ if (defined(ohos_lite)) { sources = hal_common_files sources += [ - "src/dev_info/3516/hc_dev_info.c", - "src/linux/hc_condition.c", - "src/linux/hc_file.c", - "src/linux/hc_init_protection.c", - "src/linux/hc_mutex.c", - "src/linux/hc_thread.c", - "src/linux/hc_time.c", - "src/linux/hc_types.c", - "src/linux/lite/huks_adapter.c", - "src/linux/lite/mbedtls_hash_to_point.c", + "${key_management_adapter_path}/impl/src/small/huks_adapter.c", + "${key_management_adapter_path}/impl/src/small/mbedtls_hash_to_point.c", + "${os_adapter_path}/impl/src/dev_info/3516/hc_dev_info.c", + "${os_adapter_path}/impl/src/linux/hc_condition.c", + "${os_adapter_path}/impl/src/linux/hc_file.c", + "${os_adapter_path}/impl/src/linux/hc_init_protection.c", + "${os_adapter_path}/impl/src/linux/hc_mutex.c", + "${os_adapter_path}/impl/src/linux/hc_thread.c", + "${os_adapter_path}/impl/src/linux/hc_time.c", + "${os_adapter_path}/impl/src/linux/hc_types.c", ] cflags = [ "-DHILOG_ENABLE" ] @@ -100,7 +98,6 @@ if (defined(ohos_lite)) { } else { ohos_static_library("deviceauth_hal_linux") { subsystem_name = "security" - include_dirs = hals_inc_path include_dirs += [ "//third_party/cJSON", @@ -112,16 +109,16 @@ if (defined(ohos_lite)) { sources = hal_common_files sources += [ - "src/dev_info/3516/hc_dev_info.c", - "src/linux/hc_condition.c", - "src/linux/hc_file.c", - "src/linux/hc_init_protection.c", - "src/linux/hc_mutex.c", - "src/linux/hc_thread.c", - "src/linux/hc_time.c", - "src/linux/hc_types.c", - "src/linux/standard/crypto_hash_to_point.c", - "src/linux/standard/huks_adapter.c", + "${key_management_adapter_path}/impl/src/standard/crypto_hash_to_point.c", + "${key_management_adapter_path}/impl/src/standard/huks_adapter.c", + "${os_adapter_path}/impl/src/dev_info/3516/hc_dev_info.c", + "${os_adapter_path}/impl/src/linux/hc_condition.c", + "${os_adapter_path}/impl/src/linux/hc_file.c", + "${os_adapter_path}/impl/src/linux/hc_init_protection.c", + "${os_adapter_path}/impl/src/linux/hc_mutex.c", + "${os_adapter_path}/impl/src/linux/hc_thread.c", + "${os_adapter_path}/impl/src/linux/hc_time.c", + "${os_adapter_path}/impl/src/linux/hc_types.c", ] cflags = [ "-DHILOG_ENABLE" ] deps = [ diff --git a/deps_adapter/deviceauth_hals.gni b/deps_adapter/deviceauth_hals.gni new file mode 100644 index 0000000..5ab42d8 --- /dev/null +++ b/deps_adapter/deviceauth_hals.gni @@ -0,0 +1,49 @@ +# Copyright (C) 2021 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//base/security/deviceauth/deviceauth_env.gni") + +if (target_os == "liteos" || + (defined(ohos_lite) && ohos_kernel_type == "liteos_m")) { + hals_inc_path = [ + "${common_lib_path}/interfaces", + "${key_management_adapter_path}/interfaces", + "${key_management_adapter_path}/impl/inc", + "${os_adapter_path}/interfaces", + "${os_adapter_path}/interfaces/liteos", + "${os_adapter_path}/interfaces/dev_info/3861", + ] + hal_module_name = "deviceauth_hal_liteos" +} else { + hals_inc_path = [ + "${common_lib_path}/interfaces", + "${key_management_adapter_path}/interfaces", + "${key_management_adapter_path}/impl/inc", + "${os_adapter_path}/interfaces", + "${os_adapter_path}/interfaces/linux", + "${os_adapter_path}/interfaces/dev_info/3516", + ] + hal_module_name = "deviceauth_hal_linux" +} + +hal_common_files = [ + "${common_lib_path}/impl/src/hc_parcel.c", + "${common_lib_path}/impl/src/hc_string.c", + "${common_lib_path}/impl/src/hc_tlv_parser.c", + "${common_lib_path}/impl/src/json_utils.c", + "${common_lib_path}/impl/src/common_util.c", + "${key_management_adapter_path}/impl/src/alg_loader.c", + + "${os_adapter_path}/impl/src/hc_task_thread.c", + "${os_adapter_path}/impl/src/hc_log.c", +] diff --git a/hals/inc/linux/crypto_hash_to_point.h b/deps_adapter/key_management_adapter/impl/inc/crypto_hash_to_point.h similarity index 100% rename from hals/inc/linux/crypto_hash_to_point.h rename to deps_adapter/key_management_adapter/impl/inc/crypto_hash_to_point.h diff --git a/hals/inc/linux/mbedtls_hash_to_point.h b/deps_adapter/key_management_adapter/impl/inc/mbedtls_hash_to_point.h similarity index 93% rename from hals/inc/linux/mbedtls_hash_to_point.h rename to deps_adapter/key_management_adapter/impl/inc/mbedtls_hash_to_point.h index db6033f..29c6e99 100644 --- a/hals/inc/linux/mbedtls_hash_to_point.h +++ b/deps_adapter/key_management_adapter/impl/inc/mbedtls_hash_to_point.h @@ -17,8 +17,7 @@ #define MBEDTLS_HASH_TO_POINT_H #include - -#include "common_defs.h" +#include "common_util.h" #define HASH2POINT_PARA_PREPRO 0xc0 #define BYTE_LENGTH_CURVE_25519 32 diff --git a/hals/src/common/alg_loader.c b/deps_adapter/key_management_adapter/impl/src/alg_loader.c similarity index 100% rename from hals/src/common/alg_loader.c rename to deps_adapter/key_management_adapter/impl/src/alg_loader.c diff --git a/hals/src/liteos/L0/huks_adapter.c b/deps_adapter/key_management_adapter/impl/src/mini/huks_adapter.c similarity index 100% rename from hals/src/liteos/L0/huks_adapter.c rename to deps_adapter/key_management_adapter/impl/src/mini/huks_adapter.c diff --git a/hals/src/linux/lite/huks_adapter.c b/deps_adapter/key_management_adapter/impl/src/small/huks_adapter.c similarity index 100% rename from hals/src/linux/lite/huks_adapter.c rename to deps_adapter/key_management_adapter/impl/src/small/huks_adapter.c diff --git a/hals/src/linux/lite/mbedtls_hash_to_point.c b/deps_adapter/key_management_adapter/impl/src/small/mbedtls_hash_to_point.c similarity index 92% rename from hals/src/linux/lite/mbedtls_hash_to_point.c rename to deps_adapter/key_management_adapter/impl/src/small/mbedtls_hash_to_point.c index ed281d7..8b684b6 100644 --- a/hals/src/linux/lite/mbedtls_hash_to_point.c +++ b/deps_adapter/key_management_adapter/impl/src/small/mbedtls_hash_to_point.c @@ -13,15 +13,19 @@ * limitations under the License. */ +#include "mbedtls_hash_to_point.h" #include - #include #include - #include "alg_defs.h" +#include "hc_error.h" #include "hc_log.h" -#include "mbedtls_hash_to_point.h" +#define LEN_HALF_DIVISOR 2 +#define PARAM_A_INDEX 2 +#define PARAM_U_INDEX 4 +#define PARAM_MINUS_A_INDEX 3 +#define PARAM_ONE_INDEX 5 #define HASH_TO_POINT_PARA_NUMS 6 #define LOG_AND_GOTO_CLEANUP_IF_FAIL(ret, fmt, ...) \ @@ -30,7 +34,7 @@ do { \ LOGE(fmt, ##__VA_ARGS__); \ goto CLEAN_UP; \ } \ -} while(0) +} while (0) static uint8_t g_hash2pointParas[HASH_TO_POINT_PARA_NUMS][BYTE_LENGTH_CURVE_25519] = { { 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0:p */ @@ -74,7 +78,7 @@ static void SwapEndian(uint8_t *pubKey, int len) if ((pubKey == NULL) || (len <= 0)) { return; } - for (int i = 0; i < len / 2; ++i) { + for (int i = 0; i < len / LEN_HALF_DIVISOR; ++i) { uint8_t tmp = pubKey[i]; pubKey[i] = pubKey[len - i - 1]; pubKey[len - i - 1] = tmp; @@ -103,10 +107,10 @@ static int32_t CalTmpParaX(mbedtls_mpi *tmpY, const mbedtls_mpi *tmpX, const mbe mbedtls_mpi_init(¶BnA); mbedtls_mpi_init(¶BnU); - status = mbedtls_mpi_read_binary(¶BnA, g_hash2pointParas[2], BYTE_LENGTH_CURVE_25519); + status = mbedtls_mpi_read_binary(¶BnA, g_hash2pointParas[PARAM_A_INDEX], BYTE_LENGTH_CURVE_25519); LOG_AND_GOTO_CLEANUP_IF_FAIL(status, "CalTmpParaX error1"); - status = mbedtls_mpi_read_binary(¶BnU, g_hash2pointParas[4], BYTE_LENGTH_CURVE_25519); + status = mbedtls_mpi_read_binary(¶BnU, g_hash2pointParas[PARAM_U_INDEX], BYTE_LENGTH_CURVE_25519); LOG_AND_GOTO_CLEANUP_IF_FAIL(status, "CalTmpParaX error2"); status = mbedtls_mpi_copy(&tmpBnB, tmpX); @@ -157,11 +161,11 @@ static int32_t CalTmpParab(mbedtls_mpi *tmpX, const mbedtls_mpi *modP, const uin mbedtls_mpi_init(&tmpBnA); mbedtls_mpi_init(&tmpBnB); - status = mbedtls_mpi_read_binary(¶BnNegA, g_hash2pointParas[3], BYTE_LENGTH_CURVE_25519); + status = mbedtls_mpi_read_binary(¶BnNegA, g_hash2pointParas[PARAM_MINUS_A_INDEX], BYTE_LENGTH_CURVE_25519); LOG_AND_GOTO_CLEANUP_IF_FAIL(status, "CalTmpParab error1"); - status = mbedtls_mpi_read_binary(¶BNOne, g_hash2pointParas[5], BYTE_LENGTH_CURVE_25519); + status = mbedtls_mpi_read_binary(¶BNOne, g_hash2pointParas[PARAM_ONE_INDEX], BYTE_LENGTH_CURVE_25519); LOG_AND_GOTO_CLEANUP_IF_FAIL(status, "CalTmpParab error2"); - status = mbedtls_mpi_read_binary(¶BnU, g_hash2pointParas[4], BYTE_LENGTH_CURVE_25519); + status = mbedtls_mpi_read_binary(¶BnU, g_hash2pointParas[PARAM_U_INDEX], BYTE_LENGTH_CURVE_25519); LOG_AND_GOTO_CLEANUP_IF_FAIL(status, "CalTmpParab error3"); status = mbedtls_mpi_read_binary(&tmpBnA, hash, hashLen); LOG_AND_GOTO_CLEANUP_IF_FAIL(status, "CalTmpParab error4"); @@ -219,7 +223,7 @@ static int32_t Elligator(unsigned char *point, int pointLength, const unsigned c LOG_AND_GOTO_CLEANUP_IF_FAIL(status, "Elligator error1"); status = mbedtls_mpi_read_binary(¶BnSquare, g_hash2pointParas[1], BYTE_LENGTH_CURVE_25519); LOG_AND_GOTO_CLEANUP_IF_FAIL(status, "Elligator error2"); - status = mbedtls_mpi_read_binary(¶BnNegA, g_hash2pointParas[3], BYTE_LENGTH_CURVE_25519); + status = mbedtls_mpi_read_binary(¶BnNegA, g_hash2pointParas[PARAM_MINUS_A_INDEX], BYTE_LENGTH_CURVE_25519); LOG_AND_GOTO_CLEANUP_IF_FAIL(status, "Elligator error3"); status = CalTmpParab(&tmpBnB, ¶BnP, hash, hashLength); @@ -258,11 +262,11 @@ CLEAN_UP: int32_t MbedtlsHashToPoint(const Uint8Buff *hash, Uint8Buff *outEcPoint) { if (IsInvalidBlob(hash) || IsInvalidBlob(outEcPoint)) { - return HC_ERR_INVALID_PARAMS; + return HAL_ERR_INVALID_PARAM; } if (hash->length != BYTE_LENGTH_CURVE_25519 || outEcPoint->length != BYTE_LENGTH_CURVE_25519) { LOGE("MbedtlsHashToPoint invalid length."); - return HC_ERR_INVALID_PARAMS; + return HAL_ERR_INVALID_PARAM; } uint8_t hashTmp[BYTE_LENGTH_CURVE_25519] = {0}; (void)memcpy_s(hashTmp, BYTE_LENGTH_CURVE_25519, hash->val, BYTE_LENGTH_CURVE_25519); diff --git a/hals/src/linux/standard/crypto_hash_to_point.c b/deps_adapter/key_management_adapter/impl/src/standard/crypto_hash_to_point.c similarity index 100% rename from hals/src/linux/standard/crypto_hash_to_point.c rename to deps_adapter/key_management_adapter/impl/src/standard/crypto_hash_to_point.c diff --git a/hals/src/linux/standard/huks_adapter.c b/deps_adapter/key_management_adapter/impl/src/standard/huks_adapter.c similarity index 100% rename from hals/src/linux/standard/huks_adapter.c rename to deps_adapter/key_management_adapter/impl/src/standard/huks_adapter.c diff --git a/hals/inc/common/alg_defs.h b/deps_adapter/key_management_adapter/interfaces/alg_defs.h similarity index 98% rename from hals/inc/common/alg_defs.h rename to deps_adapter/key_management_adapter/interfaces/alg_defs.h index 6a6be2b..bf41adb 100644 --- a/hals/inc/common/alg_defs.h +++ b/deps_adapter/key_management_adapter/interfaces/alg_defs.h @@ -23,8 +23,8 @@ #define HMAC_LEN 32 #define SIGNATURE_LEN 64 #define AE_TAG_LEN 16 -#define BIG_PRIME_LEN_384 384 -#define BIG_PRIME_LEN_256 256 +#define BIG_PRIME_LEN_384 384 +#define BIG_PRIME_LEN_256 256 typedef enum { PAIR_TYPE_BIND = 0, diff --git a/hals/inc/common/alg_loader.h b/deps_adapter/key_management_adapter/interfaces/alg_loader.h similarity index 100% rename from hals/inc/common/alg_loader.h rename to deps_adapter/key_management_adapter/interfaces/alg_loader.h diff --git a/hals/inc/common/huks_adapter.h b/deps_adapter/key_management_adapter/interfaces/huks_adapter.h similarity index 100% rename from hals/inc/common/huks_adapter.h rename to deps_adapter/key_management_adapter/interfaces/huks_adapter.h diff --git a/hals/src/dev_info/3516/hc_dev_info.c b/deps_adapter/os_adapter/impl/src/dev_info/3516/hc_dev_info.c similarity index 97% rename from hals/src/dev_info/3516/hc_dev_info.c rename to deps_adapter/os_adapter/impl/src/dev_info/3516/hc_dev_info.c index 5ef312e..e2a1763 100644 --- a/hals/src/dev_info/3516/hc_dev_info.c +++ b/deps_adapter/os_adapter/impl/src/dev_info/3516/hc_dev_info.c @@ -36,7 +36,7 @@ int32_t HcGetUdid(uint8_t *udid, int32_t udidLen) return HAL_SUCCESS; } -const char *GetStoragePath() +const char *GetStoragePath(void) { #ifndef LITE_DEVICE const char *storageFile = "/data/data/deviceauth/hcgroup.dat"; diff --git a/hals/src/dev_info/3861/hc_dev_info.c b/deps_adapter/os_adapter/impl/src/dev_info/3861/hc_dev_info.c similarity index 93% rename from hals/src/dev_info/3861/hc_dev_info.c rename to deps_adapter/os_adapter/impl/src/dev_info/3861/hc_dev_info.c index 0888ec6..9c7528a 100644 --- a/hals/src/dev_info/3861/hc_dev_info.c +++ b/deps_adapter/os_adapter/impl/src/dev_info/3861/hc_dev_info.c @@ -36,7 +36,7 @@ int32_t HcGetUdid(uint8_t *udid, int32_t udidLen) return HAL_SUCCESS; } -const char *GetStoragePath() +const char *GetStoragePath(void) { return "hcgroup.dat"; } diff --git a/hals/src/dev_info/watch/hc_dev_info.c b/deps_adapter/os_adapter/impl/src/dev_info/watch/hc_dev_info.c similarity index 98% rename from hals/src/dev_info/watch/hc_dev_info.c rename to deps_adapter/os_adapter/impl/src/dev_info/watch/hc_dev_info.c index ff81835..72fb1c1 100644 --- a/hals/src/dev_info/watch/hc_dev_info.c +++ b/deps_adapter/os_adapter/impl/src/dev_info/watch/hc_dev_info.c @@ -46,7 +46,7 @@ int32_t HcGetUdid(uint8_t *udid, int32_t udidLen) return result; } -const char *GetStoragePath() +const char *GetStoragePath(void) { return "user/Hichain/hcgroup.dat"; } \ No newline at end of file diff --git a/hals/src/common/hc_log.c b/deps_adapter/os_adapter/impl/src/hc_log.c similarity index 99% rename from hals/src/common/hc_log.c rename to deps_adapter/os_adapter/impl/src/hc_log.c index cc1fd94..569d7ed 100644 --- a/hals/src/common/hc_log.c +++ b/deps_adapter/os_adapter/impl/src/hc_log.c @@ -14,7 +14,6 @@ */ #include "hc_log.h" - #include #define LOG_PRINT_MAX_LEN 256 diff --git a/hals/src/common/hc_task_thread.c b/deps_adapter/os_adapter/impl/src/hc_task_thread.c similarity index 100% rename from hals/src/common/hc_task_thread.c rename to deps_adapter/os_adapter/impl/src/hc_task_thread.c diff --git a/hals/src/linux/hc_condition.c b/deps_adapter/os_adapter/impl/src/linux/hc_condition.c similarity index 94% rename from hals/src/linux/hc_condition.c rename to deps_adapter/os_adapter/impl/src/linux/hc_condition.c index 42b1492..6c673b3 100644 --- a/hals/src/linux/hc_condition.c +++ b/deps_adapter/os_adapter/impl/src/linux/hc_condition.c @@ -132,8 +132,7 @@ int32_t InitHcCond(HcCondition* hcCond, HcMutex* mutex) } else { hcCond->mutex = (HcMutex*)HcMalloc(sizeof(HcMutex), 0); if (hcCond->mutex != NULL) { - int32_t res; - res = InitHcMutex(hcCond->mutex); + int32_t res = InitHcMutex(hcCond->mutex); if (res != 0) { HcFree(hcCond->mutex); hcCond->mutex = NULL; diff --git a/hals/src/linux/hc_file.c b/deps_adapter/os_adapter/impl/src/linux/hc_file.c similarity index 100% rename from hals/src/linux/hc_file.c rename to deps_adapter/os_adapter/impl/src/linux/hc_file.c index 8974c50..2c3c781 100644 --- a/hals/src/linux/hc_file.c +++ b/deps_adapter/os_adapter/impl/src/linux/hc_file.c @@ -14,11 +14,11 @@ */ #include "hc_file.h" -#include "securec.h" #include #include #include #include +#include "securec.h" #include "hc_log.h" #include "hc_types.h" diff --git a/hals/src/linux/hc_init_protection.c b/deps_adapter/os_adapter/impl/src/linux/hc_init_protection.c similarity index 87% rename from hals/src/linux/hc_init_protection.c rename to deps_adapter/os_adapter/impl/src/linux/hc_init_protection.c index ae92510..28cd2af 100644 --- a/hals/src/linux/hc_init_protection.c +++ b/deps_adapter/os_adapter/impl/src/linux/hc_init_protection.c @@ -18,7 +18,7 @@ static bool g_isInitialized = false; -int CheckInit() +int CheckInit(void) { if (g_isInitialized) { return FINISH_INIT; @@ -26,7 +26,7 @@ int CheckInit() return CONTINUE_INIT; } -int CheckDestroy() +int CheckDestroy(void) { if (!g_isInitialized) { return FINISH_DESTROY; @@ -34,12 +34,12 @@ int CheckDestroy() return CONTINUE_DESTROY; } -void SetInitStatus() +void SetInitStatus(void) { g_isInitialized = true; } -void SetDeInitStatus() +void SetDeInitStatus(void) { g_isInitialized = false; } \ No newline at end of file diff --git a/hals/src/linux/hc_mutex.c b/deps_adapter/os_adapter/impl/src/linux/hc_mutex.c similarity index 100% rename from hals/src/linux/hc_mutex.c rename to deps_adapter/os_adapter/impl/src/linux/hc_mutex.c diff --git a/hals/src/linux/hc_thread.c b/deps_adapter/os_adapter/impl/src/linux/hc_thread.c similarity index 100% rename from hals/src/linux/hc_thread.c rename to deps_adapter/os_adapter/impl/src/linux/hc_thread.c diff --git a/hals/src/linux/hc_time.c b/deps_adapter/os_adapter/impl/src/linux/hc_time.c similarity index 100% rename from hals/src/linux/hc_time.c rename to deps_adapter/os_adapter/impl/src/linux/hc_time.c diff --git a/hals/src/linux/hc_types.c b/deps_adapter/os_adapter/impl/src/linux/hc_types.c similarity index 100% rename from hals/src/linux/hc_types.c rename to deps_adapter/os_adapter/impl/src/linux/hc_types.c diff --git a/hals/src/liteos/hc_condition.c b/deps_adapter/os_adapter/impl/src/liteos/hc_condition.c similarity index 100% rename from hals/src/liteos/hc_condition.c rename to deps_adapter/os_adapter/impl/src/liteos/hc_condition.c diff --git a/hals/src/liteos/hc_file.c b/deps_adapter/os_adapter/impl/src/liteos/hc_file.c similarity index 100% rename from hals/src/liteos/hc_file.c rename to deps_adapter/os_adapter/impl/src/liteos/hc_file.c diff --git a/hals/src/liteos/hc_mutex.c b/deps_adapter/os_adapter/impl/src/liteos/hc_mutex.c similarity index 100% rename from hals/src/liteos/hc_mutex.c rename to deps_adapter/os_adapter/impl/src/liteos/hc_mutex.c diff --git a/hals/src/liteos/hc_thread.c b/deps_adapter/os_adapter/impl/src/liteos/hc_thread.c similarity index 100% rename from hals/src/liteos/hc_thread.c rename to deps_adapter/os_adapter/impl/src/liteos/hc_thread.c diff --git a/hals/src/liteos/hc_time.c b/deps_adapter/os_adapter/impl/src/liteos/hc_time.c similarity index 100% rename from hals/src/liteos/hc_time.c rename to deps_adapter/os_adapter/impl/src/liteos/hc_time.c diff --git a/hals/src/liteos/hc_types.c b/deps_adapter/os_adapter/impl/src/liteos/hc_types.c similarity index 100% rename from hals/src/liteos/hc_types.c rename to deps_adapter/os_adapter/impl/src/liteos/hc_types.c diff --git a/hals/src/liteos/L0/hc_file.c b/deps_adapter/os_adapter/impl/src/liteos/mini/hc_file.c similarity index 95% rename from hals/src/liteos/L0/hc_file.c rename to deps_adapter/os_adapter/impl/src/liteos/mini/hc_file.c index d9e33f9..2900792 100644 --- a/hals/src/liteos/L0/hc_file.c +++ b/deps_adapter/os_adapter/impl/src/liteos/mini/hc_file.c @@ -18,7 +18,6 @@ #include #include #include -#include "common_defs.h" #include "hc_error.h" #include "hc_log.h" #include "utils_file.h" diff --git a/hals/src/liteos/L0/hc_init_protection.c b/deps_adapter/os_adapter/impl/src/liteos/mini/hc_init_protection.c similarity index 89% rename from hals/src/liteos/L0/hc_init_protection.c rename to deps_adapter/os_adapter/impl/src/liteos/mini/hc_init_protection.c index 6d54ab1..b7d3dbc 100644 --- a/hals/src/liteos/L0/hc_init_protection.c +++ b/deps_adapter/os_adapter/impl/src/liteos/mini/hc_init_protection.c @@ -23,7 +23,7 @@ static HcMutex g_countMutex; static int g_singleCount = 0; -int CheckInit() +int CheckInit(void) { g_countMutex.lock(&g_countMutex); if (g_singleCount < 0) { @@ -37,7 +37,7 @@ int CheckInit() return CONTINUE_INIT; } -int CheckDestroy() +int CheckDestroy(void) { g_countMutex.lock(&g_countMutex); if (g_singleCount == 0) { @@ -58,7 +58,7 @@ int CheckDestroy() return CONTINUE_DESTROY; } -void SetInitStatus() +void SetInitStatus(void) { g_countMutex.lock(&g_countMutex); g_singleCount = 1; @@ -66,7 +66,7 @@ void SetInitStatus() return; } -void SetDeInitStatus() +void SetDeInitStatus(void) { g_countMutex.lock(&g_countMutex); g_singleCount = 0; @@ -74,7 +74,7 @@ void SetDeInitStatus() return; } -void InitSecurityDevAuth() +void InitSecurityDevAuth(void) { int32_t res = InitHcMutex(&g_countMutex); if (res != 0) { @@ -83,7 +83,7 @@ void InitSecurityDevAuth() } SYS_SERVICE_INIT(InitSecurityDevAuth); -void DestroySecurityDevAuth() +void DestroySecurityDevAuth(void) { DestroyHcMutex(&g_countMutex); } \ No newline at end of file diff --git a/hals/src/liteos/L1/hc_init_protection.c b/deps_adapter/os_adapter/impl/src/liteos/small/hc_init_protection.c similarity index 91% rename from hals/src/liteos/L1/hc_init_protection.c rename to deps_adapter/os_adapter/impl/src/liteos/small/hc_init_protection.c index cd270a8..db55a79 100644 --- a/hals/src/liteos/L1/hc_init_protection.c +++ b/deps_adapter/os_adapter/impl/src/liteos/small/hc_init_protection.c @@ -19,7 +19,7 @@ static bool g_isInitialized = false; -int CheckInit() +int CheckInit(void) { if (g_isInitialized) { return FINISH_INIT; @@ -27,7 +27,7 @@ int CheckInit() return CONTINUE_INIT; } -int CheckDestroy() +int CheckDestroy(void) { if (!g_isInitialized) { return FINISH_DESTROY; @@ -35,12 +35,12 @@ int CheckDestroy() return CONTINUE_DESTROY; } -void SetInitStatus() +void SetInitStatus(void) { g_isInitialized = true; } -void SetDeInitStatus() +void SetDeInitStatus(void) { g_isInitialized = false; } \ No newline at end of file diff --git a/hals/inc/dev_info/3516/hc_dev_info.h b/deps_adapter/os_adapter/interfaces/dev_info/3516/hc_dev_info.h similarity index 100% rename from hals/inc/dev_info/3516/hc_dev_info.h rename to deps_adapter/os_adapter/interfaces/dev_info/3516/hc_dev_info.h diff --git a/hals/inc/dev_info/3861/hc_dev_info.h b/deps_adapter/os_adapter/interfaces/dev_info/3861/hc_dev_info.h similarity index 100% rename from hals/inc/dev_info/3861/hc_dev_info.h rename to deps_adapter/os_adapter/interfaces/dev_info/3861/hc_dev_info.h diff --git a/hals/inc/dev_info/watch/hc_dev_info.h b/deps_adapter/os_adapter/interfaces/dev_info/watch/hc_dev_info.h similarity index 100% rename from hals/inc/dev_info/watch/hc_dev_info.h rename to deps_adapter/os_adapter/interfaces/dev_info/watch/hc_dev_info.h diff --git a/hals/inc/common/hc_task_thread.h b/deps_adapter/os_adapter/interfaces/hc_task_thread.h similarity index 100% rename from hals/inc/common/hc_task_thread.h rename to deps_adapter/os_adapter/interfaces/hc_task_thread.h diff --git a/hals/inc/linux/hc_condition.h b/deps_adapter/os_adapter/interfaces/linux/hc_condition.h similarity index 96% rename from hals/inc/linux/hc_condition.h rename to deps_adapter/os_adapter/interfaces/linux/hc_condition.h index d04aec7..915371f 100644 --- a/hals/inc/linux/hc_condition.h +++ b/deps_adapter/os_adapter/interfaces/linux/hc_condition.h @@ -16,9 +16,9 @@ #ifndef HC_CONDITION_H #define HC_CONDITION_H +#include "pthread.h" #include "hc_mutex.h" #include "hc_types.h" -#include "pthread.h" #ifdef __cplusplus extern "C" { diff --git a/hals/inc/linux/hc_file.h b/deps_adapter/os_adapter/interfaces/linux/hc_file.h similarity index 100% rename from hals/inc/linux/hc_file.h rename to deps_adapter/os_adapter/interfaces/linux/hc_file.h diff --git a/hals/inc/liteos/hc_init_protection.h b/deps_adapter/os_adapter/interfaces/linux/hc_init_protection.h similarity index 93% rename from hals/inc/liteos/hc_init_protection.h rename to deps_adapter/os_adapter/interfaces/linux/hc_init_protection.h index 56252fb..a1cc9b3 100644 --- a/hals/inc/liteos/hc_init_protection.h +++ b/deps_adapter/os_adapter/interfaces/linux/hc_init_protection.h @@ -16,8 +16,6 @@ #ifndef HC_INIT_PROTECTION_H #define HC_INIT_PROTECTION_H -#include - typedef enum InitStatusEnum { CONTINUE_INIT = 0, FINISH_INIT, @@ -30,4 +28,4 @@ int CheckDestroy(void); void SetInitStatus(void); void SetDeInitStatus(void); -#endif \ No newline at end of file +#endif \ No newline at end of file diff --git a/hals/inc/linux/hc_log.h b/deps_adapter/os_adapter/interfaces/linux/hc_log.h similarity index 100% rename from hals/inc/linux/hc_log.h rename to deps_adapter/os_adapter/interfaces/linux/hc_log.h diff --git a/hals/inc/linux/hc_mutex.h b/deps_adapter/os_adapter/interfaces/linux/hc_mutex.h similarity index 96% rename from hals/inc/linux/hc_mutex.h rename to deps_adapter/os_adapter/interfaces/linux/hc_mutex.h index e4b905f..fb11a50 100644 --- a/hals/inc/linux/hc_mutex.h +++ b/deps_adapter/os_adapter/interfaces/linux/hc_mutex.h @@ -16,8 +16,8 @@ #ifndef HC_MUTEX_H #define HC_MUTEX_H -#include "pthread.h" #include +#include "pthread.h" #ifdef __cplusplus extern "C" { diff --git a/hals/inc/linux/hc_thread.h b/deps_adapter/os_adapter/interfaces/linux/hc_thread.h similarity index 100% rename from hals/inc/linux/hc_thread.h rename to deps_adapter/os_adapter/interfaces/linux/hc_thread.h diff --git a/hals/inc/linux/hc_time.h b/deps_adapter/os_adapter/interfaces/linux/hc_time.h similarity index 100% rename from hals/inc/linux/hc_time.h rename to deps_adapter/os_adapter/interfaces/linux/hc_time.h diff --git a/hals/inc/linux/hc_types.h b/deps_adapter/os_adapter/interfaces/linux/hc_types.h similarity index 100% rename from hals/inc/linux/hc_types.h rename to deps_adapter/os_adapter/interfaces/linux/hc_types.h diff --git a/hals/inc/liteos/hc_condition.h b/deps_adapter/os_adapter/interfaces/liteos/hc_condition.h similarity index 96% rename from hals/inc/liteos/hc_condition.h rename to deps_adapter/os_adapter/interfaces/liteos/hc_condition.h index 09e13c7..c63f0e9 100644 --- a/hals/inc/liteos/hc_condition.h +++ b/deps_adapter/os_adapter/interfaces/liteos/hc_condition.h @@ -16,9 +16,9 @@ #ifndef HC_CONDITION_H #define HC_CONDITION_H +#include #include "hc_mutex.h" #include "hc_types.h" -#include typedef struct HcConditionT { int (*wait)(struct HcConditionT*); diff --git a/hals/inc/liteos/hc_file.h b/deps_adapter/os_adapter/interfaces/liteos/hc_file.h similarity index 100% rename from hals/inc/liteos/hc_file.h rename to deps_adapter/os_adapter/interfaces/liteos/hc_file.h diff --git a/hals/inc/linux/hc_init_protection.h b/deps_adapter/os_adapter/interfaces/liteos/hc_init_protection.h similarity index 93% rename from hals/inc/linux/hc_init_protection.h rename to deps_adapter/os_adapter/interfaces/liteos/hc_init_protection.h index 56252fb..a1cc9b3 100644 --- a/hals/inc/linux/hc_init_protection.h +++ b/deps_adapter/os_adapter/interfaces/liteos/hc_init_protection.h @@ -16,8 +16,6 @@ #ifndef HC_INIT_PROTECTION_H #define HC_INIT_PROTECTION_H -#include - typedef enum InitStatusEnum { CONTINUE_INIT = 0, FINISH_INIT, @@ -30,4 +28,4 @@ int CheckDestroy(void); void SetInitStatus(void); void SetDeInitStatus(void); -#endif \ No newline at end of file +#endif \ No newline at end of file diff --git a/hals/inc/liteos/hc_log.h b/deps_adapter/os_adapter/interfaces/liteos/hc_log.h similarity index 100% rename from hals/inc/liteos/hc_log.h rename to deps_adapter/os_adapter/interfaces/liteos/hc_log.h diff --git a/hals/inc/liteos/hc_mutex.h b/deps_adapter/os_adapter/interfaces/liteos/hc_mutex.h similarity index 96% rename from hals/inc/liteos/hc_mutex.h rename to deps_adapter/os_adapter/interfaces/liteos/hc_mutex.h index 8859dd6..a166590 100644 --- a/hals/inc/liteos/hc_mutex.h +++ b/deps_adapter/os_adapter/interfaces/liteos/hc_mutex.h @@ -16,8 +16,8 @@ #ifndef HC_MUTEX_H #define HC_MUTEX_H -#include "pthread.h" #include +#include "pthread.h" typedef struct HcMutexT { int (*lock)(struct HcMutexT* mutex); diff --git a/hals/inc/liteos/hc_thread.h b/deps_adapter/os_adapter/interfaces/liteos/hc_thread.h similarity index 100% rename from hals/inc/liteos/hc_thread.h rename to deps_adapter/os_adapter/interfaces/liteos/hc_thread.h diff --git a/hals/inc/liteos/hc_time.h b/deps_adapter/os_adapter/interfaces/liteos/hc_time.h similarity index 100% rename from hals/inc/liteos/hc_time.h rename to deps_adapter/os_adapter/interfaces/liteos/hc_time.h diff --git a/hals/inc/liteos/hc_types.h b/deps_adapter/os_adapter/interfaces/liteos/hc_types.h similarity index 100% rename from hals/inc/liteos/hc_types.h rename to deps_adapter/os_adapter/interfaces/liteos/hc_types.h diff --git a/deviceauth_env.gni b/deviceauth_env.gni index f6a843c..0ee011b 100644 --- a/deviceauth_env.gni +++ b/deviceauth_env.gni @@ -12,7 +12,14 @@ # limitations under the License. deviceauth_path = "//base/security/deviceauth" +common_lib_path = "${deviceauth_path}/common_lib" +deps_adapter_path = "${deviceauth_path}/deps_adapter" +key_management_adapter_path = + "${deviceauth_path}/deps_adapter/key_management_adapter" +os_adapter_path = "${deviceauth_path}/deps_adapter/os_adapter" + hals_path = "${deviceauth_path}/hals" + innerkits_path = "${deviceauth_path}/interfaces/innerkits" frameworks_path = "${deviceauth_path}/frameworks" services_path = "${deviceauth_path}/services" diff --git a/hals/deviceauth_hals.gni b/hals/deviceauth_hals.gni deleted file mode 100644 index fef1a53..0000000 --- a/hals/deviceauth_hals.gni +++ /dev/null @@ -1,42 +0,0 @@ -# Copyright (C) 2021 Huawei Device Co., Ltd. -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import("//base/security/deviceauth/deviceauth_env.gni") - -if (target_os == "liteos" || - (defined(ohos_lite) && ohos_kernel_type == "liteos_m")) { - hals_inc_path = [ - "${hals_path}/inc/common", - "${hals_path}/inc/liteos", - "${hals_path}/inc/dev_info/3861", - ] - hal_module_name = "deviceauth_hal_liteos" -} else { - hals_inc_path = [ - "${hals_path}/inc/common", - "${hals_path}/inc/linux", - "${hals_path}/inc/dev_info/3516", - ] - hal_module_name = "deviceauth_hal_linux" -} - -hal_common_files = [ - "src/common/hc_parcel.c", - "src/common/hc_string.c", - "src/common/hc_task_thread.c", - "src/common/hc_tlv_parser.c", - "src/common/json_utils.c", - "src/common/common_util.c", - "src/common/alg_loader.c", - "src/common/hc_log.c", -] diff --git a/services/BUILD.gn b/services/BUILD.gn index acdb0f3..dffa753 100644 --- a/services/BUILD.gn +++ b/services/BUILD.gn @@ -16,7 +16,7 @@ if (defined(ohos_lite)) { } else { import("//build/ohos.gni") } -import("//base/security/deviceauth/hals/deviceauth_hals.gni") +import("//base/security/deviceauth/deps_adapter/deviceauth_hals.gni") import("deviceauth.gni") if (defined(ohos_lite)) { @@ -47,7 +47,7 @@ if (defined(ohos_lite)) { } deps = [ - "${hals_path}:${hal_module_name}", + "${deps_adapter_path}:${hal_module_name}", "//build/lite/config/component/cJSON:cjson_shared", "//utils/native/lite:utils", ] @@ -90,7 +90,7 @@ if (defined(ohos_lite)) { deps = [ ":deviceauth", - "${hals_path}:${hal_module_name}", + "${deps_adapter_path}:${hal_module_name}", "//base/hiviewdfx/hilog_lite/frameworks/featured:hilog_shared", "//build/lite/config/component/cJSON:cjson_shared", "//foundation/communication/ipc_lite:liteipc_adapter", @@ -124,7 +124,7 @@ if (defined(ohos_lite)) { cflags += [ "-fPIC" ] deps = [ - "${hals_path}:${hal_module_name}", + "${deps_adapter_path}:${hal_module_name}", "//base/hiviewdfx/hilog_lite/frameworks/featured:hilog_shared", "//foundation/communication/ipc_lite:liteipc_adapter", "//foundation/distributedschedule/samgr_lite/samgr:samgr", @@ -158,7 +158,7 @@ if (defined(ohos_lite)) { } deps = [ - "${hals_path}:${hal_module_name}", + "${deps_adapter_path}:${hal_module_name}", "//third_party/cJSON:cjson_static", "//utils/native/base:utils", ] @@ -209,7 +209,7 @@ if (defined(ohos_lite)) { deps = [ ":auth_service.rc", ":deviceauth", - "${hals_path}:${hal_module_name}", + "${deps_adapter_path}:${hal_module_name}", "//third_party/cJSON:cjson_static", "//utils/native/base:utils", ] @@ -251,7 +251,7 @@ if (defined(ohos_lite)) { } deps = [ - "${hals_path}:${hal_module_name}", + "${deps_adapter_path}:${hal_module_name}", "//third_party/cJSON:cjson_static", "//utils/native/base:utils", ] diff --git a/test/unittest/deviceauth/BUILD.gn b/test/unittest/deviceauth/BUILD.gn index c0f8249..9bea85f 100644 --- a/test/unittest/deviceauth/BUILD.gn +++ b/test/unittest/deviceauth/BUILD.gn @@ -11,7 +11,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -import("//base/security/deviceauth/hals/deviceauth_hals.gni") +import("//base/security/deviceauth/deps_adapter/deviceauth_hals.gni") import("//base/security/deviceauth/services/deviceauth.gni") import("//build/test.gni") @@ -31,22 +31,22 @@ ohos_unittest("deviceauth_llt") { include_dirs += hals_inc_path sources = [ - "${hals_path}/src/common/alg_loader.c", - "${hals_path}/src/common/common_util.c", - "${hals_path}/src/common/hc_parcel.c", - "${hals_path}/src/common/hc_string.c", - "${hals_path}/src/common/hc_task_thread.c", - "${hals_path}/src/common/hc_tlv_parser.c", - "${hals_path}/src/common/json_utils.c", - "${hals_path}/src/linux/standard/crypto_hash_to_point.c", - "${hals_path}/src/linux/standard/huks_adapter.c", - "${hals_path}/src/linux/hc_condition.c", - "${hals_path}/src/linux/hc_file.c", - "${hals_path}/src/linux/hc_init_protection.c", - "${hals_path}/src/linux/hc_mutex.c", - "${hals_path}/src/linux/hc_thread.c", - "${hals_path}/src/linux/hc_time.c", - "${hals_path}/src/linux/hc_types.c", + "${common_lib_path}/impl/src/common_util.c", + "${common_lib_path}/impl/src/hc_parcel.c", + "${common_lib_path}/impl/src/hc_string.c", + "${common_lib_path}/impl/src/hc_tlv_parser.c", + "${common_lib_path}/impl/src/json_utils.c", + "${key_management_adapter_path}/impl/src/alg_loader.c", + "${key_management_adapter_path}/impl/src/standard/crypto_hash_to_point.c", + "${key_management_adapter_path}/impl/src/standard/huks_adapter.c", + "${os_adapter_path}/impl/src/hc_task_thread.c", + "${os_adapter_path}/impl/src/linux/hc_condition.c", + "${os_adapter_path}/impl/src/linux/hc_file.c", + "${os_adapter_path}/impl/src/linux/hc_init_protection.c", + "${os_adapter_path}/impl/src/linux/hc_mutex.c", + "${os_adapter_path}/impl/src/linux/hc_thread.c", + "${os_adapter_path}/impl/src/linux/hc_time.c", + "${os_adapter_path}/impl/src/linux/hc_types.c", ] sources += deviceauth_files sources += [ @@ -64,7 +64,7 @@ ohos_unittest("deviceauth_llt") { ] external_deps = [ - "hiviewdfx_hilog_native:libhilog", "dsoftbus_standard:softbus_client", + "hiviewdfx_hilog_native:libhilog", ] }