Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 16 additions & 12 deletions boot/zephyr/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -300,21 +300,25 @@ elseif(CONFIG_BOOT_SIGNATURE_TYPE_ED25519 OR CONFIG_BOOT_ENCRYPT_X25519)
endif()

if(NOT CONFIG_BOOT_ED25519_PSA AND NOT CONFIG_BOOT_ECDSA_PSA)
if(CONFIG_BOOT_ENCRYPT_EC256 OR CONFIG_BOOT_ENCRYPT_X25519)
zephyr_library_sources(
${TINYCRYPT_DIR}/source/aes_encrypt.c
${TINYCRYPT_DIR}/source/aes_decrypt.c
${TINYCRYPT_DIR}/source/ctr_mode.c
${TINYCRYPT_DIR}/source/hmac.c
${TINYCRYPT_DIR}/source/ecc_dh.c
)
if(CONFIG_BOOT_USE_TINYCRYPT)
if(CONFIG_BOOT_ENCRYPT_EC256 OR CONFIG_BOOT_ENCRYPT_X25519)
zephyr_library_sources(
${TINYCRYPT_DIR}/source/aes_encrypt.c
${TINYCRYPT_DIR}/source/aes_decrypt.c
${TINYCRYPT_DIR}/source/ctr_mode.c
${TINYCRYPT_DIR}/source/hmac.c
${TINYCRYPT_DIR}/source/ecc_dh.c
)
endif()
endif()
endif()

if(CONFIG_BOOT_ENCRYPT_EC256 AND NOT CONFIG_BOOT_ECDSA_PSA)
zephyr_library_sources(
${TINYCRYPT_DIR}/source/ecc_dh.c
)
if(CONFIG_BOOT_USE_TINYCRYPT)
if(CONFIG_BOOT_ENCRYPT_EC256 AND NOT CONFIG_BOOT_ECDSA_PSA)
zephyr_library_sources(
${TINYCRYPT_DIR}/source/ecc_dh.c
)
endif()
endif()

if(CONFIG_MCUBOOT_SERIAL)
Expand Down
14 changes: 14 additions & 0 deletions boot/zephyr/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,20 @@ config BOOT_ECDSA_TINYCRYPT
bool "Use tinycrypt"
select BOOT_USE_TINYCRYPT

config BOOT_ECDSA_MBEDTLS
bool "Use mbedTLS"
select BOOT_USE_MBEDTLS
select MBEDTLS
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not really sure how you expect this to work? Given that it doesn't:

/opt/zephyr-sdk-0.17.0/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.2.0/../../../../arm-zephyr-eabi/bin/ld.bfd: app/libapp.a(image_ecdsa.c.obj): in function `bootutil_ecdsa_init':
/tmp/aa/bootloader/mcuboot/boot/bootutil/include/bootutil/crypto/ecdsa.h:490: undefined reference to `mbedtls_ecdsa_init'
/opt/zephyr-sdk-0.17.0/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.2.0/../../../../arm-zephyr-eabi/bin/ld.bfd: app/libapp.a(image_ecdsa.c.obj): in function `bootutil_ecdsa_verify':
/tmp/aa/bootloader/mcuboot/boot/bootutil/include/bootutil/crypto/ecdsa.h:577: undefined reference to `mbedtls_ecp_group_load'
/opt/zephyr-sdk-0.17.0/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.2.0/../../../../arm-zephyr-eabi/bin/ld.bfd: /tmp/aa/bootloader/mcuboot/boot/bootutil/include/bootutil/crypto/ecdsa.h:582: undefined reference to `mbedtls_ecp_point_read_binary'
/opt/zephyr-sdk-0.17.0/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.2.0/../../../../arm-zephyr-eabi/bin/ld.bfd: /tmp/aa/bootloader/mcuboot/boot/bootutil/include/bootutil/crypto/ecdsa.h:587: undefined reference to `mbedtls_ecp_check_pubkey'
/opt/zephyr-sdk-0.17.0/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.2.0/../../../../arm-zephyr-eabi/bin/ld.bfd: /tmp/aa/bootloader/mcuboot/boot/bootutil/include/bootutil/crypto/ecdsa.h:592: undefined reference to `mbedtls_ecdsa_read_signature'
/opt/zephyr-sdk-0.17.0/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.2.0/../../../../arm-zephyr-eabi/bin/ld.bfd: app/libapp.a(image_ecdsa.c.obj): in function `bootutil_ecdsa_drop':
/tmp/aa/bootloader/mcuboot/boot/bootutil/include/bootutil/crypto/ecdsa.h:495: undefined reference to `mbedtls_ecdsa_free'
/opt/zephyr-sdk-0.17.0/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.2.0/../../../../arm-zephyr-eabi/bin/ld.bfd: app/libapp.a(keys.c.obj):/tmp/aa/bootloader/mcuboot/boot/zephyr/keys.c:52: undefined reference to `ecdsa_pub_key'
/opt/zephyr-sdk-0.17.0/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.2.0/../../../../arm-zephyr-eabi/bin/ld.bfd: app/libapp.a(keys.c.obj):(.rodata.bootutil_keys+0x4): undefined reference to `ecdsa_pub_key_len'

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previously, I used sysbuild with:

CONFIG_CUSTOM_MBEDTLS_CFG_FILE=y CONFIG_MBEDTLS_CFG_FILE="config-ec.h"

to provide the missing mbedTLS functions.

I have now updated the Kconfig to select all required mbedTLS options directly, without relying on a custom mbedTLS config file. All dependencies are handled via Kconfig, including when BOOT_ENCRYPT_IMAGE is enabled. I am not entirely sure if all requirements are covered, so feedback is welcome.

select MBEDTLS_ECP_C if MBEDTLS_BUILTIN
select MBEDTLS_ECDSA_C if MBEDTLS_BUILTIN
select MBEDTLS_ECP_DP_SECP256R1_ENABLED if MBEDTLS_BUILTIN
select MBEDTLS_ASN1_PARSE_C if MBEDTLS_BUILTIN
select MBEDTLS_ECP_NIST_OPTIM if MBEDTLS_BUILTIN
select MBEDTLS_SHA256 if MBEDTLS_BUILTIN
select MBEDTLS_MD if MBEDTLS_BUILTIN
select MBEDTLS_ECDH_C if MBEDTLS_BUILTIN && BOOT_ENCRYPT_IMAGE
select BOOT_AES_MBEDTLS_DEPENDENCIES if MBEDTLS_BUILTIN && BOOT_ENCRYPT_IMAGE

config BOOT_ECDSA_CC310
bool "Use CC310"
depends on HAS_HW_NRF_CC310
Expand Down