adjust header file for hal

Signed-off-by: winnieHu <huyu35@huawei.com>
This commit is contained in:
winnieHu
2021-11-15 16:52:54 +08:00
parent 69aaa25c8e
commit cd862b5ab6
49 changed files with 53 additions and 313 deletions
+1 -1
View File
@@ -19,7 +19,7 @@
#include <securec.h>
#include "clib_error.h"
#include "clib_types.h"
#include "common_util.h"
#include "string_util.h"
#define RECURSE_FLAG_TRUE 1
@@ -13,7 +13,7 @@
* limitations under the License.
*/
#include "common_util.h"
#include "string_util.h"
#include <stdlib.h>
#include <string.h>
#include <securec.h>
@@ -13,8 +13,8 @@
* limitations under the License.
*/
#ifndef COMMON_UTIL_H
#define COMMON_UTIL_H
#ifndef STRING_UTIL_H
#define STRING_UTIL_H
#include <stdint.h>
+3 -9
View File
@@ -34,11 +34,9 @@ if (defined(ohos_lite)) {
sources = hal_common_files
sources += [
"${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_dev_info.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",
@@ -70,13 +68,11 @@ if (defined(ohos_lite)) {
sources += [
"${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_dev_info.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",
]
@@ -111,13 +107,11 @@ if (defined(ohos_lite)) {
sources += [
"${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_dev_info.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" ]
+4 -4
View File
@@ -21,7 +21,6 @@ if (target_os == "liteos" ||
"${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 {
@@ -31,7 +30,6 @@ if (target_os == "liteos" ||
"${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"
}
@@ -42,9 +40,11 @@ hal_common_files = [
"${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",
"${common_lib_path}/impl/src/string_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",
"${os_adapter_path}/impl/src/hc_mutex.c",
"${os_adapter_path}/impl/src/hc_task_thread.c",
"${os_adapter_path}/impl/src/hc_time.c",
]
@@ -17,7 +17,7 @@
#define MBEDTLS_HASH_TO_POINT_H
#include <stdint.h>
#include "common_util.h"
#include "string_util.h"
#define HASH2POINT_PARA_PREPRO 0xc0
#define BYTE_LENGTH_CURVE_25519 32
@@ -14,13 +14,13 @@
*/
#include "huks_adapter.h"
#include "common_util.h"
#include "hal_error.h"
#include "hc_file.h"
#include "hc_log.h"
#include "hks_api.h"
#include "hks_param.h"
#include "hks_type.h"
#include "string_util.h"
static int32_t BaseCheckParams(const Uint8Buff **inParams, const char **paramTags, uint32_t len)
{
@@ -14,12 +14,12 @@
*/
#include "huks_adapter.h"
#include "common_util.h"
#include "hc_log.h"
#include "hks_api.h"
#include "hks_param.h"
#include "hks_type.h"
#include "mbedtls_hash_to_point.h"
#include "string_util.h"
static enum HksKeyAlg g_algToHksAlgorithm[] = {
HKS_ALG_ED25519,
@@ -14,12 +14,12 @@
*/
#include "huks_adapter.h"
#include "common_util.h"
#include "crypto_hash_to_point.h"
#include "hc_log.h"
#include "hks_api.h"
#include "hks_param.h"
#include "hks_type.h"
#include "string_util.h"
static enum HksKeyAlg g_algToHksAlgorithm[] = {
HKS_ALG_ED25519,
@@ -16,8 +16,8 @@
#ifndef ALG_DEFS_H
#define ALG_DEFS_H
#include "common_util.h"
#include "hc_types.h"
#include "string_util.h"
#define SHA256_LEN 32
#define HMAC_LEN 32
@@ -15,6 +15,10 @@
#include "hc_mutex.h"
#ifdef __cplusplus
extern "C" {
#endif
static int HcMutexLock(HcMutex *mutex)
{
if (mutex == NULL) {
@@ -51,4 +55,8 @@ void DestroyHcMutex(struct HcMutexT *mutex)
return;
}
pthread_mutex_destroy(&mutex->mutex);
}
}
#ifdef __cplusplus
}
#endif
@@ -1,62 +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.
*/
#include "hc_mutex.h"
#ifdef __cplusplus
extern "C" {
#endif
int MutexLock(HcMutex* mutex)
{
if (mutex == NULL) {
return -1;
}
return -pthread_mutex_lock(&mutex->mutex);
}
void MutexUnlock(HcMutex* mutex)
{
if (mutex == NULL) {
return;
}
pthread_mutex_unlock(&mutex->mutex);
}
int32_t InitHcMutex(struct HcMutexT* mutex)
{
if (mutex == NULL) {
return -1;
}
int res = pthread_mutex_init(&mutex->mutex, NULL);
if (res != 0) {
return res;
}
mutex->lock = MutexLock;
mutex->unlock = MutexUnlock;
return res;
}
void DestroyHcMutex(struct HcMutexT* mutex)
{
if (mutex == NULL) {
return;
}
pthread_mutex_destroy(&mutex->mutex);
}
#ifdef __cplusplus
}
#endif
@@ -51,24 +51,6 @@ uint32_t HcStrlen(const char *str)
return p - str - 1;
}
const char *HcFmtLogData(const char *funName, char *out, int32_t outSz, const char *fmtStr, ...)
{
int32_t ret;
int32_t cnt;
int32_t n = 0;
va_list arglist;
cnt = sprintf_s(out, outSz, "%s: ", funName);
if (cnt <= 0) {
return NULL;
}
n += cnt;
va_start(arglist, fmtStr);
ret = vsprintf_s(out + n, outSz - n, fmtStr, arglist);
va_end(arglist);
return (ret > 0) ? ((const char *)out) : NULL;
}
#ifdef __cplusplus
}
#endif
@@ -1,49 +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.
*/
#include "hc_time.h"
#include <stdio.h>
#include <time.h>
#include "hc_log.h"
int64_t HcGetCurTime()
{
struct timespec start;
int res = clock_gettime(CLOCK_MONOTONIC, &start);
if (res != 0) {
LOGE("clock_gettime failed, res:%d", res);
return -1;
}
return start.tv_sec;
}
int64_t HcGetIntervalTime(int64_t startTime)
{
if (startTime < 0) {
LOGE("Start time is invalid");
return -1;
}
struct timespec end;
int res = clock_gettime(CLOCK_MONOTONIC, &end);
if (res != 0) {
LOGE("clock_gettime failed, res:%d", res);
return -1;
}
if (end.tv_sec < startTime) {
LOGE("End time is invalid");
return -1;
}
return (end.tv_sec - startTime);
}
@@ -1,43 +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.
*/
#ifndef HC_DEV_INFO_H
#define HC_DEV_INFO_H
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
#define INPUT_UDID_LEN 65
#define MAX_INPUT_UDID_LEN 200
#define MAX_SESSION_COUNT 20
/*
* Get the unique device ID of the device(UDID).
* udid: It is used to store the UDID finally obtained.
* udidLen: The size of array to store UDID. Its value is the real udid size + 1 (including '\0').
* In liteos and linux, the udidLen must be 65.
* Return 0 if the UDID is successfully obtained, other returns an error code.
*/
int32_t HcGetUdid(uint8_t *udid, int32_t udidLen);
const char *GetStoragePath(void);
#ifdef __cplusplus
}
#endif
#endif
@@ -1,31 +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.
*/
#ifndef HC_MUTEX_H
#define HC_MUTEX_H
#include <stdint.h>
#include "pthread.h"
typedef struct HcMutexT {
int (*lock)(struct HcMutexT* mutex);
void (*unlock)(struct HcMutexT* mutex);
pthread_mutex_t mutex;
} HcMutex;
int32_t InitHcMutex(HcMutex* mutex);
void DestroyHcMutex(HcMutex* mutex);
#endif
@@ -1,30 +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.
*/
#ifndef HC_TIME_H
#define HC_TIME_H
#include <stdint.h>
/* Calculate in seconds */
#define TIME_OUT_VALUE 600
/* Return in seconds */
int64_t HcGetCurTime(void);
/* Return the interval seconds from startTime to current Time */
int64_t HcGetIntervalTime(int64_t startTime);
#endif
@@ -1,29 +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.
*/
#ifndef HC_TYPES_H
#define HC_TYPES_H
#include <string.h>
#include <stdbool.h>
#include <stdlib.h>
#include <stdint.h>
#include <securec.h>
void *HcMalloc(uint32_t size, char val);
void HcFree(void *addr);
uint32_t HcStrlen(const char *str);
#endif
@@ -17,7 +17,7 @@
#define DATABASE_MANAGER_H
#include "common_defs.h"
#include "common_util.h"
#include "string_util.h"
#include "database.h"
#define HC_TRUST_DEV_ENTRY_MAX_NUM 101
@@ -16,7 +16,7 @@
#ifndef GROUP_OPERATION_COMMON_H
#define GROUP_OPERATION_COMMON_H
#include "common_util.h"
#include "string_util.h"
#include "database.h"
#include "json_utils.h"
@@ -16,7 +16,7 @@
#include "group_operation_common.h"
#include "alg_loader.h"
#include "common_util.h"
#include "string_util.h"
#include "database_manager.h"
#include "dev_auth_module_manager.h"
#include "group_operation.h"
@@ -18,7 +18,7 @@
#include "alg_defs.h"
#include "callback_manager.h"
#include "channel_manager.h"
#include "common_util.h"
#include "string_util.h"
#include "database_manager.h"
#include "group_operation_common.h"
#include "hc_dev_info.h"
+1 -1
View File
@@ -16,10 +16,10 @@
#ifndef DAS_COMMON_H
#define DAS_COMMON_H
#include "common_util.h"
#include "das_module_defines.h"
#include "hc_types.h"
#include "json_utils.h"
#include "string_util.h"
int32_t GenerateKeyAlias(const Uint8Buff *pkgName, const Uint8Buff *serviceType, const KeyAliasType keyType,
const Uint8Buff *authId, Uint8Buff *outKeyAlias);
+1 -1
View File
@@ -17,7 +17,7 @@
#define DAS_MODULE_H
#include "common_defs.h"
#include "common_util.h"
#include "string_util.h"
bool IsDasSupported(void);
@@ -16,8 +16,8 @@
#ifndef DEV_AUTH_MODULE_MANAGER_H
#define DEV_AUTH_MODULE_MANAGER_H
#include "common_util.h"
#include "json_utils.h"
#include "string_util.h"
#ifdef __cplusplus
extern "C" {
+1 -1
View File
@@ -16,7 +16,7 @@
#ifndef MODULE_COMMON_H
#define MODULE_COMMON_H
#include "common_util.h"
#include "string_util.h"
int32_t InitSingleParam(Uint8Buff *param, uint32_t len);
@@ -16,7 +16,7 @@
#ifndef PROTOCOL_COMMON_H
#define PROTOCOL_COMMON_H
#include "common_util.h"
#include "string_util.h"
typedef enum {
UNSUPPORTED_ALG = 0x0000,
@@ -21,7 +21,7 @@
#include <stdint.h>
#include "common_defs.h"
#include "common_util.h"
#include "string_util.h"
#include "auth_common.h"
#define FILE_VERSION 0x01
@@ -18,8 +18,8 @@
#include "alg_defs.h"
#include "auth_common.h"
#include "common_util.h"
#include "pake_protocol_common.h"
#include "string_util.h"
typedef enum {
TASK_TYPE_DEFAULT = 0,
+1 -1
View File
@@ -16,10 +16,10 @@
#include "das_common.h"
#include "alg_defs.h"
#include "alg_loader.h"
#include "common_util.h"
#include "hc_log.h"
#include "hc_types.h"
#include "module_common.h"
#include "string_util.h"
#define KEY_TYPE_PAIR_LEN 2
#define PACKAGE_NAME_MAX_LEN 256
@@ -15,10 +15,10 @@
#include "das_version_util.h"
#include "common_defs.h"
#include "common_util.h"
#include "hc_log.h"
#include "hc_types.h"
#include "json_utils.h"
#include "string_util.h"
#define BIND_PRIORITY_LEN 5
#define AUTH_PRIORITY_LEN 5
@@ -14,11 +14,11 @@
*/
#include "iso_server_unbind_exchange_task.h"
#include "common_util.h"
#include "das_module_defines.h"
#include "hc_log.h"
#include "hc_types.h"
#include "iso_task_common.h"
#include "string_util.h"
enum {
TASK_TYPE_BEGIN = 1,
@@ -13,13 +13,13 @@
* limitations under the License.
*/
#include "json_utils.h"
#include "common_util.h"
#include "das_common.h"
#include "hc_log.h"
#include "json_utils.h"
#include "module_common.h"
#include "pake_base_cur_task.h"
#include "protocol_common.h"
#include "string_util.h"
int32_t ParseStartJsonParams(PakeParams *params, const CJson *in)
{
@@ -14,7 +14,6 @@
*/
#include "pake_task_common.h"
#include "common_util.h"
#include "das_asy_token_manager.h"
#include "das_common.h"
#include "das_module_defines.h"
@@ -23,6 +22,7 @@
#include "module_common.h"
#include "protocol_common.h"
#include "standard_client_bind_exchange_task.h"
#include "string_util.h"
#define ASCII_CASE_DIFFERENCE_VALUE 32
@@ -14,14 +14,14 @@
*/
#include "common_standard_bind_exchange.h"
#include "securec.h"
#include "alg_defs.h"
#include "common_util.h"
#include "das_asy_token_manager.h"
#include "das_common.h"
#include "hc_log.h"
#include "hc_types.h"
#include "module_common.h"
#include "securec.h"
#include "string_util.h"
int32_t InitStandardBindExchangeParams(StandardBindExchangeParams *params)
{
@@ -15,12 +15,12 @@
#include "standard_exchange_message_util.h"
#include "common_defs.h"
#include "common_util.h"
#include "hc_log.h"
#include "hc_types.h"
#include "json_utils.h"
#include "module_common.h"
#include "pake_base_cur_task.h"
#include "string_util.h"
int32_t PackageNonceAndCipherToJson(const Uint8Buff *nonce, const Uint8Buff *cipher, CJson *data, const char *key)
{
+2 -2
View File
@@ -14,11 +14,11 @@
*/
#include "version_util.h"
#include "common_util.h"
#include "securec.h"
#include "hc_log.h"
#include "hc_types.h"
#include "protocol_common.h"
#include "securec.h"
#include "string_util.h"
static const char *Split(char *str, char delim, int *next)
{
@@ -19,7 +19,7 @@
#include "alg_defs.h"
#include "auth_session_util.h"
#include "common_defs.h"
#include "common_util.h"
#include "string_util.h"
#include "database_manager.h"
#include "dev_auth_module_manager.h"
#include "hc_log.h"
@@ -19,9 +19,9 @@
#include "alg_loader.h"
#include "auth_session_common_defines.h"
#include "common_defs.h"
#include "common_util.h"
#include "device_auth_defines.h"
#include "hc_log.h"
#include "string_util.h"
static int32_t AuthFormToModuleType(int32_t authForm)
{
@@ -15,7 +15,7 @@
#include "auth_session_common_util.h"
#include "common_defs.h"
#include "common_util.h"
#include "string_util.h"
#include "device_auth_defines.h"
#include "hc_log.h"
#include "hc_types.h"
+3 -3
View File
@@ -32,21 +32,21 @@ ohos_unittest("deviceauth_llt") {
sources = [
"${common_lib_path}/impl/src/clib_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",
"${common_lib_path}/impl/src/string_util.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_mutex.c",
"${os_adapter_path}/impl/src/hc_task_thread.c",
"${os_adapter_path}/impl/src/hc_time.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