Skip to content

init, crypto: fix settings.json warning, lock secrets, check CPUID - #248

Merged
djh58 merged 1 commit into
feature/pq-transportfrom
djh58/pq233-init-crypto
Oct 23, 2026
Merged

djh58 merged 1 commit into
feature/pq-transportfrom
djh58/pq233-init-crypto

Conversation

@djh58

@djh58 djh58 commented Oct 23, 2026 •

Copy link
Copy Markdown
Member

Five fixes from review of #233.

  • No false startup warning for true in settings.json. settings.json keeps JSON types, so "v2pqtransport": true (or "mlkemportable": true) was taken for the double negative -nov2pqtransport=0, and warned on every start; in qbit-qt that warning is a dialog.
    • The warning now checks the source of the value that takes effect, in GetSetting()'s precedence. A bool from settings.json is a plain value. A bool from the command line or qbit.conf is the double negative.
    • ArgsManager gains a const LockSettings() for this.
    • The new feature_pq_settings.py covers each source and each override. It fails against the old code.
  • ML-KEM and ECDH secrets live in locked memory. A responder holds the 3,168-byte decapsulation key until the accept arrives, and both sides hold the retained ECDH secret until the peer's version arrives. Both now live in secure_allocator memory, which is mlock'd and excluded from core dumps, as CKey is. They are still wiped on close.
  • SHA-256 CPU detection checks the maximum CPUID leaf. It used to read leaf 7 without checking. In a VM limited to leaf 1, the answer is leaf 1's data, whose APIC ID bits can claim SHA-NI, and the self-test then dies with SIGILL.
  • ForcePortableForTesting guards are counted. Guards that overlap without nesting, as on two threads, used to restore the wrong state. This is test-only; production selection is unchanged.
  • The mlkem_backend_diff fuzz target can't silently compare portable C with itself. At start-up it aborts unless the native code that the build and CPU allow is active. When only portable C runs, it says so and skips the diff.

Tests run:

  • test_qbit --run_test=bip324_tests,mlkem_tests,cpu_features_tests,crypto_tests,net_pq_tests,net_tests,argsman_tests,getarg_tests. The three new unit tests fail with the library fixes reverted.
  • The functional tests rpc_pqtransport.py, feature_pq_settings.py and feature_settings.py.
  • The fuzz targets mlkem and mlkem_backend_diff over their seed corpora, both natively (x86_64-avx2) and with MLKEM_FORCE_PORTABLE=1.
  • ruff with the lint runner's rules.

Since #245, pull requests into feature/pq-transport don't run CI. #233's full CI covers this change once it merges.

🤖 Generated with Claude Code


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need.

Found in review of #233.

- init: settings.json keeps JSON types, so "v2pqtransport": true (or
  "mlkemportable": true) was taken for the double negative -noX=0 and
  warned on every start, in qbit-qt as a dialog. The warning now looks
  at the source that wins, in GetSetting()'s precedence: a bool from
  settings.json is plain, one from the command line or qbit.conf is
  the double negative. ArgsManager gains a const LockSettings() for
  this. feature_pq_settings.py covers each source and override.
- bip324, bip324_pq: a responder holds the 3,168-byte decapsulation
  key, and both sides the retained ECDH secret, until the peer's
  version arrives. Both now live in secure_allocator memory (mlock'd,
  excluded from core dumps), like CKey, and are still wiped on close.
- sha256: SHA256AutoDetect read CPUID leaf 7 without checking the
  maximum basic leaf. In a VM limited to leaf 1 the answer is leaf 1's
  data, whose APIC ID bits can claim SHA-NI, and the self-test then
  dies with SIGILL. Leaf 7 is now read only when supported.
- mlkem: ForcePortableForTesting restored the state it replaced, which
  is wrong when guards overlap without nesting, as on two threads.
  Guards are now counted.
- fuzz: mlkem_backend_diff compared portable C with itself under
  MLKEM_FORCE_PORTABLE=1, and nothing checked that native code ran in
  the native replay. It now aborts at start-up unless the native code
  the build and CPU allow is active, and skips the diff, saying so,
  when only portable C is.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@djh58

djh58 commented Oct 23, 2026

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 23, 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-10-23T17:39:22.087361Z e9585d5 Manual request
ℹ️ 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.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Delightful!

Reviewed commit: e9585d5390

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

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.

1 participant