refactor(Crypto): replace bespoke constructions with Mathlib abstractions - #813
Open
SamuelSchlesinger wants to merge 2 commits into
Open
Conversation
SamuelSchlesinger
requested review from
chenson2018 and
fmontesi
as code owners
August 17, 2026 22:51
SamuelSchlesinger
force-pushed
the
samschlesinger/crypto-mathlib-cleanups
branch
from
August 17, 2026 23:33
d124628 to
887c320
Compare
crei
reviewed
Aug 18, 2026
| /-- The ciphertext distribution of the OTP is uniform, regardless of the | ||
| message: masking with a uniform key is the permutation `Equiv.xor` of the | ||
| uniform distribution. -/ | ||
| theorem otp_ciphertextDist_eq_uniform (l : ℕ) (m : BitVec l) : |
Collaborator
There was a problem hiding this comment.
Naming: strictly, in its syntactic form, this is not a statement about otp, but only about xor.
crei
reviewed
Aug 18, 2026
| the exact symmetry needed in the privacy proof. -/ | ||
| the exact symmetry needed in the privacy proof. | ||
|
|
||
| The requirement is strong: translation invariance forces the distribution. On |
Collaborator
There was a problem hiding this comment.
This reads a bit like an AI-generated comment in its common compressed form - is this deliberate or not (is the comment needed here)?
crei
reviewed
Aug 18, 2026
| rw [h msgDist m c, ENNReal.mul_div_cancel_right | ||
| ((PMF.mem_support_iff _ _).mp hc) (PMF.apply_ne_top _ c)] | ||
|
|
||
| private theorem perfectlySecret_of_ciphertextIndist (scheme : EncScheme M K C) |
Collaborator
There was a problem hiding this comment.
Maybe better to inline this into the proof of perfectlySecret_iff_ciphertextIndist?
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.
While surveying the crypto files for things Mathlib now does better, a few cleanups fell out. Net effect is about −100 lines with no statement weakened.
TODO: upstreamitems have since landed in Mathlib (FinEnum (BitVec n),LawfulXor), and ciphertext uniformity is now just "XOR by the key is a permutation of the uniform distribution" viaEquiv.xor. That theorem stays public since uniformity is stronger than perfect secrecy.Internal/PerfectSecrecy.leanis folded intoBasic.lean, so theInternal/convention is retired and each theorem has exactly one public name.posteriorDistis now built onPMF.normalizeinstead of a hand-rolledHasSumproof, and perfect secrecy shares its "conditioning doesn't change the prior" lemma with secret sharing instead of re-deriving it.coeffTranslatewasEquiv.addRightall along,authorized_monois now stated asMonotone, a docstring honesty fix forTailSampler(translation invariance forces uniformity), namespace opens instead of fully-qualified names, and some proof golfing.Two things reviewers might trip on:
posteriorDist_applyis no longerrfl(proofs that unfolded the old definition need to go through the lemma now), and theauthorized_monofield changed shape from∀ {s t}, s ⊆ t → …toMonotone.Assisted by Claude Fable 5.