-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlib.ocvl
9228 lines (7094 loc) · 430 KB
/
lib.ocvl
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
(*************************************************************
* *
* Cryptographic protocol verifier *
* *
* Bruno Blanchet and David Cadé *
* *
* Copyright (C) ENS, CNRS, INRIA, 2005-2022 *
* *
*************************************************************)
(*
Copyright ENS, CNRS, INRIA
contributors: Bruno Blanchet, [email protected]
David Cadé
This software is a computer program whose purpose is to verify
cryptographic protocols in the computational model.
This software is governed by the CeCILL-B license under French law and
abiding by the rules of distribution of free software. You can use,
modify and/ or redistribute the software under the terms of the CeCILL-B
license as circulated by CEA, CNRS and INRIA at the following URL
"http://www.cecill.info".
As a counterpart to the access to the source code and rights to copy,
modify and redistribute granted by the license, users are provided only
with a limited warranty and the software's author, the holder of the
economic rights, and the successive licensors have only limited
liability.
In this respect, the user's attention is drawn to the risks associated
with loading, using, modifying and/or developing or reproducing the
software by the user in light of its specific status of free software,
that may mean that it is complicated to manipulate, and that also
therefore means that it is reserved for developers and experienced
professionals having in-depth computer knowledge. Users are therefore
encouraged to load and test the software's suitability as regards their
requirements in conditions enabling the security of their systems and/or
data to be ensured and, more generally, to use and operate it in the
same conditions as regards security.
The fact that you are presently reading this means that you have had
knowledge of the CeCILL-B license and that you accept its terms.
*)
equation forall x:bool; not(not(x)) = x.
equation forall x:bool,y:bool; (not(x && y)) = (not(x) || not(y)).
equation forall x:bool,y:bool; (not(x || y)) = (not(x) && not(y)).
equation not(true) = false.
equation not(false) = true.
equation forall x:bool; (x = true) = x.
equation forall x:bool; (x <> false) = x.
equation forall x:bool; (x <> true) = not(x).
equation forall x:bool; (x = false) = not(x).
equation forall x,y,z:bool; ((x || y) && z) = ((x && z) || (y && z)).
const bottom:bitstringbot.
(******************************** Key generation ************************************************)
(* The symmetric primitives no longer include a key generation function.
If you want to add one, you can use the following macro
keyseed: type of key seeds, must be "bounded" or "nonuniform" (to be able to generate random numbers from it), typically "fixed" and "large".
key: type of keys, must be "bounded" or "nonuniform"
kgen: key generation function
The types keyseed and key must be declared before this macro is
expanded. The function kgen is declared by this macro. It must
not be declared elsewhere, and it can be used only after
expanding the macro. *)
def keygen(keyseed, key, kgen) {
fun kgen(keyseed): key.
equiv(keygen(kgen))
r <-R keyseed; Okey() := return(kgen(r))
<=(0)=>
k <-R key; Okey() := return(k).
}
(***************************** Symmetric encryption *********************************************)
(* IND-CPA probabilistic symmetric encryption
key: type of keys, must be "bounded" (to be able to generate random numbers from it, and to talk about the runtime of enc_r without mentioning the length of the key), typically "fixed" and "large".
cleartext: type of cleartexts
ciphertext: type of ciphertexts
enc_seed: type of random coins for encryption (must be "bounded"; omitted in the second version of the macro).
enc: encryption function that generates coins internally
enc_r: encryption function that takes coins as argument (omitted in the second version of the macro).
enc_r': symbol that replaces enc_r after game transformation
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 key, cleartext, ciphertext, enc_seed and the
probability Penc must be declared before this macro is
expanded. The functions enc, enc_r, enc_r', 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.
*)
def IND_CPA_sym_enc_all_args(key, cleartext, ciphertext, enc_seed, enc, enc_r, enc_r', dec, injbot, Z, Penc) {
param N.
fun enc_r(cleartext, key, enc_seed): ciphertext.
fun dec(ciphertext, key): bitstringbot.
fun enc_r'(cleartext, key, enc_seed): ciphertext.
fun injbot(cleartext):bitstringbot [data].
(* The function Z returns for each bitstring, a bitstring
of the same length, consisting only of zeroes. *)
fun Z(cleartext):cleartext.
(* The encryption function is probabilistic *)
letfun enc(m: cleartext, k: key) =
r <-R enc_seed; enc_r(m, k, r).
equation forall x:cleartext; injbot(x) <> bottom.
equation forall m:cleartext, k:key, r:enc_seed;
dec(enc_r(m, k, r), k) = injbot(m).
equiv(ind_cpa(enc))
k <-R key;
foreach i <= N do r <-R enc_seed; Oenc(x:cleartext) :=
return(enc_r(x, k, r))
<=(Penc(time, N, maxlength(x)))=>
k <-R key;
foreach i <= N do r <-R enc_seed; Oenc(x:cleartext) :=
return(enc_r'(Z(x), k, r)).
}
def IND_CPA_sym_enc(key, cleartext, ciphertext, enc, dec, injbot, Z, Penc) {
type enc_seed [bounded].
expand IND_CPA_sym_enc_all_args(key, cleartext, ciphertext, enc_seed, enc, enc_r, enc_r', dec, injbot, Z, Penc).
}
(* IND-CPA encryption with a nonce.
This is similar to the IND_CPA_sym_enc macro, but it uses a nonce
(which must have a different value in each call to encryption)
instead of random coins generated by encryption.
key: type of keys, must be "bounded" (to be able to generate random numbers from it, and to talk about the runtime of enc without mentioning the length of the key), typically "fixed" and "large".
cleartext: type of cleartexts
ciphertext: type of ciphertexts
nonce: type of the nonce
enc: encryption function
enc': symbol that replaces enc after game transformation
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 key, cleartext, ciphertext, nonce and the
probability Penc must be declared before this macro is
expanded. The functions enc, 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.
*)
def IND_CPA_sym_enc_nonce_all_args(key, cleartext, ciphertext, nonce, enc, enc', dec, injbot, Z, Penc) {
param N, N2, N3.
fun enc(cleartext, key, nonce): ciphertext.
fun dec(ciphertext, key, nonce): bitstringbot.
fun enc'(cleartext, key, nonce): ciphertext.
fun injbot(cleartext):bitstringbot [data].
equation 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.
equation forall m:cleartext, k:key, n: nonce;
dec(enc(m, k, n), k, n) = injbot(m).
(* Event raised when some nonce is used several times
with the same key, which breaks security. *)
event repeated_nonce.
(* IND-CPA *)
equiv(ind_cpa(enc))
k <-R key;
foreach i <= N do Oenc(x:cleartext, n: nonce) :=
return(enc(x, k, n))
<=(Penc(time, N, maxlength(x)))=>
k <-R key;
foreach i <= N do Oenc(x:cleartext, n: nonce) :=
find u <= N suchthat defined(x[u],n[u],r[u]) && n = n[u] && x <> x[u] then
event_abort repeated_nonce
else
let r: ciphertext = enc'(Z(x), k, n) in
return(r).
}
def IND_CPA_sym_enc_nonce(key, cleartext, ciphertext, nonce, enc, dec, injbot, Z, Penc) {
expand IND_CPA_sym_enc_nonce_all_args(key, cleartext, ciphertext, nonce, enc, enc', dec, injbot, Z, Penc).
}
(* IND-CPA and INT-CTXT probabilistic symmetric encryption
key: type of keys, must be "bounded" (to be able to generate random numbers from it, and to talk about the runtime of enc_r without mentioning the length of the key), typically "fixed" and "large".
cleartext: type of cleartexts
ciphertext: type of ciphertexts
enc_seed: type of random coins for encryption (must be "bounded"; omitted in the second version of the macro).
enc: encryption function that generates coins internally
enc_r: encryption function that takes coins as argument (omitted in the second version of the macro).
enc_r': symbol that replaces enc_r after game transformation
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 key, cleartext, ciphertext, enc_seed and the
probabilities Penc, Pencctxt must be declared before this macro is
expanded. The functions enc, enc_r, enc_r', 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.
*)
def IND_CPA_INT_CTXT_sym_enc_all_args(key, cleartext, ciphertext, enc_seed, enc, enc_r, enc_r', dec, injbot, Z, Penc, Pencctxt) {
param N, N2, N3.
fun enc_r(cleartext, key, enc_seed): ciphertext.
fun dec(ciphertext, key): bitstringbot.
fun enc_r'(cleartext, key, enc_seed): ciphertext.
fun injbot(cleartext):bitstringbot [data].
equation 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.
(* The encryption function is probabilistic *)
letfun enc(m: cleartext, k: key) =
r <-R enc_seed; enc_r(m, k, r).
equation forall m:cleartext, k:key, r:enc_seed;
dec(enc_r(m, k, r), k) = injbot(m).
(* IND-CPA *)
equiv(ind_cpa(enc))
k <-R key;
foreach i <= N do r <-R enc_seed; Oenc(x:cleartext) :=
return(enc_r(x, k, r))
<=(Penc(time, N, maxlength(x)))=>
k <-R key;
foreach i <= N do r <-R enc_seed; Oenc(x:cleartext) :=
return(enc_r'(Z(x), k, r)).
(* INT-CTXT *)
equiv(int_ctxt(enc))
k <-R key; (
foreach i <= N do r <-R enc_seed; Oenc(x:cleartext) := return(enc_r(x, k, r)) |
foreach i3 <= N3 do Odec(y:ciphertext) [useful_change] := return(dec(y,k)))
<=(Pencctxt(time, N, N3, maxlength(x), maxlength(y)))=> [computational]
k <-R key [unchanged]; (
foreach i <= N do r <-R enc_seed [unchanged]; Oenc(x:cleartext) := z:ciphertext <- enc_r(x, k, r); return(z) |
foreach i3 <= N3 do Odec(y:ciphertext) := find j <= N suchthat defined(x[j],z[j]) && z[j] = y then return(injbot(x[j])) else return(bottom)).
equiv(int_ctxt_corrupt(enc))
k <-R key; (
foreach i <= N do r <-R enc_seed; Oenc(x:cleartext) := return(enc_r(x, k, r)) |
foreach i3 <= N3 do Odec(y:ciphertext) [useful_change] := return(dec(y,k)) |
Ocorrupt() [10] := return(k))
<=(Pencctxt(time, N, N3, maxlength(x), maxlength(y)))=> [manual,computational]
k <-R key [unchanged]; (
foreach i <= N do r <-R enc_seed [unchanged]; Oenc(x:cleartext) := z:ciphertext <- enc_r(x, k, r); return(z) |
foreach i3 <= N3 do Odec(y:ciphertext) :=
if defined(corrupt) then return(dec(y,k)) else
find j <= N suchthat defined(x[j],z[j]) && z[j] = y then return(injbot(x[j])) else return(bottom) |
Ocorrupt() := let corrupt: bool = true in return(k)).
}
def IND_CPA_INT_CTXT_sym_enc(key, cleartext, ciphertext, enc, dec, injbot, Z, Penc, Pencctxt) {
type enc_seed [bounded].
expand IND_CPA_INT_CTXT_sym_enc_all_args(key, cleartext, ciphertext, enc_seed, enc, enc_r, enc_r', dec, injbot, Z, Penc, Pencctxt).
}
(* Authenticated encryption with a nonce.
This is similar to the IND_CPA_INT_CTXT_sym_enc macro, but it uses a nonce
(which must have a different value in each call to encryption)
instead of random coins generated by encryption.
key: type of keys, must be "bounded" (to be able to generate random numbers from it, and to talk about the runtime of enc without mentioning the length of the key), typically "fixed" and "large".
cleartext: type of cleartexts
ciphertext: type of ciphertexts
nonce: type of the nonce
enc: encryption function
enc': symbol that replaces enc after game transformation
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 key, cleartext, ciphertext, nonce and the
probabilities Penc, Pencctxt must be declared before this macro is
expanded. The functions enc, 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.
*)
def IND_CPA_INT_CTXT_sym_enc_nonce_all_args(key, cleartext, ciphertext, nonce, enc, enc', dec, injbot, Z, Penc, Pencctxt) {
param N, N2, N3.
fun enc(cleartext, key, nonce): ciphertext.
fun dec(ciphertext, key, nonce): bitstringbot.
fun enc'(cleartext, key, nonce): ciphertext.
fun injbot(cleartext):bitstringbot [data].
equation 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.
equation forall m:cleartext, k:key, n: nonce;
dec(enc(m, k, n), k, n) = injbot(m).
(* Event raised when some nonce is used several times
with the same key, which breaks security. *)
event repeated_nonce.
(* IND-CPA *)
equiv(ind_cpa(enc))
k <-R key;
foreach i <= N do Oenc(x:cleartext, n: nonce) :=
return(enc(x, k, n))
<=(Penc(time, N, maxlength(x)))=>
k <-R key;
foreach i <= N do Oenc(x:cleartext, n: nonce) :=
find u <= N suchthat defined(x[u],n[u],r[u]) && n = n[u] && x <> x[u] then
event_abort repeated_nonce
else
let r: ciphertext = enc'(Z(x), k, n) in
return(r).
(* INT-CTXT *)
equiv(int_ctxt(enc))
k <-R key; (
foreach i <= N do Oenc(x:cleartext, n: nonce) :=
return(enc(x, k, n)) |
foreach i3 <= N3 do Odec(y:ciphertext, c_n: nonce) [useful_change] :=
return(dec(y,k,c_n)))
<=(Pencctxt(time, N, N3, maxlength(x), maxlength(y)))=> [computational]
k <-R key [unchanged]; (
foreach i <= N do Oenc(x:cleartext, n: nonce) :=
find u <= N suchthat defined(x[u],n[u],r[u]) && n = n[u] && x <> x[u] then
event_abort repeated_nonce
else
let r: ciphertext = enc(x, k, n) in
return(r) |
foreach i3 <= N3 do Odec(y:ciphertext, c_n: nonce) :=
find j <= N suchthat defined(x[j],n[j],r[j]) &&
r[j] = y && n[j] = c_n then
return(injbot(x[j]))
else
return(bottom)).
equiv(int_ctxt_corrupt(enc))
k <-R key; (
foreach i <= N do Oenc(x:cleartext, n: nonce) :=
return(enc(x, k, n)) |
foreach i3 <= N3 do Odec(y:ciphertext, c_n: nonce) [useful_change] :=
return(dec(y, k,c_n)) |
Ocorrupt() [10] := return(k))
<=(Pencctxt(time, N, N3, maxlength(x), maxlength(y)))=> [manual,computational]
k <-R key [unchanged]; (
foreach i <= N do Oenc(x:cleartext, n: nonce) :=
find u <= N suchthat defined(x[u],n[u],r[u]) && n = n[u] && x <> x[u] then
event_abort repeated_nonce
else
let r: ciphertext = enc(x, k, n) in
return(r) |
foreach i3 <= N3 do Odec(y:ciphertext, c_n: nonce) :=
if defined(corrupt) then return(dec(y,k,c_n)) else
find j <= N suchthat defined(x[j],n[j],r[j]) &&
r[j] = y && n[j] = c_n then
return(injbot(x[j]))
else
return(bottom) |
Ocorrupt() := let corrupt: bool = true in return(k)).
}
def IND_CPA_INT_CTXT_sym_enc_nonce(key, cleartext, ciphertext, nonce, enc, dec, injbot, Z, Penc, Pencctxt) {
expand IND_CPA_INT_CTXT_sym_enc_nonce_all_args(key, cleartext, ciphertext, nonce, enc, enc', dec, injbot, Z, Penc, Pencctxt).
}
(* AEAD (authenticated encryption with additional data)
This is similar to IND-CPA and INT-CTXT authenticated encryption,
except that some additional data is just authenticated.
key: type of keys, must be "bounded" (to be able to generate random numbers from it, and to talk about the runtime of enc_r without mentioning the length of the key), typically "fixed" and "large".
cleartext: type of cleartexts
ciphertext: type of ciphertexts
add_data: type of additional data that is just authenticated
enc_seed: type of random coins for encryption (must be "bounded"; omitted in the second version of the macro).
enc: encryption function that generates coins internally
enc_r: encryption function that takes coins as argument (omitted in the second version of the macro).
enc_r': symbol that replaces enc_r after game transformation
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', ld, ld'): 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',
additional data for encryption of length at most ld, and
additional data for decryption of length at most ld'.
The types key, cleartext, ciphertext, add_data, enc_seed and the
probabilities Penc, Pencctxt must be declared before this macro is
expanded. The functions enc, enc_r, enc_r', 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.
*)
def AEAD_all_args(key, cleartext, ciphertext, add_data, enc_seed, enc, enc_r, enc_r', dec, injbot, Z, Penc, Pencctxt) {
param N, N2, N3.
fun enc_r(cleartext, add_data, key, enc_seed): ciphertext.
fun dec(ciphertext, add_data, key): bitstringbot.
fun enc_r'(cleartext, add_data, key, enc_seed): ciphertext.
fun injbot(cleartext):bitstringbot [data].
equation 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.
(* The encryption function is probabilistic *)
letfun enc(m: cleartext, d: add_data, k: key) =
r <-R enc_seed; enc_r(m, d, k, r).
equation forall m:cleartext, d: add_data, k:key, r:enc_seed;
dec(enc_r(m, d, k, r), d, k) = injbot(m).
(* IND-CPA *)
equiv(ind_cpa(enc))
k <-R key;
foreach i <= N do r <-R enc_seed; Oenc(x:cleartext, d: add_data) :=
return(enc_r(x, d, k, r))
<=(Penc(time, N, maxlength(x)))=>
k <-R key;
foreach i <= N do r <-R enc_seed; Oenc(x:cleartext, d: add_data) :=
return(enc_r'(Z(x), d, k, r)).
(* INT-CTXT *)
equiv(int_ctxt(enc))
k <-R key; (
foreach i <= N do r <-R enc_seed; Oenc(x:cleartext, d: add_data) := return(enc_r(x, d, k, r)) |
foreach i3 <= N3 do Odec(y:ciphertext, c_d: add_data) [useful_change] := return(dec(y,c_d,k)))
<=(Pencctxt(time, N, N3, maxlength(x), maxlength(y), maxlength(d), maxlength(c_d)))=> [computational]
k <-R key [unchanged]; (
foreach i <= N do r <-R enc_seed [unchanged]; Oenc(x:cleartext, d: add_data) := z:ciphertext <- enc_r(x, d, k, r); return(z) |
foreach i3 <= N3 do Odec(y:ciphertext, c_d: add_data) := find j <= N suchthat defined(x[j],d[j],z[j]) && z[j] = y && d[j] = c_d then return(injbot(x[j])) else return(bottom)).
equiv(int_ctxt_corrupt(enc))
k <-R key; (
foreach i <= N do r <-R enc_seed; Oenc(x:cleartext, d: add_data) := return(enc_r(x, d, k, r)) |
foreach i3 <= N3 do Odec(y:ciphertext, c_d: add_data) [useful_change] := return(dec(y,c_d,k)) |
Ocorrupt() [10] := return(k))
<=(Pencctxt(time, N, N3, maxlength(x), maxlength(y), maxlength(d), maxlength(c_d)))=> [manual,computational]
k <-R key [unchanged]; (
foreach i <= N do r <-R enc_seed [unchanged]; Oenc(x:cleartext, d: add_data) := z:ciphertext <- enc_r(x, d, k, r); return(z) |
foreach i3 <= N3 do Odec(y:ciphertext, c_d: add_data) :=
if defined(corrupt) then return(dec(y,c_d,k)) else
find j <= N suchthat defined(x[j],d[j],z[j]) && z[j] = y && d[j] = c_d then return(injbot(x[j])) else return(bottom) |
Ocorrupt() := let corrupt: bool = true in return(k)).
}
def AEAD(key, cleartext, ciphertext, add_data, enc, dec, injbot, Z, Penc, Pencctxt) {
type enc_seed [bounded].
expand AEAD_all_args(key, cleartext, ciphertext, add_data, enc_seed, enc, enc_r, enc_r', dec, injbot, Z, Penc, Pencctxt).
}
(* AEAD (authenticated encryption with additional data) with a nonce.
This is similar to the AEAD macro, but it uses a nonce
(which must have a different value in each call to encryption)
instead of random coins generated by encryption.
A typical example is AES-GCM.
key: type of keys, must be "bounded" (to be able to generate random numbers from it, and to talk about the runtime of enc without mentioning the length of the key), typically "fixed" and "large".
cleartext: type of cleartexts
ciphertext: type of ciphertexts
add_data: type of additional data that is just authenticated
nonce: type of the nonce
enc: encryption function
enc': symbol that replaces enc after game transformation
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', ld, ld'): 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',
additional data for encryption of length at most ld, and
additional data for decryption of length at most ld'.
The types key, cleartext, ciphertext, add_data, nonce and the
probabilities Penc, Pencctxt must be declared before this macro is
expanded. The functions enc, 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.
*)
def AEAD_nonce_all_args(key, cleartext, ciphertext, add_data, nonce, enc, enc', dec, injbot, Z, Penc, Pencctxt) {
param N, N2, N3.
fun enc(cleartext, add_data, key, nonce): ciphertext.
fun dec(ciphertext, add_data, key, nonce): bitstringbot.
fun enc'(cleartext, add_data, key, nonce): ciphertext.
fun injbot(cleartext):bitstringbot [data].
equation 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.
equation forall m:cleartext, d: add_data, k:key, n: nonce;
dec(enc(m, d, k, n), d, k, n) = injbot(m).
(* Event raised when some nonce is used several times
with the same key, which breaks security. *)
event repeated_nonce.
(* IND-CPA *)
equiv(ind_cpa(enc))
k <-R key;
foreach i <= N do Oenc(x:cleartext, d: add_data, n: nonce) :=
return(enc(x, d, k, n))
<=(Penc(time, N, maxlength(x)))=>
k <-R key;
foreach i <= N do Oenc(x:cleartext, d: add_data, n: nonce) :=
find u <= N suchthat defined(x[u],d[u],n[u],r[u]) && n = n[u] && (x <> x[u] || d <> d[u]) then
event_abort repeated_nonce
else
let r: ciphertext = enc'(Z(x), d, k, n) in
return(r).
(* INT-CTXT *)
equiv(int_ctxt(enc))
k <-R key; (
foreach i <= N do Oenc(x:cleartext, d: add_data, n: nonce) :=
return(enc(x, d, k, n)) |
foreach i3 <= N3 do Odec(y:ciphertext, c_d: add_data, c_n: nonce) [useful_change] :=
return(dec(y,c_d,k,c_n)))
<=(Pencctxt(time, N, N3, maxlength(x), maxlength(y), maxlength(d), maxlength(c_d)))=> [computational]
k <-R key [unchanged]; (
foreach i <= N do Oenc(x:cleartext, d: add_data, n: nonce) :=
find u <= N suchthat defined(x[u],d[u],n[u],r[u]) && n = n[u] && (x <> x[u] || d <> d[u]) then
event_abort repeated_nonce
else
let r: ciphertext = enc(x, d, k, n) in
return(r) |
foreach i3 <= N3 do Odec(y:ciphertext, c_d: add_data, c_n: nonce) :=
find j <= N suchthat defined(x[j],d[j],n[j],r[j]) &&
r[j] = y && d[j] = c_d && n[j] = c_n then
return(injbot(x[j]))
else
return(bottom)).
equiv(int_ctxt_corrupt(enc))
k <-R key; (
foreach i <= N do Oenc(x:cleartext, d: add_data, n: nonce) :=
return(enc(x, d, k, n)) |
foreach i3 <= N3 do Odec(y:ciphertext, c_d: add_data, c_n: nonce) [useful_change] :=
return(dec(y,c_d,k,c_n)) |
Ocorrupt() [10] := return(k))
<=(Pencctxt(time, N, N3, maxlength(x), maxlength(y), maxlength(d), maxlength(c_d)))=> [manual,computational]
k <-R key [unchanged]; (
foreach i <= N do Oenc(x:cleartext, d: add_data, n: nonce) :=
find u <= N suchthat defined(x[u],d[u],n[u],r[u]) && n = n[u] && (x <> x[u] || d <> d[u]) then
event_abort repeated_nonce
else
let r: ciphertext = enc(x, d, k, n) in
return(r) |
foreach i3 <= N3 do Odec(y:ciphertext, c_d: add_data, c_n: nonce) :=
if defined(corrupt) then return(dec(y,c_d,k,c_n)) else
find j <= N suchthat defined(x[j],d[j],n[j],r[j]) &&
r[j] = y && d[j] = c_d && n[j] = c_n then
return(injbot(x[j]))
else
return(bottom) |
Ocorrupt() := let corrupt: bool = true in return(k)).
}
def AEAD_nonce(key, cleartext, ciphertext, add_data, nonce, enc, dec, injbot, Z, Penc, Pencctxt) {
expand AEAD_nonce_all_args(key, cleartext, ciphertext, add_data, nonce, enc, enc', dec, injbot, Z, Penc, Pencctxt).
}
(* IND$-CPA probabilistic symmetric encryption
key: type of keys, must be "bounded" (to be able to generate random numbers from it, and to talk about the runtime of enc_r without mentioning the length of the key), typically "fixed" and "large".
cleartext: type of cleartexts
ciphertext: type of ciphertexts
enc_seed: type of random coins for encryption (must be "bounded"; omitted in the second version of the macro).
cipher_stream: type of unbounded streams (must be "nonuniform")
enc: encryption function that generates coins internally
enc_r: encryption function that takes coins as argument (omitted in the second version of the macro).
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.
enc_len: function that returns, for each bitstring x, a bitstring of the same length as the encryption of x, consisting only of zeroes.
truncate: truncate(s,x) is the truncation of s to the length of x, where s is a stream of unbounded length.
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 key, cleartext, ciphertext, enc_seed, cipher_stream and the
probability Penc must be declared before this macro is
expanded. The functions enc, enc_r, dec, injbot, Z, enc_len, and truncate are declared
by this macro. They must not be declared elsewhere, and they can be
used only after expanding the macro.
*)
def INDdollar_CPA_sym_enc_all_args(key, cleartext, ciphertext, enc_seed, cipher_stream, enc, enc_r, dec, injbot, Z, enc_len, truncate, Penc) {
param N.
fun enc_r(cleartext, key, enc_seed): ciphertext.
fun dec(ciphertext, key): bitstringbot.
fun injbot(cleartext):bitstringbot [data].
(* The function Z returns for each bitstring, a bitstring
of the same length, consisting only of zeroes. *)
fun Z(cleartext):cleartext.
(* The function enc_len returns, for each bitstring x,
a bitstring of the same length as the encryption of x, consisting only of zeroes. *)
fun enc_len(cleartext): ciphertext.
(* truncate(s,x) is the truncation of s to the length of x.
s is assumed to be a stream of unbounded length. *)
fun truncate(cipher_stream, ciphertext): ciphertext.
(* The encryption function is probabilistic *)
letfun enc(m: cleartext, k: key) =
r <-R enc_seed; enc_r(m, k, r).
equation forall x:cleartext; injbot(x) <> bottom.
equation forall m:cleartext, k:key, r:enc_seed;
dec(enc_r(m, k, r), k) = injbot(m).
equiv(inddollar_cpa(enc))
k <-R key;
foreach i <= N do r <-R enc_seed; Oenc(x:cleartext) :=
return(enc_r(x, k, r))
<=(Penc(time, N, maxlength(x)))=>
k <-R key;
foreach i <= N do s <-R cipher_stream; Oenc(x:cleartext) :=
return(truncate(s, enc_len(Z(x)))).
}
def INDdollar_CPA_sym_enc(key, cleartext, ciphertext, cipher_stream, enc, dec, injbot, Z, enc_len, truncate, Penc) {
type enc_seed [bounded].
expand INDdollar_CPA_sym_enc_all_args(key, cleartext, ciphertext, enc_seed, cipher_stream, enc, enc_r, dec, injbot, Z, enc_len, truncate, Penc).
}
(* IND$-CPA encryption with a nonce.
This is similar to the INDdollar_CPA_sym_enc macro, but it uses a nonce
(which must have a different value in each call to encryption)
instead of random coins generated by encryption.
key: type of keys, must be "bounded" (to be able to generate random numbers from it, and to talk about the runtime of enc without mentioning the length of the key), typically "fixed" and "large".
cleartext: type of cleartexts
ciphertext: type of ciphertexts
nonce: type of the nonce
cipher_stream: type of unbounded streams (must be "nonuniform")
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.
enc_len: function that returns, for each bitstring x, a bitstring of the same length as the encryption of x, consisting only of zeroes.
truncate: truncate(s,x) is the truncation of s to the length of x, where s is a stream of unbounded length.
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 key, cleartext, ciphertext, nonce, cipher_stream and the
probability Penc must be declared before this macro is
expanded. The functions enc, dec, injbot, Z, enc_len, and truncate are declared
by this macro. They must not be declared elsewhere, and they can be
used only after expanding the macro.
*)
def INDdollar_CPA_sym_enc_nonce(key, cleartext, ciphertext, nonce, cipher_stream, enc, dec, injbot, Z, enc_len, truncate, Penc) {
param N, N2, N3.
fun enc(cleartext, key, nonce): ciphertext.
fun dec(ciphertext, key, nonce): bitstringbot.
fun injbot(cleartext):bitstringbot [data].
equation 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.
(* The function enc_len returns, for each bitstring x,
a bitstring of the same length as the encryption of x, consisting only of zeroes. *)
fun enc_len(cleartext): ciphertext.
(* truncate(s,x) is the truncation of s to the length of x.
s is assumed to be a stream of unbounded length. *)
fun truncate(cipher_stream, ciphertext): ciphertext.
equation forall m:cleartext, k:key, n: nonce;
dec(enc(m, k, n), k, n) = injbot(m).
(* Event raised when some nonce is used several times
with the same key, which breaks security. *)
event repeated_nonce.
(* IND$-CPA *)
equiv(inddollar_cpa(enc))
k <-R key;
foreach i <= N do Oenc(x:cleartext, n: nonce) :=
return(enc(x, k, n))
<=(Penc(time, N, maxlength(x)))=>
k <-R key;
foreach i <= N do Oenc(x:cleartext, n: nonce) :=
find u <= N suchthat defined(x[u],n[u],s[u]) && n = n[u] && x <> x[u] then
event_abort repeated_nonce
else
s <-R cipher_stream;
return(truncate(s, enc_len(Z(x)))).
}
(* IND$-CPA and INT-CTXT probabilistic symmetric encryption
key: type of keys, must be "bounded" (to be able to generate random numbers from it, and to talk about the runtime of enc_r without mentioning the length of the key), typically "fixed" and "large".
cleartext: type of cleartexts
ciphertext: type of ciphertexts
enc_seed: type of random coins for encryption (must be "bounded"; omitted in the second version of the macro).
cipher_stream: type of unbounded streams (must be "nonuniform")
enc: encryption function that generates coins internally
enc_r: encryption function that takes coins as argument (omitted in the second version of the macro).
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.
enc_len: function that returns, for each bitstring x, a bitstring of the same length as the encryption of x, consisting only of zeroes.
truncate: truncate(s,x) is the truncation of s to the length of x, where s is a stream of unbounded length.
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 key, cleartext, ciphertext, enc_seed, cipher_stream and the
probabilities Penc, Pencctxt must be declared before this macro is
expanded. The functions enc, enc_r, dec, injbot, Z, enc_len, and truncate are declared
by this macro. They must not be declared elsewhere, and they can be
used only after expanding the macro.
*)
def INDdollar_CPA_INT_CTXT_sym_enc_all_args(key, cleartext, ciphertext, enc_seed, cipher_stream, enc, enc_r, dec, injbot, Z, enc_len, truncate, Penc, Pencctxt) {
param N, N2, N3.
fun enc_r(cleartext, key, enc_seed): ciphertext.
fun dec(ciphertext, key): bitstringbot.
fun injbot(cleartext):bitstringbot [data].
equation 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.
(* The function enc_len returns, for each bitstring x,
a bitstring of the same length as the encryption of x, consisting only of zeroes. *)
fun enc_len(cleartext): ciphertext.
(* truncate(s,x) is the truncation of s to the length of x.
s is assumed to be a stream of unbounded length. *)
fun truncate(cipher_stream, ciphertext): ciphertext.
(* The encryption function is probabilistic *)
letfun enc(m: cleartext, k: key) =
r <-R enc_seed; enc_r(m, k, r).
equation forall m:cleartext, k:key, r:enc_seed;
dec(enc_r(m, k, r), k) = injbot(m).
(* IND$-CPA *)
equiv(inddollar_cpa(enc))
k <-R key;
foreach i <= N do r <-R enc_seed; Oenc(x:cleartext) :=
return(enc_r(x, k, r))
<=(Penc(time, N, maxlength(x)))=>
k <-R key;
foreach i <= N do s <-R cipher_stream; Oenc(x:cleartext) :=
return(truncate(s, enc_len(Z(x)))).
(* INT-CTXT *)
equiv(int_ctxt(enc))
k <-R key; (
foreach i <= N do r <-R enc_seed; Oenc(x:cleartext) := return(enc_r(x, k, r)) |
foreach i3 <= N3 do Odec(y:ciphertext) [useful_change] := return(dec(y,k)))
<=(Pencctxt(time, N, N3, maxlength(x), maxlength(y)))=> [computational]
k <-R key [unchanged]; (
foreach i <= N do r <-R enc_seed [unchanged]; Oenc(x:cleartext) := z:ciphertext <- enc_r(x, k, r); return(z) |
foreach i3 <= N3 do Odec(y:ciphertext) := find j <= N suchthat defined(x[j],z[j]) && z[j] = y then return(injbot(x[j])) else return(bottom)).
equiv(int_ctxt_corrupt(enc))
k <-R key; (
foreach i <= N do r <-R enc_seed; Oenc(x:cleartext) := return(enc_r(x, k, r)) |
foreach i3 <= N3 do Odec(y:ciphertext) [useful_change] := return(dec(y,k)) |
Ocorrupt() [10] := return(k))
<=(Pencctxt(time, N, N3, maxlength(x), maxlength(y)))=> [manual,computational]
k <-R key [unchanged]; (
foreach i <= N do r <-R enc_seed [unchanged]; Oenc(x:cleartext) := z:ciphertext <- enc_r(x, k, r); return(z) |
foreach i3 <= N3 do Odec(y:ciphertext) :=
if defined(corrupt) then return(dec(y,k)) else
find j <= N suchthat defined(x[j],z[j]) && z[j] = y then return(injbot(x[j])) else return(bottom) |
Ocorrupt() := let corrupt: bool = true in return(k)).
}
def INDdollar_CPA_INT_CTXT_sym_enc(key, cleartext, ciphertext, cipher_stream, enc, dec, injbot, Z, enc_len, truncate, Penc, Pencctxt) {
type enc_seed [bounded].
expand INDdollar_CPA_INT_CTXT_sym_enc_all_args(key, cleartext, ciphertext, enc_seed, cipher_stream, enc, enc_r, dec, injbot, Z, enc_len, truncate, Penc, Pencctxt).
}
(* IND$-CPA and INT-CTXT Authenticated encryption with a nonce.
This is similar to the INDdollar_CPA_INT_CTXT_sym_enc macro, but it uses a nonce
(which must have a different value in each call to encryption)
instead of random coins generated by encryption.
key: type of keys, must be "bounded" (to be able to generate random numbers from it, and to talk about the runtime of enc without mentioning the length of the key), typically "fixed" and "large".
cleartext: type of cleartexts
ciphertext: type of ciphertexts
nonce: type of the nonce
cipher_stream: type of unbounded streams (must be "nonuniform")
enc: encryption function
enc': symbol that replaces enc after game transformation
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.
enc_len: function that returns, for each bitstring x, a bitstring of the same length as the encryption of x, consisting only of zeroes.
truncate: truncate(s,x) is the truncation of s to the length of x, where s is a stream of unbounded length.
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 key, cleartext, ciphertext, nonce, cipher_stream and the
probabilities Penc, Pencctxt must be declared before this macro is
expanded. The functions enc, dec, injbot, Z, enc_len, and truncate are declared
by this macro. They must not be declared elsewhere, and they can be
used only after expanding the macro.
*)
def INDdollar_CPA_INT_CTXT_sym_enc_nonce(key, cleartext, ciphertext, nonce, cipher_stream, enc, dec, injbot, Z, enc_len, truncate, Penc, Pencctxt) {
param N, N2, N3.
fun enc(cleartext, key, nonce): ciphertext.
fun dec(ciphertext, key, nonce): bitstringbot.
fun injbot(cleartext):bitstringbot [data].
equation 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.
(* The function enc_len returns, for each bitstring x,
a bitstring of the same length as the encryption of x, consisting only of zeroes. *)
fun enc_len(cleartext): ciphertext.
(* truncate(s,x) is the truncation of s to the length of x.
s is assumed to be a stream of unbounded length. *)
fun truncate(cipher_stream, ciphertext): ciphertext.
equation forall m:cleartext, k:key, n: nonce;
dec(enc(m, k, n), k, n) = injbot(m).
(* Event raised when some nonce is used several times
with the same key, which breaks security. *)
event repeated_nonce.
(* IND$-CPA *)
equiv(inddollar_cpa(enc))
k <-R key;
foreach i <= N do Oenc(x:cleartext, n: nonce) :=
return(enc(x, k, n))
<=(Penc(time, N, maxlength(x)))=>
k <-R key;
foreach i <= N do Oenc(x:cleartext, n: nonce) :=
find u <= N suchthat defined(x[u],n[u],s[u]) && n = n[u] && x <> x[u] then
event_abort repeated_nonce
else
s <-R cipher_stream;
return(truncate(s, enc_len(Z(x)))).
(* INT-CTXT *)