Repository navigation
RSA spec: RSA_check_key's checks of the CRT form, without d (vg_rsa_check_crt_key) - #1343
Merged
Merged
Conversation
…rsa_check_crt_key) `Rsa.crtKeyValid` and `Rsa.checkCrtKey`: BoringSSL's `RSA_check_key` checks of the CRT form `(n, e, p, q, dP, dQ, qInv)` of a private key, without those of the private exponent `d`, which the private-key operations do not use; and the contract and `Api` of `vg_rsa_check_crt_key`, for `PrivateKey::from_crt` to check a key in place of a whole private-key operation on 0. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01PqW9NMssoiBx9i4PpksckL
This was referenced Oct 8, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
From the rustls provider analysis in #991: loading a server key with
PrivateKey::from_crtruns at 0.10–0.20 of aws-lc-rs's speed, becausefrom_crtchecks the key with a whole constant-time private-key operation on 0. This PR is the spec half of replacing that with a cheap, proven check; the implementation follows in a separate PR, per "One kind of change per PR".Trust change (
Spec/)This is a spec change. It adds no ISA semantics and does not touch
TCB/.Spec/Rsa.lean:crtKeyValidandcheckCrtKey. These arekeyValid/checkKey(BoringSSL'sRSA_check_key) with the checks ofddropped, because the private-key operations never used:modulusValid n kandexponentValid ep q = ndP < p - 1ande dP ≡ 1 (mod p - 1)dQ < q - 1ande dQ ≡ 1 (mod q - 1)qInv < pandq qInv ≡ 1 (mod p)keyValid'sp < nandq < nare left out. They follow fromp q = nonce neither factor is 1, and the congruences modulop - 1andq - 1already rule that out, becausee ≥ 3.Spec/Rsa/Contract.lean:checkCrtKeySig,checkCrtKeyContractandcheckCrtKeyApiforvg_rsa_check_crt_key. They mirrorvg_rsa_check_key's signature, preconditions, leak and docs withoutd:checkCrtKeyholds and 0 otherwisescratchnandeVerifiedGarbageTest/Rsa.lean:checkCrtKeyon the CAVP-derived keys thatcheckKeyis already tested on:pandqeither way round and with leading zerosp = 1privateCheckedgives 0 for 0What
from_crtwill guaranteeToday
from_crtaccepts a key exactly whenprivateChecked(n, e, 0, p, q, dP, dQ, qInv)isok. That holds whennandeare valid,p q = n,qInv < p, and the CRT resultmfor 0 passesm^e ≡ 0 (mod n). The last condition only fails in degenerate cases such asdP = 0.After the implementation PR,
from_crtwill accept exactly the keyscheckCrtKeyaccepts. That guarantee is stronger in both directions:private_oprelies on: modulus valid,p q = nandqInv < p. So a refusal fromvg_rsa_private_checkedstill means the input is out of range.dP, dQ ≥ 1, so 0's result is 0 and passes the old check. Every key the new check accepts, the old one accepted too.eat load time, withInvalidPrivateKey. Today those load and then fail every operation withFault.private_op's fault check stays as it is.🤖 Generated with Claude Code
https://claude.ai/code/session_01PqW9NMssoiBx9i4PpksckL
Generated by Claude Code