Skip to content

pkg/pqm4: add ML-DSA-44 (FIPS 204) post-quantum signature package#22268

Closed
cakirmert wants to merge 3 commits into
RIOT-OS:masterfrom
cakirmert:feat/pkg-pqm4-mldsa44
Closed

pkg/pqm4: add ML-DSA-44 (FIPS 204) post-quantum signature package#22268
cakirmert wants to merge 3 commits into
RIOT-OS:masterfrom
cakirmert:feat/pkg-pqm4-mldsa44

Conversation

@cakirmert
Copy link
Copy Markdown

@cakirmert cakirmert commented May 10, 2026

Contribution description

Adds pkg/pqm4 as a new RIOT external package, exposing the
ML-DSA-44 (FIPS 204) post-quantum signature scheme via the upstream
pqm4 library (Kannwischer, Rijneveld,
Schwabe, Stoffelen et al.).

The upstream pqm4 sources are unmodified. The package consists of:

  • Makefile: fetches pqm4 at a pinned commit, hooks
    git submodule update --init mupq into PKG_PREPARED so the
    mupq/pqclean submodule is in place before consumers build
  • Makefile.pqm4: explicit SRC list for the m4f (speed-optimised)
    variant; the m4fstack (memory-optimised, ~7 KiB signing stack)
    variant is a one-line edit away
  • Makefile.include: exports header search paths and CFLAGS
  • Makefile.dep: gates the package on the cortexm_fpu feature
    (provided by Cortex-M4F / Cortex-M7 / Cortex-M33 with FPU), so
    pre-Thumb-2 ARM (e.g. msba2 / LPC23xx) and Cortex-M0/M3/M23 are
    skipped at feature-resolution rather than failing in the assembler
  • glue/riot-hal.c: implements pqm4's mupq/common/hal.h contract
    (six functions) over RIOT primitives, replacing upstream
    hal-opencm3 / hal-mps2
  • glue/riot-randombytes.c: implements PQCLEAN_randombytes()
    over RIOT's random_bytes()

The Cortex-M4F assembly in pqm4 runs unmodified on Cortex-M33
(ARMv8-M Mainline + DSP is a strict superset of ARMv7E-M + DSP).

A previous attempt at integrating pqm4 was made in PR #9897 (closed
unmerged in 2019, on the policy concern that ML-DSA was experimental
at the time). ML-DSA was standardised by NIST as FIPS 204 in
August 2024; this PR is the post-standardisation revisit.

Testing procedure

tests/pkg/pqm4 performs a keygen / sign / verify round-trip on a
fixed message. Build and run on a Cortex-M4F-or-later board:

BOARD=rpi-pico-2-arm make -C tests/pkg/pqm4 flash term

Expected serial output:

pqm4 ML-DSA-44 self-test
========================
  pk size: 1312 B
  sk size: 2560 B
  sig size: 2420 B
[1/3] crypto_sign_keypair ...
  OK
[2/3] crypto_sign ...
  OK (sm = 2442 B)
[3/3] crypto_sign_open ...
  OK (message recovered and verified)

ALL TESTS PASSED

Before this PR is applied, tests/pkg/pqm4 does not exist in the
tree and no pqm4 integration is available at all. With the PR
applied:

  • on Cortex-M4F / Cortex-M7 / Cortex-M33-with-FPU boards,
    tests/pkg/pqm4 builds, flashes, and prints the output above;
    the package becomes available to any RIOT application via
    USEPKG += pqm4 (then #include "api.h" to access
    crypto_sign_keypair(), crypto_sign(), crypto_sign_open(),
    and the matching ML-DSA-44 size constants);
  • on boards without cortexm_fpu (msba2, Cortex-M0/M3/M23 etc.),
    the build skips at feature-resolution time, reporting
    There are unsatisfied feature requirements: cortexm_fpu.

Hardware-tested on Raspberry Pi Pico 2 H (RP2350, Cortex-M33 @ 125 MHz).

Issues/PRs references

Supersedes the long-stale PR #9897 (2019 pqm4 integration attempt,
closed because ML-DSA was experimental, but that policy concern is
now obsolete with FIPS 204).

Companion PRs from the same investigation, independent merge order:

Declaration of AI-Tools / LLMs usage:

AI-Tools / LLMs that were used are:

  • Claude Code (Anthropic, claude-opus-4-7): agent mode with user
    review for code drafting, package layout, PR description authoring,
    debugging assistance, and hardware test orchestration. All commits
    are authored by me; every code change was reviewed before commit;
    the cortexm_fpu gate, the hal.h glue layout, and the test
    Makefile path were iteratively adjusted in response to maintainer
    feedback and CI errors.

@github-actions github-actions Bot added Area: doc Area: Documentation Area: tests Area: tests and testing framework Area: pkg Area: External package ports Area: cpu Area: CPU/MCU ports labels May 10, 2026
@crasbe crasbe added Type: enhancement The issue suggests enhanceable parts / The PR enhances parts of the codebase / documentation Type: new feature The issue requests / The PR implemements a new feature for RIOT CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR labels May 10, 2026
@riot-ci
Copy link
Copy Markdown

riot-ci commented May 10, 2026

Murdock results

✔️ PASSED

39a7570 tests/pkg/pqm4: address 01-run.py review feedback

Success Failures Total Runtime
11113 0 11113 09m:36s

Artifacts

@AnnsAnns
Copy link
Copy Markdown
Member

Hello, thank you for your contribution to RIOT, we always appreciate that.

I want to be quite blunt because the PR description did not follow the standard template for RIOT which felt a bit weird and a small review of the code supported it, is this AI generated?

Please switch to the default PR template description and properly declare your AI usage.

