1# Copyright (C) 2021-2024 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
14import("//base/security/huks/build/config.gni")
15import("//base/security/huks/huks.gni")
16import("//build/ohos.gni")
17
18if (os_level == "standard") {
19  config("huks_config") {
20    include_dirs = [
21      "include",
22      "../crypto_common/include",
23    ]
24    if (huks_use_rkc_in_standard) {
25      include_dirs += [ "//base/security/huks/frameworks/huks_standard/main/crypto_engine/rkc/include" ]
26    }
27    defines = [ "OPENSSL_SUPPRESS_DEPRECATED" ]
28  }
29  ohos_static_library("libhuks_openssl_standard_static") {
30    subsystem_name = "security"
31    part_name = "huks"
32    public_configs = [ ":huks_config" ]
33
34    sources = [
35      "src/hks_openssl_ability.c",
36      "src/hks_openssl_aes.c",
37      "src/hks_openssl_bn.c",
38      "src/hks_openssl_common.c",
39      "src/hks_openssl_curve25519.c",
40      "src/hks_openssl_dh.c",
41      "src/hks_openssl_dsa.c",
42      "src/hks_openssl_ecc.c",
43      "src/hks_openssl_ed25519tox25519.c",
44      "src/hks_openssl_engine.c",
45      "src/hks_openssl_hash.c",
46      "src/hks_openssl_hmac.c",
47      "src/hks_openssl_kdf.c",
48      "src/hks_openssl_rsa.c",
49      "src/hks_openssl_sm2.c",
50      "src/hks_openssl_sm3.c",
51      "src/hks_openssl_sm4.c",
52    ]
53    deps = []
54    defines = []
55    include_dirs = []
56    if (huks_use_rkc_in_standard) {
57      defines += [ "HKS_USE_RKC_IN_STANDARD" ]
58
59      include_dirs += [
60        "//base/security/huks/services/huks_standard/huks_service/main/core/include",
61        "//base/security/huks/services/huks_standard/huks_service/main/hks_storage/include",
62      ]
63      sources += [
64        "../rkc/src/hks_rkc.c",
65        "../rkc/src/hks_rkc_rw.c",
66        "//base/security/huks/services/huks_standard/huks_service/main/hks_storage/src/hks_lock.c",
67        "//base/security/huks/services/huks_standard/huks_service/main/hks_storage/src/hks_storage.c",
68        "//base/security/huks/services/huks_standard/huks_service/main/hks_storage/src/hks_storage_file_lock.c",
69        "//base/security/huks/services/huks_standard/huks_service/main/hks_storage/src/hks_storage_manager.c",
70        "//base/security/huks/services/huks_standard/huks_service/main/hks_storage/src/hks_storage_utils.c",
71        "//base/security/huks/services/huks_standard/huks_service/main/os_dependency/posix/hks_rwlock.c",
72      ]
73
74      # when uks_use_rkc_in_standard and HKS_ENABLE_CLEAN_FILE are enabled at the same time, add the dependency of HDI to the engine
75      if (huks_enable_hdi_in_standard) {
76        sources += [ "//base/security/huks/services/huks_standard/huks_service/main/os_dependency/idl/passthrough/huks_hdi_access.c" ]
77        external_deps += [ "drivers_interface_huks:libhuks_proxy_1.0" ]
78      } else {
79        sources += [
80          "//base/security/huks/services/huks_standard/huks_service/main/os_dependency/idl/passthrough/huks_access.c",
81          "//base/security/huks/services/huks_standard/huks_service/main/os_dependency/idl/passthrough/huks_core_dynamic_hal.c",
82        ]
83      }
84
85      deps += [
86        "//base/security/huks/frameworks/huks_standard/main/os_dependency:libhuks_os_dependency_standard_static",
87        "//base/security/huks/utils/file_operator:libhuks_utils_file_operator_static",
88        "//base/security/huks/utils/mutex:libhuks_utils_mutex_static",
89      ]
90
91      if (huks_enable_upgrade_rkc_v1tov2) {
92        defines += [ "HKS_ENABLE_UPGRADE_RKC_DERIVE_ALG" ]
93        sources += [ "../rkc/src/hks_rkc_v1.c" ]
94      }
95    }
96
97    deps += [ "//base/security/huks/frameworks/huks_standard/main/common:libhuks_common_standard_static" ]
98
99    complete_static_lib = true
100
101    branch_protector_ret = "pac_ret"
102
103    sanitize = {
104      integer_overflow = true
105      cfi = true
106      debug = false
107      cfi_cross_dso = true
108      boundary_sanitize = true
109      ubsan = true
110    }
111    external_deps = [
112      "c_utils:utils",
113      "hilog:libhilog",
114    ]
115    if (huks_dependency_openssl_path != "") {
116      deps += [ huks_dependency_openssl_path ]
117    } else {
118      external_deps += [ "openssl:libcrypto_shared" ]
119    }
120    configs = [
121      "//base/security/huks/frameworks/config/build:l2_standard_common_config",
122    ]
123  }
124} else {
125  ohos_static_library("libhuks_openssl_small_static") {
126    include_dirs = [ "../crypto_common/include" ]
127    sources = [
128      "src/hks_openssl_ability.c",
129      "src/hks_openssl_aes.c",
130      "src/hks_openssl_bn.c",
131      "src/hks_openssl_common.c",
132      "src/hks_openssl_curve25519.c",
133      "src/hks_openssl_dh.c",
134      "src/hks_openssl_dsa.c",
135      "src/hks_openssl_ecc.c",
136      "src/hks_openssl_ed25519tox25519.c",
137      "src/hks_openssl_engine.c",
138      "src/hks_openssl_hash.c",
139      "src/hks_openssl_hmac.c",
140      "src/hks_openssl_kdf.c",
141      "src/hks_openssl_rsa.c",
142      "src/hks_openssl_sm2.c",
143      "src/hks_openssl_sm3.c",
144      "src/hks_openssl_sm4.c",
145    ]
146
147    deps = [ "//base/security/huks/frameworks/huks_standard/main/common:libhuks_common_small_static" ]
148
149    complete_static_lib = true
150
151    external_deps = [ "hilog_lite:hilog_shared" ]
152    if (huks_dependency_openssl_path != "") {
153      deps += [ huks_dependency_openssl_path ]
154    } else {
155      deps += [ "//build/lite/config/component/openssl:openssl_shared" ]
156    }
157    configs = [
158      "//base/security/huks/frameworks/config/build:l1_small_common_config",
159    ]
160  }
161}
162