Skip to content

fix(pq): clear SHAKE state on drop - #361

Merged
polaz merged 1 commit into
mainfrom
fix/#292-shake-state-clearing
Nov 1, 2026
Merged

polaz merged 1 commit into
mainfrom
fix/#292-shake-state-clearing

Conversation

@polaz

@polaz polaz commented Nov 1, 2026 •

Copy link
Copy Markdown
Member

Summary

  • experimental-pq enables shake/zeroize, so Shake and ShakeReader clear their state and cursor on drop in a downstream build that does not ask for it.
  • experimental-pq with one XML backend builds without std, as the feature table states.

Changes

  • check-features experimental resolves a throwaway consumer outside the workspace and requires shake/zeroize in its graph. A workspace build cannot show this, because dev-dependencies enable the same feature.
  • tests/shake_state_clearing.rs requires ZeroizeOnDrop for both hashers.
  • ML-KEM key encapsulation imports Vec from alloc.
  • ML-KEM tests no longer assume a randomness source; a build without one is pinned to refuse encapsulation as unsupported.
  • CI lints the no_std configuration on a bare-metal target.
  • The ML-DSA notes limit the assurance to the state of those values: this is not complete secret erasure, and no exploit is claimed.

Testing

Tests, lints, formatting, the feature profile and the dependency audit pass on macOS, including the no_std configuration; CI covers Linux and Windows.

Closes #292

Summary by CodeRabbit

  • New Features
    • With the experimental post-quantum feature enabled, Shake state and reader cursors are cleared when those values are dropped.
  • Documentation
    • Clarified that this clearing does not cover compiler-generated copies or other temporary data, and does not guarantee complete secret erasure.

- Enable shake/zeroize from the experimental-pq feature, so a downstream
  crate gets the clearing without asking for it
- Qualify the feature on an isolated consumer, because dev-dependencies
  enable it in every workspace build
- Build experimental-pq without std, which the feature table promises and
  a missing import broke
- Stop ML-KEM tests from assuming a randomness source a build without
  signing does not have, and pin the refusal such a build answers with

Closes #292
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 1, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-01T16:05:00.124485Z b478dcd PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@coderabbitai

coderabbitai Bot commented Nov 1, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between b31650d and b478dcd.

Files selected for processing: 8
  • .github/workflows/ci.yml
  • Cargo.toml
  • docs/ml-dsa-patch.md
  • src/key_establishment.rs
  • src/provider/key_encapsulation/rustcrypto.rs
  • tests/shake_state_clearing.rs
  • tools/xml-sec-tools/src/check_features.rs
  • tools/xml-sec-tools/src/check_features/tests.rs

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

Walkthrough

The change enables shake/zeroize for the experimental PQ dependency and adds checks for state clearing and downstream feature resolution. It also updates key-encapsulation test coverage and adds an alloc-only Clippy check.

Changes: Experimental PQ SHAKE state clearing

Layer / File(s) Summary
Enable and check SHAKE state clearing
Cargo.toml, tests/shake_state_clearing.rs, docs/ml-dsa-patch.md
The optional shake dependency enables zeroize. The experimental-PQ test checks ZeroizeOnDrop for Shake128 and Shake256, and checks that their reader types need drop. The documentation limits its claims to the dependency-owned state and cursor.
Qualify the downstream feature graph
tools/xml-sec-tools/src/check_features.rs, tools/xml-sec-tools/src/check_features/tests.rs, .github/workflows/ci.yml
The experimental profile checks isolated consumer metadata for shake/zeroize and runs the state-clearing test. Tests cover missing packages, missing features, invalid metadata, and a valid feature graph. The alloc-only job adds a Clippy check for the experimental-PQ feature and roxmltree backend.

Key-encapsulation test coverage

Layer / File(s) Summary
Check encapsulation feature behavior
src/provider/key_encapsulation/rustcrypto.rs, src/key_establishment.rs
Tests check that encapsulation returns Unsupported without xmldsig-sign and gate tests that require that feature. FailedRandom now advertises random and encapsulation support, and the allowance-exhaustion retry uses it.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Bug fix

Possibly related PRs

  • structured-world/xml-sec#269: Isolates Cargo feature profiles from workspace feature unification; this change applies downstream feature-graph checking to shake/zeroize.
  • structured-world/xml-sec#320: Changes when ML-KEM encapsulation is supported; this change updates related key-encapsulation feature tests.
Merge Risk: Minimal · up to b478d

SHAKE state clearing is enabled for experimental PQ. No merge-blocking risk was identified.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 42.86% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documenta… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly identifies the main change: enabling SHAKE state clearing on drop for experimental post-quantum support.
Linked Issues check Passed Issue #292 is directly linked and active. Cargo.toml enables shake/zeroize on the existing optional dependency with default-features = false. The new shake_state_clearing target asserts `Zeroi…
Out of Scope Changes check Passed The changed files support issue #292. The ML-KEM alloc::vec::Vec import and test gating keep experimental-PQ and no_std checks valid. The CI lint adds coverage for the required bare-metal configurat…
Full details: Linked Issues check

Explanation

Issue #292 is directly linked and active. Cargo.toml enables shake/zeroize on the existing optional dependency with default-features = false. The new shake_state_clearing target asserts ZeroizeOnDrop for Shake128 and Shake256 and checks that both reader types require drop. check-features experimental now creates an out-of-workspace consumer without a direct SHAKE dependency and rejects metadata that lacks shake/zeroize. The summary reports that the required tests, feature checks, no_std lint, and supported configurations pass. The ML-DSA documentation keeps the assurance limited to dependency-owned state clearing.

Full details: Out of Scope Changes check

Explanation

The changed files support issue #292. The ML-KEM alloc::vec::Vec import and test gating keep experimental-PQ and no_std checks valid. The CI lint adds coverage for the required bare-metal configuration. The documentation states the required limits on secret-erasure claims. The downstream feature-graph code and its tests implement the issue regression. No unrelated product behavior, cryptographic implementation, or signature format change is shown.

Full details: Docstring Coverage

Explanation

Docstring coverage is 42.86% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 7 functions across 5 files. (3 skipped: 3 unsupported.)

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

Finishing Touches
Generate docstrings
  • Commit to this branch
  • Create a new PR
Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@polaz
polaz merged commit 4176191 into main Nov 1, 2026
29 checks passed
@polaz
polaz deleted the fix/#292-shake-state-clearing branch November 1, 2026 17:33
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.

Enable SHAKE state clearing for experimental PQ

1 participant