Skip to content

Commit

Permalink
[Bouffalolab] Enable BL602 hardware crypto engine for mbedtls (#24272)
Browse files Browse the repository at this point in the history
* create bl_iot_sdk.gni

* update bl_iot_sdk.gni

* remove more 702 specific-name

* update bl602

* update bl602 & bl702

* update toolchain path

* fix issues for bl602

* bl602 mbedtls

* correct partition table for bl702 and update sdk sub-repo

* fix restyle
  • Loading branch information
wy-hh authored and pull[bot] committed Aug 1, 2023
1 parent 7c59542 commit 3181353
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 40 deletions.
7 changes: 3 additions & 4 deletions src/platform/bouffalolab/BL602/CHIPPlatformConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,18 @@
#define CHIP_CONFIG_HASH_IMPLEMENTATION_MBEDTLS 0
#define CHIP_CONFIG_HASH_IMPLEMENTATION_PLATFORM 0

// FIXME: BL602 set to MBED-TLS (But this is third-party repo in CHIP, not SDK)

#define CHIP_CONFIG_AES_IMPLEMENTATION_OPENSSL 0
#define CHIP_CONFIG_AES_IMPLEMENTATION_AESNI 0
#define CHIP_CONFIG_AES_IMPLEMENTATION_MBEDTLS 1
#define CHIP_CONFIG_AES_IMPLEMENTATION_PLATFORM 0

// FIXME: BL602 currently set to CHIP (Does this use Entropy.cpp ?)

#define CHIP_CONFIG_RNG_IMPLEMENTATION_OPENSSL 0
#define CHIP_CONFIG_RNG_IMPLEMENTATION_CHIPDRBG 1
#define CHIP_CONFIG_RNG_IMPLEMENTATION_PLATFORM 0

//#define CHIP_CONFIG_SHA256_CONTEXT_SIZE sizeof(bl_sha_ctx_t)
#define CHIP_CONFIG_SHA256_CONTEXT_SIZE ((1 + 5 + 18 + 16 + 16) * sizeof(unsigned int))

#define CHIP_CONFIG_ENABLE_PASE_INITIATOR 0
#define CHIP_CONFIG_ENABLE_PASE_RESPONDER 1
#define CHIP_CONFIG_ENABLE_CASE_INITIATOR 1
Expand Down
7 changes: 7 additions & 0 deletions src/platform/bouffalolab/BL602/bl602-chip-mbedtls-config.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,5 +138,12 @@ typedef void mbedtls_ecp_restart_ctx;

#define MBEDTLS_SSL_CIPHERSUITES MBEDTLS_TLS_ECJPAKE_WITH_AES_128_CCM_8

#define MBEDTLS_ENTROPY_HARDWARE_ALT

#define MBEDTLS_SHA1_ALT
#define MBEDTLS_SHA256_ALT
#define MBEDTLS_AES_ALT
#define MBEDTLS_ECP_ALT

//#include "config-device-acceleration.h"
#include "mbedtls/check_config.h"
115 changes: 79 additions & 36 deletions third_party/bouffalolab/bl602/bl_iot_sdk.gni
Original file line number Diff line number Diff line change
Expand Up @@ -64,41 +64,6 @@ template("bl_iot_sdk") {
}
}

