Skip to content

Add experimental HQC KEM (v5.1) to wolfCrypt - #12394

Open
SparkiDev wants to merge 1 commit into
wolfSSL:masterfrom
SparkiDev:hqc
Open

SparkiDev wants to merge 1 commit into
wolfSSL:masterfrom
SparkiDev:hqc

Conversation

@SparkiDev

@SparkiDev SparkiDev commented Dec 4, 2026 •

Copy link
Copy Markdown
Contributor

Description

Implement HQC-1, HQC-3 and HQC-5 (HQC specification v5.1) with an API like ML-KEM's: wc_HqcKey_* for key generation, encapsulation, decapsulation and encoding/decoding. HQC is experimental: it is built only with --enable-experimental --enable-hqc[=options], never by --enable-all.

  • wc_hqc.c: constant-time portable C, with build options for size and speed (small, small-mem, cache-h, lazy-hek, no-cache-y, ...) and for compiling out key generation, encapsulation or decapsulation.
  • wc_hqc_asm.S/.asm: x86_64 assembly (PCLMULQDQ, VPCLMULQDQ, AVX2, AVX-512, GFNI, BMI), chosen at run time from CPU features. Encapsulation and decapsulation run several SHAKE sponges together on the 4-way and 8-way Keccak assembly.
  • cpuid: detect PCLMULQDQ, VPCLMULQDQ and GFNI.
  • Regenerated MSVC assembly: an element of a constant table is now read from the table, not from the pointer next to it (AES, AES-GCM, X25519).
  • Build: configure, CMake, Visual Studio projects, linuxkm.
  • Tests: known-answer tests repeated on each CPU path in testwolfcrypt, API tests, Reed-Solomon and fault-injection white-boxes, pq-all CI configs and a white-box CI step.
  • Benchmark: -hqc, with all-zero seeds without an RNG or with WOLFSSL_HQC_BENCH_DETERMINISTIC.
  • Docs: Doxygen (English and Japanese), ALGORITHM_DEFINES.md, ASM_AND_MATH_DEFINES.md, ChangeLog.

Testing

./configure --disable-shared --enable-hqc --enable-experimental
./configure --disable-shared --enable-hqc --enable-experimental --enable-intelasm
--enable-hqc => lazy-hek/no-cache-y/no-cache-hek/no-make-key/no-encapsulate/no-decapsulate/small/small-mem/no-large-code/1/3/5

Generator

https://github.com/wolfSSL/scripts/pull/738

@SparkiDev SparkiDev self-assigned this Dec 4, 2026
Copilot AI balanced review requested due to automatic review settings December 4, 2026 01:13
@SparkiDev

Copy link
Copy Markdown
Contributor Author

Code generated with:
https://github.com/wolfSSL/scripts/pull/738

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

HQC static-memory bucket sizing can break key generation and decapsulation, while benchmark error handling and test cleanup can use uninitialized state or skip required teardown.

4 open issues
What changed in this PR

Adds experimental HQC v5.1 support to wolfCrypt, with an ML-KEM-style API and explicit opt-in configuration.

Changes:

  • Integrates HQC parameter sets, build options, CPU dispatch, and benchmarks.
  • Adds known-answer, API, error-correction, and fault-injection tests.
  • Documents HQC and corrects MSVC assembly constant-table reads.
File Description
wolfssl/​wolfcrypt/​wc_hqc.h Defines HQC parameters and public API.
wolfssl/​wolfcrypt/​memory.h Adds larger HQC memory buckets.
wolfssl/​wolfcrypt/​include.am Installs the HQC header.
wolfssl/​wolfcrypt/​cpuid.h Defines additional CPU feature flags.
wolfssl.vcxproj Adds HQC Windows build inputs.
wolfssl-VS2022.vcxproj Adds HQC VS2022 build inputs.
wolfcrypt/​test/​test.h Declares HQC self-tests.
wolfcrypt/​test/​test.c Adds HQC known-answer and CPU-path tests.
wolfcrypt/​src/​sha3_asm.S Enables parallel Keccak for HQC.
wolfcrypt/​src/​sha3_asm.asm Enables parallel Keccak in MSVC builds.
wolfcrypt/​src/​include.am Distributes HQC MSVC assembly.
wolfcrypt/​src/​fe_x25519_asm.asm Corrects X25519 constant-table reads.
wolfcrypt/​src/​cpuid.c Detects HQC acceleration features.
wolfcrypt/​src/​aes_x86_64_asm.asm Corrects AES counter-table reads.
wolfcrypt/​src/​aes_gcm_asm.asm Corrects AES-GCM-SIV table reads.
wolfcrypt/​benchmark/​benchmark.h Declares HQC benchmarks.
wolfcrypt/​benchmark/​benchmark.c Adds HQC benchmark options and routines.
tests/​unit-mcdc/​test_wc_hqc_whitebox.c Tests Reed-Solomon error correction.
tests/​unit-mcdc/​test_hqc_fault_whitebox.c Tests allocation and hashing failures.
tests/​unit-mcdc/​smoke-expected.txt Registers HQC white-box tests.
tests/​include.am Distributes HQC white-box tests.
tests/​api/​test_hqc.h Declares HQC API tests.
tests/​api/​test_hqc.c Tests HQC API behavior.
tests/​api/​include.am Builds and distributes API tests.
tests/​api.c Registers HQC test cases.
src/​include.am Adds conditional HQC library sources.
linuxkm/​module_exports.c.template Includes HQC declarations for exports.
linuxkm/​Kbuild Configures HQC kernel assembly builds.
doc/​dox_comments/​header_files/​wc_hqc.h Documents the English HQC API.
doc/​dox_comments/​header_files/​doxygen_groups.h Adds the English HQC group.
doc/​dox_comments/​header_files-ja/​wc_hqc.h Documents the Japanese HQC API.
doc/​dox_comments/​header_files-ja/​doxygen_groups.h Adds the Japanese HQC group.
doc/​ASM_AND_MATH_DEFINES.md Lists HQC Intel acceleration.
doc/​ALGORITHM_DEFINES.md Documents HQC configuration options.
configure.ac Adds experimental HQC configuration.
CMakeLists.txt Adds HQC options and API tests.
cmake/​options.h.in Publishes HQC feature defines.
cmake/​functions.cmake Selects HQC library sources.
ChangeLog.md Records experimental HQC support.
.wolfssl_known_macro_extras Registers new supported macros.
.github/​workflows/​whitebox-smoke.yml Runs dedicated HQC white-box checks.
.github/​configs/​pq-all.json Adds HQC configuration coverage.

