Skip to content

Commit dc0b692

Browse files
sigvartmhcvinayak
authored andcommittedOct 19, 2023
[nrf noup] crypto: ecdsa: Fix shared crypto MCUBoot EXT_ABI
After the upmerge using external crypto from NSIB in MCUBoot resulted in build failures. This commit fixes the build failures but also fixes a change in the API call which resulted in `-102` error when calling the verify function. Ref. NCSDK-23994 Signed-off-by: Sigvart Hovland <sigvart.hovland@nordicsemi.no>
1 parent 1b6571d commit dc0b692

File tree

2 files changed

+24
-23
lines changed

2 files changed

+24
-23
lines changed
 

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

+23-20
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,15 @@
7373

7474
#if defined(MCUBOOT_USE_NRF_EXTERNAL_CRYPTO)
7575
#include <bl_crypto.h>
76-
#define BOOTUTIL_CRYPTO_ECDSA_P256_HASH_SIZE (4 * 8)
76+
#define NUM_ECC_BYTES (256 / 8)
7777
#endif /* MCUBOOT_USE_NRF_EXTERNAL_CRYPTO */
7878

7979
#ifdef __cplusplus
8080
extern "C" {
8181
#endif
8282

83-
#if defined(MCUBOOT_USE_TINYCRYPT) || defined(MCUBOOT_USE_MBED_TLS) || defined(MCUBOOT_USE_CC310)
83+
#if defined(MCUBOOT_USE_TINYCRYPT) || defined(MCUBOOT_USE_MBED_TLS) || defined(MCUBOOT_USE_CC310) \
84+
|| defined(MCUBOOT_USE_NRF_EXTERNAL_CRYPTO)
8485
/*
8586
* Declaring these like this adds NULL termination.
8687
*/
@@ -602,43 +603,45 @@ static inline int bootutil_ecdsa_parse_public_key(bootutil_ecdsa_context *ctx,
602603
#endif /* MCUBOOT_USE_MBED_TLS */
603604

604605
#if defined(MCUBOOT_USE_NRF_EXTERNAL_CRYPTO)
605-
typedef uintptr_t bootutil_ecdsa_p256_context;
606-
607-
static inline void bootutil_ecdsa_p256_init(bootutil_ecdsa_p256_context *ctx)
606+
typedef uintptr_t bootutil_ecdsa_context;
607+
static inline void bootutil_ecdsa_init(bootutil_ecdsa_context *ctx)
608608
{
609609
(void)ctx;
610610
}
611611

612-
static inline void bootutil_ecdsa_p256_drop(bootutil_ecdsa_p256_context *ctx)
612+
static inline void bootutil_ecdsa_drop(bootutil_ecdsa_context *ctx)
613613
{
614614
(void)ctx;
615615
}
616616

617-
static inline int bootutil_ecdsa_p256_verify(bootutil_ecdsa_p256_context *ctx,
618-
uint8_t *pk, size_t pk_len,
619-
uint8_t *hash,
620-
uint8_t *sig, size_t sig_len)
617+
static inline int bootutil_ecdsa_verify(bootutil_ecdsa_context *ctx,
618+
uint8_t *pk, size_t pk_len,
619+
uint8_t *hash, size_t hash_len,
620+
uint8_t *sig, size_t sig_len)
621621
{
622622
(void)ctx;
623623
(void)pk_len;
624+
(void)hash_len;
624625
uint8_t dsig[2 * NUM_ECC_BYTES];
625626

626627
if (bootutil_decode_sig(dsig, sig, sig + sig_len)) {
627628
return -1;
628629
}
629630

630-
/* As described on the compact representation in IETF protocols,
631-
* the first byte of the key defines if the ECC points are
632-
* compressed (0x2 or 0x3) or uncompressed (0x4).
633-
* We only support uncompressed keys.
634-
*/
635-
if (pk[0] != 0x04)
636-
return -1;
631+
/* Only support uncompressed keys. */
632+
if (pk[0] != 0x04) {
633+
return -1;
634+
}
635+
pk++;
637636

638-
pk++;
637+
return bl_secp256r1_validate(hash, BOOTUTIL_CRYPTO_ECDSA_P256_HASH_SIZE, pk, dsig);
638+
}
639639

640-
return bl_secp256r1_validate(hash, BOOTUTIL_CRYPTO_ECDSA_P256_HASH_SIZE,
641-
pk, dsig);
640+
static inline int bootutil_ecdsa_parse_public_key(bootutil_ecdsa_context *ctx,
641+
uint8_t **cp,uint8_t *end)
642+
{
643+
(void)ctx;
644+
return bootutil_import_key(cp, end);
642645
}
643646
#endif /* MCUBOOT_USE_NRF_EXTERNAL_CRYPTO */
644647

‎boot/zephyr/prj_minimal.conf

+1-3
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,8 @@ CONFIG_FLASH=y
1111
CONFIG_FPROTECT=y
1212
CONFIG_PM=n
1313

14-
CONFIG_BOOT_ENCRYPT_EC256=n
15-
CONFIG_BOOT_ENCRYPT_RSA=n
16-
CONFIG_BOOT_ENCRYPT_X25519=n
1714
CONFIG_BOOT_SWAP_SAVE_ENCTLV=n
15+
CONFIG_BOOT_ENCRYPT_IMAGE=n
1816

1917
CONFIG_BOOT_BOOTSTRAP=n
2018
CONFIG_BOOT_UPGRADE_ONLY=n

0 commit comments

Comments
 (0)