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 | ] |
Michael Spang | efa630b | 2020-07-08 22:23:08 -0400 | [diff] [blame] | 58 | } |
| 59 | |
Steven Cooreman | 3dc97f0 | 2022-08-04 20:34:20 +0200 | [diff] [blame] | 60 | source_set("public_headers") { |
| 61 | sources = [ |
| 62 | "CHIPCryptoPAL.h", |
| 63 | "OperationalKeystore.h", |
Damian Królik | b07872c | 2023-02-17 13:56:47 +0100 | [diff] [blame] | 64 | "SessionKeystore.h", |
Steven Cooreman | 3dc97f0 | 2022-08-04 20:34:20 +0200 | [diff] [blame] | 65 | ] |
| 66 | |
| 67 | public_deps = [ |
| 68 | ":crypto_buildconfig", |
| 69 | "${chip_root}/src/lib/asn1", |
| 70 | "${chip_root}/src/lib/core", |
Andrei Litvin | b389c60 | 2024-02-01 00:25:59 -0500 | [diff] [blame] | 71 | "${chip_root}/src/lib/core:types", |
Steven Cooreman | 3dc97f0 | 2022-08-04 20:34:20 +0200 | [diff] [blame] | 72 | "${chip_root}/src/lib/support", |
| 73 | "${nlassert_root}:nlassert", |
| 74 | ] |
| 75 | } |
| 76 | |
Michael Spang | efa630b | 2020-07-08 22:23:08 -0400 | [diff] [blame] | 77 | if (chip_crypto == "openssl") { |
Łukasz Duda | 4e1faf2 | 2021-01-27 17:47:25 +0100 | [diff] [blame] | 78 | import("${build_root}/config/linux/pkg_config.gni") |
Michael Spang | efa630b | 2020-07-08 22:23:08 -0400 | [diff] [blame] | 79 | |
| 80 | pkg_config("openssl_config") { |
| 81 | packages = [ "openssl" ] |
| 82 | } |
Steven Cooreman | 3dc97f0 | 2022-08-04 20:34:20 +0200 | [diff] [blame] | 83 | |
| 84 | source_set("cryptopal_openssl") { |
| 85 | sources = [ "CHIPCryptoPALOpenSSL.cpp" ] |
| 86 | public_configs = [ ":openssl_config" ] |
| 87 | public_deps = [ ":public_headers" ] |
| 88 | } |
Chris Letnick | fa549eb | 2022-07-18 09:14:02 -0400 | [diff] [blame] | 89 | } else if (chip_crypto == "boringssl") { |
Vivien Nicolas | 7301ecf | 2022-10-06 16:17:52 +0200 | [diff] [blame] | 90 | import("${chip_root}/build_overrides/boringssl.gni") |
Steven Cooreman | 3dc97f0 | 2022-08-04 20:34:20 +0200 | [diff] [blame] | 91 | |
| 92 | source_set("cryptopal_boringssl") { |
| 93 | # BoringSSL is close enough to OpenSSL that it uses same PAL, with minor #ifdef differences |
| 94 | sources = [ "CHIPCryptoPALOpenSSL.cpp" ] |
| 95 | public_deps = [ |
| 96 | ":public_headers", |
| 97 | "${boringssl_root}:boringssl", |
| 98 | ] |
| 99 | } |
Chris Letnick | fa549eb | 2022-07-18 09:14:02 -0400 | [diff] [blame] | 100 | } else if (chip_crypto == "mbedtls") { |
Michael Spang | efa630b | 2020-07-08 22:23:08 -0400 | [diff] [blame] | 101 | import("//build_overrides/mbedtls.gni") |
Steven Cooreman | 3dc97f0 | 2022-08-04 20:34:20 +0200 | [diff] [blame] | 102 | |
| 103 | source_set("cryptopal_mbedtls") { |
Damian Królik | e3b0cc0 | 2023-10-03 00:35:38 +0200 | [diff] [blame] | 104 | sources = [ |
| 105 | "CHIPCryptoPALmbedTLS.cpp", |
| 106 | "CHIPCryptoPALmbedTLS.h", |
| 107 | "CHIPCryptoPALmbedTLSCert.cpp", |
| 108 | ] |
Steven Cooreman | 3dc97f0 | 2022-08-04 20:34:20 +0200 | [diff] [blame] | 109 | public_deps = [ ":public_headers" ] |
| 110 | |
alexhqwang | d54101b | 2022-11-29 05:11:40 -0800 | [diff] [blame] | 111 | if (!chip_external_mbedtls) { |
Steven Cooreman | 3dc97f0 | 2022-08-04 20:34:20 +0200 | [diff] [blame] | 112 | public_deps += [ "${mbedtls_root}:mbedtls" ] |
| 113 | } |
| 114 | } |
Damian Królik | d37c801 | 2022-10-20 04:41:14 +0200 | [diff] [blame] | 115 | } else if (chip_crypto == "psa") { |
| 116 | import("//build_overrides/mbedtls.gni") |
| 117 | |
| 118 | source_set("cryptopal_psa") { |
Damian Królik | 12b1744 | 2022-12-13 23:18:14 +0100 | [diff] [blame] | 119 | sources = [ |
| 120 | "CHIPCryptoPALPSA.cpp", |
| 121 | "CHIPCryptoPALPSA.h", |
Damian Królik | e3b0cc0 | 2023-10-03 00:35:38 +0200 | [diff] [blame] | 122 | "CHIPCryptoPALmbedTLS.h", |
| 123 | "CHIPCryptoPALmbedTLSCert.cpp", |
Damian Królik | 12b1744 | 2022-12-13 23:18:14 +0100 | [diff] [blame] | 124 | ] |
Damian Królik | d37c801 | 2022-10-20 04:41:14 +0200 | [diff] [blame] | 125 | public_deps = [ ":public_headers" ] |
| 126 | |
Damian Królik | b07872c | 2023-02-17 13:56:47 +0100 | [diff] [blame] | 127 | if (!chip_external_mbedtls) { |
Damian Królik | d37c801 | 2022-10-20 04:41:14 +0200 | [diff] [blame] | 128 | public_deps += [ "${mbedtls_root}:mbedtls" ] |
| 129 | } |
| 130 | } |
Michael Spang | efa630b | 2020-07-08 22:23:08 -0400 | [diff] [blame] | 131 | } |
| 132 | |
| 133 | static_library("crypto") { |
| 134 | output_name = "libChipCrypto" |
| 135 | |
Michael Spang | 84c6df4 | 2020-08-13 10:01:29 -0400 | [diff] [blame] | 136 | sources = [ |
| 137 | "CHIPCryptoPAL.cpp", |
Damian Królik | b07872c | 2023-02-17 13:56:47 +0100 | [diff] [blame] | 138 | "DefaultSessionKeystore.h", |
Tennessee Carmel-Veilleux | 4e3930a | 2022-06-10 09:08:31 -0400 | [diff] [blame] | 139 | "PersistentStorageOperationalKeystore.cpp", |
| 140 | "PersistentStorageOperationalKeystore.h", |
Tennessee Carmel-Veilleux | 267951c | 2021-10-13 22:05:45 -0400 | [diff] [blame] | 141 | "RandUtils.cpp", |
| 142 | "RandUtils.h", |
Michael Spang | 84c6df4 | 2020-08-13 10:01:29 -0400 | [diff] [blame] | 143 | ] |
Michael Spang | efa630b | 2020-07-08 22:23:08 -0400 | [diff] [blame] | 144 | |
Damian Królik | b07872c | 2023-02-17 13:56:47 +0100 | [diff] [blame] | 145 | if (chip_crypto == "psa") { |
| 146 | sources += [ |
Damian Królik | e3b0cc0 | 2023-10-03 00:35:38 +0200 | [diff] [blame] | 147 | "PSAOperationalKeystore.cpp", |
| 148 | "PSAOperationalKeystore.h", |
Damian Królik | b07872c | 2023-02-17 13:56:47 +0100 | [diff] [blame] | 149 | "PSASessionKeystore.cpp", |
| 150 | "PSASessionKeystore.h", |
| 151 | ] |
| 152 | } else { |
| 153 | sources += [ |
| 154 | "RawKeySessionKeystore.cpp", |
| 155 | "RawKeySessionKeystore.h", |
| 156 | ] |
| 157 | } |
| 158 | |
Tennessee Carmel-Veilleux | 768b575 | 2022-07-18 22:13:02 -0400 | [diff] [blame] | 159 | public_configs = [] |
| 160 | |
Boris Zbarsky | 902a864 | 2020-09-25 17:41:22 -0400 | [diff] [blame] | 161 | cflags = [ "-Wconversion" ] |
| 162 | |
Steven Cooreman | 3dc97f0 | 2022-08-04 20:34:20 +0200 | [diff] [blame] | 163 | public_deps = [ ":public_headers" ] |
Michael Spang | efa630b | 2020-07-08 22:23:08 -0400 | [diff] [blame] | 164 | |
Michael Spang | efa630b | 2020-07-08 22:23:08 -0400 | [diff] [blame] | 165 | if (chip_crypto == "mbedtls") { |
Steven Cooreman | 3dc97f0 | 2022-08-04 20:34:20 +0200 | [diff] [blame] | 166 | public_deps += [ ":cryptopal_mbedtls" ] |
Damian Królik | d37c801 | 2022-10-20 04:41:14 +0200 | [diff] [blame] | 167 | } else if (chip_crypto == "psa") { |
| 168 | public_deps += [ ":cryptopal_psa" ] |
Michael Spang | efa630b | 2020-07-08 22:23:08 -0400 | [diff] [blame] | 169 | } else if (chip_crypto == "openssl") { |
Steven Cooreman | 3dc97f0 | 2022-08-04 20:34:20 +0200 | [diff] [blame] | 170 | public_deps += [ ":cryptopal_openssl" ] |
Chris Letnick | fa549eb | 2022-07-18 09:14:02 -0400 | [diff] [blame] | 171 | } else if (chip_crypto == "boringssl") { |
Steven Cooreman | 3dc97f0 | 2022-08-04 20:34:20 +0200 | [diff] [blame] | 172 | public_deps += [ ":cryptopal_boringssl" ] |
Steven Cooreman | 3dc97f0 | 2022-08-04 20:34:20 +0200 | [diff] [blame] | 173 | } else if (chip_crypto == "platform") { |
| 174 | # Platform implementation is responsible for bringing their |
| 175 | # own implementation and dependencies |
Michael Spang | efa630b | 2020-07-08 22:23:08 -0400 | [diff] [blame] | 176 | } else { |
| 177 | assert(false, "Invalid CHIP crypto") |
| 178 | } |
Michael Spang | efa630b | 2020-07-08 22:23:08 -0400 | [diff] [blame] | 179 | } |