Skip to content

Commit 55e2930

Browse files
committed
Fix for NO_SWAP_EXT=1 with encryption enabled. Peer review fixes.
1 parent 43d7bdf commit 55e2930

File tree

4 files changed

+14
-10
lines changed

4 files changed

+14
-10
lines changed

include/user_settings.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,11 @@ extern int tolower(int c);
118118
# if !defined(WOLFBOOT_TPM)
119119
# define NO_ECC_SIGN
120120
# define NO_ECC_DHE
121-
# define WOLFSSL_NO_CT_OPS /* don't use constant time ops in misc.c */
121+
/* For Renesas RX do not enable the misc.c constant time code
122+
* due to issue with 64-bit types */
123+
# if defined(__RX__)
124+
# define WOLFSSL_NO_CT_OPS /* don't use constant time ops in misc.c */
125+
# endif
122126
# if !defined(WOLFBOOT_ENABLE_WOLFHSM_CLIENT)
123127
# define NO_ECC_EXPORT
124128
# define NO_ECC_KEY_EXPORT

src/image.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1500,7 +1500,7 @@ static int update_hash_flash_fwimg(wolfBoot_hash_t* ctx,
15001500
{
15011501
uint32_t current_offset = offset;
15021502
uint32_t remaining_size = size;
1503-
uint8_t read_buf[WOLFBOOT_SHA_BLOCK_SIZE] XALIGNED(4); /* Use local buffer*/
1503+
uint8_t read_buf[WOLFBOOT_SHA_BLOCK_SIZE] XALIGNED_STACK(4); /* Use local buffer */
15041504

15051505
while (remaining_size > 0) {
15061506
uint32_t read_size = (remaining_size > WOLFBOOT_SHA_BLOCK_SIZE)
@@ -1529,7 +1529,7 @@ static int update_hash_flash_fwimg(wolfBoot_hash_t* ctx,
15291529
static int update_hash_flash_addr(wolfBoot_hash_t* ctx, uintptr_t addr,
15301530
uint32_t size, int src_ext)
15311531
{
1532-
uint8_t buffer[WOLFBOOT_SHA_BLOCK_SIZE] XALIGNED(4);
1532+
uint8_t buffer[WOLFBOOT_SHA_BLOCK_SIZE] XALIGNED_STACK(4);
15331533
uint32_t remaining_size = size;
15341534
uintptr_t current_addr = addr;
15351535

@@ -1568,7 +1568,7 @@ int wolfBoot_check_flash_image_elf(uint8_t part, unsigned long* entry_out)
15681568
size_t ph_size = 0;
15691569
size_t current_ph_offset = 0;
15701570
int64_t final_offset = -1;
1571-
uint8_t calc_digest[WOLFBOOT_SHA_DIGEST_SIZE] XALIGNED(4);
1571+
uint8_t calc_digest[WOLFBOOT_SHA_DIGEST_SIZE] XALIGNED_STACK(4);
15721572
uint8_t* exp_digest;
15731573
int32_t stored_sha_len;
15741574
int i;

src/libwolfboot.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1836,8 +1836,8 @@ int RAMFUNCTION ext_flash_encrypt_write(uintptr_t address, const uint8_t *data,
18361836
*/
18371837
int RAMFUNCTION ext_flash_decrypt_read(uintptr_t address, uint8_t *data, int len)
18381838
{
1839-
uint8_t block[ENCRYPT_BLOCK_SIZE] XALIGNED(4);
1840-
uint8_t dec_block[ENCRYPT_BLOCK_SIZE] XALIGNED(4);
1839+
uint8_t block[ENCRYPT_BLOCK_SIZE] XALIGNED_STACK(4);
1840+
uint8_t dec_block[ENCRYPT_BLOCK_SIZE] XALIGNED_STACK(4);
18411841
uint32_t row_address = address, row_offset, iv_counter = 0;
18421842
int i;
18431843
int flash_read_size;
@@ -1915,7 +1915,7 @@ int RAMFUNCTION ext_flash_decrypt_read(uintptr_t address, uint8_t *data, int len
19151915
unaligned_trailer_size = read_remaining;
19161916
if (unaligned_trailer_size > 0)
19171917
{
1918-
uint8_t dec_block[ENCRYPT_BLOCK_SIZE] XALIGNED(4);
1918+
uint8_t dec_block[ENCRYPT_BLOCK_SIZE] XALIGNED_STACK(4);
19191919
if (ext_flash_read(address, block, ENCRYPT_BLOCK_SIZE)
19201920
!= ENCRYPT_BLOCK_SIZE)
19211921
return -1;

src/update_flash.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ static int RAMFUNCTION wolfBoot_copy_sector(struct wolfBoot_image *src,
153153

154154
#ifdef EXT_ENCRYPTED
155155
wolfBoot_get_encrypt_key(key, nonce);
156-
if(src->part == PART_SWAP)
156+
if (src->part == PART_SWAP)
157157
iv_counter = dst_sector_offset;
158158
else
159159
iv_counter = src_sector_offset;
@@ -172,8 +172,8 @@ static int RAMFUNCTION wolfBoot_copy_sector(struct wolfBoot_image *src,
172172
while (pos < WOLFBOOT_SECTOR_SIZE) {
173173
if (src_sector_offset + pos <
174174
(src->fw_size + IMAGE_HEADER_SIZE + FLASHBUFFER_SIZE)) {
175-
/* bypass decryption, copy encrypted data into swap */
176-
if (dst->part == PART_SWAP) {
175+
/* bypass decryption, copy encrypted data into swap (and its external) */
176+
if (dst->part == PART_SWAP && SWAP_EXT) {
177177
ext_flash_read((uintptr_t)(src->hdr) + src_sector_offset + pos,
178178
(void *)buffer, FLASHBUFFER_SIZE);
179179
} else {

0 commit comments

Comments
 (0)