Skip to content

Commit 1171df9

Browse files
committed
Add Zephyr infrastructure for ed25519
Signed-off-by: Fabio Utzig <[email protected]>
1 parent 705dfb3 commit 1171df9

File tree

7 files changed

+110
-0
lines changed

7 files changed

+110
-0
lines changed

boot/zephyr/CMakeLists.txt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ get_filename_component(MCUBOOT_DIR ${BOOT_DIR} DIRECTORY)
6262
# Path to tinycrypt library source subdirectory of MCUBOOT_DIR.
6363
set(TINYCRYPT_DIR "${MCUBOOT_DIR}/ext/tinycrypt/lib")
6464
assert_exists(TINYCRYPT_DIR)
65+
# Path to crypto-fiat
66+
set(FIAT_DIR "${MCUBOOT_DIR}/ext/fiat")
67+
assert_exists(FIAT_DIR)
6568
# Path to mbed-tls' asn1 parser library.
6669
set(MBEDTLS_ASN1_DIR "${MCUBOOT_DIR}/ext/mbedtls")
6770
assert_exists(MBEDTLS_ASN1_DIR)
@@ -105,6 +108,7 @@ zephyr_library_sources(
105108
${BOOT_DIR}/bootutil/src/encrypted.c
106109
${BOOT_DIR}/bootutil/src/image_rsa.c
107110
${BOOT_DIR}/bootutil/src/image_ec256.c
111+
${BOOT_DIR}/bootutil/src/image_ed25519.c
108112
${BOOT_DIR}/bootutil/src/caps.c
109113
)
110114

@@ -146,6 +150,18 @@ elseif(CONFIG_BOOT_SIGNATURE_TYPE_RSA)
146150
# Use mbedTLS provided by Zephyr for RSA signatures. (Its config file
147151
# is set using Kconfig.)
148152
zephyr_include_directories(include)
153+
elseif(CONFIG_BOOT_SIGNATURE_TYPE_ED25519)
154+
# For ed25519, mbedTLS is used for ASN1 parsing and SHA512
155+
zephyr_include_directories(include)
156+
157+
zephyr_library_include_directories(
158+
${BOOT_DIR}/zephyr/include
159+
${FIAT_DIR}/include/
160+
)
161+
162+
zephyr_library_sources(
163+
${FIAT_DIR}/src/curve25519.c
164+
)
149165
endif()
150166

151167
if(CONFIG_MCUBOOT_SERIAL)

boot/zephyr/Kconfig

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +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+
7984
if BOOT_SIGNATURE_TYPE_ECDSA_P256
8085
choice
8186
prompt "Ecdsa implementation"
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/*
2+
* Configuration of mbedTLS containing only the ASN.1 parser.
3+
*
4+
* Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
5+
* Copyright (C) 2016, Linaro Ltd
6+
* SPDX-License-Identifier: Apache-2.0
7+
*
8+
* Licensed under the Apache License, Version 2.0 (the "License"); you may
9+
* not use this file except in compliance with the License.
10+
* You may obtain a copy of the License at
11+
*
12+
* http://www.apache.org/licenses/LICENSE-2.0
13+
*
14+
* Unless required by applicable law or agreed to in writing, software
15+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
16+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
* See the License for the specific language governing permissions and
18+
* limitations under the License.
19+
*
20+
* This file is part of mbed TLS (https://tls.mbed.org)
21+
*/
22+
23+
/*
24+
* Minimal configuration for using TLS in the bootloader
25+
*
26+
* - ed25519 signature verification
27+
*/
28+
29+
#ifndef MCUBOOT_MBEDTLS_CONFIG_ED25519
30+
#define MCUBOOT_MBEDTLS_CONFIG_ED25519
31+
32+
#ifdef CONFIG_MCUBOOT_SERIAL
33+
/* Mcuboot uses mbedts-base64 for serial protocol encoding. */
34+
#define MBEDTLS_BASE64_C
35+
#endif
36+
37+
/* System support */
38+
#define MBEDTLS_PLATFORM_C
39+
#define MBEDTLS_PLATFORM_MEMORY
40+
#define MBEDTLS_MEMORY_BUFFER_ALLOC_C
41+
#define MBEDTLS_NO_PLATFORM_ENTROPY
42+
#define MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES
43+
44+
/* STD functions */
45+
#define MBEDTLS_PLATFORM_NO_STD_FUNCTIONS
46+
47+
#define MBEDTLS_PLATFORM_EXIT_ALT
48+
#define MBEDTLS_PLATFORM_PRINTF_ALT
49+
#define MBEDTLS_PLATFORM_SNPRINTF_ALT
50+
51+
#if !defined(CONFIG_ARM)
52+
#define MBEDTLS_HAVE_ASM
53+
#endif
54+
55+
/* mbed TLS modules */
56+
#define MBEDTLS_ASN1_PARSE_C
57+
#define MBEDTLS_BIGNUM_C
58+
#define MBEDTLS_MD_C
59+
#define MBEDTLS_OID_C
60+
#define MBEDTLS_SHA256_C
61+
#define MBEDTLS_SHA512_C
62+
#define MBEDTLS_AES_C
63+
64+
/* Save RAM by adjusting to our exact needs */
65+
//#define MBEDTLS_ECP_MAX_BITS 2048
66+
67+
#define MBEDTLS_MPI_MAX_SIZE 64
68+
69+
//#define MBEDTLS_SSL_MAX_CONTENT_LEN 1024
70+
71+
/* Save ROM and a few bytes of RAM by specifying our own ciphersuite list */
72+
#define MBEDTLS_SSL_CIPHERSUITES MBEDTLS_TLS_ECJPAKE_WITH_AES_128_CCM_8
73+
74+
#include "mbedtls/check_config.h"
75+
76+
#endif /* MCUBOOT_MBEDTLS_CONFIG_RSA */

