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("//build/ohos.gni")
16
17if (os_level == "standard") {
18  config("huks_config") {
19    include_dirs = [
20      "include",
21      "../crypto_common/include",
22      "//base/security/huks/frameworks/huks_standard/main/crypto_engine/rkc/include",
23    ]
24  }
25  ohos_static_library("libhuks_mbedtls_standard_static") {
26    subsystem_name = "security"
27    part_name = "huks"
28    public_configs = [ ":huks_config" ]
29
30    sources = [
31      "src/hks_crypto_ed25519.c",
32      "src/hks_mbedtls_ability.c",
33      "src/hks_mbedtls_aes.c",
34      "src/hks_mbedtls_bn.c",
35      "src/hks_mbedtls_common.c",
36      "src/hks_mbedtls_dh.c",
37      "src/hks_mbedtls_dsa.c",
38      "src/hks_mbedtls_ecc.c",
39      "src/hks_mbedtls_ecdh.c",
40      "src/hks_mbedtls_ecdsa.c",
41      "src/hks_mbedtls_engine.c",
42      "src/hks_mbedtls_hash.c",
43      "src/hks_mbedtls_hmac.c",
44      "src/hks_mbedtls_kdf.c",
45      "src/hks_mbedtls_rsa.c",
46      "src/hks_mbedtls_x25519.c",
47    ]
48
49    deps = [ "//base/security/huks/frameworks/huks_standard/main/common:libhuks_common_standard_static" ]
50    if (huks_dependency_mbedtls_path != "") {
51      deps += [ huks_dependency_mbedtls_path ]
52    } else {
53      deps += [ "//third_party/mbedtls" ]
54    }
55    if (huks_dependency_openssl_path != "") {
56      deps += [ huks_dependency_openssl_path ]
57    } else {
58      deps += [ "//third_party/openssl:libcrypto_shared" ]
59    }
60
61    complete_static_lib = true
62
63    branch_protector_ret = "pac_ret"
64
65    sanitize = {
66      integer_overflow = true
67      cfi = true
68      debug = false
69      cfi_cross_dso = true
70      boundary_sanitize = true
71      ubsan = true
72    }
73    configs = [
74      "//base/security/huks/frameworks/config/build:l2_standard_common_config",
75    ]
76    external_deps = [ "hilog:libhilog" ]
77  }
78} else {
79  config("huks_config") {
80    include_dirs = [
81      "include",
82      "//base/security/huks/services/huks_standard/huks_service/main/core/include",
83      "//base/security/huks/services/huks_standard/huks_service/main/hks_storage/include",
84      "//base/security/huks/frameworks/huks_standard/main/crypto_engine/rkc/include",
85    ]
86  }
87
88  ohos_static_library("libhuks_mbedtls_small_static") {
89    public_configs = [ ":huks_config" ]
90
91    include_dirs = [
92      "//base/security/huks/frameworks/huks_standard/main/crypto_engine/rkc/include",
93      "../crypto_common/include",
94    ]
95
96    defines = []
97
98    sources = [
99      "../rkc/src/hks_rkc.c",
100      "../rkc/src/hks_rkc_rw.c",
101      "src/hks_crypto_ed25519.c",
102      "src/hks_mbedtls_ability.c",
103      "src/hks_mbedtls_aes.c",
104      "src/hks_mbedtls_bn.c",
105      "src/hks_mbedtls_common.c",
106      "src/hks_mbedtls_dh.c",
107      "src/hks_mbedtls_dsa.c",
108      "src/hks_mbedtls_ecc.c",
109      "src/hks_mbedtls_ecdh.c",
110      "src/hks_mbedtls_ecdsa.c",
111      "src/hks_mbedtls_engine.c",
112      "src/hks_mbedtls_hash.c",
113      "src/hks_mbedtls_hmac.c",
114      "src/hks_mbedtls_kdf.c",
115      "src/hks_mbedtls_rsa.c",
116      "src/hks_mbedtls_x25519.c",
117    ]
118
119    sources += [
120      "//base/security/huks/services/huks_standard/huks_service/main/hks_storage/src/hks_storage.c",
121      "//base/security/huks/services/huks_standard/huks_service/main/hks_storage/src/hks_storage_manager.c",
122      "//base/security/huks/services/huks_standard/huks_service/main/hks_storage/src/hks_storage_utils.c",
123    ]
124
125    if (huks_enable_upgrade_rkc_v1tov2) {
126      # enable upgrade rkc derivation algorithm from PBKDF2 to HKDF
127      defines += [ "HKS_ENABLE_UPGRADE_RKC_DERIVE_ALG" ]
128
129      # compile code of old version
130      sources += [ "../rkc/src/hks_rkc_v1.c" ]
131    }
132
133    deps = [ "//base/security/huks/frameworks/huks_standard/main/common:libhuks_common_small_static" ]
134    if (huks_dependency_mbedtls_path != "") {
135      deps += [ huks_dependency_mbedtls_path ]
136    } else {
137      deps += [ "//third_party/mbedtls:mbedtls_shared" ]
138    }
139    if (huks_dependency_openssl_path != "") {
140      deps += [ huks_dependency_openssl_path ]
141    } else {
142      if (ohos_kernel_type == "liteos_a" && ohos_kernel_type != "linux") {
143        deps += [ "//third_party/openssl/ohos_lite:openssl_shared" ]
144      } else {
145        deps += [ "//third_party/openssl:libcrypto_shared" ]
146      }
147    }
148    complete_static_lib = true
149    deps += [
150      "//base/security/huks/frameworks/huks_standard/main/os_dependency:libhuks_os_dependency_small_static",
151      "//base/security/huks/utils/file_operator:libhuks_utils_file_operator_static",
152    ]
153    configs = [
154      "//base/security/huks/frameworks/config/build:l1_small_common_config",
155    ]
156    external_deps = [ "hilog_lite:hilog_shared" ]
157  }
158}
159