source_set("${sdk_target_name}_code") {
sources = [
"${chip_root}/third_party/mbedtls/repo/library/aes.c",
"${chip_root}/third_party/mbedtls/repo/library/asn1parse.c",
"${chip_root}/third_party/mbedtls/repo/library/asn1write.c",
"${chip_root}/third_party/mbedtls/repo/library/bignum.c",
"${chip_root}/third_party/mbedtls/repo/library/ccm.c",
"${chip_root}/third_party/mbedtls/repo/library/cipher.c",
"${chip_root}/third_party/mbedtls/repo/library/cipher_wrap.c",
"${chip_root}/third_party/mbedtls/repo/library/constant_time.c",
"${chip_root}/third_party/mbedtls/repo/library/ctr_drbg.c",
"${chip_root}/third_party/mbedtls/repo/library/ecdh.c",
"${chip_root}/third_party/mbedtls/repo/library/ecdsa.c",
"${chip_root}/third_party/mbedtls/repo/library/ecp.c",
"${chip_root}/third_party/mbedtls/repo/library/ecp_curves.c",
"${chip_root}/third_party/mbedtls/repo/library/entropy.c",
"${chip_root}/third_party/mbedtls/repo/library/hkdf.c",
"${chip_root}/third_party/mbedtls/repo/library/hmac_drbg.c",
"${chip_root}/third_party/mbedtls/repo/library/md.c",
"${chip_root}/third_party/mbedtls/repo/library/oid.c",
"${chip_root}/third_party/mbedtls/repo/library/pk.c",
"${chip_root}/third_party/mbedtls/repo/library/pk_wrap.c",
"${chip_root}/third_party/mbedtls/repo/library/pkcs5.c",
"${chip_root}/third_party/mbedtls/repo/library/pkwrite.c",
"${chip_root}/third_party/mbedtls/repo/library/platform.c",
"${chip_root}/third_party/mbedtls/repo/library/platform_util.c",
"${chip_root}/third_party/mbedtls/repo/library/sha256.c",
"${chip_root}/third_party/mbedtls/repo/library/sha512.c",
"${chip_root}/third_party/mbedtls/repo/library/x509_create.c",
"${chip_root}/third_party/mbedtls/repo/library/x509write_csr.c",
]
configs += [ ":${sdk_target_name}_config_freertos" ]
public_configs = [ ":${sdk_target_name}_config" ]
}

source_set("${sdk_target_name}_soc") {
defines = [ "BL602_MATTER_SUPPORT" ]

Expand Down Expand Up @@ -469,6 +434,84 @@ template("bl_iot_sdk") {
]
}

config("${sdk_target_name}_config_mbedtls") {
include_dirs = [
"${bl_iot_sdk_root}/components/security/mbedtls_lts/mbedtls/include",
"${bl_iot_sdk_root}/components/security/mbedtls_lts/port",
]

defines = [ "MBEDTLS_CONFIG_FILE=\"bl602-chip-mbedtls-config.h\"" ]
}

