Michael Spang | efa630b | 2020-07-08 22:23:08 -0400 | [diff] [blame] | 1 | # 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 Duda | 4e1faf2 | 2021-01-27 17:47:25 +0100 | [diff] [blame] | 15 | import("//build_overrides/build.gni") |
Michael Spang | efa630b | 2020-07-08 22:23:08 -0400 | [diff] [blame] | 16 | import("//build_overrides/chip.gni") |
| 17 | import("//build_overrides/nlassert.gni") |
| 18 | |
Michael Spang | 09611bf | 2021-03-02 16:31:57 -0500 | [diff] [blame] | 19 | import("${chip_root}/build/chip/buildconfig_header.gni") |
Michael Spang | 1fcb6dd | 2020-08-24 11:19:04 -0400 | [diff] [blame] | 20 | |
Michael Spang | efa630b | 2020-07-08 22:23:08 -0400 | [diff] [blame] | 21 | import("crypto.gni") |
| 22 | |
Steven Cooreman | 3dc97f0 | 2022-08-04 20:34:20 +0200 | [diff] [blame] | 23 | if (chip_crypto == "") { |
| 24 | if (current_os == "android" || current_os == "freertos" || |
Artur Tynecki | 0efd318 | 2022-12-05 20:18:32 +0100 | [diff] [blame] | 25 | current_os == "zephyr" || current_os == "mbed" || current_os == "webos" || |
| 26 | current_os == "cmsis-rtos") { |
Steven Cooreman | 3dc97f0 | 2022-08-04 20:34:20 +0200 | [diff] [blame] | 27 | chip_crypto = "mbedtls" |
Boris Zbarsky | 9c631df | 2023-02-09 12:29:36 -0500 | [diff] [blame^] | 28 | } else if (current_os == "mac" || current_os == "ios") { |
| 29 | chip_crypto = "boringssl" |
Steven Cooreman | 3dc97f0 | 2022-08-04 20:34:20 +0200 | [diff] [blame] | 30 | } else { |
| 31 | chip_crypto = "openssl" |
| 32 | } |
| 33 | } |
| 34 | |
| 35 | assert( |
Damian Królik | d37c801 | 2022-10-20 04:41:14 +0200 | [diff] [blame] | 36 | chip_crypto == "mbedtls" || chip_crypto == "psa" || |
andrei-menzopol | 7d17e47 | 2023-02-09 16:23:22 +0200 | [diff] [blame] | 37 | chip_crypto == "openssl" || chip_crypto == "boringssl" || |
| 38 | chip_crypto == "platform", |
| 39 | "Please select a valid crypto implementation: mbedtls, psa, openssl, boringssl, platform") |
Steven Cooreman | 3dc97f0 | 2022-08-04 20:34:20 +0200 | [diff] [blame] | 40 | |
Michael Spang | 1fcb6dd | 2020-08-24 11:19:04 -0400 | [diff] [blame] | 41 | buildconfig_header("crypto_buildconfig") { |
| 42 | header = "CryptoBuildConfig.h" |
| 43 | header_dir = "crypto" |
| 44 | |
Tennessee Carmel-Veilleux | 768b575 | 2022-07-18 22:13:02 -0400 | [diff] [blame] | 45 | chip_crypto_mbedtls = chip_crypto == "mbedtls" |
Damian Królik | d37c801 | 2022-10-20 04:41:14 +0200 | [diff] [blame] | 46 | chip_crypto_psa = chip_crypto == "psa" |
Tennessee Carmel-Veilleux | 768b575 | 2022-07-18 22:13:02 -0400 | [diff] [blame] | 47 | chip_crypto_openssl = chip_crypto == "openssl" |
| 48 | chip_crypto_boringssl = chip_crypto == "boringssl" |
Steven Cooreman | 3dc97f0 | 2022-08-04 20:34:20 +0200 | [diff] [blame] | 49 | chip_crypto_platform = chip_crypto == "platform" |
Tennessee Carmel-Veilleux | 768b575 | 2022-07-18 22:13:02 -0400 | [diff] [blame] | 50 | |
| 51 | defines = [ |
| 52 | "CHIP_CRYPTO_MBEDTLS=${chip_crypto_mbedtls}", |
Damian Królik | d37c801 | 2022-10-20 04:41:14 +0200 | [diff] [blame] | 53 | "CHIP_CRYPTO_PSA=${chip_crypto_psa}", |
Tennessee Carmel-Veilleux | 768b575 | 2022-07-18 22:13:02 -0400 | [diff] [blame] | 54 | "CHIP_CRYPTO_OPENSSL=${chip_crypto_openssl}", |
| 55 | "CHIP_CRYPTO_BORINGSSL=${chip_crypto_boringssl}", |
Steven Cooreman | 3dc97f0 | 2022-08-04 20:34:20 +0200 | [diff] [blame] | 56 | "CHIP_CRYPTO_PLATFORM=${chip_crypto_platform}", |
Tennessee Carmel-Veilleux | 768b575 | 2022-07-18 22:13:02 -0400 | [diff] [blame] | 57 | ] |
Jagadish-NXP | 467dd44 | 2021-04-15 20:14:25 +0530 | [diff] [blame] | 58 | |
| 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 Spang | efa630b | 2020-07-08 22:23:08 -0400 | [diff] [blame] | 66 | } |
| 67 | |
Steven Cooreman | 3dc97f0 | 2022-08-04 20:34:20 +0200 | [diff] [blame] | 68 | source_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 Spang | efa630b | 2020-07-08 22:23:08 -0400 | [diff] [blame] | 83 | if (chip_crypto == "openssl") { |
Łukasz Duda | 4e1faf2 | 2021-01-27 17:47:25 +0100 | [diff] [blame] | 84 | import("${build_root}/config/linux/pkg_config.gni") |
Michael Spang | efa630b | 2020-07-08 22:23:08 -0400 | [diff] [blame] | 85 | |
| 86 | pkg_config("openssl_config") { |
| 87 | packages = [ "openssl" ] |
| 88 | } |
Steven Cooreman | 3dc97f0 | 2022-08-04 20:34:20 +0200 | [diff] [blame] | 89 | |
| 90 | source_set("cryptopal_openssl") { |
| 91 | sources = [ "CHIPCryptoPALOpenSSL.cpp" ] |
| 92 | public_configs = [ ":openssl_config" ] |
| 93 | public_deps = [ ":public_headers" ] |
| 94 | } |
Chris Letnick | fa549eb | 2022-07-18 09:14:02 -0400 | [diff] [blame] | 95 | } else if (chip_crypto == "boringssl") { |
Vivien Nicolas | 7301ecf | 2022-10-06 16:17:52 +0200 | [diff] [blame] | 96 | import("${chip_root}/build_overrides/boringssl.gni") |
Steven Cooreman | 3dc97f0 | 2022-08-04 20:34:20 +0200 | [diff] [blame] | 97 | |
| 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 Letnick | fa549eb | 2022-07-18 09:14:02 -0400 | [diff] [blame] | 106 | } else if (chip_crypto == "mbedtls") { |
Michael Spang | efa630b | 2020-07-08 22:23:08 -0400 | [diff] [blame] | 107 | import("//build_overrides/mbedtls.gni") |
Steven Cooreman | 3dc97f0 | 2022-08-04 20:34:20 +0200 | [diff] [blame] | 108 | |
| 109 | source_set("cryptopal_mbedtls") { |
| 110 | sources = [ "CHIPCryptoPALmbedTLS.cpp" ] |
| 111 | public_deps = [ ":public_headers" ] |
| 112 | |
alexhqwang | d54101b | 2022-11-29 05:11:40 -0800 | [diff] [blame] | 113 | if (!chip_external_mbedtls) { |
Steven Cooreman | 3dc97f0 | 2022-08-04 20:34:20 +0200 | [diff] [blame] | 114 | public_deps += [ "${mbedtls_root}:mbedtls" ] |
| 115 | } |
| 116 | } |
Damian Królik | d37c801 | 2022-10-20 04:41:14 +0200 | [diff] [blame] | 117 | } else if (chip_crypto == "psa") { |
| 118 | import("//build_overrides/mbedtls.gni") |
| 119 | |
| 120 | source_set("cryptopal_psa") { |
Damian Królik | 12b1744 | 2022-12-13 23:18:14 +0100 | [diff] [blame] | 121 | sources = [ |
| 122 | "CHIPCryptoPALPSA.cpp", |
| 123 | "CHIPCryptoPALPSA.h", |
| 124 | "PSAOperationalKeystore.cpp", |
| 125 | "PSAOperationalKeystore.h", |
| 126 | ] |
Damian Królik | d37c801 | 2022-10-20 04:41:14 +0200 | [diff] [blame] | 127 | 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 Spang | efa630b | 2020-07-08 22:23:08 -0400 | [diff] [blame] | 135 | } |
| 136 | |
| 137 | static_library("crypto") { |
| 138 | output_name = "libChipCrypto" |
| 139 | |
Michael Spang | 84c6df4 | 2020-08-13 10:01:29 -0400 | [diff] [blame] | 140 | sources = [ |
| 141 | "CHIPCryptoPAL.cpp", |
Tennessee Carmel-Veilleux | 4e3930a | 2022-06-10 09:08:31 -0400 | [diff] [blame] | 142 | "PersistentStorageOperationalKeystore.cpp", |
| 143 | "PersistentStorageOperationalKeystore.h", |
Tennessee Carmel-Veilleux | 267951c | 2021-10-13 22:05:45 -0400 | [diff] [blame] | 144 | "RandUtils.cpp", |
| 145 | "RandUtils.h", |
Michael Spang | 84c6df4 | 2020-08-13 10:01:29 -0400 | [diff] [blame] | 146 | ] |
Michael Spang | efa630b | 2020-07-08 22:23:08 -0400 | [diff] [blame] | 147 | |
Tennessee Carmel-Veilleux | 768b575 | 2022-07-18 22:13:02 -0400 | [diff] [blame] | 148 | public_configs = [] |
| 149 | |
Boris Zbarsky | 902a864 | 2020-09-25 17:41:22 -0400 | [diff] [blame] | 150 | cflags = [ "-Wconversion" ] |
| 151 | |
Steven Cooreman | 3dc97f0 | 2022-08-04 20:34:20 +0200 | [diff] [blame] | 152 | public_deps = [ ":public_headers" ] |
Michael Spang | efa630b | 2020-07-08 22:23:08 -0400 | [diff] [blame] | 153 | |
Michael Spang | efa630b | 2020-07-08 22:23:08 -0400 | [diff] [blame] | 154 | if (chip_crypto == "mbedtls") { |
Steven Cooreman | 3dc97f0 | 2022-08-04 20:34:20 +0200 | [diff] [blame] | 155 | public_deps += [ ":cryptopal_mbedtls" ] |
Damian Królik | d37c801 | 2022-10-20 04:41:14 +0200 | [diff] [blame] | 156 | } else if (chip_crypto == "psa") { |
| 157 | public_deps += [ ":cryptopal_psa" ] |
Michael Spang | efa630b | 2020-07-08 22:23:08 -0400 | [diff] [blame] | 158 | } else if (chip_crypto == "openssl") { |
Steven Cooreman | 3dc97f0 | 2022-08-04 20:34:20 +0200 | [diff] [blame] | 159 | public_deps += [ ":cryptopal_openssl" ] |
Chris Letnick | fa549eb | 2022-07-18 09:14:02 -0400 | [diff] [blame] | 160 | } else if (chip_crypto == "boringssl") { |
Steven Cooreman | 3dc97f0 | 2022-08-04 20:34:20 +0200 | [diff] [blame] | 161 | public_deps += [ ":cryptopal_boringssl" ] |
Steven Cooreman | 3dc97f0 | 2022-08-04 20:34:20 +0200 | [diff] [blame] | 162 | } else if (chip_crypto == "platform") { |
| 163 | # Platform implementation is responsible for bringing their |
| 164 | # own implementation and dependencies |
Michael Spang | efa630b | 2020-07-08 22:23:08 -0400 | [diff] [blame] | 165 | } else { |
| 166 | assert(false, "Invalid CHIP crypto") |
| 167 | } |
Jagadish-NXP | 467dd44 | 2021-04-15 20:14:25 +0530 | [diff] [blame] | 168 | |
| 169 | if (chip_with_se05x == 1) { |
sujaygkulkarni-nxp | 6a0533d | 2021-04-26 19:00:05 +0530 | [diff] [blame] | 170 | sources += [ |
Jagadish-NXP | b6ccd46 | 2021-05-12 22:16:20 +0530 | [diff] [blame] | 171 | "hsm/nxp/CHIPCryptoPALHsm_SE05X_HKDF.cpp", |
Tennessee Carmel-Veilleux | 8b5b24f | 2021-07-07 17:49:38 -0400 | [diff] [blame] | 172 | "hsm/nxp/CHIPCryptoPALHsm_SE05X_HMAC.cpp", |
sujaygkulkarni-nxp | 6a0533d | 2021-04-26 19:00:05 +0530 | [diff] [blame] | 173 | "hsm/nxp/CHIPCryptoPALHsm_SE05X_P256.cpp", |
Jagadish-NXP | a8226ab | 2021-05-05 20:14:28 +0530 | [diff] [blame] | 174 | "hsm/nxp/CHIPCryptoPALHsm_SE05X_PBKDF.cpp", |
sujaygkulkarni-nxp | 6a0533d | 2021-04-26 19:00:05 +0530 | [diff] [blame] | 175 | "hsm/nxp/CHIPCryptoPALHsm_SE05X_Spake2p.cpp", |
| 176 | "hsm/nxp/CHIPCryptoPALHsm_SE05X_utils.cpp", |
sujaygkulkarni-nxp | 769eca4 | 2022-08-16 03:02:40 +0530 | [diff] [blame] | 177 | "hsm/nxp/PersistentStorageOperationalKeystoreHSM.cpp", |
| 178 | "hsm/nxp/PersistentStorageOperationalKeystoreHSM.h", |
sujaygkulkarni-nxp | 6a0533d | 2021-04-26 19:00:05 +0530 | [diff] [blame] | 179 | ] |
Jagadish-NXP | 467dd44 | 2021-04-15 20:14:25 +0530 | [diff] [blame] | 180 | public_deps += [ "${chip_root}/third_party/simw-top-mini:se05x" ] |
| 181 | public_configs += [ "${chip_root}/third_party/simw-top-mini:se05x_config" ] |
| 182 | } |
Michael Spang | efa630b | 2020-07-08 22:23:08 -0400 | [diff] [blame] | 183 | } |