-
Notifications
You must be signed in to change notification settings - Fork 182
refactor(Crypto): replace bespoke constructions with Mathlib abstractions #813
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,8 +7,9 @@ Authors: Samuel Schlesinger | |
| module | ||
|
|
||
| public import Cslib.Crypto.Protocols.PerfectSecrecy.Basic | ||
| public import Cslib.Crypto.Protocols.PerfectSecrecy.Internal.OneTimePad | ||
| public import Mathlib.Probability.Distributions.Uniform | ||
| public import Mathlib.Data.FinEnum | ||
| import Cslib.Probability.PMF | ||
| import Mathlib.Data.LawfulXor.Equiv | ||
|
|
||
| /-! | ||
| # One-Time Pad | ||
|
|
@@ -34,18 +35,30 @@ The one-time pad (Vernam cipher) over `BitVec l` | |
|
|
||
| namespace Cslib.Crypto.Protocols.PerfectSecrecy | ||
|
|
||
| open Cslib.Probability.PMF | ||
|
|
||
| /-- The one-time pad over `l`-bit strings. Encryption and decryption | ||
| are XOR ([KatzLindell2020], Construction 2.9). -/ | ||
| noncomputable def otp (l : ℕ) : | ||
| EncScheme (BitVec l) (BitVec l) (BitVec l) := | ||
| .ofPure (PMF.uniformOfFintype _) (· ^^^ ·) (· ^^^ ·) fun k m => by | ||
| simp [← BitVec.xor_assoc] | ||
| simp [xor_cancel_left] | ||
|
|
||
| /-- 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. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Naming: strictly, in its syntactic form, this is not a statement about
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point. |
||
| (PMF.uniformOfFintype (BitVec l)).bind (fun k => PMF.pure (k ^^^ m)) = | ||
| PMF.uniformOfFintype (BitVec l) := by | ||
| have h : (fun k : BitVec l => PMF.pure (k ^^^ m)) = (PMF.pure ∘ ⇑(Equiv.xor m)) := | ||
| congrArg (PMF.pure ∘ ·) xor_right_eq | ||
| rw [h, PMF.bind_pure_comp, uniformOfFintype_map_equiv] | ||
|
|
||
| /-- The one-time pad is perfectly secret ([KatzLindell2020], Theorem 2.10). -/ | ||
| theorem otp_perfectlySecret (l : ℕ) : (otp l).PerfectlySecret := | ||
| (EncScheme.perfectlySecret_iff_ciphertextIndist _).mpr fun m₀ m₁ => by | ||
| simp only [EncScheme.ciphertextDist, otp] | ||
| exact (OTP.otp_ciphertextDist_eq_uniform l m₀).trans | ||
| (OTP.otp_ciphertextDist_eq_uniform l m₁).symm | ||
| exact (otp_ciphertextDist_eq_uniform l m₀).trans | ||
| (otp_ciphertextDist_eq_uniform l m₁).symm | ||
|
|
||
| end Cslib.Crypto.Protocols.PerfectSecrecy | ||
There was a problem hiding this comment.
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?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll see how it looks when I do that.