-
Notifications
You must be signed in to change notification settings - Fork 16
/
tls-lib.cvl
2157 lines (1709 loc) · 87.1 KB
/
tls-lib.cvl
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
forall x:bool; not(not(x)) = x.
forall x:bool,y:bool; (not(x && y)) = (not(x) || not(y)).
forall x:bool,y:bool; (not(x || y)) = (not(x) && not(y)).
forall ; not(true) = false.
forall ; not(false) = true.
const bottom:bitstringbot.
(* We define the equivalence used internally by the command "move array" *)
define move_array_internal_macro(T) {
param N, NX, Neq.
equiv move_array(T)
!N new X:T; (!NX OX() := X,
!Neq Oeq(X':T) := X' = X)
<=(#Oeq / |T|)=> [manual,computational]
!N (!NX OX() := find[unique] j<=NX suchthat defined(Y[j]) then Y[j] else new Y:T; Y,
!Neq Oeq(X':T) := find[unique] j<=NX suchthat defined(Y[j]) then X' = Y[j] else false).
}
(***************************** Symmetric encryption *********************************************)
(* IND-CPA probabilistic symmetric encryption
keyseed: type of key seeds, must be "bounded" (to be able to generate random numbers from it), typically "fixed" and "large".
key: type of keys, must be "bounded"
cleartext: type of cleartexts
ciphertext: type of ciphertexts
seed: type of random seeds for encryption, must be "bounded", typically "fixed".
kgen: key generation function
enc: encryption function
dec: decryption function
injbot: natural injection from cleartext to bitstringbot
Z: function that returns for each cleartext a cleartext of the same length consisting only of zeroes.
Penc(t, N, l): probability of breaking the IND-CPA property in time
t for one key and N encryption queries with cleartexts of length at
most l
The types keyseed, key, cleartext, ciphertext, seed and the
probability Penc must be declared before this macro is
expanded. The functions kgen, enc, dec, injbot, and Z are declared
by this macro. They must not be declared elsewhere, and they can be
used only after expanding the macro.
*)
define IND_CPA_sym_enc(keyseed, key, cleartext, ciphertext, seed, kgen, enc, dec, injbot, Z, Penc) {
param N, N2.
fun enc(cleartext, key, seed): ciphertext.
fun kgen(keyseed):key.
fun dec(ciphertext, key): bitstringbot.
fun enc2(cleartext, key, seed): ciphertext.
fun kgen2(keyseed):key.
fun injbot(cleartext):bitstringbot [compos].
(* The function Z returns for each bitstring, a bitstring
of the same length, consisting only of zeroes. *)
fun Z(cleartext):cleartext.
forall x:cleartext; injbot(x) <> bottom.
forall m:cleartext, r:keyseed, r2:seed;
dec(enc(m, kgen(r), r2), kgen(r)) = injbot(m).
equiv ind_cpa(enc)
! N2 new r: keyseed; ! N new r2: seed; Oenc(x:cleartext) := enc(x, kgen(r), r2)
<=(N2 * Penc(time + (N2-1)*(time(kgen) + N*time(enc, maxlength(x)) + N*time(Z, maxlength(x))), N, maxlength(x)))=>
! N2 new r: keyseed; ! N new r2: seed; Oenc(x:cleartext) := enc2(Z(x), kgen2(r), r2).
}
(* IND-CPA and INT-CTXT probabilistic symmetric encryption
keyseed: type of key seeds, must be "bounded" (to be able to generate random numbers from it), typically "fixed" and "large".
key: type of keys, must be "bounded"
cleartext: type of cleartexts
ciphertext: type of ciphertexts
seed: type of random seeds for encryption, must be "bounded", typically "fixed".
kgen: key generation function
enc: encryption function
dec: decryption function
injbot: natural injection from cleartext to bitstringbot
Z: function that returns for each cleartext a cleartext of the same length consisting only of zeroes.
Penc(t, N, l): probability of breaking the IND-CPA property in time
t for one key and N encryption queries with cleartexts of length at
most l
Pencctxt(t, N, N', l, l'): probability of breaking the INT-CTXT property
in time t for one key, N encryption queries, N' decryption queries with
cleartexts of length at most l and ciphertexts of length at most l'.
The types keyseed, key, cleartext, ciphertext, seed and the
probabilities Penc, Pencctxt must be declared before this macro is
expanded. The functions kgen, enc, dec, injbot, and Z are declared
by this macro. They must not be declared elsewhere, and they can be
used only after expanding the macro.
*)
define IND_CPA_INT_CTXT_sym_enc(keyseed, key, cleartext, ciphertext, seed, kgen, enc, dec, injbot, Z, Penc, Pencctxt) {
param N, N2, N3.
fun enc(cleartext, key, seed): ciphertext.
fun kgen(keyseed):key.
fun dec(ciphertext, key): bitstringbot.
fun enc2(cleartext, key, seed): ciphertext.
fun kgen2(keyseed):key.
fun injbot(cleartext):bitstringbot [compos].
forall x:cleartext; injbot(x) <> bottom.
(* The function Z returns for each bitstring, a bitstring
of the same length, consisting only of zeroes. *)
fun Z(cleartext):cleartext.
forall m:cleartext, r:keyseed, r2:seed;
dec(enc(m, kgen(r), r2), kgen(r)) = injbot(m).
(* IND-CPA *)
equiv ind_cpa(enc)
! N2 new r: keyseed; ! N new r2: seed; Oenc(x:cleartext) := enc(x, kgen2(r), r2)
<=(N2 * Penc(time + (N2-1)*(time(kgen) + N*time(enc, maxlength(x)) + N*time(Z, maxlength(x))), N, maxlength(x)))=>
! N2 new r: keyseed; ! N new r2: seed; Oenc(x:cleartext) := enc2(Z(x), kgen2(r), r2).
(* INT-CTXT *)
equiv int_ctxt(enc)
! N2 new r: keyseed; (!N new r2: seed; Oenc(x:cleartext) := enc(x, kgen(r), r2),
!N3 Odec(y:ciphertext) := dec(y,kgen(r)))
<=(N2 * Pencctxt(time + (N2-1)*(time(kgen) + N*time(enc, maxlength(x)) + N3*time(dec,maxlength(y))), N, N3, maxlength(x), maxlength(y)))=> [computational]
! N2 new r: keyseed [unchanged];
(!N new r2: seed [unchanged]; Oenc(x:cleartext) := let z:ciphertext = enc(x, kgen2(r), r2) in z,
!N3 Odec(y:ciphertext) := find j <= N suchthat defined(x[j],r2[j],z[j]) && z[j] = y then injbot(x[j]) else bottom).
}
(* IND-CCA2 probabilistic symmetric encryption
keyseed: type of key seeds, must be "bounded" (to be able to generate random numbers from it), typically "fixed" and "large".
key: type of keys, must be "bounded"
cleartext: type of cleartexts
ciphertext: type of ciphertexts
seed: type of random seeds for encryption, must be "bounded", typically "fixed".
kgen: key generation function
enc: encryption function
dec: decryption function
injbot: natural injection from cleartext to bitstringbot
Z: function that returns for each cleartext a cleartext of the same length consisting only of zeroes.
Penc(t, N, N', l, l'): probability of breaking the IND-CCA2 property
in time t for one key, N encryption queries, N' decryption queries with
cleartexts of length at most l and ciphertexts of length at most l'.
The types keyseed, key, cleartext, ciphertext, seed and the
probability Penc must be declared before this macro is
expanded. The functions kgen, enc, dec, injbot, and Z are declared
by this macro. They must not be declared elsewhere, and they can be
used only after expanding the macro.
*)
define IND_CCA2_sym_enc(keyseed, key, cleartext, ciphertext, seed, kgen, enc, dec, injbot, Z, Penc) {
param N, N2, N3.
fun enc(cleartext, key, seed): ciphertext.
fun kgen(keyseed):key.
fun dec(ciphertext, key): bitstringbot.
fun enc2(cleartext, key, seed): ciphertext.
fun kgen2(keyseed):key.
fun dec2(ciphertext, key): bitstringbot.
fun injbot(cleartext):bitstringbot [compos].
forall x:cleartext; injbot(x) <> bottom.
(* The function Z returns for each bitstring, a bitstring
of the same length, consisting only of zeroes. *)
fun Z(cleartext):cleartext.
forall m:cleartext, r:keyseed, r2:seed;
dec(enc(m, kgen(r), r2), kgen(r)) = injbot(m).
(* IND-CCA2 *)
equiv ind_cca2(enc)
! N2 new r: keyseed; (! N new r2: seed; Oenc(x:cleartext) := enc(x, kgen(r), r2),
! N3 Odec(y:ciphertext) := dec(y,kgen(r)))
<=(N2 * Penc(time + (N2-1)*(time(kgen) + N*time(enc, maxlength(x)) + N*time(Z, maxlength(x)) + N3*time(dec,maxlength(y))), N, N3, maxlength(x), maxlength(y)))=>
! N2 new r: keyseed; (! N new r2: seed; Oenc(x:cleartext) := let z:ciphertext = enc2(Z(x), kgen2(r), r2) in z,
! N3 Odec(y:ciphertext) := find j <= N suchthat defined(x[j],r2[j],z[j]) && y = z[j] then injbot(x[j]) else dec2(y, kgen2(r))).
}
(* INT-PTXT probabilistic symmetric encryption
keyseed: type of key seeds, must be "bounded" (to be able to generate random numbers from it), typically "fixed" and "large".
key: type of keys, must be "bounded"
cleartext: type of cleartexts
ciphertext: type of ciphertexts
seed: type of random seeds for encryption, must be "bounded", typically "fixed".
kgen: key generation function
enc: encryption function
dec: decryption function
injbot: natural injection from cleartext to bitstringbot
Pencptxt(t, N, N', l, l'): probability of breaking the INT-PTXT property
in time t for one key, N encryption queries, N' decryption queries with
cleartexts of length at most l and ciphertexts of length at most l'.
The types keyseed, key, cleartext, ciphertext, seed and the
probability Pencptxt must be declared before this macro is
expanded. The functions kgen, enc, dec, and injbot are declared
by this macro. They must not be declared elsewhere, and they can be
used only after expanding the macro.
*)
define INT_PTXT_sym_enc(keyseed, key, cleartext, ciphertext, seed, kgen, enc, dec, injbot, Pencptxt) {
param N, N2, N3.
fun enc(cleartext, key, seed): ciphertext.
fun kgen(keyseed):key.
fun dec(ciphertext, key): bitstringbot.
fun dec2(ciphertext, key): bitstringbot.
fun injbot(cleartext):bitstringbot [compos].
forall x:cleartext; injbot(x) <> bottom.
forall m:cleartext, r:keyseed, r2:seed;
dec(enc(m, kgen(r), r2), kgen(r)) = injbot(m).
(* INT-PTXT *)
equiv int_ptxt(enc)
! N2 new r: keyseed; (! N new r2: seed; Oenc(x:cleartext) := enc(x, kgen(r), r2),
! N3 Odec(y:ciphertext) [useful_change] := dec(y,kgen(r)))
<=(N2 * Pencptxt(time + (N2-1)*(time(kgen) + N*time(enc, maxlength(x)) + N3*time(dec,maxlength(y))), N, N3, maxlength(x), maxlength(y)))=> [computational]
! N2 new r: keyseed [unchanged];
(! N new r2: seed [unchanged]; Oenc(x:cleartext) := enc(x, kgen(r), r2),
! N3 Odec(y:ciphertext) :=
let z = dec2(y, kgen(r)) in
find j <= N suchthat defined(x[j]) && z = injbot(x[j]) then injbot(x[j]) else bottom).
}
(* IND-CCA2 and INT-PTXT probabilistic symmetric encryption
keyseed: type of key seeds, must be "bounded" (to be able to generate random numbers from it), typically "fixed" and "large".
key: type of keys, must be "bounded"
cleartext: type of cleartexts
ciphertext: type of ciphertexts
seed: type of random seeds for encryption, must be "bounded", typically "fixed".
kgen: key generation function
enc: encryption function
dec: decryption function
injbot: natural injection from cleartext to bitstringbot
Z: function that returns for each cleartext a cleartext of the same length consisting only of zeroes.
Penc(t, N, N', l, l'): probability of breaking the IND-CCA2 property
in time t for one key, N encryption queries, N' decryption queries with
cleartexts of length at most l and ciphertexts of length at most l'.
Pencptxt(t, N, N', l, l'): probability of breaking the INT-PTXT property
in time t for one key, N encryption queries, N' decryption queries with
cleartexts of length at most l and ciphertexts of length at most l'.
The types keyseed, key, cleartext, ciphertext, seed and the
probabilities Penc, Pencctxt must be declared before this macro is
expanded. The functions kgen, enc, dec, injbot, and Z are declared
by this macro. They must not be declared elsewhere, and they can be
used only after expanding the macro.
CryptoVerif often needs manual guidance with this property,
because it does not know which property (IND-CCA2 or INT-PTXT)
to apply first. Moreover, when empty plaintexts are not allowed,
IND-CCA2 and INT-PTXT is equivalent to IND-CPA and INT-CTXT,
which is much easier to use for CryptoVerif, so we recommend
using the latter property when possible.
*)
define IND_CCA2_INT_PTXT_sym_enc(keyseed, key, cleartext, ciphertext, seed, kgen, enc, dec, injbot, Z, Penc, Pencptxt) {
param N, N2, N3.
fun enc(cleartext, key, seed): ciphertext.
fun kgen(keyseed):key.
fun dec(ciphertext, key): bitstringbot.
fun enc2(cleartext, key, seed): ciphertext.
fun kgen2(keyseed):key.
fun dec2(ciphertext, key): bitstringbot.
fun injbot(cleartext):bitstringbot [compos].
forall x:cleartext; injbot(x) <> bottom.
(* The function Z returns for each bitstring, a bitstring
of the same length, consisting only of zeroes. *)
fun Z(cleartext):cleartext.
forall m:cleartext, r:keyseed, r2:seed;
dec(enc(m, kgen(r), r2), kgen(r)) = injbot(m).
(* IND-CCA2 *)
equiv ind_cca2(enc)
! N2 new r: keyseed; (! N new r2: seed; Oenc(x:cleartext) := enc(x, kgen(r), r2),
! N3 Odec(y:ciphertext) := dec(y,kgen(r)))
<=(N2 * Penc(time + (N2-1)*(time(kgen) + N*time(enc, maxlength(x)) + N*time(Z, maxlength(x)) + N3*time(dec,maxlength(y))), N, N3, maxlength(x), maxlength(y)))=>
! N2 new r: keyseed; (! N new r2: seed; Oenc(x:cleartext) := let z:ciphertext = enc2(Z(x), kgen2(r), r2) in z,
! N3 Odec(y:ciphertext) := find j <= N suchthat defined(x[j],r2[j],z[j]) && y = z[j] then injbot(x[j]) else dec(y, kgen2(r))).
equiv ind_cca2_after_int_ptxt(enc)
! N2 new r: keyseed; (! N new r2: seed; Oenc(x:cleartext) := enc(x, kgen(r), r2),
! N3 Odec(y:ciphertext) := dec2(y,kgen(r)))
<=(N2 * Penc(time + (N2-1)*(time(kgen) + N*time(enc, maxlength(x)) + N*time(Z, maxlength(x)) + N3*time(dec,maxlength(y))), N, N3, maxlength(x), maxlength(y)))=>
! N2 new r: keyseed; (! N new r2: seed; Oenc(x:cleartext) := let z:ciphertext = enc2(Z(x), kgen2(r), r2) in z,
! N3 Odec(y:ciphertext) := find j <= N suchthat defined(x[j],r2[j],z[j]) && y = z[j] then injbot(x[j]) else dec2(y, kgen2(r))).
(* INT-PTXT *)
equiv int_ptxt(enc)
! N2 new r: keyseed; (! N new r2: seed; Oenc(x:cleartext) := enc(x, kgen(r), r2),
! N3 Odec(y:ciphertext) [useful_change] := dec(y,kgen(r)))
<=(N2 * Pencptxt(time + (N2-1)*(time(kgen) + N*time(enc, maxlength(x)) + N3*time(dec,maxlength(y))), N, N3, maxlength(x), maxlength(y)))=> [computational]
! N2 new r: keyseed [unchanged];
(! N new r2: seed [unchanged]; Oenc(x:cleartext) := enc(x, kgen(r), r2),
! N3 Odec(y:ciphertext) :=
let z = dec2(y, kgen(r)) in
find j <= N suchthat defined(x[j]) && z = injbot(x[j]) then injbot(x[j]) else bottom).
equiv int_ptxt_after_ind_cca2(enc)
! N2 new r: keyseed; (! N new r2: seed; Oenc(x:cleartext) := enc2(x, kgen2(r), r2),
! N3 Odec(y:ciphertext) [useful_change] := dec(y,kgen2(r)))
<=(N2 * Pencptxt(time + (N2-1)*(time(kgen) + N*time(enc, maxlength(x)) + N3*time(dec,maxlength(y))), N, N3, maxlength(x), maxlength(y)))=> [computational]
! N2 new r: keyseed [unchanged];
(! N new r2: seed [unchanged]; Oenc(x:cleartext) := enc2(x, kgen2(r), r2),
! N3 Odec(y:ciphertext) :=
let z = dec2(y, kgen2(r)) in
find j <= N suchthat defined(x[j]) && z = injbot(x[j]) then injbot(x[j]) else bottom).
}
(* SPRP block cipher
keyseed: type of key seeds, must be "bounded" (to be able to generate random numbers from it), typically "fixed" and "large".
key: type of keys, must be "bounded"
blocksize: type of the input and output of the cipher, must be "fixed" and "large".
(The modeling of SPRP block ciphers is not perfect in that, in
order to encrypt a new message, one chooses a fresh random number,
not necessarily different from previously generated random
numbers. Then CryptoVerif needs to eliminate collisions between
those random numbers, so blocksize must really be "large".)
kgen: key generation function
enc: encryption function
dec: decryption function
Penc(t, N, N'): probability of breaking the SPRP property
in time t for one key, N encryption queries, and N' decryption queries.
The types keyseed, key, blocksize and the probability Penc must be
declared before this macro is expanded. The functions kgen, enc,
dec are declared by this macro. They must not be declared
elsewhere, and they can be used only after expanding the macro.
*)
define SPRP_cipher(keyseed, key, blocksize, kgen, enc, dec, Penc) {
param N, N2, N3.
fun enc(blocksize, key): blocksize.
fun kgen(keyseed):key.
fun dec(blocksize, key): blocksize.
forall m:blocksize, r:keyseed;
dec(enc(m, kgen(r)), kgen(r)) = m.
equiv sprp(enc)
!N3 new r: keyseed; (!N Oenc(x:blocksize) := enc(x, kgen(r)),
!N2 Odec(m:blocksize) := dec(m, kgen(r)))
<=(N3 * (Penc(time + (N3-1)*(time(kgen) + N*time(enc) + N2*time(dec)), N, N2) + (N+N2)*(N+N2-1)/|blocksize|))=>
!N3 new r: keyseed; (!N Oenc(x:blocksize) :=
find[unique] j<=N suchthat defined(x[j],r2[j]) && x = x[j] then r2[j]
orfind k<=N2 suchthat defined(r4[k],m[k]) && x = r4[k] then m[k]
else new r2: blocksize; r2,
! N2 Odec(m:blocksize) :=
find[unique] j<=N suchthat defined(x[j],r2[j]) && m = r2[j] then x[j]
orfind k<=N2 suchthat defined(r4[k],m[k]) && m = m[k] then r4[k]
else new r4: blocksize; r4).
}
(* PRP block cipher
keyseed: type of key seeds, must be "bounded" (to be able to generate random numbers from it), typically "fixed" and "large".
key: type of keys, must be "bounded"
blocksize: type of the input and output of the cipher, must be "fixed" and "large".
(The modeling of PRP block ciphers is not perfect in that, in order
to encrypt a new message, one chooses a fresh random number, not
necessarily different from previously generated random numbers. In
other words, we model a PRF rather than a PRP, and apply the
PRF/PRP switching lemma to make sure that this is sound. Then
CryptoVerif needs to eliminate collisions between those random
numbers, so blocksize must really be "large".)
kgen: key generation function
enc: encryption function
dec: decryption function
Penc(t, N): probability of breaking the PRP property
in time t for one key and N encryption queries.
The types keyseed, key, blocksize and the probability Penc must be
declared before this macro is expanded. The functions kgen, enc,
dec are declared by this macro. They must not be declared
elsewhere, and they can be used only after expanding the macro.
*)
define PRP_cipher(keyseed, key, blocksize, kgen, enc, dec, Penc) {
param N, N2, N3.
fun enc(blocksize, key): blocksize.
fun kgen(keyseed):key.
fun dec(blocksize, key): blocksize.
forall m:blocksize, r:keyseed;
dec(enc(m, kgen(r)), kgen(r)) = m.
equiv prp(enc)
!N3 new r: keyseed; !N Oenc(x:blocksize) := enc(x, kgen(r))
<=(N3 * (Penc(time + (N3-1)*(time(kgen) + N*time(enc)), N) + N * (N-1) / |blocksize|))=>
!N3 new r: keyseed; !N Oenc(x:blocksize) :=
find[unique] j<=N suchthat defined(x[j],r2[j]) && x = x[j] then r2[j]
else new r2: blocksize; r2.
}
(* Ideal Cipher Model
cipherkey: type of keys that correspond to the choice of the scheme, must be "bounded", typically "fixed".
key: type of keys (typically "large")
blocksize: type of the input and output of the cipher, must be "fixed" and "large".
(The modeling of the ideal cipher model is not perfect in that, in
order to encrypt a new message, one chooses a fresh random number,
not necessarily different from previously generated random
numbers. Then CryptoVerif needs to eliminate collisions between
those random numbers, so blocksize must really be "large".)
enc: encryption function
dec: decryption function
WARNING: the encryption and decryption functions take 2 keys as
input: the key of type cipherkey that corresponds to the choice of
the scheme, and the normal encryption/decryption key. The cipherkey
must be chosen once and for all at the beginning of the game and
the encryption and decryption oracles must be made available to the
adversary, by including a process such as
(! qE in(c1, (x:blocksize, ke:key)); out(c2, enc(ck,x,ke)))
| (! qD in(c3, (m:blocksize, kd:key)); out(c4, dec(ck,m,kd)))
where c1, c2, c3, c4 are channels,
qE the number of requests to the encryption oracle,
qD the number of requests to the decryption oracle,
ck the cipherkey.
The types cipherkey, key, blocksize must be declared before this macro is
expanded. The functions enc, dec are declared by this macro. They
must not be declared elsewhere, and they can be used only after
expanding the macro.
*)
define ICM_cipher(cipherkey, key, blocksize, enc, dec) {
param Ne, Nd, Nck.
fun enc(cipherkey, blocksize, key): blocksize.
fun dec(cipherkey, blocksize, key): blocksize.
forall ck: cipherkey, m:blocksize, k:key;
dec(ck, enc(ck, m, k), k) = m.
equiv icm(enc)
!Nck new ck: cipherkey;
(!Ne Oenc(me:blocksize, ke:key) := enc(ck, me, ke),
!Nd Odec(md:blocksize, kd:key) := dec(ck, md, kd))
<=((#Oenc+#Odec)*(#Oenc+#Odec-1)/|blocksize|)=> [computational]
!Nck (!Ne Oenc(me:blocksize, ke:key) :=
find[unique] j<=Ne suchthat defined(me[j],ke[j],re[j]) && me = me[j] && ke = ke[j] then re[j]
orfind k<=Nd suchthat defined(rd[k],md[k],kd[k]) && me = rd[k] && ke = kd[k] then md[k]
else new re: blocksize; re,
!Nd Odec(md:blocksize, kd:key) :=
find[unique] j<=Ne suchthat defined(me[j],ke[j],re[j]) && md = re[j] && kd = ke[j] then me[j]
orfind k<=Nd suchthat defined(rd[k],md[k],kd[k]) && md = md[k] && kd = kd[k] then rd[k]
else new rd: blocksize; rd).
(* The difference of probability is the probability of collision between two
random numbers in blocksize among the N+N2 chosen random numbers. *)
(*When CryptoVerif will support parametric processes
param qE, qD [noninteractive].
channel c1, c2, c3, c4.
let enc_dec_oracle(ck) = (! qE in(c1, (me:blocksize, ke:key)); out(c2, enc(ck,me,ke)))
| (! qD in(c3, (md:blocksize, kd:key)); out(c4, dec(ck,md,kd))).
*)
}
(*************************************** MACs ***************************************)
(* UF-CMA mac
mkeyseed: type of key seeds, must be "bounded" (to be able to generate random numbers from it), typically "fixed" and "large".
mkey: type of keys, must be "bounded"
macinput: type of inputs of MACs
macres: type of result of MACs
mkgen: key generation function
mac: MAC function
check: verification function
Pmac(t, N, N', l): probability of breaking the UF-CMA property in
time t for one key, N MAC queries, N' verification queries for
messages of length at most l.
The types mkeyseed, mkey, macinput, macres and the probability Pmac
must be declared before this macro is expanded. The functions
mkgen, mac, check are declared by this macro. They must not be
declared elsewhere, and they can be used only after expanding the
macro.
*)
define UF_CMA_mac(mkeyseed, mkey, macinput, macres, mkgen, mac, check, Pmac) {
param N, N2, N3.
const mark: bitstring.
fun mac(macinput, mkey):macres.
fun check(macinput, mkey, macres): bool.
fun mkgen(mkeyseed):mkey.
fun mac2(macinput, mkey):macres.
fun check2(macinput, mkey, macres): bool.
fun mkgen2(mkeyseed):mkey.
forall m:macinput, r:mkeyseed;
check(m, mkgen(r), mac(m, mkgen(r))).
forall m:macinput, r:mkeyseed;
check2(m, mkgen2(r), mac2(m, mkgen2(r))).
equiv uf_cma(mac)
! N3 new r: mkeyseed;(
!N Omac(x: macinput) := mac(x, mkgen(r)),
!N2 Ocheck(m: macinput, ma: macres) := check(m, mkgen(r), ma))
<=(N3 * Pmac(time + (N3-1)*(time(mkgen) + N*time(mac,maxlength(x)) + N2*time(check,maxlength(m),maxlength(ma))), N, N2, max(maxlength(x), maxlength(m))))=> [computational]
! N3 new r: mkeyseed [unchanged];(
!N Omac(x: macinput) := mac2(x, mkgen2(r)),
!N2 Ocheck(m: macinput, ma: macres) :=
find j <= N suchthat defined(x[j]) && (m = x[j]) && check2(x[j], mkgen2(r), ma) then true else false).
equiv uf_cma_corrupt(mac)
! N3 new r: mkeyseed;(
!N Omac(x: macinput) [useful_change] := mac(x, mkgen(r)),
!N2 Ocheck(m: macinput, ma: macres) [useful_change] := check(m, mkgen(r), ma),
Ocorrupt() [10] := r)
<=(N3 * Pmac(time + (N3-1)*(time(mkgen) + N*time(mac,maxlength(x)) + N2*time(check,maxlength(m),maxlength(ma))), N, N2, max(maxlength(x), maxlength(m))))=> [manual,computational]
! N3 new r: mkeyseed [unchanged];(
!N Omac(x: macinput) := mac2(x, mkgen2(r)),
!N2 Ocheck(m: macinput, ma: macres) :=
if defined(corrupt) then check2(m, mkgen2(r), ma) else
find j <= N suchthat defined(x[j]) && (m = x[j]) && check2(x[j], mkgen2(r), ma) then true else false,
Ocorrupt() := let corrupt: bitstring = mark in r).
}
(* SUF-CMA mac (strongly unforgeable MAC)
The difference between a UF-CMA MAC and a SUF-CMA MAC is that, for a UF-CMA MAC, the adversary may
easily forge a new MAC for a message for which he has already seen a MAC. Such a forgery is guaranteed
to be hard for a SUF-CMA MAC.
mkeyseed: type of key seeds, must be "bounded" (to be able to generate random numbers from it), typically "fixed" and "large".
mkey: type of keys, must be "bounded"
macinput: type of inputs of MACs
macres: type of result of MACs
mkgen: key generation function
mac: MAC function
check: verification function
Pmac(t, N, N', l): probability of breaking the SUF-CMA property in
time t for one key, N MAC queries, N' verification queries for
messages of length at most l.
The types mkeyseed, mkey, macinput, macres and the probability Pmac
must be declared before this macro is expanded. The functions
mkgen, mac, check are declared by this macro. They must not be
declared elsewhere, and they can be used only after expanding the
macro.
*)
define SUF_CMA_mac(mkeyseed, mkey, macinput, macres, mkgen, mac, check, Pmac) {
param N, N2, N3.
const mark: bitstring.
fun mac(macinput, mkey):macres.
fun check(macinput, mkey, macres): bool.
fun mkgen(mkeyseed):mkey.
fun mac2(macinput, mkey):macres.
fun mkgen2(mkeyseed):mkey.
forall m:macinput, r:mkeyseed;
check(m, mkgen(r), mac(m, mkgen(r))).
equiv suf_cma(mac)
! N3 new r: mkeyseed;(
!N Omac(x: macinput) := mac(x, mkgen(r)),
!N2 Ocheck(m: macinput, ma: macres) := check(m, mkgen(r), ma))
<=(N3 * Pmac(time + (N3-1)*(time(mkgen) + N*time(mac,maxlength(x)) + N2*time(check,maxlength(m),maxlength(ma))), N, N2, max(maxlength(x), maxlength(m))))=> [computational]
! N3 new r: mkeyseed [unchanged];(
!N Omac(x: macinput) := let ma2:macres = mac2(x, mkgen2(r)) in ma2,
!N2 Ocheck(m: macinput, ma: macres) :=
find j <= N suchthat defined(x[j], ma2[j]) && (m = x[j]) && ma = ma2[j] then true else false).
equiv suf_cma_corrupt(mac)
! N3 new r: mkeyseed;(
!N Omac(x: macinput) [useful_change] := mac(x, mkgen(r)),
!N2 Ocheck(m: macinput, ma: macres) [useful_change] := check(m, mkgen(r), ma),
Ocorrupt() [10] := r)
<=(N3 * Pmac(time + (N3-1)*(time(mkgen) + N*time(mac,maxlength(x)) + N2*time(check,maxlength(m),maxlength(ma))), N, N2, max(maxlength(x), maxlength(m))))=> [manual,computational]
! N3 new r: mkeyseed [unchanged];(
!N Omac(x: macinput) := let ma2:macres = mac2(x, mkgen2(r)) in ma2,
!N2 Ocheck(m: macinput, ma: macres) :=
if defined(corrupt) then check(m, mkgen2(r), ma) else
find j <= N suchthat defined(x[j], ma2[j]) && (m = x[j]) && ma = ma2[j] then true else false,
Ocorrupt() := let corrupt: bitstring = mark in r).
}
(******************************* Public-key encryption *******************************)
(* IND-CCA2 probabilistic public-key encryption
keyseed: type of key seeds, must be "bounded" (to be able to generate random numbers from it), typically "fixed" and "large".
pkey: type of public keys, must be "bounded"
skey: type of secret keys, must be "bounded"
cleartext: type of cleartexts, must be "bounded" or "fixed"
(the encryptions of *all* cleartexts of any length
are assumed to be indistinguishable from each other).
ciphertext: type of ciphertexts
seed: type of random seeds for encryption, must be "bounded", typically "fixed".
pkgen: public-key generation function
skgen: secret-key generation function
enc: encryption function
dec: decryption function
injbot: natural injection from cleartext to bitstringbot
Z: a constant cleartext
Penc(t, N): probability of breaking the IND-CCA2 property
in time t for one key and N decryption queries.
Penccoll: probability of collision between independently generated keys
The types keyseed, pkey, skey, cleartext, ciphertext, seed and the
probabilities Penc, Penccoll must be declared before this macro is
expanded. The functions pkgen, skgen, enc, dec, injbot, and the
constant Z are declared by this macro. They must not be declared
elsewhere, and they can be used only after expanding the macro.
*)
define IND_CCA2_public_key_enc(keyseed, pkey, skey, cleartext, ciphertext, seed, skgen, pkgen, enc, dec, injbot, Z, Penc, Penccoll) {
param N, N2, N3, N4.
fun enc(cleartext, pkey, seed): ciphertext.
fun skgen(keyseed):skey.
fun pkgen(keyseed):pkey.
fun dec(ciphertext, skey): bitstringbot.
fun enc2(cleartext, pkey, seed): ciphertext.
fun skgen2(keyseed):skey.
fun pkgen2(keyseed):pkey.
fun dec2(ciphertext, skey): bitstringbot.
fun injbot(cleartext):bitstringbot [compos].
const Z:cleartext.
forall m:cleartext, r:keyseed, r2:seed;
dec(enc(m, pkgen(r), r2), skgen(r)) = injbot(m).
forall m:cleartext, r:keyseed, r2:seed;
dec2(enc2(m, pkgen2(r), r2), skgen2(r)) = injbot(m).
equiv ind_cca2(enc)
!N3 new r: keyseed; (Opk() [2] := pkgen(r),
!N2 Odec(m:ciphertext) := dec(m, skgen(r)),
!N new r1:seed; Oenc(x1:cleartext) := enc(x1, pkgen(r),r1)),
!N4 new r2:seed; Oenc2(x:cleartext, y:pkey) [3] := enc(x,y,r2) [all]
<=((N3 * N + N4) * Penc(time + (N4+N-1) * time(enc) + (N3-1)*(time(pkgen) + time(skgen) + N2 * time(dec, maxlength(m)) + N * time(enc)), N2))=>
!N3 new r: keyseed; (Opk() := pkgen2(r),
!N2 Odec(m:ciphertext) :=
find j <= N suchthat defined(m1[j],x1[j]) && m = m1[j] then injbot(x1[j]) else
find j <= N4 suchthat defined(m2[j],y[j],x[j]) &&
y[j] = pkgen2(r) && m = m2[j] then injbot(x[j]) else dec2(m, skgen2(r)),
!N new r1:seed; Oenc(x1:cleartext) :=
let m1:ciphertext = enc2(Z, pkgen2(r), r1) in
m1),
!N4 Oenc2(x:cleartext, y:pkey) :=
find k <= N3 suchthat defined(r[k]) && y = pkgen2(r[k]) then
(new r2:seed;
let m2:ciphertext = enc2(Z, y, r2) in
m2)
else new r3:seed; enc(x,y,r3).
collision new r1:keyseed; new r2:keyseed;
pkgen(r1) = pkgen(r2) <=(Penccoll)=> false.
collision new r1:keyseed; new r2:keyseed;
pkgen2(r1) = pkgen2(r2) <=(Penccoll)=> false.
collision new r1:keyseed; new r2:keyseed;
pkgen(r1) = pkgen2(r2) <=(Penccoll)=> false.
collision new r1:keyseed; new r2:keyseed;
skgen(r1) = skgen(r2) <=(Penccoll)=> false.
collision new r1:keyseed; new r2:keyseed;
skgen(r1) = skgen2(r2) <=(Penccoll)=> false.
collision new r1:keyseed; new r2:keyseed;
skgen2(r1) = skgen2(r2) <=(Penccoll)=> false.
}
(*************************************** Signatures ******************************)
(* UF-CMA probabilistic signatures
keyseed: type of key seeds, must be "bounded" (to be able to generate random numbers from it), typically "fixed" and "large".
pkey: type of public keys, must be "bounded"
skey: type of secret keys, must be "bounded"
signinput: type of inputs of signatures
signature: type of signatures
seed: type of random seeds for signatures, must be "bounded", typically "fixed"
pkgen: public-key generation function
skgen: secret-key generation function
sign: signature function
check: verification function
Psign(t, N, l): probability of breaking the UF-CMA property
in time t, for one key, N signature queries with messages of length
at most l.
Psigncoll: probability of collision between independently generated keys
The types keyseed, pkey, skey, signinput, signature, seed and the
probabilities Psign, Psigncoll must be declared before this macro
is expanded. The functions pkgen, skgen, sign, and check are
declared by this macro. They must not be declared elsewhere, and
they can be used only after expanding the macro.
*)
define UF_CMA_signature(keyseed, pkey, skey, signinput, signature, seed, skgen, pkgen, sign, check, Psign, Psigncoll) {
param N, N2, N3, N4.
const mark: bitstring.
fun sign(signinput, skey, seed): signature.
fun skgen(keyseed):skey.
fun pkgen(keyseed):pkey.
fun check(signinput, pkey, signature): bool.
fun sign2(signinput, skey, seed): signature.
fun skgen2(keyseed):skey.
fun pkgen2(keyseed):pkey.
fun check2(signinput, pkey, signature): bool.
forall m:signinput, r:keyseed, r2:seed;
check(m, pkgen(r), sign(m, skgen(r), r2)) = true.
forall m:signinput, r:keyseed, r2:seed;
check2(m, pkgen2(r), sign2(m, skgen2(r), r2)) = true.
equiv uf_cma(sign)
!N3 new r: keyseed; (Opk() [2] := pkgen(r),
!N2 new r2: seed; Osign(x: signinput) := sign(x, skgen(r), r2),
!N Ocheck(m1: signinput, si1:signature) := check(m1, pkgen(r), si1)),
!N4 Ocheck2(m: signinput, y: pkey, si: signature) [3] := check(m, y, si) [all]
<=(N3 * Psign(time + (N4+N-1) * time(check, max(maxlength(m1), maxlength(m)), max(maxlength(si1), maxlength(si))) + (N3-1)*(time(pkgen) + time(skgen) + N2 * time(sign, maxlength(x)) + N * time(check, maxlength(m1), maxlength(si1))), N2, maxlength(x)))=> [computational]
!N3 new r: keyseed [unchanged];
(Opk() := pkgen2(r),
!N2 new r2: seed [unchanged]; Osign(x: signinput) := sign2(x, skgen2(r), r2),
!N Ocheck(m1: signinput, si1:signature) :=
find j <= N2 suchthat defined(x[j]) && m1 = x[j] && check2(m1, pkgen2(r), si1) then true else false),
!N4 Ocheck2(m: signinput, y: pkey, si: signature) :=
find j <= N2, k <= N3 suchthat defined(x[j,k],r[k]) && y = pkgen2(r[k]) && m = x[j,k] && check2(m, y, si) then true else
find k <= N3 suchthat defined(r[k]) && y = pkgen2(r[k]) then false else
check(m,y,si).
equiv uf_cma_corrupt(sign)
!N3 new r: keyseed; (Opk() [useful_change] [2] := pkgen(r),
!N2 new r2: seed; Osign(x: signinput) [useful_change] := sign(x, skgen(r), r2),
!N Ocheck(m1: signinput, si1:signature) [useful_change] := check(m1, pkgen(r), si1),
Ocorrupt() [10] := r),
!N4 Ocheck2(m: signinput, y: pkey, si: signature) [3] := check(m, y, si) [all]
<=(N3 * Psign(time + (N4+N-1) * time(check, max(maxlength(m1), maxlength(m)), max(maxlength(si1), maxlength(si))) + (N3-1)*(time(pkgen) + time(skgen) + N2 * time(sign, maxlength(x)) + N * time(check, maxlength(m1), maxlength(si1))), N2, maxlength(x)))=> [manual,computational]
!N3 new r: keyseed [unchanged];
(Opk() := pkgen2(r),
!N2 new r2: seed [unchanged]; Osign(x: signinput) := sign2(x, skgen2(r), r2),
!N Ocheck(m1: signinput, si1:signature) :=
if defined(corrupt) then check2(m1, pkgen2(r), si1) else
find j <= N2 suchthat defined(x[j]) && m1 = x[j] && check2(m1, pkgen2(r), si1) then true else false,
Ocorrupt() := let corrupt: bitstring = mark in r),
!N4 Ocheck2(m: signinput, y: pkey, si: signature) :=
find k <= N3 suchthat defined(r[k],corrupt[k]) && y = pkgen2(r[k]) then check2(m, y, si) else
find j <= N2, k <= N3 suchthat defined(x[j,k],r[k]) && y = pkgen2(r[k]) && m = x[j,k] && check2(m, y, si) then true else
find k <= N3 suchthat defined(r[k]) && y = pkgen2(r[k]) then false else
check(m,y,si).
collision new r1:keyseed; new r2:keyseed;
pkgen(r1) = pkgen(r2) <=(Psigncoll)=> false.
collision new r1:keyseed; new r2:keyseed;
pkgen(r1) = pkgen2(r2) <=(Psigncoll)=> false.
collision new r1:keyseed; new r2:keyseed;
pkgen2(r1) = pkgen2(r2) <=(Psigncoll)=> false.
collision new r1:keyseed; new r2:keyseed;
skgen(r1) = skgen(r2) <=(Psigncoll)=> false.
collision new r1:keyseed; new r2:keyseed;
skgen(r1) = skgen2(r2) <=(Psigncoll)=> false.
collision new r1:keyseed; new r2:keyseed;
skgen2(r1) = skgen2(r2) <=(Psigncoll)=> false.
}
(* SUF-CMA probabilistic signatures
keyseed: type of key seeds, must be "bounded" (to be able to generate random numbers from it), typically "fixed" and "large".
pkey: type of public keys, must be "bounded"
skey: type of secret keys, must be "bounded"
signinput: type of inputs of signatures
signature: type of signatures
seed: type of random seeds for signatures, must be "bounded", typically "fixed"
pkgen: public-key generation function
skgen: secret-key generation function
sign: signature function
check: verification function
Psign(t, N, l): probability of breaking the SUF-CMA property
in time t, for one key, N signature queries with messages of length
at most l.
Psigncoll: probability of collision between independently generated keys
The types keyseed, pkey, skey, signinput, signature, seed and the
probabilities Psign, Psigncoll must be declared before this macro
is expanded. The functions pkgen, skgen, sign, and check are
declared by this macro. They must not be declared elsewhere, and
they can be used only after expanding the macro.
*)
define SUF_CMA_signature(keyseed, pkey, skey, signinput, signature, seed, skgen, pkgen, sign, check, Psign, Psigncoll) {
param N, N2, N3, N4.
const mark: bitstring.
fun sign(signinput, skey, seed): signature.
fun skgen(keyseed):skey.
fun pkgen(keyseed):pkey.
fun check(signinput, pkey, signature): bool.
fun sign2(signinput, skey, seed): signature.
fun skgen2(keyseed):skey.
fun pkgen2(keyseed):pkey.
fun check2(signinput, pkey, signature): bool.
forall m:signinput, r:keyseed, r2:seed;
check(m, pkgen(r), sign(m, skgen(r), r2)) = true.
forall m:signinput, r:keyseed, r2:seed;
check2(m, pkgen2(r), sign2(m, skgen2(r), r2)) = true.
equiv suf_cma(sign)
!N3 new r: keyseed; (Opk() [2] := pkgen(r),
!N2 new r2: seed; Osign(x: signinput) := sign(x, skgen(r), r2),
!N Ocheck(m1: signinput, si1:signature) := check(m1, pkgen(r), si1)),
!N4 Ocheck2(m: signinput, y: pkey, si: signature) [3] := check(m, y, si) [all]
<=(N3 * Psign(time + (N4+N-1) * time(check, max(maxlength(m), maxlength(m1)), max(maxlength(si), maxlength(si1))) + (N3-1)*(time(pkgen) + time(skgen) + N2 * time(sign, maxlength(x)) + N * time(check, maxlength(m1), maxlength(si1))), N2, maxlength(x)))=> [computational]
!N3 new r: keyseed [unchanged];
(Opk() := pkgen2(r),
!N2 new r2: seed [unchanged]; Osign(x: signinput) := let s:signature = sign2(x, skgen2(r), r2) in s,
!N Ocheck(m1: signinput, si1:signature) :=
find j <= N2 suchthat defined(x[j],s[j]) && m1 = x[j] && si1 = s[j] then true else false),
!N4 Ocheck2(m: signinput, y: pkey, si: signature) :=
find j <= N2, k <= N3 suchthat defined(x[j,k],r[k],s[j,k]) && y = pkgen2(r[k]) && m = x[j,k] && si = s[j,k] then true else
find k <= N3 suchthat defined(r[k]) && y = pkgen2(r[k]) then false else
check(m,y,si).
equiv suf_cma_corrupt(sign)
!N3 new r: keyseed; (Opk() [useful_change] [2] := pkgen(r),
!N2 new r2: seed; Osign(x: signinput) [useful_change] := sign(x, skgen(r), r2),
!N Ocheck(m1: signinput, si1:signature) [useful_change] := check(m1, pkgen(r), si1),
Ocorrupt() [10] := r),
!N4 Ocheck2(m: signinput, y: pkey, si: signature) [3] := check(m, y, si) [all]
<=(N3 * Psign(time + (N4+N-1) * time(check, max(maxlength(m), maxlength(m1)), max(maxlength(si), maxlength(si1))) + (N3-1)*(time(pkgen) + time(skgen) + N2 * time(sign, maxlength(x)) + N * time(check, maxlength(m1), maxlength(si1))), N2, maxlength(x)))=> [manual,computational]
!N3 new r: keyseed [unchanged];
(Opk() := pkgen2(r),
!N2 new r2: seed [unchanged]; Osign(x: signinput) := let s:signature = sign2(x, skgen2(r), r2) in s,
!N Ocheck(m1: signinput, si1:signature) :=
if defined(corrupt) then check2(m1, pkgen2(r), si1) else
find j <= N2 suchthat defined(x[j],s[j]) && m1 = x[j] && si1 = s[j] then true else false,
Ocorrupt() := let corrupt: bitstring = mark in r),
!N4 Ocheck2(m: signinput, y: pkey, si: signature) :=
find k <= N3 suchthat defined(r[k],corrupt[k]) && y = pkgen2(r[k]) then check2(m, y, si) else
find j <= N2, k <= N3 suchthat defined(x[j,k],r[k],s[j,k]) && y = pkgen2(r[k]) && m = x[j,k] && si = s[j,k] then true else
find k <= N3 suchthat defined(r[k]) && y = pkgen2(r[k]) then false else
check(m,y,si).
collision new r1:keyseed; new r2:keyseed;
pkgen(r1) = pkgen(r2) <=(Psigncoll)=> false.
collision new r1:keyseed; new r2:keyseed;
pkgen(r1) = pkgen2(r2) <=(Psigncoll)=> false.
collision new r1:keyseed; new r2:keyseed;
pkgen2(r1) = pkgen2(r2) <=(Psigncoll)=> false.
collision new r1:keyseed; new r2:keyseed;
skgen(r1) = skgen(r2) <=(Psigncoll)=> false.
collision new r1:keyseed; new r2:keyseed;
skgen(r1) = skgen2(r2) <=(Psigncoll)=> false.
collision new r1:keyseed; new r2:keyseed;
skgen2(r1) = skgen2(r2) <=(Psigncoll)=> false.
}
(******************************* Hash functions ****************************)
(* Hash function in the random oracle model
key: type of the key of the hash function, which models the choice of the hash function, must be "bounded", typically "fixed"
hashinput: type of the input of the hash function
hashoutput: type of the output of the hash function, must be "bounded" and "large", typically "fixed".
hash: the hash function.
WARNING: hash is a keyed hash function.
The key must be generated once and for all at the beginning of the game
and the hash oracle must be made available to the adversary,
by including a process such as
! qH in(c1, x:hashinput); out(c2, hash(k,x))
where k is the key, qH the number of requests to the hash oracle,
c1 and c2 channels.
The types key, hashinput, and hashoutput must be declared before
this macro. The function hash is defined by this macro. It not
must be declared elsewhere, and it can be used only after expanding
the macro.
*)
define ROM_hash(key, hashinput, hashoutput, hash (*, hashoracle, qH*)) {
param Nh, N, Neq.
fun hash(key, hashinput):hashoutput.
equiv rom(hash)
!Nh new k:key;
(!N Ohash(x:hashinput) := hash(k,x),
!Neq Oeq(x':hashinput, r':hashoutput) := r' = hash(k,x'))
<=(#Oeq / |hashoutput|)=> [computational]
!Nh (!N Ohash(x:hashinput) :=
find[unique] j <= N suchthat defined(x[j],r[j]) && x = x[j] then r[j] else
new r:hashoutput; r,
!Neq Oeq(x':hashinput, r':hashoutput) :=
find[unique] j <= N suchthat defined(x[j],r[j]) && x' = x[j] then r' = r[j] else
false).
(* When CryptoVerif will support parametric processes
param qH [noninteractive].
channel c1, c2.
let hashoracle(k) = ! qH in(c1, x:hashinput); out(c2, hash(k,x)).
*)
}
(* ROM_hash_pair, ROM_hash_triple, and ROM_hash_quad are similar
to ROM_hash, for random oracle with 2, 3, and 4 arguments
respectively. Letting N be the number of arguments of the oracle,
hashinput1...hashinputN are the types of the inputs of the hash function
and the hash oracle that must be provided to the adversary is
! qH in(c1, (x1:hashinput1,...,xN:hashinputN)); out(c2, hash(k,x1,...,xN))
*)
define ROM_hash_pair(key, hashinput1, hashinput2, hashoutput, hash) {
param Nh, N, Neq.