@cakirmert cakirmert force-pushed the feat/pkg-pqm4-mldsa44 branch from c43666a to ac3fcaa Compare May 10, 2026 19:35
@github-actions github-actions Bot removed the Area: cpu Area: CPU/MCU ports label May 10, 2026
@cakirmert cakirmert changed the title pkg/pqm4: add ML-DSA-44 package + RP2350 UART fixes pkg/pqm4: add ML-DSA-44 (FIPS 204) post-quantum signature package May 10, 2026
@cakirmert cakirmert force-pushed the feat/pkg-pqm4-mldsa44 branch from ac3fcaa to 6899874 Compare May 10, 2026 19:53
@cakirmert cakirmert marked this pull request as ready for review May 10, 2026 20:23
@cakirmert
Copy link
Copy Markdown
Author

cakirmert commented May 10, 2026

@AnnsAnns You're right, sorry about that. I've rewritten the description to follow PULL_REQUEST_TEMPLATE.md (Contribution description / Testing procedure / Issues/PRs references / AI declaration sections), and added an explicit declaration: this work was done with Claude Code (Anthropic, claude-opus-4-7) in agent mode, with my review on every commit.

The pqm4 wrapper, the UART fixes (#22269) and the periph_timer driver (#22270) all came out of getting a post-quantum mutual-attestation firmware to run on real Pi Pico 2 H boards. I made the substantive decisions (which pqm4 variant, which features to gate on, what to fix in the PL011 driver); Claude helped me draft, debug, and write up. Every register-level claim was checked against the RP2350 datasheet and PL011 TRM, and the firmware was hardware-tested on Pico 2 H boards before each PR was opened.

I should have used the template and declared the tool from the start; sorry for the friction. Happy to take any further changes you'd like to see.

Copy link
Copy Markdown
Contributor

@crasbe crasbe left a comment

Choose a reason for hiding this comment

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

I don't like reviewing AI code...

Comment thread pkg/pqm4/doc.txt Outdated
Comment thread pkg/pqm4/doc.txt Outdated
Comment thread pkg/pqm4/doc.txt Outdated
Comment thread pkg/pqm4/doc.txt Outdated
Comment thread pkg/pqm4/doc.txt Outdated
Comment thread tests/pkg/pqm4/main.c
Comment thread pkg/pqm4/riot-hal.c Outdated
Comment thread pkg/pqm4/glue/riot-randombytes.c Outdated
Comment thread pkg/pqm4/glue/Makefile Outdated
Comment thread pkg/pqm4/Makefile.pqm4 Outdated
@cakirmert cakirmert force-pushed the feat/pkg-pqm4-mldsa44 branch from 6899874 to d6dceb9 Compare May 11, 2026 21:00
@cakirmert cakirmert requested a review from jia200x as a code owner May 11, 2026 21:00
@cakirmert
Copy link
Copy Markdown
Author

@crasbe thanks for the careful review. All 19 threads have been addressed

cakirmert added 2 commits May 11, 2026 23:42
Add a RIOT package wrapper for the pqm4 post-quantum crypto library
(Kannwischer et al.). The upstream pqm4 sources are unmodified; the
package provides fetch/build Makefiles and two glue source files
(riot-hal.c, riot-randombytes.c) compiled directly into the pqm4
module via vpath.

Currently wired for the ML-DSA-44 m4f (speed-optimised) variant.
The m4fstack (memory-optimised, ~7 KiB signing stack) variant can be
selected by changing the source paths in Makefile.pqm4.

The Cortex-M4F assembly in pqm4 runs unmodified on Cortex-M33
(ARMv8-M Mainline + DSP is a superset of ARMv7E-M + DSP). The
package gates on the cortexm_fpu RIOT feature, which restricts it
to cortex-m4f, cortex-m7, and cortex-m33 - pre-Thumb-2 and FPU-less
cores are skipped at feature resolution.

Tested on: Raspberry Pi Pico 2 H (RP2350, Cortex-M33 @ 125 MHz).
Basic round-trip test for the pqm4 package: generates a keypair,
signs a test message, verifies the signature, and checks the
recovered message matches the original.

Includes tests/01-run.py so the test plugs into the standard
RIOT testrunner.
@cakirmert cakirmert force-pushed the feat/pkg-pqm4-mldsa44 branch from d6dceb9 to da1050d Compare May 11, 2026 21:42
@AnnsAnns
Copy link
Copy Markdown
Member

AnnsAnns commented May 12, 2026

Please do not squash / force push unless asked to https://github.com/RIOT-OS/RIOT/blob/master/CONTRIBUTING.md#squash-commits-after-review

This makes it extremely hard for reviewers to understand changes and breaks any references to existing files on outstanding reviews!

Comment thread tests/pkg/pqm4/tests/01-run.py Outdated
Comment thread tests/pkg/pqm4/tests/01-run.py
Comment thread tests/pkg/pqm4/tests/01-run.py
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.

Did you actually run this test?

- Switch the copyright header to SPDX format (see #21515)
- Reduce double blank lines around testfunc and __main__ guard
  per reviewer suggestion
@AnnsAnns
Copy link
Copy Markdown
Member

Hello, once again thank you for being wilful to contribute to RIOT, we do appreciate it.

Due to various reasons, such as the currently unresolved legal issues around AI code combined with the very high degree of AI assistance, among other things, we have decided that we can not accept this PR as of now.

This is not meant to stop you from contributing to RIOT. For example, if you want to PR code written by yourself, we are open to review and help you.

@AnnsAnns AnnsAnns closed this May 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: doc Area: Documentation Area: pkg Area: External package ports Area: tests Area: tests and testing framework CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Type: enhancement The issue suggests enhanceable parts / The PR enhances parts of the codebase / documentation Type: new feature The issue requests / The PR implemements a new feature for RIOT

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants