blob: e06ab28cb988ef6afe667347f28d446272a5d5f5 [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" ||
25 current_os == "zephyr" || current_os == "mbed" || current_os == "webos") {
26 chip_crypto = "mbedtls"
27 } else {
28 chip_crypto = "openssl"
29 }
30}
31
32assert(
33 chip_crypto == "mbedtls" || chip_crypto == "openssl" ||
34 chip_crypto == "tinycrypt" || chip_crypto == "boringssl" ||
35 chip_crypto == "platform",
36 "Please select a valid crypto implementation: mbedtls, openssl, tinycrypt, boringssl, platform")
37
Michael Spang1fcb6dd2020-08-24 11:19:04 -040038buildconfig_header("crypto_buildconfig") {
39 header = "CryptoBuildConfig.h"
40 header_dir = "crypto"
41
Tennessee Carmel-Veilleux768b5752022-07-18 22:13:02 -040042 chip_crypto_mbedtls = chip_crypto == "mbedtls"
43 chip_crypto_openssl = chip_crypto == "openssl"
44 chip_crypto_boringssl = chip_crypto == "boringssl"
Steven Cooreman3dc97f02022-08-04 20:34:20 +020045 chip_crypto_platform = chip_crypto == "platform"
Tennessee Carmel-Veilleux768b5752022-07-18 22:13:02 -040046
47 defines = [
48 "CHIP_CRYPTO_MBEDTLS=${chip_crypto_mbedtls}",
49 "CHIP_CRYPTO_OPENSSL=${chip_crypto_openssl}",
50 "CHIP_CRYPTO_BORINGSSL=${chip_crypto_boringssl}",
Steven Cooreman3dc97f02022-08-04 20:34:20 +020051 "CHIP_CRYPTO_PLATFORM=${chip_crypto_platform}",
Tennessee Carmel-Veilleux768b5752022-07-18 22:13:02 -040052 ]
Jagadish-NXP467dd442021-04-15 20:14:25 +053053
54 if (chip_with_se05x == 1) {
55 defines += [ "CHIP_CRYPTO_HSM=1" ]
56 defines += [ "CHIP_CRYPTO_HSM_NXP=1" ]
57 } else {
58 defines += [ "CHIP_CRYPTO_HSM=0" ]
59 defines += [ "CHIP_CRYPTO_HSM_NXP=0" ]
60 }
sujaygkulkarni-nxp2ef08db2021-11-26 01:00:25 +053061
62 if (chip_with_se05x_da == 1) {
63 defines += [ "ENABLE_HSM_DEVICE_ATTESTATION=1" ]
64 }
Michael Spangefa630b2020-07-08 22:23:08 -040065}
66
Steven Cooreman3dc97f02022-08-04 20:34:20 +020067source_set("public_headers") {
68 sources = [
69 "CHIPCryptoPAL.h",
70 "OperationalKeystore.h",
71 ]
72
73 public_deps = [
74 ":crypto_buildconfig",
75 "${chip_root}/src/lib/asn1",
76 "${chip_root}/src/lib/core",
77 "${chip_root}/src/lib/support",
78 "${nlassert_root}:nlassert",
79 ]
80}
81
Michael Spangefa630b2020-07-08 22:23:08 -040082if (chip_crypto == "openssl") {
Łukasz Duda4e1faf22021-01-27 17:47:25 +010083 import("${build_root}/config/linux/pkg_config.gni")
Michael Spangefa630b2020-07-08 22:23:08 -040084
85 pkg_config("openssl_config") {
86 packages = [ "openssl" ]
87 }
Steven Cooreman3dc97f02022-08-04 20:34:20 +020088
89 source_set("cryptopal_openssl") {
90 sources = [ "CHIPCryptoPALOpenSSL.cpp" ]
91 public_configs = [ ":openssl_config" ]
92 public_deps = [ ":public_headers" ]
93 }
Chris Letnickfa549eb2022-07-18 09:14:02 -040094} else if (chip_crypto == "boringssl") {
95 import("//build_overrides/boringssl.gni")
Steven Cooreman3dc97f02022-08-04 20:34:20 +020096
97 source_set("cryptopal_boringssl") {
98 # BoringSSL is close enough to OpenSSL that it uses same PAL, with minor #ifdef differences
99 sources = [ "CHIPCryptoPALOpenSSL.cpp" ]
100 public_deps = [
101 ":public_headers",
102 "${boringssl_root}:boringssl",
103 ]
104 }
Chris Letnickfa549eb2022-07-18 09:14:02 -0400105} else if (chip_crypto == "mbedtls") {
Michael Spangefa630b2020-07-08 22:23:08 -0400106 import("//build_overrides/mbedtls.gni")
Steven Cooreman3dc97f02022-08-04 20:34:20 +0200107
108 source_set("cryptopal_mbedtls") {
109 sources = [ "CHIPCryptoPALmbedTLS.cpp" ]
110 public_deps = [ ":public_headers" ]
111
112 external_mbedtls = current_os == "zephyr"
113
114 if (!external_mbedtls) {
115 public_deps += [ "${mbedtls_root}:mbedtls" ]
116 }
117 }
doru919b2c8892022-07-22 21:40:26 +0300118} else if (chip_crypto == "tinycrypt") {
119 import("//build_overrides/mbedtls.gni")
Steven Cooreman3dc97f02022-08-04 20:34:20 +0200120
121 source_set("cryptopal_tinycrypt") {
122 sources = [ "CHIPCryptoPALTinyCrypt.cpp" ]
123 public_deps = [
124 ":public_headers",
125 "${mbedtls_root}:mbedtls",
126 ]
127 }
Michael Spangefa630b2020-07-08 22:23:08 -0400128}
129
130static_library("crypto") {
131 output_name = "libChipCrypto"
132
Michael Spang84c6df42020-08-13 10:01:29 -0400133 sources = [
134 "CHIPCryptoPAL.cpp",
Tennessee Carmel-Veilleux4e3930a2022-06-10 09:08:31 -0400135 "PersistentStorageOperationalKeystore.cpp",
136 "PersistentStorageOperationalKeystore.h",
Tennessee Carmel-Veilleux267951c2021-10-13 22:05:45 -0400137 "RandUtils.cpp",
138 "RandUtils.h",
Michael Spang84c6df42020-08-13 10:01:29 -0400139 ]
Michael Spangefa630b2020-07-08 22:23:08 -0400140
Tennessee Carmel-Veilleux768b5752022-07-18 22:13:02 -0400141 public_configs = []
142
Boris Zbarsky902a8642020-09-25 17:41:22 -0400143 cflags = [ "-Wconversion" ]
144
Steven Cooreman3dc97f02022-08-04 20:34:20 +0200145 public_deps = [ ":public_headers" ]
Michael Spangefa630b2020-07-08 22:23:08 -0400146
Michael Spangefa630b2020-07-08 22:23:08 -0400147 if (chip_crypto == "mbedtls") {
Steven Cooreman3dc97f02022-08-04 20:34:20 +0200148 public_deps += [ ":cryptopal_mbedtls" ]
Michael Spangefa630b2020-07-08 22:23:08 -0400149 } else if (chip_crypto == "openssl") {
Steven Cooreman3dc97f02022-08-04 20:34:20 +0200150 public_deps += [ ":cryptopal_openssl" ]
Chris Letnickfa549eb2022-07-18 09:14:02 -0400151 } else if (chip_crypto == "boringssl") {
Steven Cooreman3dc97f02022-08-04 20:34:20 +0200152 public_deps += [ ":cryptopal_boringssl" ]
doru919b2c8892022-07-22 21:40:26 +0300153 } else if (chip_crypto == "tinycrypt") {
Steven Cooreman3dc97f02022-08-04 20:34:20 +0200154 public_deps += [ ":cryptopal_tinycrypt" ]
155 } else if (chip_crypto == "platform") {
156 # Platform implementation is responsible for bringing their
157 # own implementation and dependencies
Michael Spangefa630b2020-07-08 22:23:08 -0400158 } else {
159 assert(false, "Invalid CHIP crypto")
160 }
Jagadish-NXP467dd442021-04-15 20:14:25 +0530161
162 if (chip_with_se05x == 1) {
sujaygkulkarni-nxp6a0533d2021-04-26 19:00:05 +0530163 sources += [
Jagadish-NXPb6ccd462021-05-12 22:16:20 +0530164 "hsm/nxp/CHIPCryptoPALHsm_SE05X_HKDF.cpp",
Tennessee Carmel-Veilleux8b5b24f2021-07-07 17:49:38 -0400165 "hsm/nxp/CHIPCryptoPALHsm_SE05X_HMAC.cpp",
sujaygkulkarni-nxp6a0533d2021-04-26 19:00:05 +0530166 "hsm/nxp/CHIPCryptoPALHsm_SE05X_P256.cpp",
Jagadish-NXPa8226ab2021-05-05 20:14:28 +0530167 "hsm/nxp/CHIPCryptoPALHsm_SE05X_PBKDF.cpp",
sujaygkulkarni-nxp6a0533d2021-04-26 19:00:05 +0530168 "hsm/nxp/CHIPCryptoPALHsm_SE05X_Spake2p.cpp",
169 "hsm/nxp/CHIPCryptoPALHsm_SE05X_utils.cpp",
sujaygkulkarni-nxp769eca42022-08-16 03:02:40 +0530170 "hsm/nxp/PersistentStorageOperationalKeystoreHSM.cpp",
171 "hsm/nxp/PersistentStorageOperationalKeystoreHSM.h",
sujaygkulkarni-nxp6a0533d2021-04-26 19:00:05 +0530172 ]
Jagadish-NXP467dd442021-04-15 20:14:25 +0530173 public_deps += [ "${chip_root}/third_party/simw-top-mini:se05x" ]
174 public_configs += [ "${chip_root}/third_party/simw-top-mini:se05x_config" ]
175 }
Michael Spangefa630b2020-07-08 22:23:08 -0400176}