Review effort: Balanced

Comment thread tests/api/test_hqc.c Resolved
Comment thread tests/api/test_hqc.c Resolved
Comment thread wolfcrypt/benchmark/benchmark.c Resolved
Comment thread wolfssl/wolfcrypt/memory.h Resolved
@github-actions

github-actions Bot commented Dec 4, 2026 •

Copy link
Copy Markdown

MemBrowse Memory Report · Explore what changed →

stm32-sim-stm32h753

  • FLASH: .text +64 B (+0.0%, 220,632 B / 2,097,152 B, total: 11% used)

zephyr-frdm_rw612

  • FLASH: datas +16 B, log_const_area -8 B, rodata +108 B, text +13,944 B (+5.0%, 296,524 B / 67,108,864 B, total: 0% used)
  • RAM: bss +49 B, datas +16 B (+0.1%, 58,423 B / 983,040 B, total: 6% used)

No memory changes detected for:


Catch memory regressions in CI with MemBrowse. Free for open source.

@SparkiDev
SparkiDev force-pushed the hqc branch 2 times, most recently from ca20886 to 1ef8d6c Compare December 4, 2026 01:51
@SparkiDev
SparkiDev requested review from wolfSSL-Fenrir-bot and a balanced review from Copilot December 4, 2026 01:52
@SparkiDev

Copy link
Copy Markdown
Contributor Author

@claude review

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 default static-memory benchmark pool lacks enough large blocks for HQC with small-stack enabled, causing allocation to fail before encapsulation.

1 open issue
4 resolved since last review

Review effort: Balanced

Comment thread wolfcrypt/benchmark/benchmark.c Resolved

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I reviewed this PR and didn't find any bugs. It adds about 66k lines of new post-quantum crypto (a portable C core plus two x86_64 assembly files of about 28k lines each) and also changes existing AES-GCM-SIV and X25519 MSVC assembly, so a human look would still be worthwhile.

What was reviewed:

  • The memory.h static-memory changes: with HQC enabled, WOLFMEM_BUCKETS and WOLFMEM_DIST both have 9 entries, and the largest bucket (131072) holds HQC's workspaces of up to 43 KB.
  • The regenerated MSVC assembly: the AES-GCM-SIV counter loads now read L_aes_gcmsiv_ctr_inc_* directly instead of the ptr_ slot next to it. This changes behavior in existing Windows code, not only in HQC.
  • Not done: the KATs and the per-CPU-path tests were not run as part of this review, and neither assembly file was checked instruction by instruction.
Extended reasoning...

The change adds the HQC KEM to wolfCrypt: wc_hqc.c, wc_hqc_asm.S/.asm, CPUID detection for PCLMULQDQ, VPCLMULQDQ and GFNI, sha3 asm guard changes, memory.h bucket sizing, and build, test and documentation integration across 45 files. It is security-sensitive cryptographic code whose constant-time behavior can't be fully confirmed by reading the code. It also changes existing AES-GCM-SIV and X25519 Windows assembly, which affects builds that don't enable HQC. The size, the crypto surface and four Copilot threads that only the author resolved led to deferring rather than approving.

@wolfSSL-Fenrir-bot wolfSSL-Fenrir-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Fenrir Automated Review — PR #12394

