@@ -132,8 +132,6 @@ static int bootutil_import_key(uint8_t **cp, uint8_t *end)
132
132
}
133
133
#endif /* MCUBOOT_USE_TINYCRYPT || MCUBOOT_USE_MBED_TLS || MCUBOOT_USE_CC310 */
134
134
135
- #if defined(MCUBOOT_USE_TINYCRYPT )
136
- #ifndef MCUBOOT_ECDSA_NEED_ASN1_SIG
137
135
/*
138
136
* cp points to ASN1 string containing an integer.
139
137
* Verify the tag, and that the length is 32 bytes. Helper function.
@@ -183,8 +181,8 @@ static int bootutil_decode_sig(uint8_t signature[NUM_ECC_BYTES * 2], uint8_t *cp
183
181
}
184
182
return 0 ;
185
183
}
186
- #endif /* not MCUBOOT_ECDSA_NEED_ASN1_SIG */
187
184
185
+ #if defined(MCUBOOT_USE_TINYCRYPT )
188
186
typedef uintptr_t bootutil_ecdsa_context ;
189
187
static inline void bootutil_ecdsa_init (bootutil_ecdsa_context * ctx )
190
188
{
@@ -253,16 +251,20 @@ static inline int bootutil_ecdsa_verify(bootutil_ecdsa_context *ctx,
253
251
{
254
252
(void )ctx ;
255
253
(void )pk_len ;
256
- (void )sig_len ;
257
254
(void )hash_len ;
255
+ uint8_t dsig [2 * NUM_ECC_BYTES ];
256
+
257
+ if (bootutil_decode_sig (dsig , sig , sig + sig_len )) {
258
+ return -1 ;
259
+ }
258
260
259
261
/* Only support uncompressed keys. */
260
262
if (pk [0 ] != 0x04 ) {
261
263
return -1 ;
262
264
}
263
265
pk ++ ;
264
266
265
- return cc310_ecdsa_verify_secp256r1 (hash , pk , sig , BOOTUTIL_CRYPTO_ECDSA_P256_HASH_SIZE );
267
+ return cc310_ecdsa_verify_secp256r1 (hash , pk , dsig , BOOTUTIL_CRYPTO_ECDSA_P256_HASH_SIZE );
266
268
}
267
269
268
270
static inline int bootutil_ecdsa_parse_public_key (bootutil_ecdsa_context * ctx ,
@@ -619,7 +621,11 @@ static inline int bootutil_ecdsa_p256_verify(bootutil_ecdsa_p256_context *ctx,
619
621
{
620
622
(void )ctx ;
621
623
(void )pk_len ;
622
- (void )sig_len ;
624
+ uint8_t dsig [2 * NUM_ECC_BYTES ];
625
+
626
+ if (bootutil_decode_sig (dsig , sig , sig + sig_len )) {
627
+ return -1 ;
628
+ }
623
629
624
630
/* As described on the compact representation in IETF protocols,
625
631
* the first byte of the key defines if the ECC points are
@@ -632,7 +638,7 @@ static inline int bootutil_ecdsa_p256_verify(bootutil_ecdsa_p256_context *ctx,
632
638
pk ++ ;
633
639
634
640
return bl_secp256r1_validate (hash , BOOTUTIL_CRYPTO_ECDSA_P256_HASH_SIZE ,
635
- pk , sig );
641
+ pk , dsig );
636
642
}
637
643
#endif /* MCUBOOT_USE_NRF_EXTERNAL_CRYPTO */
638
644
0 commit comments