From 715681057c15530dfb70180e27d64e99ac1a3075 Mon Sep 17 00:00:00 2001 From: night1rider Date: Wed, 2 Dec 2026 11:48:40 -0700 Subject: [PATCH 1/2] Add unit test exposing AES-CTR IV carry truncation in update_disk.c Reproduce the 32-bit IV carry drop in disk_crypto_set_iv() with real AES-256-CTR and wire the test into tools/unit-tests/Makefile. --- .gitignore | 1 + tools/unit-tests/Makefile | 11 +- .../unit-update-disk-aes-iv-carry.c | 392 ++++++++++++++++++ 3 files changed, 403 insertions(+), 1 deletion(-) create mode 100644 tools/unit-tests/unit-update-disk-aes-iv-carry.c diff --git a/.gitignore b/.gitignore index e58350d14b..76a2fe64ba 100644 --- a/.gitignore +++ b/.gitignore @@ -213,6 +213,7 @@ tools/unit-tests/unit-image-dts-sha3-384 tools/unit-tests/unit-store-sbrk tools/unit-tests/unit-tpm-blob tools/unit-tests/unit-update-disk +tools/unit-tests/unit-update-disk-aes-iv-carry tools/unit-tests/unit-policy-sign tools/unit-tests/unit-fdt tools/unit-tests/unit-hal-otp diff --git a/tools/unit-tests/Makefile b/tools/unit-tests/Makefile index 81c6cf0e5d..1d6ae7edc9 100644 --- a/tools/unit-tests/Makefile +++ b/tools/unit-tests/Makefile @@ -92,7 +92,7 @@ TESTS:=unit-parser unit-parser-large-header unit-fdt unit-extflash unit-string \ unit-update-flash-self-update-monolithic \ unit-nsc-update \ unit-update-flash-enc unit-update-flash-enc-cache unit-update-flash-enc-full unit-update-flash-enc-intswap unit-update-ram unit-update-ram-fit unit-update-ram-uboot unit-update-ram-enc unit-update-ram-enc-start unit-update-ram-enc-nopart unit-update-ram-nofixed unit-update-ram-nofixed-noramboot unit-update-ram-noramboot unit-update-ram-custom-trailer unit-update-ram-rollback-unconfirmed unit-compressed-tlv unit-custom-trailer-nopart unit-update-flash-hwswap unit-update-flash-custom-trailer unit-pkcs11_store unit-psa_store unit-wolfhsm_flash_hal unit-disk \ - unit-update-disk unit-update-disk-confirm unit-update-disk-golden unit-update-disk-failover unit-update-disk-golden-enckey unit-update-disk-fsp unit-update-disk-oob unit-update-disk-fit unit-update-disk-fit-ramdisk unit-multiboot unit-boot-x86-fsp unit-loader-tpm-init unit-qspi-flash unit-fwtpm-stub unit-tpm-rsa-exp \ + unit-update-disk unit-update-disk-confirm unit-update-disk-golden unit-update-disk-failover unit-update-disk-golden-enckey unit-update-disk-aes-iv-carry unit-update-disk-fsp unit-update-disk-oob unit-update-disk-fit unit-update-disk-fit-ramdisk unit-multiboot unit-boot-x86-fsp unit-loader-tpm-init unit-qspi-flash unit-fwtpm-stub unit-tpm-rsa-exp \ unit-image-nopart unit-image-sha384 unit-image-sha3-384 unit-image-dts \ unit-image-dts-sha384 unit-image-dts-sha3-384 unit-store-sbrk \ unit-tpm-blob unit-policy-create unit-policy-sign unit-rot-auth unit-sdhci-response-bits \ @@ -663,6 +663,9 @@ unit-update-disk-failover:CFLAGS+=-DMOCK_PARTITIONS -DPRINTF_ENABLED -DWOLFBOOT_ -DWOLFBOOT_ORIGIN=MOCK_ADDRESS_BOOT -DBOOTLOADER_PARTITION_SIZE=WOLFBOOT_PARTITION_SIZE unit-update-disk-golden-enckey:CFLAGS+=-DMOCK_PARTITIONS -DPRINTF_ENABLED -DWOLFBOOT_RAMBOOT_MAX_SIZE=0x400 \ -DWOLFBOOT_ORIGIN=MOCK_ADDRESS_BOOT -DBOOTLOADER_PARTITION_SIZE=WOLFBOOT_PARTITION_SIZE +unit-update-disk-aes-iv-carry:CFLAGS+=-DMOCK_PARTITIONS -DPRINTF_ENABLED -DWOLFBOOT_RAMBOOT_MAX_SIZE=0x400 \ + -DEXT_ENCRYPTED -DENCRYPT_WITH_AES256 -DWOLFSSL_AES_DIRECT -DWOLFSSL_AES_256 -DWOLFSSL_AES_COUNTER \ + -DWOLFBOOT_ORIGIN=MOCK_ADDRESS_BOOT -DBOOTLOADER_PARTITION_SIZE=WOLFBOOT_PARTITION_SIZE # Non-FSP disk-boot OOB regression (CRIT-03). WOLFBOOT_RAMBOOT_MAX_SIZE is the # cap the loader applies to the unauthenticated header fw_size before loading to # RAM, the same bound update_disk.c and update_ram.c enforce. @@ -1607,6 +1610,12 @@ unit-update-disk-failover: ../../include/target.h unit-update-disk-failover.c unit-update-disk-golden-enckey: ../../include/target.h unit-update-disk-golden-enckey.c gcc -o $@ unit-update-disk-golden-enckey.c $(CFLAGS) $(LDFLAGS) +unit-update-disk-aes-iv-carry: ../../include/target.h unit-update-disk-aes-iv-carry.c + gcc -o $@ unit-update-disk-aes-iv-carry.c \ + $(WOLFBOOT_LIB_WOLFSSL)/wolfcrypt/src/aes.c \ + $(WOLFBOOT_LIB_WOLFSSL)/wolfcrypt/src/memory.c \ + $(CFLAGS) $(LDFLAGS) + # WOLFBOOT_FSP (x86) boot path of update_disk.c: the low-memory (tolum) # size check must reject a slot and fall back to the other one, like every # other per-slot rejection in the retry loop. diff --git a/tools/unit-tests/unit-update-disk-aes-iv-carry.c b/tools/unit-tests/unit-update-disk-aes-iv-carry.c new file mode 100644 index 0000000000..90ac5c0624 --- /dev/null +++ b/tools/unit-tests/unit-update-disk-aes-iv-carry.c @@ -0,0 +1,392 @@ +/* unit-update-disk-aes-iv-carry.c + * + * Regression test for AES-CTR 128-bit IV carry propagation in + * src/update_disk.c (disk_crypto_set_iv()). + * + * tools/keytools/sign.c encrypts the manifest header and payload as a single + * continuous AES-CTR stream via wc_AesCtrEncrypt(), which increments the full + * 16-byte big-endian counter across word boundaries (matching aes_set_iv() in + * src/libwolfboot.c). When the low 32-bit word of the IV wraps across the + * header, disk_crypto_set_iv(IMAGE_HEADER_SIZE / ENCRYPT_BLOCK_SIZE) must + * propagate the carry into bytes 0..11 so payload decryption uses the same + * keystream as sign.c. + * + * Copyright (C) 2026 wolfSSL Inc. + * + * This file is part of wolfBoot. + * + * wolfBoot is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * wolfBoot is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA + */ + +#define WOLFBOOT_UPDATE_DISK +#define WOLFBOOT_SELF_UPDATE_MONOLITHIC +#define RAM_CODE +#define WOLFBOOT_SELF_HEADER +#define IMAGE_HEADER_SIZE 256 +#define BOOT_PART_A 0 +#define BOOT_PART_B 1 +#define MOCK_ADDRESS_BOOT 0xCD000000 + +#include +#include +#include +#include + +#include "hal.h" +#include "target.h" +#include "wolfboot/wolfboot.h" +#include "image.h" +#include "loader.h" +#include + +#define TEST_PAYLOAD_SIZE 64 +#define TEST_IMAGE_SIZE (IMAGE_HEADER_SIZE + TEST_PAYLOAD_SIZE) + +static uint8_t load_buffer[TEST_PAYLOAD_SIZE]; +#define WOLFBOOT_LOAD_ADDRESS ((uintptr_t)load_buffer) + +static uint8_t part_a_image[TEST_IMAGE_SIZE]; +static uint8_t part_b_image[TEST_IMAGE_SIZE]; +static uint8_t expected_payload[TEST_PAYLOAD_SIZE]; + +static const uint8_t test_key[ENCRYPT_KEY_SIZE] = { + 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, + 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, + 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, + 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F +}; +static uint8_t test_nonce[ENCRYPT_NONCE_SIZE]; + +static int mock_do_boot_called; +static const uint32_t *mock_boot_address; + +Aes aes_dec; +Aes aes_enc; + +static void set_u16_le(uint8_t *dst, uint16_t value) +{ + dst[0] = (uint8_t)(value & 0xFFU); + dst[1] = (uint8_t)(value >> 8); +} + +static void set_u32_le(uint8_t *dst, uint32_t value) +{ + dst[0] = (uint8_t)(value & 0xFFU); + dst[1] = (uint8_t)((value >> 8) & 0xFFU); + dst[2] = (uint8_t)((value >> 16) & 0xFFU); + dst[3] = (uint8_t)(value >> 24); +} + +/* Build a signed-style image and encrypt header + payload in one continuous + * AES-256-CTR pass via wc_AesCtrEncrypt(), matching tools/keytools/sign.c. */ +static void build_encrypted_image(uint8_t *dst, uint32_t version, + const uint8_t *nonce) +{ + uint8_t plain[TEST_IMAGE_SIZE]; + Aes aes_e; + size_t i; + int ret; + + memset(plain, 0xFF, sizeof(plain)); + set_u32_le(plain, WOLFBOOT_MAGIC); + set_u32_le(plain + sizeof(uint32_t), TEST_PAYLOAD_SIZE); + set_u16_le(plain + IMAGE_HEADER_OFFSET, HDR_VERSION); + set_u16_le(plain + IMAGE_HEADER_OFFSET + sizeof(uint16_t), 4); + set_u32_le(plain + IMAGE_HEADER_OFFSET + 2 * sizeof(uint16_t), version); + + for (i = 0; i < TEST_PAYLOAD_SIZE; i++) { + expected_payload[i] = (uint8_t)(0x10U + i); + } + memcpy(plain + IMAGE_HEADER_SIZE, expected_payload, TEST_PAYLOAD_SIZE); + + ret = wc_AesInit(&aes_e, NULL, INVALID_DEVID); + ck_assert_int_eq(ret, 0); + ret = wc_AesSetKeyDirect(&aes_e, test_key, ENCRYPT_KEY_SIZE, nonce, + AES_ENCRYPTION); + ck_assert_int_eq(ret, 0); + ret = wc_AesCtrEncrypt(&aes_e, dst, plain, TEST_IMAGE_SIZE); + ck_assert_int_eq(ret, 0); + wc_AesFree(&aes_e); +} + +static void reset_mocks(const uint8_t *nonce) +{ + memcpy(test_nonce, nonce, ENCRYPT_NONCE_SIZE); + memset(load_buffer, 0, sizeof(load_buffer)); + memset(part_a_image, 0, sizeof(part_a_image)); + memset(part_b_image, 0, sizeof(part_b_image)); + build_encrypted_image(part_a_image, 2, test_nonce); + mock_do_boot_called = 0; + mock_boot_address = NULL; + wolfBoot_panicked = 0; +} + +int aes_init(void) +{ + int ret; + + ret = wc_AesInit(&aes_dec, NULL, INVALID_DEVID); + if (ret != 0) + return -1; + ret = wc_AesSetKeyDirect(&aes_dec, test_key, ENCRYPT_KEY_SIZE, NULL, + AES_ENCRYPTION); + if (ret != 0) + return -1; + return 0; +} + +int wolfBoot_initialize_encryption(void) +{ + return aes_init(); +} + +int wolfBoot_get_encrypt_key(uint8_t *key, uint8_t *nonce) +{ + memcpy(key, test_key, ENCRYPT_KEY_SIZE); + memcpy(nonce, test_nonce, ENCRYPT_NONCE_SIZE); + return 0; +} + +int disk_init(int drv) +{ + (void)drv; + return 0; +} + +int disk_open(int drv) +{ + (void)drv; + return 0; +} + +void disk_close(int drv) +{ + (void)drv; +} + +int disk_part_read(int drv, int part, uint64_t off, uint64_t sz, uint8_t *buf) +{ + const uint8_t *image; + + (void)drv; + image = (part == BOOT_PART_B) ? part_b_image : part_a_image; + if ((off > TEST_IMAGE_SIZE) || (sz > (TEST_IMAGE_SIZE - off))) + return -1; + memcpy(buf, image + off, (size_t)sz); + return (int)sz; +} + +int wolfBoot_open_image_address(struct wolfBoot_image *img, uint8_t *image) +{ + uint32_t magic; + uint32_t fw_size; + + memcpy(&magic, image, sizeof(magic)); + if (magic != WOLFBOOT_MAGIC) + return -1; + memset(img, 0, sizeof(*img)); + img->hdr = image; + memcpy(&fw_size, image + sizeof(uint32_t), sizeof(fw_size)); + img->fw_size = fw_size; + img->fw_base = image + IMAGE_HEADER_SIZE; + img->hdr_ok = 1; + return 0; +} + +int wolfBoot_verify_integrity(struct wolfBoot_image *img) +{ + if (memcmp(img->fw_base, expected_payload, TEST_PAYLOAD_SIZE) != 0) + return -1; + img->sha_ok = 1; + return 0; +} + +int wolfBoot_verify_authenticity(struct wolfBoot_image *img) +{ + img->signature_ok = 1; + return 0; +} + +int wolfBoot_image_part_matches(struct wolfBoot_image *img) +{ + (void)img; + return 0; +} + +int wolfBoot_get_dts_size(void *dts_addr, uint32_t capacity) +{ + (void)dts_addr; + (void)capacity; + return -1; +} + +void hal_prepare_boot(void) +{ +} + +void do_boot(const uint32_t *address) +{ + mock_do_boot_called++; + mock_boot_address = address; +} + +int hal_flash_protect(haladdr_t address, int len) +{ + (void)address; + (void)len; + return 0; +} + +#include "update_disk.c" + +/* Verify that disk_crypto_set_iv(block_offset) produces the exact same + * AES-256-CTR keystream block as initializing wolfCrypt directly with + * expected_iv. */ +static void assert_iv_offset_matches(const uint8_t *base_iv, + uint32_t block_offset, const uint8_t *expected_iv) +{ + static const uint8_t zeros[ENCRYPT_BLOCK_SIZE] = { 0 }; + uint8_t got[ENCRYPT_BLOCK_SIZE]; + uint8_t want[ENCRYPT_BLOCK_SIZE]; + Aes ref; + + ck_assert_int_eq(aes_init(), 0); + memcpy(disk_encrypt_nonce, base_iv, ENCRYPT_NONCE_SIZE); + disk_crypto_set_iv(block_offset); + ck_assert_int_eq(wc_AesCtrEncrypt(&aes_dec, got, zeros, sizeof(zeros)), 0); + + ck_assert_int_eq(wc_AesInit(&ref, NULL, INVALID_DEVID), 0); + ck_assert_int_eq(wc_AesSetKeyDirect(&ref, test_key, ENCRYPT_KEY_SIZE, + expected_iv, AES_ENCRYPTION), 0); + ck_assert_int_eq(wc_AesCtrEncrypt(&ref, want, zeros, sizeof(zeros)), 0); + wc_AesFree(&ref); + + ck_assert_mem_eq(got, want, sizeof(want)); +} + +START_TEST(test_aes256_boot_non_wrapping_iv) +{ + const uint8_t nonce[ENCRYPT_NONCE_SIZE] = { + 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, + 0x88, 0x99, 0xAA, 0xBB, 0x00, 0x00, 0x00, 0x00 + }; + + reset_mocks(nonce); + wolfBoot_start(); + + ck_assert_int_eq(wolfBoot_panicked, 0); + ck_assert_int_eq(mock_do_boot_called, 1); + ck_assert_ptr_eq(mock_boot_address, (const uint32_t *)load_buffer); + ck_assert_mem_eq(load_buffer, expected_payload, TEST_PAYLOAD_SIZE); +} +END_TEST + +START_TEST(test_aes256_boot_iv_carry_across_word_boundary) +{ + /* Low 32-bit word is 0xFFFFFFFA. Header is 256 bytes (16 blocks), so + * wc_AesCtrEncrypt() carries into byte 11 (0xBB -> 0xBC) during the + * header and encrypts payload block 0 at counter ...AA BC 00 00 00 0A. */ + const uint8_t nonce[ENCRYPT_NONCE_SIZE] = { + 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, + 0x88, 0x99, 0xAA, 0xBB, 0xFF, 0xFF, 0xFF, 0xFA + }; + + reset_mocks(nonce); + wolfBoot_start(); + + ck_assert_int_eq(wolfBoot_panicked, 0); + ck_assert_int_eq(mock_do_boot_called, 1); + ck_assert_ptr_eq(mock_boot_address, (const uint32_t *)load_buffer); + ck_assert_mem_eq(load_buffer, expected_payload, TEST_PAYLOAD_SIZE); +} +END_TEST + +START_TEST(test_aes256_boot_iv_carry_full_128bit_wrap) +{ + /* All 128 bits carry and wrap around to 00..00 08 after 16 header + * blocks. */ + const uint8_t nonce[ENCRYPT_NONCE_SIZE] = { + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xF8 + }; + + reset_mocks(nonce); + wolfBoot_start(); + + ck_assert_int_eq(wolfBoot_panicked, 0); + ck_assert_int_eq(mock_do_boot_called, 1); + ck_assert_ptr_eq(mock_boot_address, (const uint32_t *)load_buffer); + ck_assert_mem_eq(load_buffer, expected_payload, TEST_PAYLOAD_SIZE); +} +END_TEST + +START_TEST(test_disk_crypto_set_iv_carry_multi_word) +{ + const uint8_t base_mid[ENCRYPT_NONCE_SIZE] = { + 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xF0 + }; + const uint8_t exp_mid[ENCRYPT_NONCE_SIZE] = { + 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x08, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 + }; + const uint8_t base_all_ff[ENCRYPT_NONCE_SIZE] = { + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF + }; + const uint8_t exp_all_zero[ENCRYPT_NONCE_SIZE] = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 + }; + const uint8_t base_max_off[ENCRYPT_NONCE_SIZE] = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01 + }; + const uint8_t exp_max_off[ENCRYPT_NONCE_SIZE] = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00 + }; + + assert_iv_offset_matches(base_mid, 16, exp_mid); + assert_iv_offset_matches(base_all_ff, 1, exp_all_zero); + assert_iv_offset_matches(base_max_off, 0xFFFFFFFFU, exp_max_off); +} +END_TEST + +Suite *wolfboot_suite(void) +{ + Suite *s = suite_create("wolfBoot"); + TCase *tc = tcase_create("update-disk-aes-iv-carry"); + + tcase_add_test(tc, test_aes256_boot_non_wrapping_iv); + tcase_add_test(tc, test_aes256_boot_iv_carry_across_word_boundary); + tcase_add_test(tc, test_aes256_boot_iv_carry_full_128bit_wrap); + tcase_add_test(tc, test_disk_crypto_set_iv_carry_multi_word); + + suite_add_tcase(s, tc); + return s; +} + +int main(void) +{ + int fails; + Suite *s = wolfboot_suite(); + SRunner *sr = srunner_create(s); + + srunner_run_all(sr, CK_NORMAL); + fails = srunner_ntests_failed(sr); + srunner_free(sr); + return fails; +} From 1d811020df0584572bff31b9900952988695aa19 Mon Sep 17 00:00:00 2001 From: night1rider Date: Wed, 2 Dec 2026 11:48:41 -0700 Subject: [PATCH 2/2] Fix AES-CTR 128-bit IV carry propagation in update_disk.c Propagate carry branch-free across all 16 bytes of the big-endian AES-CTR IV in disk_crypto_set_iv(), matching aes_set_iv(). --- src/update_disk.c | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/src/update_disk.c b/src/update_disk.c index 684f609271..99e64e2a5d 100644 --- a/src/update_disk.c +++ b/src/update_disk.c @@ -287,25 +287,30 @@ static void disk_crypto_set_iv(uint32_t block_offset) #if defined(ENCRYPT_WITH_CHACHA) wc_Chacha_SetIV(&chacha, disk_encrypt_nonce, block_offset); #elif defined(ENCRYPT_WITH_AES128) || defined(ENCRYPT_WITH_AES256) - /* For AES CTR, we need to construct the IV with the counter. - * The sign tool uses the IV directly without byte-reversal, - * so we must match that behavior here. */ + /* For AES-CTR, wolfCrypt (and tools/keytools/sign.c) increments the full + * 128-bit big-endian counter across all 16 bytes. Add block_offset with + * an unconditional, branch-free carry across all four 32-bit big-endian + * words (matching aes_set_iv() in src/libwolfboot.c). */ uint8_t iv[ENCRYPT_BLOCK_SIZE]; - uint32_t ctr; + uint32_t word, prev, carry; + int i; - /* Copy nonce/IV (first 12 bytes for CTR nonce, last 4 for counter) */ memcpy(iv, disk_encrypt_nonce, ENCRYPT_NONCE_SIZE); - /* Add block offset to the counter portion (last 4 bytes, big-endian) */ - /* The IV from sign.c is already in the correct format, we just need - * to add the block offset to the counter portion */ - ctr = ((uint32_t)iv[12] << 24) | ((uint32_t)iv[13] << 16) | - ((uint32_t)iv[14] << 8) | (uint32_t)iv[15]; - ctr += block_offset; - iv[12] = (uint8_t)(ctr >> 24); - iv[13] = (uint8_t)(ctr >> 16); - iv[14] = (uint8_t)(ctr >> 8); - iv[15] = (uint8_t)(ctr); + carry = block_offset; + for (i = 3; i >= 0; i--) { + int off = i * 4; + prev = ((uint32_t)iv[off] << 24) | + ((uint32_t)iv[off + 1] << 16) | + ((uint32_t)iv[off + 2] << 8) | + ((uint32_t)iv[off + 3]); + word = prev + carry; + carry = (uint32_t)(word < prev); + iv[off] = (uint8_t)(word >> 24); + iv[off + 1] = (uint8_t)(word >> 16); + iv[off + 2] = (uint8_t)(word >> 8); + iv[off + 3] = (uint8_t)(word); + } wc_AesSetIV(&aes_dec, iv); /* Scrub the stack copy: the counter bytes are derived from the