Scan targets checked: wolfcrypt-src, wolfcrypt-bugs, wolfssl-src, wolfssl-bugs
Not reviewed (no scan target covers them): .github/configs/pq-all.json, .github/workflows/whitebox-smoke.yml, .wolfssl_known_macro_extras, CMakeLists.txt, ChangeLog.md, cmake/functions.cmake, cmake/options.h.in, configure.ac, doc/ALGORITHM_DEFINES.md, doc/ASM_AND_MATH_DEFINES.md, doc/dox_comments/header_files-ja/doxygen_groups.h, doc/dox_comments/header_files-ja/wc_hqc.h, doc/dox_comments/header_files/doxygen_groups.h, doc/dox_comments/header_files/wc_hqc.h, linuxkm/Kbuild, linuxkm/module_exports.c.template, src/include.am, tests/api/include.am, tests/api/test_hqc.h, tests/include.am and 15 more
Coverage: 9 of 10 in-scope changed file(s) opened by the reviewer; not opened: tests/api.c

Fenrir result: Approved ✅

No new issues found in the changed files.

Advisory only — this automated result does not count as a GitHub approval.

Review tier: Max

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

Active issues leave an out-of-bounds test write after SHAKE initialization failure and allow benchmark cleanup to invoke a device callback on uninitialized SHAKE state.

2 open issues
1 resolved since last review

Review effort: Balanced

Comment thread tests/api/test_hqc.c Resolved
Comment thread wolfcrypt/benchmark/benchmark.c Resolved

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 test wrappers can break compilation or linking in HQC-disabled configurations, and the INTIME SDK header-copy list omits the newly required wc_hqc.h header.

2 open issues
2 resolved since last review

Review effort: Balanced

Comment thread wolfssl/wolfcrypt/include.am Resolved

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.

🔵 Needs a closer look

The security-critical KEM and assembly changes require specialist review and cross-CPU Windows validation for constant-time behavior and interoperability not established by the supplied evidence.

No open issues 🎉

2 resolved since last review

Review effort: Balanced

@SparkiDev

Copy link
Copy Markdown
Contributor Author

@claude review

@wolfSSL-Fenrir-bot wolfSSL-Fenrir-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Fenrir Automated Review — PR #12394

Scan targets checked: wolfssl-src, wolfssl-bugs
Unchanged since last review (not re-run): wolfcrypt-src, wolfcrypt-bugs
Not reviewed (no scan target covers them): .github/configs/pq-all.json, .github/workflows/whitebox-smoke.yml, .wolfssl_known_macro_extras, CMakeLists.txt, ChangeLog.md, IDE/INTIME-RTOS/Makefile, cmake/functions.cmake, cmake/options.h.in, configure.ac, doc/ALGORITHM_DEFINES.md, doc/ASM_AND_MATH_DEFINES.md, doc/dox_comments/header_files-ja/doxygen_groups.h, doc/dox_comments/header_files-ja/wc_hqc.h, doc/dox_comments/header_files/doxygen_groups.h, doc/dox_comments/header_files/wc_hqc.h, linuxkm/Kbuild, linuxkm/module_exports.c.template, src/include.am, tests/api/include.am, tests/api/test_hqc.h and 16 more
Coverage: 1 of 2 in-scope changed file(s) opened by the reviewer; not opened: tests/unit-mcdc/test_hqc_fault_whitebox.c

Fenrir result: Approved ✅

No new issues found in the changed files.

Advisory only — this automated result does not count as a GitHub approval.

Review tier: Lite

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code review found no issues

No high-confidence issues detected in this change.

Implement HQC-1, HQC-3 and HQC-5 (HQC specification v5.1) with an API
like ML-KEM's: wc_HqcKey_* for key generation, encapsulation,
decapsulation and encoding/decoding. HQC is experimental: it is built only
with --enable-experimental --enable-hqc[=options], never by --enable-all.

 - wc_hqc.c: constant-time portable C, with build options for size and
   speed (small, small-mem, cache-h, lazy-hek, no-cache-y, ...) and for
   compiling out key generation, encapsulation or decapsulation.
 - wc_hqc_asm.S/.asm: x86_64 assembly (PCLMULQDQ, VPCLMULQDQ, AVX2,
   AVX-512, GFNI, BMI), chosen at run time from CPU features. Encapsulation
   and decapsulation run several SHAKE sponges together on the 4-way and
   8-way Keccak assembly.
 - cpuid: detect PCLMULQDQ, VPCLMULQDQ and GFNI.
 - Regenerated MSVC assembly: an element of a constant table is now read
   from the table, not from the pointer next to it (AES, AES-GCM, X25519).
 - Build: configure, CMake, Visual Studio projects, linuxkm.
 - Tests: known-answer tests repeated on each CPU path in testwolfcrypt,
   API tests, Reed-Solomon and fault-injection white-boxes, pq-all CI
   configs and a white-box CI step.
 - Benchmark: -hqc, with all-zero seeds without an RNG or with
   WOLFSSL_HQC_BENCH_DETERMINISTIC.
 - Docs: Doxygen (English and Japanese), ALGORITHM_DEFINES.md,
   ASM_AND_MATH_DEFINES.md, ChangeLog.
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