Skip to content

Commit b07d99b

Browse files
dgarskedanielinux
authored andcommitted
Fix RX TSIP IV nonce. Adjust location of XALIGNED in declarations.
1 parent 7bc947d commit b07d99b

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
#if defined(WOLFBOOT_CERT_CHAIN_VERIFY) && \
5959
defined(WOLFBOOT_ENABLE_WOLFHSM_CLIENT)
@@ -813,7 +813,7 @@ uint16_t wolfBoot_get_header(struct wolfBoot_image *img, uint16_t type,
813813
}
814814

815815
#ifdef EXT_FLASH
816-
static uint8_t XALIGNED(4) ext_hash_block[WOLFBOOT_SHA_BLOCK_SIZE];
816+
static uint8_t ext_hash_block[WOLFBOOT_SHA_BLOCK_SIZE] XALIGNED(4);
817817
#endif
818818
/**
819819
* @brief Get a block of data to be hashed.
@@ -837,7 +837,7 @@ static uint8_t *get_sha_block(struct wolfBoot_image *img, uint32_t offset)
837837
}
838838

839839
#ifdef EXT_FLASH
840-
static uint8_t XALIGNED(4) hdr_cpy[IMAGE_HEADER_SIZE];
840+
static uint8_t hdr_cpy[IMAGE_HEADER_SIZE] XALIGNED(4);
841841
static int hdr_cpy_done = 0;
842842

843843
/**
@@ -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 XALIGNED(4) read_buf[WOLFBOOT_SHA_BLOCK_SIZE]; /* Use local buffer */
1568+
uint8_t read_buf[WOLFBOOT_SHA_BLOCK_SIZE] XALIGNED(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 XALIGNED(4) buffer[WOLFBOOT_SHA_BLOCK_SIZE];
1597+
uint8_t buffer[WOLFBOOT_SHA_BLOCK_SIZE] XALIGNED(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 XALIGNED(4) calc_digest[WOLFBOOT_SHA_DIGEST_SIZE];
1636+
uint8_t calc_digest[WOLFBOOT_SHA_DIGEST_SIZE] XALIGNED(4);
16371637
uint8_t* exp_digest;
16381638
int32_t stored_sha_len;
16391639
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)