Skip to content

Commit 34e93a5

Browse files
committed
boot: zephyr: mynewt: sha-512 from tinycrypt
* Mynewt always uses sha-512 from tinycrypt * Zephyr can choose either tinycrypt or mbedTLS Signed-off-by: Fabio Utzig <[email protected]>
1 parent a1c142d commit 34e93a5

File tree

3 files changed

+46
-10
lines changed

3 files changed

+46
-10
lines changed

boot/bootutil/pkg.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,5 +49,7 @@ pkg.deps.BOOTUTIL_USE_TINYCRYPT:
4949
- "@mcuboot/ext/mbedtls-asn1"
5050

5151
pkg.deps.BOOTUTIL_SIGN_ED25519:
52-
- "@apache-mynewt-core/crypto/mbedtls"
52+
- "@mcuboot/ext/tinycrypt/lib"
53+
- "@mcuboot/ext/tinycrypt-sha512/lib"
54+
- "@mcuboot/ext/mbedtls-asn1"
5355
- "@mcuboot/ext/fiat"

boot/zephyr/CMakeLists.txt

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ get_filename_component(MCUBOOT_DIR ${BOOT_DIR} DIRECTORY)
5151
# Path to tinycrypt library source subdirectory of MCUBOOT_DIR.
5252
set(TINYCRYPT_DIR "${MCUBOOT_DIR}/ext/tinycrypt/lib")
5353
assert_exists(TINYCRYPT_DIR)
54+
set(TINYCRYPT_SHA512_DIR "${MCUBOOT_DIR}/ext/tinycrypt-sha512/lib")
55+
assert_exists(TINYCRYPT_SHA512_DIR)
5456
# Path to crypto-fiat
5557
set(FIAT_DIR "${MCUBOOT_DIR}/ext/fiat")
5658
assert_exists(FIAT_DIR)
@@ -144,8 +146,27 @@ elseif(CONFIG_BOOT_SIGNATURE_TYPE_RSA)
144146
# is set using Kconfig.)
145147
zephyr_include_directories(include)
146148
elseif(CONFIG_BOOT_SIGNATURE_TYPE_ED25519)
147-
# For ed25519, mbedTLS is used for ASN1 parsing and SHA512
148-
zephyr_include_directories(include)
149+
if(CONFIG_BOOT_USE_TINYCRYPT)
150+
zephyr_library_include_directories(
151+
${MBEDTLS_ASN1_DIR}/include
152+
${BOOT_DIR}/zephyr/include
153+
${TINYCRYPT_DIR}/include
154+
${TINYCRYPT_SHA512_DIR}/include
155+
)
156+
zephyr_library_sources(
157+
${TINYCRYPT_DIR}/source/sha256.c
158+
${TINYCRYPT_DIR}/source/utils.c
159+
${TINYCRYPT_SHA512_DIR}/source/sha512.c
160+
# Additionally pull in just the ASN.1 parser from mbedTLS.
161+
${MBEDTLS_ASN1_DIR}/src/asn1parse.c
162+
${MBEDTLS_ASN1_DIR}/src/platform_util.c
163+
)
164+
zephyr_library_compile_definitions(
165+
MBEDTLS_CONFIG_FILE="${CMAKE_CURRENT_LIST_DIR}/include/mcuboot-mbedtls-cfg.h"
166+
)
167+
else()
168+
zephyr_include_directories(include)
169+
endif()
149170

150171
zephyr_library_include_directories(
151172
${BOOT_DIR}/zephyr/include

boot/zephyr/Kconfig

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -76,16 +76,11 @@ endif
7676
config BOOT_SIGNATURE_TYPE_ECDSA_P256
7777
bool "Elliptic curve digital signatures with curve P-256"
7878

79-
config BOOT_SIGNATURE_TYPE_ED25519
80-
bool "Edwards curve digital signatures using ed25519"
81-
select BOOT_USE_MBEDTLS
82-
select MBEDTLS
83-
8479
if BOOT_SIGNATURE_TYPE_ECDSA_P256
8580
choice
8681
prompt "Ecdsa implementation"
87-
default BOOT_TINYCRYPT
88-
config BOOT_TINYCRYPT
82+
default BOOT_ECDSA_TINYCRYPT
83+
config BOOT_ECDSA_TINYCRYPT
8984
bool "Use tinycrypt"
9085
select BOOT_USE_TINYCRYPT
9186
config BOOT_CC310
@@ -96,6 +91,24 @@ config BOOT_CC310
9691
select BOOT_USE_CC310
9792
endchoice
9893
endif
94+
95+
config BOOT_SIGNATURE_TYPE_ED25519
96+
bool "Edwards curve digital signatures using ed25519"
97+
98+
if BOOT_SIGNATURE_TYPE_ED25519
99+
choice
100+
prompt "Ecdsa implementation"
101+
default BOOT_ED25519_TINYCRYPT
102+
config BOOT_ED25519_TINYCRYPT
103+
bool "Use tinycrypt"
104+
select BOOT_USE_TINYCRYPT
105+
config BOOT_ED25519_MBEDTLS
106+
bool "Use mbedTLS"
107+
select BOOT_USE_MBEDTLS
108+
select MBEDTLS
109+
endchoice
110+
endif
111+
99112
endchoice
100113

101114
config BOOT_SIGNATURE_KEY_FILE

0 commit comments

Comments
 (0)