-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathRedundantHashing.eca
810 lines (690 loc) · 21.5 KB
/
RedundantHashing.eca
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
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
(* RedundantHashing.eca *)
(* Redundant Hashing *)
(* This abstract theory implements random oracles with procedures for
ordinary and redundant hashing (as well as an initialization
procedure).
There are two implementations:
A "non-optimized" one, in which redundant hashing works just like
ordinary hashing (and using the same map), but the hashing results
are discarded.
An "optimized" one in which redundant hashing does nothing.
The main lemma allows one to go back and forth between these
two implementations, as long as one only cares about an overall
boolean result. *)
prover quorum=2 ["Alt-Ergo" "Z3"]. (* both Alt-Ergo and Z3 must succeed *)
(***************************** Standard Theories ******************************)
require import AllCore Distr FSet SmtMap List.
require IterProc.
(***************************** Auxiliary Theories *****************************)
require import ListAux.
require import FSetAux.
(***************************** Theory Parameters ******************************)
type input. (* type of oracle inputs *)
type output. (* type of oracle outputs *)
(* lossless distribution on outputs *)
op doutput : output distr.
axiom doutput_ll : is_lossless doutput.
(************************** End of Theory Parameters **************************)
(* Hashing Oracles *)
module type HASHING = {
(* initialization *)
proc init() : unit
(* ordinary hashing *)
proc hash(inp : input) : output
(* redundant hashing - result ignored *)
proc rhash(inp : input) : unit
}.
(* non-optimized implementation of Hashing Oracle *)
module NonOptHashing : HASHING = {
var mp : (input, output) fmap
proc init() : unit = {
mp <- empty;
}
proc hash(inp : input) : output = {
var out : output;
if (! dom mp inp) {
out <$ doutput;
mp.[inp] <- out;
}
return oget mp.[inp];
}
proc rhash(inp : input) : unit = {
hash(inp);
}
}.
(* optimized implementation of Hashing Oracle *)
module OptHashing : HASHING = {
var mp : (input, output) fmap
proc init() : unit = {
mp <- empty;
}
proc hash(inp : input) : output = {
var out : output;
if (! dom mp inp) {
out <$ doutput;
mp.[inp] <- out;
}
return oget mp.[inp];
}
proc rhash(inp : input) : unit = { }
}.
(* Hashing Adversary *)
module type HASHING_ADV (H : HASHING) = {
proc main() : bool {H.hash H.rhash}
}.
(* games based on the two implementations of hashing *)
module GNonOptHashing (HashAdv : HASHING_ADV) = {
module HA = HashAdv(NonOptHashing)
proc main() : bool = {
var b : bool;
NonOptHashing.init();
b <@ HA.main();
return b;
}
}.
module GOptHashing (HashAdv : HASHING_ADV) = {
module HA = HashAdv(OptHashing)
proc main() : bool = {
var b : bool;
OptHashing.init();
b <@ HA.main();
return b;
}
}.
(* see end of section for main lemma *)
section.
(* our proof uses EasyCrypt's eager tactics, but the idea behind the
proof is simple: we can repeatedly postpone redundant hashing,
until the point when it is (non-redundantly) hashed or the hashing
adversary has already returned its boolean result (and so oracle
map equality is no longer of interest) *)
declare module HashAdv : HASHING_ADV{NonOptHashing, OptHashing}.
(* extended hashing module interface
implementations include two global variables: the oracle's map,
plus a record of which inputs are *redundant* - i.e., have been
supplied to rhash but not to hash
some of the details of the two implementations that follow can be
best understood by reading the subsequent proofs *)
module type HASHING' = {
(* initialization *)
proc init() : unit
(* ordinary hashing *)
proc hash(inp : input) : output
(* redundant hashing - result ignored *)
proc rhash(inp : input) : unit
(* rehash redundant inputs *)
proc rehash_red_inps() : unit
(* rehash redundant inputs, and then look up value of inp *)
proc rehash_red_inps_rslt(inp : input) : output
(* hash inp either before or after (depending on the implementation)
rehashing redundant inputs, returning value of inp (obtained
immediately after hashing it) *)
proc rehash_red_inps_addl(inp : input) : output
}.
(* so we can use iteration over inputs *)
local clone include IterProc with type t <- input
proof *.
(* nothing to realize *)
(* non-optimized implementation *)
local module NOH' : HASHING, HASHING' = {
var mp : (input, output) fmap
var red_inps : input fset
proc init() : unit = {
mp <- empty; red_inps <- fset0;
}
proc hash(inp : input) : output = {
var out : output;
if (! dom mp inp) {
out <$ doutput;
mp.[inp] <- out;
}
else {
(* if inp was redundant it's no longer so *)
red_inps <- red_inps `\` fset1 inp;
}
return oget mp.[inp];
}
proc rhash(inp : input) : unit = {
var out : output;
if (! dom mp inp) {
out <$ doutput;
mp.[inp] <- out;
(* inp is redundant *)
red_inps <- red_inps `|` fset1 inp;
}
}
module I = {
proc f (inp : input) = {
var out : output;
out <$ doutput;
mp.[inp] <- out;
}
}
proc rehash_red_inps() = {
Iter(I).iter(elems red_inps);
}
proc rehash_red_inps_rslt(inp : input) : output = {
var out : output;
rehash_red_inps();
out <- oget mp.[inp];
return out;
}
proc rehash_red_inps_addl(inp : input) : output = {
var out : output;
rehash_red_inps();
out <$ doutput; (* after *)
mp.[inp] <- out;
out <- oget mp.[inp]; (* makes easier to use *)
return out;
}
}.
(* optimized implementation *)
local module OH' : HASHING, HASHING' = {
var mp : (input, output) fmap
var red_inps : input fset
proc init() : unit = {
mp <- empty; red_inps <- fset0;
}
proc hash(inp : input) : output = {
var out : output;
(* the second disjunct is needed for the proof of
lemma eager_hash, because there we can't use
the invariant:
forall inp', mem red_inps inp' => ! dom mp inp' *)
if (! dom mp inp \/ mem red_inps inp) {
out <$ doutput;
mp.[inp] <- out;
red_inps <- red_inps `\` fset1 inp;
}
return oget mp.[inp];
}
proc rhash(inp : input) : unit = {
if (! dom mp inp) {
red_inps <- red_inps `|` fset1 inp;
}
}
module I = {
proc f (inp : input) = {
var out : output;
out <$ doutput;
mp.[inp] <- out;
}
}
proc rehash_red_inps() = {
Iter(I).iter(elems red_inps);
}
proc rehash_red_inps_rslt(inp : input) : output = {
var out : output;
rehash_red_inps();
out <- oget mp.[inp];
return out;
}
proc rehash_red_inps_addl(inp : input) : output = {
var out : output;
out <$ doutput; (* before *)
mp.[inp] <- out;
out <- oget mp.[inp]; (* makes easier to use *)
rehash_red_inps();
return out;
}
}.
local lemma OH'_rehash_red_inps_ll :
islossless OH'.rehash_red_inps.
proof.
proc.
call (iter_ll OH'.I _).
proc; auto; progress; apply doutput_ll.
auto.
qed.
local lemma NOH'_rehash_red_inps_empty_preserves_map mp':
phoare
[NOH'.rehash_red_inps :
NOH'.mp = mp' /\ NOH'.red_inps = fset0 ==>
NOH'.mp = mp'] = 1%r.
proof.
proc.
inline*.
seq 1 : (l = [] /\ NOH'.mp = mp'); first auto.
auto; smt(elems_fset0).
rcondf 1; auto.
hoare; auto; smt(elems_fset0).
trivial.
qed.
(* games based on the two extended hashing implementations,
where adversay only gets access to hash and rhash *)
local module GNOH' = {
module HA = HashAdv(NOH')
proc main() : bool = {
var b : bool;
NOH'.init();
b <@ HA.main();
return b;
}
}.
local module GOH' = {
module HA = HashAdv(OH')
proc main() : bool = {
var b : bool;
OH'.init();
b <@ HA.main();
return b;
}
}.
(* moving from NonOptHashing to NOH' *)
local lemma NonOptHashing_NOH'_hash :
equiv
[NonOptHashing.hash ~ NOH'.hash :
={inp} /\ ={mp}(NonOptHashing, NOH') ==>
={res} /\ ={mp}(NonOptHashing, NOH')].
proof.
proc; if => //; auto.
qed.
local lemma NonOptHashing_NOH'_rhash :
equiv
[NonOptHashing.rhash ~ NOH'.rhash :
={inp} /\ ={mp}(NonOptHashing, NOH') ==>
={res} /\ ={mp}(NonOptHashing, NOH')].
proof.
proc; inline NonOptHashing.hash; sp.
if => //; auto.
qed.
local lemma GNonOptHashing_GNOH'_main :
equiv
[GNonOptHashing(HashAdv).main ~ GNOH'.main :
={glob HashAdv} ==> ={res}].
proof.
proc; inline NonOptHashing.init NOH'.init.
seq 1 2 : (={glob HashAdv} /\ ={mp}(NonOptHashing, NOH')).
auto.
call (_ : ={mp}(NonOptHashing, NOH')).
apply NonOptHashing_NOH'_hash.
apply NonOptHashing_NOH'_rhash.
auto.
qed.
local lemma GNonOptHashing_GNOH' &m :
Pr[GNonOptHashing(HashAdv).main() @ &m : res] = Pr[GNOH'.main() @ &m : res].
proof. by byequiv GNonOptHashing_GNOH'_main. qed.
(* moving from OH' to OptHashing *)
local lemma OH'_OptHashing_hash :
equiv
[OH'.hash ~ OptHashing.hash:
={inp} /\ ={mp}(OH', OptHashing) /\
(forall (inp' : input),
mem OH'.red_inps{1} inp' => ! dom OH'.mp{1} inp') ==>
={res} /\ ={mp}(OH', OptHashing) /\
(forall (inp' : input),
mem OH'.red_inps{1} inp' => ! dom OH'.mp{1} inp')].
proof.
proc.
if.
smt().
auto; progress;
rewrite -mem_fdom fdom_set in_fsetU1 negb_or; smt(in_fsetD1 mem_fdom).
auto.
qed.
local lemma OH'_OptHashing_rhash :
equiv
[OH'.rhash ~ OptHashing.rhash:
={inp} /\ ={mp}(OH', OptHashing) /\
(forall (inp' : input),
mem OH'.red_inps{1} inp' => ! dom OH'.mp{1} inp') ==>
={res} /\ ={mp}(OH', OptHashing) /\
(forall (inp' : input),
mem OH'.red_inps{1} inp' => ! dom OH'.mp{1} inp')].
proof.
proc; auto; progress; smt(fdom_set mem_fdom in_fsetU1 in_fsetD1).
qed.
local lemma GOH'_GOptHashing_main :
equiv
[GOH'.main ~ GOptHashing(HashAdv).main :
={glob HashAdv} ==> ={res}].
proof.
proc; inline OH'.init OptHashing.init.
seq 2 1 :
(={glob HashAdv} /\ ={mp}(OH', OptHashing) /\
(forall (inp' : input),
mem OH'.red_inps{1} inp' => ! dom OH'.mp{1} inp')).
auto; smt(in_fset0).
call
(_ :
={mp}(OH', OptHashing) /\
(forall (inp' : input),
mem OH'.red_inps{1} inp' => ! dom OH'.mp{1} inp')).
apply OH'_OptHashing_hash.
apply OH'_OptHashing_rhash.
auto.
qed.
local lemma GOH'_GOptHashing &m :
Pr[GOH'.main() @ &m : res] = Pr[GOptHashing(HashAdv).main() @ &m : res].
proof. by byequiv GOH'_GOptHashing_main. qed.
(* middle step of sequence of games *)
local lemma NOH'_rehash_red_inps_red_dom (inp' : input) :
hoare
[NOH'.rehash_red_inps :
mem NOH'.red_inps inp' ==> dom NOH'.mp inp'].
proof.
proc; inline*; sp.
while (mem l inp' \/ dom NOH'.mp inp').
auto; progress;
rewrite -mem_fdom fdom_set in_fsetU1; smt(mem_fdom mem_ne_list_drop1).
auto; smt(memE).
qed.
local lemma NOH'_rehash_red_inps_not_red_not_dom (inp' : input) :
hoare
[NOH'.rehash_red_inps :
! mem NOH'.red_inps inp' /\ ! dom NOH'.mp inp' ==>
! dom NOH'.mp inp'].
proof.
proc; inline*; sp.
while (! mem l inp' /\ ! dom NOH'.mp inp').
auto; progress;
[smt(mem_ne_list_drop1) |
rewrite -mem_fdom fdom_set in_fsetU1 mem_fdom;
smt(mem_ne_list_drop1)].
auto; smt(memE).
qed.
local lemma NOH'_rehash_red_inps_not_red_dom (inp' : input) :
hoare
[NOH'.rehash_red_inps :
! mem NOH'.red_inps inp' /\ dom NOH'.mp inp' ==>
dom NOH'.mp inp'].
proof.
proc; inline*; sp.
while (dom NOH'.mp inp').
auto; progress.
rewrite -mem_fdom fdom_set in_fsetU1 mem_fdom /#.
auto.
qed.
local lemma NOH'_OH'_rehash_red_inps_indep_pres
(inp : input, out : output) :
equiv
[NOH'.rehash_red_inps ~ OH'.rehash_red_inps :
={mp, red_inps}(NOH', OH') /\ ! mem NOH'.red_inps{1} inp /\
oget NOH'.mp{1}.[inp] = out ==>
NOH'.mp{1} = OH'.mp{2} /\ oget NOH'.mp{1}.[inp] = out].
proof.
proc; inline*; sp.
while
(={l} /\ NOH'.mp{1} = OH'.mp{2} /\
! mem l{1} inp /\ oget NOH'.mp{1}.[inp] = out).
auto; progress; [smt(mem_drop) | smt(mem_ne_list_drop1 get_setE)].
auto; smt(memE).
qed.
local lemma NOH'_OH'_rehash_red_inps_addl_not_red :
equiv
[NOH'.rehash_red_inps_addl ~ OH'.rehash_red_inps_addl :
={inp} /\ ={mp, red_inps}(NOH', OH') /\
! mem NOH'.red_inps{1} inp{1} ==>
={res} /\ NOH'.mp{1} = OH'.mp{2}].
proof.
proc.
swap{1} 2 -1.
seq 1 1 :
(={inp, out} /\ ={mp, red_inps}(NOH', OH') /\
! mem NOH'.red_inps{1} inp{1}); first auto.
inline*; swap{2} 3 -2.
seq 1 1 :
(={inp, out, l} /\ ={mp, red_inps}(NOH', OH') /\
! mem l{1} inp{1}); first auto; smt(memE).
wp; sp.
while
(={inp, l} /\ ! mem l{1} inp{1} /\
NOH'.red_inps{1} = OH'.red_inps{2} /\
NOH'.mp{1}.[inp{1} <- out{1}] = OH'.mp{2}).
auto; progress;
[smt(mem_drop) |
rewrite 2!set_setE; smt(mem_ne_list_drop1)].
auto; progress; by rewrite 2!get_set_sameE oget_some.
qed.
(* lemma for using iters_perm *)
local lemma iter_perm2 :
equiv
[Iter(NOH'.I).iter_12 ~ Iter(NOH'.I).iter_21 :
={glob NOH'.I, t1, t2} ==> ={glob NOH'.I}].
proof.
proc => /=; inline*; sp.
case (t1{1} = t2{1}); first auto.
swap 3 -2.
swap{1} 4 -1.
swap{2} 4 -2.
auto; progress; rewrite set_setE /#.
qed.
local lemma NOH'_rehash_red_inps_rslt_rehash_red_inps_addl :
equiv
[NOH'.rehash_red_inps_rslt ~ NOH'.rehash_red_inps_addl :
={inp, NOH'.mp} /\ ! mem NOH'.red_inps{2} inp{1} /\
NOH'.red_inps{1} = NOH'.red_inps{2} `|` fset1 inp{1} ==>
={res, NOH'.mp}].
proof.
proc; inline NOH'.rehash_red_inps; wp 1 3.
conseq (_ : _ ==> ={NOH'.mp}) => //.
transitivity*{2}
{ Iter(NOH'.I).iters(elems NOH'.red_inps, [inp]); } => //.
progress; by exists NOH'.mp{2} NOH'.red_inps{2} inp{2} out{2}.
symmetry.
call (iters_perm NOH'.I iter_perm2).
auto; progress.
rewrite setUE elems_fset1.
have {1}<- :
undup(elems NOH'.red_inps{1} ++ [inp{1}]) =
elems NOH'.red_inps{1} ++ [inp{1}]
by rewrite undup_id 1:cat_uniq 1:uniq_elems /= 1:-memE.
rewrite FSet.oflistK.
inline Iter(NOH'.I).iters; inline{1} (2) Iter(NOH'.I).iter.
seq 4 1 : (={inp, NOH'.mp, NOH'.red_inps} /\ l{1} = [inp{1}]).
sp; wp.
call (_ : ={glob NOH'.I}); first sim.
auto.
rcondt{1} 1; first auto.
inline{1} (1) NOH'.I.f.
seq 4 2 : (={NOH'.mp} /\ l{1} = []); first auto.
rcondf{1} 1; auto.
qed.
local lemma NOH'_rehash_red_inps_rslt_OH'_rehash_red_inps :
equiv
[NOH'.rehash_red_inps_rslt ~ OH'.rehash_red_inps :
={mp, red_inps}(NOH', OH') ==> ={mp, red_inps}(NOH', OH')].
proof.
proc*; inline NOH'.rehash_red_inps_rslt; wp; sp.
call (_ : ={mp, red_inps}(NOH', OH')); first sim.
auto.
qed.
(* now we use the eager tactics: *)
local lemma eager_hash :
eager
[NOH'.rehash_red_inps(); , NOH'.hash ~
OH'.hash, OH'.rehash_red_inps(); :
={inp} /\ ={mp, red_inps}(NOH', OH') ==>
={res} /\ ={mp, red_inps}(NOH', OH')].
proof.
eager proc.
case (mem NOH'.red_inps{1} inp{1}).
rcondt{2} 1; first auto; smt().
rcondf{1} 2; first auto; call (NOH'_rehash_red_inps_red_dom inp{m}); auto.
swap{1} 2 1. swap{2} 3 -2. wp 2 5; sp; elim* => red_inps_R.
conseq
(_ :
={inp} /\ NOH'.mp{1} = OH'.mp{2} /\ ! mem OH'.red_inps{2} inp{1} /\
NOH'.red_inps{1} = OH'.red_inps{2} `|` fset1 inp{1} ==>
={result} /\ NOH'.mp{1} = OH'.mp{2}) => //.
progress;
[smt(in_fsetD1) |
rewrite fsetP; smt(in_fsetU1 in_fsetU in_fsetD1 in_fset1)].
transitivity{1}
{ result <@ NOH'.rehash_red_inps_rslt(inp); }
(={inp, NOH'.mp, NOH'.red_inps} ==> ={result, NOH'.mp, NOH'.red_inps})
(={inp} /\ ={mp}(NOH', OH') /\ ! mem OH'.red_inps{2} inp{1} /\
NOH'.red_inps{1} = OH'.red_inps{2} `|` fset1 inp{1} ==>
={result} /\ ={mp}(NOH', OH')) => //.
progress; by exists OH'.mp{2} (OH'.red_inps{2} `|` fset1 inp{2}) inp{2}.
inline NOH'.rehash_red_inps_rslt; sim.
transitivity{1}
{ result <@ NOH'.rehash_red_inps_addl(inp); }
(={inp, NOH'.mp} /\
! mem NOH'.red_inps{2} inp{1} /\
NOH'.red_inps{1} = NOH'.red_inps{2} `|` fset1 inp{1} ==>
={result} /\ ={mp}(NOH', NOH'))
(={inp} /\ ={mp, red_inps}(NOH', OH') /\
! mem OH'.red_inps{2} inp{1} ==>
={result} /\ ={mp}(NOH', OH')) => //.
progress; by exists OH'.mp{2} OH'.red_inps{2} inp{2}.
call NOH'_rehash_red_inps_rslt_rehash_red_inps_addl; auto.
transitivity{2}
{ result <@ OH'.rehash_red_inps_addl(inp); }
(={inp} /\ ={mp, red_inps}(NOH', OH') /\ ! mem NOH'.red_inps{1} inp{1} ==>
={result} /\ ={mp}(NOH', OH'))
(={inp, OH'.mp, OH'.red_inps} ==> ={result, OH'.mp}) => //.
progress; by exists OH'.mp{2} OH'.red_inps{2} inp{2}.
call NOH'_OH'_rehash_red_inps_addl_not_red; auto.
inline OH'.rehash_red_inps_addl; sim.
(* second case: ! mem NOH'.red_inps{1} inp{1} *)
case (! dom NOH'.mp{1} inp{1}).
rcondt{2} 1; first auto; smt().
rcondt{1} 2;
first auto; call (NOH'_rehash_red_inps_not_red_not_dom inp{m}); auto.
swap{2} 3 -2.
seq 0 1 :
(={inp} /\ NOH'.mp{1} = OH'.mp{2} /\ NOH'.red_inps{1} = OH'.red_inps{2} /\
! mem NOH'.red_inps{1} inp{1}).
auto; progress.
rewrite fsetP => inp; smt(in_fsetD1).
transitivity{1}
{ result <@ NOH'.rehash_red_inps_addl(inp); }
(={inp, NOH'.mp, NOH'.red_inps} ==> ={result, NOH'.mp, NOH'.red_inps})
(={inp} /\ ={mp, red_inps}(NOH', OH') /\ ! mem NOH'.red_inps{1} inp{1} ==>
={result} /\ ={mp, red_inps}(NOH', OH')) => //.
progress; by exists OH'.mp{2} OH'.red_inps{2} inp{2}.
inline NOH'.rehash_red_inps_addl; sim.
transitivity{2}
{ result <@ OH'.rehash_red_inps_addl(inp); }
(={inp} /\ ={mp, red_inps}(NOH', OH') /\ ! mem NOH'.red_inps{1} inp{1} ==>
={result} /\ ={mp, red_inps}(NOH', OH'))
(={inp, OH'.mp, OH'.red_inps} ==> ={result, OH'.mp, OH'.red_inps}) => //.
progress; exists OH'.mp{2} OH'.red_inps{2} inp{2}.
progress; by exists OH'.mp{2} OH'.red_inps{2} inp{2}.
call NOH'_OH'_rehash_red_inps_addl_not_red; auto.
inline OH'.rehash_red_inps_addl; sim.
(* second subcase: mem (dom NOH'.mp{1}) inp{1} *)
rcondf{2} 1; first auto; smt().
rcondf{1} 2;
first auto; call (NOH'_rehash_red_inps_not_red_dom inp{m}); auto.
wp; sp.
exists* inp{1}; elim* => inp'. exists* result{2}; elim* => out'.
call (NOH'_OH'_rehash_red_inps_indep_pres inp' out').
auto; progress; by rewrite minus1_not_mem.
qed.
local lemma eager_rhash :
eager
[NOH'.rehash_red_inps(); , NOH'.rhash ~
OH'.rhash, OH'.rehash_red_inps(); :
={inp} /\ ={mp, red_inps}(NOH', OH') ==>
={res} /\ ={mp, red_inps}(NOH', OH')].
proof.
eager proc.
case (mem NOH'.red_inps{1} inp{1}).
seq 0 1 :
(={inp} /\ NOH'.mp{1} = OH'.mp{2} /\ NOH'.red_inps{1} = OH'.red_inps{2} /\
mem NOH'.red_inps{1} inp{1}).
if{2} => //.
auto; progress.
rewrite fsetUC subset_fsetU_id //.
move => x; by rewrite in_fset1.
rcondf{1} 2; auto.
call{1} (NOH'_rehash_red_inps_red_dom inp{m}); auto.
sim.
case (dom NOH'.mp{1} inp{1}).
rcondf{2} 1; first auto. rcondf{1} 2; auto.
call (NOH'_rehash_red_inps_not_red_dom inp{m}); auto.
sim.
rcondt{2} 1; first auto. rcondt{1} 2; first auto.
call (NOH'_rehash_red_inps_not_red_not_dom inp{m}); auto.
wp 3 2; sp; elim* => red_inps_R.
conseq
(_ :
={inp} /\ ={mp}(NOH', OH') /\ ! mem NOH'.red_inps{1} inp{1} /\
NOH'.red_inps{1} `|` fset1 inp{1} = OH'.red_inps{2} ==>
NOH'.mp{1} = OH'.mp{2}) => //.
transitivity{1}
{ out <@ NOH'.rehash_red_inps_addl(inp); }
(={inp, NOH'.mp, NOH'.red_inps} /\ ! mem NOH'.red_inps{1} inp{1} ==>
={out, NOH'.mp})
(={inp} /\ ={mp}(NOH', OH') /\ ! mem NOH'.red_inps{1} inp{1} /\
NOH'.red_inps{1} `|` fset1 inp{1} = OH'.red_inps{2} ==>
={mp}(NOH', OH')) => //.
progress; by exists OH'.mp{2} NOH'.red_inps{1} inp{2}.
inline NOH'.rehash_red_inps_addl; sp; wp; rnd.
call (_ : ={NOH'.mp, NOH'.red_inps}); first sim.
skip; progress; by rewrite get_set_sameE.
transitivity{1}
{ out <@ NOH'.rehash_red_inps_rslt(inp); }
(={inp, NOH'.mp} /\ ! mem NOH'.red_inps{1} inp{1} /\
NOH'.red_inps{1} `|` fset1 inp{1} = NOH'.red_inps{2} ==>
={NOH'.mp})
(={inp} /\ ={mp, red_inps}(NOH', OH') ==> ={mp}(NOH', OH')) => //.
progress; by exists OH'.mp{2} (NOH'.red_inps{1} `|` fset1 inp{2}) inp{2}.
symmetry.
call NOH'_rehash_red_inps_rslt_rehash_red_inps_addl; auto.
call NOH'_rehash_red_inps_rslt_OH'_rehash_red_inps; auto.
qed.
(* now we use eager_hash and eager_rhash to prove: *)
local lemma eager_hashing_adv :
eager
[NOH'.rehash_red_inps(); , HashAdv(NOH').main ~
HashAdv(OH').main, OH'.rehash_red_inps(); :
={glob HashAdv} /\ ={mp, red_inps}(NOH', OH') ==>
={res} /\ ={mp, red_inps}(NOH', OH')].
proof.
eager proc
(base : NOH'.rehash_red_inps(); ~ OH'.rehash_red_inps(); :
={mp, red_inps}(NOH', OH') ==> ={mp, red_inps}(NOH', OH'))
(={mp, red_inps}(NOH', OH')) => //.
sim.
apply eager_hash.
sim.
apply eager_rhash.
sim.
qed.
(* finish the middle step: *)
local lemma GNOH'_GOH' &m :
Pr[GNOH'.main() @ &m : res] = Pr[GOH'.main() @ &m : res].
proof.
byequiv => //; proc.
seq 1 1 :
(={glob HashAdv} /\ ={mp, red_inps}(NOH', OH') /\
NOH'.red_inps{1} = fset0).
inline*; auto.
transitivity{1}
{ NOH'.rehash_red_inps(); b <@ GNOH'.HA.main(); }
(={glob HashAdv} /\ ={NOH'.mp, NOH'.red_inps} /\
NOH'.red_inps{1} = fset0 ==>
={b})
(={glob HashAdv} /\ ={mp, red_inps}(NOH', OH') ==> ={b}) => //.
progress; by exists (glob HashAdv){2} OH'.mp{2} fset0.
seq 0 1 : (={glob HashAdv} /\ ={NOH'.mp, NOH'.red_inps}).
exists* NOH'.mp{2}; elim* => mp'.
call{2} (NOH'_rehash_red_inps_empty_preserves_map mp'); auto.
sim.
transitivity{2}
{ b <@ GOH'.HA.main(); OH'.rehash_red_inps(); }
(={glob HashAdv} /\ ={mp, red_inps}(NOH', OH') ==> ={b})
(={glob HashAdv} /\ ={OH'.mp, OH'.red_inps} ==> ={b}) => //.
progress; by exists (glob HashAdv){2} OH'.mp{2} OH'.red_inps{2}.
eager call eager_hashing_adv; auto.
call{1} OH'_rehash_red_inps_ll.
sim.
qed.
(* putting it all together *)
lemma GNonOptHashing_GOH' &m :
Pr[GNonOptHashing(HashAdv).main() @ &m : res] =
Pr[GOptHashing(HashAdv).main() @ &m : res].
proof.
by rewrite (GNonOptHashing_GNOH' &m)
(GNOH'_GOH' &m)
(GOH'_GOptHashing &m).
qed.
end section.
lemma GNonOptHashing_GOptHashing
(HashAdv <: HASHING_ADV{NonOptHashing, OptHashing}) &m :
Pr[GNonOptHashing(HashAdv).main() @ &m : res] =
Pr[GOptHashing(HashAdv).main() @ &m : res].
proof. apply (GNonOptHashing_GOH' HashAdv &m). qed.