-
Notifications
You must be signed in to change notification settings - Fork 3
/
AttackerAPI.fst
610 lines (546 loc) · 27 KB
/
AttackerAPI.fst
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
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
/// AttackerAPI (implementation)
/// =============================
module AttackerAPI
let query_result (idx_state:timestamp) (p:principal) (si:nat) (sv:nat) (res:bytes) : Type0 =
(exists ver_vec state.
state_was_set_at idx_state p ver_vec state /\
Seq.length ver_vec = Seq.length state /\
Seq.length ver_vec > si /\
Seq.index ver_vec si = sv /\
Seq.index state si == res)
let rec attacker_can_derive (i:timestamp) (steps:nat) (t:bytes):
Tot Type0 (decreases steps) =
if steps = 0 then
(* Attacker can read terms that were published (i.e., messages sent by someone in the past) *)
((i > 0 /\ was_published_before (i-1) t) \/
(* Attacker can read the state of corrupted principals *)
(exists idx_state sess_idx sess_ver corrupted_principal.
idx_state < i /\
query_result idx_state corrupted_principal sess_idx sess_ver t /\
was_corrupted_before i corrupted_principal sess_idx sess_ver) \/
(* Attacker can call from_pub_bytes, i.e., can derive constants *)
t == empty \/
(exists (s:string). t == string_to_bytes s) \/
(exists (len s:nat). t == nat_to_bytes len s) \/
(exists sz x. t == nat_lbytes_to_bytes sz x) \/
(exists (s:bytestring). t == bytestring_to_bytes s))
else (
// Just reduce steps by one
(attacker_can_derive i (steps - 1) t) \/
// Attacker can concatenate bytes
(exists (ll:nat) (t1 t2:bytes).
t == concat_len_prefixed ll t1 t2 /\
attacker_can_derive i (steps - 1) t1 /\
attacker_can_derive i (steps - 1) t2) \/
(exists (t1 t2:bytes).
t == raw_concat t1 t2 /\
attacker_can_derive i (steps - 1) t1 /\
attacker_can_derive i (steps - 1) t2) \/
// Attacker can construct public key from private key
(exists (priv_key:bytes).
t == pk priv_key /\
attacker_can_derive i (steps - 1) priv_key) \/
// Asymmetric encryption
(exists (t1 t2 t3:bytes).
t == pke_enc t1 t2 t3 /\
attacker_can_derive i (steps - 1) t1 /\
attacker_can_derive i (steps - 1) t2 /\
attacker_can_derive i (steps - 1) t3) \/
// Symmetric encryption
(exists (t1 t2 t3 t4:bytes).
t == aead_enc t1 t2 t3 t4 /\
attacker_can_derive i (steps - 1) t1 /\
attacker_can_derive i (steps - 1) t2 /\
attacker_can_derive i (steps - 1) t3 /\
attacker_can_derive i (steps - 1) t4) \/
// Create signatures
(exists (t1 t2 t3:bytes).
t == sign t1 t2 t3 /\
attacker_can_derive i (steps - 1) t1 /\
attacker_can_derive i (steps - 1) t2 /\
attacker_can_derive i (steps - 1) t3) \/
// Create macs
(exists (t1 t2:bytes).
t == mac t1 t2 /\
attacker_can_derive i (steps - 1) t1 /\
attacker_can_derive i (steps - 1) t2) \/
// Create hashes
(exists t1.
t == hash t1 /\
attacker_can_derive i (steps - 1) t1) \/
// Attacker can derive new keys from a key and a context
(exists (t1 t2:bytes).
t == extract t1 t2 /\
attacker_can_derive i (steps - 1) t1 /\
attacker_can_derive i (steps - 1) t2) \/
(exists (t1:bytes) (t2:bytes).
t == expand t1 t2 /\
attacker_can_derive i (steps - 1) t1 /\
attacker_can_derive i (steps - 1) t2) \/
// Split up concatenated bytes
(exists (ll:nat) (t1 t2:bytes).
is_succ2 (split_len_prefixed ll t1) t t2 /\
attacker_can_derive i (steps - 1) t1) \/
(exists (ll:nat) (t1 t2:bytes).
is_succ2 (split_len_prefixed ll t1) t2 t /\
attacker_can_derive i (steps - 1) t1) \/
(exists (ll:nat) (t1 t2:bytes).
is_succ2 (split_at ll t1) t t2 /\
attacker_can_derive i (steps - 1) t1) \/
(exists (ll:nat) (t1 t2:bytes).
is_succ2 (split_at ll t1) t2 t /\
attacker_can_derive i (steps - 1) t1) \/
// Asymmetric decryption
(exists (t1 t2:bytes).
is_succ (pke_dec t1 t2) t /\
attacker_can_derive i (steps - 1) t1 /\
attacker_can_derive i (steps - 1) t2) \/
// Symmetric decryption
(exists (t1 t2 t3 t4:bytes).
is_succ (aead_dec t1 t2 t3 t4) t /\
attacker_can_derive i (steps - 1) t1 /\
attacker_can_derive i (steps - 1) t2 /\
attacker_can_derive i (steps - 1) t3 /\
attacker_can_derive i (steps - 1) t4) \/
// DH
(exists (t1 :bytes).
t == (dh_pk t1) /\
attacker_can_derive i (steps - 1) t1) \/
(exists (t1 t2:bytes).
t == (dh t1 t2) /\
attacker_can_derive i (steps - 1) t1 /\
attacker_can_derive i (steps - 1) t2))
let attacker_can_query_compromised_state idx_state idx_corrupt idx_query principal si sv res =
assert (query_result idx_state principal si sv res);
assert (query_result idx_state principal si sv res)
let rec attacker_can_derive_in_more_steps i steps1 steps2 =
if steps2 = 0 then ()
else if steps1 = steps2 then ()
else (attacker_can_derive_in_more_steps i steps1 (steps2 - 1))
#push-options "--z3rlimit 50"
let rec attacker_can_derive_later i steps j =
if steps = 0 then ()
else (attacker_can_derive_later i (steps - 1) j)
#pop-options
let attacker_can_derive_empty i = ()
let max a b =
if a >= b then a else b
let attacker_can_derive_concat_in_same_steps i a b :
Lemma (forall s. attacker_can_derive i s a /\ attacker_can_derive i s b ==> attacker_can_derive i (s+1) (raw_concat a b))
= ()
let attacker_can_derive_concat_in_diff_steps i (sa:nat) a (sb:nat) b :
Lemma
(requires (attacker_can_derive i sa a /\ attacker_can_derive i sb b
))
(ensures attacker_can_derive i ((max sa sb) + 1) (raw_concat a b) )
= let m = max sa sb in
attacker_can_derive_in_more_steps i sa m;
attacker_can_derive_in_more_steps i sb m;
assert(attacker_can_derive i m a /\ attacker_can_derive i m b);
attacker_can_derive_concat_in_same_steps i a b
let attacker_can_derive_concat i a b :
Lemma (forall sa sb. attacker_can_derive i sa a /\ attacker_can_derive i sb b ==> attacker_can_derive i (max sa sb + 1) (raw_concat a b))
= introduce forall sa sb. attacker_can_derive i sa a /\ attacker_can_derive i sb b ==> attacker_can_derive i (max sa sb + 1) (raw_concat a b)
with
begin
introduce attacker_can_derive i sa a /\ attacker_can_derive i sb b ==> attacker_can_derive i (max sa sb + 1) (raw_concat a b)
with _ . attacker_can_derive_concat_in_diff_steps i sa a sb b
end
let attacker_can_derive_split_left i l t1 t :
Lemma
(requires Success? (split_at l t1)
/\ fst (Success?.v (split_at l t1)) == t )
(ensures forall s. attacker_can_derive i s t1 ==> attacker_can_derive i (s+1) t)
= let Success (t,t2) = (split_at l t1) in
assert(is_succ2 (split_at l t1) t t2)
let attacker_can_derive_split_right i l t1 t :
Lemma
(requires Success? (split_at l t1)
/\ snd (Success?.v (split_at l t1)) == t )
(ensures forall s. attacker_can_derive i s t1 ==> attacker_can_derive i (s+1) t)
= let Success (t2,t) = (split_at l t1) in
assert(is_succ2 (split_at l t1) t2 t)
let attacker_can_derive_from_nat i sz n :
Lemma (attacker_can_derive i 0 (nat_lbytes_to_bytes sz n))
= ()
let attacker_knows_later i j =
let attacker_knows_later_steps (steps:nat) (a:bytes):
Lemma (ensures (attacker_can_derive i steps a ==> attacker_can_derive j steps a))
[SMTPat (attacker_can_derive i steps a); SMTPat (attacker_can_derive j steps a)] =
attacker_can_derive_later i steps j in
()
let attacker_knows_empty i = attacker_can_derive_empty i
let attacker_knows_concat i a b =
introduce attacker_knows_at i a /\ attacker_knows_at i b
==> attacker_knows_at i (raw_concat a b)
with _ .
begin
eliminate exists sa sb. attacker_can_derive i sa a /\ attacker_can_derive i sb b
returns attacker_knows_at i (raw_concat a b)
with _ . attacker_can_derive_concat_in_diff_steps i sa a sb b
end
let attacker_knows_split_left i l t1 t :
Lemma
(requires Success? (split_at l t1) /\ fst (Success?.v (split_at l t1)) = t)
(ensures attacker_knows_at i t1 ==> attacker_knows_at i t)
= attacker_can_derive_split_left i l t1 t
let attacker_knows_split_right i l t1 t :
Lemma
(requires Success? (split_at l t1) /\ snd (Success?.v (split_at l t1)) = t)
(ensures attacker_knows_at i t1 ==> attacker_knows_at i t)
= attacker_can_derive_split_right i l t1 t
let attacker_knows_split i l b
= let Success (t1,t2) = split_at l b in
attacker_knows_split_left i l b t1;
attacker_knows_split_right i l b t2
let attacker_knows_from_nat i sz n
= attacker_can_derive_from_nat i sz n
let string_to_pub_bytes s = string_to_bytes s
let string_to_pub_bytes_lemma t = ()
let pub_bytes_to_string #i t = bytes_to_string t
let pub_bytes_to_string_lemma #i t = ()
let nat_to_pub_bytes len s = nat_to_bytes len s
let nat_to_pub_bytes_lemma len t = ()
let pub_bytes_to_nat #i t = bytes_to_nat t
let pub_bytes_to_nat_lemma #i t = ()
let bytestring_to_pub_bytes s = bytestring_to_bytes s
let bytestring_to_pub_bytes_lemma t = ()
let pub_bytes_to_bytestring #i t = bytes_to_bytestring t
let pub_bytes_to_bytestring_lemma #i t = ()
let nat_lbytes_to_pub_bytes sz x = nat_lbytes_to_bytes sz x
let nat_lbytes_to_pub_bytes_lemma sz x = ()
let pub_bytes_to_nat_lbytes b = bytes_to_nat_lbytes b
let pub_bytes_to_nat_lbytes_lemma b = ()
#push-options "--z3rlimit 100"
val meet_derives: i:timestamp -> j:timestamp -> steps1:nat -> steps2:nat -> t1:bytes -> t2:bytes ->
Lemma (requires (attacker_can_derive i steps1 t1 /\
attacker_can_derive j steps2 t2))
(ensures (attacker_can_derive (max i j) (max steps1 steps2) t1 /\
attacker_can_derive (max i j) (max steps1 steps2) t2))
let meet_derives i j steps1 steps2 t1 t2 =
(if steps1 < steps2 then
attacker_can_derive_in_more_steps i steps1 steps2
else
attacker_can_derive_in_more_steps j steps2 steps1);
(if i < j then
attacker_can_derive_later i (max steps1 steps2) j
else
attacker_can_derive_later j (max steps1 steps2) i);
assert (attacker_can_derive (max i j) (max steps1 steps2) t1);
assert (attacker_can_derive (max i j) (max steps1 steps2) t2)
#pop-options
val meet_derives3: i:timestamp -> j:timestamp -> k:timestamp -> steps1:nat -> steps2:nat -> steps3:nat -> t1:bytes -> t2:bytes -> t3:bytes ->
Lemma (requires (attacker_can_derive i steps1 t1 /\ attacker_can_derive j steps2 t2 /\ attacker_can_derive k steps3 t3))
(ensures (attacker_can_derive (max (max i j) k) (max (max steps1 steps2) steps3) t1 /\
attacker_can_derive (max (max i j) k) (max (max steps1 steps2) steps3) t2 /\
attacker_can_derive (max (max i j) k) (max (max steps1 steps2) steps3) t3))
let meet_derives3 i j k steps1 steps2 steps3 t1 t2 t3 =
meet_derives i j steps1 steps2 t1 t2;
meet_derives (max i j) k (max steps1 steps2) steps3 t1 t3;
meet_derives (max i j) k (max steps1 steps2) steps3 t2 t3
#push-options "--z3rlimit 50 --max_fuel 1 --max_ifuel 1"
val meet_derives4 (i j k l:timestamp) (steps1 steps2 steps3 steps4:nat) (t1 t2 t3 t4:bytes):
Lemma (requires (attacker_can_derive i steps1 t1 /\ attacker_can_derive j steps2 t2
/\ attacker_can_derive k steps3 t3 /\ attacker_can_derive l steps4 t4))
(ensures (attacker_can_derive (max (max (max i j) k) l) (max (max (max steps1 steps2) steps3) steps4) t1 /\
attacker_can_derive (max (max (max i j) k) l) (max (max (max steps1 steps2) steps3) steps4) t2 /\
attacker_can_derive (max (max (max i j) k) l) (max (max (max steps1 steps2) steps3) steps4) t3 /\
attacker_can_derive (max (max (max i j) k) l) (max (max (max steps1 steps2) steps3) steps4) t4))
let meet_derives4 i j k l steps1 steps2 steps3 steps4 t1 t2 t3 t4 =
meet_derives i j steps1 steps2 t1 t2;
meet_derives (max i j) k (max steps1 steps2) steps3 t1 t3;
meet_derives (max i j) k (max steps1 steps2) steps3 t2 t3;
meet_derives (max (max i j) k) l (max (max steps1 steps2) steps3) steps4 t1 t4;
meet_derives (max (max i j) k) l (max (max steps1 steps2) steps3) steps4 t2 t4;
meet_derives (max (max i j) k) l (max (max steps1 steps2) steps3) steps4 t3 t4
#pop-options
(* Concatenate and split bytestrings *)
let incr a = a + 1
#set-options "--z3rlimit 100 --max_fuel 1 --max_ifuel 1"
let concat_len_prefixed #i ll t1 t2 =
let concat_len_prefixed_pub_lemma0 (i:timestamp) (ll:nat) (t1:bytes) (t2:bytes) (steps:nat) :
Lemma (requires (attacker_can_derive i steps t1 /\ attacker_can_derive i steps t2))
(ensures (attacker_can_derive i (steps + 1) (concat_len_prefixed ll t1 t2))) = () in
let concat_len_prefixed_pub_lemma (i j:timestamp) (ll:nat) (t1:bytes) (t2:bytes) (steps1:nat) (steps2:nat) :
Lemma (requires (attacker_can_derive i steps1 t1 /\ attacker_can_derive j steps2 t2))
(ensures (attacker_can_derive (max i j) (max steps1 steps2 + 1) (concat_len_prefixed ll t1 t2)))
[SMTPat (attacker_can_derive i steps1 t1); SMTPat (attacker_can_derive j steps2 t2);
SMTPat (concat_len_prefixed ll t1 t2)] =
meet_derives i j steps1 steps2 t1 t2;
concat_len_prefixed_pub_lemma0 (max i j) ll t1 t2 (max steps1 steps2);
assert (attacker_can_derive (max i j) (max steps1 steps2 + 1) (concat_len_prefixed ll t1 t2)) in
let c = concat_len_prefixed ll t1 t2 in
c
let concat_len_prefixed_lemma #i ll t1 t2 = ()
let split_len_prefixed #i ll t =
let split_len_prefixed_pub_lemma1 (i:timestamp) (ll:nat) (a1:bytes) (a:bytes) (a2:bytes) (steps:nat) :
Lemma (requires (attacker_can_derive i steps a1 /\ is_succ2 (split_len_prefixed ll a1) a a2))
(ensures (attacker_can_derive i (steps + 1) a))
[SMTPat (attacker_can_derive i steps a1); SMTPat (is_succ2 (split_len_prefixed ll a1) a a2)] = () in
let split_len_prefixed_pub_lemma2 (i:timestamp) (ll:nat) (a1:bytes) (a:bytes) (a2:bytes) (steps:nat) :
Lemma (requires (attacker_can_derive i steps a1 /\ is_succ2 (split_len_prefixed ll a1) a2 a))
(ensures (attacker_can_derive i (steps + 1) a))
[SMTPat (attacker_can_derive i steps a1); SMTPat (is_succ2 (split_len_prefixed ll a1) a2 a)] = () in
let b = split_len_prefixed ll t in
match b with
| Success (a1,a2) -> (
assert (is_succ2 (split_len_prefixed ll t) a1 a2);
let p1:pub_bytes i = a1 in
let p2:pub_bytes i = a2 in
assert (split_len_prefixed ll t == Success (a1,a2));
Success (a1,a2))
| Error s -> (assert (match split_len_prefixed ll t with | Error s -> True | Success _ -> False); Error s)
let split_len_prefixed_lemma #i ll t = ()
let raw_concat t1 t2 =
let raw_concat_pub_lemma0 (i:timestamp) (t1:bytes) (t2:bytes) (steps:nat) :
Lemma (requires (attacker_can_derive i steps t1 /\ attacker_can_derive i steps t2))
(ensures (attacker_can_derive i (steps + 1) (raw_concat t1 t2))) = () in
let raw_concat_pub_lemma (i j:timestamp) (t1:bytes) (t2:bytes) (steps1:nat) (steps2:nat) :
Lemma (requires (attacker_can_derive i steps1 t1 /\ attacker_can_derive j steps2 t2))
(ensures (attacker_can_derive (max i j) (max steps1 steps2 + 1) (raw_concat t1 t2)))
[SMTPat (attacker_can_derive i steps1 t1); SMTPat (attacker_can_derive j steps2 t2);
SMTPat (raw_concat t1 t2)] =
meet_derives i j steps1 steps2 t1 t2;
raw_concat_pub_lemma0 (max i j) t1 t2 (max steps1 steps2);
assert (attacker_can_derive (max i j) (max steps1 steps2 + 1) (raw_concat t1 t2)) in
raw_concat t1 t2
let raw_concat_lemma t1 t2 = ()
let split_at #i l t =
let split_pub_lemma1 (i:timestamp) (ll:nat) (a1:bytes) (a:bytes) (a2:bytes) (steps:nat) :
Lemma (requires (attacker_can_derive i steps a1 /\ is_succ2 (split_at ll a1) a a2))
(ensures (attacker_can_derive i (steps + 1) a))
[SMTPat (attacker_can_derive i steps a1); SMTPat (is_succ2 (split_at ll a1) a a2)] = () in
let split_pub_lemma2 (i:timestamp) (ll:nat) (a1:bytes) (a:bytes) (a2:bytes) (steps:nat) :
Lemma (requires (attacker_can_derive i steps a1 /\ is_succ2 (split_at ll a1) a2 a))
(ensures (attacker_can_derive i (steps + 1) a))
[SMTPat (attacker_can_derive i steps a1); SMTPat (is_succ2 (split_at ll a1) a2 a)] = () in
let b = split_at l t in
match b with
| Success (a1,a2) -> (
assert (is_succ2 (split_at l t) a1 a2);
let p1:pub_bytes i = a1 in
let p2:pub_bytes i = a2 in
assert (split_at l t == Success (a1,a2));
Success (a1,a2))
| Error s -> (assert (match split_at l t with | Error s -> True | Success _ -> False); Error s)
let split_at_lemma #i ll t = ()
(* Public key corresponding to a secret key *)
let pk #i k =
let pk_pub_lemma (i:timestamp) (s:bytes) (steps:nat) :
Lemma (requires (attacker_can_derive i steps s))
(ensures (attacker_can_derive i (steps + 1) (pk s)))
[SMTPat (attacker_can_derive i steps s)] = () in
pk k
let pk_lemma #i s = ()
(* Public key encryption *)
let pke_enc #i t1 t2 t3 =
let pke_enc_pub_lemma0 (i:timestamp) (t1 t2 t3:bytes) (steps:nat) :
Lemma (requires (attacker_can_derive i steps t1 /\ attacker_can_derive i steps t2
/\ attacker_can_derive i steps t3))
(ensures (attacker_can_derive i (steps + 1) (pke_enc t1 t2 t3)))
[SMTPat (attacker_can_derive i steps t1); SMTPat (attacker_can_derive i steps t3);
SMTPat (attacker_can_derive i steps t2)] = () in
let pke_enc_pub_lemma (i:timestamp) (t1 t2 t3:bytes) (steps1 steps2 steps3:nat):
Lemma (requires (attacker_can_derive i steps1 t1 /\ attacker_can_derive i steps2 t2 /\ attacker_can_derive i steps3 t3))
(ensures (attacker_knows_at i (pke_enc t1 t2 t3)))
[SMTPat (attacker_can_derive i steps1 t1); SMTPat (attacker_can_derive i steps2 t2); SMTPat (attacker_can_derive i steps3 t3)] =
meet_derives3 i i i steps1 steps2 steps3 t1 t2 t3 in
pke_enc t1 t2 t3
let pke_enc_lemma #i t1 t2 t3 = ()
let pke_dec #i k e =
let pke_dec_pub_lemma0 (i:timestamp) (k:bytes) (e:bytes) (p:bytes) (steps:nat):
Lemma (requires (attacker_can_derive i steps k /\
attacker_can_derive i steps e /\
is_succ (pke_dec k e) p))
(ensures (attacker_can_derive i (steps + 1) p))
[SMTPat (attacker_can_derive i steps k);
SMTPat (attacker_can_derive i steps e);
SMTPat (is_succ (pke_dec k e) p)] = () in
let pke_dec_pub_lemma (i:timestamp) (j:timestamp) (k:bytes) (e:bytes) (p:bytes) (steps1:nat) (steps2:nat):
Lemma (requires (attacker_can_derive i steps1 k /\
attacker_can_derive j steps2 e /\
is_succ (pke_dec k e) p))
(ensures (attacker_can_derive (max i j) (max steps1 steps2 + 1) p))
[SMTPat (attacker_can_derive i steps1 k);
SMTPat (attacker_can_derive j steps2 e);
SMTPat (is_succ (pke_dec k e) p)] =
meet_derives i j steps1 steps2 k e;
assert (attacker_can_derive (max i j) (max steps1 steps2 + 1) p) in
match pke_dec k e with
| Success p -> Success p
| Error s -> Error s
let pke_dec_lemma #i t1 t2 = ()
#push-options "--z3rlimit 100 --max_fuel 1 --max_ifuel 1"
let aead_enc #i t1 t2 t3 t4 =
let aead_enc_pub_lemma0 (i:timestamp) (t1 t2 t3 t4:bytes) (steps:nat) :
Lemma (requires (attacker_can_derive i steps t1 /\ attacker_can_derive i steps t2
/\ attacker_can_derive i steps t3 /\ attacker_can_derive i steps t4))
(ensures (attacker_can_derive i (steps + 1) (aead_enc t1 t2 t3 t4))) = () in
let aead_enc_pub_lemma (i:timestamp) (t1 t2 t3 t4:bytes) (steps1 steps2 steps3 steps4:nat):
Lemma (requires (attacker_can_derive i steps1 t1 /\ attacker_can_derive i steps2 t2
/\ attacker_can_derive i steps3 t3 /\ attacker_can_derive i steps4 t4))
(ensures (attacker_knows_at i (aead_enc t1 t2 t3 t4)))
[SMTPat (attacker_can_derive i steps1 t1); SMTPat (attacker_can_derive i steps2 t2);
SMTPat (attacker_can_derive i steps3 t3); SMTPat (attacker_can_derive i steps4 t4)] =
meet_derives4 i i i i steps1 steps2 steps3 steps4 t1 t2 t3 t4;
assert (max (max (max i i) i) i == i);
let msteps = max (max (max steps1 steps2) steps3) steps4 in
aead_enc_pub_lemma0 i t1 t2 t3 t4 msteps;
() in
aead_enc t1 t2 t3 t4
#pop-options
let aead_enc_lemma #i t1 t2 t3 t4 = ()
let aead_dec #i k n e ad =
let aead_dec_pub_lemma0 (i:timestamp) (k n:bytes) (e:bytes) (p:bytes) (ad:bytes) (steps:nat) :
Lemma (requires (attacker_can_derive i steps k /\
attacker_can_derive i steps n /\
attacker_can_derive i steps e /\
attacker_can_derive i steps ad /\
is_succ (aead_dec k n e ad) p))
(ensures (attacker_can_derive i (steps + 1) p))
[SMTPat (attacker_can_derive i steps k);
SMTPat (attacker_can_derive i steps n);
SMTPat (attacker_can_derive i steps e);
SMTPat (attacker_can_derive i steps ad);
SMTPat (is_succ (aead_dec k n e ad) p)] = () in
let aead_dec_pub_lemma (i:timestamp) (k n e p ad:bytes) (steps1 steps2 steps3 steps4:nat):
Lemma (requires (attacker_can_derive i steps1 k /\
attacker_can_derive i steps2 n /\
attacker_can_derive i steps3 e /\
attacker_can_derive i steps4 ad /\
is_succ (aead_dec k n e ad) p))
(ensures (attacker_knows_at i p))
[SMTPat (attacker_can_derive i steps1 k);
SMTPat (attacker_can_derive i steps2 n);
SMTPat (attacker_can_derive i steps3 e);
SMTPat (attacker_can_derive i steps4 ad);
SMTPat (is_succ (aead_dec k n e ad) p)] =
meet_derives4 i i i i steps1 steps2 steps3 steps4 k n e ad in
match aead_dec k n e ad with
| Success p ->
assert (is_succ (aead_dec k n e ad) p);
let p:pub_bytes i = p in
Success p
| Error s -> Error s
let aead_dec_lemma #i t1 t2 t3 t4 = ()
#push-options "--z3rlimit 100 --max_fuel 1 --max_ifuel 1"
let sign #i t1 t2 t3 =
let sign_pub_lemma0 (i:timestamp) (t1 t2 t3:bytes) (steps:nat) :
Lemma (requires (attacker_can_derive i steps t1 /\ attacker_can_derive i steps t2
/\ attacker_can_derive i steps t3))
(ensures (attacker_can_derive i (steps + 1) (sign t1 t2 t3)))
= () in
let sign_pub_lemma (i:timestamp) (t1 t2 t3:bytes) (steps1 steps2 steps3:nat):
Lemma (requires (attacker_can_derive i steps1 t1 /\ attacker_can_derive i steps2 t2
/\ attacker_can_derive i steps3 t3))
(ensures (attacker_knows_at i (sign t1 t2 t3)))
[SMTPat (attacker_can_derive i steps1 t1); SMTPat (attacker_can_derive i steps2 t2);
SMTPat (attacker_can_derive i steps3 t3)] =
meet_derives3 i i i steps1 steps2 steps3 t1 t2 t3;
sign_pub_lemma0 i t1 t2 t3 (max (max steps1 steps2) steps3) in
sign t1 t2 t3
#pop-options
let sign_lemma #i t1 t2 t4 = ()
let verify #i t1 t2 t3 = verify t1 t2 t3
let verify_lemma #i t1 t2 t3 = ()
let mac #i t1 t2 =
let mac_pub_lemma0 (i:timestamp) (t1:bytes) (t2:bytes) (steps:nat) :
Lemma (requires (attacker_can_derive i steps t1 /\ attacker_can_derive i steps t2))
(ensures (attacker_can_derive i (steps + 1) (mac t1 t2)))
= () in
let mac_pub_lemma (i:timestamp) (j:timestamp) (t1:bytes) (t2:bytes) (steps1:nat) (steps2:nat) :
Lemma (requires (attacker_can_derive i steps1 t1 /\ attacker_can_derive j steps2 t2))
(ensures (attacker_can_derive (max i j) (max steps1 steps2 + 1) (mac t1 t2)))
[SMTPat (attacker_can_derive i steps1 t1); SMTPat (attacker_can_derive j steps2 t2)] =
meet_derives i j steps1 steps2 t1 t2;
mac_pub_lemma0 (max i j) t1 t2 (max steps1 steps2) in
mac t1 t2
let mac_lemma #i t1 t2 = ()
let verify_mac #i t1 t2 t3 = verify_mac t1 t2 t3
let verify_mac_lemma #i t1 t2 t3 = ()
let hash #i t1 =
let hash_pub_lemma0 (i:timestamp) (t1:bytes) (steps:nat) :
Lemma (requires (attacker_can_derive i steps t1))
(ensures (attacker_can_derive i (steps + 1) (hash t1)))
= () in
let hash_pub_lemma (i:timestamp) (t1:bytes) (steps1:nat):
Lemma (requires (attacker_can_derive i steps1 t1))
(ensures (attacker_can_derive i (steps1 + 1) (hash t1)))
[SMTPat (attacker_can_derive i steps1 t1)] =
hash_pub_lemma0 i t1 steps1 in
hash t1
let hash_lemma #i t1 = ()
let dh_pk #i t1 =
let dh_pk_pub_lemma0 (i:timestamp) (t1:bytes) (steps:nat) :
Lemma (requires (attacker_can_derive i steps t1))
(ensures (attacker_can_derive i (steps + 1) (dh_pk t1)))
= () in
let dh_pk_pub_lemma (i:timestamp) (t1:bytes) (steps:nat) :
Lemma (requires (attacker_can_derive i steps t1))
(ensures (attacker_can_derive i (steps + 1) (dh_pk t1)))
[SMTPat (attacker_can_derive i steps t1)] =
dh_pk_pub_lemma0 i t1 steps in
dh_pk t1
let dh_pk_lemma #i t1 = ()
let dh #i priv_component pub_component =
let dh_pub_lemma0 (i:timestamp) (t1:bytes) (t2:bytes) (steps1:nat) (steps2:nat):
Lemma (requires (attacker_can_derive i steps1 t1) /\ (attacker_can_derive i steps2 t2))
(ensures (attacker_can_derive i ((max steps1 steps2) + 1) (dh t1 t2)))
=
let max_steps = (max steps1 steps2) in
attacker_can_derive_in_more_steps i steps1 (max_steps);
attacker_can_derive_in_more_steps i steps2 (max_steps);
assert((attacker_can_derive i (max_steps) t1));
assert((attacker_can_derive i (max_steps) t2));
() in
let dh_pub_lemma (i:timestamp) (t1:bytes) (t2:bytes) (steps1:nat) (steps2:nat):
Lemma (requires (attacker_can_derive i steps1 t1) /\ (attacker_can_derive i steps2 t2))
(ensures (attacker_can_derive i ((max steps1 steps2) + 1) (dh t1 t2)))
[SMTPat (attacker_can_derive i steps1 t1); SMTPat (attacker_can_derive i steps2 t2)]
= dh_pub_lemma0 i t1 t2 steps1 steps2 in
dh priv_component pub_component
let dh_lemma #i priv_component pub_component = ()
let global_timestamp () = global_timestamp ()
#push-options "--max_ifuel 2 --z3rlimit 200"
let pub_rand_gen u =
let t0 = get () in
let n = gen public u in
let t1 = get() in
let i = send "*" "*" n in
let t2 = get() in
assert (was_published_at (trace_len t0 + 1) n);
assert (was_published_before (trace_len t0 + 1) n);
assert (attacker_can_derive (trace_len t0+2) 0 n);
let i = global_timestamp () in
assert (i == trace_len t2);
(|i, n|)
let send #i p1 p2 a = send p1 p2 a
let receive_i i p2 =
let (_,m) = receive_i i p2 in
let n = global_timestamp () in
assert (was_published_at i m);
assert (was_published_before i m);
assert (attacker_can_derive (i+1) 0 m);
assert (attacker_knows_at (i+1) m);
let m' : pub_bytes (i+1) = m in
(| n, m |)
let compromise p s v =
let n = global_timestamp () in
compromise p s v;
n
let query_state_i idx_state idx_corrupt idx_query p si sv =
let (v,s) = get_state_i idx_state p in
assert (state_was_set_at idx_state p v s);
if Seq.length v <= si || Seq.index v si <> sv || Seq.length s <> Seq.length v
then error "cannot query state"
else
let n = global_timestamp () in
let res = s.[si] in
attacker_can_query_compromised_state idx_state idx_corrupt idx_query p si sv res;
res
let query_state #now idx_corrupt p si sv =
match get_last_state_before (now-1) p with
| Some (idx_state, _, _) -> (
query_state_i idx_state idx_corrupt now p si sv
)
| _ -> error ("No state to query found for " ^ p)