Skip to content

x86-64 secp256k1 and brainpool public-key functions and ECDH return without secret residue - #4900

Merged
reaperhulk merged 1 commit into
claude/residue-ecfrom
claude/residue-ec-2
Nov 10, 2026
Merged

reaperhulk merged 1 commit into
claude/residue-ecfrom
claude/residue-ec-2

Conversation

@reaperhulk

@reaperhulk reaperhulk commented Nov 10, 2026 •

Copy link
Copy Markdown
Member

Stacked on #4899, whose shared PostOut proofs (Proof/EcKey/X86_64/Scrub/Out.lean) this PR uses. Its base is that PR's branch; it is meant to be retargeted to main once #4899 merges. It takes 28 more lines off ci/residue_allowlist.txt. No trust change: nothing under TCB/ or Spec/ changes, and no Lean module is added.

What is converted

  • Public keys (16): public_key, compress_public_key, decompress_public_key and validate_public_key for secp256k1, brainpoolP256r1, brainpoolP384r1 and brainpoolP512r1.
  • ECDH (12): vg_ecdh_{p192,p224,p256,p384,p521,secp256k1,brainpoolp256r1,brainpoolp384r1,brainpoolp512r1}, and the _adx variants of P-256, P-384 and P-521.

For each of them the residue analysis finds nothing on the stack to wipe, so the scrub only clears registers.

How

As in #4899:

  • The scrub for each registration (scrubKs, scrubOk, scrubReg) is in the module that proves its code:
    • Proof/EcKey/{Compressed,Validate}/X86_64/<C>.lean;
    • Proof/EcKey/X86_64/<C>/Verified.lean;
    • Proof/Ecdh/X86_64/<C>/Verified.lean;
    • the VerifiedAdx.lean files, for the _adx variants (scrubRegAdx).
  • Out.lean gains exchangeOut, for ECDH's postcondition.
  • The registration files only bind.

Checks

  • lake build (all modules), Emit.lean --check, the Static checks job, check_lean_public_imports.py on the changed modules: pass.
  • cargo fmt --check, cargo clippy --all-targets -- -D warnings: pass.
  • cargo test with Wycheproof, with every CPU feature and with VG_CPU_FEATURES=none: pass.

Speed

Benchmarks run 42779179146: x86-64, against #4899's branch, one interleaved run, with every CPU feature and with none.

  • The comparison table has the validate benchmarks of every curve, brainpoolP512r1's public key, and its ECDH: 10 and 11 rows.
  • Each row is within 1.9% faster to 0.9% slower.
  • The other ECDH benchmarks ran but are missing from the table.

🤖 Generated with Claude Code

https://claude.ai/code/session_015ajQWxYnEynffr2A7QLPVa

Return without secret residue (`X86_64.RScrub.withScrub`) from the x86-64
`vg_ec_<curve>_{public_key,compress_public_key,decompress_public_key,
validate_public_key}` for secp256k1, brainpoolP256r1, brainpoolP384r1 and
brainpoolP512r1, and from every `vg_ecdh_<curve>` (P-192, P-224, P-256,
P-384, P-521, secp256k1 and the three Brainpool curves, with the `_adx`
variants of P-256, P-384 and P-521): 28 functions leave
ci/residue_allowlist.txt. The residue analysis finds nothing to wipe in any
of them.

`exchangeOut` (`Proof/EcKey/X86_64/Scrub/Out.lean`) proves, for every
curve, that ECDH's postcondition reads the memory on return only within
`out`. As before, each scrubbed registration is in the module that proves
its code, taking the curve's law as an argument, so the registration files
only bind.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015ajQWxYnEynffr2A7QLPVa
@reaperhulk
reaperhulk added this pull request to stack #4915 November 10, 2026 16:11
@reaperhulk
reaperhulk added this pull request to the merge queue Nov 10, 2026
Merged via the queue into main with commit 4f3a0c5 Nov 10, 2026
36 checks passed
@reaperhulk
reaperhulk deleted the claude/residue-ec-2 branch November 10, 2026 16:23
alex pushed a commit that referenced this pull request Nov 10, 2026
…work's

scrubAllCode and its proof move from Proof/Framework/X86_64/Scrub.lean to
their one user, Proof/Pbkdf2/Md/X86_64/ScrubStream.lean, so that this change
leaves Scrub.lean as main has it. Every function that is scrubbed imports
that module, the EC key and ECDH functions of #4899 and #4900 among them,
whose proofs CI's Lean shard rebuilt together, twice ending with the
runner's shutdown.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TKUFHFEUkKJRQvsEBN9oBp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants