-
Notifications
You must be signed in to change notification settings - Fork 0
/
Client.ec
3037 lines (2759 loc) · 92.8 KB
/
Client.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
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
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
(* Client.ec *)
(* Proof of Security Against Client *)
prover quorum=2 ["Alt-Ergo" "Z3"]. (* both Alt-Ergo and Z3 must succeed *)
(************* PCR Protocol and Supporting Definitions and Lemmas *************)
require import Protocol.
(********************************* Adversary **********************************)
(* Adversary's hashing budget *)
op adv_budget : int.
axiom adv_budget_ge0 : 0 <= adv_budget.
(* maximum number of distinct elements in database chosen by Adversary *)
op db_uniqs_max : int.
axiom db_uniqs_max_ge0 : 0 <= db_uniqs_max.
(* maximum number of queries that may be made by Adversary *)
op qrys_max : int.
axiom qrys_max_ge0 : 0 <= qrys_max.
(* total hashing budget, either performed directly by Adversary, or
performed by Protocol due to Adversary's choices of
database/queries *)
op budget : int = adv_budget + db_uniqs_max + qrys_max.
lemma budget_ge0 : 0 <= budget.
proof.
rewrite /budget addz_ge0 1:addz_ge0 1:adv_budget_ge0
1:db_uniqs_max_ge0 qrys_max_ge0.
qed.
(* the following axiom implies that hash collisions aren't *forced*,
if no more than budget hash tags are chosen *)
axiom budget_ub : budget <= 2 ^ tag_len.
(* Adversary is limited via counted random oracle *)
clone RO.Counted as CRO with
op budget <- adv_budget
proof *.
(* beginning of realization *)
realize budget_ge0. apply adv_budget_ge0. qed.
(* end of realization *)
(* Adversary module type, parameterized by a counted random oracle *)
module type ADV(O : CRO.COR) = {
(* all procedures are supplied the current Client view
init_and_get_db, get_qry and qry_done may call O.chash (counted
hashing); final may call O.hash (ordinary hashing) *)
(* initialize Adversary, and try to get a database from it; None
means refusal *)
proc init_and_get_db(cv : client_view) : db option {O.chash}
(* try to get a query from Adversary; None means done supplying queries *)
proc get_qry(cv : client_view) : elem option {O.chash}
(* tell the Adversary that done processing its last query *)
proc qry_done(cv : client_view) : unit {O.chash}
(* finalize the Adversary, which returns its boolean judgment *)
proc final(cv : client_view) : bool {O.hash}
}.
(*************************** Real and Ideal Games *****************************)
(* the "real" game
parameterized by Adversary, which has counted access to random
oracle (meaning it may do unlimited hashing, but it's monitored for
whether it stays within budget) *)
module GReal(Adv : ADV) : GAME = {
module Or = RO.Or (* random oracle *)
module COr = CRO.COr(Or) (* counted random oracle built from Or *)
module A = Adv(COr) (* specialization of Adversary to COr *)
(* custom environment to be passed to Protocol *)
module Env : ENV = {
var qrys_ctr : int (* number of queries processed *)
proc init_and_get_db() : db option = {
var db_opt : db option; var adv_within_budg : bool;
qrys_ctr <- 0;
COr.init(); (* Or.init is called by Protocol.main *)
db_opt <@ A.init_and_get_db(Protocol.cv);
if (db_opt <> None) {
(* if too many elements in oget db_opt or Adversary has
already exceeded its hashing budget, return None *)
adv_within_budg <@ COr.within_budget();
if (db_uniqs_max < num_uniqs(oget db_opt) \/ !adv_within_budg) {
db_opt <- None;
}
}
return db_opt;
}
proc get_qry() : elem option = {
var qry_opt : elem option;
var adv_within_budg : bool;
qry_opt <@ A.get_qry(Protocol.cv);
if (qry_opt <> None) {
(* if too many queries have been processed or Adversary has
exceeded its hashing budget, return None; otherwise note
that one more query has been processed *)
adv_within_budg <@ COr.within_budget();
if (qrys_ctr < qrys_max /\ adv_within_budg) {
qrys_ctr <- qrys_ctr + 1;
}
else {
qry_opt <- None;
}
}
return qry_opt;
}
proc put_qry_count(cnt : int) : unit = {
(* ignore the count, but Protocol.cv contains
it *)
A.qry_done(Protocol.cv);
}
proc final() : bool = {
var b : bool;
b <@ A.final(Protocol.cv);
return b;
}
}
proc main() : bool = {
var b : bool;
b <@ Protocol(Env).main();
return b;
}
}.
(* Client's Simulator's interface to Ideal Game *)
module type SIG = {
(* ask Ideal Game for next query along with its count; None means no
more queries
this involves the Ideal Game communicating with Adversary *)
proc get_qry_count(cv : client_view) : (elem * int) option
(* say that done processing a query *)
proc qry_done(cv : client_view) : unit
}.
(* module type for Client's Simulator
parameterized by random oracle and Simulator's interface to Ideal
Game, SIG
only client_loop may call procedures of SIG or O (Simulator can't
directly use RO.Or because of module restriction in top-level
theorem) *)
module type SIM(O : RO.OR, SIG : SIG) = {
(* initialization *)
proc init() : unit { (* no use of O, SIG *) }
(* get current view *)
proc get_view() : client_view { (* no use of O, SIG *) }
(* run the Client's query loop *)
proc client_loop() : unit {O.hash, SIG.get_qry_count, SIG.qry_done}
}.
(* the "ideal" game
parameterized by Adversary and Simulator for Client
database is turned into elements counts map, which is used for
processing Simulator's queries *)
module GIdeal (Adv : ADV, Sim : SIM) : GAME = {
module Or = RO.Or (* random oracle *)
module COr = CRO.COr(Or) (* counted random oracle built from Or *)
module A = Adv(COr) (* specialization of Adversary to COr *)
var db_elems_cnts : elems_counts (* elements counts map for database *)
var qrys_ctr : int (* number queries processed *)
(* turn database into elements counts map *)
proc count_db(db : db) : unit = {
var i : int; var elem : elem;
db_elems_cnts <- empty_ec; i <- 0;
while (i < size db) {
elem <- nth elem_default db i;
db_elems_cnts <- incr_count db_elems_cnts elem;
i <- i + 1;
}
}
(* Simulator's interface to Ideal Game *)
module SIG : SIG = {
proc get_qry_count(cv : client_view) : (elem * int) option = {
var qry_opt : elem option;
var qry_cnt_opt : (elem * int) option;
var adv_within_budg : bool; var cnt : int;
qry_opt <@ A.get_qry(cv);
if (qry_opt = None) {
qry_cnt_opt <- None;
}
else {
(* has Adversary proposed too many queries or exceeded its
hashing budget? *)
adv_within_budg <@ COr.within_budget();
if (qrys_ctr < qrys_max /\ adv_within_budg) {
qrys_ctr <- qrys_ctr + 1;
cnt <- get_count db_elems_cnts (oget qry_opt);
qry_cnt_opt <- Some (oget qry_opt, cnt);
}
else {
qry_cnt_opt <- None;
}
}
return qry_cnt_opt;
}
proc qry_done(cv : client_view) : unit = {
A.qry_done(cv);
}
}
(* connect Simulator with Or and SIG *)
module S = Sim(Or, SIG)
proc main() : bool = {
var db_opt : db option; var b : bool; var adv_within_budg : bool;
var cv : client_view;
qrys_ctr <- 0; S.init();
Or.init(); COr.init();
cv <@ S.get_view(); db_opt <@ A.init_and_get_db(cv);
if (db_opt <> None) {
(* if too many elements in oget db_opt or Adversary has already
exceeded its hashing budget, then skip main part of game *)
adv_within_budg <@ COr.within_budget();
if (num_uniqs(oget db_opt) <= db_uniqs_max /\ adv_within_budg) {
(* turn oget db_opt into elements counts map, db_elems_cnts;
nothing else is done with oget db_opt *)
count_db(oget db_opt);
S.client_loop(); (* run the Simulator's client loop *)
}
}
cv <@ S.get_view(); b <@ A.final(cv);
return b;
}
}.
(* see end-of-file for top-level theorem *)
(********************************* Proof Body *********************************)
(* Client's Simulator *)
module (Sim : SIM) (O : RO.OR, SIG : SIG) = {
var cv : client_view
var sec : sec
proc init() : unit = {
sec <$ sec_distr;
cv <- [cv_got_sec sec];
}
proc get_view() : client_view = {
return cv;
}
proc client_loop() : unit = {
var tag : tag; var qry : elem; var cnt : int;
var qry_cnt_opt : (elem * int) option;
var not_done : bool <- true;
while (not_done) {
qry_cnt_opt <@ SIG.get_qry_count(cv);
if (qry_cnt_opt = None) {
not_done <- false;
cv <- cv ++ [cv_got_qry None];
}
else {
(qry, cnt) <- oget qry_cnt_opt;
cv <- cv ++ [cv_got_qry (Some qry)];
tag <@ O.hash((qry, sec));
cv <- cv ++ [cv_query_count(qry, tag, cnt)];
SIG.qry_done(cv);
}
}
}
}.
(************************* Theories Supporting Proof **************************)
(* injective maps *)
require import Inj.
(* numbers of occurrences of elements in lists *)
require import NumOccs.
(* iteration over lists *)
require IterProc. (* abstract theory *)
(******************************** Proof Section *******************************)
(* the rest of the proof is within a section, in which the Adversary,
Adv, is declared locally *)
section.
(* declare Adversary module -- subsequent games will reference it, instead
of being parameterized by it *)
declare module Adv <: ADV{-GReal, -GIdeal, -Sim}.
(* these axioms will be preconditions of the lemma we export
from section *)
declare axiom init_and_get_db_ll :
forall (O <: CRO.COR{-Adv}),
islossless O.chash => islossless Adv(O).init_and_get_db.
declare axiom get_qry_ll :
forall (O <: CRO.COR{-Adv}),
islossless O.chash => islossless Adv(O).get_qry.
declare axiom qry_done_ll :
forall (O <: CRO.COR{-Adv}),
islossless O.chash => islossless Adv(O).qry_done.
declare axiom final_ll :
forall (O <: CRO.COR{-Adv}),
islossless O.hash => islossless Adv(O).final.
(* budgeted random oracle *)
local clone RO.BudgetedRandomOracle as BRO with
op adv_budget <- adv_budget,
op serv_budget <- db_uniqs_max,
op clnt_budget <- qrys_max
proof *.
(* beginning of realization *)
realize adv_budget_ge0. apply adv_budget_ge0. qed.
realize serv_budget_ge0. apply db_uniqs_max_ge0. qed.
realize clnt_budget_ge0. apply qrys_max_ge0. qed.
realize sum_budgets_ub. rewrite -/budget budget_ub. qed.
(* end of realization *)
local lemma Or_hash_BOr_server_bhash :
equiv
[RO.Or.hash ~ BRO.BOr.server_bhash :
={inp} /\ RO.Or.mp{1} = BRO.BOr.mp{2} ==>
={res} /\ RO.Or.mp{1} = BRO.BOr.mp{2}].
proof.
proc; inline BRO.BOr.hash.
if{2}; wp; sim.
qed.
local lemma Or_hash_BOr_client_bhash :
equiv
[RO.Or.hash ~ BRO.BOr.client_bhash :
={inp} /\ RO.Or.mp{1} = BRO.BOr.mp{2} ==>
={res} /\ RO.Or.mp{1} = BRO.BOr.mp{2}].
proof.
proc; inline BRO.BOr.hash.
if{2}; wp; sim.
qed.
(* convert a budgeted random oracle to a counted random oracle
for giving to Adversary
only chash and hash will be used *)
local module BOrToCOr(O : BRO.BOR) : CRO.COR = {
proc chash(inp : elem * sec) : tag = {
var out : tag;
out <@ O.adv_bhash(inp);
return out;
}
proc hash = O.hash
proc init() : unit = {} (* dummy *)
proc within_budget() : bool = { (* dummy *)
return false;
}
}.
local lemma COr_Or_chash_BOr_adv_bhash :
equiv
[CRO.COr(RO.Or).chash ~ BRO.BOr.adv_bhash :
={inp} /\
RO.Or.mp{1} = BRO.BOr.mp{2} /\
CRO.COr.inps{1} = BRO.BOr.adv_inps{2} /\
CRO.COr.ctr{1} = BRO.BOr.adv_ctr{2} /\
CRO.COr.over{1} = BRO.BOr.adv_over{2} ==>
={res} /\
RO.Or.mp{1} = BRO.BOr.mp{2} /\
CRO.COr.inps{1} = BRO.BOr.adv_inps{2} /\
CRO.COr.ctr{1} = BRO.BOr.adv_ctr{2} /\
CRO.COr.over{1} = BRO.BOr.adv_over{2}].
proof. sim. qed.
local lemma COr_Or_BOrToCOr_BOr_chash :
equiv
[CRO.COr(RO.Or).chash ~ BOrToCOr(BRO.BOr).chash :
={inp} /\
RO.Or.mp{1} = BRO.BOr.mp{2} /\
CRO.COr.inps{1} = BRO.BOr.adv_inps{2} /\
CRO.COr.ctr{1} = BRO.BOr.adv_ctr{2} /\
CRO.COr.over{1} = BRO.BOr.adv_over{2} ==>
={res} /\
RO.Or.mp{1} = BRO.BOr.mp{2} /\
CRO.COr.inps{1} = BRO.BOr.adv_inps{2} /\
CRO.COr.ctr{1} = BRO.BOr.adv_ctr{2} /\
CRO.COr.over{1} = BRO.BOr.adv_over{2}].
proof.
proc*; inline BOrToCOr(BRO.BOr).chash; wp.
call COr_Or_chash_BOr_adv_bhash.
auto.
qed.
local lemma COr_Or_BOrToCOr_BOr_hash :
equiv
[CRO.COr(RO.Or).hash ~ BOrToCOr(BRO.BOr).hash :
={inp} /\ RO.Or.mp{1} = BRO.BOr.mp{2} ==>
={res} /\ RO.Or.mp{1} = BRO.BOr.mp{2}].
proof. sim. qed.
(* H1 is like GReal(Adv), except
- it takes a budgeted random oracle O as its parameter
- Adversary is given result of converting O to counted random
oracle, Server uses O.server_bhash, Client uses O.client_bhash,
and O.adv_within_budget is used to check if Adversary is
within budget
- inlining and dead code elimination have been done *)
local module H1(O : BRO.BOR) = {
module A = Adv(BOrToCOr(O))
var cv : client_view
var sec : sec
var hdb : hdb
var qrys_ctr : int
proc server_hash_db(db : db) : unit = {
var i : int; var elem : elem; var tag : tag;
db <@ Shuffle.shuffle(db);
hdb <- []; i <- 0;
while (i < size db) {
elem <- nth elem_default db i;
tag <@ O.server_bhash((elem, sec));
hdb <- hdb ++ [tag];
i <- i + 1;
}
}
proc tp_count_tag(tag : tag) : int = {
var i, cnt : int;
cnt <- 0; i <- 0;
while (i < size hdb) {
if (nth zeros_tag hdb i = tag) {
cnt <- cnt + 1;
}
i <- i + 1;
}
return cnt;
}
proc client_loop() : unit = {
var cnt : int;
var tag : tag;
var qry_opt : elem option;
var not_done : bool <- true;
var adv_within_budg : bool;
while (not_done) {
qry_opt <@ A.get_qry(cv);
if (qry_opt = None) {
not_done <- false;
cv <- cv ++ [cv_got_qry None];
}
else {
adv_within_budg <@ O.adv_within_budget();
if (qrys_ctr < qrys_max /\ adv_within_budg) {
cv <- cv ++ [cv_got_qry qry_opt];
qrys_ctr <- qrys_ctr + 1;
tag <@ O.client_bhash((oget qry_opt, sec));
cnt <@ tp_count_tag(tag);
cv <- cv ++ [cv_query_count(oget qry_opt, tag, cnt)];
A.qry_done(cv);
}
else {
not_done <- false;
cv <- cv ++ [cv_got_qry None];
}
}
}
}
proc main() : bool = {
var db_opt : db option;
var b : bool;
var adv_within_budg : bool;
sec <$ sec_distr;
cv <- [cv_got_sec sec];
qrys_ctr <- 0;
O.init();
db_opt <@ A.init_and_get_db(cv);
if (db_opt <> None) {
adv_within_budg <@ O.adv_within_budget();
if (num_uniqs(oget db_opt) <= db_uniqs_max /\ adv_within_budg) {
server_hash_db(oget db_opt);
client_loop();
}
}
b <@ A.final(cv);
return b;
}
}.
(* G1 is identical to H1 except it uses oracle BRO.BOr, instead of
being parameterized by budgeted random oracle *)
local module G1 = H1(BRO.BOr).
local lemma Protocol_GReal_Env_G1_server_hash_db :
equiv
[Protocol(GReal(Adv).Env).server_hash_db ~ G1.server_hash_db :
={db} /\ ={mp}(RO.Or, BRO.BOr) /\ Protocol.server_sec{1} = G1.sec{2} ==>
Protocol.server_hdb{1} = G1.hdb{2} /\ ={mp}(RO.Or, BRO.BOr)].
proof.
sim
(: ={mp}(RO.Or, BRO.BOr)) / true :
(Protocol.server_hdb{1} = G1.hdb{2} /\ ={mp}(RO.Or, BRO.BOr)).
apply Or_hash_BOr_server_bhash.
qed.
local lemma Protocol_GReal_Env_G1_client_loop :
equiv
[Protocol(GReal(Adv).Env).client_loop ~ G1.client_loop :
={glob Adv} /\ RO.Or.mp{1} = BRO.BOr.mp{2} /\
CRO.COr.inps{1} = BRO.BOr.adv_inps{2} /\
CRO.COr.ctr{1} = BRO.BOr.adv_ctr{2} /\
CRO.COr.over{1} = BRO.BOr.adv_over{2} /\
Protocol.client_sec{1} = G1.sec{2} /\
GReal.Env.qrys_ctr{1} = G1.qrys_ctr{2} /\
Protocol.tp_hdb{1} = G1.hdb{2} /\ Protocol.cv{1} = G1.cv{2} ==>
={glob Adv} /\ RO.Or.mp{1} = BRO.BOr.mp{2} /\
CRO.COr.inps{1} = BRO.BOr.adv_inps{2} /\
CRO.COr.ctr{1} = BRO.BOr.adv_ctr{2} /\
CRO.COr.over{1} = BRO.BOr.adv_over{2} /\
GReal.Env.qrys_ctr{1} = G1.qrys_ctr{2} /\ Protocol.cv{1} = G1.cv{2}].
proof.
proc.
inline GReal(Adv).Env.get_qry GReal(Adv).Env.put_qry_count.
sp.
while
(={not_done, glob Adv} /\ RO.Or.mp{1} = BRO.BOr.mp{2} /\
CRO.COr.inps{1} = BRO.BOr.adv_inps{2} /\
CRO.COr.ctr{1} = BRO.BOr.adv_ctr{2} /\
CRO.COr.over{1} = BRO.BOr.adv_over{2} /\
Protocol.client_sec{1} = G1.sec{2} /\
GReal.Env.qrys_ctr{1} = G1.qrys_ctr{2} /\
Protocol.tp_hdb{1} = G1.hdb{2} /\ Protocol.cv{1} = G1.cv{2}).
seq 1 1 :
(={not_done, glob Adv} /\ RO.Or.mp{1} = BRO.BOr.mp{2} /\
CRO.COr.inps{1} = BRO.BOr.adv_inps{2} /\
CRO.COr.ctr{1} = BRO.BOr.adv_ctr{2} /\
CRO.COr.over{1} = BRO.BOr.adv_over{2} /\
Protocol.client_sec{1} = G1.sec{2} /\
GReal.Env.qrys_ctr{1} = G1.qrys_ctr{2} /\
Protocol.tp_hdb{1} = G1.hdb{2} /\ Protocol.cv{1} = G1.cv{2} /\
qry_opt0{1} = qry_opt{2}).
call
(_ :
RO.Or.mp{1} = BRO.BOr.mp{2} /\
CRO.COr.inps{1} = BRO.BOr.adv_inps{2} /\
CRO.COr.ctr{1} = BRO.BOr.adv_ctr{2} /\
CRO.COr.over{1} = BRO.BOr.adv_over{2}).
apply COr_Or_BOrToCOr_BOr_chash.
auto.
case (qry_opt{2} = None).
rcondf{1} 1; first auto. rcondt{2} 1; first auto.
rcondt{1} 3; first auto.
auto.
rcondt{1} 1; first auto. rcondf{2} 1; first auto.
inline GReal(Adv).COr.within_budget BRO.BOr.adv_within_budget.
sp 1 1.
if => //.
rcondf{1} 4; first auto.
call
(_ :
RO.Or.mp{1} = BRO.BOr.mp{2} /\
CRO.COr.inps{1} = BRO.BOr.adv_inps{2} /\
CRO.COr.ctr{1} = BRO.BOr.adv_ctr{2} /\
CRO.COr.over{1} = BRO.BOr.adv_over{2}).
apply COr_Or_BOrToCOr_BOr_chash.
wp.
call (_ : Protocol.tp_hdb{1} = G1.hdb{2}); first sim.
call Or_hash_BOr_client_bhash.
auto.
rcondt{1} 4; first auto.
auto.
auto.
qed.
local lemma GReal_G1_main :
equiv[GReal(Adv).main ~ G1.main : ={glob Adv} ==> ={res}].
proof.
proc.
inline Protocol(GReal(Adv).Env).main
Protocol(GReal(Adv).Env).init_views
Protocol(GReal(Adv).Env).server_gen_sec
Protocol(GReal(Adv).Env).client_receive_sec
Protocol(GReal(Adv).Env).tp_receive_hdb
Protocol(GReal(Adv).Env).server_get_hdb
Protocol(GReal(Adv).Env).server_get_sec
GReal(Adv).Env.init_and_get_db
GReal(Adv).Env.final.
seq 11 4 :
(={glob Adv} /\
RO.Or.mp{1} = BRO.BOr.mp{2} /\
CRO.COr.inps{1} = BRO.BOr.adv_inps{2} /\
CRO.COr.ctr{1} = BRO.BOr.adv_ctr{2} /\
CRO.COr.over{1} = BRO.BOr.adv_over{2} /\
Protocol.server_sec{1} = G1.sec{2} /\
GReal.Env.qrys_ctr{1} = G1.qrys_ctr{2} /\
Protocol.client_sec{1} = G1.sec{2} /\
Protocol.cv{1} = G1.cv{2}).
swap{1} 5 -4; inline *; auto.
seq 1 1 :
(={glob Adv} /\
RO.Or.mp{1} = BRO.BOr.mp{2} /\
CRO.COr.inps{1} = BRO.BOr.adv_inps{2} /\
CRO.COr.ctr{1} = BRO.BOr.adv_ctr{2} /\
CRO.COr.over{1} = BRO.BOr.adv_over{2} /\
Protocol.server_sec{1} = G1.sec{2} /\
GReal.Env.qrys_ctr{1} = G1.qrys_ctr{2} /\
Protocol.client_sec{1} = G1.sec{2} /\
Protocol.cv{1} = G1.cv{2} /\ db_opt0{1} = db_opt{2}).
call
(_ :
RO.Or.mp{1} = BRO.BOr.mp{2} /\
CRO.COr.inps{1} = BRO.BOr.adv_inps{2} /\
CRO.COr.ctr{1} = BRO.BOr.adv_ctr{2} /\
CRO.COr.over{1} = BRO.BOr.adv_over{2}).
apply COr_Or_BOrToCOr_BOr_chash.
auto.
if => //.
inline GReal(Adv).COr.within_budget BRO.BOr.adv_within_budget.
sp 1 1; wp.
case
(num_uniqs (oget db_opt{2}) <= db_uniqs_max /\
adv_within_budg{2}).
rcondf{1} 1; first auto; smt().
rcondt{2} 1; first auto.
rcondt{1} 2; first auto.
call (_ : RO.Or.mp{1} = BRO.BOr.mp{2}).
apply COr_Or_BOrToCOr_BOr_hash.
call Protocol_GReal_Env_G1_client_loop.
wp.
call Protocol_GReal_Env_G1_server_hash_db; auto.
rcondt{1} 1; first auto; smt().
rcondf{2} 1; first auto.
rcondf{1} 3; first auto.
call (_ : RO.Or.mp{1} = BRO.BOr.mp{2}).
apply COr_Or_BOrToCOr_BOr_hash.
auto.
rcondf{1} 2; first auto.
wp.
call (_ : RO.Or.mp{1} = BRO.BOr.mp{2}).
apply COr_Or_BOrToCOr_BOr_hash.
auto.
qed.
local lemma GReal_G1 &m :
Pr[GReal(Adv).main() @ &m : res] = Pr[G1.main() @ &m : res].
proof. by byequiv GReal_G1_main. qed.
(* G2 is the same as G1, except it uses BRO.BOrInj (which will stay
collision free (injective) as long as all three budgets are
respected and only budgeted hashing is done) not BRO.BOr *)
local module G2 = H1(BRO.BOrInj).
(* we apply the Switching lemma to G1/G2
our concrete switching adversary H1' is the same as H1, except that
its main procedure doesn't (can't!) initialize the oracle, and hdb
is initialized by main *)
local module (H1' : BRO.SWADV) (O : BRO.BOR) = {
module A = Adv(BOrToCOr(O))
var cv : client_view
var sec : sec
var hdb : hdb
var qrys_ctr : int
proc server_hash_db(db : db) : unit = {
var i : int;
var elem : elem;
var tag : tag;
db <@ Shuffle.shuffle(db);
hdb <- []; i <- 0;
while (i < size db) {
elem <- nth elem_default db i;
tag <@ O.server_bhash((elem, sec));
hdb <- hdb ++ [tag];
i <- i + 1;
}
}
proc tp_count_tag(tag : tag) : int = {
var i, cnt : int;
cnt <- 0; i <- 0;
while (i < size hdb) {
if (nth zeros_tag hdb i = tag) {
cnt <- cnt + 1;
}
i <- i + 1;
}
return cnt;
}
proc client_loop() : unit = {
var cnt : int;
var tag : tag;
var qry_opt : elem option;
var not_done : bool <- true;
var adv_within_budg : bool;
while (not_done) {
qry_opt <@ A.get_qry(cv);
if (qry_opt = None) {
not_done <- false;
cv <- cv ++ [cv_got_qry None];
}
else {
adv_within_budg <@ O.adv_within_budget();
if (qrys_ctr < qrys_max /\ adv_within_budg) {
cv <- cv ++ [cv_got_qry qry_opt];
qrys_ctr <- qrys_ctr + 1;
tag <@ O.client_bhash((oget qry_opt, sec));
cnt <@ tp_count_tag(tag);
cv <- cv ++ [cv_query_count(oget qry_opt, tag, cnt)];
A.qry_done(cv);
}
else {
not_done <- false;
cv <- cv ++ [cv_got_qry None];
}
}
}
}
proc main() : bool = {
var db_opt : db option;
var b : bool;
var adv_within_budg : bool;
sec <$ sec_distr;
cv <- [cv_got_sec sec];
qrys_ctr <- 0;
hdb <- [];
db_opt <@ A.init_and_get_db(cv);
if (db_opt <> None) {
adv_within_budg <@ O.adv_within_budget();
if (num_uniqs (oget db_opt) <= db_uniqs_max /\ adv_within_budg) {
server_hash_db(oget db_opt);
client_loop();
}
}
b <@ A.final(cv);
return b;
}
}.
(* we work up to showing losslessness of H1'.main *)
local lemma H1'_server_hash_db_ll :
forall (O <: BRO.BOR),
islossless O.server_bhash => islossless H1'(O).server_hash_db.
proof.
move => O server_bhash_ll; proc.
while (true) (size db - i).
move => z; wp.
call (_ : true ==> true).
auto; smt().
wp.
call (_ : true ==> true); first apply Shuffle_shuffle_ll.
auto; smt().
qed.
local lemma H1'_tp_count_tag_ll :
forall (O <: BRO.BOR),
islossless H1'(O).tp_count_tag.
proof.
move => O; proc; wp.
while (true) (size H1'.hdb - i).
auto; smt().
auto; smt().
qed.
local lemma H1'_client_loop_ll :
forall (O <: BRO.BOR{-H1'}),
islossless O.adv_bhash => islossless O.adv_within_budget =>
islossless O.server_bhash => islossless O.client_bhash =>
islossless O.hash =>
phoare
[H1'(O).client_loop :
H1'.qrys_ctr <= qrys_max ==> true] = 1%r.
proof.
move =>
O adv_bhash_ll adv_within_budget_ll server_bhash_ll
client_bhash_ll hash_ll.
proc; sp.
while (H1'.qrys_ctr <= qrys_max)
(b2i not_done * (qrys_max - H1'.qrys_ctr + 1)).
auto.
seq 1 :
(H1'.qrys_ctr <= qrys_max /\ not_done /\
b2i not_done * (qrys_max - H1'.qrys_ctr + 1) = z).
auto.
call (_ : true ==> true).
apply (get_qry_ll (BOrToCOr(O))); proc; call adv_bhash_ll; auto.
auto.
if.
auto; smt().
seq 1 :
(H1'.qrys_ctr <= qrys_max /\ not_done /\
b2i not_done * (qrys_max - H1'.qrys_ctr + 1) = z).
call (_ : true); first auto.
call adv_within_budget_ll; auto.
if.
call (_ : true ==> true).
apply (qry_done_ll (BOrToCOr(O))); proc; call adv_bhash_ll; auto.
wp.
call (H1'_tp_count_tag_ll O).
call client_bhash_ll.
auto; smt().
auto; smt().
hoare.
call (_ : true); auto; smt().
smt().
hoare.
call (_ : true); auto; smt().
smt().
auto; smt().
qed.
local lemma H1'_main_ll :
forall (O <: BRO.BOR{-H1'}),
islossless O.adv_bhash => islossless O.adv_within_budget =>
islossless O.server_bhash => islossless O.client_bhash =>
islossless O.hash =>
islossless H1'(O).main.
proof.
move =>
O adv_bhash_ll adv_within_budget_ll server_bhash_ll client_bhash_ll
hash_ll.
proc.
call (_ : true ==> true).
apply (final_ll (BOrToCOr(O))); apply hash_ll.
seq 5 : (H1'.qrys_ctr = 0).
call (_ : true).
proc; call (_ : true); auto.
auto.
call (_ : true ==> true).
apply (init_and_get_db_ll (BOrToCOr(O))); proc; call adv_bhash_ll; auto.
auto; progress; apply sec_distr_ll.
if.
seq 1 : (H1'.qrys_ctr = 0 /\ db_opt <> None).
call (_ : true); auto.
call adv_within_budget_ll; auto.
if.
call (_ : H1'.qrys_ctr <= qrys_max ==> true).
apply (H1'_client_loop_ll O);
[apply adv_bhash_ll | apply adv_within_budget_ll |
apply server_bhash_ll | apply client_bhash_ll |
apply hash_ll].
call (_ : true ==> true).
apply (H1'_server_hash_db_ll O); apply server_bhash_ll.
auto; progress; apply qrys_max_ge0.
auto.
hoare; call (_ : true); auto.
trivial.
auto.
hoare.
call (_ : true).
proc; call (_ : true); auto.
auto.
trivial.
qed.
(* now we apply the Switching Lemma to H1' *)
local lemma GSwitching_H1' &m :
`|Pr[BRO.GSwitching(H1', BRO.BOr).main() @ &m : res] -
Pr[BRO.GSwitching(H1', BRO.BOrInj).main() @ &m : res]| <=
BRO.coll_bound.
proof.
apply (BRO.Switching H1' &m).
move => O; apply (H1'_main_ll O).
qed.
(* now we connect G1 and G2 *)
local lemma G1_GSwitching_H1'_BOr_main &m :
equiv
[G1.main ~ BRO.GSwitching(H1', BRO.BOr).main :
={glob Adv} ==> ={res}].
proof.
proc.
inline BRO.GSwitching(H1', BRO.BOr).SA.main.
swap{1} 4 -3; sim.
qed.
local lemma G1_GSwitching_H1'_BOr &m :
Pr[G1.main() @ &m : res] =
Pr[BRO.GSwitching(H1', BRO.BOr).main() @ &m : res].
proof. by byequiv (G1_GSwitching_H1'_BOr_main &m). qed.
local lemma GSwitching_H1'_BOrInj_G2_main &m :
equiv
[BRO.GSwitching(H1', BRO.BOrInj).main ~ G2.main:
={glob Adv} ==> ={res}].
proof.
proc.
inline BRO.GSwitching(H1', BRO.BOrInj).SA.main.
swap{2} 4 -3; sim.
qed.
local lemma GSwitching_H1'_BOrInj_G2 &m :
Pr[BRO.GSwitching(H1', BRO.BOrInj).main() @ &m : res] =
Pr[G2.main() @ &m : res].
proof. by byequiv (GSwitching_H1'_BOrInj_G2_main &m). qed.
local lemma G1_G2 &m :
`|Pr[G1.main() @ &m : res] - Pr[G2.main() @ &m : res]| <=
BRO.coll_bound.
proof.
rewrite (G1_GSwitching_H1'_BOr &m) -(GSwitching_H1'_BOrInj_G2 &m)
(GSwitching_H1' &m).
qed.
local lemma GReal_G2 &m :
`|Pr[GReal(Adv).main() @ &m : res] - Pr[G2.main() @ &m : res]| <=
BRO.coll_bound.
proof. rewrite (GReal_G1 &m) (G1_G2 &m). qed.
(* In H2:
server_hash_db is renamed to server_hash_and_count_db; it still
hashes the database, but no longer constructs the hashed database
(and thus the global variable hdb is deleted) -- instead it
produces an elements counts map from the database
client_loop now asks the TP to look up the counts for a query
in the elements counts map, but it still hashes each query *)
local module H2(O : BRO.BOR) = {
module A = Adv(BOrToCOr(O))
var cv : client_view
var sec : sec
var elems_cnts : elems_counts