Skip to content

Add configurable IV length for AES-GCM benchmark - #549

Merged
bigbrett merged 1 commit into
wolfSSL:mainfrom
kojiws:add_bench_aes_gcm_iv_length
Oct 26, 2026
Merged

bigbrett merged 1 commit into
wolfSSL:mainfrom
kojiws:add_bench_aes_gcm_iv_length

Conversation

@kojiws

@kojiws kojiws commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Make the IV length used by the AES-GCM benchmarks configurable via a new macro, WOLFHSM_CFG_BENCH_AES_GCM_IV_SIZE. The IV length was previously fixed at 16 bytes (sizeof(iv)), which made it impossible to benchmark with the recommended 96-bit (12-byte) GCM nonce.

Changes

  • benchmark/bench_modules/wh_bench_mod_aes.c
    • Add WOLFHSM_CFG_BENCH_AES_GCM_IV_SIZE, defaulting to 12.
    • Reject values outside 1..16 with a compile-time #error. The bound is written as the literal 16 because WC_AES_BLOCK_SIZE is an enum and cannot be evaluated by the preprocessor.
    • Use the macro as the IV length in all four AES-GCM benchmark calls (standard and DMA, encrypt and decrypt).
    • The iv buffer itself stays WC_AES_BLOCK_SIZE bytes, since it is also passed to wc_AesSetIV(), which always reads a full block.
  • benchmark/README.md: document the new option.

Usage

/* wolfhsm_cfg.h */
#define WOLFHSM_CFG_BENCH_AES_GCM_IV_SIZE 16

or -DWOLFHSM_CFG_BENCH_AES_GCM_IV_SIZE=16 in the compiler flags.

Testing

Tested with wolfSSL v5.9.4-stable.

  • Default build (non-DMA): builds and runs; AES-GCM benchmarks work.
  • DMA=1 with IV size 12 and 16, run with --type dma: builds and runs with no failures, including the AES-GCM DMA benchmarks.
  • Compile-time check: -1, 0 and 17 fail with the expected #error; 1, 12 and 16 build.

Copilot AI balanced review requested due to automatic review settings October 26, 2026 02:19

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

The change consistently applies the validated IV length, preserves existing defaults and buffer safety, and has no identified blocking issues.

No open issues 🎉

What changed in this PR

This PR makes the AES-GCM benchmark IV length configurable, enabling 12-byte nonces while preserving the existing 16-byte default.

Changes:

  • Adds WOLFHSM_CFG_BENCH_AES_GCM_IV_SIZE with compile-time validation for values from 1 to 16.
  • Applies the setting to standard and DMA encryption/decryption benchmarks while retaining full-block IV buffers.
  • Documents the option and recommended 12-byte setting.
File Description
benchmark/​README.md Documents the IV length option, default, and supported range.
benchmark/​bench_modules/​wh_bench_mod_aes.c Defines and validates the option and uses it in all four AES-GCM benchmark calls.

Review effort: Balanced

@kojiws
kojiws force-pushed the add_bench_aes_gcm_iv_length branch from bfe225e to 7c15470 Compare October 26, 2026 02:35
@kojiws kojiws assigned kojiws and wolfSSL-Bot and unassigned kojiws Oct 26, 2026

@bigbrett bigbrett 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.

Great addition. I think we should just make the default 12 bytes too, and allow user to override if for some reason they want a slower implementation

Comment thread benchmark/bench_modules/wh_bench_mod_aes.c Outdated
@bigbrett bigbrett assigned kojiws and unassigned wolfSSL-Bot Oct 26, 2026
@kojiws
kojiws force-pushed the add_bench_aes_gcm_iv_length branch from 7c15470 to 6a4c89e Compare October 26, 2026 15:13
@kojiws kojiws removed their assignment Oct 26, 2026
@kojiws
kojiws requested a review from bigbrett October 26, 2026 15:27
@bigbrett bigbrett self-assigned this Oct 26, 2026

@bigbrett bigbrett 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.

thanks!

@bigbrett
bigbrett merged commit d57ab3b into wolfSSL:main Oct 26, 2026
26 checks passed
@kojiws
kojiws deleted the add_bench_aes_gcm_iv_length branch October 26, 2026 23:14
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.

4 participants