Skip to content

Commit 146b0aa

Browse files
committed
Move encrypt cache to stack
This avoids claiming a large amount of RAM when using libwolfboot from the app.
1 parent 71346b8 commit 146b0aa

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/libwolfboot.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1339,12 +1339,13 @@ int wolfBoot_fallback_is_possible(void)
13391339
#endif
13401340

13411341

1342-
13431342
#ifdef NVM_FLASH_WRITEONCE
13441343
#define ENCRYPT_CACHE NVM_CACHE
13451344
#else
1345+
#ifdef WOLFBOOT_SMALL_STACK
13461346
static uint8_t ENCRYPT_CACHE[NVM_CACHE_SIZE] __attribute__((aligned(32)));
13471347
#endif
1348+
#endif
13481349

13491350
#if defined(EXT_ENCRYPTED) && defined(MMU)
13501351
static uint8_t ENCRYPT_KEY[ENCRYPT_KEY_SIZE + ENCRYPT_NONCE_SIZE];
@@ -1356,6 +1357,11 @@ static int RAMFUNCTION hal_set_key(const uint8_t *k, const uint8_t *nonce)
13561357
int ret = 0;
13571358
int sel_sec = 0;
13581359
uint32_t trailer_relative_off = 4;
1360+
1361+
#if !defined(WOLFBOOT_SMALL_STACK) && !defined(NVM_FLASH_WRITEONCE)
1362+
uint8_t ENCRYPT_CACHE[NVM_CACHE_SIZE] __attribute__((aligned(32)));
1363+
#endif
1364+
13591365
#ifdef MMU
13601366
XMEMCPY(ENCRYPT_KEY, k, ENCRYPT_KEY_SIZE);
13611367
XMEMCPY(ENCRYPT_KEY + ENCRYPT_KEY_SIZE, nonce, ENCRYPT_NONCE_SIZE);
@@ -1692,6 +1698,9 @@ int RAMFUNCTION ext_flash_encrypt_write(uintptr_t address, const uint8_t *data,
16921698
int sz = len, i, step;
16931699
uint8_t part;
16941700
uint32_t iv_counter = 0;
1701+
#if defined(EXT_ENCRYPTED) && !defined(WOLFBOOT_SMALL_STACK) && !defined(NVM_FLASH_WRITEONCE)
1702+
uint8_t ENCRYPT_CACHE[NVM_CACHE_SIZE] __attribute__((aligned(32)));
1703+
#endif
16951704

16961705
row_offset = address & (ENCRYPT_BLOCK_SIZE - 1);
16971706
if (row_offset != 0) {

0 commit comments

Comments
 (0)