@@ -573,7 +573,7 @@ boot_enc_load(struct boot_loader_state *state, int slot,
573573 const struct image_header * hdr , const struct flash_area * fap ,
574574 struct boot_status * bs )
575575{
576- struct enc_key_data * enc_state = BOOT_CURR_ENC (state );
576+ struct enc_key_data * enc_state = BOOT_CURR_ENC_SLOT (state , slot );
577577 uint32_t off ;
578578 uint16_t len ;
579579 struct image_tlv_iter it ;
@@ -587,13 +587,13 @@ boot_enc_load(struct boot_loader_state *state, int slot,
587587 BOOT_LOG_DBG ("boot_enc_load: slot %d" , slot );
588588
589589 /* Already loaded... */
590- if (enc_state [ slot ]. valid ) {
590+ if (boot_enc_valid ( enc_state ) ) {
591591 BOOT_LOG_DBG ("boot_enc_load: already loaded" );
592592 return 1 ;
593593 }
594594
595595 /* Initialize the AES context */
596- boot_enc_init (enc_state , slot );
596+ boot_enc_init (enc_state );
597597
598598#if defined(MCUBOOT_SWAP_USING_OFFSET )
599599 it .start_off = boot_get_state_secondary_offset (state , fap );
@@ -627,48 +627,46 @@ boot_enc_load(struct boot_loader_state *state, int slot,
627627}
628628
629629int
630- boot_enc_init (struct enc_key_data * enc_state , uint8_t slot )
630+ boot_enc_init (struct enc_key_data * enc_state )
631631{
632- bootutil_aes_ctr_init (& enc_state [ slot ]. aes_ctr );
632+ bootutil_aes_ctr_init (& enc_state -> aes_ctr );
633633 return 0 ;
634634}
635635
636636int
637- boot_enc_drop (struct enc_key_data * enc_state , uint8_t slot )
637+ boot_enc_drop (struct enc_key_data * enc_state )
638638{
639- bootutil_aes_ctr_drop (& enc_state [ slot ]. aes_ctr );
640- enc_state [ slot ]. valid = 0 ;
639+ bootutil_aes_ctr_drop (& enc_state -> aes_ctr );
640+ enc_state -> valid = 0 ;
641641 return 0 ;
642642}
643643
644644int
645- boot_enc_set_key (struct enc_key_data * enc_state , uint8_t slot ,
646- const struct boot_status * bs )
645+ boot_enc_set_key (struct enc_key_data * enc_state , const uint8_t * key )
647646{
648647 int rc ;
649648
650- rc = bootutil_aes_ctr_set_key (& enc_state [ slot ]. aes_ctr , bs -> enckey [ slot ] );
649+ rc = bootutil_aes_ctr_set_key (& enc_state -> aes_ctr , key );
651650 if (rc != 0 ) {
652- boot_enc_drop (enc_state , slot );
651+ boot_enc_drop (enc_state );
653652 return -1 ;
654653 }
655654
656- enc_state [ slot ]. valid = 1 ;
655+ enc_state -> valid = 1 ;
657656
658657 return 0 ;
659658}
660659
661660bool
662- boot_enc_valid (struct enc_key_data * enc_state , int slot )
661+ boot_enc_valid (const struct enc_key_data * enc_state )
663662{
664- return enc_state [ slot ]. valid ;
663+ return enc_state -> valid ;
665664}
666665
667666void
668- boot_enc_encrypt (struct enc_key_data * enc_state , int slot , uint32_t off ,
667+ boot_enc_encrypt (struct enc_key_data * enc , uint32_t off ,
669668 uint32_t sz , uint32_t blk_off , uint8_t * buf )
670669{
671- struct enc_key_data * enc = & enc_state [slot ];
672670 uint8_t nonce [16 ];
673671
674672 /* Nothing to do with size == 0 */
@@ -688,10 +686,9 @@ boot_enc_encrypt(struct enc_key_data *enc_state, int slot, uint32_t off,
688686}
689687
690688void
691- boot_enc_decrypt (struct enc_key_data * enc_state , int slot , uint32_t off ,
689+ boot_enc_decrypt (struct enc_key_data * enc , uint32_t off ,
692690 uint32_t sz , uint32_t blk_off , uint8_t * buf )
693691{
694- struct enc_key_data * enc = & enc_state [slot ];
695692 uint8_t nonce [16 ];
696693
697694 /* Nothing to do with size == 0 */
@@ -718,7 +715,7 @@ boot_enc_zeroize(struct enc_key_data *enc_state)
718715{
719716 uint8_t slot ;
720717 for (slot = 0 ; slot < BOOT_NUM_SLOTS ; slot ++ ) {
721- (void )boot_enc_drop (enc_state , slot );
718+ (void )boot_enc_drop (& enc_state [ slot ] );
722719 }
723720 memset (enc_state , 0 , sizeof (struct enc_key_data ) * BOOT_NUM_SLOTS );
724721}
0 commit comments