mirror of https://github.com/wolfSSL/wolfBoot.git
Both partial-block read-modify-write paths in ext_flash_encrypt_write read the stored block (ciphertext), spliced the new plaintext in, and re-encrypted the whole block. The untouched bytes were therefore XOR'd with the keystream a second time: stored ciphertext came back as plaintext in flash, and the next read of those bytes returned raw ciphertext instead of the original data. Any encrypted update whose first or last block partially overlaps a block with previous content - e.g. a retry over a previously written update image - silently corrupted the neighbouring bytes. Decrypt the stored block before splicing (into the scratch buffer, so no backend has to handle in-place decrypt) and re-encrypt the merged plaintext. Erased (0xFF) bytes round-trip unchanged because the decrypt/encrypt pair is the identity on the stored value. The re-encryption re-syncs the stream to the block index first: the decrypt step consumes keystream, and on the ChaCha/PKCS#11 backends encrypt and decrypt share a single stream state, while on the AES backends the decrypt context had not advanced with the full-block writes. The tail path also syncs the decrypt context, which on the AES backends sits at the first block's index after the aligned writes. Fallback-IV offset handling mirrors ext_flash_decrypt_read. New unit-extflash tests (run under the plain, AES-128, AES-256 and ChaCha20 variants): a mid-block patch must leave the untouched bytes of a previously written block intact, a trailing partial block must leave the rest of a previously written block intact, and a stream written in small unaligned chunks must round-trip byte for byte. All three fail on the pre-fix code with every cipher. |
||
|---|---|---|
| .. | ||
| dice | ||
| x86 | ||
| arm_tee_psa_ipc.c | ||
| arm_tee_psa_veneer.c | ||
| boot_aarch64.c | ||
| boot_aarch64_efi.c | ||
| boot_aarch64_start.S | ||
| boot_arm.c | ||
| boot_arm32.c | ||
| boot_arm32_start.S | ||
| boot_ppc.c | ||
| boot_ppc_mp.S | ||
| boot_ppc_start.S | ||
| boot_renesas.c | ||
| boot_renesas_start.S | ||
| boot_riscv.c | ||
| boot_riscv_start.S | ||
| boot_x86_64.c | ||
| boot_x86_fsp.c | ||
| boot_x86_fsp_payload.c | ||
| boot_x86_fsp_start.S | ||
| clang_sections.S | ||
| ddr_cadence.c | ||
| delta.c | ||
| disk.c | ||
| elf.c | ||
| fdt.c | ||
| flash_otp_keystore.c | ||
| fwtpm_callable.c | ||
| gpt.c | ||
| gzip.c | ||
| image.c | ||
| libwolfboot.c | ||
| loader.c | ||
| multiboot.c | ||
| pci.c | ||
| pkcs11_callable.c | ||
| pkcs11_store.c | ||
| psa_store.c | ||
| qspi_flash.c | ||
| riscv_sbi.c | ||
| sdhci.c | ||
| spi_flash.c | ||
| stage2_params.c | ||
| store_sbrk.c | ||
| store_sbrk.h | ||
| string.c | ||
| tpm.c | ||
| uart_flash.c | ||
| update_disk.c | ||
| update_flash.c | ||
| update_flash_hwswap.c | ||
| update_ram.c | ||
| vector_riscv.S | ||
| wc_callable.c | ||
| wolfhsm_callable.c | ||
| wolfhsm_flash_hal.c | ||
| xmalloc.c | ||