Skip to content

refactor(Crypto): replace bespoke constructions with Mathlib abstractions - #813

Open
SamuelSchlesinger wants to merge 2 commits into
leanprover:mainfrom
SamuelSchlesinger:samschlesinger/crypto-mathlib-cleanups
Open

refactor(Crypto): replace bespoke constructions with Mathlib abstractions#813
SamuelSchlesinger wants to merge 2 commits into
leanprover:mainfrom
SamuelSchlesinger:samschlesinger/crypto-mathlib-cleanups

Conversation

@SamuelSchlesinger

@SamuelSchlesinger SamuelSchlesinger commented Aug 17, 2026

Copy link
Copy Markdown
Collaborator

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.

  • The internal one-time pad file is gone: both of its TODO: upstream items 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" via Equiv.xor. That theorem stays public since uniformity is stronger than perfect secrecy.
  • Internal/PerfectSecrecy.lean is folded into Basic.lean, so the Internal/ convention is retired and each theorem has exactly one public name.
  • posteriorDist is now built on PMF.normalize instead of a hand-rolled HasSum proof, and perfect secrecy shares its "conditioning doesn't change the prior" lemma with secret sharing instead of re-deriving it.
  • Smaller stuff: coeffTranslate was Equiv.addRight all along, authorized_mono is now stated as Monotone, a docstring honesty fix for TailSampler (translation invariance forces uniformity), namespace opens instead of fully-qualified names, and some proof golfing.

Two things reviewers might trip on: posteriorDist_apply is no longer rfl (proofs that unfolded the old definition need to go through the lemma now), and the authorized_mono field changed shape from ∀ {s t}, s ⊆ t → … to Monotone.

Assisted by Claude Fable 5.

@SamuelSchlesinger
SamuelSchlesinger force-pushed the samschlesinger/crypto-mathlib-cleanups branch from d124628 to 887c320 Compare August 17, 2026 23:33
/-- 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) :

@crei crei Aug 18, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Naming: strictly, in its syntactic form, this is not a statement about otp, but only about xor.

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

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This reads a bit like an AI-generated comment in its common compressed form - is this deliberate or not (is the comment needed here)?

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)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe better to inline this into the proof of perfectlySecret_iff_ciphertextIndist?

@crei crei left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just some minor comments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants