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
14import("//base/security/huks/build/config.gni")
15import("//base/security/huks/huks.gni")
16import("//build/ohos.gni")
17import("//build/test.gni")
18
19module_output_path = "huks_standard/hal_unittest"
20
21config("json_config") {
22  cflags_cc = [ "-fexceptions" ]
23}
24
25ohos_unittest("crypto_engine_unit_test") {
26  module_out_path = module_output_path
27  include_dirs = [
28    ".",
29    "include",
30    "//base/security/huks/frameworks/huks_standard/main/common/include",
31    "//base/security/huks/interfaces/inner_api/huks_standard/main/include",
32  ]
33
34  sources = [
35    "./src/hks_crypto_hal_aes_cipher.cpp",
36    "./src/hks_crypto_hal_aes_decrypt.cpp",
37    "./src/hks_crypto_hal_aes_encrypt.cpp",
38    "./src/hks_crypto_hal_aes_key.cpp",
39    "./src/hks_crypto_hal_common.cpp",
40    "./src/hks_crypto_hal_common.h",
41    "./src/hks_crypto_hal_dh.cpp",
42    "./src/hks_crypto_hal_dh_agree.cpp",
43    "./src/hks_crypto_hal_dsa_key.cpp",
44    "./src/hks_crypto_hal_dsa_sign.cpp",
45    "./src/hks_crypto_hal_ecc_key.cpp",
46    "./src/hks_crypto_hal_ecdh_agree.cpp",
47    "./src/hks_crypto_hal_ecdsa_sign.cpp",
48    "./src/hks_crypto_hal_hmac_hmac.cpp",
49    "./src/hks_crypto_hal_hmac_key.cpp",
50    "./src/hks_crypto_hal_rsa_cipher.cpp",
51    "./src/hks_crypto_hal_rsa_decrypt.cpp",
52    "./src/hks_crypto_hal_rsa_encrypt.cpp",
53    "./src/hks_crypto_hal_rsa_key.cpp",
54    "./src/hks_crypto_hal_rsa_oaep_decrypt.cpp",
55    "./src/hks_crypto_hal_rsa_oaep_encrypt.cpp",
56    "./src/hks_crypto_hal_rsa_sign.cpp",
57    "./src/hks_crypto_hal_sm3_cipher.cpp",
58  ]
59  if (use_crypto_lib == "openssl") {
60    sources += [ "./src/hks_crypto_hal_api_openssl.cpp" ]
61  }
62  if (use_crypto_lib == "mbedtls") {
63    sources += [ "./src/hks_crypto_hal_api_mbedtls.cpp" ]
64  }
65
66  defines = [ "_HUKS_LOG_ENABLE_" ]
67
68  if (use_crypto_lib == "openssl") {
69    defines += [ "_USE_OPENSSL_" ]
70  }
71  if (use_crypto_lib == "mbedtls") {
72    defines += [ "_USE_MBEDTLS_" ]
73  }
74
75  if (huks_security_level == "software") {
76    defines += [ "HKS_UNTRUSTED_RUNNING_ENV" ]
77  }
78
79  configs = [
80    "//base/security/huks/frameworks/config/build:l2_standard_common_config",
81  ]
82
83  deps = [
84    "//base/security/huks/frameworks/huks_standard/main/crypto_engine:libhuks_crypto_engine_standard_static",
85    "//base/security/huks/frameworks/huks_standard/main/os_dependency:libhuks_mem_standard_static",
86    "//base/security/huks/frameworks/huks_standard/main/os_dependency:libhuks_os_dependency_standard_static",
87    "//base/security/huks/frameworks/huks_standard/main/os_dependency:libhuks_util_standard_static",
88  ]
89  external_deps = [
90    "c_utils:utils",
91    "hilog:libhilog",
92  ]
93
94  if (os_level == "standard") {
95    external_deps += [ "googletest:gtest" ]
96  }
97
98  cflags = [
99    "-Wall",
100    "-Werror",
101  ]
102
103  if (use_crypto_lib == "openssl") {
104    deps += [ "//base/security/huks/frameworks/huks_standard/main/crypto_engine/openssl:libhuks_openssl_standard_static" ]
105  }
106  if (use_crypto_lib == "mbedtls") {
107    deps += [ "//base/security/huks/frameworks/huks_standard/main/crypto_engine/mbedtls:libhuks_mbedtls_standard_static" ]
108  }
109
110  subsystem_name = "security"
111  part_name = "huks"
112}
113