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,66 @@ 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+ /* API expects particular values:
754+ * pk_len -> 64, plus one byte for key type/format (consumed by this function)
755+ * hash_len -> 32
756+ * sig_len -> 64 but it is encoded in asn1 format which can have variable length
757+ * */
758+ if (pk_len != 65 || hash_len != 32 || sig_len == 0 ) {
759+ return -1 ;
760+ }
761+
762+ uint8_t signature [2 * NUM_ECC_BYTES ];
763+ int rc = bootutil_decode_sig (signature , sig , sig + sig_len );
764+ if (rc ) {
765+ return rc ;
766+ }
767+
768+ /* Support only uncompressed keys */
769+ if (pk [0 ] != UNCOMPRESSED_KEY_PREFIX ) {
770+ return -1 ;
771+ }
772+
773+ /* Skip the first byte holding key format */
774+ pk ++ ;
775+
776+ return ocrypto_ecdsa_p256_verify_hash (signature , hash , pk );
777+ }
778+
779+ static inline int bootutil_ecdsa_parse_public_key (bootutil_ecdsa_context * ctx ,
780+ uint8_t * * cp , uint8_t * end )
781+ {
782+ (void )ctx ;
783+
784+ return bootutil_import_key (cp , end );
785+ }
786+
787+ #endif /* MCUBOOT_USE_NRF_OBERON */
788+
722789#ifdef __cplusplus
723790}
724791#endif
0 commit comments