Skip to content

Commit 87761e8

Browse files
jpbland1danielinux
authored andcommitted
make aes_init and chacha_init read the backup key
1 parent 5a7665a commit 87761e8

1 file changed

Lines changed: 4 additions & 12 deletions

File tree

src/libwolfboot.c

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1539,16 +1539,12 @@ int RAMFUNCTION chacha_init(void)
15391539
#if defined(MMU) || defined(UNIT_TEST)
15401540
uint8_t *key = ENCRYPT_KEY;
15411541
#else
1542-
uint8_t *key = (uint8_t *)(WOLFBOOT_PARTITION_BOOT_ADDRESS +
1543-
ENCRYPT_TMP_SECRET_OFFSET);
1542+
uint8_t key[ENCRYPT_KEY_SIZE + ENCRYPT_NONCE_SIZE];
1543+
wolfBoot_get_encrypt_key(key, key + ENCRYPT_KEY_SIZE);
15441544
#endif
15451545
uint8_t ff[ENCRYPT_KEY_SIZE];
15461546
uint8_t* stored_nonce;
15471547

1548-
#ifdef NVM_FLASH_WRITEONCE
1549-
key -= WOLFBOOT_SECTOR_SIZE * nvm_select_fresh_sector(PART_BOOT);
1550-
#endif
1551-
15521548
stored_nonce = key + ENCRYPT_KEY_SIZE;
15531549

15541550
XMEMSET(&chacha, 0, sizeof(chacha));
@@ -1585,17 +1581,13 @@ int aes_init(void)
15851581
#if defined(MMU) || defined(UNIT_TEST)
15861582
uint8_t *key = ENCRYPT_KEY;
15871583
#else
1588-
uint8_t *key = (uint8_t *)(WOLFBOOT_PARTITION_BOOT_ADDRESS +
1589-
ENCRYPT_TMP_SECRET_OFFSET);
1584+
uint8_t key[ENCRYPT_KEY_SIZE + ENCRYPT_NONCE_SIZE];
1585+
wolfBoot_get_encrypt_key(key, key + ENCRYPT_KEY_SIZE);
15901586
#endif
15911587
uint8_t ff[ENCRYPT_KEY_SIZE];
15921588
uint8_t iv_buf[ENCRYPT_NONCE_SIZE];
15931589
uint8_t* stored_nonce;
15941590

1595-
#ifdef NVM_FLASH_WRITEONCE
1596-
key -= WOLFBOOT_SECTOR_SIZE * nvm_select_fresh_sector(PART_BOOT);
1597-
#endif
1598-
15991591
stored_nonce = key + ENCRYPT_KEY_SIZE;
16001592

16011593
XMEMSET(&aes_enc, 0, sizeof(aes_enc));

0 commit comments

Comments
 (0)