Skip to content

wolfSSL: document wolfCrypt structure alignment - #294

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

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

Conversation

@Frauschi

@Frauschi Frauschi commented Nov 3, 2026

Copy link
Copy Markdown
Member

Adds a "Structure Alignment" section to the wolfCrypt Usage Reference: when WOLFSSL_USE_ALIGN is defined, which structures need 16-byte or larger alignment, and what malloc() provides. A misaligned wc_Sha256 crashed curl's HMAC code on x86_64 (curl/curl#23690). The Japanese manual (wolfSSL/src-ja/chapter10.md) is not updated.

wolfSSL/wolfssl#11969 adds doxygen notes to the relevant wolfCrypt methods as well.

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.

🟡 Changes recommended

The alignment guidance omits matching header and library configurations, packed context risks, and 64-byte-aligned LMS/XMSS types.

3 open issues
What changed in this PR

This documentation-only PR adds structure-alignment guidance to the wolfCrypt Usage Reference, motivated by a misaligned wc_Sha256 crash in curl.

Changes:

  • Explains when WOLFSSL_USE_ALIGN is enabled and lists affected structures.
  • Describes allocation alignment limits and warns about contexts placed at arbitrary buffer offsets.
  • Updates only the English manual; the Japanese manual remains unchanged.
File Description
wolfSSL/​src/​chapter10.md Adds a Structure Alignment section covering configuration, affected types, and memory allocation guidance.

Review effort: Balanced

Comment thread wolfSSL/src/chapter10.md Resolved
Comment thread wolfSSL/src/chapter10.md Resolved
Comment thread wolfSSL/src/chapter10.md Resolved
Some wolfCrypt structures declare 16-byte or larger aligned members
when WOLFSSL_USE_ALIGN is defined, which configure and CMake builds do
by default, and need memory that meets that alignment. Add a short
section to the wolfCrypt Usage Reference that lists when the macro gets
defined, which structures it affects and what malloc() guarantees.

The section also asks applications to build against the same
configuration as the library (options.h or the same user_settings.h),
since a mismatch changes the layout regardless of allocation, and notes
that a packed enclosing structure can misalign a member. LmsState is
listed as a 64-byte case because wc_hss_verify() is public and takes a
caller-allocated state whose n-way members are ALIGN64 on x86_64 with
USE_INTEL_SPEEDUP or the SHAKE parameter sets. XmssState has the same
members but is only reachable through WOLFSSL_LOCAL functions.
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