Skip to content

Commit d3795c8

Browse files
committed
Implicitly add trailer when setting enc key
1 parent 8b73250 commit d3795c8

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

src/libwolfboot.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1381,9 +1381,12 @@ static int RAMFUNCTION hal_set_key(const uint8_t *k, const uint8_t *nonce)
13811381
if (ret != 0)
13821382
return ret;
13831383
#endif
1384+
13841385
XMEMCPY(ENCRYPT_CACHE + addr_off, k, ENCRYPT_KEY_SIZE);
13851386
XMEMCPY(ENCRYPT_CACHE + addr_off + ENCRYPT_KEY_SIZE, nonce,
13861387
ENCRYPT_NONCE_SIZE);
1388+
XMEMCPY(ENCRYPT_CACHE + addr_off - 4,
1389+
&wolfboot_magic_trail, 4);
13871390
ret = hal_flash_write(addr_align, ENCRYPT_CACHE, WOLFBOOT_SECTOR_SIZE);
13881391
#ifdef NVM_FLASH_WRITEONCE
13891392
/* now erase the old populated sector */
@@ -1412,7 +1415,6 @@ static int RAMFUNCTION hal_set_key(const uint8_t *k, const uint8_t *nonce)
14121415
int RAMFUNCTION wolfBoot_set_encrypt_key(const uint8_t *key,
14131416
const uint8_t *nonce)
14141417
{
1415-
set_partition_magic(PART_BOOT);
14161418
hal_set_key(key, nonce);
14171419
return 0;
14181420
}

src/update_flash.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -821,7 +821,7 @@ void RAMFUNCTION wolfBoot_start(void)
821821
updateRet = wolfBoot_get_partition_state(PART_UPDATE, &updateState);
822822

823823

824-
#if !defined(DISABLE_BACKUP) && !defined(EXT_ENCRYPTED)
824+
#if !defined(DISABLE_BACKUP)
825825
/* resume the final erase in case the power failed before it finished */
826826
resumedFinalErase = wolfBoot_swap_and_final_erase(1);
827827
if (resumedFinalErase != 0)

0 commit comments

Comments
 (0)