source_set("${sdk_target_name}_mbedtls") {
include_dirs =
[ "${bl_iot_sdk_root}/components/security/mbedtls_lts/mbedtls/library" ]

sources = [
"${bl_iot_sdk_root}/components/security/mbedtls_lts/port/hw_acc/aes_alt.c",
"${bl_iot_sdk_root}/components/security/mbedtls_lts/port/hw_acc/bignum_hw.c",
"${bl_iot_sdk_root}/components/security/mbedtls_lts/port/hw_acc/ecp_alt.c",
"${bl_iot_sdk_root}/components/security/mbedtls_lts/port/hw_acc/ecp_curves_alt.c",
"${bl_iot_sdk_root}/components/security/mbedtls_lts/port/hw_acc/hw_common.c",
"${bl_iot_sdk_root}/components/security/mbedtls_lts/port/hw_acc/hw_common.h",
"${bl_iot_sdk_root}/components/security/mbedtls_lts/port/hw_acc/sha1_alt.c",
"${bl_iot_sdk_root}/components/security/mbedtls_lts/port/hw_acc/sha256_alt.c",
]

sources += [
"${bl_iot_sdk_root}/components/security/mbedtls_lts/port/bignum_ext.c",
"${bl_iot_sdk_root}/components/security/mbedtls_lts/port/hw_entropy_poll.c",
"${bl_iot_sdk_root}/components/security/mbedtls_lts/port/mbedtls_port_mem.c",
"${bl_iot_sdk_root}/components/security/mbedtls_lts/port/net_sockets.c",
"${bl_iot_sdk_root}/components/security/mbedtls_lts/port/pkparse.c",
]

sources += [
"${bl_iot_sdk_root}/components/security/mbedtls_lts/mbedtls/library/aes.c",
"${bl_iot_sdk_root}/components/security/mbedtls_lts/mbedtls/library/asn1parse.c",
"${bl_iot_sdk_root}/components/security/mbedtls_lts/mbedtls/library/asn1write.c",
"${bl_iot_sdk_root}/components/security/mbedtls_lts/mbedtls/library/bignum.c",
"${bl_iot_sdk_root}/components/security/mbedtls_lts/mbedtls/library/ccm.c",
"${bl_iot_sdk_root}/components/security/mbedtls_lts/mbedtls/library/cipher.c",
"${bl_iot_sdk_root}/components/security/mbedtls_lts/mbedtls/library/cipher_wrap.c",
"${bl_iot_sdk_root}/components/security/mbedtls_lts/mbedtls/library/constant_time.c",
"${bl_iot_sdk_root}/components/security/mbedtls_lts/mbedtls/library/ctr_drbg.c",
"${bl_iot_sdk_root}/components/security/mbedtls_lts/mbedtls/library/ecdh.c",
"${bl_iot_sdk_root}/components/security/mbedtls_lts/mbedtls/library/ecdsa.c",
"${bl_iot_sdk_root}/components/security/mbedtls_lts/mbedtls/library/ecp.c",
"${bl_iot_sdk_root}/components/security/mbedtls_lts/mbedtls/library/ecp_curves.c",
"${bl_iot_sdk_root}/components/security/mbedtls_lts/mbedtls/library/entropy.c",
"${bl_iot_sdk_root}/components/security/mbedtls_lts/mbedtls/library/hkdf.c",
"${bl_iot_sdk_root}/components/security/mbedtls_lts/mbedtls/library/hmac_drbg.c",
"${bl_iot_sdk_root}/components/security/mbedtls_lts/mbedtls/library/md.c",
"${bl_iot_sdk_root}/components/security/mbedtls_lts/mbedtls/library/oid.c",
"${bl_iot_sdk_root}/components/security/mbedtls_lts/mbedtls/library/pk.c",
"${bl_iot_sdk_root}/components/security/mbedtls_lts/mbedtls/library/pk_wrap.c",
"${bl_iot_sdk_root}/components/security/mbedtls_lts/mbedtls/library/pkcs5.c",
"${bl_iot_sdk_root}/components/security/mbedtls_lts/mbedtls/library/pkwrite.c",
"${bl_iot_sdk_root}/components/security/mbedtls_lts/mbedtls/library/platform.c",
"${bl_iot_sdk_root}/components/security/mbedtls_lts/mbedtls/library/platform_util.c",
"${bl_iot_sdk_root}/components/security/mbedtls_lts/mbedtls/library/sha256.c",
"${bl_iot_sdk_root}/components/security/mbedtls_lts/mbedtls/library/sha512.c",
"${bl_iot_sdk_root}/components/security/mbedtls_lts/mbedtls/library/x509_create.c",
"${bl_iot_sdk_root}/components/security/mbedtls_lts/mbedtls/library/x509write_csr.c",
]

cflags_c = [
"-Wno-sign-compare",
"-Wno-implicit-function-declaration",
]
configs += [
":${sdk_target_name}_config_BSP_Driver",
":${sdk_target_name}_config_hosal",
":${sdk_target_name}_config_freertos",
]
public_configs = [
":${sdk_target_name}_config",
":${sdk_target_name}_config_mbedtls",
]
}

config("${sdk_target_name}_ble_config") {
include_dirs = [
"${bl_iot_sdk_root}/components/network/ble/blecontroller/ble_inc",
Expand Down Expand Up @@ -874,11 +917,11 @@ template("bl_iot_sdk") {
":${sdk_target_name}_bl602_freertos",
":${sdk_target_name}_blcrypto_suite",
":${sdk_target_name}_ble",
":${sdk_target_name}_code",
":${sdk_target_name}_fs",
":${sdk_target_name}_hosal",
":${sdk_target_name}_libc",
":${sdk_target_name}_lwip",
":${sdk_target_name}_mbedtls",
":${sdk_target_name}_soc",
":${sdk_target_name}_stage",
":${sdk_target_name}_sys",
Expand Down

0 comments on commit 3181353

Please sign in to comment.