-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchooser2.ec
159 lines (128 loc) · 2.77 KB
/
chooser2.ec
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
include "groups_prime_order.ec".
type chooser_state.
type choice = bool.
type group4 = (group * group * group * group).
adversary A(mc : group4) : bool {}.
game ChooserSec = {
abs A = A {}
fun Chooser(sigma : bool) : group4 = {
var a, b, c : zq;
var z0, z1 : group;
a = i_to_zq([0..q-1]);
b = i_to_zq([0..q-1]);
c = i_to_zq([0..q-1]);
if (sigma) {
z1 = g^(a*b); z0 = g^c;
} else {
z0 = g^(a*b); z1 = g^c;
}
return (g^a, g^b, z0, z1);
}
fun Main() : bool = {
var sigma, sigma' : bool;
var mc : group4;
sigma = {0,1};
mc = Chooser(sigma);
sigma' = A(mc);
return (sigma = sigma');
}
}.
game DDH0 = {
abs A = A {}
fun Chooser(sigma : bool, U : group, V : group, W : group) : group4 = {
var z0, z1 : group;
var c : zq;
c = i_to_zq([0..q-1]);
if (sigma) {
z1 = W; z0 = g^c;
} else {
z0 = W; z1 = g^c;
}
return (U, V, z0, z1);
}
fun B(U : group, V : group, W : group) : bool = {
var sigma, sigma' : bool;
var mc : group4;
sigma = {0,1};
mc = Chooser(sigma, U, V, W);
sigma' = A(mc);
return (sigma = sigma');
}
fun Main() : bool = {
var a, b : zq;
var guess : bool;
a = i_to_zq([0..q-1]);
b = i_to_zq([0..q-1]);
guess = B(g^a, g^b, g^(a*b));
return guess;
}
}.
equiv Eq_ChooserSec_DDH0 : ChooserSec.Main ~ DDH0.Main : true ==> ={res}.
inline.
swap {2} 6 -5.
rnd >>.
sp.
swap {2} 10 -7.
derandomize.
!3rnd>>.
sp 3 10.
case {1}: sigma_0.
condt.
auto.
condf.
auto.
save.
game DDH1 = DDH0
where Main = {
var a, b, u : zq;
var guess : bool;
a = i_to_zq([0..q-1]);
b = i_to_zq([0..q-1]);
u = i_to_zq([0..q-1]);
guess = B(g^a, g^b, g^u);
return guess;
}.
game G1 = {
abs A = A {}
fun Main() : bool = {
var sigma, sigma' : bool;
var mc : group4;
var a, b, c, d : zq;
a = i_to_zq([0..q-1]);
b = i_to_zq([0..q-1]);
c = i_to_zq([0..q-1]);
d = i_to_zq([0..q-1]);
mc = (g^a, g^b, g^c, g^d);
sigma' = A(mc);
sigma = {0,1};
return (sigma = sigma');
}
}.
equiv Eq_DDH1_G1 : DDH1.Main ~ G1.Main : true ==> ={res}.
inline.
swap {2} 7 -6.
swap {1} 7 -6.
rnd >>.
case {1} : sigma.
condt {1} at 12.
derandomize.
!4rnd {1} >>. sp.
trivial.
derandomize.
swap {2} 3 1.
!4rnd >>.
auto.
condf {1} at 12.
derandomize.
!4rnd {1} >>. sp.
trivial.
derandomize.
!4rnd >>.
auto.
save.
claim C_G1 :G1.Main[res] = 1%r/2%r compute.
claim C_ChooserSec_DDH0: ChooserSec.Main[res] = DDH0.Main[res]
using Eq_ChooserSec_DDH0.
claim C_DDH1_G1: DDH1.Main[res] = G1.Main[res] using Eq_DDH1_G1.
claim C_ChooserSec:
| ChooserSec.Main[res] - 1%r/2%r | = | DDH0.Main[res] - DDH1.Main[res] |.