Skip to content

Commit a0c21e2

Browse files
sigvartmhjfischer-no
authored andcommitted
[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 <[email protected]> Signed-off-by: Dominik Ermel <[email protected]> (cherry picked from commit 4015754)
1 parent ba55561 commit a0c21e2

File tree

1 file changed

+23
-20
lines changed
  • boot/bootutil/include/bootutil/crypto

1 file changed

+23
-20
lines changed

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

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,16 @@
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

8383
#if (defined(MCUBOOT_USE_TINYCRYPT) || defined(MCUBOOT_USE_MBED_TLS) || \
84-
defined(MCUBOOT_USE_CC310)) && !defined(MCUBOOT_USE_PSA_CRYPTO)
84+
defined(MCUBOOT_USE_CC310) || defined(MCUBOOT_USE_NRF_EXTERNAL_CRYPTO)) \
85+
&& !defined(MCUBOOT_USE_PSA_CRYPTO)
8586
/*
8687
* Declaring these like this adds NULL termination.
8788
*/
@@ -603,43 +604,45 @@ static inline int bootutil_ecdsa_parse_public_key(bootutil_ecdsa_context *ctx,
603604
#endif /* MCUBOOT_USE_MBED_TLS */
604605

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

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

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

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

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

639-
pk++;
638+
return bl_secp256r1_validate(hash, BOOTUTIL_CRYPTO_ECDSA_P256_HASH_SIZE, pk, dsig);
639+
}
640640

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

0 commit comments

Comments
 (0)