Commit 28ee5b0e authored by Fabio Utzig's avatar Fabio Utzig Committed by David Brown
Browse files

Add Zephyr support for bundled mbed-tls ASN1 parser

When using EC256 for signing, Zephyr now uses the bundled tinycrypt
and mbed-tls ASN1 parser instead of relying on the one provided by
the OS.

Signed-off-by: default avatarFabio Utzig <utzig@apache.org>
parent ac18eec7
Loading
Loading
Loading
Loading
+11 −1
Changes for boot/zephyr/CMakeLists.txt: 11 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -131,12 +131,18 @@ get_filename_component(BOOT_DIR ${APPLICATION_SOURCE_DIR} DIRECTORY)
get_filename_component(MCUBOOT_DIR ${BOOT_DIR} DIRECTORY)
# Path to tinycrypt library source subdirectory of MCUBOOT_DIR.
set(TINYCRYPT_DIR "${MCUBOOT_DIR}/ext/tinycrypt/lib")
# Path to mbed-tls' asn1 parser library.
set(MBEDTLS_ASN1_DIR "${MCUBOOT_DIR}/ext/mbedtls")

# Zephyr application include directories.
if (NOT NEED_TINYCRYPT)
  # Zephyr's mbedTLS needs this.
  zephyr_include_directories(include)

# Zephyr application include directories.
  # Use full mbedtls provided by OS for RSA
  target_include_directories(app PRIVATE $ENV{ZEPHYR_BASE}/ext/lib/crypto/mbedtls/include)
endif()

target_include_directories(app PRIVATE include)
target_include_directories(app PRIVATE targets)
if(EXISTS "${APPLICATION_SOURCE_DIR}/targets/${BOARD}.h")
@@ -164,12 +170,16 @@ target_sources(app PRIVATE "${BOOT_DIR}/bootutil/src/caps.c")

# Tinycrypt sources and includes, if needed.
if (NEED_TINYCRYPT)
  target_include_directories(app PRIVATE "${BOOT_DIR}/zephyr/include")
  target_include_directories(app PRIVATE "${TINYCRYPT_DIR}/include")
  target_include_directories(app PRIVATE "${MBEDTLS_ASN1_DIR}/include")

  target_sources(app PRIVATE "${TINYCRYPT_DIR}/source/ecc.c")
  target_sources(app PRIVATE "${TINYCRYPT_DIR}/source/ecc_dsa.c")
  target_sources(app PRIVATE "${TINYCRYPT_DIR}/source/sha256.c")
  target_sources(app PRIVATE "${TINYCRYPT_DIR}/source/utils.c")

  target_sources(app PRIVATE "${MBEDTLS_ASN1_DIR}/src/asn1parse.c")
endif()

if (CONFIG_MCUBOOT_SERIAL)
+2 −1
Changes for boot/zephyr/os.c: 2 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -22,11 +22,12 @@

#include "os/os_heap.h"

#ifdef MCUBOOT_USE_MBED_TLS

#define MBEDTLS_CONFIG_FILE CONFIG_MBEDTLS_CFG_FILE
#include <mbedtls/platform.h>
#include <mbedtls/memory_buffer_alloc.h>

#ifdef MCUBOOT_USE_MBED_TLS
/*
 * This is the heap for mbed TLS.  The value needed depends on the key
 * size and algorithm used.  For RSA-2048, 6144 bytes seems to be
+1 −1
Changes for boot/zephyr/prj-p256.conf: 1 added line, 1 removed line.
Original line number Diff line number Diff line
@@ -5,7 +5,7 @@ CONFIG_SYSTEM_CLOCK_DISABLE=y

CONFIG_MAIN_STACK_SIZE=10240
CONFIG_MBEDTLS=y
CONFIG_MBEDTLS_BUILTIN=y
CONFIG_MBEDTLS_BUILTIN=n
CONFIG_MBEDTLS_CFG_FILE="config-asn1.h"
# CONFIG_TINYCRYPT is not set
# CONFIG_TINYCRYPT_ECC_DSA is not set