|
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 | 83 | #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) |
85 | 86 | /*
|
86 | 87 | * Declaring these like this adds NULL termination.
|
87 | 88 | */
|
@@ -603,43 +604,45 @@ static inline int bootutil_ecdsa_parse_public_key(bootutil_ecdsa_context *ctx,
|
603 | 604 | #endif /* MCUBOOT_USE_MBED_TLS */
|
604 | 605 |
|
605 | 606 | #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) |
609 | 609 | {
|
610 | 610 | (void)ctx;
|
611 | 611 | }
|
612 | 612 |
|
613 |
| -static inline void bootutil_ecdsa_p256_drop(bootutil_ecdsa_p256_context *ctx) |
| 613 | +static inline void bootutil_ecdsa_drop(bootutil_ecdsa_context *ctx) |
614 | 614 | {
|
615 | 615 | (void)ctx;
|
616 | 616 | }
|
617 | 617 |
|
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) |
622 | 622 | {
|
623 | 623 | (void)ctx;
|
624 | 624 | (void)pk_len;
|
| 625 | + (void)hash_len; |
625 | 626 | uint8_t dsig[2 * NUM_ECC_BYTES];
|
626 | 627 |
|
627 | 628 | if (bootutil_decode_sig(dsig, sig, sig + sig_len)) {
|
628 | 629 | return -1;
|
629 | 630 | }
|
630 | 631 |
|
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++; |
638 | 637 |
|
639 |
| - pk++; |
| 638 | + return bl_secp256r1_validate(hash, BOOTUTIL_CRYPTO_ECDSA_P256_HASH_SIZE, pk, dsig); |
| 639 | +} |
640 | 640 |
|
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); |
643 | 646 | }
|
644 | 647 | #endif /* MCUBOOT_USE_NRF_EXTERNAL_CRYPTO */
|
645 | 648 |
|
|
0 commit comments