|
73 | 73 |
|
74 | 74 | #if defined(MCUBOOT_USE_NRF_EXTERNAL_CRYPTO) |
75 | 75 | #include <bl_crypto.h> |
76 | | - #define BOOTUTIL_CRYPTO_ECDSA_P256_HASH_SIZE (4 * 8) |
| 76 | + #define NUM_ECC_BYTES (256 / 8) |
77 | 77 | #endif /* MCUBOOT_USE_NRF_EXTERNAL_CRYPTO */ |
78 | 78 |
|
79 | 79 | #ifdef __cplusplus |
80 | 80 | extern "C" { |
81 | 81 | #endif |
82 | 82 |
|
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) |
84 | 85 | /* |
85 | 86 | * Declaring these like this adds NULL termination. |
86 | 87 | */ |
@@ -602,43 +603,45 @@ static inline int bootutil_ecdsa_parse_public_key(bootutil_ecdsa_context *ctx, |
602 | 603 | #endif /* MCUBOOT_USE_MBED_TLS */ |
603 | 604 |
|
604 | 605 | #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) |
608 | 608 | { |
609 | 609 | (void)ctx; |
610 | 610 | } |
611 | 611 |
|
612 | | -static inline void bootutil_ecdsa_p256_drop(bootutil_ecdsa_p256_context *ctx) |
| 612 | +static inline void bootutil_ecdsa_drop(bootutil_ecdsa_context *ctx) |
613 | 613 | { |
614 | 614 | (void)ctx; |
615 | 615 | } |
616 | 616 |
|
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) |
621 | 621 | { |
622 | 622 | (void)ctx; |
623 | 623 | (void)pk_len; |
| 624 | + (void)hash_len; |
624 | 625 | uint8_t dsig[2 * NUM_ECC_BYTES]; |
625 | 626 |
|
626 | 627 | if (bootutil_decode_sig(dsig, sig, sig + sig_len)) { |
627 | 628 | return -1; |
628 | 629 | } |
629 | 630 |
|
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++; |
637 | 636 |
|
638 | | - pk++; |
| 637 | + return bl_secp256r1_validate(hash, BOOTUTIL_CRYPTO_ECDSA_P256_HASH_SIZE, pk, dsig); |
| 638 | +} |
639 | 639 |
|
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); |
642 | 645 | } |
643 | 646 | #endif /* MCUBOOT_USE_NRF_EXTERNAL_CRYPTO */ |
644 | 647 |
|
|
0 commit comments