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" || |
| 25 | current_os == "zephyr" || current_os == "mbed" || current_os == "webos") { |
| 26 | chip_crypto = "mbedtls" |
| 27 | } else { |
| 28 | chip_crypto = "openssl" |
| 29 | } |
| 30 | } |
| 31 | |
| 32 | assert( |
| 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 Spang | 1fcb6dd | 2020-08-24 11:19:04 -0400 | [diff] [blame] | 38 | buildconfig_header("crypto_buildconfig") { |
| 39 | header = "CryptoBuildConfig.h" |
| 40 | header_dir = "crypto" |
| 41 | |
Tennessee Carmel-Veilleux | 768b575 | 2022-07-18 22:13:02 -0400 | [diff] [blame] | 42 | chip_crypto_mbedtls = chip_crypto == "mbedtls" |
| 43 | chip_crypto_openssl = chip_crypto == "openssl" |
| 44 | chip_crypto_boringssl = chip_crypto == "boringssl" |
Steven Cooreman | 3dc97f0 | 2022-08-04 20:34:20 +0200 | [diff] [blame] | 45 | chip_crypto_platform = chip_crypto == "platform" |
Tennessee Carmel-Veilleux | 768b575 | 2022-07-18 22:13:02 -0400 | [diff] [blame] | 46 | |
| 47 | defines = [ |
| 48 | "CHIP_CRYPTO_MBEDTLS=${chip_crypto_mbedtls}", |
| 49 | "CHIP_CRYPTO_OPENSSL=${chip_crypto_openssl}", |
| 50 | "CHIP_CRYPTO_BORINGSSL=${chip_crypto_boringssl}", |
Steven Cooreman | 3dc97f0 | 2022-08-04 20:34:20 +0200 | [diff] [blame] | 51 | "CHIP_CRYPTO_PLATFORM=${chip_crypto_platform}", |
Tennessee Carmel-Veilleux | 768b575 | 2022-07-18 22:13:02 -0400 | [diff] [blame] | 52 | ] |
Jagadish-NXP | 467dd44 | 2021-04-15 20:14:25 +0530 | [diff] [blame] | 53 | |
| 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-nxp | 2ef08db | 2021-11-26 01:00:25 +0530 | [diff] [blame] | 61 | |
| 62 | if (chip_with_se05x_da == 1) { |
| 63 | defines += [ "ENABLE_HSM_DEVICE_ATTESTATION=1" ] |
| 64 | } |
Michael Spang | efa630b | 2020-07-08 22:23:08 -0400 | [diff] [blame] | 65 | } |
| 66 | |
Steven Cooreman | 3dc97f0 | 2022-08-04 20:34:20 +0200 | [diff] [blame] | 67 | source_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 Spang | efa630b | 2020-07-08 22:23:08 -0400 | [diff] [blame] | 82 | if (chip_crypto == "openssl") { |
Łukasz Duda | 4e1faf2 | 2021-01-27 17:47:25 +0100 | [diff] [blame] | 83 | import("${build_root}/config/linux/pkg_config.gni") |
Michael Spang | efa630b | 2020-07-08 22:23:08 -0400 | [diff] [blame] | 84 | |
| 85 | pkg_config("openssl_config") { |
| 86 | packages = [ "openssl" ] |
| 87 | } |
Steven Cooreman | 3dc97f0 | 2022-08-04 20:34:20 +0200 | [diff] [blame] | 88 | |
| 89 | source_set("cryptopal_openssl") { |
| 90 | sources = [ "CHIPCryptoPALOpenSSL.cpp" ] |
| 91 | public_configs = [ ":openssl_config" ] |
| 92 | public_deps = [ ":public_headers" ] |
| 93 | } |
Chris Letnick | fa549eb | 2022-07-18 09:14:02 -0400 | [diff] [blame] | 94 | } else if (chip_crypto == "boringssl") { |
| 95 | import("//build_overrides/boringssl.gni") |
Steven Cooreman | 3dc97f0 | 2022-08-04 20:34:20 +0200 | [diff] [blame] | 96 | |
| 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 Letnick | fa549eb | 2022-07-18 09:14:02 -0400 | [diff] [blame] | 105 | } else if (chip_crypto == "mbedtls") { |
Michael Spang | efa630b | 2020-07-08 22:23:08 -0400 | [diff] [blame] | 106 | import("//build_overrides/mbedtls.gni") |
Steven Cooreman | 3dc97f0 | 2022-08-04 20:34:20 +0200 | [diff] [blame] | 107 | |
| 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 | } |
doru91 | 9b2c889 | 2022-07-22 21:40:26 +0300 | [diff] [blame] | 118 | } else if (chip_crypto == "tinycrypt") { |
| 119 | import("//build_overrides/mbedtls.gni") |
Steven Cooreman | 3dc97f0 | 2022-08-04 20:34:20 +0200 | [diff] [blame] | 120 | |
| 121 | source_set("cryptopal_tinycrypt") { |
| 122 | sources = [ "CHIPCryptoPALTinyCrypt.cpp" ] |
| 123 | public_deps = [ |
| 124 | ":public_headers", |
| 125 | "${mbedtls_root}:mbedtls", |
| 126 | ] |
| 127 | } |
Michael Spang | efa630b | 2020-07-08 22:23:08 -0400 | [diff] [blame] | 128 | } |
| 129 | |
| 130 | static_library("crypto") { |
| 131 | output_name = "libChipCrypto" |
| 132 | |
Michael Spang | 84c6df4 | 2020-08-13 10:01:29 -0400 | [diff] [blame] | 133 | sources = [ |
| 134 | "CHIPCryptoPAL.cpp", |
Tennessee Carmel-Veilleux | 4e3930a | 2022-06-10 09:08:31 -0400 | [diff] [blame] | 135 | "PersistentStorageOperationalKeystore.cpp", |
| 136 | "PersistentStorageOperationalKeystore.h", |
Tennessee Carmel-Veilleux | 267951c | 2021-10-13 22:05:45 -0400 | [diff] [blame] | 137 | "RandUtils.cpp", |
| 138 | "RandUtils.h", |
Michael Spang | 84c6df4 | 2020-08-13 10:01:29 -0400 | [diff] [blame] | 139 | ] |
Michael Spang | efa630b | 2020-07-08 22:23:08 -0400 | [diff] [blame] | 140 | |
Tennessee Carmel-Veilleux | 768b575 | 2022-07-18 22:13:02 -0400 | [diff] [blame] | 141 | public_configs = [] |
| 142 | |
Boris Zbarsky | 902a864 | 2020-09-25 17:41:22 -0400 | [diff] [blame] | 143 | cflags = [ "-Wconversion" ] |
| 144 | |
Steven Cooreman | 3dc97f0 | 2022-08-04 20:34:20 +0200 | [diff] [blame] | 145 | public_deps = [ ":public_headers" ] |
Michael Spang | efa630b | 2020-07-08 22:23:08 -0400 | [diff] [blame] | 146 | |
Michael Spang | efa630b | 2020-07-08 22:23:08 -0400 | [diff] [blame] | 147 | if (chip_crypto == "mbedtls") { |
Steven Cooreman | 3dc97f0 | 2022-08-04 20:34:20 +0200 | [diff] [blame] | 148 | public_deps += [ ":cryptopal_mbedtls" ] |
Michael Spang | efa630b | 2020-07-08 22:23:08 -0400 | [diff] [blame] | 149 | } else if (chip_crypto == "openssl") { |
Steven Cooreman | 3dc97f0 | 2022-08-04 20:34:20 +0200 | [diff] [blame] | 150 | public_deps += [ ":cryptopal_openssl" ] |
Chris Letnick | fa549eb | 2022-07-18 09:14:02 -0400 | [diff] [blame] | 151 | } else if (chip_crypto == "boringssl") { |
Steven Cooreman | 3dc97f0 | 2022-08-04 20:34:20 +0200 | [diff] [blame] | 152 | public_deps += [ ":cryptopal_boringssl" ] |
doru91 | 9b2c889 | 2022-07-22 21:40:26 +0300 | [diff] [blame] | 153 | } else if (chip_crypto == "tinycrypt") { |
Steven Cooreman | 3dc97f0 | 2022-08-04 20:34:20 +0200 | [diff] [blame] | 154 | public_deps += [ ":cryptopal_tinycrypt" ] |
| 155 | } else if (chip_crypto == "platform") { |
| 156 | # Platform implementation is responsible for bringing their |
| 157 | # own implementation and dependencies |
Michael Spang | efa630b | 2020-07-08 22:23:08 -0400 | [diff] [blame] | 158 | } else { |
| 159 | assert(false, "Invalid CHIP crypto") |
| 160 | } |
Jagadish-NXP | 467dd44 | 2021-04-15 20:14:25 +0530 | [diff] [blame] | 161 | |
| 162 | if (chip_with_se05x == 1) { |
sujaygkulkarni-nxp | 6a0533d | 2021-04-26 19:00:05 +0530 | [diff] [blame] | 163 | sources += [ |
Jagadish-NXP | b6ccd46 | 2021-05-12 22:16:20 +0530 | [diff] [blame] | 164 | "hsm/nxp/CHIPCryptoPALHsm_SE05X_HKDF.cpp", |
Tennessee Carmel-Veilleux | 8b5b24f | 2021-07-07 17:49:38 -0400 | [diff] [blame] | 165 | "hsm/nxp/CHIPCryptoPALHsm_SE05X_HMAC.cpp", |
sujaygkulkarni-nxp | 6a0533d | 2021-04-26 19:00:05 +0530 | [diff] [blame] | 166 | "hsm/nxp/CHIPCryptoPALHsm_SE05X_P256.cpp", |
Jagadish-NXP | a8226ab | 2021-05-05 20:14:28 +0530 | [diff] [blame] | 167 | "hsm/nxp/CHIPCryptoPALHsm_SE05X_PBKDF.cpp", |
sujaygkulkarni-nxp | 6a0533d | 2021-04-26 19:00:05 +0530 | [diff] [blame] | 168 | "hsm/nxp/CHIPCryptoPALHsm_SE05X_Spake2p.cpp", |
| 169 | "hsm/nxp/CHIPCryptoPALHsm_SE05X_utils.cpp", |
sujaygkulkarni-nxp | 769eca4 | 2022-08-16 03:02:40 +0530 | [diff] [blame^] | 170 | "hsm/nxp/PersistentStorageOperationalKeystoreHSM.cpp", |
| 171 | "hsm/nxp/PersistentStorageOperationalKeystoreHSM.h", |
sujaygkulkarni-nxp | 6a0533d | 2021-04-26 19:00:05 +0530 | [diff] [blame] | 172 | ] |
Jagadish-NXP | 467dd44 | 2021-04-15 20:14:25 +0530 | [diff] [blame] | 173 | public_deps += [ "${chip_root}/third_party/simw-top-mini:se05x" ] |
| 174 | public_configs += [ "${chip_root}/third_party/simw-top-mini:se05x_config" ] |
| 175 | } |
Michael Spang | efa630b | 2020-07-08 22:23:08 -0400 | [diff] [blame] | 176 | } |