|
1 | 1 | /- |
2 | | - ----------------------------------------------------------- |
3 | | - Security games as pmfs |
4 | | - ----------------------------------------------------------- |
| 2 | +Copyright (c) 2021 Joey Lupo. All rights reserved. |
| 3 | +Released under Apache 2.0 license as described in the file LICENSE. |
| 4 | +Authors: Joey Lupo |
5 | 5 | -/ |
| 6 | +import Cryptolib.ToMathlib |
| 7 | +import Cryptolib.Uniform |
| 8 | +import Mathlib.Data.ZMod.Basic |
| 9 | +import Mathlib.Probability.Distributions.Uniform |
6 | 10 |
|
7 | | -import data.zmod.basic |
8 | | -import probability.probability_mass_function.basic |
9 | | -import to_mathlib |
10 | | -import uniform |
| 11 | +/-! |
| 12 | +# Security games as PMFs |
11 | 13 |
|
12 | | -noncomputable theory |
| 14 | +This file provides formal definitions for correctness and semantic security of a public |
| 15 | +key encryption scheme. |
| 16 | +-/ |
| 17 | + |
| 18 | +noncomputable section |
13 | 19 |
|
14 | 20 | /- |
15 | | - G1 = public key space, G2 = private key space, |
16 | | - M = message space, C = ciphertext space |
17 | | - A_state = type for state A1 passes to A2 |
| 21 | +G1 = public key space, G2 = private key space, |
| 22 | +M = message space, C = ciphertext space |
| 23 | +A_state = type for state A1 passes to A2 |
18 | 24 | -/ |
19 | | -variables {G1 G2 M C A_state: Type} [decidable_eq M] |
20 | | - (keygen : pmf (G1 × G2)) |
21 | | - (encrypt : G1 → M → pmf C) |
22 | | - (decrypt : G2 → C → M) |
23 | | - (A1 : G1 → pmf (M × M × A_state)) |
24 | | - (A2 : C → A_state → pmf (zmod 2)) -- Should have G1 else how can A2 do further encryptions? Any general result about encryptions before getting challenge ciphertext...? |
| 25 | +variable {G1 G2 M C A_state: Type} [DecidableEq M] |
| 26 | + (keygen : PMF (G1 × G2)) |
| 27 | + (encrypt : G1 → M → PMF C) |
| 28 | + (decrypt : G2 → C → M) |
| 29 | + (A1 : G1 → PMF (M × M × A_state)) |
| 30 | + (A2 : C → A_state → PMF (ZMod 2)) -- Should have G1 else how can A2 do further encryptions? Any general result about encryptions before getting challenge ciphertext...? |
25 | 31 |
|
26 | 32 | /- |
27 | | - Executes the a public-key protocol defined by keygen, |
28 | | - encrypt, and decrypt |
| 33 | +Executes a public-key protocol defined by keygen, |
| 34 | +encrypt, and decrypt |
29 | 35 | -/ |
30 | 36 | -- Simulates running the program and returns 1 with prob 1 if: |
31 | 37 | -- `Pr[D(sk, E(pk, m)) = m] = 1` holds |
32 | | -def enc_dec (m : M) : pmf (zmod 2) := -- given a message m |
| 38 | +def enc_dec (m : M) : PMF (ZMod 2) := -- given a message m |
33 | 39 | do |
34 | | - k ← keygen, -- produces a public / secret key pair |
35 | | - c ← encrypt k.1 m, -- encrypts m using pk |
| 40 | + let k ← keygen -- produces a public / secret key pair |
| 41 | + let c ← encrypt k.1 m -- encrypts m using pk |
36 | 42 | pure (if decrypt k.2 c = m then 1 else 0) -- decrypts using sk and checks for equality with m |
37 | 43 |
|
38 | 44 | /- |
39 | | - A public-key encryption protocol is correct if decryption undoes |
40 | | - encryption with probability 1 |
| 45 | +A public-key encryption protocol is correct if decryption undoes |
| 46 | +encryption with probability 1 |
41 | 47 | -/ |
42 | 48 |
|
43 | | -def pke_correctness : Prop := ∀ (m : M), enc_dec keygen encrypt decrypt m = pure 1 -- This chain of encryption/decryption matches the monadic actions in the `enc_dec` function |
| 49 | +/- |
| 50 | +This chain of encryption/decryption matches the monadic actions in the `enc_dec` function |
| 51 | +-/ |
| 52 | +def PkeCorrectness : Prop := ∀ (m : M), enc_dec keygen encrypt decrypt m = pure 1 |
44 | 53 |
|
45 | 54 | /- |
46 | | - The semantic security game. |
47 | | - Returns 1 if the attacker A2 guesses the correct bit |
| 55 | +The semantic security game. |
| 56 | +Returns 1 if the attacker A2 guesses the correct bit |
48 | 57 | -/ |
49 | | -def SSG : pmf (zmod 2):= |
| 58 | +def SSG : PMF (ZMod 2) := |
50 | 59 | do |
51 | | - k ← keygen, |
52 | | - m ← A1 k.1, |
53 | | - b ← uniform_2, |
54 | | - c ← encrypt k.1 (if b = 0 then m.1 else m.2.1), |
55 | | - b' ← A2 c m.2.2, |
| 60 | + let k ← keygen |
| 61 | + let m ← A1 k.1 |
| 62 | + let b ← uniform_2 |
| 63 | + let c ← encrypt k.1 (if b = 0 then m.1 else m.2.1) |
| 64 | + let b' ← A2 c m.2.2 |
56 | 65 | pure (1 + b + b') |
57 | 66 |
|
58 | 67 | -- SSG(A) denotes the event that A wins the semantic security game |
59 | | -local notation `Pr[SSG(A)]` := (SSG keygen encrypt A1 A2 1) |
| 68 | +local notation "Pr[SSG(A)]" => (SSG keygen encrypt A1 A2 1) |
60 | 69 |
|
61 | | -def pke_semantic_security (ε : nnreal) : Prop := abs (Pr[SSG(A)] - 1/2) ≤ ε |
| 70 | +def PkeSemanticSecurity (ε : NNReal) : Prop := abs (Pr[SSG(A)].toReal - 1/2) ≤ ε |
0 commit comments