6464#endif /* MCUBOOT_USE_NRF_OBERON_EXPERIMENT */
6565
6666/*TODO: remove this after cypress port mbedtls to abstract crypto api */
67- #if defined(MCUBOOT_USE_CC310 ) || defined(MCUBOOT_USE_MBED_TLS )
67+ #if defined(MCUBOOT_USE_CC310 ) || defined(MCUBOOT_USE_MBED_TLS ) || defined( MCUBOOT_USE_NRF_OBERON_EXPERIMENT )
6868#define NUM_ECC_BYTES (256 / 8)
6969#endif
7070
@@ -88,7 +88,8 @@ extern "C" {
8888#endif
8989
9090#if (defined(MCUBOOT_USE_TINYCRYPT ) || defined(MCUBOOT_USE_MBED_TLS ) || \
91- defined(MCUBOOT_USE_CC310 ) || defined(MCUBOOT_USE_NRF_EXTERNAL_CRYPTO )) \
91+ defined(MCUBOOT_USE_CC310 ) || defined(MCUBOOT_USE_NRF_EXTERNAL_CRYPTO ) || \
92+ defined(MCUBOOT_USE_NRF_OBERON_EXPERIMENT )) \
9293 && !defined(MCUBOOT_USE_PSA_CRYPTO )
9394/*
9495 * Declaring these like this adds NULL termination.
@@ -141,7 +142,7 @@ static int bootutil_import_key(uint8_t **cp, uint8_t *end)
141142}
142143#endif /* (MCUBOOT_USE_TINYCRYPT || MCUBOOT_USE_MBED_TLS || MCUBOOT_USE_CC310) && !MCUBOOT_USE_PSA_CRYPTO */
143144
144- #if !defined(MCUBOOT_USE_PSA_CRYPTO ) && !defined( MCUBOOT_USE_NRF_OBERON_EXPERIMENT )
145+ #if !defined(MCUBOOT_USE_PSA_CRYPTO )
145146/*
146147 * cp points to ASN1 string containing an integer.
147148 * Verify the tag, and that the length is 32 bytes. Helper function.
@@ -191,7 +192,7 @@ static int bootutil_decode_sig(uint8_t signature[NUM_ECC_BYTES * 2], uint8_t *cp
191192 }
192193 return 0 ;
193194}
194- #endif /* !defined(MCUBOOT_USE_PSA_CRYPTO) && !defined(MCUBOOT_USE_NRF_OBERON_EXPERIMENT) */
195+ #endif /* !defined(MCUBOOT_USE_PSA_CRYPTO) */
195196
196197#if defined(MCUBOOT_USE_TINYCRYPT )
197198typedef uintptr_t bootutil_ecdsa_context ;
@@ -746,16 +747,28 @@ static inline int bootutil_ecdsa_verify(bootutil_ecdsa_context *ctx,
746747 return -1 ;
747748 }
748749
749- return ocrypto_ecdsa_p256_verify_hash (sig , hash , pk );
750+ uint8_t signature [2 * NUM_ECC_BYTES ];
751+ int rc = bootutil_decode_sig (signature , sig , sig + sig_len );
752+ if (rc ) {
753+ return -1 ;
754+ }
755+
756+ /* Only support uncompressed keys */
757+ if (pk [0 ] != 0x04 ) {
758+ return -1 ;
759+ }
760+ /* Skip the first byte holding key format */
761+ pk ++ ;
762+
763+ rc = ocrypto_ecdsa_p256_verify_hash (signature , hash , pk );
764+ return rc ;
750765}
751766
752767static inline int bootutil_ecdsa_parse_public_key (bootutil_ecdsa_context * ctx ,
753768 uint8_t * * cp ,uint8_t * end )
754769{
755- /* NOTE: No corresponding funciton in ocrypto */
756770 (void )ctx ;
757- (void )cp ;
758- (void )end ;
771+ return bootutil_import_key (cp , end );
759772 return 0 ;
760773}
761774#endif /* MCUBOOT_USE_NRF_OBERON_EXPERIMENT */
0 commit comments