From a23e2f89be7a084b3b9d65edee54f3bc5c277a21 Mon Sep 17 00:00:00 2001 From: Koji Takeda Date: Wed, 28 Oct 2026 13:36:45 +0900 Subject: [PATCH] Add WOLFHSM_CFG_FLASH_UNIT_NO_ALIGN8_CHECK to skip the flash unit alignment check --- wolfhsm/wh_flash_unit.h | 4 ++++ wolfhsm/wh_settings.h | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/wolfhsm/wh_flash_unit.h b/wolfhsm/wh_flash_unit.h index 03ec9fe73..116312c89 100644 --- a/wolfhsm/wh_flash_unit.h +++ b/wolfhsm/wh_flash_unit.h @@ -65,17 +65,21 @@ typedef union whFlashUnit_t { #define WHFU_BYTES_PER_UNIT sizeof(whFlashUnit) /* Reject unsupported layouts at compile time. */ +#ifndef WOLFHSM_CFG_FLASH_UNIT_NO_ALIGN8_CHECK struct whFlashUnitAlignmentCheck { uint8_t byte; whFlashUnit unit; }; +#endif WH_UTILS_STATIC_ASSERT(sizeof(whFlashUnit) == WOLFHSM_CFG_FLASH_UNIT_SIZE, "whFlashUnit size mismatch"); +#ifndef WOLFHSM_CFG_FLASH_UNIT_NO_ALIGN8_CHECK WH_UTILS_STATIC_ASSERT( (offsetof(struct whFlashUnitAlignmentCheck, unit) >= 8) && ((offsetof(struct whFlashUnitAlignmentCheck, unit) % 8) == 0), "whFlashUnit must be aligned to 8 bytes"); +#endif #define WHFU_BYTES2UNITS(_b) (((_b) / WHFU_BYTES_PER_UNIT) + \ !!((_b) % WHFU_BYTES_PER_UNIT)) diff --git a/wolfhsm/wh_settings.h b/wolfhsm/wh_settings.h index 5381eb014..e1ef3bc07 100644 --- a/wolfhsm/wh_settings.h +++ b/wolfhsm/wh_settings.h @@ -127,6 +127,12 @@ * WH_ALIGN8 - Compiler-specific 8-byte alignment attribute. * Default: Detected from the compiler * + * WOLFHSM_CFG_FLASH_UNIT_NO_ALIGN8_CHECK - If defined, skip the compile-time + * check that whFlashUnit is 8-byte aligned. The size check is still enforced. + * When this option is defined, whFlashUnit may be less than 8-byte aligned, + * so the flash callbacks must not assume 8-byte aligned buffers. + * Default: Not defined + * * WOLFHSM_CFG_NVM_FLASH_CRC16 - If defined, the nvm_flash backend stores a * CRC16 of each object's metadata and data in the on-flash object state and * verifies them: metadata when the directory is loaded, data on full-object