3535#if (defined(MCUBOOT_USE_TINYCRYPT ) + \
3636 defined(MCUBOOT_USE_CC310 ) + \
3737 defined(MCUBOOT_USE_NRF_EXTERNAL_CRYPTO ) + \
38- defined(MCUBOOT_USE_PSA_OR_MBED_TLS )) != 1
39- #error "One crypto backend must be defined: either CC310/TINYCRYPT/MBED_TLS/PSA_CRYPTO"
38+ defined(MCUBOOT_USE_PSA_OR_MBED_TLS ) + \
39+ defined(MCUBOOT_USE_NRF_OBERON )) != 1
40+ #error "One crypto backend must be defined: either CC310/TINYCRYPT/MBED_TLS/PSA_CRYPTO/NRF_OBERON"
4041#endif
4142
4243#if defined(MCUBOOT_USE_TINYCRYPT )
5859 #define MCUBOOT_ECDSA_NEED_ASN1_SIG
5960#endif /* MCUBOOT_USE_MBED_TLS */
6061
62+ #if defined(MCUBOOT_USE_NRF_OBERON )
63+ #include <ocrypto_ecdsa_p256.h>
64+ #endif /* MCUBOOT_USE_NRF_OBERON */
65+
6166/*TODO: remove this after cypress port mbedtls to abstract crypto api */
62- #if defined(MCUBOOT_USE_CC310 ) || defined(MCUBOOT_USE_MBED_TLS )
67+ #if defined(MCUBOOT_USE_CC310 ) || defined(MCUBOOT_USE_MBED_TLS ) || \
68+ defined(MCUBOOT_USE_NRF_OBERON )
6369#define NUM_ECC_BYTES (256 / 8)
6470#endif
6571
@@ -83,7 +89,8 @@ extern "C" {
8389#endif
8490
8591#if (defined(MCUBOOT_USE_TINYCRYPT ) || defined(MCUBOOT_USE_MBED_TLS ) || \
86- defined(MCUBOOT_USE_CC310 ) || defined(MCUBOOT_USE_NRF_EXTERNAL_CRYPTO )) \
92+ defined(MCUBOOT_USE_CC310 ) || defined(MCUBOOT_USE_NRF_EXTERNAL_CRYPTO ) || \
93+ defined(MCUBOOT_USE_NRF_OBERON )) \
8794 && !defined(MCUBOOT_USE_PSA_CRYPTO )
8895/*
8996 * Declaring these like this adds NULL termination.
@@ -719,6 +726,57 @@ static inline int bootutil_ecdsa_parse_public_key(bootutil_ecdsa_context *ctx,
719726}
720727#endif /* MCUBOOT_USE_NRF_EXTERNAL_CRYPTO */
721728
729+ #if defined(MCUBOOT_USE_NRF_OBERON )
730+ #define UNCOMPRESSED_KEY_PREFIX 0x04
731+
732+ typedef uintptr_t bootutil_ecdsa_context ;
733+
734+ static inline void bootutil_ecdsa_init (bootutil_ecdsa_context * ctx )
735+ {
736+ (void )ctx ;
737+ }
738+
739+ static inline void bootutil_ecdsa_drop (bootutil_ecdsa_context * ctx )
740+ {
741+ (void )ctx ;
742+ }
743+
744+ static inline int bootutil_ecdsa_verify (bootutil_ecdsa_context * ctx ,
745+ uint8_t * pk , size_t pk_len ,
746+ uint8_t * hash , size_t hash_len ,
747+ uint8_t * sig , size_t sig_len )
748+ {
749+ if (pk == NULL || hash == NULL || sig == NULL ) {
750+ return -1 ;
751+ }
752+
753+ uint8_t signature [2 * NUM_ECC_BYTES ];
754+ int rc = bootutil_decode_sig (signature , sig , sig + sig_len );
755+ if (rc ) {
756+ return rc ;
757+ }
758+
759+ /* Support only uncompressed keys */
760+ if (pk [0 ] != UNCOMPRESSED_KEY_PREFIX ) {
761+ return -2 ;
762+ }
763+
764+ /* Skip the first byte holding key format */
765+ pk ++ ;
766+
767+ return ocrypto_ecdsa_p256_verify_hash (signature , hash , pk );
768+ }
769+
770+ static inline int bootutil_ecdsa_parse_public_key (bootutil_ecdsa_context * ctx ,
771+ uint8_t * * cp , uint8_t * end )
772+ {
773+ (void )ctx ;
774+
775+ return bootutil_import_key (cp , end );
776+ }
777+
778+ #endif /* MCUBOOT_USE_NRF_OBERON */
779+
722780#ifdef __cplusplus
723781}
724782#endif
0 commit comments