blob: bcf20280c0551e33909c5c13d064ab691cb2aca6 [file] [log] [blame]
Michael Spangefa630b2020-07-08 22:23:08 -04001# Copyright (c) 2020 Project CHIP Authors
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
Łukasz Duda4e1faf22021-01-27 17:47:25 +010015import("//build_overrides/build.gni")
Michael Spangefa630b2020-07-08 22:23:08 -040016import("//build_overrides/chip.gni")
17import("//build_overrides/nlassert.gni")
18
Michael Spang09611bf2021-03-02 16:31:57 -050019import("${chip_root}/build/chip/buildconfig_header.gni")
Michael Spang1fcb6dd2020-08-24 11:19:04 -040020
Michael Spangefa630b2020-07-08 22:23:08 -040021import("crypto.gni")
22
Steven Cooreman3dc97f02022-08-04 20:34:20 +020023if (chip_crypto == "") {
24 if (current_os == "android" || current_os == "freertos" ||
Artur Tynecki0efd3182022-12-05 20:18:32 +010025 current_os == "zephyr" || current_os == "mbed" || current_os == "webos" ||
26 current_os == "cmsis-rtos") {
Steven Cooreman3dc97f02022-08-04 20:34:20 +020027 chip_crypto = "mbedtls"
Boris Zbarsky9c631df2023-02-09 12:29:36 -050028 } else if (current_os == "mac" || current_os == "ios") {
29 chip_crypto = "boringssl"
Steven Cooreman3dc97f02022-08-04 20:34:20 +020030 } else {
31 chip_crypto = "openssl"
32 }
33}
34
35assert(
Damian Królikd37c8012022-10-20 04:41:14 +020036 chip_crypto == "mbedtls" || chip_crypto == "psa" ||
andrei-menzopol7d17e472023-02-09 16:23:22 +020037 chip_crypto == "openssl" || chip_crypto == "boringssl" ||
38 chip_crypto == "platform",
39 "Please select a valid crypto implementation: mbedtls, psa, openssl, boringssl, platform")
Steven Cooreman3dc97f02022-08-04 20:34:20 +020040
Michael Spang1fcb6dd2020-08-24 11:19:04 -040041buildconfig_header("crypto_buildconfig") {
42 header = "CryptoBuildConfig.h"
43 header_dir = "crypto"
44
Tennessee Carmel-Veilleux768b5752022-07-18 22:13:02 -040045 chip_crypto_mbedtls = chip_crypto == "mbedtls"
Damian Królikd37c8012022-10-20 04:41:14 +020046 chip_crypto_psa = chip_crypto == "psa"
Tennessee Carmel-Veilleux768b5752022-07-18 22:13:02 -040047 chip_crypto_openssl = chip_crypto == "openssl"
48 chip_crypto_boringssl = chip_crypto == "boringssl"
Steven Cooreman3dc97f02022-08-04 20:34:20 +020049 chip_crypto_platform = chip_crypto == "platform"
Tennessee Carmel-Veilleux768b5752022-07-18 22:13:02 -040050
51 defines = [
52 "CHIP_CRYPTO_MBEDTLS=${chip_crypto_mbedtls}",
Damian Królikd37c8012022-10-20 04:41:14 +020053 "CHIP_CRYPTO_PSA=${chip_crypto_psa}",
Tennessee Carmel-Veilleux768b5752022-07-18 22:13:02 -040054 "CHIP_CRYPTO_OPENSSL=${chip_crypto_openssl}",
55 "CHIP_CRYPTO_BORINGSSL=${chip_crypto_boringssl}",
Steven Cooreman3dc97f02022-08-04 20:34:20 +020056 "CHIP_CRYPTO_PLATFORM=${chip_crypto_platform}",
Tennessee Carmel-Veilleux768b5752022-07-18 22:13:02 -040057 ]
Jagadish-NXP467dd442021-04-15 20:14:25 +053058
59 if (chip_with_se05x == 1) {
60 defines += [ "CHIP_CRYPTO_HSM=1" ]
61 defines += [ "CHIP_CRYPTO_HSM_NXP=1" ]
62 } else {
63 defines += [ "CHIP_CRYPTO_HSM=0" ]
64 defines += [ "CHIP_CRYPTO_HSM_NXP=0" ]
65 }
Michael Spangefa630b2020-07-08 22:23:08 -040066}
67
Steven Cooreman3dc97f02022-08-04 20:34:20 +020068source_set("public_headers") {
69 sources = [
70 "CHIPCryptoPAL.h",
71 "OperationalKeystore.h",
72 ]
73
74 public_deps = [
75 ":crypto_buildconfig",
76 "${chip_root}/src/lib/asn1",
77 "${chip_root}/src/lib/core",
78 "${chip_root}/src/lib/support",
79 "${nlassert_root}:nlassert",
80 ]
81}
82
Michael Spangefa630b2020-07-08 22:23:08 -040083if (chip_crypto == "openssl") {
Łukasz Duda4e1faf22021-01-27 17:47:25 +010084 import("${build_root}/config/linux/pkg_config.gni")
Michael Spangefa630b2020-07-08 22:23:08 -040085
86 pkg_config("openssl_config") {
87 packages = [ "openssl" ]
88 }
Steven Cooreman3dc97f02022-08-04 20:34:20 +020089
90 source_set("cryptopal_openssl") {
91 sources = [ "CHIPCryptoPALOpenSSL.cpp" ]
92 public_configs = [ ":openssl_config" ]
93 public_deps = [ ":public_headers" ]
94 }
Chris Letnickfa549eb2022-07-18 09:14:02 -040095} else if (chip_crypto == "boringssl") {
Vivien Nicolas7301ecf2022-10-06 16:17:52 +020096 import("${chip_root}/build_overrides/boringssl.gni")
Steven Cooreman3dc97f02022-08-04 20:34:20 +020097
98 source_set("cryptopal_boringssl") {
99 # BoringSSL is close enough to OpenSSL that it uses same PAL, with minor #ifdef differences
100 sources = [ "CHIPCryptoPALOpenSSL.cpp" ]
101 public_deps = [
102 ":public_headers",
103 "${boringssl_root}:boringssl",
104 ]
105 }
Chris Letnickfa549eb2022-07-18 09:14:02 -0400106} else if (chip_crypto == "mbedtls") {
Michael Spangefa630b2020-07-08 22:23:08 -0400107 import("//build_overrides/mbedtls.gni")
Steven Cooreman3dc97f02022-08-04 20:34:20 +0200108
109 source_set("cryptopal_mbedtls") {
110 sources = [ "CHIPCryptoPALmbedTLS.cpp" ]
111 public_deps = [ ":public_headers" ]
112
alexhqwangd54101b2022-11-29 05:11:40 -0800113 if (!chip_external_mbedtls) {
Steven Cooreman3dc97f02022-08-04 20:34:20 +0200114 public_deps += [ "${mbedtls_root}:mbedtls" ]
115 }
116 }
Damian Królikd37c8012022-10-20 04:41:14 +0200117} else if (chip_crypto == "psa") {
118 import("//build_overrides/mbedtls.gni")
119
120 source_set("cryptopal_psa") {
Damian Królik12b17442022-12-13 23:18:14 +0100121 sources = [
122 "CHIPCryptoPALPSA.cpp",
123 "CHIPCryptoPALPSA.h",
124 "PSAOperationalKeystore.cpp",
125 "PSAOperationalKeystore.h",
126 ]
Damian Królikd37c8012022-10-20 04:41:14 +0200127 public_deps = [ ":public_headers" ]
128
129 external_mbedtls = current_os == "zephyr"
130
131 if (!external_mbedtls) {
132 public_deps += [ "${mbedtls_root}:mbedtls" ]
133 }
134 }
Michael Spangefa630b2020-07-08 22:23:08 -0400135}
136
137static_library("crypto") {
138 output_name = "libChipCrypto"
139
Michael Spang84c6df42020-08-13 10:01:29 -0400140 sources = [
141 "CHIPCryptoPAL.cpp",
Tennessee Carmel-Veilleux4e3930a2022-06-10 09:08:31 -0400142 "PersistentStorageOperationalKeystore.cpp",
143 "PersistentStorageOperationalKeystore.h",
Tennessee Carmel-Veilleux267951c2021-10-13 22:05:45 -0400144 "RandUtils.cpp",
145 "RandUtils.h",
Michael Spang84c6df42020-08-13 10:01:29 -0400146 ]
Michael Spangefa630b2020-07-08 22:23:08 -0400147
Tennessee Carmel-Veilleux768b5752022-07-18 22:13:02 -0400148 public_configs = []
149
Boris Zbarsky902a8642020-09-25 17:41:22 -0400150 cflags = [ "-Wconversion" ]
151
Steven Cooreman3dc97f02022-08-04 20:34:20 +0200152 public_deps = [ ":public_headers" ]
Michael Spangefa630b2020-07-08 22:23:08 -0400153
Michael Spangefa630b2020-07-08 22:23:08 -0400154 if (chip_crypto == "mbedtls") {
Steven Cooreman3dc97f02022-08-04 20:34:20 +0200155 public_deps += [ ":cryptopal_mbedtls" ]
Damian Królikd37c8012022-10-20 04:41:14 +0200156 } else if (chip_crypto == "psa") {
157 public_deps += [ ":cryptopal_psa" ]
Michael Spangefa630b2020-07-08 22:23:08 -0400158 } else if (chip_crypto == "openssl") {
Steven Cooreman3dc97f02022-08-04 20:34:20 +0200159 public_deps += [ ":cryptopal_openssl" ]
Chris Letnickfa549eb2022-07-18 09:14:02 -0400160 } else if (chip_crypto == "boringssl") {
Steven Cooreman3dc97f02022-08-04 20:34:20 +0200161 public_deps += [ ":cryptopal_boringssl" ]
Steven Cooreman3dc97f02022-08-04 20:34:20 +0200162 } else if (chip_crypto == "platform") {
163 # Platform implementation is responsible for bringing their
164 # own implementation and dependencies
Michael Spangefa630b2020-07-08 22:23:08 -0400165 } else {
166 assert(false, "Invalid CHIP crypto")
167 }
Jagadish-NXP467dd442021-04-15 20:14:25 +0530168
169 if (chip_with_se05x == 1) {
sujaygkulkarni-nxp6a0533d2021-04-26 19:00:05 +0530170 sources += [
Jagadish-NXPb6ccd462021-05-12 22:16:20 +0530171 "hsm/nxp/CHIPCryptoPALHsm_SE05X_HKDF.cpp",
Tennessee Carmel-Veilleux8b5b24f2021-07-07 17:49:38 -0400172 "hsm/nxp/CHIPCryptoPALHsm_SE05X_HMAC.cpp",
sujaygkulkarni-nxp6a0533d2021-04-26 19:00:05 +0530173 "hsm/nxp/CHIPCryptoPALHsm_SE05X_P256.cpp",
Jagadish-NXPa8226ab2021-05-05 20:14:28 +0530174 "hsm/nxp/CHIPCryptoPALHsm_SE05X_PBKDF.cpp",
sujaygkulkarni-nxp6a0533d2021-04-26 19:00:05 +0530175 "hsm/nxp/CHIPCryptoPALHsm_SE05X_Spake2p.cpp",
176 "hsm/nxp/CHIPCryptoPALHsm_SE05X_utils.cpp",
sujaygkulkarni-nxp769eca42022-08-16 03:02:40 +0530177 "hsm/nxp/PersistentStorageOperationalKeystoreHSM.cpp",
178 "hsm/nxp/PersistentStorageOperationalKeystoreHSM.h",
sujaygkulkarni-nxp6a0533d2021-04-26 19:00:05 +0530179 ]
Jagadish-NXP467dd442021-04-15 20:14:25 +0530180 public_deps += [ "${chip_root}/third_party/simw-top-mini:se05x" ]
181 public_configs += [ "${chip_root}/third_party/simw-top-mini:se05x_config" ]
182 }
Michael Spangefa630b2020-07-08 22:23:08 -0400183}