summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/doc/latex/cryptocode
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2015-03-28 21:41:27 +0000
committerKarl Berry <karl@freefriends.org>2015-03-28 21:41:27 +0000
commit66d4bb2ab2031db51d7818a691dc267fd3991d79 (patch)
tree52d3a6e71c87eeca3dffa016cd60025ae56eb7c8 /Master/texmf-dist/doc/latex/cryptocode
parent719d9d5c5bf005dd81b357ada574bf794b34a7d2 (diff)
cryptocode (28mar15)
git-svn-id: svn://tug.org/texlive/trunk@36659 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/doc/latex/cryptocode')
-rw-r--r--Master/texmf-dist/doc/latex/cryptocode/cryptocode.pdfbin810963 -> 623560 bytes
-rw-r--r--Master/texmf-dist/doc/latex/cryptocode/cryptocode.tex824
2 files changed, 533 insertions, 291 deletions
diff --git a/Master/texmf-dist/doc/latex/cryptocode/cryptocode.pdf b/Master/texmf-dist/doc/latex/cryptocode/cryptocode.pdf
index 802ec5b0226..602430e15a0 100644
--- a/Master/texmf-dist/doc/latex/cryptocode/cryptocode.pdf
+++ b/Master/texmf-dist/doc/latex/cryptocode/cryptocode.pdf
Binary files differ
diff --git a/Master/texmf-dist/doc/latex/cryptocode/cryptocode.tex b/Master/texmf-dist/doc/latex/cryptocode/cryptocode.tex
index 3dd048a2aee..35c85948c70 100644
--- a/Master/texmf-dist/doc/latex/cryptocode/cryptocode.tex
+++ b/Master/texmf-dist/doc/latex/cryptocode/cryptocode.tex
@@ -47,39 +47,42 @@
\usetikzlibrary{shapes.callouts}
-\usetikzlibrary{ocgx}
\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.5,0.5,0.5}
+\definecolor{mygray}{rgb}{0.1,0.1,0.1}
\definecolor{mymauve}{rgb}{0.58,0,0.82}
\lstset{language=[LaTeX]TeX,
- backgroundcolor=\color{white}, % choose the background color; you must add \usepackage{color} or \usepackage{xcolor}
- basicstyle=\footnotesize, % the size of the fonts that are used for the code
+ 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
- deletekeywords={...}, % if you want to delete keywords from the given language
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
- language=Octave, % the language of the code
- morekeywords={*,...}, % if you want to add more keywords to the set
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
@@ -87,13 +90,15 @@
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=2, % the step between two line-numbers. If it's 1, each line will be numbered
+ 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}
-%\pcfixhyperref
\maketitle
@@ -125,16 +130,16 @@ x \sample \ZZ_q \< \< \\
\end{center}
-
\end{abstract}
\newpage
-\pagenumbering{arabic}
+\pagenumbering{roman}
\tableofcontents
\thispagestyle{empty}
\newpage
+\pagenumbering{arabic}
\chapter{Cryptocode by Example}
Cryptocode is a \LaTeX package to ease the writing of cryptographic papers. It provides mechanisms
@@ -199,7 +204,7 @@ The above code is generated by (the code is actually wrapped in an \lstinline$fb
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 \pseudocodeconstant[]{return}).
+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.
@@ -222,8 +227,8 @@ the \lstinline$\procedure$ command which takes an additional argument to specify
\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{PseudocodeConstants}
-such as \lstinline$\pcfor$, \lstinline$\pcif$, etc.
+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.
@@ -273,6 +278,8 @@ is the same code with an overlay explanation and a division of the pseudocode.
\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$
@@ -510,6 +517,8 @@ by using plain TIKZ commands.
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[
@@ -537,6 +546,8 @@ papers (especially once you get to cryptographic notions and primitives). So ple
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}
@@ -555,25 +566,38 @@ Load the package option ``advantage'' in order to define the command \lstinline$
\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 l l l}
+\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$ & Rounding down & $\floor{42.5}$ & \\
-\lstinline$\ceil$ & Rounding up & $\ceil{41.5}$ & \\
-\lstinline$\Angle$ & Vector product & $\Angle{x,y}$ & \\
-\lstinline$\abs$ & Absolute number & $\abs{42.9}$ & \\
-\lstinline$\norm$ & Norm & $\norm{x}$ & \\
+\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}
@@ -596,6 +620,8 @@ The style in which an adversary is rendered is controlled via
\section{Landau}
+\index{Landau|see {package options}}
+\index{package options!Landau}
The \enquote{landau} option provides the following list of commands:
\begin{center}
@@ -610,6 +636,8 @@ The \enquote{landau} option provides the following list of commands:
\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}
@@ -671,6 +699,8 @@ This yields
\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}
@@ -691,6 +721,7 @@ In addation the following commands are provided
\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$ \\
@@ -698,15 +729,18 @@ In addation the following commands are provided
\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$\indcpa$ & IND-CCA security for encryption schemes & $\indcca$ \\
-\lstinline$\indcpai$ & IND-CCA1 security for encryption schemes & $\indccai$ \\
-\lstinline$\indcpaii$ & IND-CCA2 security for encryption schemes & $\indccaii$ \\
+\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$ \\
@@ -724,6 +758,8 @@ The style in which notions are displayed can be controlled via redefining
\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}
@@ -741,6 +777,9 @@ The \enquote{logic} option provides the following list of commands:
% 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}
@@ -765,6 +804,9 @@ The style in which these are displayed can be controlled via redefining
% 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}
@@ -787,6 +829,9 @@ The style in which these are displayed can be controlled via redefining
\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:
@@ -824,6 +869,8 @@ The style in which these are displayed can be controlled via redefining
\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
@@ -840,6 +887,8 @@ where the second is meant as the negation. These are typset as
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}
@@ -864,6 +913,8 @@ The style in which these are displayed can be controlled via redefining
\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}
@@ -871,8 +922,8 @@ The \enquote{asymptotics} option provides the following list of commands:
\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$ \\
+\lstinline$\pp$ & some polynomial $\pp$ & $\pp$ \\
+\lstinline$\qq$ & some polynomial $\qq$ & $\qq$ \\
\end{tabular}
\end{center}
@@ -882,13 +933,15 @@ The style in which these are displayed can be controlled via redefining
\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 & $\npol$ \\
+\lstinline$\pk$ &public key & $\pk$ \\
\lstinline$\vk$ & verification key& $\vk$ \\
\lstinline$\sk$ & secret key& $\sk$ \\
\lstinline$\key$ & a plain key& $\key$ \\
@@ -910,6 +963,7 @@ The style in which these are displayed can be controlled via redefining
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} in order to write simple cryptostyle algorithms.
Consider the following definition of an IND-CPA game
@@ -951,6 +1005,24 @@ Code
\subsection{Customizing Pseudocode}
+\index{lnstart}
+\index{head}
+\index{lnstartright}
+\index{linenumbering}
+\index{syntaxhighlight}
+\index{keywords}
+\index{keywordsindent}
+\index{keywordsunindent}
+\index{keywordsuninindent}
+\index{addkeywords}
+\index{altkeywords}
+\index{mode}
+\index{space}
+\index{xshift}
+\index{colsep}
+\index{addtolength}
+\index{nodraft}
+
Besides the mandatory argument the \lstinline{\pseudocode} command can take an optional argument which consists of a list of key=value pairs
separated by commas (,).
\begin{lstlisting}
@@ -972,13 +1044,33 @@ Enables line numbering.
When set to \enquote{auto} cryptocode will attempt to automatically hightlight keywords such as \enquote{for}, \enquote{foreach}
and \enquote{return}
\item[keywords]
-Provide a comma separated list of keywords for automatic syntax highlighting.
+Provide a comma separated list of keywords for automatic syntax highlighting. To customize the behavior of automatic spacing
+you can provide keywords as
+\begin{description}
+\item[keywordsindent]
+After seeing this keyword all following lines will be indented one extra level.
+\item[keywordsunindent]
+After seeing this keyword the current and all following lines will be unindented one extra level.
+\item[keywordsuninindent]
+After seeing this keyword the current line will be unindented one level.
+\end{description}
\item[addkeywords]
Provide additional keywords for automatic syntax highlighting.
+\item[altkeywords]
+Provide a second list of keywords for automatic syntax highlighting that are highlighted differently.
\item[mode]
When set to text pseudocode will not start in math mode but in text mode.
+\item[space]
+Allows you to enable automatic spacing mode. If set to \enquote{keep} the spaces in the input are preserved.
+If set to \enquote{auto} it will try to detect spacing according to keywords such as \enquote{if} and \enquote{fi}.
\item[xshift]
Allows horizontal shifting
+\item[colsep]
+Defines the space between columns.
+\item[addtolength]
+Is added to the automatically computed width of the pseudocode (which does not take colsep into account).
+\item[nodraft]
+Forces syntax highlighting also in draft mode.
\end{description}
The following code
\begin{lstlisting}
@@ -989,12 +1081,56 @@ creates
\fbox{\pseudocode[linenumbering,syntaxhighlight=auto,head=Header]{ return null }}
\end{center}
+\subsection{Customized Pseudocode Commands}
+\index{\textbackslash procedure}
+\index{\textbackslash createpseudocodecommand}
+\index{\textbackslash createprocedurecommand}
+
+Besides the \lstinline{\pseudocode} command the command \lstinline{\procedure}
+provides easy access to generate code with a header. It takes the following form
+\begin{lstlisting}
+\procedure[options]{Header}{Body}
+\end{lstlisting}
+
+\subsubsection{Examples}
+\begin{center}
+\fbox{%
+\procedure{$\indcpa_\enc^\adv$}{%
+ 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}
+\procedure{$\indcpa_\enc^\adv$}{%
+ 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{lstlisting}
+
+You can define customized pseudocode commands with either take one optional argument and two mandatory arguments (as the procedure command)
+or one optional and one mandatory argument (as the pseudocode command). The following
+\begin{lstlisting}
+\createprocedurecommand{mypseudocode}{}{}{linenumbering}
+\createpseudocodecommand{myheadlesscmd}{}{}{linenumbering}
+\end{lstlisting}
+creates the commands \lstinline$\mypseudocode$ and \lstinline$\myheadlesscmd$ with line numbering always enabled. The first command
+has an identical interface as the \lstinline$\pseudocode$ command, the second has an interface as the \lstinline$\procedure$ command.
+The second and third argument that we kept empty when generating the commands allows us to specify commands that are executed at the
+very beginning when the command is called (argument 2) and a prefix for the header.
-\subsection{Indentation}
+\section{Indentation}
\index{indentation}
-\index{pcind}
-\index{t}
+\index{\textbackslash pcind}
+\index{\textbackslash t}
In order to indent code use \lstinline$\pcind$ or short \lstinline$\t$. You can also usecustomized spacing such as \lstinline$\quad$ or \lstinline$\hspace$
when using the pseudocode command in math mode.
@@ -1040,13 +1176,94 @@ You can specify multiple levels via the optional first argument
\pcind[5] T[i] \sample \bin^n }
\end{lstlisting}
-\index{pcindentname}
+\index{\textbackslash pcindentname}
You can customize the indentation shortcut by redefining
\begin{lstlisting}
\renewcommand{\pcindentname}{t}
\end{lstlisting}
+
+\subsubsection{Automatic Indentation}
+The pseudocode command comes with an option \enquote{space=auto} which tries to detect the correct indentation from the use of
+keywords. When it sees one of the following keywords
+\begin{lstlisting}
+\pcif, \pcfor, \pcwhile, \pcrepeat, \pcforeach
+\end{lstlisting}
+it will increase the indentation starting from the next line. It will again remove the indentation on seeing
+\begin{lstlisting}
+\pcfi, \pcendif, \pcendfor, \pcendwhile, \pcuntil, \pcendforeach
+\end{lstlisting}
+Additionally, on seeing
+\begin{lstlisting}
+\pcelse, \pcelseif
+\end{lstlisting}
+it will remove the indentation for that particular line. Thus the following
+\begin{center}
+\fbox{\pseudocode[space=auto]{%
+\pcfor a \in [10] \pcdo \\
+ \pcfor a \in [10] \pcdo \\
+ \pcfor a \in [10] \pcdo \\
+ \pcif a = b \pcthen \\
+ \text{some operation} \\
+ \pcelseif a = c \pcthen \\
+ \text{some operation} \\
+ \pcelse \\
+ \text{some default operation} \\
+ \pcfi \\
+ \pcendfor \\
+ \pcendfor \\
+\pcendfor \\
+\pcreturn a}}
+\end{center}
+can be obtained by:
+\begin{lstlisting}
+\pseudocode[space=auto]{%
+\pcfor a \in [10] \pcdo \\
+ \pcfor a \in [10] \pcdo \\
+ \pcfor a \in [10] \pcdo \\
+ \pcif a = b \pcthen \\
+ \text{some operation} \\
+ \pcelseif a = c \pcthen \\
+ \text{some operation} \\
+ \pcelse \\
+ \text{some default operation} \\
+ \pcfi \\
+ \pcendfor \\
+ \pcendfor \\
+\pcendfor \\
+\pcreturn a}
+\end{lstlisting}
+Note that the manual indentation in the above example is not necessary for the outcome. Further note that the same
+works when using automatic syntax highlighting (see Section~\ref{sec:syntaxhighlight}).
+
+\subsubsection{Keep Input Indentation}
+\label{sec:keepindent}
+The pseudocode package comes with an experimental feature that preserves the spacing in the input. This can be enabled with
+the option \enquote{space=keep}. Thus the above can also be written as
+\begin{center}
+\pseudocode[space=keep]{%
+\pcfor i = 1..10 \pcdo \\
+ T[i] \sample \bin^n \\
+ T[i] \sample \bin^n \\
+ T[i] \sample \bin^n \\
+ T[i] \sample \bin^n \\
+ T[i] \sample \bin^n }
+\end{center}
+\begin{lstlisting}
+\pseudocode[space=keep]{%
+\pcfor i = 1..10 \pcdo \\
+ T[i] \sample \bin^n \\
+ T[i] \sample \bin^n \\
+ T[i] \sample \bin^n \\
+ T[i] \sample \bin^n \\
+ T[i] \sample \bin^n }
+\end{lstlisting}
+Note that automatic spacing only works when the \lstinline$\pseudocode$ command is not wrapped within another command.
+Thus in order to get a frame box \lstinline$\fbox{\pseudocode[space=keep]{code}}$ will not work but you would need to use
+an environment such as one offered by the \emph{mdframed} package ((\url{https://www.ctan.org/pkg/mdframed}). Also see
+Section~\ref{sec:keepindent-problem}.
+
-\subsection{Textmode}
+\section{Textmode}
\index{text mode}
By default pseudocode enables \LaTeX' math mode. You can change this behavior and tell the pseudocode command to interpret the content
@@ -1062,26 +1279,32 @@ This is \\
\t simply text}
\end{lstlisting}
-\subsection{Syntax Highlighting}
-
-\index{pccontinue}
-\index{pccomment}
-\index{pcdo}
-\index{pcdone}
-\index{pcelse}
-\index{pcfi}
-\index{pcforeach}
-\index{pcglobvar}
-\index{pcif}
-\index{pcin}
-\index{pcnew}
-\index{pcnull}
-\index{pcparse}
-\index{pcrepeat}
-\index{pcreturn}
-\index{pcthen}
-\index{pctrue}
-\index{pcwhile}
+\section{Syntax Highlighting}
+\label{sec:syntaxhighlight}
+
+\index{\textbackslash pccontinue}
+\index{\textbackslash pccomment}
+\index{\textbackslash pcdo}
+\index{\textbackslash pcdone}
+\index{\textbackslash pcelse}
+\index{\textbackslash pcelseif}
+\index{\textbackslash pcfi}
+\index{\textbackslash pcendif}
+\index{\textbackslash pcforeach}
+\index{\textbackslash pcendforeach}
+\index{\textbackslash pcglobvar}
+\index{\textbackslash pcif}
+\index{\textbackslash pcin}
+\index{\textbackslash pcnew}
+\index{\textbackslash pcnull}
+\index{\textbackslash pcparse}
+\index{\textbackslash pcrepeat}
+\index{\textbackslash pcuntil}
+\index{\textbackslash pcreturn}
+\index{\textbackslash pcthen}
+\index{\textbackslash pctrue}
+\index{\textbackslash pcwhile}
+\index{\textbackslash pcendwhile}
In the above examples we have used commands \lstinline$\pcreturn$ and \lstinline$\pcfor$ to highlight certain keywords.
@@ -1096,12 +1319,16 @@ examples the package defines the following set of constants:
pcdo & \lstinline$\pcdo$ & \pcdo \\
pcdone & \lstinline$\pcdone$ & \pcdone \\
pcfalse & \lstinline$\pcfalse$ & \pcfalse \\
- pcelse & \lstinline$\pcelse$ & \pcelse \\
+ pcif & \lstinline$\pcif$ & \pcif \\
pcfi & \lstinline$\pcfi$ & \pcfi \\
+ pcendif & \lstinline$\pcendif$ & \pcendif \\
+ pcelse & \lstinline$\pcelse$ & \pcelse \\
+ pcelseif & \lstinline$\pcelseif$ & \pcelseif \\
pcfor & \lstinline$\pcfor$ & \pcfor \\
+ pcendfor & \lstinline$\pcendfor$ & \pcendfor \\
pcforeach & \lstinline$\pcforeach$ & \pcforeach \\
+ pcendforeach & \lstinline$\pcendforeach$ & \pcendforeach \\
pcglobvar & \lstinline$\pcglobvar$ & \pcglobvar \\
- pcif & \lstinline$\pcif$ & \pcif \\
pcin & \lstinline$\pcin$ & \pcin \\
pcnew & \lstinline$\pcnew$ & \pcnew \\
pcnull & \lstinline$\pcnull$ & \pcnull \\
@@ -1111,7 +1338,8 @@ examples the package defines the following set of constants:
pcreturn & \lstinline$\pcreturn$ & \pcreturn \\
pcthen & \lstinline$\pcthen$ & \pcthen \\
pctrue & \lstinline$\pctrue$ & \pctrue \\
- pcwhile & \lstinline$\pcwhile$ & \pcwhile
+ pcwhile & \lstinline$\pcwhile$ & \pcwhile \\
+ pcendwhile & \lstinline$\pcendwhile$ & \pcendwhile \\
\end{tabular}
\end{center}
Note that \lstinline{\pcdo}, \lstinline{\pcin} and \lstinline{\pcthen} have a leading space. This is due to their usual usage scenarios
@@ -1127,10 +1355,12 @@ Furthermore all constants have a trailing space. This can be removed by adding t
\pseudocode{\pcfor i \pcin[] \{1,\ldots,10\}}
\end{lstlisting}
-\index{pseudocodeconstant}
-In order to change the font you can overwrite the command \lstinline{\pseudocodeconstant} which is defined as
+\index{highlight keywords}
+\index{emphasize|see highlight keywords}
+\index{\textbackslash highlightkeyword}
+In order to change the font you can overwrite the command \lstinline{\highlightkeyword} which is defined as
\begin{lstlisting}
-\newcommand{\pseudocodeconstant}[2][\ ]{\ensuremath{\mathbf{#2}}#1}
+\newcommand{\highlightkeyword}[2][\ ]{\ensuremath{\mathbf{#2}}#1}
\end{lstlisting}
\subsubsection{Automatic Syntax Highlighting}
@@ -1171,128 +1401,126 @@ can be typeset as
until \neg s }
\end{lstlisting}
-You can also define additional keywords using the \enquote{addkeywords} option. This would allow ous to specify length and swap in the above example.
-We can also overwrite how a single keyword is set by defining the command \lstinline$dohighlightKEYWORD$. Thus to set swap and length in \lstinline$\mathsf$
-we could define
-\begin{lstlisting}
-\newcommand{\dohighlightswap}[1]{\mathsf{#1}}
-\newcommand{\dohighlightlengt}[1]{\mathsf{#1}}
-\end{lstlisting}
-and then
-\begin{lstlisting}
-\procedure[syntaxhighlight=auto,addkeywords={swap,length}]{Bubblesort(A : list of items)}{
- n \gets length(A) \\
- repeat \\
- \t s \gets false \\
- \t for i = 1 to n-1 do \\
- \t\t \pccomment{if this pair is out of order} \\
- \t\t if A[i-1] > A[i] then \\
- \t\t\t \pccomment{swap them and remember something changed} \\
- \t\t\t swap( A[i-1], A[i] ) \\
- \t\t\t s \gets true \\
- until \neg s }
-\end{lstlisting}
-
-\subsection{Predefined Headings}
-\index{procedure}
-\index{mainprocedure}
-\index{circuit}
-\index{program}
-
-Besides the \lstinline{\pseudocode} command the commands \lstinline{\procedure}, \lstinline{\mainprocedure}, \lstinline{\circuit} and \lstinline{\program}
-provide easy access to generate code with common headers. They all take two mandatory arguments and an optional argument.
-\begin{lstlisting}
-\procedure[options]{Header}{Body}
-\end{lstlisting}
-
-\subsubsection{Examples}
-\begin{center}
-\fbox{%
-\procedure{$\indcpa_\enc^\adv$}{%
- 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}
-\procedure{$\indcpa_\enc^\adv$}{%
- 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{lstlisting}
-
-And the same with \lstinline{\mainprocedure}, \lstinline{\circuit}, \lstinline{\program} and \lstinline{\algorithm}:
-
-\begin{center}
-\begin{pcvstack}
-\begin{pchstack}
-\mainprocedure{$\indcpa_\enc^\adv$}{%
- 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' }
-\hspace{2cm}
-\circuit{$\indcpa_\enc^\adv$}{%
- 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{pchstack}
-
-\vspace{0.5cm}
-
-\begin{pchstack}
-\program{$\indcpa_\enc^\adv$}{%
- 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' }
-\hspace{2cm}
-\algorithm{$\indcpa_\enc^\adv$}{%
- 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{pchstack}
-\end{pcvstack}
-\end{center}
-
-
-The prefixes (Main, Circ, etc.) can be controlled via the commands:
-
-\begin{center}
-\begin{tabular}{ll}
-\textbf{Command} & \textbf{Default} \\
-\lstinline$\pcmainname$ & \lstinline$\textsc{Main }$ \\
-\lstinline$\pcalgorithmname$ & \lstinline$\textsc{Algo. }$\\
-\lstinline$\pccircuitname$ & \lstinline$\textsc{Circ. }$\\
-\lstinline$\pcprogramname$ & \lstinline$\textsc{Prog. }$\\
-\lstinline$\pcprotocolname$ & \lstinline$\textsc{Protocol }$
-\end{tabular}
-\end{center}
+\index{addkeywords}
+You can also define additional keywords using the \enquote{addkeywords} option. This would allow us to specify \enquote{length} and \enquote{swap} in the above example. Combined with automatic spacing we could thus get
+\begin{center}
+\procedure[space=keep,syntaxhighlight=auto,addkeywords={swap,length}]{Bubblesort(A : list of items)}{
+n \gets length(A) \\
+repeat \\
+ s \gets false \\
+ for i=1 to n-1 do \\
+ \pccomment{if this pair is out of order} \\
+ if A[i-1]>A[i] then \\
+ \pccomment{swap them and remember something changed} \\
+ swap(A[i-1], A[i]) \\
+ s \gets true \\
+until \neg{}s }
+\end{center}
+Simply by writing (note the \lstinline$\neg{}$ in order to not have a space before $s$):
+\begin{lstlisting}
+\procedure[space=keep,syntaxhighlight=auto,addkeywords={swap,length}]{Bubblesort(A : list of items)}{
+n \gets length(A) \\
+repeat \\
+ s \gets false \\
+ for i=1 to n-1 do \\
+ \pccomment{if this pair is out of order} \\
+ if A[i-1]>A[i] then \\
+ \pccomment{swap them and remember something changed} \\
+ swap(A[i-1], A[i]) \\
+ s \gets true \\
+until \neg{}s }
+\end{lstlisting}
+Also note that a simple \lstinline$\fbox$ around the above \lstinline$\procedure$ command has the effect that the automatic spacing fails.
+For this also see Section~\ref{sec:keepindent-problem}. As an alternative we could use automatic spacing and insert \enquote{group end}
+keywords such as \enquote{fi}:
+\begin{center}
+\fbox{\procedure[space=auto,syntaxhighlight=auto,addkeywords={swap,length}]{Bubblesort(A : list of items)}{
+n \gets length(A) \\
+repeat \\
+ s \gets false \\
+ for i=1 to n-1 do \\
+ \pccomment{assuming this pair is out of order} \\
+ if A[i-1]>A[i] then \\
+ \pccomment{swap them and remember something changed} \\
+ swap(A[i-1], A[i]) \\
+ s \gets true \\
+ endif \\
+ endfor \\
+until \neg s }}
+\end{center}
+The last example is generated as (note that here fbox is fine.)
+\begin{lstlisting}
+\fbox{\procedure[space=auto,syntaxhighlight=auto,addkeywords={swap,length}]{Bubblesort(A : list of items)}{
+n \gets length(A) \\
+repeat \\
+ s \gets false \\
+ for i=1 to n-1 do \\
+ \pccomment{assuming this pair is out of order} \\
+ if A[i-1]>A[i] then \\
+ \pccomment{swap them and remember something changed} \\
+ swap(A[i-1], A[i]) \\
+ s \gets true \\
+ endif \\
+ endfor \\
+until \neg s }}
+\end{lstlisting}
+
+\subsection{Alternative Keywords}
+\index{altkeywords}
+There is a second keyword list that you can add keywords to which are highlighted not via \lstinline$\highlightkeyword$ but via \lstinline$\highlightaltkeyword$
+where alt stands for alternate. This allows you to have two different keyword styles which are by default defined as
+\begin{lstlisting}
+\newcommand{\highlightkeyword}[2][\ ]{\ensuremath{\mathbf{#2}}#1}
+\newcommand{\highlightaltkeyword}[1]{\ensuremath{\mathsf{#1}}}
+\end{lstlisting}
+This allows you to rewrite the above example and highlight the different nature of swap and length.
+\begin{center}
+\fbox{\procedure[space=auto,syntaxhighlight=auto,altkeywords={swap,length}]{Bubblesort(A : list of items)}{
+n \gets length(A) \\
+repeat \\
+ s \gets false \\
+ for i=1 to n-1 do \\
+ \pccomment{assuming this pair is out of order} \\
+ if A[i-1]>A[i] then \\
+ \pccomment{swap them and remember something changed} \\
+ swap(A[i-1], A[i]) \\
+ s \gets true \\
+ endif \\
+ endfor \\
+until \neg s }}
+\end{center}
+\begin{lstlisting}
+\procedure[space=auto,syntaxhighlight=auto,addkeywords={swap,length}]{Bubblesort(A : list of items)}{
+n \gets length(A) \\
+repeat \\
+ s \gets false \\
+ for i=1 to n-1 do \\
+ \pccomment{assuming this pair is out of order} \\
+ if A[i-1]>A[i] then \\
+ \pccomment{swap them and remember something changed} \\
+ swap(A[i-1], A[i]) \\
+ s \gets true \\
+ endif \\
+ endfor \\
+until \neg s }
+\end{lstlisting}
+
+\subsection{Draft Mode}
+\index{nodraft}
+\index{performance}
+\index{draft mode}
+Automatic syntax highlighting is a somewhat expensive operation as it requires several rounds of regular expression matching.
+In order to speed up compilation the pseudocode command will not attempt automatic highlighting when the document is in draft mode.
+When in draft mode and you want to force a specific instance of \lstinline$\pseudocode$ to render the code with automatic syntax
+highlighting you can use the option \lstinline$nodraft$.
\section{Line Numbering}
\index{line numbering}
-\index{pcln}
-\index{pclnr}
-\index{pcrln}
-The pseudocode command allows to insert line numbers into pseudocode. You can either manually control linenumbering or simply turn on the option
+\index{\textbackslash pcln}
+\index{\textbackslash pclnr}
+\index{\textbackslash pcrln}
+The pseudocode command allows to insert line numbers into pseudocode. You can either manually control line numbering or simply turn on the option
\enquote{linenumbering}.
\begin{center}
\fbox{%
@@ -1317,7 +1545,7 @@ is generated by
\end{lstlisting}
Note how you can use labels such as \lstinline$\label{tmp:line:label}$ which now points to \ref{tmp:line:label}.
-\subsection{Manually Inserting Linenumbers}
+\subsection{Manually Inserting Line Numbers}
In order to manually insert line numbers use the command \lstinline$\pcln$.
\begin{center}
\fbox{%
@@ -1362,7 +1590,7 @@ You can specify the start value (-1) of the counter by setting the option \enquo
\end{center}
\subsection{Separators}
-\index{pclnseparator}
+\index{\textbackslash pclnseparator}
The commands \lstinline$\pclnseparator$ defines the separator between the pseudocode and the line numbering. By
default the left separator is set to (:) colon. Also see Section~\ref{sec:protocol:separator}.
@@ -1439,7 +1667,7 @@ by the subprocedure. For more control, either use manual numbering or set the op
\section{Stacking Procedures}
-You can stack procedures horizontally or vertically using the environments ``pchstack'' and ``pcvstack''.
+You can stack procedures horizontally or vertically using the environments \enquote{pchstack} and \enquote{pcvstack}.
\begin{lstlisting}
\begin{pchstack}[center] body \end{pchstack}
\begin{pcvstack}[center] body \end{pcvstack}
@@ -1617,7 +1845,7 @@ Horizontal and vertical stacking can be combined
\section{Divisions and Linebreaks}
\index{linebreaks}
-\index{hline}
+\index{\textbackslash hline}
Within the pseudocode command you generate linebreaks as $\\$. In order to specify the linewidth you can add an optional argument
\begin{lstlisting}
\\[height]
@@ -1650,7 +1878,7 @@ Furthermore, you can add, for example a horizontal line by using the second opti
\end{lstlisting}
-\section{Fancy Code}
+\section{Fancy Code with Overlays}
Consider the \indcpa\ game. Here we have a single adversary $\adv$ that is called twice, first to output two messages then
given the ciphertext of one of the messages to \enquote{guess} which one was encrypted. Often this is not visualized.
@@ -1771,68 +1999,17 @@ As an exmaple of what you can do with this, let us put an explanation to a line
\end{center}
\end{lstlisting}
-Using the \emph{ocgx} package (\url{https://www.ctan.org/pkg/ocgx}) we could even make the
-$\kgen$ command clickable:
-
-\begin{center}
-\begin{pcimage}
-\procedure{$\indcpa_\enc^\adv$}{%
- \pcln b \sample \bin \\
- \pcln (\pk,\sk) \sample \switchocg{kgen}{\kgen (\secparam)}\pcnode{kgen} \\
- \pcln (m_0,m_1) \sample \adv(\secparam, \pk, c) \\
- \pcln c \sample \enc(\pk,m_b) \\
- \pcln b' \sample \adv(\secparam, \pk, c, \state) \\
- \pcln \pcreturn b = b' }
-
-\pcdraw{
- \begin{scope}[ocg={ref=kgen,status=invisible,name=Key Generation Explanation}]
- \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{scope}
-}
-\end{pcimage}
-\end{center}
-
-(Click on $\kgen$ to see the magic.)
-
-\begin{lstlisting}
-\begin{center}
-\begin{pcimage}
-\procedure{$\indcpa_\enc^\adv$}{%
- \pcln b \sample \bin \\
- \pcln (\pk,\sk) \sample \switchocg{kgen}{\kgen (\secparam)}\pcnode{kgen} \\
- \pcln (m_0,m_1) \sample \adv(\secparam, \pk, c) \\
- \pcln c \sample \enc(\pk,m_b) \\
- \pcln b' \sample \adv(\secparam, \pk, c, \state) \\
- \pcln \pcreturn b = b' }
-
-\pcdraw{
- \begin{scope}[ocg={ref=kgen,status=invisible,name=Key Generation Explanation}]
- \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{scope}
-}
-\end{pcimage}
-\end{center}
-\end{lstlisting}
-
\chapter{Tabbing Mode}
\label{chap:tabbing}
+\index{\&}
\index{Tabbing Mode}
-\index{mintabmode}
+\index{\textbackslash $"<$}
+\index{\textbackslash $">$}
In the following chapter we discuss how to create multiple columns within a \lstinline$pseudocode$ command.
Within a \lstinline$pseudocode$ command you can switch to a new column by inserting a \lstinline$\>$.
-This is similar to using an \lstinline$align$ environment and placing a tabbing \& character. Also,
-similarly to using \lstinline$align$ you need to ensure that the number of \lstinline$\>$ are identical
+This is similar to using an \lstinline$align$ environment and placing a tabbing character (\&). Also,
+similarly to using \lstinline$align$ you should ensure that the number of \lstinline$\>$ are identical
on each line.
\begin{center}
\fbox{%
@@ -1862,6 +2039,26 @@ using \lstinline$\>\>$. You can also use \lstinline$\<$ a shorthand for \lstinli
b \sample \bin \< b \sample \bin \< b \sample \bin \< b \sample \bin}
\end{lstlisting}
+\paragraph{Column Spacing}
+\index{colsep}
+\index{addtolength}
+You can control the space between columns using the option \enquote{colsep=2em}. Note that when doing so you should
+additionally use \enquote{addtolength=5em} (where 5em depends on the number of columns) in order to avoid having
+overfull hboxes.
+\begin{center}
+\fbox{%
+\pseudocode[colsep=1em,addtolength=10em]{%
+ \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{%
+\pseudocode[colsep=1em,addtolength=10em]{%
+ \textbf{First} \< \textbf{Second} \< \textbf{Third} \< \textbf{Fourth} \\
+ b \sample \bin \< b \sample \bin \< b \sample \bin \< b \sample \bin}
+\end{lstlisting}
+
This is basically all you need to know in order to go on to writing protocols with the
cryptocode package. So unless you want to know a bit more about tabbing (switching columns)
and learn some of the internals, feel free to proceed to Chapter~\ref{chap:protocols}.
@@ -1894,7 +2091,7 @@ The next two sections are rather technical, so feel free to skip them.
\subsection{Overriding The Tabbing Character}
-\index{pctabname}
+\index{\textbackslash pctabname}
If you don't like \lstinline$\>$ as the tabbing character you can choose a custom command by overwriting \lstinline$\pctabname$.
For example
\begin{lstlisting}
@@ -1908,11 +2105,11 @@ For example
\end{lstlisting}
\subsection{Custom Line Spacing and Horizontal Rules}
-\index{pclb}
+\index{\textbackslash pclb}
As explained underlying the pseudocode command is an flalign environment. This would allow the use
of \lstinline$\\[spacing]$ to specifiy the spacing between two lines or of \lstinline$[\\\hline]$
to insert a horizontal rule. In order to achieve the same effect within the pseudocode command you
-can use \lstinline$\\{[spacing][\hline]}$. You can also use \lstinline$\pclb$ to get a line break which
+can use \lstinline$\\[spacing][\hline]$. You can also use \lstinline$\pclb$ to get a line break which
does not insert the additional alignment characters.
\chapter{Protocols}
@@ -1921,7 +2118,7 @@ does not insert the additional alignment characters.
The pseudocode package can also be used to write protocols such as
\begin{center}
\fbox{%
-\protocol{My Protocol}{%
+\procedure{My Protocol}{%
\textbf{Alice} \> \> \textbf{Bob} \\
b \sample \bin \> \> \\
\> \xrightarrow{\text{send over } b} \> \\
@@ -1932,7 +2129,7 @@ The pseudocode package can also be used to write protocols such as
\end{center}
which uses the tabbing feature of align and is generated as
\begin{lstlisting}
-\protocol{My Protocol}{%
+\procedure{My Protocol}{%
\textbf{Alice} \> \> \textbf{Bob} \\
b \sample \bin \> \> \\
\> \xrightarrow{\text{send over } b} \> \\
@@ -1941,6 +2138,11 @@ which uses the tabbing feature of align and is generated as
\text{finalize} \> \>}
}
\end{lstlisting}
+
+\index{\textbackslash sendmessageright*}
+\index{\textbackslash sendmessageright}
+\index{\textbackslash sendmessageleft*}
+\index{\textbackslash sendmessageleft}
In order to get nicer message arrows use the commands \lstinline$\sendmessageright*{message}$ and \lstinline$\sendmessageleft*{message}$.
Both take an additional optional argument specifying the length of the arrow and both are run
in math mode.
@@ -1952,7 +2154,7 @@ in math mode.
\begin{center}
\fbox{%
-\protocol{My Protocol}{%
+\procedure{My Protocol}{%
\textbf{Alice} \> \> \textbf{Bob} \\
b \sample \bin \> \> \\
\> \sendmessageright*{\text{send over } b} \> \\
@@ -1962,7 +2164,7 @@ in math mode.
}
\end{center}
\begin{lstlisting}
-\protocol{My Protocol}{%
+\procedure{My Protocol}{%
\textbf{Alice} \> \> \textbf{Bob} \\
b \sample \bin \> \> \\
\> \sendmessageright*{\text{send over } b} \> \\
@@ -1974,7 +2176,7 @@ in math mode.
Besides the starred version there is also the unstarred version which allows more flexibility. Note that a crucial difference between
the starred and unstarred versions are that \lstinline$\sendmessageleft*{message}$ wraps an aligned environment around the message.
\begin{center}
-\protocol{My Protocol}{%
+\procedure{My Protocol}{%
\textbf{Alice} \> \> \textbf{Bob} \\
b \sample \bin \> \> \\
\> \sendmessageright{centercol=3,top=send over $b$,bottom=Text below,topstyle={draw,solid,yshift=0.25cm},style={dashed}} \> \\
@@ -1983,7 +2185,7 @@ the starred and unstarred versions are that \lstinline$\sendmessageleft*{messag
\text{finalize} \> \> }
\end{center}
\begin{lstlisting}
-\protocol{My Protocol}{%
+\procedure{My Protocol}{%
\textbf{Alice} \> \> \textbf{Bob} \\
b \sample \bin \> \> \\
\> \sendmessageright{centercol=3,top=send over $b$,bottom=Text below,topstyle={draw,solid,yshift=0.25cm},style={dashed}} \> \\
@@ -2030,7 +2232,7 @@ For this you can use \lstinline$\<$ instead of \lstinline$\>$ (see Chapter~\ref{
Following is once more the example from before but now with double tapping.
\begin{center}
\fbox{%
-\protocol{My Protocol}{%
+\procedure{My Protocol}{%
\textbf{Alice} \< \< \textbf{Bob} \\
b \sample \bin \< \< \\
\< \sendmessageright*{\text{send over } b} \< \\
@@ -2045,7 +2247,7 @@ Using the send message commands you can easily generate multiline messages as th
wraps an \emph{aligned} environment around the message.
\begin{center}
\fbox{%
-\protocol{My Protocol}{%
+\procedure{My Protocol}{%
\textbf{Alice} \< \< \textbf{Bob} \\
b \sample \bin \< \< \\
\< \sendmessageright*{\text{send over } b\\ \text{second line}} \< \\
@@ -2055,7 +2257,7 @@ wraps an \emph{aligned} environment around the message.
}
\end{center}
\begin{lstlisting}
-\protocol{My Protocol}{%
+\procedure{My Protocol}{%
\textbf{Alice} \< \< \textbf{Bob} \\
b \sample \bin \< \< \\
\< \sendmessageright*{\text{send over } b\\ \text{second line}} \< \\
@@ -2076,7 +2278,7 @@ You are not limited to two players. In order to send messages skipping players u
\begin{center}
\fbox{%
-\protocol{Multiparty Protocol}{%
+\procedure{Multiparty Protocol}{%
\textbf{Alice} \< \< \textbf{Bob} \< \< \textbf{Charlie} \\
\text{work} \< \< \< \< \\
\< \sendmessageright{top=Work result} \< \< \< \\
@@ -2090,7 +2292,7 @@ You are not limited to two players. In order to send messages skipping players u
\begin{lstlisting}
\begin{center}
-\protocol{Multiparty Protocol}{%
+\procedure{Multiparty Protocol}{%
\textbf{Alice} \< \< \textbf{Bob} \< \< \textbf{Charlie} \\
\text{work} \< \< \< \< \\
\< \sendmessageright{top=Work result} \< \< \< \\
@@ -2115,7 +2317,7 @@ before. Also see Chapter~\ref{chap:tabbing}.
\begin{center}
\fbox{%
-\protocol{My Protocol}{%
+\procedure{My Protocol}{%
\textbf{Alice} \< \< \textbf{Bob} \\
b \sample \bin \< \< \pclb
\pcintertext[dotted]{Some Division} \\
@@ -2128,7 +2330,7 @@ before. Also see Chapter~\ref{chap:tabbing}.
\end{center}
\begin{lstlisting}
-\protocol{My Protocol}{%
+\procedure{My Protocol}{%
\textbf{Alice} \< \< \textbf{Bob} \\
b \sample \bin \< \< \pclb
\pcintertext[dotted]{Some Division} \\
@@ -2147,7 +2349,7 @@ allows you to right align line numbers but uses the same counter as \lstinline$\
\begin{center}
\fbox{%
-\protocol{My Protocol}{%
+\procedure{My Protocol}{%
\pcln \textbf{Alice} \< \< \textbf{Bob} \< \\
\pcln b \sample \bin \< \< \< \\
\< \sendmessageright*{\text{send over } b} \< \< \pclnr\\
@@ -2158,7 +2360,7 @@ allows you to right align line numbers but uses the same counter as \lstinline$\
\end{center}
Which is generated as
\begin{lstlisting}
-\protocol{My Protocol}{%
+\procedure{My Protocol}{%
\pcln \textbf{Alice} \< \< \textbf{Bob} \< \\
\pcln b \sample \bin \< \< \< \\
\< \sendmessageright*{\text{send over } b} \< \< \pclnr\\
@@ -2172,7 +2374,7 @@ Which is generated as
And using \lstinline$\pcrln$:
\begin{center}
\fbox{%
-\protocol{My Protocol}{%
+\procedure{My Protocol}{%
\pcln \textbf{Alice} \< \< \textbf{Bob} \< \\
\pcln b \sample \bin \< \< \< \\
\< \sendmessageright*{\text{send over } b} \<\< \pcrln\\
@@ -2183,7 +2385,7 @@ And using \lstinline$\pcrln$:
\end{center}
Which is generated as
\begin{lstlisting}
-\protocol{My Protocol}{%
+\procedure{My Protocol}{%
\pcln \textbf{Alice} \< \< \textbf{Bob} \\
\pcln b \sample \bin \< \< \\
\< \sendmessageright*{\text{send over } b} \< \pcrln\\
@@ -2206,12 +2408,12 @@ Use the \enquote{subprocedure} function also to create sub protocols.
\begin{center}
\fbox{%
-\protocol{My Protocol}{%
+\procedure{My Protocol}{%
\textbf{Alice} \< \< \textbf{Bob} \\
b \sample \bin \< \< \\
\< \sendmessageright*{\text{send over } b} \< \\
\< \< \text{do something} \\
- \<\< \dbox{\begin{subprocedure}\pseudocode{
+ \<\< \dbox{\begin{subprocedure}\procedure{Subprotocol}{
\< \< \textbf{Charlie} \\
\text{something more} \< \< \\
\< \sendmessageright*[1.5cm]{\text{message}} \< \\
@@ -2227,13 +2429,13 @@ Use the \enquote{subprocedure} function also to create sub protocols.
\end{center}
- \begin{lstlisting}
-\protocol{My Protocol}{%
+\begin{lstlisting}
+\procedure{My Protocol}{%
\textbf{Alice} \< \< \textbf{Bob} \\
b \sample \bin \< \< \\
\< \sendmessageright*{\text{send over } b} \< \\
\< \< \text{do something} \\
- \<\< \dbox{\begin{subprocedure}\pseudocode{
+ \<\< \dbox{\begin{subprocedure}\procedure{Subprotocol}{
\< \< \textbf{Charlie} \\
\text{something more} \< \< \\
\< \sendmessageright*[1.5cm]{\text{message}} \< \\
@@ -2298,7 +2500,8 @@ by using
\subsection{Highlight Changes}
-\index{gamechange}
+\index{highlight game change}
+\index{\textbackslash gamechange}
In order to highlight changes from one game to the next use \lstinline$\gamechange$.
\begin{center}
\begin{gameproof}
@@ -2326,7 +2529,7 @@ In order to highlight changes from one game to the next use \lstinline$\gamechan
\end{lstlisting}
\subsection{Boxed games}
-\index{tbxgameprocedure}
+\index{\textbackslash tbxgameprocedure}
Use \lstinline$\tbxgameprocedure$ in order to create two consecutive games where the second game is \emph{boxed}. Use
\lstinline$\pcbox$ to create boxed statements.
\begin{center}
@@ -2364,7 +2567,7 @@ Use \lstinline$\tbxgameprocedure$ in order to create two consecutive games where
\end{lstlisting}
\subsection{Reduction Hints}
-\index{addgamehop}
+\index{\textbackslash addgamehop}
In a game based proof in order to go from one game to the next we usually give a reduction, for example, we show that
the difference between two games is bound by the security of some pseudorandom generator $\mathsf{PRG}$. To give a hint
within the pseudocode that the difference between two games is down to ``something'' you can use the \lstinline$\addgamehop$
@@ -2510,8 +2713,8 @@ The default name and argument are controlled via the commands \lstinline$\pcgame
\subsection{Two Directional Games}
-\index{bxgameprocedure}
-\index{addloopgamehop}
+\index{\textbackslash bxgameprocedure}
+\index{\textbackslash addloopgamehop}
You can use the \lstinline$\bxgameprocedure$ to generate games for going in two directions. Use the \lstinline$\addloopgamehop$
to add the gamehop in the middle.
@@ -2555,8 +2758,8 @@ to add the gamehop in the middle.
\label{chap:bbr}
\index{bbrenv}
\index{bbrbox}
-\index{bbrinput}
-\index{bbroutput}
+\index{\textbackslash bbrinput}
+\index{\textbackslash bbroutput}
The cryptocode package comes with support for drawing basic black box reductions. A reduction is
always of the following form.
@@ -2652,13 +2855,15 @@ name=Box Name
\end{lstlisting}
to specify the label. The following options are available
+\begin{center}
\begin{tabular}{ll}
-Option & Description \\ \hline
+\textbf{Option} & \textbf{Description} \\ \hline
name & Specifies the box' label \\
minheight & The minimal height \\
xshift & Allows horizontal positioning \\
style & allows to customize the node
\end{tabular}
+\end{center}
\section{Nesting of Boxes}
@@ -2721,10 +2926,10 @@ existing bbrbox.
\end{lstlisting}
\section{Messages and Queries}
-\index{bbrmsgto}
-\index{bbrmsgfrom}
-\index{bbrqryto}
-\index{bbrqryfrom}
+\index{\textbackslash bbrmsgto}
+\index{\textbackslash bbrmsgfrom}
+\index{\textbackslash bbrqryto}
+\index{\textbackslash bbrqryfrom}
You can send messages and queries to boxes. For this use the commands
\begin{lstlisting}
@@ -2907,7 +3112,7 @@ Via the option \enquote{length} you can specifiy the length of the arrow.
\end{lstlisting}
\subsection{Loops}
-\index{bbrloop}
+\index{\textbackslash bbrloop}
Often an adversary may send poly many queries to an oracle, or a reduction sends many queries to an adversary.
Consider the following setting
@@ -3014,7 +3219,8 @@ to be shown on the left, center or right. Here is the result.
\end{lstlisting}
\subsection{Add Space}
-\index{bbrmsgspace}
+\index{\textbackslash bbrmsgspace}
+\index{\textbackslash bbrqryspace}
If the spacing between messages is not sufficient you can use the \lstinline$bbrmsgspace$ and
\lstinline$bbrqryspace$ commands to add additional space.
\begin{bbrenv}{A}
@@ -3075,8 +3281,8 @@ If the spacing between messages is not sufficient you can use the \lstinline$bbr
\subsection{Intertext}
-\index{bbrmsgtxt}
-\index{bbrqrytxt}
+\index{\textbackslash bbrmsgtxt}
+\index{\textbackslash bbrqrytxt}
If your reduction needs to do some extra work between queries use the \lstinline$\bbrmsgtxt$
and \lstinline$\bbrqrytxt$ commands.
@@ -3158,6 +3364,7 @@ and \lstinline$\bbrqrytxt$ commands.
\section{Oracles}
\index{bbroracle}
+\index{distance}
Each box can have one or more oracles which are drawn on the right hand side of the box. An oracle
is created similarly to a \emph{bbrenv} environment using the \emph{bbroracle} environment. Oracles
go behind the single \emph{bbrbox} environment within an \emph{bbrenv} enviornment.
@@ -3183,7 +3390,7 @@ go behind the single \emph{bbrbox} environment within an \emph{bbrenv} enviornme
\end{bbrbox}
\end{bbroracle}
- \begin{bbroracle}{OraB}
+ \begin{bbroracle}{OraB}[distance=3cm]
\begin{bbrbox}[name=Oracle 2]
\end{bbrbox}
\end{bbroracle}
@@ -3218,10 +3425,12 @@ go behind the single \emph{bbrbox} environment within an \emph{bbrenv} enviornme
\end{bbroracle}
\end{bbrenv}
\end{lstlisting}
+Via the option \enquote{distance=length} you can control the horizontal position of the oracle. By default this value is set to 1cm.
+
\subsection{Communicating with Oracles}
-\index{bbroraclequeryfrom}
-\index{bbroraclequeryto}
+\index{\textbackslash bbroraclequeryfrom}
+\index{\textbackslash bbroraclequeryto}
As oracles use the \emph{bbrbox} environment we can directly use the established ways to send messages and
queries to oracles. In addition you can use the \lstinline$\bbroraclequeryfrom$ and \lstinline$\bbroraclequeryto$.
\begin{lstlisting}
@@ -3296,16 +3505,49 @@ that oracle messages need to be added after the closing \lstinline$\end{bbroracl
\end{bbrenv}
\end{lstlisting}
-%\chapter{Known Issues}
-%
-%\section{Hyperref}
-%\label{sec:hyperref}
-%\index{pcfixhyperref}
-%Referencing line numbers breaks the hyperref package. In order to fix this call
-%\begin{lstlisting}
-%\pcfixhyperref
-%\end{lstlisting}
-%after \lstinline$\begin{document}$.
+
+\chapter{Known Issues}
+
+\section{Pseudocode KeepSpacing within Commands}
+\label{sec:keepindent-problem}
+\index{\textbackslash fbox}
+\index{framebox}
+The \enquote{space=keep} option of pseudocode which should output spacing identical to that of the input
+will fail, if the pseudocode command is called from within another command. An example is to
+wrap the \lstinline$\pseudocode$ command with an \lstinline$\fbox$. As a workaround for generating frame boxes you should hence
+use a package such as \emph{mdframed} (\url{https://www.ctan.org/pkg/mdframed}) which provides a frame environment.
+
+\begin{mdframed}
+\pseudocode[space=keep,mode=text]{ Pseudocode with - spaces -}
+\end{mdframed}
+\begin{lstlisting}
+\pseudocode[space=keep,mode=text]{ Pseudocode with - spaces -}
+\end{lstlisting}
+
+As an alternative you could use a \emph{savebox} (in combination with the \lstinline$lrbox$ environment):
+
+\newsavebox{\mypcbox}
+\begin{lrbox}{\mypcbox}%
+\pseudocode[space=keep,mode=text]{ Pseudocode with - spaces -}%
+\end{lrbox}
+\fbox{\usebox{\mypcbox}}
+
+\begin{lstlisting}
+\newsavebox{\mypcbox}
+\begin{lrbox}{\mypcbox}%
+\pseudocode[space=keep,mode=text]{ Pseudocode with - spaces -}%
+\end{lrbox}
+\fbox{\usebox{\mypcbox}}
+\end{lstlisting}
+
+\section{AMSFonts}
+\index{amsfonts}
+\index{noamsfonts|see {package options}}
+\index{package options!noamsfonts}
+Some packages are not happy with the \enquote{amsfonts} package. Cryptocode will attempt to load amsfonts if it is loaded
+with either the \enquote{sets} or the \enquote{probability} option. In order to not load amsfonts you can additionally add the
+\enquote{noamsfonts} at the very end. Note that in this case you should ensure that the command \lstinline$\mathbb$ is defined
+as this is used by most of the commands in \enquote{sets} and some of the commands in \enquote{probability}.
\printindex