Skip to content

Commit f00a9c7

Browse files
committed
Fix RX TSIP IV nonce. Adjust location of XALIGNED in declarations.
1 parent 7246f8b commit f00a9c7

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

src/image.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
#endif
5454

5555
/* Globals */
56-
static uint8_t XALIGNED(4) digest[WOLFBOOT_SHA_DIGEST_SIZE];
56+
static uint8_t digest[WOLFBOOT_SHA_DIGEST_SIZE] XALIGNED(4);
5757

5858
/* TPM based verify */
5959
#if defined(WOLFBOOT_TPM) && defined(WOLFBOOT_TPM_VERIFY)
@@ -748,7 +748,7 @@ uint16_t wolfBoot_get_header(struct wolfBoot_image *img, uint16_t type,
748748
}
749749

750750
#ifdef EXT_FLASH
751-
static uint8_t XALIGNED(4) ext_hash_block[WOLFBOOT_SHA_BLOCK_SIZE];
751+
static uint8_t ext_hash_block[WOLFBOOT_SHA_BLOCK_SIZE] XALIGNED(4);
752752
#endif
753753
/**
754754
* @brief Get a block of data to be hashed.
@@ -772,7 +772,7 @@ static uint8_t *get_sha_block(struct wolfBoot_image *img, uint32_t offset)
772772
}
773773

774774
#ifdef EXT_FLASH
775-
static uint8_t XALIGNED(4) hdr_cpy[IMAGE_HEADER_SIZE];
775+
static uint8_t hdr_cpy[IMAGE_HEADER_SIZE] XALIGNED(4);
776776
static int hdr_cpy_done = 0;
777777

778778
/**
@@ -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 XALIGNED(4) read_buf[WOLFBOOT_SHA_BLOCK_SIZE]; /* Use local buffer */
1503+
uint8_t read_buf[WOLFBOOT_SHA_BLOCK_SIZE] XALIGNED(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 XALIGNED(4) buffer[WOLFBOOT_SHA_BLOCK_SIZE];
1532+
uint8_t buffer[WOLFBOOT_SHA_BLOCK_SIZE] XALIGNED(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 XALIGNED(4) calc_digest[WOLFBOOT_SHA_DIGEST_SIZE];
1571+
uint8_t calc_digest[WOLFBOOT_SHA_DIGEST_SIZE] XALIGNED(4);
15721572
uint8_t* exp_digest;
15731573
int32_t stored_sha_len;
15741574
int i;

src/libwolfboot.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464

6565
#if defined(EXT_ENCRYPTED)
6666
static int encrypt_initialized = 0;
67-
static uint8_t encrypt_iv_nonce[ENCRYPT_NONCE_SIZE];
67+
static uint8_t encrypt_iv_nonce[ENCRYPT_NONCE_SIZE] XALIGNED(4);
6868
#if defined(__WOLFBOOT)
6969
#include "encrypt.h"
7070
#elif !defined(XMEMSET)
@@ -1598,14 +1598,15 @@ int aes_init(void)
15981598
/* register AES crypto callback */
15991599
wc_CryptoCb_RegisterDevice(devId, wc_tsip_AesCipher, NULL);
16001600

1601-
encrypt_initialized = 1;
1602-
16031601
/* AES_ENCRYPTION is used for both directions in CTR */
16041602
/* unwrapped key never leaves TSIP and is referenced by tsip_keyIdx */
16051603
wc_AesSetKeyDirect(&aes_enc, enc_key->encrypted_user_key,
16061604
ENCRYPT_KEY_SIZE, enc_key->initial_vector, AES_ENCRYPTION);
16071605
wc_AesSetKeyDirect(&aes_dec, enc_key->encrypted_user_key,
16081606
ENCRYPT_KEY_SIZE, enc_key->initial_vector, AES_ENCRYPTION);
1607+
1608+
XMEMCPY(encrypt_iv_nonce, enc_key->initial_vector, ENCRYPT_NONCE_SIZE);
1609+
encrypt_initialized = 1;
16091610
}
16101611
#else
16111612

@@ -1825,8 +1826,8 @@ int RAMFUNCTION ext_flash_encrypt_write(uintptr_t address, const uint8_t *data,
18251826
*/
18261827
int RAMFUNCTION ext_flash_decrypt_read(uintptr_t address, uint8_t *data, int len)
18271828
{
1828-
uint8_t block[ENCRYPT_BLOCK_SIZE];
1829-
uint8_t dec_block[ENCRYPT_BLOCK_SIZE];
1829+
uint8_t block[ENCRYPT_BLOCK_SIZE] XALIGNED(4);
1830+
uint8_t dec_block[ENCRYPT_BLOCK_SIZE] XALIGNED(4);
18301831
uint32_t row_address = address, row_offset, iv_counter = 0;
18311832
int i;
18321833
int flash_read_size;

0 commit comments

Comments
 (0)