-
Notifications
You must be signed in to change notification settings - Fork 0
/
FO_Proofs.thy
1209 lines (1061 loc) · 59.7 KB
/
FO_Proofs.thy
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
theory FO_Proofs
imports FO_Specification General_Proofs T_Proofs FO_Proofs0 T_Security
(* "HOL-Eisbach.Eisbach" "HOL-Eisbach.Eisbach_Tools" *)
begin
(* Can be used with "simp split!:" or with Splitter.split_asm_tac *)
lemma Cla_split_asm: "P (Cla[Q]) = (\<not> ((Q \<and> \<not> P top) \<or> (\<not> Q \<and> \<not> P bot)))"
by (cases Q, auto)
lemma correctness_enc_leq1[simp]:
"correctness params keygen enc dec msg_space \<le> 1"
apply (rule correctness_leq1)
by auto
lemma correctness_enc_pos[simp]:
"correctness params keygen enc dec msg_space \<ge> 0"
apply (rule correctness_pos)
by auto
(* lemma case_option_beta: "x\<noteq>None \<Longrightarrow> (case x of None \<Rightarrow> y | Some z \<Rightarrow> w z) = w (the x)" *)
(* by auto *)
lemma decapsQuery_decapsQueryPRF_vc:
"\<CC>\<ll>\<aa>[pk_of_sk sk2 = pk2 \<and> skfo1 = (sk2, prfk2) \<and> cstar1 = cstar2 \<and> classA1 = classA2 \<and> c1 = c2 \<and> K'1 = K'2 \<and> b1 = b2 \<and> G1 = G2 \<and> H1 = H2 \<and> Kstar1 = Kstar2 \<and> in_pk1 = in_pk2 \<and> in_cstar1 = in_cstar2] \<sqinter> \<lbrakk>quantA1, Hin1, Hout1, Gin1, Gout1\<rbrakk> \<equiv>\<qq> \<lbrakk>quantA2, Hin2, Hout2, Gin2, Gout2\<rbrakk> \<le> (\<CC>\<ll>\<aa>[c2 \<noteq> cstar2] + (\<CC>\<ll>\<aa>[c1 \<noteq> cstar1] + \<CC>\<ll>\<aa>[pk_of_sk sk2 = pk2 \<and> skfo1 = (sk2, prfk2) \<and> cstar1 = cstar2 \<and> classA1 = classA2 \<and> c1 = c2 \<and> None = None \<and> b1 = b2 \<and> G1 = G2 \<and> H1 = H2 \<and> Kstar1 = Kstar2 \<and> in_pk1 = in_pk2 \<and> in_cstar1 = in_cstar2] \<sqinter> \<lbrakk>quantA1, Hin1, Hout1, Gin1, Gout1\<rbrakk> \<equiv>\<qq> \<lbrakk>quantA2, Hin2, Hout2, Gin2, Gout2\<rbrakk>) \<sqinter> (\<CC>\<ll>\<aa>[c1 = cstar1] + \<CC>\<ll>\<aa>[pk_of_sk sk2 = pk2 \<and> skfo1 = (sk2, prfk2) \<and> cstar1 = cstar2 \<and> classA1 = classA2 \<and> c1 = c2 \<and> decapsFO (G1, H1) skfo1 c1 = None \<and> b1 = b2 \<and> G1 = G2 \<and> H1 = H2 \<and> Kstar1 = Kstar2 \<and> in_pk1 = in_pk2 \<and> in_cstar1 = in_cstar2] \<sqinter> \<lbrakk>quantA1, Hin1, Hout1, Gin1, Gout1\<rbrakk> \<equiv>\<qq> \<lbrakk>quantA2, Hin2, Hout2, Gin2, Gout2\<rbrakk>)) \<sqinter> (\<CC>\<ll>\<aa>[c2 = cstar2] + (\<CC>\<ll>\<aa>[\<not> (dec () sk2 c2 = None \<or> encr () pk2 (the (dec () sk2 c2)) (G2 (the (dec () sk2 c2))) \<noteq> c2)] + (\<CC>\<ll>\<aa>[c1 \<noteq> cstar1] + \<CC>\<ll>\<aa>[pk_of_sk sk2 = pk2 \<and> skfo1 = (sk2, prfk2) \<and> cstar1 = cstar2 \<and> classA1 = classA2 \<and> c1 = c2 \<and> None = Some (PRF prfk2 c2) \<and> b1 = b2 \<and> G1 = G2 \<and> H1 = H2 \<and> Kstar1 = Kstar2 \<and> in_pk1 = in_pk2 \<and> in_cstar1 = in_cstar2] \<sqinter> \<lbrakk>quantA1, Hin1, Hout1, Gin1, Gout1\<rbrakk> \<equiv>\<qq> \<lbrakk>quantA2, Hin2, Hout2, Gin2, Gout2\<rbrakk>) \<sqinter> (\<CC>\<ll>\<aa>[c1 = cstar1] + \<CC>\<ll>\<aa>[pk_of_sk sk2 = pk2 \<and> skfo1 = (sk2, prfk2) \<and> cstar1 = cstar2 \<and> classA1 = classA2 \<and> c1 = c2 \<and> decapsFO (G1, H1) skfo1 c1 = Some (PRF prfk2 c2) \<and> b1 = b2 \<and> G1 = G2 \<and> H1 = H2 \<and> Kstar1 = Kstar2 \<and> in_pk1 = in_pk2 \<and> in_cstar1 = in_cstar2] \<sqinter> \<lbrakk>quantA1, Hin1, Hout1, Gin1, Gout1\<rbrakk> \<equiv>\<qq> \<lbrakk>quantA2, Hin2, Hout2, Gin2, Gout2\<rbrakk>)) \<sqinter> (\<CC>\<ll>\<aa>[dec () sk2 c2 = None \<or> encr () pk2 (the (dec () sk2 c2)) (G2 (the (dec () sk2 c2))) \<noteq> c2] + (\<CC>\<ll>\<aa>[c1 \<noteq> cstar1] + \<CC>\<ll>\<aa>[pk_of_sk sk2 = pk2 \<and> skfo1 = (sk2, prfk2) \<and> cstar1 = cstar2 \<and> classA1 = classA2 \<and> c1 = c2 \<and> None = Some (H2 (the (dec () sk2 c2))) \<and> b1 = b2 \<and> G1 = G2 \<and> H1 = H2 \<and> Kstar1 = Kstar2 \<and> in_pk1 = in_pk2 \<and> in_cstar1 = in_cstar2] \<sqinter> \<lbrakk>quantA1, Hin1, Hout1, Gin1, Gout1\<rbrakk> \<equiv>\<qq> \<lbrakk>quantA2, Hin2, Hout2, Gin2, Gout2\<rbrakk>) \<sqinter> (\<CC>\<ll>\<aa>[c1 = cstar1] + \<CC>\<ll>\<aa>[pk_of_sk sk2 = pk2 \<and> skfo1 = (sk2, prfk2) \<and> cstar1 = cstar2 \<and> classA1 = classA2 \<and> c1 = c2 \<and> decapsFO (G1, H1) skfo1 c1 = Some (H2 (the (dec () sk2 c2))) \<and> b1 = b2 \<and> G1 = G2 \<and> H1 = H2 \<and> Kstar1 = Kstar2 \<and> in_pk1 = in_pk2 \<and> in_cstar1 = in_cstar2] \<sqinter> \<lbrakk>quantA1, Hin1, Hout1, Gin1, Gout1\<rbrakk> \<equiv>\<qq> \<lbrakk>quantA2, Hin2, Hout2, Gin2, Gout2\<rbrakk>)))"
(* "\<CC>\<ll>\<aa>[pk_of_sk sk2 = pk2 \<and> skfo1 = (sk2, prfk2) \<and> cstar1 = cstar2 \<and> classA1 = classA2 \<and> c1 = c2 \<and> K'1 = K'2 \<and> b1 = b2 \<and> G1 = G2 \<and> H1 = H2 \<and> Kstar1 = Kstar2 \<and> in_pk1 = in_pk2 \<and> in_cstar1 = in_cstar2] \<sqinter> \<lbrakk>quantA1, Hin1, Hout1, Gin1, Gout1\<rbrakk> \<equiv>\<qq> \<lbrakk>quantA2, Hin2, Hout2, Gin2, Gout2\<rbrakk> \<le> (\<CC>\<ll>\<aa>[c2 \<noteq> cstar2] \<squnion> (\<CC>\<ll>\<aa>[c1 \<noteq> cstar1] \<squnion> \<CC>\<ll>\<aa>[pk_of_sk sk2 = pk2 \<and> skfo1 = (sk2, prfk2) \<and> cstar1 = cstar2 \<and> classA1 = classA2 \<and> c1 = c2 \<and> None = None \<and> b1 = b2 \<and> G1 = G2 \<and> H1 = H2 \<and> Kstar1 = Kstar2 \<and> in_pk1 = in_pk2 \<and> in_cstar1 = in_cstar2] \<sqinter> \<lbrakk>quantA1, Hin1, Hout1, Gin1, Gout1\<rbrakk> \<equiv>\<qq> \<lbrakk>quantA2, Hin2, Hout2, Gin2, Gout2\<rbrakk>) \<sqinter> (\<CC>\<ll>\<aa>[c1 = cstar1] \<squnion> \<CC>\<ll>\<aa>[pk_of_sk sk2 = pk2 \<and> skfo1 = (sk2, prfk2) \<and> cstar1 = cstar2 \<and> classA1 = classA2 \<and> c1 = c2 \<and> decapsFO (G1, H1) skfo1 c1 = None \<and> b1 = b2 \<and> G1 = G2 \<and> H1 = H2 \<and> Kstar1 = Kstar2 \<and> in_pk1 = in_pk2 \<and> in_cstar1 = in_cstar2] \<sqinter> \<lbrakk>quantA1, Hin1, Hout1, Gin1, Gout1\<rbrakk> \<equiv>\<qq> \<lbrakk>quantA2, Hin2, Hout2, Gin2, Gout2\<rbrakk>)) \<sqinter> (\<CC>\<ll>\<aa>[c2 = cstar2] \<squnion> (\<CC>\<ll>\<aa>[\<not> (dec () sk2 c2 = None \<or> encr () pk2 (the (dec () sk2 c2)) (G2 (the (dec () sk2 c2))) \<noteq> c2)] \<squnion> (\<CC>\<ll>\<aa>[c1 \<noteq> cstar1] \<squnion> \<CC>\<ll>\<aa>[pk_of_sk sk2 = pk2 \<and> skfo1 = (sk2, prfk2) \<and> cstar1 = cstar2 \<and> classA1 = classA2 \<and> c1 = c2 \<and> None = Some (PRF prfk2 c2) \<and> b1 = b2 \<and> G1 = G2 \<and> H1 = H2 \<and> Kstar1 = Kstar2 \<and> in_pk1 = in_pk2 \<and> in_cstar1 = in_cstar2] \<sqinter> \<lbrakk>quantA1, Hin1, Hout1, Gin1, Gout1\<rbrakk> \<equiv>\<qq> \<lbrakk>quantA2, Hin2, Hout2, Gin2, Gout2\<rbrakk>) \<sqinter> (\<CC>\<ll>\<aa>[c1 = cstar1] \<squnion> \<CC>\<ll>\<aa>[pk_of_sk sk2 = pk2 \<and> skfo1 = (sk2, prfk2) \<and> cstar1 = cstar2 \<and> classA1 = classA2 \<and> c1 = c2 \<and> decapsFO (G1, H1) skfo1 c1 = Some (PRF prfk2 c2) \<and> b1 = b2 \<and> G1 = G2 \<and> H1 = H2 \<and> Kstar1 = Kstar2 \<and> in_pk1 = in_pk2 \<and> in_cstar1 = in_cstar2] \<sqinter> \<lbrakk>quantA1, Hin1, Hout1, Gin1, Gout1\<rbrakk> \<equiv>\<qq> \<lbrakk>quantA2, Hin2, Hout2, Gin2, Gout2\<rbrakk>)) \<sqinter> (\<CC>\<ll>\<aa>[dec () sk2 c2 = None \<or> encr () pk2 (the (dec () sk2 c2)) (G2 (the (dec () sk2 c2))) \<noteq> c2] \<squnion> (\<CC>\<ll>\<aa>[c1 \<noteq> cstar1] \<squnion> \<CC>\<ll>\<aa>[pk_of_sk sk2 = pk2 \<and> skfo1 = (sk2, prfk2) \<and> cstar1 = cstar2 \<and> classA1 = classA2 \<and> c1 = c2 \<and> None = Some (H2 (the (dec () sk2 c2))) \<and> b1 = b2 \<and> G1 = G2 \<and> H1 = H2 \<and> Kstar1 = Kstar2 \<and> in_pk1 = in_pk2 \<and> in_cstar1 = in_cstar2] \<sqinter> \<lbrakk>quantA1, Hin1, Hout1, Gin1, Gout1\<rbrakk> \<equiv>\<qq> \<lbrakk>quantA2, Hin2, Hout2, Gin2, Gout2\<rbrakk>) \<sqinter> (\<CC>\<ll>\<aa>[c1 = cstar1] \<squnion> \<CC>\<ll>\<aa>[pk_of_sk sk2 = pk2 \<and> skfo1 = (sk2, prfk2) \<and> cstar1 = cstar2 \<and> classA1 = classA2 \<and> c1 = c2 \<and> decapsFO (G1, H1) skfo1 c1 = Some (H2 (the (dec () sk2 c2))) \<and> b1 = b2 \<and> G1 = G2 \<and> H1 = H2 \<and> Kstar1 = Kstar2 \<and> in_pk1 = in_pk2 \<and> in_cstar1 = in_cstar2] \<sqinter> \<lbrakk>quantA1, Hin1, Hout1, Gin1, Gout1\<rbrakk> \<equiv>\<qq> \<lbrakk>quantA2, Hin2, Hout2, Gin2, Gout2\<rbrakk>)))" *)
proof -
note encrT_def[simp] decapsFO_def[simp] decT_def[simp]
obtain sk1 prfk1 where [simp]: "skfo1 = (sk1,prfk1)" apply atomize_elim by auto
consider (ccstar) "c1=cstar1" | (decNone) "c1\<noteq>cstar1 \<and> dec () sk1 c1 = None"
| (decM) m where "c1\<noteq>cstar1 \<and> dec () sk1 c1 = Some m"
apply atomize_elim by auto
then show ?thesis
proof cases
case ccstar
then show ?thesis
by simp
next
case decNone
then show ?thesis
by auto
next case (decM m)
then show ?thesis
by auto
qed
qed
lemma [simp]: "keygenFO (G,H1) = keygenFO (G,H2)"
unfolding keygenFO_def by simp
lemma keygenFO_keygenT: "map_distr (\<lambda>x. ((fst x, fst (snd x)), snd (snd x))) (keygenFO (G, H2)) = product_distr (keygenT G) keygenPRF"
unfolding keygenFO_def by (auto simp: case_prod_beta)
lemma pk_of_sk_keygenFO:
assumes "x \<in> supp (keygenFO (G1, H2))"
shows "pk_of_sk (fst (snd x)) = fst x"
using assms unfolding keygenFO_def
by (auto simp: pk_of_sk)
lemma [simp]: "uniform (msg_spaceT G1) = uniform (msg_spaceT G2)"
unfolding msg_spaceT_def by simp
lemma [simp]: "keygenFO (G, H) = keygenFO (G1, H1)"
unfolding keygenFO_def keygenT_def by simp
(* lemma [simp]: "map_distr (\<lambda>x. ((fst x, fst (snd x)), snd (snd x), snd x)) (keygenFO (G, H)) = bind_distr (keygenT G2) (\<lambda>z. map_distr (\<lambda>x. (z, x, snd z, x)) keygenPRF)"
unfolding keygenFO_def keygenT_def case_prod_conv
by (simp add: case_prod_beta bind_distr_map_distr[symmetric]) *)
lemma [simp]: "map_distr (\<lambda>x. (fst x, fst (snd x))) (keygenFO (G, H)) = keygenT G2"
unfolding keygenFO_def keygenT_def case_prod_beta
by simp
lemma G2G2:
assumes [simp]: "declared_qvars \<lbrakk>Gin1,Gin2,Gout1,Gout2,quantA1,quantA2,Hin1,Hout1,Hin2,Hout2\<rbrakk>"
shows "Uoracle H\<guillemotright>\<lbrakk>Gin2, Gout2\<rbrakk> \<cdot> (Uoracle H\<guillemotright>\<lbrakk>Gin1, Gout1\<rbrakk> \<cdot>
\<lbrakk>quantA1, Hin1, Hout1, Gin1, Gout1\<rbrakk> \<equiv>\<qq> \<lbrakk>quantA2, Hin2, Hout2, Gin2, Gout2\<rbrakk>)
= \<lbrakk>quantA1, Hin1, Hout1, Gin1, Gout1\<rbrakk> \<equiv>\<qq> \<lbrakk>quantA2, Hin2, Hout2, Gin2, Gout2\<rbrakk>"
(is "_ = ?Q1 \<equiv>\<qq> ?Q2")
proof -
have 1: "Uoracle H\<guillemotright>\<lbrakk>Gin1, Gout1\<rbrakk> = (idOp \<otimes> (idOp \<otimes> (idOp \<otimes> Uoracle H)))\<guillemotright>?Q1"
apply (subst lift_tensorOp[symmetric], simp)+ by simp
have 2: "Uoracle H\<guillemotright>\<lbrakk>Gin2, Gout2\<rbrakk> = (idOp \<otimes> (idOp \<otimes> (idOp \<otimes> Uoracle H)))\<guillemotright>?Q2"
apply (subst lift_tensorOp[symmetric], simp)+ by simp
show ?thesis
unfolding 1 2 by simp
qed
lemma Cla_split':
assumes "Q \<Longrightarrow> P top" and "\<not> Q \<longrightarrow> P bot"
shows "P (Cla[Q])"
using assms by (cases Q, auto)
lemma H2H2':
assumes [simp]: "declared_qvars \<lbrakk>Gin1,Gin2,Gout1,Gout2,quantA1,quantA2,Hin1,Hout1,Hin2,Hout2\<rbrakk>"
shows "Uoracle H\<guillemotright>\<lbrakk>Hin2, Hout2\<rbrakk> \<cdot> (Uoracle H\<guillemotright>\<lbrakk>Hin1, Hout1\<rbrakk> \<cdot>
\<lbrakk>quantA1, Hin1, Hout1, Gin1, Gout1\<rbrakk> \<equiv>\<qq> \<lbrakk>quantA2, Hin2, Hout2, Gin2, Gout2\<rbrakk>)
= \<lbrakk>quantA1, Hin1, Hout1, Gin1, Gout1\<rbrakk> \<equiv>\<qq> \<lbrakk>quantA2, Hin2, Hout2, Gin2, Gout2\<rbrakk>"
(is "_ = ?Q1 \<equiv>\<qq> ?Q2")
proof -
have 1: "Uoracle H\<guillemotright>\<lbrakk>Hin1, Hout1\<rbrakk> = (idOp \<otimes> (assoc_op* o\<^sub>C\<^sub>L (Uoracle H \<otimes> idOp) o\<^sub>C\<^sub>L assoc_op))\<guillemotright>?Q1"
apply (subst lift_tensorOp[symmetric], simp_all)
apply (subst assoc_op_lift')
by (subst lift_tensorOp[symmetric], simp_all)
have 2: "Uoracle H\<guillemotright>\<lbrakk>Hin2, Hout2\<rbrakk> = (idOp \<otimes> (assoc_op* o\<^sub>C\<^sub>L (Uoracle H \<otimes> idOp) o\<^sub>C\<^sub>L assoc_op))\<guillemotright>?Q2"
apply (subst lift_tensorOp[symmetric], simp_all)
apply (subst assoc_op_lift')
by (subst lift_tensorOp[symmetric], simp_all)
have "(assoc_op* \<cdot> Uoracle H \<otimes> idOp \<cdot> assoc_op) \<cdot> (assoc_op* \<cdot> (Uoracle H* \<otimes> idOp \<cdot> assoc_op)) =
assoc_op* \<cdot> (Uoracle H \<otimes> idOp \<cdot> (assoc_op \<cdot> assoc_op*) \<cdot> Uoracle H* \<otimes> idOp) \<cdot> assoc_op"
by (simp only: cblinfun_compose_assoc)
also have "\<dots> = idOp"
by simp
finally have cancel: "(assoc_op* \<cdot> Uoracle H \<otimes> idOp \<cdot> assoc_op) \<cdot> (assoc_op* \<cdot> (Uoracle H* \<otimes> idOp \<cdot> assoc_op)) = idOp"
by -
show ?thesis
unfolding 1 2 by (simp add: cancel)
qed
lemma Hq1_Hq2:
assumes notin: "cstar2 \<notin> (encrT G2 pk2) ` msg_spaceT G2"
assumes eq: "(\<forall>x. x \<noteq> cstar2 \<longrightarrow> Hq1 x = Hq2 x)"
shows "mk_Hq Hq1 H0 G2 pk2 = mk_Hq Hq2 H0 G2 pk2"
proof (rule ext)
fix m
consider (cstar) "m \<in> msg_spaceT G2" and "encrT G2 pk2 m = cstar2" | (msgspace) "m \<in> msg_spaceT G2" and "encrT G2 pk2 m \<noteq> cstar2" | (outside) "m \<notin> msg_spaceT G2" by auto
then show "mk_Hq Hq1 H0 G2 pk2 m = mk_Hq Hq2 H0 G2 pk2 m"
proof cases
case msgspace
then have "Hq1 (encrT G2 pk2 m) = Hq2 (encrT G2 pk2 m)"
apply (subst eq[rule_format]) by simp_all
then show ?thesis
unfolding mk_Hq_def by auto
next
case cstar
with notin have False by auto
then show ?thesis by simp
next
case outside
then show ?thesis
unfolding mk_Hq_def by auto
qed
qed
lemma map_distr_Hq_Kstar:
"map_distr (\<lambda>HK::(ciph\<Rightarrow>key)*key. ((fst HK)(cstar1 := snd HK), snd HK)) (uniform UNIV) = map_distr (\<lambda>H. (H, H cstar1)) (uniform UNIV)"
(is "?lhs=?rhs")
proof -
define S :: "(_ * key) set" where "S = {(H,K). H cstar1 = K}"
have "regular_betw (\<lambda>(x,y). (x(cstar1 := y), y)) UNIV S"
proof (rule regular_betwI)
define n :: nat where "n=CARD(key)"
show "n\<noteq>0" unfolding n_def by simp
show "range (\<lambda>(x, y). (x(cstar1 := y), y)) = S"
unfolding S_def
using image_iff case_prod_beta by fastforce
show "card ((\<lambda>(x, y). (x(cstar1 := y), y)) -` {HK} \<inter> UNIV) = n" if "HK \<in> S" for HK
proof -
obtain H K where HK_def: "HK = (H,K)" by fastforce
with that have H_cstar1: "H cstar1 = K" by (simp add: S_def)
define f :: "((ciph\<Rightarrow>key)*key) \<Rightarrow> _" where "f = (\<lambda>(H',K'). H' cstar1)"
define g :: "_ \<Rightarrow> ((ciph\<Rightarrow>key)*key)" where "g K' = (H(cstar1:=K'),K)" for K'
show ?thesis
unfolding n_def HK_def apply simp
proof (rule card_bij_eq[where f=f and g=g])
show "inj_on f ((\<lambda>(x, y). (x(cstar1 := y), y)) -` {(H, K)})"
apply (rule inj_onI) unfolding f_def apply auto
by (metis array_rules(5) fun_upd_triv)
show "inj g"
apply (rule injI) unfolding g_def apply auto
by (meson fun_upd_eqD)
show "range g \<subseteq> (\<lambda>(x, y). (x(cstar1 := y), y)) -` {(H, K)}"
apply (auto simp: g_def case_prod_beta)
using H_cstar1 by blast
qed auto
qed
qed
then have 1: "?lhs = uniform S"
unfolding case_prod_beta by simp
have "bij_betw (\<lambda>d. (d, d cstar1)) UNIV S"
apply (rule bij_betwI')
by (auto simp: S_def)
then have 2: "?rhs = uniform S"
by simp
from 1 2 show ?thesis by simp
qed
(* lemma [simp]: "weight (keygenT p) = 1"
unfolding keygenT_def keygen_def by simp *)
lemma [simp]: "weight (keygenFO p) = 1"
unfolding keygenFO_def case_prod_beta by auto
lemma [simp]: "weight (fakeenc () pk) = 1"
unfolding fakeenc_def enc0_def by simp
(*
lemma
quantum_eq_add_state2:
fixes U :: "('a::universe,'c) l2bounded" and V :: "('b::universe,'c) l2bounded" and \<psi> :: "'d::universe ell2"
and Q :: "'a::universe variables" and R :: "'b::universe variables" and T :: "'d variables"
assumes "distinct_qvars (variable_concat Q (variable_concat R T))"
assumes "norm \<psi> = 1"
shows "quantum_equality_full V R U Q \<sqinter> ccspan {\<psi>}\<guillemotright>T
= quantum_equality_full (addState \<psi> \<cdot> V) R (U \<otimes> idOp) (variable_concat Q T)"
proof -
from assms(1) have [simp]: "distinct_qvars (variable_concat T Q)"
by (subst (asm) distinct_qvars_split2, simp)
then have [simp]: "distinct_qvars (variable_concat Q T)"
by (rule distinct_qvars_swap)
from assms(1) have [simp]: "distinct_qvars (variable_concat R Q)"
by (subst (asm) distinct_qvars_split2, simp)
then have [simp]: "distinct_qvars (variable_concat Q R)"
by (rule distinct_qvars_swap)
from assms(1) have [simp]: "distinct_qvars (variable_concat R T)"
by (subst (asm) distinct_qvars_split2, simp)
then have [simp]: "distinct_qvars (variable_concat T R)"
by (rule distinct_qvars_swap)
have [simp]: "distinct_qvars (variable_concat (variable_concat Q T) R)"
by (subst distinct_qvars_split1, simp)
show ?thesis
apply (subst quantum_equality_sym, simp)
apply (subst quantum_eq_add_state)
apply (simp_all add: assms)[2]
by (rule quantum_equality_sym, simp)
qed
*)
(* lemma [simp]: "paramsT \<noteq> 0"
by (metis UNIV_not_empty finite paramsT_def suppP_empty_simp supp_uniform) *)
lemma [simp]: "disjointnessT \<le> 1"
unfolding disjointnessT_def
apply (rule disjointness_leq1)
by auto
lemma [simp]: "disjointnessT \<ge> 0"
unfolding disjointnessT_def
apply (rule disjointness_geq0)
by auto
lemma Prob_leq_disjointnessT:
assumes "G1 \<in> supp paramsT" and "(pk1, sk1) \<in> supp (keygenT G1)"
shows "Prob (fakeenc () pk1) (encrT G1 pk1 ` msg_spaceT G1) \<le> disjointnessT"
unfolding disjointnessT_def fakeencT_def[symmetric, of G1] encT_def
using _ assms apply (rule disjointness_geqI[where p=G1 and pk=pk1])
apply (metis assms(2) keygenT_def mem_simps(2) suppP_empty_simp)
by (simp add: UNION_singleton_eq_range fakeencT_def)
(* lemma aux_xa_x_1: "(\<forall>x xa::bit. xa = x + 1 \<or> P xa x) = (\<forall>x. P x x)"
using bit_neq by blast *)
lemma encT_injective:
assumes "P \<in> supp paramsT"
assumes "(pk,sk) \<in> supp (keygenT P)"
shows "inj_on (encrT P pk) (msg_spaceT P)"
proof -
have "(pk,sk) \<in> supp (keygen0 ())"
using assms(2) unfolding keygenT_def keygen_def by simp
then have iep: "injective_enc_pk () enc0 msg_space0 pk"
using enc0_injective[unfolded injective_enc_def, rule_format]
by auto
show ?thesis
proof (rule inj_onI)
fix m0 :: msg
and m1 :: msg
assume m0: "m0 \<in> msg_spaceT P"
and m1: "m1 \<in> msg_spaceT P"
and eqT: "encrT P pk m0 = encrT P pk m1"
have disj: "disjnt (supp (enc0 () pk m0)) (supp (enc0 () pk m1))"
apply (rule iep[unfolded injective_enc_pk_def, rule_format])
using m0 m1 msg_space unfolding msg_spaceT_def by auto
moreover have "encrT P pk m0 \<in> supp (enc0 () pk m0)"
unfolding encrT_def encr_def enc0_def by auto
moreover have "encrT P pk m1 \<in> supp (enc0 () pk m1)"
unfolding encrT_def encr_def enc0_def by auto
ultimately show "m0 = m1"
using eqT by (auto simp: disjnt_def)
qed
qed
lemma mk_Hq_uniform:
assumes "(pk,(sk,prfk)) \<in> supp (keygenFO (G,anyH))"
shows "map_distr (\<lambda>HqH0. mk_Hq (snd HqH0) (fst HqH0) G pk) (uniform UNIV) = uniform UNIV"
(is "?lhs = ?rhs")
proof -
have inj_encrT: "inj_on (encrT G pk) (msg_spaceT G)"
apply (rule encT_injective)
using assms by (auto simp: keygenFO_def paramsT_def)
have "?lhs = map_distr (\<lambda>HqH0' m. HqH0' (if m \<in> msg_spaceT G then Inr (encrT G pk m) else Inl m))
(map_distr (\<lambda>HqH0 m. case m of Inl m' \<Rightarrow> fst HqH0 m' | Inr m' \<Rightarrow> snd HqH0 m') (uniform UNIV))"
apply (simp add: mk_Hq_def[abs_def])
apply (subst if_distrib[where f="\<lambda>x. case x of Inl x \<Rightarrow> _ x | Inr x \<Rightarrow> _ x"])
apply (subst sum.case)+
by auto
also have "\<dots> = map_distr (\<lambda>HqH0' m. HqH0' (if m \<in> msg_spaceT G then Inr (encrT G pk m) else Inl m)) (uniform UNIV)"
apply (subst map_distr_uniform[where B=UNIV])
apply (rule bijI')
apply auto
apply (metis case_sum_o_inj(1))
apply (metis case_sum_o_inj(2))
by (metis case_sum_expand_Inr_pointfree)
also have "\<dots> = uniform UNIV"
apply (rule map_distr_uniform_regular[where B=UNIV])
thm reindex_regular[where i = "\<lambda>m. (if m \<in> msg_spaceT G then Inr (encrT G pk m) else Inl m)"]
apply (rule reindex_regular)
apply (rule injI)
apply (case_tac "x \<in> msg_spaceT G"; case_tac "y \<in> msg_spaceT G")
using inj_encrT by (auto simp: inj_onD)
finally show ?thesis
by -
qed
lemma keygenFO_anyH: "NO_MATCH undefined H \<Longrightarrow> keygenFO (G,H) = keygenFO (G,undefined)"
unfolding keygenFO_def by simp
lemma keygenFO_anyG: "NO_MATCH undefined G \<Longrightarrow> keygenFO (G,H) = keygenFO (undefined,H)"
unfolding keygenFO_def keygenT_def by simp
definition "Rbad pk sk m =
(if m\<in>msg_space() then {r. dec () sk (encr () pk m r) \<noteq> Some m} else {})"
definition "bad_pk pk sk = (\<exists>m\<in>msg_space(). Rbad pk sk m = UNIV)"
definition "RgoodG pk sk G \<longleftrightarrow> (\<forall>m. G m \<notin> Rbad pk sk m)"
definition "\<delta>bad pk sk m = real (card (Rbad pk sk m)) / real (card (UNIV::rand set))"
lemma [simp]: "\<delta>bad pk sk m \<ge> 0"
unfolding \<delta>bad_def by auto
lemma [simp]: "\<delta>bad pk sk m \<le> 1"
unfolding \<delta>bad_def
by (simp add: card_mono)
lemma \<delta>bad_correctness_pkskm: "\<delta>bad pk sk m = correctness_pkskm enc dec () pk sk m"
if "m \<in> msg_space()"
proof -
have "correctness_pkskm enc dec () pk sk m = Prob (uniform UNIV) (encr () pk m -` {c. dec () sk c \<noteq> Some m})"
unfolding correctness_pkskm_def enc_def Prob_map_distr' by simp
also have "\<dots> = real (card {r. dec () sk (encr () pk m r) \<noteq> Some m}) / real CARD(rand)"
unfolding Prob_uniform by simp
also have "\<dots> = \<delta>bad pk sk m"
by (simp add: \<delta>bad_def Rbad_def that)
finally show ?thesis
by simp
qed
lemma \<delta>bad_correctness_pksk:
"\<delta>bad pk sk m \<le> correctness_pksk enc dec msg_space () pk sk"
proof (cases "m \<in> msg_space()")
case True
then show ?thesis
unfolding correctness_pksk_def
by (simp add: cSUP_upper \<delta>bad_correctness_pkskm)
next
case False
then show ?thesis
unfolding \<delta>bad_def Rbad_def by auto
qed
definition "Rbad_select pk sk =
map_distr (\<lambda>F. {m. F m = 1}) (product_distr' (\<lambda>m. bernoulli (\<delta>bad pk sk m)))"
lemma [simp]: "weight (Rbad_select a b) = 1"
unfolding Rbad_select_def apply simp
apply (rule total_product_distr'I)
by simp
(* Needed to avoid undesired corner cases where we uniformly pick from the empty set *)
definition "Rbad' pk sk m = (if Rbad pk sk m = {} then {undefined} else Rbad pk sk m)"
definition "Rgood' pk sk m = (if Rbad pk sk m = UNIV then {undefined} else - Rbad pk sk m)"
definition "Rgood'G pk sk G \<longleftrightarrow> (\<forall>m. G m \<in> Rgood' pk sk m)"
lemma Rgood'_notempty[simp]: "Rgood' pk sk m \<noteq> {}"
unfolding Rgood'_def (* apply (cases "Rbad pk sk m = {}") *) by auto
lemma Rbad'_notempty[simp]: "Rbad' pk sk m \<noteq> {}"
unfolding Rbad'_def (* apply (cases "Rbad pk sk m = {}") *) by auto
lemma Rgood'_ex: "\<exists>x. \<forall>m. x m \<in> Rgood' pk sk m"
apply (subst choice_iff[symmetric])
using Rgood'_notempty by (meson equals0I)
lemma Rbad'_ex: "\<exists>x. \<forall>m. x m \<in> Rbad' pk sk m"
apply (subst choice_iff[symmetric])
using Rbad'_notempty by (meson equals0I)
(* Need to use uniform' instead of uniform in case Rbad is empty or UNIV *)
definition "G_goodbad_squash pk sk =
bind_distr (uniform {G. \<forall>m. G m \<in> Rgood' pk sk m})
(\<lambda>Ggood. map_distr (Pair Ggood)
(bind_distr (uniform {G. \<forall>m. G m \<in> Rbad' pk sk m})
(\<lambda>Gbad. map_distr (\<lambda>S. (Gbad, S, \<lambda>m. if m \<in> S then Gbad m else Ggood m))
(Rbad_select pk sk))))"
lemma G_goodbad_squash_4th: "map_distr (\<lambda>x. snd (snd (snd x))) (G_goodbad_squash pk2 sk2) = uniform UNIV"
(is "?lhs = _")
proof -
define good bad Ber where "good = Rgood' pk2 sk2"
and "bad = Rbad' pk2 sk2" and "Ber i = bernoulli (\<delta>bad pk2 sk2 i)" for i
have [simp]: "bad m \<noteq> {}" and [simp]: "good m \<noteq> {}" for m
unfolding bad_def Rbad'_def good_def Rgood'_def by auto
have "?lhs = bind_distr (uniform {G. \<forall>m. G m \<in> good m})
(\<lambda>goodG. bind_distr (uniform {G. \<forall>m. G m \<in> bad m})
(\<lambda>badG. map_distr (\<lambda>c m. if m \<in> c then badG m else goodG m)
(Rbad_select pk2 sk2)))"
unfolding G_goodbad_squash_def good_def bad_def
by (simp add: map_product_distr' flip: bind_distr_map_distr)
also have "\<dots> = product_distr'
(\<lambda>m. bind_distr (uniform (good m))
(\<lambda>Ggood. bind_distr (uniform (bad m))
(\<lambda>Gbad. map_distr (\<lambda>c. if c = 1 then Gbad else Ggood)
(Ber m))))"
(is "_ = product_distr' ?U")
unfolding Rbad_select_def Ber_def
apply (simp flip: product_distr'_uniform bind_distr_map_distr)
apply (subst map_product_distr')
apply (subst bind_product_distr')
apply (subst bind_product_distr')
by simp
also { fix m
consider (allGood) "Rbad pk2 sk2 m = {}"| (allBad) "Rbad pk2 sk2 m = UNIV"
| (normal) "Rbad pk2 sk2 m \<noteq> {}" and "Rbad pk2 sk2 m \<noteq> UNIV" by auto
then have "?U m = uniform UNIV"
proof cases
case normal
then show ?thesis
unfolding Ber_def apply (subst bernoulli_combine_uniform)
by (auto simp: \<delta>bad_def bad_def good_def disjnt_iff Rbad'_def Rgood'_def)
next
case allGood
then have "\<delta>bad pk2 sk2 m = 0"
unfolding \<delta>bad_def by simp
then have [simp]: "Ber m = point_distr 0"
unfolding Ber_def by (simp add: bernoulli_p0)
from allGood have [simp]: "good m = UNIV"
unfolding good_def Rgood'_def by simp
show ?thesis
apply (subst bind_point_distr[symmetric])
apply (subst bind_distr_twice_indep[where A="Ber m", symmetric])
apply (subst bind_distr_twice_indep[where A="Ber m", symmetric])
by simp
next
case allBad
then have "\<delta>bad pk2 sk2 m = 1"
unfolding \<delta>bad_def by simp
then have [simp]: "Ber m = point_distr 1"
unfolding Ber_def by (simp add: bernoulli_p1)
from allBad have [simp]: "bad m = UNIV"
unfolding bad_def Rbad'_def by simp
show ?thesis
apply (subst bind_point_distr[symmetric])
apply (subst bind_distr_twice_indep[where A="Ber m", symmetric])
apply (subst bind_distr_twice_indep[where A="Ber m", symmetric])
by simp
qed
}
then have "product_distr' ?U = uniform UNIV"
by auto
finally show ?thesis by -
qed
(* Ggood,Gbad,S,G <$ G_goodbad_squash pk sk; *)
(* Must be defined exactly like the term resulting from the squash tacting
in indcca-enc-fo-game1-game2.qrhl because it is used via "simp * G_goodbad_o2h_squash[symmetric]" *)
definition "G_goodbad_o2h_squash =
bind_distr (keygenT undefined) (\<lambda>z. map_distr (Pair z)
(bind_distr (uniform {G. \<forall>m. G m \<in> Rgood' (fst z) (snd z) m})
(\<lambda>za. map_distr (Pair za) (bind_distr
(uniform {G. \<forall>m. G m \<in> Rbad' (fst z) (snd z) m})
(\<lambda>zb. map_distr (\<lambda>x. (zb, x, \<lambda>m. if m \<in> x then zb m else za m))
(Rbad_select (fst z) (snd z)))))))"
lemma [simp]: "weight G_goodbad_o2h_squash = 1"
unfolding G_goodbad_o2h_squash_def
apply (simp flip: not_ex not_all)
apply (subst choice_iff[symmetric])+
apply (subst ex_in_conv[])+
using Rgood'_notempty Rbad'_notempty
by simp
(* A coupling of goodbad_o2h_distr and G_goodbad_o2h_squash.
Returns ((pk,sk),Ggood,Gbad,S,G), (S,G,Ggood,(pk,sk)) *)
definition "goodbad_o2h_distr_ext =
bind_distr (keygenT undefined) (\<lambda>(pk,sk).
bind_distr (uniform {G. \<forall>m. G m \<in> Rgood' pk sk m}) (\<lambda>Ggood.
bind_distr (uniform {G. \<forall>m. G m \<in> Rbad' pk sk m}) (\<lambda>Gbad.
bind_distr (Rbad_select pk sk) (\<lambda>S::msg set.
let G = \<lambda>m. if m \<in> S then Gbad m else Ggood m in
point_distr (((pk,sk),Ggood,Gbad,S,G), (S,Ggood,G,(pk,sk)))))))"
lemma [simp]: "weight goodbad_o2h_distr_ext = 1"
unfolding goodbad_o2h_distr_ext_def
apply (simp flip: not_ex not_all add: Let_def case_prod_beta)
apply (subst choice_iff[symmetric])+
apply (subst ex_in_conv[])+
using Rgood'_notempty Rbad'_notempty
by simp
(* (S,G,G',z') <$ goodbad_o2h_distr; *)
definition "goodbad_o2h_distr =
map_distr snd goodbad_o2h_distr_ext"
lemma weight_goodbad_o2h_distr[simp]: "weight goodbad_o2h_distr = 1"
unfolding goodbad_o2h_distr_def by simp
lemma [simp]: "goodbad_o2h_distr \<noteq> 0"
using weight_goodbad_o2h_distr by fastforce
lemma goodbad_o2h_distr_oradiff:
assumes "(S, G, H, z) \<in> supp goodbad_o2h_distr"
assumes "x \<notin> S"
shows "G x = H x"
using assms unfolding goodbad_o2h_distr_def goodbad_o2h_distr_ext_def
by (auto simp add: Let_def)
lemma [simp]: "map_distr fst goodbad_o2h_distr_ext = G_goodbad_o2h_squash"
by (simp add: goodbad_o2h_distr_ext_def G_goodbad_o2h_squash_def
bind_distr_map_distr[symmetric] case_prod_beta Let_def)
lemma [simp]: "map_distr snd goodbad_o2h_distr_ext = goodbad_o2h_distr"
unfolding goodbad_o2h_distr_def by simp
lemma goodbad_o2h_distr_ext_relationships[simplified Ball_def case_prod_beta prod_eq_iff fst_conv snd_conv, rule_format]:
"\<forall>(((pk1,sk1),Ggood1,Gbad1,S1,G1), (S2,G2,G'2,z'2))\<in>supp goodbad_o2h_distr_ext.
(pk1,sk1) = z'2 \<and> G1=G'2 \<and> S1=S2"
unfolding goodbad_o2h_distr_ext_def
by (simp add: case_prod_beta Let_def)
(* (S,G,z) <$ goodbad_scs_distr; *)
definition "goodbad_scs_distr =
bind_distr (keygenT undefined) (\<lambda>(pk,sk).
bind_distr (uniform {G. \<forall>m. G m \<in> Rgood' pk sk m}) (\<lambda>Ggood.
bind_distr (Rbad_select pk sk) (\<lambda>S::msg set.
point_distr (S,Ggood,(pk,sk)))))"
lemma [simp]: "weight goodbad_scs_distr = 1"
unfolding goodbad_scs_distr_def
apply (simp flip: not_ex not_all add: Let_def case_prod_beta)
apply (subst choice_iff[symmetric])+
apply (subst ex_in_conv[])+
using Rgood'_notempty Rbad'_notempty
by simp
lemma map_distr_goodbad_o2h_distr_goodbad_scs_distr:
"map_distr (\<lambda>x. (fst x, fst (snd x), snd (snd (snd x)))) goodbad_o2h_distr = goodbad_scs_distr"
proof -
have "map_distr (\<lambda>(S,G,G',z'). (S,G,z')) goodbad_o2h_distr = goodbad_scs_distr"
unfolding goodbad_o2h_distr_def goodbad_o2h_distr_ext_def goodbad_scs_distr_def
apply (simp flip: bind_distr_map_distr add: case_prod_beta Let_def)
apply (subst choice_iff[symmetric])+
apply (subst ex_in_conv[])+
using Rbad'_notempty unfolding case_prod_beta by simp
then show ?thesis
unfolding case_prod_beta by -
qed
lemma squash_rnd1:
"map_distr (\<lambda>x. (snd (snd x), fst (snd x), fst x)) goodbad_scs_distr = bind_distr (keygenT undefined) (\<lambda>z. map_distr (Pair z) (product_distr (uniform {G. \<forall>m. G m \<in> Rgood' (fst z) (snd z) m}) (Rbad_select (fst z) (snd z))))"
unfolding goodbad_scs_distr_def
by (simp flip: bind_distr_map_distr add: case_prod_beta)
lemma comm_op_Gout2_tmp_Gout2:
assumes [simp]: "declared_qvars \<lbrakk>quantA1, Hin1, Hout1, Gin1, Gout1, quantA2, Hin2, Hout2, Gin2, Gout2, tmp_Gout2\<rbrakk>"
shows "(comm_op\<guillemotright>\<lbrakk>Gout2, tmp_Gout2\<rbrakk>) \<cdot> \<lbrakk>quantA1, Hin1, Hout1, Gin1, Gout1\<rbrakk> \<equiv>\<qq> \<lbrakk>quantA2, Hin2, Hout2, Gin2, Gout2\<rbrakk>
= \<lbrakk>quantA1, Hin1, Hout1, Gin1, Gout1\<rbrakk> \<equiv>\<qq> \<lbrakk>quantA2, Hin2, Hout2, Gin2, tmp_Gout2\<rbrakk>"
(is "?lhs = ?rhs")
proof -
define C where "C = comm_op\<guillemotright>\<lbrakk>Gout2, tmp_Gout2\<rbrakk>"
have "unitary C"
unfolding C_def by simp
note colo = qvar_trafo'_colocal[OF _ \<open>unitary C\<close>]
have C_tmp_Gout2: "qvar_trafo' C \<lbrakk>tmp_Gout2\<rbrakk> \<lbrakk>Gout2\<rbrakk>"
unfolding C_def by (rule qvar_trafo'_comm_op', simp)
have C1: "qvar_trafo' C \<lbrakk>quantA1, Hin1, Hout1, Gin1, Gout1\<rbrakk> \<lbrakk>quantA1, Hin1, Hout1, Gin1, Gout1\<rbrakk>"
by (rule colo, simp add: C_def)
have C2:"qvar_trafo' C \<lbrakk>quantA2, Hin2, Hout2, Gin2, tmp_Gout2\<rbrakk> \<lbrakk>quantA2, Hin2, Hout2, Gin2, Gout2\<rbrakk>"
apply (rule qvar_trafo'_concat[rotated 2], simp, simp)
apply (rule colo, simp add: C_def)
apply (rule qvar_trafo'_concat[rotated 2], simp, simp)
apply (rule colo, simp add: C_def)
apply (rule qvar_trafo'_concat[rotated 2], simp, simp)
apply (rule colo, simp add: C_def)
apply (rule qvar_trafo'_concat[rotated 2], simp, simp)
apply (rule colo, simp add: C_def)
by (fact C_tmp_Gout2)
from C1 C2 have "qvar_trafo' C
(variable_concat \<lbrakk>quantA1, Hin1, Hout1, Gin1, Gout1\<rbrakk> \<lbrakk>quantA2, Hin2, Hout2, Gin2, tmp_Gout2\<rbrakk>)
(variable_concat \<lbrakk>quantA1, Hin1, Hout1, Gin1, Gout1\<rbrakk> \<lbrakk>quantA2, Hin2, Hout2, Gin2, Gout2\<rbrakk>)"
by (rule qvar_trafo'_concat, simp_all)
then show ?thesis
unfolding C_def
by (rule qvar_trafo'_quantum_equality_full)
qed
lemma comm_op_Gout2_tmp_Gout2_tmp:
assumes [simp]: "declared_qvars \<lbrakk>quantA1, Hin1, Hout1, Gin1, Gout1, quantA2, Hin2, Hout2, Gin2, Gout2, tmp_Gout2, tmp_Gout1\<rbrakk>"
shows "(comm_op\<guillemotright>\<lbrakk>Gout2, tmp_Gout2\<rbrakk>) \<cdot> \<lbrakk>quantA1, Hin1, Hout1, Gin1, Gout1, tmp_Gout1\<rbrakk> \<equiv>\<qq> \<lbrakk>quantA2, Hin2, Hout2, Gin2, Gout2, tmp_Gout2\<rbrakk>
= \<lbrakk>quantA1, Hin1, Hout1, Gin1, Gout1, tmp_Gout1\<rbrakk> \<equiv>\<qq> \<lbrakk>quantA2, Hin2, Hout2, Gin2, tmp_Gout2, Gout2\<rbrakk>"
(is "?lhs = ?rhs")
proof -
define C where "C = comm_op\<guillemotright>\<lbrakk>Gout2, tmp_Gout2\<rbrakk>"
have "unitary C"
unfolding C_def by simp
note colo = qvar_trafo'_colocal[OF _ \<open>unitary C\<close>]
have C_tmp_Gout2: "qvar_trafo' C \<lbrakk>tmp_Gout2\<rbrakk> \<lbrakk>Gout2\<rbrakk>"
unfolding C_def by (rule qvar_trafo'_comm_op', simp)
have C_tmp_Gout2': "qvar_trafo' C \<lbrakk>Gout2\<rbrakk> \<lbrakk>tmp_Gout2\<rbrakk>"
unfolding C_def by (rule qvar_trafo'_comm_op, simp)
have C1: "qvar_trafo' C \<lbrakk>quantA1, Hin1, Hout1, Gin1, Gout1, tmp_Gout1\<rbrakk> \<lbrakk>quantA1, Hin1, Hout1, Gin1, Gout1, tmp_Gout1\<rbrakk>"
by (rule colo, simp add: C_def)
have C2:"qvar_trafo' C \<lbrakk>quantA2, Hin2, Hout2, Gin2, tmp_Gout2, Gout2\<rbrakk> \<lbrakk>quantA2, Hin2, Hout2, Gin2, Gout2, tmp_Gout2\<rbrakk>"
apply (rule qvar_trafo'_concat[rotated 2], simp, simp)
apply (rule colo, simp add: C_def)
apply (rule qvar_trafo'_concat[rotated 2], simp, simp)
apply (rule colo, simp add: C_def)
apply (rule qvar_trafo'_concat[rotated 2], simp, simp)
apply (rule colo, simp add: C_def)
apply (rule qvar_trafo'_concat[rotated 2], simp, simp)
apply (rule colo, simp add: C_def)
apply (rule qvar_trafo'_concat[rotated 2], simp, simp)
apply (fact C_tmp_Gout2)
by (fact C_tmp_Gout2')
from C1 C2 have "qvar_trafo' C
(variable_concat \<lbrakk>quantA1, Hin1, Hout1, Gin1, Gout1, tmp_Gout1\<rbrakk> \<lbrakk>quantA2, Hin2, Hout2, Gin2, tmp_Gout2, Gout2\<rbrakk>)
(variable_concat \<lbrakk>quantA1, Hin1, Hout1, Gin1, Gout1, tmp_Gout1\<rbrakk> \<lbrakk>quantA2, Hin2, Hout2, Gin2, Gout2, tmp_Gout2\<rbrakk>)"
by (rule qvar_trafo'_concat, simp_all)
then show ?thesis
unfolding C_def
by (rule qvar_trafo'_quantum_equality_full)
qed
lemma comm_op_Gout2_tmp_Gout2':
assumes [simp]: "declared_qvars \<lbrakk>quantA1, Hin1, Hout1, Gin1, Gout1, quantA2, Hin2, Hout2, tmp_Gin2, Gout2, tmp_Gout2\<rbrakk>"
shows "(comm_op\<guillemotright>\<lbrakk>Gout2, tmp_Gout2\<rbrakk>) \<cdot> \<lbrakk>quantA1, Hin1, Hout1, Gin1, Gout1\<rbrakk> \<equiv>\<qq> \<lbrakk>quantA2, Hin2, Hout2, tmp_Gin2, tmp_Gout2\<rbrakk>
= \<lbrakk>quantA1, Hin1, Hout1, Gin1, Gout1\<rbrakk> \<equiv>\<qq> \<lbrakk>quantA2, Hin2, Hout2, tmp_Gin2, Gout2\<rbrakk>"
(is "?lhs = ?rhs")
apply (rule qvar_trafo'_quantum_equality_full)
apply (rule qvar_trafo'_concat[rotated 2], simp, simp)
apply (rule qvar_trafo'_colocal, simp, simp)
apply (rule qvar_trafo'_concat[rotated 2], simp, simp)
apply (rule qvar_trafo'_colocal, simp, simp)
apply (rule qvar_trafo'_concat[rotated 2], simp, simp)
apply (rule qvar_trafo'_colocal, simp, simp)
apply (rule qvar_trafo'_concat[rotated 2], simp, simp)
apply (rule qvar_trafo'_colocal, simp, simp)
apply (rule qvar_trafo'_concat[rotated 2], simp, simp)
apply (rule qvar_trafo'_colocal, simp, simp)
apply (rule qvar_trafo'_comm_op, simp)
by -
lemma comm_op_Gin2_tmp_Gin2:
assumes [simp]: "declared_qvars \<lbrakk>quantA1, Hin1, Hout1, Gin1, Gout1, quantA2, Hin2, Hout2, Gin2, tmp_Gout2, tmp_Gin2\<rbrakk>"
shows "(comm_op\<guillemotright>\<lbrakk>Gin2, tmp_Gin2\<rbrakk>) \<cdot> \<lbrakk>quantA1, Hin1, Hout1, Gin1, Gout1\<rbrakk> \<equiv>\<qq> \<lbrakk>quantA2, Hin2, Hout2, Gin2, tmp_Gout2\<rbrakk>
= \<lbrakk>quantA1, Hin1, Hout1, Gin1, Gout1\<rbrakk> \<equiv>\<qq> \<lbrakk>quantA2, Hin2, Hout2, tmp_Gin2, tmp_Gout2\<rbrakk>"
apply (rule qvar_trafo'_quantum_equality_full)
apply (rule qvar_trafo'_concat[rotated 2], simp, simp)
apply (rule qvar_trafo'_colocal, simp, simp)
apply (rule qvar_trafo'_concat[rotated 2], simp, simp)
apply (rule qvar_trafo'_colocal, simp, simp)
apply (rule qvar_trafo'_concat[rotated 2], simp, simp)
apply (rule qvar_trafo'_colocal, simp, simp)
apply (rule qvar_trafo'_concat[rotated 2], simp, simp)
apply (rule qvar_trafo'_colocal, simp, simp)
apply (rule qvar_trafo'_concat[rotated 2], simp, simp)
apply (rule qvar_trafo'_comm_op', simp)
by (rule qvar_trafo'_colocal, simp, simp)
lemma comm_op_Gin2_tmp_Gin2':
assumes [simp]: "declared_qvars \<lbrakk>quantA1, Hin1, Hout1, Gin1, Gout1, quantA2, Hin2, Hout2, Gin2, Gout2, tmp_Gin2\<rbrakk>"
shows "comm_op\<guillemotright>\<lbrakk>Gin2, tmp_Gin2\<rbrakk> \<cdot> \<lbrakk>quantA1, Hin1, Hout1, Gin1, Gout1\<rbrakk> \<equiv>\<qq> \<lbrakk>quantA2, Hin2, Hout2, tmp_Gin2, Gout2\<rbrakk>
= \<lbrakk>quantA1, Hin1, Hout1, Gin1, Gout1\<rbrakk> \<equiv>\<qq> \<lbrakk>quantA2, Hin2, Hout2, Gin2, Gout2\<rbrakk>"
apply (rule qvar_trafo'_quantum_equality_full)
apply (rule qvar_trafo'_concat[rotated 2], simp, simp)
apply (rule qvar_trafo'_colocal, simp, simp)
apply (rule qvar_trafo'_concat[rotated 2], simp, simp)
apply (rule qvar_trafo'_colocal, simp, simp)
apply (rule qvar_trafo'_concat[rotated 2], simp, simp)
apply (rule qvar_trafo'_colocal, simp, simp)
apply (rule qvar_trafo'_concat[rotated 2], simp, simp)
apply (rule qvar_trafo'_colocal, simp, simp)
apply (rule qvar_trafo'_concat[rotated 2], simp, simp)
apply (rule qvar_trafo'_comm_op, simp)
apply (rule qvar_trafo'_colocal, simp, simp)
by -
lemma aux5a:
assumes [simp]: "declared_qvars \<lbrakk>quantA1, quantA2, Gout2, Gin2, aux1, aux2\<rbrakk>"
shows "\<lbrakk>quantA1,aux1\<rbrakk> \<equiv>\<qq> \<lbrakk>quantA2,aux2\<rbrakk>
\<sqinter> ccspan {ket (gin2, G2 gin2)}\<guillemotright>\<lbrakk>Gin2, Gout2\<rbrakk>
\<le> \<lbrakk>quantA1,aux1\<rbrakk> \<equiv>\<qq> \<lbrakk>quantA2,aux2\<rbrakk>
\<sqinter> ccspan {ket (G2 gin2)}\<guillemotright>\<lbrakk>Gout2\<rbrakk> \<squnion> (- ccspan {ket (G2 gin2)})\<guillemotright>\<lbrakk>Gout2\<rbrakk>"
apply (rule sup.coboundedI1)
apply (rule inf_mono)
apply simp
apply (rule ket_less_specific)
by simp
lemma aux5b:
assumes [simp]: "declared_qvars \<lbrakk>quantA1, quantA2, Gout2, Gin2, aux1, aux2\<rbrakk>"
shows "x \<noteq> G2 gin2 \<Longrightarrow> \<lbrakk>quantA1,aux1\<rbrakk> \<equiv>\<qq> \<lbrakk>quantA2,aux2\<rbrakk>
\<sqinter> ccspan {ket (gin2, G2 gin2)}\<guillemotright>\<lbrakk>Gin2, Gout2\<rbrakk> \<le> (- ccspan {ket x})\<guillemotright>\<lbrakk>Gout2\<rbrakk>"
apply (rule inf.coboundedI2)
apply (rule order_trans)
apply (rule ket_less_specific)
apply simp
apply simp
apply (rule ccspan_leq_ortho_ccspan)
by simp
(* lemma variable_for_name[intro]: "variable_name (Abs_variable (Abs_variable_raw (name,range (embedding::'a\<Rightarrow>_))) :: 'a::universe variable) = name"
unfolding variable_name.rep_eq
apply (subst Abs_variable_inverse)
unfolding variable_raw_domain.rep_eq
apply simp
apply (subst Abs_variable_raw_inverse)
apply simp_all
unfolding variable_raw_name.rep_eq
apply (subst Abs_variable_raw_inverse)
by auto *)
lemma aux6:
assumes [simp]: "declared_qvars \<lbrakk>quantA1, quantA2, Gout2, Gin2, aux1, aux2\<rbrakk>"
shows "\<lbrakk>quantA1,aux1\<rbrakk> \<equiv>\<qq> \<lbrakk>quantA2,aux2\<rbrakk> \<sqinter> ccspan {ket gin2}\<guillemotright>\<lbrakk>Gin2\<rbrakk> \<le> \<CC>\<ll>\<aa>[\<parallel>ket 0\<parallel> = 1] \<sqinter> (\<lbrakk>quantA1,aux1\<rbrakk> \<equiv>\<qq> \<lbrakk>quantA2,aux2\<rbrakk> \<sqinter> ccspan {ket (gin2, 0)}\<guillemotright>\<lbrakk>Gin2, Gout2\<rbrakk>) \<div> ket 0\<guillemotright>\<lbrakk>Gout2\<rbrakk>"
apply (auto intro: inf.coboundedI2 inf.coboundedI1 simp: ket_product)
apply (subst inf_commute, subst inf_assoc, rule inf.coboundedI2, subst inf_commute)
apply (subst tensor_lift[symmetric], simp)
apply (subst span_tensor)
by (simp add: ket_product)
lemma [simp]: "{..<n} = {} \<longleftrightarrow> n=0" for n :: nat
by auto
lemma correctness_pksk_enc_leq1[simp]: "correctness_pksk enc dec msg_space p pk sk \<le> 1"
apply (rule correctness_pksk_leq1)
by auto
lemma Prob_Rbad_select: "Prob (Rbad_select pk sk) (Collect ((\<in>) guess2)) = \<delta>bad pk sk guess2"
proof -
have "Prob (Rbad_select pk sk) (Collect ((\<in>) guess2)) =
prob (map_distr (\<lambda>S. guess2\<in>S) (Rbad_select pk sk)) True"
by (subst Prob_map_distr, simp)
also have "\<dots> = prob (bernoulli (\<delta>bad pk sk guess2)) 1"
apply (simp add: Rbad_select_def)
apply (subst map_distr_product_distr'_onepoint, simp)
apply (subst prob_True_prob_1, simp)
apply (rewrite at "map_distr \<hole>" DEADID.rel_mono_strong[of _ "\<lambda>x. x"])
by auto
also have "\<dots> = \<delta>bad pk sk guess2"
apply (subst bernoulli1)
by auto
finally show ?thesis
by -
qed
(* lemma "bind_distr \<mu> (\<lambda>x. bernoulli (f x)) = bernoulli (expectation (map_distr f \<mu>))" *)
lemma bind_keygen_bernoulli_correct:
"bind_distr (keygenT undefined) (\<lambda>x. bernoulli (correctness_pksk enc dec msg_space () (fst x) (snd x))) = bernoulli (correctness params keygen enc dec msg_space)"
proof (rule bin_distr_eqI[where x=1 and y=0], (auto)[3])
define c C where "c x = correctness_pksk enc dec msg_space () (fst x) (snd x)"
and "C = correctness params keygen enc dec msg_space" for x
have "prob (bind_distr (keygenT undefined) (\<lambda>x. bernoulli (c x))) 1 =
prob (bind_distr (map_distr c (keygenT undefined)) bernoulli) 1"
apply (subst bind_distr_map_distr') by simp
also have "\<dots> = expectation' (keygenT undefined) c"
apply (rule prob_bind_distr_bernoulli)
unfolding c_def by auto
also have "\<dots> = C"
unfolding C_def c_def correctness_def params_def params0_def keygenT_def case_prod_beta
by simp
also have "\<dots> = prob (bernoulli C) 1"
apply (subst bernoulli1)
unfolding C_def by auto
finally show "prob (bind_distr (keygenT undefined) (\<lambda>x. bernoulli (c x))) 1 = prob (bernoulli C) 1"
by -
qed
lemma aux7:
assumes "x <= 4 * real (qG + 2 * qH + qD + 1) * y"
shows "2 * sqrt ((1 + real (qG + 2 * qH + qD + 1)) * x)
\<le> 2 * sqrt (4 * (1 + real (qG + 2 * qH + qD + 1)) *
real (qG + 2 * qH + qD + 1) * y)"
apply (subst (5) mult.commute)
apply (subst mult.assoc)
using assms by auto
lemma aux8:
assumes "x \<le> y"
shows "4 * real (qG + 2 * qH + qD + 1) * x \<le> (4 + (4 * real qG + 8 * real qH + 4 * real qD)) * y"
(* shows "4 * real (qG + 2 * qH + qD + 1) * x \<le> (1 + (real qG + 2 * real qH + real qD)) * y" *)
(* shows "4 * real (qG + 2 * qH + qD + 1) * x \<le> (4 + (4 * real qG + 8 * real qH + 4 * real qD)) * y" *)
using assms by auto
definition "G_goodbad_o2h_squash2 =
bind_distr (keygenT undefined) (\<lambda>z. map_distr (Pair z) (bind_distr (uniform {G. \<forall>m. G m \<in> Rgood' (fst z) (snd z) m}) (\<lambda>za. map_distr (Pair za) (bind_distr (uniform {G. \<forall>m. G m \<in> Rbad' (fst z) (snd z) m}) (\<lambda>zb. map_distr (\<lambda>x. (zb, x, za)) (Rbad_select (fst z) (snd z)))))))"
(* A coupling of goodbad_o2h_distr and G_goodbad_o2h_squash2.
Returns ((pk,sk),Ggood,Gbad,S,G), (S,G,Ggood,(pk,sk)) *)
definition "goodbad_o2h_distr_ext2 =
bind_distr (keygenT undefined) (\<lambda>(pk,sk).
bind_distr (uniform {G. \<forall>m. G m \<in> Rgood' pk sk m}) (\<lambda>Ggood.
bind_distr (uniform {G. \<forall>m. G m \<in> Rbad' pk sk m}) (\<lambda>Gbad.
bind_distr (Rbad_select pk sk) (\<lambda>S::msg set.
let G = \<lambda>m. if m \<in> S then Gbad m else Ggood m in
point_distr (((pk,sk),Ggood,Gbad,S,Ggood), (S,Ggood,G,(pk,sk)))))))"
lemma goodbad_o2h_distr_ext2_relationships[simplified Ball_def case_prod_beta prod_eq_iff fst_conv snd_conv, rule_format]:
"\<forall>(((pk1,sk1),Ggood1,Gbad1,S1,G1), (S2,G2,G'2,z'2))\<in>supp goodbad_o2h_distr_ext2.
(pk1,sk1) = z'2 \<and> G1=G2 \<and> S1=S2"
unfolding goodbad_o2h_distr_ext2_def
by (simp add: case_prod_beta Let_def)
lemma [simp]: "map_distr fst goodbad_o2h_distr_ext2 = G_goodbad_o2h_squash2"
unfolding goodbad_o2h_distr_ext2_def G_goodbad_o2h_squash2_def
Let_def bind_distr_map_distr[symmetric] case_prod_beta
by simp
lemma [simp]: "map_distr snd goodbad_o2h_distr_ext2 = goodbad_o2h_distr"
unfolding goodbad_o2h_distr_def goodbad_o2h_distr_ext2_def goodbad_o2h_distr_ext_def
Let_def bind_distr_map_distr[symmetric] case_prod_beta
by simp
lemma [simp]: "a \<sqinter> b \<sqinter> c \<le> b" for b :: "_::semilattice_inf"
by (simp add: inf.coboundedI1)
lemma [simp]: "a \<sqinter> b \<sqinter> c \<le> a" for b :: "_::semilattice_inf"
by (simp add: inf.coboundedI1)
lemma Prob_goodbad_o2h_distr_bad_pk:
"Prob goodbad_o2h_distr {(S, G, G', x, y). bad_pk x y} \<le> correctness params keygen enc dec msg_space"
proof -
have [simp]: "\<exists>xa. \<forall>m. xa m \<in> Rgood' (fst x) (snd x) m" for x
by (simp add: Rgood'_ex)
have [simp]: "\<exists>xa. \<forall>m. xa m \<in> Rbad' (fst x) (snd x) m" for x
by (simp add: Rbad'_ex)
let ?cpksk = "correctness_pksk enc dec msg_space ()"
let ?cpkskm = "correctness_pkskm enc dec ()"
have "?cpksk pk sk \<ge> 1" if "bad_pk pk sk" for pk sk
proof -
from that obtain m where msg_space: "m\<in>msg_space ()" and "Rbad pk sk m = UNIV"
unfolding bad_pk_def by auto
then have "dec () sk (encr () pk m r) \<noteq> Some m" for r
unfolding Rbad_def by auto
with msg_space have "?cpkskm pk sk m = 1"
unfolding correctness_pkskm_def enc_def Prob_map_distr by auto
with msg_space show "?cpksk pk sk \<ge> 1"
by (metis (full_types) \<delta>bad_correctness_pksk \<delta>bad_correctness_pkskm)
qed
moreover have "bad_pk pk sk" if "?cpksk pk sk \<ge> 1" for pk sk
proof -
from that have "?cpksk pk sk = 1"
by (simp add: basic_trans_rules(24))
from this[symmetric] have "1 \<in> correctness_pkskm enc dec () pk sk ` msg_space ()"
unfolding correctness_pksk_def
by (metis (full_types) Max_ge Max_in cSup_eq_maximum equals0D equals0I finite finite_imageI imageI nonempty_msg_space)
then obtain m where msg_space: "m\<in>msg_space ()" and "?cpkskm pk sk m = 1"
by auto
then have "Prob (enc () pk m) {c. dec () sk c \<noteq> Some m} = 1"
unfolding correctness_pkskm_def by simp
then have "Prob (uniform UNIV) {r. dec () sk (encr () pk m r) \<noteq> Some m} = 1"
unfolding Prob_map_distr enc_def by simp
then have "{r. dec () sk (encr () pk m r) \<noteq> Some m} = UNIV"
apply (rule full_Prob[rotated 2])
by auto
with msg_space have "Rbad pk sk m = UNIV"
unfolding Rbad_def by simp
with msg_space show "bad_pk pk sk"
unfolding bad_pk_def by auto
qed
ultimately have bad_pk_cpksk: "bad_pk pk sk \<longleftrightarrow> ?cpksk pk sk \<ge> 1" for pk sk
by auto
have "Prob goodbad_o2h_distr {(S, G, G', x, y). bad_pk x y} = Prob (keygenT undefined) {(pk,sk). bad_pk pk sk}"
unfolding goodbad_o2h_distr_def goodbad_o2h_distr_ext_def Prob_map_distr case_prod_beta bind_distr_map_distr[symmetric] Let_def
by simp
also have "\<dots> = Prob (map_distr (\<lambda>(pk,sk). ?cpksk pk sk) (keygenT undefined)) {1..}"
apply (subst bad_pk_cpksk)
unfolding bad_pk_def correctness_pksk_def Prob_map_distr case_prod_beta
by auto
also have "\<dots> \<le> expectation (map_distr (\<lambda>(pk,sk). ?cpksk pk sk) (keygenT undefined)) / 1"
apply (rule markov_inequality)
apply (rule expectation_exists_bounded[where a=0 and b=1])
by auto
also have "\<dots> = correctness params keygen enc dec msg_space"
unfolding correctness_def params_def params0_def keygenT_def
by simp
finally show ?thesis
by -
qed
lemma Rgood'_def':
assumes "\<not> bad_pk pk sk"
assumes "m \<in> msg_space()"
shows "Rgood' pk sk m = - Rbad pk sk m"
using assms unfolding Rgood'_def bad_pk_def by auto
lemma guard_equal_not_in_range:
fixes pk sk G c
assumes good: "Rgood'G pk sk G"
defines "m' == dec () sk c"
shows "(if bad_pk pk sk then (c \<notin> encrT G pk ` msg_space ())
else (m'=None \<or> encrT G pk (the m') \<noteq> c))
\<longleftrightarrow> c \<notin> encrT G pk ` msg_space ()"
proof (cases "bad_pk pk sk")
case True
then show ?thesis by simp
next
case False
note not_bad = False
have "m'\<noteq>None" if "c \<in> encrT G pk ` msg_space ()"
proof -
from that obtain m2 where msg_space: "m2 \<in> msg_space ()" and c: "c = encrT G pk m2"
unfolding msg_spaceT_def apply atomize_elim by auto
from good have "G m2 \<in> Rgood' pk sk m2"
unfolding Rgood'G_def by simp
with not_bad msg_space have "G m2 \<notin> Rbad pk sk m2"
apply (subst (asm) Rgood'_def')
by auto
with msg_space have "dec () sk c = Some m2"
unfolding Rbad_def encrT_def c by simp
with m'_def have "m' = Some m2"
by simp
then show ?thesis
by simp
qed
moreover have "encrT G pk (the m') = c" if "c \<in> encrT G pk ` msg_space ()" and "m' \<noteq> None"
proof -
from \<open>m' \<noteq> None\<close> obtain m where m': "m' = Some m"
by auto
from that obtain m2 where msg_space: "m2 \<in> msg_space ()" and c: "c = encrT G pk m2"
unfolding msg_spaceT_def apply atomize_elim by auto
from good have "G m2 \<in> Rgood' pk sk m2"
unfolding Rgood'G_def by simp
with not_bad msg_space have "G m2 \<notin> Rbad pk sk m2"
apply (subst (asm) Rgood'_def')
by auto
with msg_space have "dec () sk c = Some m2"
unfolding Rbad_def encrT_def c by simp
with m' m'_def have "m = m2"
by simp
with c show ?thesis
unfolding encrT_def m' by auto
qed
moreover have "c \<in> encrT G pk ` msg_space ()"
if "m'\<noteq>None" and c_def[symmetric]: "encrT G pk (the m') = c"
proof -
from that obtain m where msg_space: "m \<in> msg_space ()" and m': "m' = Some m"
\<comment> \<open>Uses that dec never returns a message outside the msg_space by construction\<close>
apply atomize_elim unfolding dec_def m'_def apply auto
by (smt option.case_eq_if option.sel option.simps(2))
have "c = encrT G pk m"
unfolding encrT_def c_def m' by simp
with msg_space show ?thesis by auto
qed
ultimately show ?thesis using False by auto
qed
lemma goodbad_o2h_distr_goodG:
assumes "(S, Ggood, Gbad, (pk,sk)) \<in> supp goodbad_o2h_distr"
shows "Rgood'G pk sk Ggood"
proof -
from assms have "Ggood \<in> supp (uniform {G. \<forall>m. G m \<in> Rgood' pk sk m})"
unfolding goodbad_o2h_distr_def goodbad_o2h_distr_ext_def
by (auto simp: Let_def)
then have "Ggood m \<in> Rgood' pk sk m" for m