Skip to content

ARMv7: verified vg_rsa_private_precompute - #4930

Closed
alex wants to merge 1 commit into
mainfrom
claude/arm-rsa-precompute
Closed

alex wants to merge 1 commit into
mainfrom
claude/arm-rsa-precompute

Conversation

@alex

@alex alex commented Nov 10, 2026

Copy link
Copy Markdown
Member

Adds the ARMv7 implementation of vg_rsa_private_precompute (Spec.Rsa.privatePrecomputeContract), verified for correctness and constant time. No Rust caller yet: the Rust switch to the precomputed private-key path comes in a later PR, once every architecture has this function.

Design

The function reuses the private CRT's own frame, entry and validation:

  • The caller's frame is saved and pre is cleared.

  • A second frame pushes a made-up set of CRT stack arguments:

    • the input and the coefficient are the cleared pre;
    • the exponents are the factors themselves.

    The CRT's validation then accepts exactly when p q = n for a valid n.

  • Inside the CRT's frame, after the validation:

    • each factor is prepared in the narrow workspace at its own width, max(2, ⌈len/8⌉) (Spec.Rsa.primeWords), and its R² mod p is exported to pre after the modulus' values;
    • the main workspace then gives R² mod n, and the public precomputation's export (precomputeOut) writes n and R² mod n;
    • the secret acceptance bit (maskOutput) masks all of pre.
  • The only branch tests the public modulus.

The stack use is 168 bytes.

Files

  • Impl/Bignum/Arm/PrivPreFn.lean: the code.
  • Proof/Bignum/Arm/PrivPre{Enter,Phase,Modulus,Frame,Fn}.lean: correctness.
  • Proof/Bignum/Arm/PrivPre{BlocksCT,ValidCT,FrameCT,Verified}.lean: constant time and Verified.
  • Artifacts/Rsa/Arm.lean: registration.
  • crates/verified-garbage-asm-arm: regenerated (full emitter).

Changes to existing proofs

These are not TCB or Spec changes. Proof/Bignum/Arm/CrtEntryReady.lean now makes public two sections it already had, crt_begin_ok and crt_validateStage_ct, and three of its imports, so that this proof can reuse them.

Checks

  • Static checks pass.
  • check_lean_public_imports.py passes on the changed modules.
  • The full Emit.lean --check passes.
  • cargo fmt --check passes.
  • cargo clippy --target armv7-unknown-linux-gnueabihf -D warnings passes.

No benchmark run: nothing calls the new function yet, so no speed changes.


Generated by Claude Code

The precomputation runs the private CRT's own frame and validation on a
fabricated CRT call: a second frame pushes the CRT's stack arguments, the
input and coefficient being the cleared pre and the exponents the factors,
so that the validation accepts exactly when p q = n for a valid n. Each
factor is then prepared in the narrow workspace at its own width,
max(2, ceil(len/8)), and its R^2 mod p exported to pre after the modulus'
values; the main workspace gives R^2 mod n, the public precomputation's
export writes n and it, and the secret acceptance bit masks all of pre.

CrtEntryReady exposes crt_begin_ok and crt_validateStage_ct, which the
proof reuses.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TKUFHG7VqNCm5vQWRrXrv5

alex commented Nov 11, 2026

Copy link
Copy Markdown
Member Author

Split by entrypoint at alex's request into #4943 (stacked on #4940).


Generated by Claude Code

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