Skip to content

Commit b79be86

Browse files
dgarskedanielinux
authored andcommitted
Fix for NO_SWAP_EXT=1 with encryption enabled. Peer review fixes.
1 parent bd179ed commit b79be86

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
@@ -1565,7 +1565,7 @@ static int update_hash_flash_fwimg(wolfBoot_hash_t* ctx,
15651565
{
15661566
uint32_t current_offset = offset;
15671567
uint32_t remaining_size = size;
1568-
uint8_t read_buf[WOLFBOOT_SHA_BLOCK_SIZE] XALIGNED(4); /* Use local buffer*/
1568+
uint8_t read_buf[WOLFBOOT_SHA_BLOCK_SIZE] XALIGNED_STACK(4); /* Use local buffer */
15691569

15701570
while (remaining_size > 0) {
15711571
uint32_t read_size = (remaining_size > WOLFBOOT_SHA_BLOCK_SIZE)
@@ -1594,7 +1594,7 @@ static int update_hash_flash_fwimg(wolfBoot_hash_t* ctx,
15941594
static int update_hash_flash_addr(wolfBoot_hash_t* ctx, uintptr_t addr,
15951595
uint32_t size, int src_ext)
15961596
{
1597-
uint8_t buffer[WOLFBOOT_SHA_BLOCK_SIZE] XALIGNED(4);
1597+
uint8_t buffer[WOLFBOOT_SHA_BLOCK_SIZE] XALIGNED_STACK(4);
15981598
uint32_t remaining_size = size;
15991599
uintptr_t current_addr = addr;
16001600

@@ -1633,7 +1633,7 @@ int wolfBoot_check_flash_image_elf(uint8_t part, unsigned long* entry_out)
16331633
size_t ph_size = 0;
16341634
size_t current_ph_offset = 0;
16351635
int64_t final_offset = -1;
1636-
uint8_t calc_digest[WOLFBOOT_SHA_DIGEST_SIZE] XALIGNED(4);
1636+
uint8_t calc_digest[WOLFBOOT_SHA_DIGEST_SIZE] XALIGNED_STACK(4);
16371637
uint8_t* exp_digest;
16381638
int32_t stored_sha_len;
16391639
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)