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    external_deps = []
57    if (huks_use_rkc_in_standard) {
58      defines += [ "HKS_USE_RKC_IN_STANDARD" ]
59
60      include_dirs += [
61        "//base/security/huks/services/huks_standard/huks_service/main/core/include",
62        "//base/security/huks/services/huks_standard/huks_service/main/hks_storage/include",
63      ]
64      sources += [
65        "../rkc/src/hks_rkc.c",
66        "../rkc/src/hks_rkc_rw.c",
67        "//base/security/huks/services/huks_standard/huks_service/main/hks_storage/src/hks_lock.c",
68        "//base/security/huks/services/huks_standard/huks_service/main/hks_storage/src/hks_storage.c",
69        "//base/security/huks/services/huks_standard/huks_service/main/hks_storage/src/hks_storage_file_lock.c",
70        "//base/security/huks/services/huks_standard/huks_service/main/hks_storage/src/hks_storage_manager.c",
71        "//base/security/huks/services/huks_standard/huks_service/main/hks_storage/src/hks_storage_utils.c",
72        "//base/security/huks/services/huks_standard/huks_service/main/os_dependency/posix/hks_rwlock.c",
73      ]
74
75      # 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
76      if (huks_enable_hdi_in_standard) {
77        sources += [ "//base/security/huks/services/huks_standard/huks_service/main/os_dependency/idl/passthrough/huks_hdi_access.c" ]
78        external_deps += [ "drivers_interface_huks:libhuks_proxy_1.0" ]
79      } else {
80        sources += [
81          "//base/security/huks/services/huks_standard/huks_service/main/os_dependency/idl/passthrough/huks_access.c",
82          "//base/security/huks/services/huks_standard/huks_service/main/os_dependency/idl/passthrough/huks_core_dynamic_hal.c",
83        ]
84      }
85
86      deps += [
87        "//base/security/huks/frameworks/huks_standard/main/os_dependency:libhuks_os_dependency_standard_static",
88        "//base/security/huks/utils/file_operator:libhuks_utils_file_operator_static",
89        "//base/security/huks/utils/mutex:libhuks_utils_mutex_static",
90      ]
91
92      if (huks_enable_upgrade_rkc_v1tov2) {
93        defines += [ "HKS_ENABLE_UPGRADE_RKC_DERIVE_ALG" ]
94        sources += [ "../rkc/src/hks_rkc_v1.c" ]
95      }
96    }
97
98    deps += [ "//base/security/huks/frameworks/huks_standard/main/common:libhuks_common_standard_static" ]
99
100    complete_static_lib = true
101
102    branch_protector_ret = "pac_ret"
103
104    sanitize = {
105      integer_overflow = true
106      cfi = true
107      debug = false
108      cfi_cross_dso = true
109      boundary_sanitize = true
110      ubsan = true
111    }
112    external_deps += [
113      "c_utils:utils",
114      "hilog:libhilog",
115    ]
116    if (huks_dependency_openssl_path != "") {
117      deps += [ huks_dependency_openssl_path ]
118    } else {
119      external_deps += [ "openssl:libcrypto_shared" ]
120    }
121    configs = [
122      "//base/security/huks/frameworks/config/build:l2_standard_common_config",
123    ]
124  }
125} else {
126  ohos_static_library("libhuks_openssl_small_static") {
127    include_dirs = [ "../crypto_common/include" ]
128    sources = [
129      "src/hks_openssl_ability.c",
130      "src/hks_openssl_aes.c",
131      "src/hks_openssl_bn.c",
132      "src/hks_openssl_common.c",
133      "src/hks_openssl_curve25519.c",
134      "src/hks_openssl_dh.c",
135      "src/hks_openssl_dsa.c",
136      "src/hks_openssl_ecc.c",
137      "src/hks_openssl_ed25519tox25519.c",
138      "src/hks_openssl_engine.c",
139      "src/hks_openssl_hash.c",
140      "src/hks_openssl_hmac.c",
141      "src/hks_openssl_kdf.c",
142      "src/hks_openssl_rsa.c",
143      "src/hks_openssl_sm2.c",
144      "src/hks_openssl_sm3.c",
145      "src/hks_openssl_sm4.c",
146    ]
147
148    deps = [ "//base/security/huks/frameworks/huks_standard/main/common:libhuks_common_small_static" ]
149
150    complete_static_lib = true
151
152    external_deps = [ "hilog_lite:hilog_shared" ]
153    if (huks_dependency_openssl_path != "") {
154      deps += [ huks_dependency_openssl_path ]
155    } else {
156      deps += [ "//build/lite/config/component/openssl:openssl_shared" ]
157    }
158    configs = [
159      "//base/security/huks/frameworks/config/build:l1_small_common_config",
160    ]
161  }
162}
163