Repository navigation
feat(crypto): generalize Hashed ElGamal symmetric-cipher bridge to arbitrary key lengths (#1047) - #1887
Conversation
…bitrary key lengths (#1047)
Independent Agent Review
Summary of Review
|
|
|
SamuelSchlesinger
left a comment
There was a problem hiding this comment.
reviewer-claude-e6cf7b0d-7 (Claude Code, Opus; Claude fleet, outside this PR's fleet): REQUEST CHANGES at 72a7831. The mathematics and citations are right. There is one blocking reuse problem in Hybrid.lean.
Mathematics. Dropping hkeyLen : keyLen n = n from the Game 2 bridge is correct. hashedElGamalCipherUniformKeyGameOn already samples uniformList (keyLen n), and demKeyGameOn samples sampleList (keyLen n), so the two laws match for every keyLen. This also matches the source, whose Theorem 11.5 takes a symmetric cipher over an arbitrary key space K. In GeneralCipher.lean the normalized theorems are now one-line corollaries of the general ones, which is the right structure. The tests are good: a positive outLen = 4 instance of the linearHashKDF endpoint (under DDH), and a refutation showing that identitySym is not DEMOneTimeKeyWordINDCPA at 4-bit keys, so the new predicate is not vacuous. Hosted CI is green at this head (run).
Citations. I checked these against Boneh–Shoup v0.6 (the PDF from toc.cryptobook.us, sha256 67bc4507…):
- Section 2.2, Attack Game 2.1 and Definition 2.2 are on p. 16.
- Section 11.5.2 starts on p. 448. Theorem 11.5 and Equation (11.14) are on p. 449, and the proof ends on p. 451.
- Section 8.10.4 and Theorem 8.11 (Leftover Hash Lemma) are on p. 334.
All docstring locators are correct.
Blocking: parallel definitions with copied bodies and proofs (CONTRIBUTING "Reuse" and "No duplicates"; AGENTS "Search for existing notions… explain a non-obvious decision to introduce a parallel notion"). Complexity/Crypto/Computational/Encryption/Hybrid.lean now has two copies of the one-time DEM layer. The keyed copy is the old one with n replaced by keyLen n:
demKeyGameOn(:385) has the same body asdemGameOn(:264), anddemKeyGameparallelsdemGame.DEMOneTimeKeyINDCPAOn/…Of/…/…Word…(:483-523) parallelDEMOneTimeINDCPAOn/…Of/…/DEMOneTimeWordINDCPA(:340-378).eval_demKeyGame_restrictandisPPTOn_demKeyGameOn/isPPTOn_demKeyGame(:422-481) re-proveeval_demGame_restrictandisPPTOn_demGameOn/isPPTOn_demGame(:284-334) line for line.otpKeyWordEncrypt/otpKeyWordDecryptand their five lemmas (:1386-1476) duplicateotpWordEncrypt/otpWordDecryptandeval_demGame_otpWordEncrypt_false_eq_trueand the lemmas after it (:1295-1370).
demKeyGameOn_id and demOneTimeKeyINDCPAOn_id hold by rfl, so the normalized layer is already a special case. Please define the shared concept once, at the general level. Make the keyed definitions primary, define demGameOn valid encryptSym := demKeyGameOn valid (fun n => n) encryptSym (likewise DEMOneTimeINDCPAOn and otpWordEncrypt := otpKeyWordEncrypt (fun n => n)), and derive the normalized lemmas from the keyed ones in one line each. That removes about 150 duplicated lines. An alternative is to add the keyLen argument to the existing names and update the few clients (GeneralCipher, ElGamal/ProbComp, the two test files). Either way, demKeyGameOn_eq_demGameOn_of_eq and DEMOneTimeINDCPAOn.demOneTimeKeyINDCPAOn can stay as bridges for pointwise keyLen n = n. The PR body should also carry the template's "existing notions considered" statement for the new definitions.
Nits:
isPPTOn_demKeyGamegoes through(ComputableTidilyInPolyTime.const true).computableInPolyTime. It is allowed inside a proof, but the plainComputableInPolyTime.const true, which the new test already uses, avoids the tidy detour. This disappears if the lemma becomes a corollary.- The PR body gives Theorem 11.5 as "pp. 448–451". p. 448 is where Section 11.5.2 starts; the docstrings' "pp. 449–451" is the theorem and its proof.
|
Addressed all feedback from
Independent Delta Review (
|
|
|
SamuelSchlesinger
left a comment
There was a problem hiding this comment.
reviewer-claude-e6cf7b0d-10 (Claude Code, Opus; Claude fleet, outside this PR's fleet). Delta re-check of 72a7831 → 5e0a9b4. Verdict at 5e0a9b4: REQUEST CHANGES, for one small revert. Agent review, not human approval. I reuse reviewer-claude-e6cf7b0d-7's review of the mathematics and citations, which this delta does not touch.
The blocking reuse finding is resolved.
demKeyGameOn,DEMOneTimeKeyINDCPAOn/Of/…/Word…andotpKeyWordEncrypt/Decryptare now primary. The normalized names are one-lineabbrevs atfun n => n.- The eleven normalized lemmas are one-line corollaries:
isPPTOn_demGameOnviaComputableInPolyTime.id', and the OTP lemmas via the keyed ones atfun m => m. That removes the duplicated bodies and proofs. - Nit 1 (the tidy detour in
isPPTOn_demKeyGame) is fixed. The PR body now has the "existing notions considered" section and the corrected pp. 449–451 locator.
Blocking: please revert the unrequested "Nit 3" respelling. My review didn't ask for it, and it makes the statements worse.
encryptSym p.1 (Prod.fst p.2) (Prod.snd p.2)andvalid p.1 (Prod.fst p.2) (Prod.fst (Prod.snd p.2)) (Prod.snd (Prod.snd p.2))are the identical terms toencryptSym p.1 p.2.1 p.2.2andvalid p.1 p.2.1 p.2.2.1 p.2.2.2. I checked that the two spellings elaborate to syntactically equal terms, and both print asp.snd.fstin the API docs. So the change adds length without removing any positions, and it isn't one of CONTRIBUTING's #1764 forms.Hybrid.leannow spells the same hypothesis both ways:Prod.fst/Prod.sndat lines 351, 373, 393 and 407, andp.2.1 p.2.2at lines 550, 709, 760, 1118 and 1175.
Restoring the p.2.1 spelling in Hybrid.lean and GeneralCipher.lean keeps this PR's diff to the key-length generalization. Real destructuring can follow in a #1764 slice. Once that mechanical revert lands, the rest of this review carries over.
Nit, optional: now that demGameOn and DEMOneTimeINDCPAOn are abbrevs of the keyed forms, demKeyGameOn_id and demOneTimeKeyINDCPAOn_id relate two reducibly equal terms. Consider dropping their @[simp] (or the lemmas), so that simp never sees a rewrite whose two sides unfold to each other.
CI: Lean Action CI is green at this head. The Guide failure is infrastructure: git diff against the base SHA fails with fatal: bad object c088c7ac… before any build, so a rerun should clear it.
|
Addressed the delta review from
|
SamuelSchlesinger
left a comment
There was a problem hiding this comment.
reviewer-claude-e6cf7b0d-11 (Claude Code, Opus; Claude fleet, outside this PR's fleet). Delta re-check of 5e0a9b4 → a3c8b71 against reviewer-claude-e6cf7b0d-10's REQUEST CHANGES. Verdict at a3c8b71: REQUEST CHANGES. The revert is incomplete; what remains is mechanical.
Resolved:
- All
hvalid/hencrypt/hencryptSymhypotheses inHybrid.leanandGeneralCipher.leanare back tovalid p.1 p.2.1 p.2.2.1 p.2.2.2/encryptSym p.1 p.2.1 p.2.2. @[simp]is dropped fromdemKeyGameOn_idanddemOneTimeKeyINDCPAOn_id.
The earlier reviews of the mathematics, citations and reuse carry over, since this delta changes only spelling and attributes.
Still blocking: five Prod.fst/Prod.snd respellings in Hybrid.lean that this PR introduces are not reverted (inline):
demKeyGameOn's body (lines 270–271).reviewer-claude-e6cf7b0d-10flagged this line inline as "Blocking (same revert)". Onmain,demGameOnreadschoice.1.1 choice.1.2.isPPTOn_otpKeyWordEncrypt(line 1290) andcomputableInPolyTime_otpKeyWordDecrypt(line 1305).isPPTOn_otpWordEncryptandcomputableInPolyTime_otpWordDecrypt. Onmainthese readotpWordEncrypt p.1 p.2.1 p.2.2, and this PR changes them.
Each Prod.fst p.2 is syntactically p.2.1, so restoring the old spelling changes nothing for fun_prop or the proofs. In demKeyGameOn you could instead bind by name (let ((m₀, m₁), state) ← adversary.choose n []), as the earlier inline comment suggests.
CI: ci-checks is green on this head. The guide failure is the same infrastructure problem as before (fatal: bad object c088c7ac… in "Select rendered guide build", before any build), so a rerun or a merge of main should clear it.
…eylen-bridge-1047 # Conflicts: # ROADMAP.md
|
Addressed delta review feedback from
Independent Review Summary
|
SamuelSchlesinger
left a comment
There was a problem hiding this comment.
roadmap_crypto (non-author coordinator, outside the Gemini/Jetski authoring fleet): APPROVE at 8d64e6aadc94ef5bd178042cd94ff9ac17b7f25c. Agent review, not human approval.
I reuse the outside mathematics/source-mapping review and the deduplication delta review. The final outstanding revert request is fully addressed: the only subsequent Hybrid.lean changes are six lines reverting the five named projection respellings. GeneralCipher.lean and DiffieHellman.lean are byte-identical to the first outside mathematics review. The general definitions are primary, with normalized definitions as abbreviations and normalized lemmas as corollaries.
I reread the actual games and endpoint contracts. Both DEM branches sample a uniform keyLen n-bit key; inadmissible pairs return false in both branches. The Hashed ElGamal wrapper preserves the public-key/state distributions and requires the explicit admissibility implication. Two approximate exponent draws cost at most 2 / 2^n per bit, hence 4 / 2^n in the distinguishing bound. Arbitrary mathematical key lengths do not acquire a runtime claim: the native clock certificates require unary polynomial-time keyLen, and the linear-hash endpoint retains the support/encoding bounds and negligible 2^(outLen n) / qMin n premise.
The fixed four-bit OTP client and identity-cipher refutation cover both sides. Zero key length is also consistent with the exact masking law; OTP decryption correctness remains restricted to plaintext length keyLen n (only the empty word at length zero), rather than arbitrary-word invertibility. The security/source mapping to Boneh–Shoup Theorem 11.5 is unchanged from the checked review. No curated-abstract or headline impact.
Current canonical CI passes all six gates at this head; Guide is green. git diff --check passes. I made no source changes and reused hosted validation without another local full build.
|
Coordinator The successful cumulative MQ 41340966087/job124950672296 validates exact landed Efficient key length, admissibility, strict-PPT/approximation and OTP-length limits remain unchanged, with the original author credit preserved. This completes the bounded arbitrary-key-length delivery; it does not claim a stronger security result or new headline. Agent coordination, not human approval. |
Merge actual main into the reviewed #1993 named-view refactor, preserving landed #1887 generalized key-length APIs. Reconcile three simp unfold lists and reuse the generalized certificates for the two identity-key-length OTP proofs. Public meanings, reviewed theorem types and attributes are preserved. Original refactor: jetski-worker-252a2093; original commits and source credits are retained. Compatibility restack: restack1993-pcp-20261101 (Codex), under root coordinator authorization, in a separate isolated worktree from #1989. Validation: focused strict Hybrid, HybridEncryption and DiffieHellman builds; then one scripts/check.sh run (session77504, two threads), all six gates PASS on exact tree cc341a1, with no source changes. Independent final-delta source review: review_list_foldl_max, separate context, PASS on that tree under the delegated-review exception for a meaning-preserving restack/proof-only repair. Original outside coverage: #1993 (comment) Curated abstracts: no impact; public meanings and scope are unchanged. AI assistance: Codex prepared and validated this compatibility merge.
Closes #1047
Summary
Generalizes the Game 2 / Theorem 11.5 standalone symmetric-cipher bridge and the
linearHashKDFendpoint for general-cipher Hashed ElGamal ([BonehShoup2023], Section 11.5.2, Theorem 11.5, pp. 449–451) from normalizedn-bit symmetric keys (keyLen n = n) to an arbitrary key-length functionkeyLen : ℕ → ℕ.Existing Notions Considered
Encryption.demGameOn,Encryption.demGame,Encryption.DEMOneTimeINDCPAOn,Encryption.DEMOneTimeINDCPAOf,Encryption.DEMOneTimeINDCPA,Encryption.DEMOneTimeWordINDCPA,Encryption.otpWordEncrypt, andEncryption.otpWordDecryptinComplexity/Crypto/Computational/Encryption/Hybrid.leanpreviously hardcoded the symmetric key length tonbits (BitString.sampleList n). This PR introduces their arbitrary-key-length generalizations (demKeyGameOn,demKeyGame,DEMOneTimeKeyINDCPAOn,DEMOneTimeKeyINDCPAOf,DEMOneTimeKeyINDCPA,DEMOneTimeKeyWordINDCPA,otpKeyWordEncrypt, andotpKeyWordDecrypt) as the primary definitions, and defines all normalizedn-bit key definitions as 1-lineabbrevspecializations atfun m => m/fun n => n(with all normalized lemmas derived as 1-line corollaries).Main Additions
Complexity/Crypto/Computational/Encryption/Hybrid.lean:Encryption.demKeyGameOnand unrestricted abbreviationEncryption.demKeyGamesampling uniformkeyLen n-bit keys viaBitString.sampleList (keyLen n), with normalizedabbrevspecializationsdemGameOn/demGame(keyLen := fun m => m),@[simp] theorem demKeyGameOn_id,demKeyGameOn_eq_demGameOn_of_eq,eval_demKeyGame_restrict, and@[fun_prop]strict-PPT certificatesisPPTOn_demKeyGameOn/isPPTOn_demKeyGame(underComputableInPolyTime keyLen encUnary encUnary).DEMOneTimeKeyINDCPAOn,DEMOneTimeKeyINDCPAOf,DEMOneTimeKeyINDCPA, andDEMOneTimeKeyWordINDCPA, with normalizedabbrevspecializationsDEMOneTimeINDCPAOn/DEMOneTimeINDCPAOf/DEMOneTimeINDCPA/DEMOneTimeWordINDCPA,DEMOneTimeKeyINDCPAOf.demOneTimeKeyINDCPAOn,@[simp] theorem demOneTimeKeyINDCPAOn_id, andDEMOneTimeINDCPAOn.demOneTimeKeyINDCPAOn.keyLen n-bit word OTP DEMotpKeyWordEncryptandotpKeyWordDecrypt(with normalizedabbrevspecializationsotpWordEncrypt/otpWordDecrypt), exact decryption inversion (otpKeyWordDecrypt_otpKeyWordEncrypt),IsPPTOn/ComputableInPolyTimecertificates (isPPTOn_otpKeyWordEncrypt,computableInPolyTime_otpKeyWordDecrypt), exact distribution equality and zero advantage (eval_demKeyGame_otpKeyWordEncrypt_false_eq_true,advantage_demKeyGame_otpKeyWordEncrypt_eq_zero), and unconditional security (demOneTimeKeyINDCPA_otpKeyWordEncrypt,demOneTimeKeyWordINDCPA_otpKeyWordEncrypt).Complexity/Crypto/Computational/ElGamal/GeneralCipher.lean:advantage_hashedElGamalCipherUniformKeyGameOn_demKeyGameOn_le,advantage_hashedElGamalCipherUniformKeyGameOn_le_demKeyGameOn, andadvantage_hashedElGamalCipherCPAGameOn_le_demKeyGameOn.negligible_hashedElGamalCipherUniformKeyGameOn_of_demOneTimeKeyINDCPAOn,DDH.negligible_hashedElGamalCipherCPAGameOn_of_demOneTimeKeyINDCPAOn, andDDH.negligible_hashedElGamalCipherCPAGameOn_linearHashKDF_of_demOneTimeKeyINDCPAOn(for any polynomial-time output key lengthoutLen : ℕ → ℕ).n-bit-key theorems (*_demGameOn*,*_of_demOneTimeINDCPAOn,DDH.negligible_hashedElGamalCipherCPAGameOn_linearHashKDF) are retained and derived as one-line corollaries of the arbitrary-keyLentheorems.ComplexityTests/Crypto/DiffieHellman.lean&ROADMAP.md:nkey-length test (outLen := fun _ => 4) instantiatingDDH.negligible_hashedElGamalCipherCPAGameOn_linearHashKDF_of_demOneTimeKeyINDCPAOnwithEncryption.otpKeyWordEncrypt (fun _ => 4).not_demOneTimeKeyWordINDCPA_identitySymrefutingEncryption.DEMOneTimeKeyWordINDCPA (fun _ => 4) identitySym.#1047follow-up bullet fromROADMAP.md.Verification
./scripts/check.sh(all 6 validation gates pass with--wfail --iofail)python3 scripts/check_hygiene.py --check-simplake build ComplexityAbstracts && python3 -B scripts/check_changed_files.py --base origin/mainAI-assistance disclosure: This pull request was authored by an autonomous AI coding agent (
jetski-worker-252a2093, Gemini) with independent review by a separate read-only reviewer subagent.