Implicitly add trailer when setting enc key

pull/470/head
Daniele Lacamera 2024-07-17 18:33:37 +02:00
parent 8b73250324
commit d3795c81cd
2 changed files with 4 additions and 2 deletions

View File

@ -1381,9 +1381,12 @@ static int RAMFUNCTION hal_set_key(const uint8_t *k, const uint8_t *nonce)
if (ret != 0)
return ret;
#endif
XMEMCPY(ENCRYPT_CACHE + addr_off, k, ENCRYPT_KEY_SIZE);
XMEMCPY(ENCRYPT_CACHE + addr_off + ENCRYPT_KEY_SIZE, nonce,
ENCRYPT_NONCE_SIZE);
XMEMCPY(ENCRYPT_CACHE + addr_off - 4,
&wolfboot_magic_trail, 4);
ret = hal_flash_write(addr_align, ENCRYPT_CACHE, WOLFBOOT_SECTOR_SIZE);
#ifdef NVM_FLASH_WRITEONCE
/* now erase the old populated sector */
@ -1412,7 +1415,6 @@ static int RAMFUNCTION hal_set_key(const uint8_t *k, const uint8_t *nonce)
int RAMFUNCTION wolfBoot_set_encrypt_key(const uint8_t *key,
const uint8_t *nonce)
{
set_partition_magic(PART_BOOT);
hal_set_key(key, nonce);
return 0;
}

View File

@ -821,7 +821,7 @@ void RAMFUNCTION wolfBoot_start(void)
updateRet = wolfBoot_get_partition_state(PART_UPDATE, &updateState);
#if !defined(DISABLE_BACKUP) && !defined(EXT_ENCRYPTED)
#if !defined(DISABLE_BACKUP)
/* resume the final erase in case the power failed before it finished */
resumedFinalErase = wolfBoot_swap_and_final_erase(1);
if (resumedFinalErase != 0)