-
Notifications
You must be signed in to change notification settings - Fork 5
/
cryptocode.tex
3981 lines (3421 loc) · 120 KB
/
cryptocode.tex
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
%% Copyright 2018 Arno Mittelbach
%
% This work may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either version 1.3
% of this license or (at your option) any later version.
% The latest version of this license is in
% http://www.latex-project.org/lppl.txt
% and version 1.3 or later is part of all distributions of LaTeX
% version 2005/12/01 or later.
%
% This work has the LPPL maintenance status `maintained'.
%
% The Current Maintainer of this work is Arno Mittelbach.
%
% This work consists of the files cryptocode.tex and cryptocode.sty
\documentclass[a4paper]{report}
% more than one optional parameter
\usepackage[usenames]{xcolor}
\usepackage{hyperref}
\usepackage[
n,
operators,
advantage,
sets,
adversary,
landau,
probability,
notions,
logic,
ff,
mm,
primitives,
events,
complexity,
asymptotics,
keys]{cryptocode}
\usepackage{csquotes}
\usepackage{fullpage}
\usepackage{dashbox}
\usepackage{todonotes}
\usepackage{url}
\usetikzlibrary{shapes.callouts}
\usepackage{listings}
\usepackage{trace}
\usepackage{makeidx}
\usepackage{mdframed}
\makeindex
\author{Arno Mittelbach\\
\texttt{mail@arno-mittelbach.de}}
\title{\Huge Cryptocode \\ \large\textsc{Typesetting Cryptography}}
\definecolor{mygreen}{rgb}{0,0.6,0}
\definecolor{mygray}{rgb}{0.1,0.1,0.1}
\definecolor{mymauve}{rgb}{0.58,0,0.82}
\lstset{language=[LaTeX]TeX,
backgroundcolor=\color{lightgray}, % choose the background color; you must add \usepackage{color} or \usepackage{xcolor}
rulecolor=\color{lightgray},
basicstyle=\scriptsize, % the size of the fonts that are used for the code
breakatwhitespace=false, % sets if automatic breaks should only happen at whitespace
breaklines=true, % sets automatic line breaking
captionpos=b, % sets the caption-position to bottom
commentstyle=\color{mygreen}, % comment style
escapeinside={\%*}{*)}, % if you want to add LaTeX within your code
extendedchars=true, % lets you use non-ASCII characters; for 8-bits encodings only, does not work with UTF-8
frame=single, % adds a frame around the code
keepspaces=true, % keeps spaces in text, useful for keeping indentation of code (possibly needs columns=flexible)
keywordstyle=\color{blue}, % keyword style
numbers=left, % where to put the line-numbers; possible values are (none, left, right)
numbersep=5pt, % how far the line-numbers are from the code
numberstyle=\tiny\color{mygray}, % the style that is used for the line-numbers
rulecolor=\color{black}, % if not set, the frame-color may be changed on line-breaks within not-black text (e.g. comments (green here))
showspaces=false, % show spaces everywhere adding particular underscores; it overrides 'showstringspaces'
showstringspaces=false, % underline spaces within strings only
showtabs=false, % show tabs within strings adding particular underscores
stepnumber=1, % the step between two line-numbers. If it's 1, each line will be numbered
stringstyle=\color{mymauve}, % string literal style
frameround=ftff,
belowskip=0em,
aboveskip=1em,
tabsize=2, % sets default tabsize to 2 spaces
title=\lstname }
\begin{document}
\maketitle
\begin{abstract}
\thispagestyle{empty}
The cryptocode package provides a set of macros to ease the typesetting of
pseudocode, algorithms and protocols (such as the one below). In addition it comes with a wide range of tools to typeset cryptographic papers (hence the name).
This includes simple predefined commands for concepts such as
a security parameter $\secparam$ or advantage terms $\advantage{prf}{\adv,\prf} = \negl$ but also flexible and powerful
environments to layout game-based proofs or black-box reductions.
\vspace{2em}
\begin{center}
\fbox{
\pseudocode{%
\textbf{ Alice} \< \< \textbf{ Bob} \\[0.1\baselineskip][\hline]
\<\< \\[-0.5\baselineskip]
x \sample \ZZ_q \< \< \\
X \gets g^x \<\< \\
\< \sendmessageright*{\GG,q,g,X} \< \\
\<\< y \sample \ZZ_q \\
\<\< Y \gets g^y \\
\< \sendmessageleft*{Y} \< \\
\key_A \gets Y^x \<\< \key_B \gets X^y }
}
\end{center}
\end{abstract}
\newpage
\pagenumbering{roman}
\tableofcontents
\thispagestyle{empty}
\newpage
\pagenumbering{arabic}
\chapter{Cryptocode by Example}
The cryptocode package provides a set of commands to ease the typesetting of
pseudocode, protocols, game-based proofs and black-box reductions. In addition it comes
with a large number of predefined commands. In this chapter we present the various features of
cryptocode by giving small examples. But first, let's load the package
\begin{lstlisting}
\usepackage[
n,
advantage,
operators,
sets,
adversary,
landau,
probability,
notions,
logic,
ff,
mm,
primitives,
events,
complexity,
asymptotics,
keys
]{cryptocode}
\end{lstlisting}
Note that all the options refer to a set of commands. That is, without any options cryptocode will provide the mechanisms
for writing pseudocode, protocols, game-based proofs and black-box reductions but not define additional commands,
such as \lstinline$\pk$ or \lstinline$\sk$ (for typesetting public and private/secret keys) which are part of the keys option.
We discuss the various options and associated commands in Chapter~\ref{chap:commands}.
\section{Pseudocode}
The cryptocode package tries to make writing pseudocode easy and enjoyable. The
\lstinline$\pseudocode$ command takes a single parameter where you can start writing
code in mathmode using \lstinline{\\} as line breaks. Following is an $\indcpa$ game
definition using various commands from cryptocode to ease writing keys (\lstinline{\pk,\sk}),
sampling (\lstinline{\sample}), and more:
\begin{center}
\fbox{\pseudocode[linenumbering,syntaxhighlight=auto]{%
b \sample \bin \\
(\pk,\sk) \sample \kgen (\secparam) \\
(\state,m_0,m_1) \sample \adv(\secparam, \pk, c) \\
c \sample \enc(\pk,m_b) \\
b' \sample \adv(\secparam, \pk, c, \state) \\
return b = b' }}
\end{center}
The above code is generated by (the code is actually wrapped in an \lstinline$fbox$).
\begin{lstlisting}
\pseudocode[linenumbering,syntaxhighlight=auto]{%
b \sample \bin \\
(\pk,\sk) \sample \kgen (\secparam) \\
(\state,m_0,m_1) \sample \adv(\secparam, \pk, c) \\
c \sample \enc(\pk,m_b) \\
b' \sample \adv(\secparam, \pk, c, \state) \\
return b = b' }
\end{lstlisting}
The pseudocode command thus takes a single mandatory argument (the code) plus an optional argument
which allows you to specify options in a key=value fashion. In the above example we used the linenumbering
option (which not surprisingly adds line numbers to the code) as well as the syntaxhighlighting option which
highlights certain keywords (in the example it is responsible for setting \enquote{return} as \highlightkeyword[]{return}).
It is easy to define a heading for your code. Either specify the header using the option \enquote{head} or use
the \lstinline$\procedure$ command which takes an additional argument to specify the headline.
\begin{center}
\fbox{\procedure[linenumbering]{$\indcpa_\enc^\adv$}{%
b \sample \bin \\
(\pk,\sk) \sample \kgen (\secparam) \\
(\state,m_0,m_1) \sample \adv(\secparam, \pk, c) \\
c \sample \enc(\pk,m_b) \\
b' \sample \adv(\secparam, \pk, c, \state) \\
\pcreturn b = b' }}
\end{center}
\begin{lstlisting}
\procedure[linenumbering]{$\indcpa_\enc^\adv$}{%
b \sample \bin \\
(\pk,\sk) \sample \kgen (\secparam) \\
(\state,m_0,m_1) \sample \adv(\secparam, \pk, c) \\
c \sample \enc(\pk,m_b) \\
b' \sample \adv(\secparam, \pk, c, \state) \\
\pcreturn b = b' }
\end{lstlisting}
Here in the example we have not turned on the automatic syntax highlighting but used the command \lstinline$\pcreturn$
to highlight the return statement. Besides \lstinline$\pcreturn$ there are a variant of predefined \enquote{keywords}
such as \lstinline$\pcfor$, \lstinline$\pcif$, etc. (all prefixed with pc)
There is a lot more that we will discuss in detail in Chapter~\ref{chap:pseudocode}. Here, for example
is the same code with an overlay explanation and a division of the pseudocode.
\begin{center}
\fbox{
\begin{pcimage}
\procedure[linenumbering]{$\indcpa_\enc^\adv$}{%
b \sample \bin \\
(\pk,\sk) \sample \kgen (\secparam)\pcnode{kgen} \pclb
\pcintertext[dotted]{Setup Completed}
(m_0,m_1) \sample \adv(\secparam, \pk, c) \\
c \sample \enc(\pk,m_b) \\
b' \sample \adv(\secparam, \pk, c, \state) \\
\pcreturn b = b' }
\pcdraw{
\node[rectangle callout,callout absolute pointer=(kgen),fill=orange]
at ([shift={(+3,-1)}]kgen) {
\begin{varwidth}{3cm}
$\kgen(\secparam)$ samples a public key $\pk$ and a private key $\sk$.
\end{varwidth}
};
}
\end{pcimage}
}
\end{center}
\begin{lstlisting}
\begin{pcimage}
\procedure[linenumbering]{$\indcpa_\enc^\adv$}{%
b \sample \bin \\
(\pk,\sk) \sample \kgen (\secparam)\pcnode{kgen} \pclb
\pcintertext[dotted]{Setup Completed}
(m_0,m_1) \sample \adv(\secparam, \pk, c) \\
c \sample \enc(\pk,m_b) \\
b' \sample \adv(\secparam, \pk, c, \state) \\
\pcreturn b = b' }
\pcdraw{
\node[rectangle callout,callout absolute pointer=(kgen),fill=orange]
at ([shift={(+3,-1)}]kgen) {
\begin{varwidth}{3cm}
$\kgen(\secparam)$ samples a public key $\pk$ and a private key $\sk$.
\end{varwidth}
};
}
\end{pcimage}
\end{lstlisting}
\section{Columns}
The \lstinline$\pseudocode$ and \lstinline$\procedure$ commands allow the usage of multiple columns.
You switch to a new column by inserting a \lstinline$\>$. This is similar to using an \lstinline$align$
environment and placing a tabbing \& character.\footnote{In fact, the \emph{pseudocode} command
is based on amsmath's flalign environment.}
\begin{center}
\fbox{%
\pseudocode{%
\textbf{First} \> \textbf{Second} \> \textbf{Third} \> \textbf{Fourth} \\
b \sample \bin \> b \sample \bin \> b \sample \bin \> b \sample \bin}
}
\end{center}
\begin{lstlisting}
\pseudocode{%
\textbf{First} \> \textbf{Second} \> \textbf{Third} \> \textbf{Fourth} \\
b \sample \bin \> b \sample \bin \> b \sample \bin \> b \sample \bin}
\end{lstlisting}
As you can see the first column is left aligned the second right, the third left and so forth.
In order to get only left aligned columns you could thus simply always skip a column by
using \lstinline$\>\>$. You can also use \lstinline$\<$ a shorthand for \lstinline$\>\>$.
\begin{center}
\fbox{%
\pseudocode{%
\textbf{First} \< \textbf{Second} \< \textbf{Third} \< \textbf{Fourth} \\
b \sample \bin \< b \sample \bin \< b \sample \bin \< b \sample \bin}
}
\end{center}
\section{Protocols}
Using columns makes it easy to write even complex protocols. Following is a simple
three party protocol
\begin{center}
\fbox{%
\pseudocode{%
\textbf{Alice} \< \< \textbf{Bob} \< \< \textbf{Charlie} \\[][\hline]
\text{work} \< \< \< \< \\
\< \sendmessageright{top=Work result,topstyle=red} \< \< \< \\
\< \< \text{work} \< \< \\
\< \< \< \sendmessageright{top=Work result,bottom=Bottom message} \< \\
\< \< \< \< \text{work} \\
\< \sendmessageleftx{8}{\text{A long message for Alice}} \< \\
\text{finalize} \< \< \< \< }
}
\end{center}
\begin{lstlisting}
\pseudocode{%
\textbf{Alice} \< \< \textbf{Bob} \< \< \textbf{Charlie} \\[][\hline]
\text{work} \< \< \< \< \\
\< \sendmessageright{top=Work result,topstyle=red} \< \< \< \\
\< \< \text{work} \< \< \\
\< \< \< \sendmessageright{top=Work result,bottom=Bottom message} \< \\
\< \< \< \< \text{work} \\
\< \sendmessageleftx{8}{\text{A long message for Alice}} \< \\
\text{finalize} \< \< \< \< }
\end{lstlisting}
The commands \lstinline$\sendmessageright$ and \lstinline$\sendmessageleft$ are very flexible and
allow to style the sending of messages in various ways. Also note the \lstinline$\\[][\hline]$ at the end of the
first line. Here the first optional argument allows us to specify the lineheight (similarly to the behavior in an
align environment). The second optional argument allows us to, for example, draw a horizontal line.
In multi player protocols such as the one
above the commands \lstinline$\sendmessagerightx$ and \lstinline$\sendmessageleftx$ (note the x at the end)
allow to send messages over multiple columns. In the example, as we were using \lstinline$\<$ the
final message thus spans 8 columns.
For basic protocols you might also utilize the \lstinline$\sendmessageright*$ and \lstinline$\sendmessageleft*$
commands which simply take a message which is displayed.
\begin{center}
\fbox{%
\pseudocode{%
\textbf{ Alice} \< \< \textbf{ Bob} \\[0.1\baselineskip][\hline]
\<\< \\[-0.5\baselineskip]
x \sample \ZZ_q \< \< \\
X \gets g^x \<\< \\
\< \sendmessageright*{\GG,q,g,X} \< \\
\<\< y \sample \ZZ_q \\
\<\< Y \gets g^y \\
\< \sendmessageleft*{Y} \< \\
\key_A \gets Y^x \<\< \key_B \gets X^y
}
}
\end{center}
\begin{lstlisting}
\pseudocode{%
\textbf{ Alice} \< \< \textbf{ Bob} \\[0.1\baselineskip][\hline]
\<\< \\[-0.5\baselineskip]
x \sample \ZZ_q \< \< \\
X \gets g^x \<\< \\
\< \sendmessageright*{\GG,q,g,X} \< \\
\<\< y \sample \ZZ_q \\
\<\< Y \gets g^y \\
\< \sendmessageleft*{Y} \< \\
\key_A \gets Y^x \<\< \key_B \gets X^y }
\end{lstlisting}
We will discuss protocols in greater detail in Chapter~\ref{chap:protocols}.
\section{Game-based Proofs}
Cryptocode supports authors in visualizing game-based proofs. It defines an environment
\lstinline$gameproof$ which allows to wrap a number of game procedures displaying helpful
information as to what changes from game to game, and to what each step is reduced.
\vspace{2\baselineskip}
\begin{center}
\begin{gameproof}
\gameprocedure[linenumbering,mode=text]{%
Step 1 \\
Step 2 \\
Step 3
}
\gameprocedure[mode=text]{%
Step 1 \\
\gamechange{Step 2 is different} \\
Step 3
}
\addgamehop{1}{2}{hint={\footnotesize some hint}}
\end{gameproof}
\end{center}
\begin{lstlisting}
\begin{gameproof}
\gameprocedure[linenumbering,mode=text]{%
Step 1 \\
Step 2 \\
Step 3
}
\gameprocedure[mode=text]{%
Step 1 \\
\gamechange{Step 2 is different} \\
Step 3
}
\addgamehop{1}{2}{hint={\footnotesize some hint}}
\end{gameproof}
\end{lstlisting}
Note that we made use of the option \enquote{mode=text} in the above example which tells the underlying pseudocode
command to not work in math mode but in plain text mode. We'll discuss how to visualize game-based proofs in Chapter~\ref{chap:gbproofs}.
\section{Black-box Reductions}
Cryptocode provides a strucured syntax to visualize black-box reductions. Basically cryptocode
provides an environment to draw boxes that may have oracles and that can be communicated with.
Cryptocode makes heavy use of TIKZ (\url{https://www.ctan.org/pkg/pgf}) for this, which gives you
quite some control over how things should look like. Additionally, as you can specify node names
(for example the outer box in the next example is called \enquote{A}) you can easily extend the pictures
by using plain TIKZ commands.
\begin{bbrenv}[1cm]{A}[0.5cm]
\begin{bbrbox}[name=Reduction]
\pseudocode{
\text{Do something} \\
\text{Step 2}
}
\begin{bbrenv}{B}
\begin{bbrbox}[name=Adversary,minheight=4cm]
\end{bbrbox}
\bbrmsgto{top=$m$}
\bbrmsgfrom{top=$\sigma$}
\bbrmsgtxt{\pseudocode{%
\text{more work}
}}
\bbrmsgto{top=$m$}
\bbrmsgfrom{top=$\sigma$}
\bbrqryto{side=$m$}
\bbrqryfrom{side=$b$}
\end{bbrenv}
\pseudocode{
\text{finalize}
}
\end{bbrbox}
\bbrinput{input}
\bbroutput{output}
\begin{bbroracle}{OraA}
\begin{bbrbox}[name=Oracle 1,minheight=1cm]
\end{bbrbox}
\end{bbroracle}
\bbroracleqryto{top=$m$}
\bbroracleqryfrom{top=$b$}
\begin{bbroracle}{OraB}
\begin{bbrbox}[name=Oracle 2,minheight=1cm]
\end{bbrbox}
\end{bbroracle}
\bbroracleqryto{top=$m$}
\bbroracleqryfrom{top=$b$}
\end{bbrenv}
\begin{lstlisting}
\begin{bbrenv}{A}
\begin{bbrbox}[name=Reduction]
\pseudocode{
\text{Do something} \\
\text{Step 2}
}
\begin{bbrenv}{B}
\begin{bbrbox}[name=Adversary,minheight=4cm]
\end{bbrbox}
\bbrmsgto{top=$m$}
\bbrmsgfrom{top=$\sigma$}
\bbrmsgtxt{\pseudocode{%
\text{more work}
}}
\bbrmsgto{top=$m$}
\bbrmsgfrom{top=$\sigma$}
\bbrqryto{side=$m$}
\bbrqryfrom{side=$b$}
\end{bbrenv}
\pseudocode{
\text{finalize}
}
\end{bbrbox}
\bbrinput{input}
\bbroutput{output}
\begin{bbroracle}{OraA}
\begin{bbrbox}[name=Oracle 1,minheight=1cm]
\end{bbrbox}
\end{bbroracle}
\bbroracleqryto{top=$m$}
\bbroracleqryfrom{top=$b$}
\begin{bbroracle}{OraB}
\begin{bbrbox}[name=Oracle 2,minheight=1cm]
\end{bbrbox}
\end{bbroracle}
\bbroracleqryto{top=$m$}
\bbroracleqryfrom{top=$b$}
\end{bbrenv}
\end{lstlisting}
We'll discuss the details in Chapter~\ref{chap:bbr}.
\chapter{Cryptographic Notation}
\label{chap:commands}
\index{package options}
In this section we'll discuss the various commands for notation that can be loaded via package options.
\begin{lstlisting}
\usepackage[
n,
advantage,
operators,
sets,
adversary,
landau,
probability,
notions,
logic,
ff,
mm,
primitives,
events,
complexity,
asymptotics,
keys
]{cryptocode}
\end{lstlisting}
\textbf{Remark. } The commands defined so far are far from complete and are currently mostly targeted at what I needed in my
papers (especially once you get to cryptographic notions and primitives). So please if you feel that something should be added
drop me an email.
\section{Security Parameter}
\index{security parameter|see {package options}}
\index{package options!security parameter}
In cryptography we make use of a security parameter which is usually written as $1^n$ or $1^\lambda$. The cryptocode
package, when loading either option \enquote{n} or option \enquote{lambda} will define the commands
\begin{lstlisting}
\secpar
\secparam
\end{lstlisting}
The first command provides the \enquote{letter}, i.e., either $n$ or $\lambda$, whereas \lstinline$\secparam$ points
to $1^\secpar$.
\section{Advantage Terms}
Load the package option ``advantage'' in order to define the command \lstinline$\advantage$ used to specify advantage terms such as:
\[
\advantage{prf}{\adv,\prf} = \negl
\]
\begin{lstlisting}
\advantage{prf}{\adv,\prf} = \negl
\end{lstlisting}
Specify an optional third parameter to replace the $(\secpar)$.
\begin{lstlisting}
\advantage{prf}{\adv,\prf}[(arg)]
\end{lstlisting}
In order to redefine the styles in which superscript and subscript are set redefine
\begin{lstlisting}
\renewcommand{\pcadvantagesuperstyle}[1]{\mathrm{\MakeLowercase{#1}}}
\renewcommand{\pcadvantagesubstyle}[1]{#1}
\end{lstlisting}
\section{Math Operators}
\index{operators|see {package options}}
\index{package options!operators}
\index{math operators|see {package options}}
The \enquote{operators} option provides the following list of commands:
\begin{center}
\begin{tabular}{l p{6cm} l l}
\textbf{Command} & \textbf{Description} & \textbf{Result} & \textbf{Example} \\\hline
\lstinline$\sample$ & Sampling from a distribution, or running a randomized procedure & $\sample$ & $b \sample \bin$ \\
\lstinline$\floor{42.5}$ & Rounding down & $\floor{42.5}$ & \\
\lstinline$\ceil{41.5}$ & Rounding up & $\ceil{41.5}$ & \\
\lstinline$\Angle{x,y}$ & Vector product & $\Angle{x,y}$ & \\
\lstinline$\abs{42.9}$ & Absolute number & $\abs{42.9}$ & \\
\lstinline$\norm{x}$ & Norm & $\norm{x}$ & \\
\lstinline$\concat$ & Verbose concatenation (I usually prefer simply \lstinline$\|$) & $\concat$ & $x \gets a\concat b$ \\
\lstinline$\emptystring$ & The empty string & $\emptystring$ & $x \gets \emptystring$
\end{tabular}
\end{center}
\section{Adversaries}
\index{adversary|see {package options}}
\index{package options!adversary}
The \enquote{adversary} option provides the following list of commands:
\begin{center}
\begin{tabular}{l l l}
\textbf{Command} & \textbf{Description} & \textbf{Result} \\\hline
\lstinline$\adv$ & Adversary & $\adv$ \\
\lstinline$\bdv$ & Adversary & $\bdv$ \\
\lstinline$\cdv$ & Adversary & $\cdv$ \\
\lstinline$\ddv$ & Adversary & $\ddv$ \\
\lstinline$\mdv$ & Adversary & $\mdv$ \\
\lstinline$\pdv$ & Adversary & $\pdv$ \\
\lstinline$\sdv$ & Adversary & $\sdv$
\end{tabular}
\end{center}
The style in which an adversary is rendered is controlled via
\begin{lstlisting}
\renewcommand{\pcadvstyle}[1]{\mathcal{#1}}
\end{lstlisting}
\section{Landau}
\index{Landau|see {package options}}
\index{package options!Landau}
The \enquote{landau} option provides the following list of commands:
\begin{center}
\begin{tabular}{l l l}
\textbf{Command} & \textbf{Description} & \textbf{Result} \\\hline
\lstinline$\bigO{n^2}$ & Big O notation & $\bigO{n^2}$ \\
\lstinline$\smallO{n^2}$ & small o notation & $\smallO{n^2}$ \\
\lstinline$\bigOmega{n^2}$ & Big Omega notation & $\bigOmega{n^2}$ \\
\lstinline$\bigsmallO{n^2}$ & Big and small O notation & $\bigsmallO{n^2}$
\end{tabular}
\end{center}
\section{Probabilities}
\index{probability|see {package options}}
\index{package options!probabilities}
The \enquote{probability} option provides commands for writing probabilities. Use
\begin{lstlisting}
\prob{X=x}
\probsub{x\sample{\bin^n}}{x=5}
\condprob{X=x}{A=b}
\condprobsub{x\sample{\bin^n}}{x=5}{A=b}
\end{lstlisting}
to write basic probabilities, probabilities with explicit probability spaces and conditional probabilities.
\begin{align*}
& \prob{X=x} \\
& \probsub{x\sample{\bin^n}}{X=x} \\
& \condprob{X=x}{A=b} \\
& \condprobsub{x\sample{\bin^n}}{x=5}{A=b}
\end{align*}
You can control the probability symbol (Pr) by redefining
\begin{lstlisting}
\renewcommand{\probname}{Pr}
\end{lstlisting}
For expectations you can use
\begin{lstlisting}
\expect{X}
\expsub{x,y\sample\set{1,\ldots,6}}{x+y}
\condexp{X+Y}{Y>3}
\condexpsub{x,y\sample\set{1,\ldots,6}}{x+y}{y>3}
\end{lstlisting}
yielding
\begin{align*}
& \expect{X} \\
& \expsub{x,y\sample\set{1,\ldots,6}}{x+y} \\
& \condexp{X+Y}{Y>3} \\
& \condexpsub{x,y\sample\set{1,\ldots,6}}{x+y}{y>3}
\end{align*}
You can control the expactation symbol ($\mathbb{E}$) by redefining
\begin{lstlisting}
\renewcommand{\expectationname}{\ensuremath{\mathbb{E}}}
\end{lstlisting}
The support $\supp{X}$ of a random variable $X$ can be written as
\begin{lstlisting}
\supp{X}
\end{lstlisting}
where again the name can be controlled via
\begin{lstlisting}
\renewcommand{\supportname}{Supp}
\end{lstlisting}
For denoting entropy and min-entropy use
\begin{lstlisting}
\entropy{X}
\minentropy{X}
\condentropy{X}{Y=5}
\condminentropy{X}{Y=5}
\condavgminentropy(X}{Y=5}
\end{lstlisting}
This yields
\begin{align*}
& \entropy{X} \\
& \minentropy{X} \\
& \condentropy{X}{Y=5} \\
& \condminentropy{X}{Y=5} \\
& \condavgminentropy{X}{Y=5}
\end{align*}
\section{Sets}
\index{sets|see {package options}}
\index{package options!sets}
The \enquote{sets} option provides commands for basic mathematical sets.
You can write sets and sequences as
\begin{lstlisting}
\set{1, \ldots, 10}
\sequence{1, \ldots, 10}
\end{lstlisting}
which is typeset as
\begin{align*}
& \set{1, \ldots, 10} \\
& \sequence{1, \ldots, 10}
\end{align*}
In addation the following commands are provided
\begin{center}
\begin{tabular}{l l l}
\textbf{Command} & \textbf{Description} & \textbf{Result} \\\hline
\lstinline$\bin$ & The set containing 0 and 1 & $\bin$ \\
\lstinline$\NN$ & Natural numbers & $\NN$ \\
\lstinline$\ZZ$ & Integers & $\ZZ$ \\
\lstinline$\QQ$ & Rational numbers & $\QQ$ \\
\lstinline$\CC$ & Complex numbers & $\CC$ \\
\lstinline$\RR$ & Reals & $\RR$ \\
\lstinline$\PP$ & & $\PP$ \\
\lstinline$\FF$ & & $\FF$ \\
\end{tabular}
\end{center}
\section{Crypto Notions}
\index{notions|see {package options}}
\index{package options!notions}
\index{Crypto notions|see {package options}}
The \enquote{notions} option provides the following list of commands:
\begin{center}
\begin{tabular}{l l l}
\textbf{Command} & \textbf{Description} & \textbf{Result} \\\hline
\lstinline$\indcpa$ & IND-CPA security for encryption schemes & $\indcpa$ \\
\lstinline$\indcca$ & IND-CCA security for encryption schemes & $\indcca$ \\
\lstinline$\indccai$ & IND-CCA1 security for encryption schemes & $\indccai$ \\
\lstinline$\indccaii$ & IND-CCA2 security for encryption schemes & $\indccaii$ \\
\lstinline$\priv$ & PRIV security for deterministic public-key encryption schemes & $\priv$ \\
\lstinline$\ind$ & IND security (for deterministic public-key encryption schemes) & $\ind$ \\
\lstinline$\prvcda$ & PRV-CDA security (for deterministic public-key encryption schemes)& $\prvcda$ \\
\lstinline$\prvrcda$ & PRV\$-CDA security (for deterministic public-key encryption schemes) & $\prvrcda$ \\
\lstinline$\kiae$ & Key independent authenticated encryption & $\kiae$ \\
\lstinline$\kdae$ & Key dependent authenticated encryption & $\kdae$ \\
\lstinline$\mle$ & Message locked encryption & $\mle$ \\
\lstinline$\uce$ & Universal computational extractors & $\uce$ \\
\end{tabular}
\end{center}
The style in which notions are displayed can be controlled via redefining
\begin{lstlisting}
\renewcommand{\pcnotionstyle}[1]{\ensuremath{\mathrm{#1}}}
\end{lstlisting}
\section{Logic}
\index{logic|see {package options}}
\index{package options!logic}
The \enquote{logic} option provides the following list of commands:
\begin{center}
\begin{tabular}{l l l}
\textbf{Command} & \textbf{Description} & \textbf{Result} \\\hline
\lstinline$\AND$ & Logical AND & $\AND$ \\
\lstinline$\NAND$ & Logical NAND & $\NAND$ \\
\lstinline$\OR$ & Logical OR & $\OR$ \\
\lstinline$\NOR$ & Logical NOR & $\NOR$ \\
\lstinline$\XOR$ & Logical XOR & $\XOR$ \\
\lstinline$\XNOR$ & Logical XNOR & $\XNOR$ \\
\lstinline$\NOT$ & not & $\NOT$ \\
\lstinline$\xor$ & exclusive or & $\xor$ \\
\lstinline$\false$ & false & $\false$ \\
\lstinline$\true$ & true & $\true$
\end{tabular}
\end{center}
% Function Families
\section{Function Families}
\index{ff|see {package options}}
\index{package options!ff}
\index{function families|see {package options}}
The \enquote{ff} option provides the following list of commands:
\begin{center}
\begin{tabular}{l l l}
\textbf{Command} & \textbf{Description} & \textbf{Result} \\\hline
\lstinline$\kgen$ & Key generation & $\kgen$ \\
\lstinline$\pgen$ & Parameter generation & $\pgen$ \\
\lstinline$\eval$ & Evaluation & $\eval$ \\
\lstinline$\invert$ & Inversion & $\invert$ \\
\lstinline$\il$ & Input length & $\il$ \\
\lstinline$\ol$ & Output length & $\ol$ \\
\lstinline$\kl$ & Key length & $\kl$ \\
\lstinline$\nl$ & Nonce length & $\nl$ \\
\lstinline$\rl$ & Randomness length & $\rl$
\end{tabular}
\end{center}
The style in which these are displayed can be controlled via redefining
\begin{lstlisting}
\renewcommand{\pcalgostyle}[1]{\ensuremath{\mathsf{#1}}}
\end{lstlisting}
% Machine Model
\section{Machine Model}
\index{machine model|see {package options}}
\index{package options!mm}
\index{mm|see {package options}}
The \enquote{mm} option provides the following list of commands:
\begin{center}
\begin{tabular}{l l l}
\textbf{Command} & \textbf{Description} & \textbf{Result} \\\hline
\lstinline$\CRKT$ & A circuit & $\CRKT$ \\
\lstinline$\TM$ & A Turing machine & $\TM$ \\
\lstinline$\PROG$ & A program & $\PROG$ \\
\lstinline$\uTM$ & A universal Turing machine & $\uTM$ \\
\lstinline$\uC$ & A universal Circuit & $\uC$ \\
\lstinline$\uP$ & A universal Program & $\uP$ \\
\lstinline$\tmtime$ & Time (of a TM) & $\tmtime$ \\
\lstinline$\ppt$ & Probabilistic polynomial time & $\ppt$
\end{tabular}
\end{center}
The style in which these are displayed can be controlled via redefining
\begin{lstlisting}
\renewcommand{\pcmachinemodelstyle}[1]{\ensuremath{\mathsf{#1}}}
\end{lstlisting}
\section{Crypto Primitives}
\index{primitives|see {package options}}
\index{package options!primitives}
\index{Crypto primitives|see {package options}}
The \enquote{primitives} option provides the following list of commands:
\begin{center}
\begin{tabular}{l l l}
\textbf{Command} & \textbf{Description} & \textbf{Result} \\\hline
\lstinline$\prover$ & Proover & $\prover$ \\
\lstinline$\verifier$ & Verifier & $\verifier$ \\
\lstinline$\nizk$ & Non interactie zero knowledge & $\nizk$ \\
\lstinline$\hash$ & A hash function & $\hash$ \\
\lstinline$\gash$ & A hash function& $\gash$ \\
\lstinline$\fash$ & A hash function & $\fash$ \\
\lstinline$\enc$ & Encryption & $\enc$ \\
\lstinline$\dec$ & Decryption & $\dec$ \\
\lstinline$\sig$ & Signing & $\sig$ \\
\lstinline$\verify$ & Verifying & $\verify$ \\
\lstinline$\obf$ & Obfuscation & $\obf$ \\
\lstinline$\iO$ & Indistinguishability obfuscation & $\iO$ \\
\lstinline$\diO$ & Differing inputs obfuscation & $\diO$ \\
\lstinline$\mac$ & Message authentication & $\mac$ \\
\lstinline$\puncture$ & Puncturing & $\puncture$ \\
\lstinline$\source$ & A source & $\source$ \\
\lstinline$\predictor$ & A predictor & $\predictor$ \\
\lstinline$\sam$ & A sampler & $\sam$ \\
\lstinline$\distinguisher$ & A distinguisher & $\distinguisher$ \\
\lstinline$\dist$ & A distinguisher& $\dist$ \\
\lstinline$\simulator$ & A simulator & $\simulator$ \\
\lstinline$\ext$ & An extractor & $\ext$
\end{tabular}
\end{center}
The style in which these are displayed can be controlled via redefining
\begin{lstlisting}
\renewcommand{\pcalgostyle}[1]{\ensuremath{\mathsf{#1}}}
\end{lstlisting}
\section{Events}
\index{events|see {package options}}
\index{package options!events}
The \enquote{events} option provides the following list of commands.
To classify an event use
\begin{lstlisting}
\event{Event}
\nevent{Event}
\end{lstlisting}
where the second is meant as the negation. These are typset as
\begin{align*}
&\event{Event}\\
&\nevent{Event}
\end{align*}
For bad events, use \lstinline$\bad$ ($\bad$).
\section{Complexity}
\index{complexity|see {package options}}
\index{package options!complexity}
The \enquote{complexity} option provides the following list of commands:
\begin{center}
\begin{tabular}{l l l}
\textbf{Command} & \textbf{Result} \\\hline
\lstinline$\npol$ & $\npol$ \\
\lstinline$\conpol$ & $\conpol$ \\
\lstinline$\pol$ & $\pol$ \\
\lstinline$\bpp$ & $\bpp$ \\
\lstinline$\ppoly$ & $\ppoly$ \\
\lstinline$\NC{1}$ & $\NC1$ \\
\lstinline$\AC{1}$ & $\AC1$ \\
\lstinline$\TC{1}$ & $\TC1$ \\
\lstinline$\AM$ & $\AM$ \\
\lstinline$\coAM$ & $\coAM$
\end{tabular}
\end{center}
The style in which these are displayed can be controlled via redefining
\begin{lstlisting}
\renewcommand{\pccomplexitystyle}[1]{\ensuremath{\mathsf{#1}}}
\end{lstlisting}
\section{Asymptotics}
\index{asymptotics|see {package options}}
\index{package options!asymptotics}
The \enquote{asymptotics} option provides the following list of commands:
\begin{center}
\begin{tabular}{l l p{7.5cm}}
\textbf{Command} & \textbf{Description} & \textbf{Result} \\\hline
\lstinline$\negl$ & A negligible function & $\negl$ (takes an optional argument \lstinline$\negl[a]$ ($\negl[a]$). Write \lstinline$\negl[]$ for $\negl[]$.) \\
\lstinline$\poly$ & A polynomial & $\poly$ (takes an optional argument \lstinline$\poly[a]$ ($\poly[a]$). Write \lstinline$\poly[]$ for $\poly[]$.) \\
\lstinline$\pp$ & some polynomial $\pp$ & $\pp$ \\
\lstinline$\qq$ & some polynomial $\qq$ & $\qq$ \\
\end{tabular}
\end{center}
The style in which these are displayed can be controlled via redefining
\begin{lstlisting}
\renewcommand{\pcpolynomialstyle}[1]{\ensuremath{\mathrm{#1}}}
\end{lstlisting}
\section{Keys}
\index{keys|see {package options}}
\index{package options!keys}
The \enquote{keys} option provides the following list of commands:
\begin{center}
\begin{tabular}{l l l}
\textbf{Command} & \textbf{Description} & \textbf{Result} \\\hline
\lstinline$\pk$ &public key & $\pk$ \\
\lstinline$\vk$ & verification key& $\vk$ \\
\lstinline$\sk$ & secret key& $\sk$ \\
\lstinline$\key$ & a plain key& $\key$ \\
\lstinline$\hk$ & hash key& $\hk$ \\
\lstinline$\gk$ &gash key & $\gk$ \\
\lstinline$\fk$ & function key & $\fk$
\end{tabular}
\end{center}
The style in which these are displayed can be controlled via redefining
\begin{lstlisting}
\renewcommand{\pckeystyle}[1]{\ensuremath{\mathsf{#1}}}
\end{lstlisting}
\chapter{Pseudocode}
\label{chap:pseudocode}
In this chapter we discuss how to write pseudocode with the cryptocode library.
\section{Basics}
\index{\textbackslash pseudocode}
The cryptocode package provides the command \emph{pseudocode} for typesetting algorithms.
Consider the following definition of an IND-CPA game
\begin{center}
\fbox{%
\pseudocode{%
b \sample \bin \\
(\pk,\sk) \sample \kgen (\secparam) \\
(m_0,m_1) \sample \adv(\secparam, \pk, c) \\
c \sample \enc(\pk,m_b) \\
b' \sample \adv(\secparam, \pk, c) \\
\pcreturn b = b' }
}
\end{center}
which is generated as
\begin{lstlisting}
\pseudocode{%
b \sample \bin \\
(\pk,\sk) \sample \kgen (\secparam) \\
(m_0,m_1) \sample \adv(\secparam, \pk, c) \\
c \sample \enc(\pk,m_b) \\
b' \sample \adv(\secparam, \pk, c) \\