-
Notifications
You must be signed in to change notification settings - Fork 0
/
dhkem.curveprime.auth.cv
250 lines (177 loc) · 5.74 KB
/
dhkem.curveprime.auth.cv
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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
proof {
out_game "g00.out.cv" occ;
insert after "in(ch1\\["
"let concat3(protocol: bitstring, label: bitstring, concat2(p2b(Marshal(dh1: G_t)), p2b(Marshal(dh2: G_t)))) = x2 in";
out_game "g01.out.cv" occ;
crypto rom(Extract);
focus "query secret k public_vars skE_hon";
crypto gdh(exp);
out_game "g02.out.cv";
crypto prf(Expand) **;
success
;
(* now prove the other "query secret k public_vars skS_adv" *)
crypto gdh(exp);
crypto prf(Expand) **;
success
}
channel c_start, c_setup, c_enc, c_enc_oth, c_dec.
param N_enc, N_enc_oth, N_dec.
type length_t [fixed].
fun l2b(length_t): bitstring [data].
const Nzz: length_t.
const RFCXXXX: bitstring.
const label_dh: bitstring.
const label_prk: bitstring.
fun concat2(bitstring, bitstring): bitstring [data].
(* This can be data because we only use it with fixed-length parameters *)
fun concat3(bitstring, bitstring, bitstring): bitstring [data].
(* This can be data because we only use it with a few known constants
for the two first parameters, or with fixed-length parameters. *)
fun concat4(bitstring, bitstring, bitstring, bitstring): bitstring.
(* DH-based KEM *)
(* For P-256 and P-521
se a left-hand-side pattern matching of Marshal
*)
type G_t [bounded,large].
type encoded_point_t [fixed,large].
fun Marshal(G_t): encoded_point_t [data].
fun p2b(encoded_point_t): bitstring [data].
type Z_t [bounded,large].
const dummy_Zt: Z_t.
expand DH_good_group(
G_t,
Z_t,
g,
exp,
exp_1,
mult
).
proba P_GDH.
expand GDH(
(* types *)
G_t, (* Group elements *)
Z_t, (* Exponents *)
(* variables *)
g, (* a generator of the group *)
exp, (* exponentiation function *)
exp_1, (* a symbol that replaces exp after game transformation *)
mult, (* multiplication function for exponents *)
(* probabilities *)
P_GDH (* probability of breaking the GDH assumption *)
).
letfun DH(exponent: Z_t, group_element: G_t) =
Marshal(exp(group_element, exponent)).
letfun pk(exponent: Z_t) =
exp(g, exponent).
letfun GenerateKeyPair() =
new z: Z_t;
(z, exp(g, z)).
(* KDF *)
type hash_key_t [fixed].
type extract_t [fixed,large].
fun e2b(extract_t): bitstring.
const zeroNh_e: extract_t.
const zeroNh: bitstring.
equation e2b(zeroNh_e) = zeroNh.
expand ROM_hash_2(
(* types *)
hash_key_t,
bitstring,
bitstring,
extract_t,
(* functions *)
Extract,
(* processes *)
Extract_orcl,
(* parameters *)
N_qExtr (* number of queries to the oracle by the adversary *)
).
proba P_PRF.
type expand_t [fixed,large].
expand PRF_1(
extract_t,
bitstring,
expand_t,
Expand,
P_PRF
).
letfun LabeledExtract(key_extr: hash_key_t, salt: bitstring, label: bitstring, IKM: bitstring) =
let labeledIKM = concat3(RFCXXXX, label, IKM) in
Extract(key_extr, salt, labeledIKM).
letfun LabeledExpand(PRK: extract_t, label: bitstring, info: bitstring, L: length_t) =
let labeledInfo = concat4(l2b(L), RFCXXXX, label, info) in
Expand(PRK, labeledInfo).
letfun ExtractAndExpand(key_extr: hash_key_t, dh: bitstring, kemContext: bitstring) =
let prk = LabeledExtract(key_extr, zeroNh, label_dh, dh) in
LabeledExpand(prk, label_prk, kemContext, Nzz).
type AuthEncap_res_t.
fun AuthEncap_Some(expand_t, bitstring): AuthEncap_res_t [data].
const AuthEncap_None: AuthEncap_res_t.
equation forall zz: expand_t, enc: bitstring;
AuthEncap_Some(zz, enc) <> AuthEncap_None.
letfun AuthEncap(key_extr: hash_key_t, pkR: G_t, skS: Z_t) =
let (skE: Z_t, pkE: G_t) = GenerateKeyPair() in
(
let dh: bitstring = concat2(p2b(DH(skE, pkR)), p2b(DH(skS, pkR))) in
let enc: bitstring = p2b(Marshal(pkE)) in
let pkRm: bitstring = p2b(Marshal(pkR)) in
let pkSm: bitstring = p2b(Marshal(pk(skS))) in
let kemContext: bitstring = concat3(enc, pkRm, pkSm) in
let zz: expand_t = ExtractAndExpand(key_extr, dh, kemContext) in
(AuthEncap_Some(zz, enc), skE)
) else (
(AuthEncap_None, dummy_Zt)
).
type AuthDecap_res_t.
fun AuthDecap_Some(expand_t): AuthDecap_res_t [data].
const AuthDecap_None: AuthDecap_res_t.
equation forall zz: expand_t; AuthDecap_Some(zz) <> AuthDecap_None.
letfun AuthDecap(key_extr: hash_key_t, enc: bitstring, skR: Z_t, pkS: G_t) =
let p2b(Marshal(pkE: G_t)) = enc in
(
let dh: bitstring = concat2(p2b(DH(skR, pkE)), p2b(DH(skR, pkS))) in
let pkRm: bitstring = p2b(Marshal(pk(skR))) in
let pkSm: bitstring = p2b(Marshal(pkS)) in
let kemContext: bitstring = concat3(enc, pkRm, pkSm) in
let zz: expand_t = ExtractAndExpand(key_extr, dh, kemContext) in
AuthDecap_Some(zz)
) else (
AuthDecap_None
).
query secret k public_vars skE_hon.
(* making skE_hon_oth public is not useful because
the adversary is anyway supposed to know skO and could then
compute zz from enc (k_oth is public anyway) *)
query secret k public_vars skS_adv.
process
in(c_start, ());
new key_extr: hash_key_t;
let (skR: Z_t, pkR: G_t) = GenerateKeyPair() in
let (skS: Z_t, pkS: G_t) = GenerateKeyPair() in
let skS_adv: Z_t = skS in
out(c_setup, (pkR, pkS));
((
! i_enc <= N_enc
in(c_enc, ());
let (AuthEncap_Some(k: expand_t, enc_hon: bitstring), skE_hon: Z_t) =
AuthEncap(key_extr, pkR, skS) in
out(c_enc, enc_hon)
)|(
! i_enc_oth <= N_enc_oth
in(c_enc_oth, (pkO: G_t));
let (AuthEncap_Some(k_oth: expand_t, enc_hon_oth: bitstring), skE_hon_oth: Z_t) =
AuthEncap(key_extr, pkO, skS) in
(* only publishing enc is not enough: enc is independent from skS *)
out(c_enc_oth, (enc_hon_oth, k_oth))
)|(
! i_dec <= N_dec
in(c_dec, enc_req: bitstring);
find j <= N_enc suchthat defined(enc_hon[j]) && enc_req = enc_hon[j] then
(
out(c_dec, ())
) else (
out(c_dec, AuthDecap(key_extr, enc_req, skR, pkS))
)
)| Extract_orcl(key_extr)
)