boot/zephyr/include/mcuboot-mbedtls-cfg.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
#include "config-rsa.h"
2626
#elif defined(CONFIG_BOOT_SIGNATURE_TYPE_ECDSA_P256)
2727
#include "config-asn1.h"
28+
#elif defined(CONFIG_BOOT_SIGNATURE_TYPE_ED25519)
29+
#include "config-ed25519.h"
2830
#else
2931
#error "Cannot configure mbedTLS; signature type is unknown."
3032
#endif

boot/zephyr/include/mcuboot_config/mcuboot_config.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
# endif
2929
#elif defined(CONFIG_BOOT_SIGNATURE_TYPE_ECDSA_P256)
3030
#define MCUBOOT_SIGN_EC256
31+
#elif defined(CONFIG_BOOT_SIGNATURE_TYPE_ED25519)
32+
#define MCUBOOT_SIGN_ED25519
3133
#endif
3234

3335
#ifdef CONFIG_BOOT_USE_MBEDTLS

boot/zephyr/keys.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ extern unsigned int rsa_pub_key_len;
3636
#define HAVE_KEYS
3737
extern const unsigned char ecdsa_pub_key[];
3838
extern unsigned int ecdsa_pub_key_len;
39+
#elif defined(MCUBOOT_SIGN_ED25519)
40+
#define HAVE_KEYS
41+
extern const unsigned char ed25519_pub_key[];
42+
extern unsigned int ed25519_pub_key_len;
3943
#else
4044
#error "No public key available for given signing algorithm."
4145
#endif
@@ -54,6 +58,9 @@ const struct bootutil_key bootutil_keys[] = {
5458
#elif defined(MCUBOOT_SIGN_EC256)
5559
.key = ecdsa_pub_key,
5660
.len = &ecdsa_pub_key_len,
61+
#elif defined(MCUBOOT_SIGN_ED25519)
62+
.key = ed25519_pub_key,
63+
.len = &ed25519_pub_key_len,
5764
#endif
5865
},
5966
};

boot/zephyr/prj.conf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ CONFIG_BOOT_BOOTSTRAP=n
1414
CONFIG_BOOT_SIGNATURE_TYPE_RSA=y
1515
CONFIG_BOOT_SIGNATURE_TYPE_RSA_LEN=2048
1616
CONFIG_BOOT_SIGNATURE_TYPE_ECDSA_P256=n
17+
CONFIG_BOOT_SIGNATURE_TYPE_ED25519=n
1718

1819
### The bootloader generates its own signature verification based on a
1920
### key file which needs to be provided and needs to match the selected signing
@@ -22,6 +23,7 @@ CONFIG_BOOT_SIGNATURE_TYPE_ECDSA_P256=n
2223
CONFIG_BOOT_SIGNATURE_KEY_FILE="root-rsa-2048.pem"
2324
#CONFIG_BOOT_SIGNATURE_KEY_FILE="root-rsa-3072.pem"
2425
#CONFIG_BOOT_SIGNATURE_KEY_FILE="root-ec-p256.pem"
26+
#CONFIG_BOOT_SIGNATURE_KEY_FILE="root-ed25519.pem"
2527

2628
### mbedTLS has its own heap
2729
# CONFIG_HEAP_MEM_POOL_SIZE is not set

0 commit comments

Comments
 (0)