@@ -67,13 +67,13 @@ static int bootutil_constant_time_compare(const uint8_t *a, const uint8_t *b, si
67
67
68
68
#if defined(MCUBOOT_ENCRYPT_KW )
69
69
static 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 )
71
71
{
72
72
bootutil_aes_kw_context aes_kw ;
73
73
int rc ;
74
74
75
75
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 );
77
77
if (rc != 0 ) {
78
78
goto done ;
79
79
}
@@ -441,13 +441,23 @@ boot_decrypt_key(const uint8_t *buf, uint8_t *enckey)
441
441
uint8_t counter [BOOTUTIL_CRYPTO_AES_CTR_BLOCK_SIZE ];
442
442
uint16_t len ;
443
443
#endif
444
+ struct bootutil_key * bootutil_enc_key = NULL ;
444
445
int rc = -1 ;
445
446
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
+
446
456
#if defined(MCUBOOT_ENCRYPT_RSA )
447
457
448
458
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 ;
451
461
452
462
/* The enckey is encrypted through RSA so for decryption we need the private key */
453
463
rc = bootutil_rsa_parse_private_key (& rsa , & cp , cpend );
@@ -466,15 +476,15 @@ boot_decrypt_key(const uint8_t *buf, uint8_t *enckey)
466
476
467
477
#if defined(MCUBOOT_ENCRYPT_KW )
468
478
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 );
471
481
472
482
#endif /* defined(MCUBOOT_ENCRYPT_KW) */
473
483
474
484
#if defined(MCUBOOT_ENCRYPT_EC256 )
475
485
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 ;
478
488
479
489
/*
480
490
* Load the stored EC256 decryption private key
@@ -500,8 +510,8 @@ boot_decrypt_key(const uint8_t *buf, uint8_t *enckey)
500
510
501
511
#if defined(MCUBOOT_ENCRYPT_X25519 )
502
512
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 ;
505
515
506
516
/*
507
517
* Load the stored X25519 decryption private key
0 commit comments