1# Copyright (C) 2021-2023 Huawei Device Co., Ltd.
2# Licensed under the Apache License, Version 2.0 (the "License");
3# you may not use this file except in compliance with the License.
4# You may obtain a copy of the License at
5#
6#     http://www.apache.org/licenses/LICENSE-2.0
7#
8# Unless required by applicable law or agreed to in writing, software
9# distributed under the License is distributed on an "AS IS" BASIS,
10# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11# See the License for the specific language governing permissions and
12# limitations under the License.
13
14if (defined(ohos_lite)) {
15  import("//build/lite/config/component/lite_component.gni")
16} else {
17  import("//build/ohos.gni")
18}
19import("deviceauth_hals.gni")
20
21if (defined(ohos_lite)) {
22  if (ohos_kernel_type == "liteos_m") {
23    static_library("deviceauth_hal_liteos") {
24      include_dirs = hals_inc_path
25      include_dirs += [
26        "//base/security/device_auth/interfaces/inner_api",
27        "//third_party/cJSON",
28        "//commonlibrary/utils_lite/include",
29        "//base/hiviewdfx/hilog_lite/interfaces/native/kits/hilog_lite",
30        "//commonlibrary/utils_lite/memory/include",
31        "//base/startup/init/interfaces/innerkits/include/syspara",
32        "//third_party/mbedtls/include",
33      ]
34
35      sources = hal_common_files
36      sources += [
37        "${key_management_adapter_path}/impl/src/common/mbedtls_ec_adapter.c",
38        "${key_management_adapter_path}/impl/src/huks_adapter.c",
39        "${key_management_adapter_path}/impl/src/mini/huks_adapter_diff_impl.c",
40        "${os_adapter_path}/impl/src/liteos/hc_condition.c",
41        "${os_adapter_path}/impl/src/liteos/hc_dev_info.c",
42        "${os_adapter_path}/impl/src/liteos/hc_thread.c",
43        "${os_adapter_path}/impl/src/liteos/hc_types.c",
44        "${os_adapter_path}/impl/src/liteos/mini/hc_init_protection.c",
45      ]
46
47      if (device_auth_enable_posix_interface) {
48        sources += [ "${os_adapter_path}/impl/src/liteos/mini/hc_file_posix.c" ]
49      } else {
50        sources += [ "${os_adapter_path}/impl/src/liteos/mini/hc_file.c" ]
51      }
52
53      cflags = [ "-DHILOG_ENABLE" ]
54      cflags += [ "-DAUTH_STORAGE_PATH=\"${device_auth_storage_path}\"" ]
55      if (board_toolchain_type == "iccarm") {
56        cflags += [
57          "--diag_suppress",
58          "Pe223,Pe226",
59          "-DOHOS_MEM",
60          "-DSET_THREAD_NAME",
61        ]
62      } else {
63        cflags += build_flags
64      }
65      deps = [
66        "//base/security/huks/interfaces/inner_api/huks_lite:huks_3.0_sdk",
67        "//base/startup/init/interfaces/innerkits:libbegetutil",
68        "//build/lite/config/component/cJSON:cjson_shared",
69        "//commonlibrary/utils_lite:utils",
70        "//third_party/mbedtls:mbedtls_shared",
71      ]
72    }
73  } else {
74    static_library("deviceauth_hal_linux") {
75      include_dirs = hals_inc_path
76      include_dirs += [
77        "//base/security/device_auth/interfaces/inner_api",
78        "//third_party/cJSON",
79        "//commonlibrary/utils_lite/include",
80        "//base/hiviewdfx/hilog_lite/interfaces/native/innerkits/hilog",
81        "//third_party/bounds_checking_function/include",
82        "//base/startup/init/interfaces/innerkits/include/syspara",
83        "//third_party/mbedtls/include",
84      ]
85
86      sources = hal_common_files
87      sources += [
88        "${key_management_adapter_path}/impl/src/common/mbedtls_ec_adapter.c",
89        "${key_management_adapter_path}/impl/src/huks_adapter.c",
90        "${key_management_adapter_path}/impl/src/small/huks_adapter_diff_impl.c",
91        "${os_adapter_path}/impl/src/hc_log.c",
92        "${os_adapter_path}/impl/src/linux/hc_condition.c",
93        "${os_adapter_path}/impl/src/linux/hc_dev_info.c",
94        "${os_adapter_path}/impl/src/linux/hc_file.c",
95        "${os_adapter_path}/impl/src/linux/hc_init_protection.c",
96        "${os_adapter_path}/impl/src/linux/hc_thread.c",
97        "${os_adapter_path}/impl/src/linux/hc_types.c",
98      ]
99
100      defines = []
101      if (enable_extend_plugin) {
102        defines += [ "DEV_AUTH_PLUGIN_ENABLE" ]
103        sources += [
104          "${os_adapter_path}/impl/src/liteos/small/dev_auth_dynamic_load.c",
105        ]
106      }
107
108      cflags = build_flags
109      cflags += [ "-DHILOG_ENABLE" ]
110      defines += [ "LITE_DEVICE" ]
111      deps = [
112        "//base/hiviewdfx/hilog_lite/frameworks/featured:hilog_shared",
113        "//base/security/huks/interfaces/inner_api/huks_lite:huks_3.0_sdk",
114        "//base/startup/init/interfaces/innerkits:libbegetutil",
115        "//build/lite/config/component/cJSON:cjson_shared",
116        "//commonlibrary/utils_lite:utils",
117        "//third_party/bounds_checking_function:libsec_shared",
118        "//third_party/mbedtls:mbedtls_shared",
119        "//third_party/openssl/ohos_lite:openssl_shared",
120      ]
121    }
122  }
123} else {
124  ohos_static_library("deviceauth_hal_linux") {
125    subsystem_name = "security"
126    part_name = "device_auth"
127    include_dirs = hals_inc_path
128
129    sources = hal_common_files
130    sources += [
131      "${key_management_adapter_path}/impl/src/common/mbedtls_ec_adapter.c",
132      "${key_management_adapter_path}/impl/src/huks_adapter.c",
133      "${key_management_adapter_path}/impl/src/standard/crypto_hash_to_point.c",
134      "${key_management_adapter_path}/impl/src/standard/huks_adapter_diff_impl.c",
135      "${os_adapter_path}/impl/src/hc_log.c",
136      "${os_adapter_path}/impl/src/linux/hc_condition.c",
137      "${os_adapter_path}/impl/src/linux/hc_dev_info.c",
138      "${os_adapter_path}/impl/src/linux/hc_file.c",
139      "${os_adapter_path}/impl/src/linux/hc_init_protection.c",
140      "${os_adapter_path}/impl/src/linux/hc_thread.c",
141      "${os_adapter_path}/impl/src/linux/hc_types.c",
142    ]
143
144    defines = []
145    defines += [ "DEV_AUTH_ENABLE_CE" ]
146    if (enable_extend_plugin) {
147      defines += [ "DEV_AUTH_PLUGIN_ENABLE" ]
148      sources += [ "${os_adapter_path}/impl/src/linux/dev_auth_dynamic_load.c" ]
149    }
150
151    cflags = build_flags
152    cflags += [
153      "-DHILOG_ENABLE",
154      "-DSET_THREAD_NAME",
155    ]
156    branch_protector_ret = "pac_ret"
157    sanitize = {
158      cfi = true
159      cfi_cross_dso = true
160      integer_overflow = true
161      boundary_sanitize = true
162      ubsan = true
163      debug = false
164    }
165    external_deps = [
166      "bounds_checking_function:libsec_shared",
167      "cJSON:cjson",
168      "c_utils:utils",
169      "hilog:libhilog",
170      "huks:libhukssdk",
171      "init:libbegetutil",
172      "mbedtls:mbedtls_shared",
173      "openssl:libcrypto_shared",
174    ]
175  }
176
177  ohos_static_library("deviceauth_hal_linux_test") {
178    subsystem_name = "security"
179    part_name = "device_auth"
180    include_dirs = hals_inc_path
181
182    sources = hal_common_files
183    sources += [
184      "${key_management_adapter_path}/impl/src/common/mbedtls_ec_adapter.c",
185      "${key_management_adapter_path}/impl/src/huks_adapter.c",
186      "${key_management_adapter_path}/impl/src/standard/crypto_hash_to_point.c",
187      "${key_management_adapter_path}/impl/src/standard/huks_adapter_diff_impl.c",
188      "${os_adapter_path}/impl/src/hc_log.c",
189      "${os_adapter_path}/impl/src/linux/hc_condition.c",
190      "${os_adapter_path}/impl/src/linux/hc_dev_info.c",
191      "${os_adapter_path}/impl/src/linux/hc_file.c",
192      "${os_adapter_path}/impl/src/linux/hc_init_protection.c",
193      "${os_adapter_path}/impl/src/linux/hc_thread.c",
194      "${os_adapter_path}/impl/src/linux/hc_types.c",
195    ]
196
197    defines = []
198    if (enable_extend_plugin) {
199      defines += [ "DEV_AUTH_PLUGIN_ENABLE" ]
200      sources += [ "${os_adapter_path}/impl/src/linux/dev_auth_dynamic_load.c" ]
201    }
202
203    cflags = build_flags
204    cflags += [
205      "-DHILOG_ENABLE",
206      "-DSET_THREAD_NAME",
207    ]
208    branch_protector_ret = "pac_ret"
209    sanitize = {
210      cfi = true
211      cfi_cross_dso = true
212      integer_overflow = true
213      boundary_sanitize = true
214      ubsan = true
215      debug = false
216    }
217    external_deps = [
218      "bounds_checking_function:libsec_shared",
219      "cJSON:cjson",
220      "c_utils:utils",
221      "hilog:libhilog",
222      "huks:libhukssdk",
223      "init:libbegetutil",
224      "mbedtls:mbedtls_shared",
225      "openssl:libcrypto_shared",
226    ]
227  }
228}
229