Skip to content

doc: note the alignment of wolfCrypt context structures - #11969

Open
Frauschi wants to merge 1 commit into
wolfSSL:masterfrom
Frauschi:doc-struct-alignment
Open

Frauschi wants to merge 1 commit into
wolfSSL:masterfrom
Frauschi:doc-struct-alignment

Conversation

@Frauschi

@Frauschi Frauschi commented Nov 3, 2026 •

Copy link
Copy Markdown
Member

Several wolfCrypt context structures need 16-byte alignment when WOLFSSL_USE_ALIGN is defined, which configure and CMake builds do by default, but the API docs never said so. curl's HMAC code placed a wc_Sha256 8 bytes off a 16-byte boundary and crashed on x86_64 (curl/curl#23690).

Changes:

  • Add an alignment \note to the SHA-256/224, HMAC, AES, Curve25519 and Ed25519 init docs
  • Add the missing doxygen entry for wc_HmacInit()

wolfSSL/documentation#294 adds these requirements to the documentation as well.

@Frauschi Frauschi self-assigned this Nov 3, 2026
Copilot AI balanced review requested due to automatic review settings November 3, 2026 10:09

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues are recorded for this documentation-only update clarifying wolfCrypt context alignment requirements.

No open issues 🎉

What changed in this PR

This documentation-only PR clarifies wolfCrypt context alignment requirements to help integrations avoid misaligned allocations, motivated by the reported curl HMAC crash.

Changes:

  • Add alignment notes to SHA-256/224, HMAC, AES, Curve25519, and Ed25519 initialization documentation.
  • Document wc_HmacInit() parameters, return values, usage, and cleanup, and link it from wc_HmacSetKey().
File Description
doc/​dox_comments/​header_files/​sha256.h Add alignment notes for SHA-256 and SHA-224 initialization.
doc/​dox_comments/​header_files/​hmac.h Add wc_HmacInit() documentation, alignment guidance, and a cross-reference.
doc/​dox_comments/​header_files/​ed25519.h Document alignment for Ed25519 key initialization.
doc/​dox_comments/​header_files/​curve25519.h Document alignment for Curve25519 key initialization.
doc/​dox_comments/​header_files/​aes.h Document AES alignment, including the Xilinx Versal exception.

Review effort: Balanced

wc_Sha256, wc_Sha224, Hmac, Aes, curve25519_key and ed25519_key declare
16-byte aligned members, directly or through an embedded context, so
the structures themselves need 16-byte alignment when WOLFSSL_USE_ALIGN
is defined. configure (--enable-aligndata) and CMake
(WOLFSSL_ALIGN_DATA) define it by default, and types.h forces it for
AES-NI, Intel speedups, ARM assembly, Xilinx and 32-bit ARM without
unaligned access. For the SHA-256 context and Hmac this applies on
64-bit CPUs, unless a hardware port replaces the software hash state.
On Xilinx Versal, Aes needs 64-byte alignment. The compiler may use
aligned loads and stores on these structures, so an instance placed at
an arbitrary offset inside a larger buffer can crash, as seen with
wc_Sha256 contexts in curl's HMAC code on x86_64.

Add a note to the init functions of these structures: wc_InitSha256(),
wc_InitSha224() and their _ex variants, wc_AesInit(), and
wc_curve25519_init() and wc_ed25519_init() with their _ex variants.
wc_HmacInit() had no doxygen entry, so add one to carry the Hmac note,
and reference it from wc_HmacSetKey().
@Frauschi
Frauschi force-pushed the doc-struct-alignment branch from 9139767 to f26f4ee Compare November 3, 2026 18:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants