-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStretchPRG.v
199 lines (165 loc) · 5.4 KB
/
StretchPRG.v
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
(**
Really simply proof of Claim 5.5 from "The Joy of Cryptography" (p. 94).
It is simple and easy to follow.
*)
From Relational Require Import OrderEnrichedCategory GenericRulesSimple.
Set Warnings "-notation-overridden,-ambiguous-paths".
From mathcomp Require Import all_ssreflect all_algebra reals distr realsum
ssrnat ssreflect ssrfun ssrbool ssrnum eqtype choice seq.
Set Warnings "notation-overridden,ambiguous-paths".
From Mon Require Import SPropBase.
From Crypt Require Import Axioms ChoiceAsOrd SubDistr Couplings
UniformDistrLemmas FreeProbProg Theta_dens RulesStateProb
pkg_core_definition choice_type pkg_composition pkg_rhl Package Prelude.
From extructures Require Import ord fset fmap.
Import SPropNotations.
Import PackageNotation.
From Equations Require Import Equations.
Require Equations.Prop.DepElim.
Set Equations With UIP.
Set Bullet Behavior "Strict Subproofs".
Set Default Goal Selector "!".
Set Primitive Projections.
Import Num.Def.
Import Num.Theory.
Import Order.POrderTheory.
Section StretchPRG_example.
Definition tt := Datatypes.tt.
Variable (n: nat).
Definition Word_N: nat := 2^n.
Definition Word: choice_type := 'fin Word_N.
Notation " 'word " := (Word) (in custom pack_type at level 2).
Notation " 'word " := (Word) (at level 2): package_scope.
Context (PRG: Word -> Word * Word).
Definition query: nat := 0.
Definition mkpair {Lt Lf E}
(t: package Lt [interface] E) (f: package Lf [interface] E):
loc_GamePair E := fun b => if b then {locpackage t} else {locpackage f}.
Definition GEN_pkg_tt:
package fset0 [interface]
[interface #val #[query]: 'unit → 'word × 'word ] :=
[package
#def #[query] (_: 'unit): 'word × 'word {
s <$ uniform Word_N ;;
ret (PRG s)
}
].
Definition GEN_pkg_ff:
package fset0 [interface]
[interface #val #[query]: 'unit → 'word × 'word ] :=
[package
#def #[query] (_: 'unit): 'word × 'word {
x <$ uniform Word_N ;;
y <$ uniform Word_N ;;
ret (x, y)
}
].
Definition GEN := mkpair GEN_pkg_tt GEN_pkg_ff.
Definition GEN_STRETCH_pkg_tt:
package fset0 [interface]
[interface #val #[query]: 'unit → 'word × 'word × 'word ] :=
[package
#def #[query] (_: 'unit): 'word × 'word × 'word {
s <$ uniform Word_N ;;
let (x, y) := PRG s in
ret (x, PRG y)
}
].
Definition GEN_STRETCH_pkg_ff:
package fset0 [interface]
[interface #val #[query]: 'unit → 'word × 'word × 'word ] :=
[package
#def #[query] (_: 'unit): 'word × 'word × 'word {
x <$ uniform Word_N ;;
u <$ uniform Word_N ;;
v <$ uniform Word_N ;;
ret (x, (u, v))
}
].
Definition GEN_STRETCH := mkpair GEN_STRETCH_pkg_tt GEN_STRETCH_pkg_ff.
Definition GEN_STRETCH_HYB_pkg_1:
package fset0
[interface #val #[query]: 'unit → 'word × 'word ]
[interface #val #[query]: 'unit → 'word × 'word × 'word ] :=
[package
#def #[query] (_: 'unit): 'word × 'word × 'word {
#import {sig #[query]: 'unit → 'word × 'word } as query ;;
'(x, y) ← query tt ;;
ret (x, PRG y)
}
].
Definition GEN_STRETCH_HYB_pkg_2:
package fset0
[interface #val #[query]: 'unit → 'word × 'word ]
[interface #val #[query]: 'unit → 'word × 'word × 'word ] :=
[package
#def #[query] (_: 'unit): 'word × 'word × 'word {
#import {sig #[query]: 'unit → 'word × 'word } as query ;;
x <$ uniform Word_N ;;
uv ← query tt ;;
ret (x, uv)
}
].
Lemma GEN_equiv_true:
GEN_STRETCH true ≈₀ GEN_STRETCH_HYB_pkg_1 ∘ GEN true.
Proof.
apply: eq_rel_perf_ind_eq.
simplify_eq_rel m.
apply rpost_weaken_rule with eq;
last by move=> [? ?] [? ?] [].
simplify_linking.
ssprove_code_simpl.
by apply: rreflexivity_rule.
Qed.
Lemma GEN_HYB_equiv:
GEN_STRETCH_HYB_pkg_1 ∘ GEN false ≈₀ GEN_STRETCH_HYB_pkg_2 ∘ GEN true.
Proof.
apply: eq_rel_perf_ind_eq.
simplify_eq_rel m.
apply rpost_weaken_rule with eq;
last by move=> [? ?] [? ?] [].
simplify_linking.
by apply: rreflexivity_rule.
Qed.
Lemma GEN_equiv_false:
GEN_STRETCH_HYB_pkg_2 ∘ GEN false ≈₀ GEN_STRETCH false.
Proof.
apply: eq_rel_perf_ind_eq.
simplify_eq_rel m.
apply rpost_weaken_rule with eq;
last by move=> [? ?] [? ?] [].
simplify_linking.
by apply: rreflexivity_rule.
Qed.
Local Open Scope ring_scope.
(**
The advantage an adversary can gain over the PRG, i.e. the chance by
which an adversary can distinguish the PRG from truly random numbers.
Negligible by assumption.
*)
Definition prg_epsilon := Advantage GEN.
Theorem security_based_on_prf LA A:
ValidPackage LA
[interface #val #[query]: 'unit → 'word × 'word × 'word ]
A_export A ->
Advantage GEN_STRETCH A <=
prg_epsilon (A ∘ GEN_STRETCH_HYB_pkg_1) +
prg_epsilon (A ∘ GEN_STRETCH_HYB_pkg_2).
Proof.
move=> vA.
rewrite Advantage_E Advantage_sym.
ssprove triangle (GEN_STRETCH true) [::
GEN_STRETCH_HYB_pkg_1 ∘ GEN true ;
GEN_STRETCH_HYB_pkg_1 ∘ GEN false ;
GEN_STRETCH_HYB_pkg_2 ∘ GEN true ;
GEN_STRETCH_HYB_pkg_2 ∘ GEN false
] (GEN_STRETCH false) A
as ineq.
apply: le_trans.
1: by apply: ineq.
rewrite GEN_equiv_true ?fdisjointUr ?fdisjoints0 // GRing.add0r.
rewrite GEN_HYB_equiv ?fdisjointUr ?fdisjoints0 // GRing.addr0.
rewrite GEN_equiv_false ?fdisjointUr ?fdisjoints0 // GRing.addr0.
by rewrite /prg_epsilon !Advantage_E -!Advantage_link !(Advantage_sym (GEN true)).
Qed.
End StretchPRG_example.