|
14 | 14 |
|
15 | 15 | #if (defined(MCUBOOT_USE_TINYCRYPT) + \
|
16 | 16 | defined(MCUBOOT_USE_CC310) + \
|
| 17 | + defined(MCUBOOT_USE_NRF_EXTERNAL_CRYPTO) + \ |
17 | 18 | defined(MCUBOOT_USE_MBED_TLS)) != 1
|
18 | 19 | #error "One crypto backend must be defined: either CC310, TINYCRYPT, or MBED_TLS"
|
19 | 20 | #endif
|
|
47 | 48 | #include "bootutil/sign_key.h"
|
48 | 49 | #include "common.h"
|
49 | 50 |
|
| 51 | +#if defined(MCUBOOT_USE_NRF_EXTERNAL_CRYPTO) |
| 52 | + #include <bl_crypto.h> |
| 53 | + #define BOOTUTIL_CRYPTO_ECDSA_P256_HASH_SIZE (4 * 8) |
| 54 | +#endif /* MCUBOOT_USE_NRF_EXTERNAL_CRYPTO */ |
| 55 | + |
50 | 56 | #ifdef __cplusplus
|
51 | 57 | extern "C" {
|
52 | 58 | #endif
|
@@ -372,6 +378,43 @@ static inline int bootutil_ecdsa_p256_parse_public_key(bootutil_ecdsa_p256_conte
|
372 | 378 |
|
373 | 379 | #endif /* MCUBOOT_USE_MBED_TLS */
|
374 | 380 |
|
| 381 | +#if defined(MCUBOOT_USE_NRF_EXTERNAL_CRYPTO) |
| 382 | +typedef uintptr_t bootutil_ecdsa_p256_context; |
| 383 | + |
| 384 | +static inline void bootutil_ecdsa_p256_init(bootutil_ecdsa_p256_context *ctx) |
| 385 | +{ |
| 386 | + (void)ctx; |
| 387 | +} |
| 388 | + |
| 389 | +static inline void bootutil_ecdsa_p256_drop(bootutil_ecdsa_p256_context *ctx) |
| 390 | +{ |
| 391 | + (void)ctx; |
| 392 | +} |
| 393 | + |
| 394 | +static inline int bootutil_ecdsa_p256_verify(bootutil_ecdsa_p256_context *ctx, |
| 395 | + uint8_t *pk, size_t pk_len, |
| 396 | + uint8_t *hash, |
| 397 | + uint8_t *sig, size_t sig_len) |
| 398 | +{ |
| 399 | + (void)ctx; |
| 400 | + (void)pk_len; |
| 401 | + (void)sig_len; |
| 402 | + |
| 403 | + /* As described on the compact representation in IETF protocols, |
| 404 | + * the first byte of the key defines if the ECC points are |
| 405 | + * compressed (0x2 or 0x3) or uncompressed (0x4). |
| 406 | + * We only support uncompressed keys. |
| 407 | + */ |
| 408 | + if (pk[0] != 0x04) |
| 409 | + return -1; |
| 410 | + |
| 411 | + pk++; |
| 412 | + |
| 413 | + return bl_secp256r1_validate(hash, BOOTUTIL_CRYPTO_ECDSA_P256_HASH_SIZE, |
| 414 | + pk, sig); |
| 415 | +} |
| 416 | +#endif /* MCUBOOT_USE_NRF_EXTERNAL_CRYPTO */ |
| 417 | + |
375 | 418 | #ifdef __cplusplus
|
376 | 419 | }
|
377 | 420 | #endif
|
|
0 commit comments