Skip to content

Commit

Permalink
Merge pull request #245 from danielinux/fix-encrypted-delta
Browse files Browse the repository at this point in the history
Fixed bug in encrypted-delta update
  • Loading branch information
rizlik authored Oct 24, 2022
2 parents 9690327 + 95b35e6 commit 83dc546
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
5 changes: 4 additions & 1 deletion src/spi_flash.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ static int RAMFUNCTION spi_flash_write_page(uint32_t address, const void *data,
{
const uint8_t *buf = data;
int j = 0;
if (len < 1)
return -1;
while (len > 0) {
wait_busy();
flash_write_enable();
Expand All @@ -129,14 +131,15 @@ static int RAMFUNCTION spi_flash_write_page(uint32_t address, const void *data,
spi_cs_off(SPI_CS_FLASH);
}
wait_busy();
return j;
return 0;
}

static int RAMFUNCTION spi_flash_write_sb(uint32_t address, const void *data, int len)
{
const uint8_t *buf = data;
uint8_t verify = 0;
int j = 0;

wait_busy();
if (len < 1)
return -1;
Expand Down
4 changes: 2 additions & 2 deletions src/uart_flash.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ int ext_flash_write(uintptr_t address, const uint8_t *data, int len)
if (wait_ack() != 0)
return -1;
}
return i;
return 0;
}

int ext_flash_read(uintptr_t address, uint8_t *data, int len)
Expand All @@ -118,7 +118,7 @@ int ext_flash_read(uintptr_t address, uint8_t *data, int len)
return 0;
uart_tx(CMD_ACK);
}
return len;
return 0;
}

int ext_flash_erase(uintptr_t address, int len)
Expand Down
9 changes: 7 additions & 2 deletions src/update_flash.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ static void RAMFUNCTION wolfBoot_self_update(struct wolfBoot_image *src)
while (pos < src->fw_size) {
uint8_t buffer[FLASHBUFFER_SIZE];
if (src_offset + pos < (src->fw_size + IMAGE_HEADER_SIZE + FLASHBUFFER_SIZE)) {
uint32_t opos = pos + ((uint32_t)&_start_text);
uint32_t opos = pos + ((uint32_t)&_start_text);
ext_flash_check_read((uintptr_t)(src->hdr) + src_offset + pos, (void *)buffer, FLASHBUFFER_SIZE);
hal_flash_write(opos, buffer, FLASHBUFFER_SIZE);
}
Expand Down Expand Up @@ -254,13 +254,18 @@ static int wolfBoot_delta_update(struct wolfBoot_image *boot,
if (ret > 0) {
#ifdef EXT_ENCRYPTED
uint32_t iv_counter = sector * WOLFBOOT_SECTOR_SIZE + len;
int wr_ret;
iv_counter /= ENCRYPT_BLOCK_SIZE;
/* Encrypt + send */
crypto_set_iv(nonce, iv_counter);
crypto_encrypt(enc_blk, delta_blk, ret);
ret = ext_flash_write(
wr_ret = ext_flash_write(
(uint32_t)(WOLFBOOT_PARTITION_SWAP_ADDRESS + len),
enc_blk, ret);
if (wr_ret < 0) {
ret = wr_ret;
goto out;
}
#else
wb_flash_write(swap, len, delta_blk, ret);
#endif
Expand Down

0 comments on commit 83dc546

Please sign in to comment.