Skip to content

Fix STM32 CubeMX AES-GCM AAD over-read from HAL word reads (ST SA0076) - #11102

Open
dgarske wants to merge 1 commit into
wolfSSL:masterfrom
dgarske:stm32_sa0076
Open

Fix STM32 CubeMX AES-GCM AAD over-read from HAL word reads (ST SA0076)#11102
dgarske wants to merge 1 commit into
wolfSSL:masterfrom
dgarske:stm32_sa0076

Conversation

@dgarske

@dgarske dgarske commented Aug 6, 2026

Copy link
Copy Markdown
Member

Description

Fix STM32 CubeMX AES-GCM AAD over-read from HAL word reads (ST SA0076)

This fix mitigates an issue in the STM32Cube HAL CRYP driver (fixed in CubeU5 1.9.0 / HAL CRYP v1.6.3)

Fixes ZD 22274

Testing

Validated on hardware (NUCLEO-U385RG-Q with the CubeMX HAL crypto driver): AES-GCM known-answer tests with no AAD, 20-byte, 13-byte and 5-byte AAD all pass, byte-identical before and after the change.

Checklist

  • added tests
  • updated/added doxygen
  • updated appropriate READMEs
  • Updated manual and documentation

@dgarske dgarske self-assigned this Aug 6, 2026
Copilot AI lite review requested due to automatic review settings August 6, 2026 22:08

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.

Pull request overview

Warning

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Mitigates an STM32Cube HAL CRYP AES-GCM issue (ST SA0076) where AAD can be over-read due to HAL performing trailing 32-bit word reads, by ensuring the AAD buffer provided to HAL is word-padded without altering the GHASH length reported to the peripheral.

Changes:

  • Introduces STM_CRYPT_HEADER_PAD_WIDTH to express the HAL’s word read/pad granularity (default 4 bytes).
  • Updates STM32 AES-GCM encrypt/decrypt paths to allocate/copy a zero-padded AAD buffer sized to a word boundary while keeping the HAL-reported AAD length unchanged.
  • Adds cleanup to avoid leaking the allocated AAD buffer when the HW mutex lock fails.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
wolfssl/wolfcrypt/port/st/stm32.h Adds a configurable pad-width macro for STM32 HAL AAD word-padding behavior.
wolfcrypt/src/aes.c Pads AAD buffers up to word size for STM32 AES-GCM, and frees temp buffers on mutex-lock failure.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread wolfcrypt/src/aes.c
Comment on lines +11613 to +11625
/* The HAL reads the auth header a word at a time, including the trailing
* partial word, so the buffer handed to it has to be zero padded up to a
* word. authPadSz stays the length reported to the HAL, so the GHASH
* length block, and with it the hardware tag, does not change. */
authBufSz = authPadSz;
if (authBufSz < authInSz) {
authBufSz = authInSz;
}
if ((authBufSz % STM_CRYPT_HEADER_PAD_WIDTH) != 0) {
authBufSz += STM_CRYPT_HEADER_PAD_WIDTH -
(authBufSz % STM_CRYPT_HEADER_PAD_WIDTH);
}
if (authBufSz != authInSz) {
Comment thread wolfcrypt/src/aes.c
Comment on lines +10760 to +10771
/* The HAL reads the auth header a word at a time, including the trailing
* partial word, so the buffer handed to it has to be zero padded up to a
* word. authPadSz stays the length reported to the HAL, so the GHASH
* length block, and with it the hardware tag, does not change. */
authBufSz = authPadSz;
if (authBufSz < authInSz) {
authBufSz = authInSz;
}
if ((authBufSz % STM_CRYPT_HEADER_PAD_WIDTH) != 0) {
authBufSz += STM_CRYPT_HEADER_PAD_WIDTH -
(authBufSz % STM_CRYPT_HEADER_PAD_WIDTH);
}
Comment on lines +784 to +786
#ifndef STM_CRYPT_HEADER_PAD_WIDTH
#define STM_CRYPT_HEADER_PAD_WIDTH 4
#endif
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.

2 participants