Skip to content

Commit 3dc152c

Browse files
committed
Added ENCRYPT_CACHE= config option
1 parent 146b0aa commit 3dc152c

File tree

4 files changed

+29
-9
lines changed

4 files changed

+29
-9
lines changed

docs/encrypted_partitions.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,13 @@ as template. The file `hal/stm32l0_chacha_ram.ld` contains the changes described
179179
all the needed symbols in RAM.
180180

181181

182+
### Using a custom buffer as encrypt/decrypt cache
183+
184+
By default, encryption support requires a buffer of the same size as the external flash page size to be allocated in RAM.
185+
You can provide a custom pre-allocated buffer by passing its address via the option `ENCRYPT_CACHE`, e.g.:
186+
187+
`ENCRYPT_CACHE=0x20010000`
188+
182189
### API usage in the application
183190

184191
When transferring the image, the application can still use the libwolfboot API functions to store the encrypted firmware. When called from the application,

options.mk

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -766,6 +766,14 @@ ifeq ($(RAM_CODE),1)
766766
endif
767767
endif
768768

769+
# Support external encryption cache
770+
#
771+
ifeq ($(ENCRYPT),1)
772+
ifeq ($(ENCRYPT_CACHE),1)
773+
CFLAGS+=-D"WOLFBOOT_ENCRYPT_CACHE=$(ENCRYPT_CACHE)"
774+
endif
775+
endif
776+
769777
# support for elf32 or elf64 loader
770778
ifeq ($(ELF),1)
771779
CFLAGS+=-DWOLFBOOT_ELF

src/libwolfboot.c

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1334,17 +1334,21 @@ int wolfBoot_fallback_is_possible(void)
13341334

13351335
#ifdef EXT_ENCRYPTED
13361336
#include "encrypt.h"
1337+
13371338
#if !defined(EXT_FLASH) && !defined(MMU)
1338-
#error option EXT_ENCRYPTED requires EXT_FLASH or MMU mode
1339+
#error option EXT_ENCRYPTED requires EXT_FLASH or MMU mode
13391340
#endif
13401341

1341-
1342-
#ifdef NVM_FLASH_WRITEONCE
1343-
#define ENCRYPT_CACHE NVM_CACHE
1342+
#ifndef WOLFBOOT_ENCRYPT_CACHE
1343+
#ifdef NVM_FLASH_WRITEONCE
1344+
#define ENCRYPT_CACHE NVM_CACHE
1345+
#else
1346+
#ifdef WOLFBOOT_SMALL_STACK
1347+
static uint8_t ENCRYPT_CACHE[NVM_CACHE_SIZE] __attribute__((aligned(32)));
1348+
#endif
1349+
#endif
13441350
#else
1345-
#ifdef WOLFBOOT_SMALL_STACK
1346-
static uint8_t ENCRYPT_CACHE[NVM_CACHE_SIZE] __attribute__((aligned(32)));
1347-
#endif
1351+
#define ENCRYPT_CACHE (WOLFBOOT_ENCRYPT_CACHE)
13481352
#endif
13491353

13501354
#if defined(EXT_ENCRYPTED) && defined(MMU)
@@ -1358,7 +1362,7 @@ static int RAMFUNCTION hal_set_key(const uint8_t *k, const uint8_t *nonce)
13581362
int sel_sec = 0;
13591363
uint32_t trailer_relative_off = 4;
13601364

1361-
#if !defined(WOLFBOOT_SMALL_STACK) && !defined(NVM_FLASH_WRITEONCE)
1365+
#if !defined(WOLFBOOT_SMALL_STACK) && !defined(NVM_FLASH_WRITEONCE) && !defined(WOLFBOOT_ENCRYPT_CACHE)
13621366
uint8_t ENCRYPT_CACHE[NVM_CACHE_SIZE] __attribute__((aligned(32)));
13631367
#endif
13641368

tools/config.mk

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,4 +111,5 @@ CONFIG_VARS:= ARCH TARGET SIGN HASH MCUXSDK MCUXPRESSO MCUXPRESSO_CPU MCUXPRESSO
111111
NO_ARM_ASM \
112112
SIGN_SECONDARY \
113113
WOLFHSM_CLIENT \
114-
WOLFHSM_CLIENT_LOCAL_KEYS
114+
WOLFHSM_CLIENT_LOCAL_KEYS \
115+
ENCRYPT_CACHE

0 commit comments

Comments
 (0)