Skip to content

Commit ff54861

Browse files
committed
WIP - add configs and implementation for ocrypto (nrf_oberon).
At the moment hello_world_mini_boot sample builds but app image verification at boot fails - TBD. Signed-off-by: Adam Szczygieł <[email protected]>
1 parent 0d263fa commit ff54861

File tree

5 files changed

+113
-4
lines changed

5 files changed

+113
-4
lines changed

boot/bootutil/include/bootutil/crypto/ecdsa.h

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@
3535
#if (defined(MCUBOOT_USE_TINYCRYPT) + \
3636
defined(MCUBOOT_USE_CC310) + \
3737
defined(MCUBOOT_USE_NRF_EXTERNAL_CRYPTO) + \
38-
defined(MCUBOOT_USE_PSA_OR_MBED_TLS)) != 1
38+
defined(MCUBOOT_USE_PSA_OR_MBED_TLS) + \
39+
defined(MCUBOOT_USE_NRF_OBERON_EXPERIMENT)) != 1
3940
#error "One crypto backend must be defined: either CC310/TINYCRYPT/MBED_TLS/PSA_CRYPTO"
4041
#endif
4142

@@ -58,6 +59,10 @@
5859
#define MCUBOOT_ECDSA_NEED_ASN1_SIG
5960
#endif /* MCUBOOT_USE_MBED_TLS */
6061

62+
#if defined(MCUBOOT_USE_NRF_OBERON_EXPERIMENT)
63+
#include <ocrypto_ecdsa_p256.h>
64+
#endif /* MCUBOOT_USE_NRF_OBERON_EXPERIMENT */
65+
6166
/*TODO: remove this after cypress port mbedtls to abstract crypto api */
6267
#if defined(MCUBOOT_USE_CC310) || defined(MCUBOOT_USE_MBED_TLS)
6368
#define NUM_ECC_BYTES (256 / 8)
@@ -136,7 +141,7 @@ static int bootutil_import_key(uint8_t **cp, uint8_t *end)
136141
}
137142
#endif /* (MCUBOOT_USE_TINYCRYPT || MCUBOOT_USE_MBED_TLS || MCUBOOT_USE_CC310) && !MCUBOOT_USE_PSA_CRYPTO */
138143

139-
#ifndef MCUBOOT_USE_PSA_CRYPTO
144+
#if !defined(MCUBOOT_USE_PSA_CRYPTO) && !defined(MCUBOOT_USE_NRF_OBERON_EXPERIMENT)
140145
/*
141146
* cp points to ASN1 string containing an integer.
142147
* Verify the tag, and that the length is 32 bytes. Helper function.
@@ -186,7 +191,7 @@ static int bootutil_decode_sig(uint8_t signature[NUM_ECC_BYTES * 2], uint8_t *cp
186191
}
187192
return 0;
188193
}
189-
#endif /* !MCUBOOT_USE_PSA_CRYPTO */
194+
#endif /* !defined(MCUBOOT_USE_PSA_CRYPTO) && !defined(MCUBOOT_USE_NRF_OBERON_EXPERIMENT) */
190195

191196
#if defined(MCUBOOT_USE_TINYCRYPT)
192197
typedef uintptr_t bootutil_ecdsa_context;
@@ -719,6 +724,42 @@ static inline int bootutil_ecdsa_parse_public_key(bootutil_ecdsa_context *ctx,
719724
}
720725
#endif /* MCUBOOT_USE_NRF_EXTERNAL_CRYPTO */
721726

727+
#if defined(MCUBOOT_USE_NRF_OBERON_EXPERIMENT)
728+
typedef uintptr_t bootutil_ecdsa_context;
729+
730+
static inline void bootutil_ecdsa_init(bootutil_ecdsa_context *ctx)
731+
{
732+
(void)ctx;
733+
}
734+
735+
static inline void bootutil_ecdsa_drop(bootutil_ecdsa_context *ctx)
736+
{
737+
(void)ctx;
738+
}
739+
740+
static inline int bootutil_ecdsa_verify(bootutil_ecdsa_context *ctx,
741+
uint8_t *pk, size_t pk_len,
742+
uint8_t *hash, size_t hash_len,
743+
uint8_t *sig, size_t sig_len)
744+
{
745+
if (pk == NULL || hash == NULL || sig == NULL) {
746+
return -1;
747+
}
748+
749+
return ocrypto_ecdsa_p256_verify_hash(sig, hash, pk);
750+
}
751+
752+
static inline int bootutil_ecdsa_parse_public_key(bootutil_ecdsa_context *ctx,
753+
uint8_t **cp,uint8_t *end)
754+
{
755+
/* NOTE: No corresponding funciton in ocrypto */
756+
(void)ctx;
757+
(void)cp;
758+
(void)end;
759+
return 0;
760+
}
761+
#endif /* MCUBOOT_USE_NRF_OBERON_EXPERIMENT */
762+
722763
#ifdef __cplusplus
723764
}
724765
#endif

