@@ -67,13 +67,13 @@ static int bootutil_constant_time_compare(const uint8_t *a, const uint8_t *b, si
6767
6868#if defined(MCUBOOT_ENCRYPT_KW )
6969static int
70- key_unwrap (const uint8_t * wrapped , uint8_t * enckey )
70+ key_unwrap (const uint8_t * wrapped , uint8_t * enckey , struct bootutil_key * bootutil_enc_key )
7171{
7272 bootutil_aes_kw_context aes_kw ;
7373 int rc ;
7474
7575 bootutil_aes_kw_init (& aes_kw );
76- rc = bootutil_aes_kw_set_unwrap_key (& aes_kw , bootutil_enc_key . key , * bootutil_enc_key . len );
76+ rc = bootutil_aes_kw_set_unwrap_key (& aes_kw , bootutil_enc_key -> key , * bootutil_enc_key -> len );
7777 if (rc != 0 ) {
7878 goto done ;
7979 }
@@ -441,13 +441,23 @@ boot_decrypt_key(const uint8_t *buf, uint8_t *enckey)
441441 uint8_t counter [BOOTUTIL_CRYPTO_AES_CTR_BLOCK_SIZE ];
442442 uint16_t len ;
443443#endif
444+ struct bootutil_key * bootutil_enc_key = NULL ;
444445 int rc = -1 ;
445446
447+ rc = boot_enc_retrieve_private_key (& bootutil_enc_key );
448+ if (rc ) {
449+ return rc ;
450+ }
451+
452+ if (bootutil_enc_key == NULL ) {
453+ return rc ;
454+ }
455+
446456#if defined(MCUBOOT_ENCRYPT_RSA )
447457
448458 bootutil_rsa_init (& rsa );
449- cp = (uint8_t * )bootutil_enc_key . key ;
450- cpend = cp + * bootutil_enc_key . len ;
459+ cp = (uint8_t * )bootutil_enc_key -> key ;
460+ cpend = cp + * bootutil_enc_key -> len ;
451461
452462 /* The enckey is encrypted through RSA so for decryption we need the private key */
453463 rc = bootutil_rsa_parse_private_key (& rsa , & cp , cpend );
@@ -466,15 +476,15 @@ boot_decrypt_key(const uint8_t *buf, uint8_t *enckey)
466476
467477#if defined(MCUBOOT_ENCRYPT_KW )
468478
469- assert (* bootutil_enc_key . len == BOOT_ENC_KEY_SIZE );
470- rc = key_unwrap (buf , enckey );
479+ assert (* bootutil_enc_key -> len == BOOT_ENC_KEY_SIZE );
480+ rc = key_unwrap (buf , enckey , bootutil_enc_key );
471481
472482#endif /* defined(MCUBOOT_ENCRYPT_KW) */
473483
474484#if defined(MCUBOOT_ENCRYPT_EC256 )
475485
476- cp = (uint8_t * )bootutil_enc_key . key ;
477- cpend = cp + * bootutil_enc_key . len ;
486+ cp = (uint8_t * )bootutil_enc_key -> key ;
487+ cpend = cp + * bootutil_enc_key -> len ;
478488
479489 /*
480490 * Load the stored EC256 decryption private key
@@ -500,8 +510,8 @@ boot_decrypt_key(const uint8_t *buf, uint8_t *enckey)
500510
501511#if defined(MCUBOOT_ENCRYPT_X25519 )
502512
503- cp = (uint8_t * )bootutil_enc_key . key ;
504- cpend = cp + * bootutil_enc_key . len ;
513+ cp = (uint8_t * )bootutil_enc_key -> key ;
514+ cpend = cp + * bootutil_enc_key -> len ;
505515
506516 /*
507517 * Load the stored X25519 decryption private key
0 commit comments