@@ -473,6 +473,7 @@ static int bootutil_ecdsa_parse_public_key(bootutil_ecdsa_context *ctx,
473
473
}
474
474
#endif /* !MCUBOOT_BUILTIN_KEY */
475
475
476
+ #if !defined(CONFIG_NRF_BOOT_SIGNATURE_USING_ITS )
476
477
/* Verify the signature against the provided hash. The signature gets parsed from
477
478
* the encoding first, then PSA Crypto has a dedicated API for ECDSA verification
478
479
*/
@@ -491,6 +492,55 @@ static inline int bootutil_ecdsa_verify(bootutil_ecdsa_context *ctx,
491
492
return (int ) psa_verify_hash (ctx -> key_id , PSA_ALG_ECDSA (ctx -> required_algorithm ),
492
493
hash , hlen , reformatted_signature , 2 * ctx -> curve_byte_count );
493
494
}
495
+ #else /* !CONFIG_NRF_BOOT_SIGNATURE_USING_ITS */
496
+
497
+ static const psa_key_id_t builtin_key_ids [] = {
498
+ 0x40022100 ,
499
+ 0x40022101 ,
500
+ 0x40022102 ,
501
+ 0x40022103
502
+ };
503
+
504
+ #define BOOT_SIGNATURE_BUILTIN_KEY_SLOTS ARRAY_SIZE(builtin_key_ids)
505
+
506
+ static inline int bootutil_ecdsa_verify (bootutil_ecdsa_context * ctx ,
507
+ uint8_t * pk , size_t pk_len ,
508
+ uint8_t * hash , size_t hlen ,
509
+ uint8_t * sig , size_t slen )
510
+ {
511
+ (void )pk ;
512
+ (void )pk_len ;
513
+ (void )slen ;
514
+ psa_status_t status = PSA_ERROR_BAD_STATE ;
515
+
516
+ /* Initialize PSA Crypto */
517
+ status = psa_crypto_init ();
518
+ if (status != PSA_SUCCESS ) {
519
+ BOOT_LOG_ERR ("PSA crypto init failed %d" , status );
520
+ return 1 ;
521
+ }
522
+
523
+ uint8_t reformatted_signature [96 ] = {0 }; /* Enough for P-384 signature sizes */
524
+ parse_signature_from_rfc5480_encoding (sig , ctx -> curve_byte_count , reformatted_signature );
525
+
526
+ status = PSA_ERROR_BAD_STATE ;
527
+
528
+ for (int i = 0 ; i < BOOT_SIGNATURE_BUILTIN_KEY_SLOTS ; ++ i ) {
529
+ psa_key_id_t kid = builtin_key_ids [i ];
530
+
531
+ status = psa_verify_hash (kid , PSA_ALG_ECDSA (ctx -> required_algorithm ),
532
+ hash , hlen , reformatted_signature , 2 * ctx -> curve_byte_count );
533
+ if (status == PSA_SUCCESS ) {
534
+ break ;
535
+ }
536
+ BOOT_LOG_ERR ("ECDSA signature verification failed %d" , status );
537
+ }
538
+
539
+ return status == PSA_SUCCESS ? 0 : 2 ;
540
+ }
541
+
542
+ #endif /* !CONFIG_NRF_BOOT_SIGNATURE_USING_ITS */
543
+
494
544
#elif defined(MCUBOOT_USE_MBED_TLS )
495
545
496
546
typedef mbedtls_ecdsa_context bootutil_ecdsa_context ;
0 commit comments