boot/bootutil/include/bootutil/crypto/sha.h

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@
3131
#if (defined(MCUBOOT_USE_PSA_OR_MBED_TLS) + \
3232
defined(MCUBOOT_USE_TINYCRYPT) + \
3333
defined(MCUBOOT_USE_NRF_EXTERNAL_CRYPTO) + \
34-
defined(MCUBOOT_USE_CC310)) != 1
34+
defined(MCUBOOT_USE_CC310) + \
35+
defined(MCUBOOT_USE_NRF_OBERON_EXPERIMENT)) != 1
3536
#error "One crypto backend must be defined: either CC310/MBED_TLS/TINYCRYPT/PSA_CRYPTO"
3637
#endif
3738

@@ -82,6 +83,10 @@
8283
#include <cc310_glue.h>
8384
#endif /* MCUBOOT_USE_CC310 */
8485

86+
#if defined(MCUBOOT_USE_NRF_OBERON_EXPERIMENT)
87+
#include <ocrypto_sha256.h>
88+
#endif /* MCUBOOT_USE_NRF_OBERON_EXPERIMENT */
89+
8590
#include <stdint.h>
8691

8792
#ifdef __cplusplus
@@ -302,6 +307,52 @@ static inline int bootutil_sha_finish(bootutil_sha_context *ctx,
302307
}
303308
#endif /* MCUBOOT_USE_NRF_EXTERNAL_CRYPTO */
304309

310+
#if defined(MCUBOOT_USE_NRF_OBERON_EXPERIMENT)
311+
typedef ocrypto_sha256_ctx bootutil_sha_context;
312+
313+
static inline int bootutil_sha_init(bootutil_sha_context *ctx)
314+
{
315+
if (ctx == NULL) {
316+
return -1;
317+
}
318+
319+
ocrypto_sha256_init(ctx);
320+
return 0;
321+
}
322+
323+
static inline int bootutil_sha_drop(bootutil_sha_context *ctx)
324+
{
325+
/* NOTE: No corresponding function for ocrypto_sha256 */
326+
(void)ctx;
327+
return 0;
328+
}
329+
330+
static inline int bootutil_sha_update(bootutil_sha_context *ctx,
331+
const void *data,
332+
uint32_t data_len)
333+
{
334+
if (ctx == NULL || data == NULL) {
335+
return -1;
336+
}
337+
338+
ocrypto_sha256_update(ctx, (const uint8_t *)data, (size_t)data_len);
339+
340+
return 0;
341+
}
342+
343+
static inline int bootutil_sha_finish(bootutil_sha_context *ctx,
344+
uint8_t *output)
345+
{
346+
if (ctx == NULL || output == NULL) {
347+
return -1;
348+
}
349+
350+
ocrypto_sha256_final(ctx, output);
351+
return 0;
352+
}
353+
354+
#endif /* MCUBOOT_USE_NRF_OBERON_EXPERIMENT */
355+
305356
#ifdef __cplusplus
306357
}
307358
#endif

boot/bootutil/zephyr/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ if(CONFIG_BOOT_USE_PSA_CRYPTO)
4545
)
4646
endif()
4747

48+
if(CONFIG_BOOT_USE_NRF_OBERON_EXPERIMENT)
49+
target_include_directories(MCUBOOT_BOOTUTIL INTERFACE ${OBERON_BASE}/include)
50+
zephyr_link_libraries(nrfxlib_crypto)
51+
endif()
52+
4853
if(CONFIG_BOOT_USE_MBEDTLS OR CONFIG_BOOT_USE_PSA_CRYPTO AND NOT CONFIG_NRF_SECURITY)
4954
zephyr_link_libraries(mbedTLS)
5055
endif()

boot/zephyr/Kconfig

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@ config BOOT_USE_CC310
5454
config BOOT_USE_NRF_CC310_BL
5555
bool
5656

57+
config BOOT_USE_NRF_OBERON_EXPERIMENT
58+
bool
59+
default n
60+
help
61+
Use nrf oberon.
62+
5763
config NRFXLIB_CRYPTO
5864
bool
5965

@@ -286,6 +292,10 @@ choice BOOT_ECDSA_IMPLEMENTATION
286292
default BOOT_ECDSA_PSA if NRF_SECURITY
287293
default BOOT_ECDSA_TINYCRYPT
288294

295+
config BOOT_ECDSA_NRF_OBERON_EXPERIMENT
296+
bool "Use nrf oberon"
297+
select BOOT_USE_NRF_OBERON_EXPERIMENT
298+
289299
config BOOT_ECDSA_TINYCRYPT
290300
bool "Use tinycrypt"
291301
select BOOT_USE_TINYCRYPT

boot/zephyr/include/mcuboot_config/mcuboot_config.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@
5151
#define MCUBOOT_USE_PSA_CRYPTO
5252
#elif defined(CONFIG_BOOT_USE_NRF_EXTERNAL_CRYPTO)
5353
#define MCUBOOT_USE_NRF_EXTERNAL_CRYPTO
54+
#elif defined(CONFIG_BOOT_USE_NRF_OBERON_EXPERIMENT)
55+
#define MCUBOOT_USE_NRF_OBERON_EXPERIMENT
5456
#endif
5557

5658
#ifdef CONFIG_BOOT_IMG_HASH_ALG_SHA512

0 commit comments

Comments
 (0)