diff options
Diffstat (limited to 'Master/texmf-dist/doc/latex/cryptocode/cryptocode.tex')
-rw-r--r-- | Master/texmf-dist/doc/latex/cryptocode/cryptocode.tex | 287 |
1 files changed, 213 insertions, 74 deletions
diff --git a/Master/texmf-dist/doc/latex/cryptocode/cryptocode.tex b/Master/texmf-dist/doc/latex/cryptocode/cryptocode.tex index 35c85948c70..fbbb292109f 100644 --- a/Master/texmf-dist/doc/latex/cryptocode/cryptocode.tex +++ b/Master/texmf-dist/doc/latex/cryptocode/cryptocode.tex @@ -112,12 +112,11 @@ It provides various predefined commands for different topics in cryptography. In particular it provides an easy interface to write pseudocode, protocols, game based proofs and draw black-box reductions. - \vspace{2em} \begin{center} \fbox{ \pseudocode{% -\textbf{ Alice} \< \< \textbf{ Bob} \\[0.5\baselineskip][\hline] +\textbf{ Alice} \< \< \textbf{ Bob} \\[0.1\baselineskip][\hline] \<\< \\[-0.5\baselineskip] x \sample \ZZ_q \< \< \\ X \gets g^x \<\< \\ @@ -217,6 +216,7 @@ the \lstinline$\procedure$ command which takes an additional argument to specify b' \sample \adv(\secparam, \pk, c, \state) \\ \pcreturn b = b' }} \end{center} + \begin{lstlisting} \procedure[linenumbering]{$\indcpa_\enc^\adv$}{% b \sample \bin \\ @@ -350,7 +350,7 @@ commands which simply take a message which is displayed. \begin{center} \fbox{% \pseudocode{% -\textbf{ Alice} \< \< \textbf{ Bob} \\[0.5\baselineskip][\hline] +\textbf{ Alice} \< \< \textbf{ Bob} \\[0.1\baselineskip][\hline] \<\< \\[-0.5\baselineskip] x \sample \ZZ_q \< \< \\ X \gets g^x \<\< \\ @@ -364,7 +364,7 @@ x \sample \ZZ_q \< \< \\ \end{center} \begin{lstlisting} \pseudocode{% -\textbf{ Alice} \< \< \textbf{ Bob} \\[0.5\baselineskip][\hline] +\textbf{ Alice} \< \< \textbf{ Bob} \\[0.1\baselineskip][\hline] \<\< \\[-0.5\baselineskip] x \sample \ZZ_q \< \< \\ X \gets g^x \<\< \\ @@ -457,15 +457,15 @@ by using plain TIKZ commands. \begin{bbrbox}[name=Oracle 1,minheight=1cm] \end{bbrbox} \end{bbroracle} - \bbroraclequeryto{top=$m$} - \bbroraclequeryfrom{top=$b$} + \bbroracleqryto{top=$m$} + \bbroracleqryfrom{top=$b$} \begin{bbroracle}{OraB} \begin{bbrbox}[name=Oracle 2,minheight=1cm] \end{bbrbox} \end{bbroracle} - \bbroraclequeryto{top=$m$} - \bbroraclequeryfrom{top=$b$} + \bbroracleqryto{top=$m$} + \bbroracleqryfrom{top=$b$} \end{bbrenv} \begin{lstlisting} \begin{bbrenv}{A} @@ -503,15 +503,15 @@ by using plain TIKZ commands. \begin{bbrbox}[name=Oracle 1,minheight=1cm] \end{bbrbox} \end{bbroracle} - \bbroraclequeryto{top=$m$} - \bbroraclequeryfrom{top=$b$} + \bbroracleqryto{top=$m$} + \bbroracleqryfrom{top=$b$} \begin{bbroracle}{OraB} \begin{bbrbox}[name=Oracle 2,minheight=1cm] \end{bbrbox} \end{bbroracle} - \bbroraclequeryto{top=$m$} - \bbroraclequeryfrom{top=$b$} + \bbroracleqryto{top=$m$} + \bbroracleqryfrom{top=$b$} \end{bbrenv} \end{lstlisting} We'll discuss the details in Chapter~\ref{chap:bbr}. @@ -1012,6 +1012,7 @@ Code \index{syntaxhighlight} \index{keywords} \index{keywordsindent} +\index{codesize} \index{keywordsunindent} \index{keywordsuninindent} \index{addkeywords} @@ -1022,6 +1023,9 @@ Code \index{colsep} \index{addtolength} \index{nodraft} +\index{yshift} +\index{bodylinesep} +\index{headlinesep} 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 (,). @@ -1063,8 +1067,18 @@ 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[codesize] +Allows to specify the fontsize for the pseudocode. Set to \lstinline$\scriptsize$ for a smaller size. + \item[xshift] Allows horizontal shifting +\item[yshift] +Allows horizontal shifting + +\item[headlinesep] +Specifies the distance between header and the line. +\item[bodylinesep] +Specifies the distance between body and the line. \item[colsep] Defines the space between columns. \item[addtolength] @@ -1603,7 +1617,7 @@ The pseudocode package allows the typesetting of sub procedures such as \procedure[linenumbering]{$\indcpa_\enc^\adv$}{% b \sample \bin \\ (\pk,\sk) \sample \kgen(\secparam) \\ - (m_0,m_1) \sample \begin{subprocedure}% + (m_0,m_1) \sample \begin{subprocedure}% \dbox{\procedure{$\adv(\secparam, \pk, c)$}{% \text{Step 1} \\ \text{Step 2} \\ @@ -1757,9 +1771,10 @@ use \lstinline{\pcvspace} which takes an optional length as a parameter. Horizontal and vertical stacking can be combined \begin{pchstack}[center] -\begin{pcvstack} + +\begin{pcvstack}% \procedure{$\indcpa_\enc^\adv$}{% - \pcln b \sample \bin \\ + \pcln b \sample \bin \\ \pcln (\pk,\sk) \sample \kgen(\secparam) \\ \pcln (m_0,m_1) \sample \adv^{O,H_1,H_2}(\secparam, \pk) \\ \pcln c \sample \enc(\pk,m_b) \\ @@ -1952,6 +1967,7 @@ command. We can achieve a similar effect without an additional pcimage environme \pcln \pcreturn b = b' } \end{lstlisting} +\pagebreak \subsection{Example: Explain your Code} As an exmaple of what you can do with this, let us put an explanation to a line of the code. @@ -2587,6 +2603,7 @@ A TIKZ style to be used for the path. A TIKZ style to be used for the edge. This defaults to \enquote{bend left}. \end{description} +\vspace{1ex} \begin{center} \begin{gameproof} \gameprocedure{% @@ -2806,7 +2823,7 @@ This box is generated as The commands \lstinline$bbrinput$ and \lstinline$bbroutput$ allow to specify input and output for the latest ''bbrenv´´ environment. The single argument to the bbrenv environment needs to specify a unique identifier -(unique for the current reduction). This id is used as an internal TIKZ node name (\url{http://www.ctan.org/tex-archive/graphics/pgf/}). +(unique for the current reduction). This id is used as an internal TIKZ node name (\url{https://www.ctan.org/pkg/pgf}). \begin{lstlisting} \begin{bbrenv}{UNIQUE IDENTIFIER} \end{lstlisting} @@ -2855,12 +2872,20 @@ name=Box Name \end{lstlisting} to specify the label. The following options are available +\index{namepos} +\index{namestyle} +\index{minheight} +\index{xshift} +\index{yshift} \begin{center} \begin{tabular}{ll} \textbf{Option} & \textbf{Description} \\ \hline name & Specifies the box' label \\ +namepos & Specifies the position (left, center, right, top left, top center, top right) \\ +namestyle & Specifies the style of the name \\ minheight & The minimal height \\ xshift & Allows horizontal positioning \\ +yshift & Allows horizontal positioning \\ style & allows to customize the node \end{tabular} \end{center} @@ -2869,6 +2894,7 @@ style & allows to customize the node \section{Nesting of Boxes} Boxes can be nested. For this simply insert a bbrenv (together with a single bbrbox) environment into an existing bbrbox. + \begin{bbrenv}{A} \begin{bbrbox}[name=Box Name] \pseudocode{ @@ -3027,7 +3053,7 @@ Following is a complete example. Notice that cryptocode takes care of the vertic \subsection{Options} Besides specifying labels for top, side and bottom you can further specify how cryptocode renders the message. -Remember that tnderneath the reduction commands is a TIKZ image (\url{http://www.ctan.org/tex-archive/graphics/pgf/}). +Remember that tnderneath the reduction commands is a TIKZ image (\url{https://www.ctan.org/pkg/pgf/}). For each label position (top, side, bottom) a node is generated. You can provide additional properties for this node using the options: \begin{itemize} @@ -3111,11 +3137,12 @@ Via the option \enquote{length} you can specifiy the length of the arrow. \end{bbrenv} \end{lstlisting} -\subsection{Loops} -\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 +\subsection{Add Space} +\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} \begin{bbrbox}[name=Reduction] \pseudocode{ @@ -3128,8 +3155,13 @@ Consider the following setting \end{bbrbox} - \bbrmsgto{top=$m$,sidename=BeginLoop} - \bbrmsgfrom{top=$\sigma$,sidename=EndLoop} + \bbrmsgto{top=$m$} + \bbrmsgspace{1.5cm} + \bbrmsgfrom{top=$\sigma$} + + \bbrqryto{top=$m$} + \bbrqryspace{1cm} + \bbrqryfrom{top=$\sigma$} \end{bbrenv} @@ -3152,8 +3184,13 @@ Consider the following setting \end{bbrbox} \bbrmsgto{top=$m$} + \bbrmsgspace{1.5cm} \bbrmsgfrom{top=$\sigma$} + \bbrqryto{top=$m$} + \bbrqryspace{1cm} + \bbrqryfrom{top=$\sigma$} + \end{bbrenv} \end{bbrbox} @@ -3162,14 +3199,12 @@ Consider the following setting \end{bbrenv} \end{lstlisting} -First note that by specifying the minheight and xshift option we shifted the adversary box a bit to the right -and enlarged its box. Further we specified custom names for the node on the side of the two messages. We -can now use the \lstinline$bbrloop$ command to visualize that these two messages are exchanged $q$ many times -\begin{lstlisting} -\bbrloop{BeginLoop}{EndLoop}{center=$q$} -\end{lstlisting} -The \lstinline$bbrloop$ command takes two node names and a config which allows you to specify if the label is -to be shown on the left, center or right. Here is the result. + +\subsection{Loops} +\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 + \begin{bbrenv}{A} \begin{bbrbox}[name=Reduction] \pseudocode{ @@ -3184,7 +3219,6 @@ to be shown on the left, center or right. Here is the result. \bbrmsgto{top=$m$,sidename=BeginLoop} \bbrmsgfrom{top=$\sigma$,sidename=EndLoop} - \bbrloop{BeginLoop}{EndLoop}{center=$q$} \end{bbrenv} @@ -3206,9 +3240,8 @@ to be shown on the left, center or right. Here is the result. \end{bbrbox} - \bbrmsgto{top=$m$,sidename=BeginLoop} - \bbrmsgfrom{top=$\sigma$,sidename=EndLoop} - \bbrloop{BeginLoop}{EndLoop}{center=$q$} + \bbrmsgto{top=$m$} + \bbrmsgfrom{top=$\sigma$} \end{bbrenv} @@ -3218,11 +3251,15 @@ to be shown on the left, center or right. Here is the result. \end{bbrenv} \end{lstlisting} -\subsection{Add Space} -\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. +First note that by specifying the minheight and xshift option we shifted the adversary box a bit to the right +and enlarged its box. Further we specified custom names for the node on the side of the two messages. We +can now use the \lstinline$bbrloop$ command to visualize that these two messages are exchanged $q$ many times +\begin{lstlisting} +\bbrloop{BeginLoop}{EndLoop}{center=$q$} +\end{lstlisting} +The \lstinline$bbrloop$ command takes two node names and a config which allows you to specify if the label is +to be shown on the left, center or right. Here is the result. + \begin{bbrenv}{A} \begin{bbrbox}[name=Reduction] \pseudocode{ @@ -3235,13 +3272,10 @@ If the spacing between messages is not sufficient you can use the \lstinline$bbr \end{bbrbox} - \bbrmsgto{top=$m$} - \bbrmsgspace{1.5cm} - \bbrmsgfrom{top=$\sigma$} - - \bbrqryto{top=$m$} - \bbrqryspace{1cm} - \bbrqryfrom{top=$\sigma$} + \bbrmsgto{top=$m$,sidename=BeginLoop} + \bbrmsgspace{0.5cm} + \bbrmsgfrom{top=$\sigma$,sidename=EndLoop} + \bbrloop{BeginLoop}{EndLoop}{center=$q$} \end{bbrenv} @@ -3263,13 +3297,10 @@ If the spacing between messages is not sufficient you can use the \lstinline$bbr \end{bbrbox} - \bbrmsgto{top=$m$} - \bbrmsgspace{1.5cm} - \bbrmsgfrom{top=$\sigma$} - - \bbrqryto{top=$m$} - \bbrqryspace{1cm} - \bbrqryfrom{top=$\sigma$} + \bbrmsgto{top=$m$,sidename=BeginLoop} + \bbrmsgspace{0.5cm} + \bbrmsgfrom{top=$\sigma$,sidename=EndLoop} + \bbrloop{BeginLoop}{EndLoop}{center=$q$} \end{bbrenv} @@ -3279,7 +3310,6 @@ If the spacing between messages is not sufficient you can use the \lstinline$bbr \end{bbrenv} \end{lstlisting} - \subsection{Intertext} \index{\textbackslash bbrmsgtxt} \index{\textbackslash bbrqrytxt} @@ -3364,7 +3394,8 @@ and \lstinline$\bbrqrytxt$ commands. \section{Oracles} \index{bbroracle} -\index{distance} +\index{hdistance} +\index{vdistance} 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. @@ -3390,7 +3421,7 @@ go behind the single \emph{bbrbox} environment within an \emph{bbrenv} enviornme \end{bbrbox} \end{bbroracle} - \begin{bbroracle}{OraB}[distance=3cm] + \begin{bbroracle}{OraB}[vdistance=2cm,hdistance=3cm] \begin{bbrbox}[name=Oracle 2] \end{bbrbox} \end{bbroracle} @@ -3419,23 +3450,23 @@ go behind the single \emph{bbrbox} environment within an \emph{bbrenv} enviornme \end{bbrbox} \end{bbroracle} - \begin{bbroracle}{OraB} + \begin{bbroracle}{OraB}[vdistance=2cm,hdistance=3cm] \begin{bbrbox}[name=Oracle 2] \end{bbrbox} \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. +Via the option \enquote{hdistance=length} and \enquote{vdistance=length} you can control the horizontal and vertical position of the oracle. By default this value is set to 1.5cm and \lstinline$\baselineskip$. \subsection{Communicating with Oracles} -\index{\textbackslash bbroraclequeryfrom} -\index{\textbackslash bbroraclequeryto} +\index{\textbackslash bbroracleqryfrom} +\index{\textbackslash bbroracleqryto} 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$. +queries to oracles. In addition you can use the \lstinline$\bbroracleqryfrom$ and \lstinline$\bbroracleqryto$. \begin{lstlisting} -\bbroraclequeryfrom{options} -\bbroraclequeryto{options} +\bbroracleqryfrom{options} +\bbroracleqryto{options} \end{lstlisting} Here options allow you to specify where the label goes (top, bottom). In addition you can use \lstinline$\bbroracleqryspace$ to generate extra space between oracle messages. Note @@ -3448,7 +3479,7 @@ that oracle messages need to be added after the closing \lstinline$\end{bbroracl } \begin{bbrenv}{B} - \begin{bbrbox}[name=Adversary,minheight=3cm,xshift=4cm] + \begin{bbrbox}[name=Adversary,minheight=3cm,xshift=3cm] \end{bbrbox} \end{bbrenv} @@ -3461,15 +3492,15 @@ that oracle messages need to be added after the closing \lstinline$\end{bbroracl \begin{bbrbox}[name=Oracle 1,minheight=1cm] \end{bbrbox} \end{bbroracle} - \bbroraclequeryfrom{top=$m$} - \bbroraclequeryto{top=$b$} + \bbroracleqryfrom{top=$m$} + \bbroracleqryto{top=$b$} \begin{bbroracle}{OraB} \begin{bbrbox}[name=Oracle 2,minheight=1cm] \end{bbrbox} \end{bbroracle} - \bbroraclequeryfrom{bottom=$m$} - \bbroraclequeryto{bottom=$b$} + \bbroracleqryfrom{bottom=$m$} + \bbroracleqryto{bottom=$b$} \end{bbrenv} \begin{lstlisting} @@ -3480,7 +3511,7 @@ that oracle messages need to be added after the closing \lstinline$\end{bbroracl } \begin{bbrenv}{B} - \begin{bbrbox}[name=Adversary,minheight=3cm,xshift=4cm] + \begin{bbrbox}[name=Adversary,minheight=3cm,xshift=3cm] \end{bbrbox} \end{bbrenv} @@ -3493,19 +3524,123 @@ that oracle messages need to be added after the closing \lstinline$\end{bbroracl \begin{bbrbox}[name=Oracle 1,minheight=1cm] \end{bbrbox} \end{bbroracle} - \bbroraclequeryfrom{top=$m$} - \bbroraclequeryto{top=$b$} + \bbroracleqryfrom{top=$m$} + \bbroracleqryto{top=$b$} \begin{bbroracle}{OraB} \begin{bbrbox}[name=Oracle 2,minheight=1cm] \end{bbrbox} \end{bbroracle} - \bbroraclequeryfrom{bottom=$m$} - \bbroraclequeryto{bottom=$b$} + \bbroracleqryfrom{bottom=$m$} + \bbroracleqryto{bottom=$b$} +\end{bbrenv} +\end{lstlisting} + +\section{Challengers} +\index{bbrchallenger} +\index{hdistance} +\index{vdistance} +Each box can have one or more challengers which are drawn on the left hand side of the box. Challengers +behave identically to oracles with the exception that they are to the left of the box. A challenger +is created similarly to a \emph{bbrenv} environment using the \emph{bbrchallenger} environment. Challengers +go behind the single \emph{bbrbox} environment within an \emph{bbrenv} enviornment. + +\begin{bbrenv}{A} + \begin{bbrbox}[name=Adversary,minheight=2cm] + \pseudocode{ + \text{Do something} + } + + \end{bbrbox} + \bbrinput{input} + \bbroutput{output} + + \begin{bbrchallenger}{ChaA} + \begin{bbrbox}[name=Challenger,minheight=2cm] + + \end{bbrbox} + \end{bbrchallenger} +\end{bbrenv} + + +\begin{lstlisting} +\begin{bbrenv}{A} + \begin{bbrbox}[name=Adversary,minheight=2cm] + \pseudocode{ + \text{Do something} + } + + \end{bbrbox} + \bbrinput{input} + \bbroutput{output} + + \begin{bbrchallenger}{ChaA} + \begin{bbrbox}[name=Challenger,minheight=2cm] + + \end{bbrbox} + \end{bbrchallenger} +\end{bbrenv} +\end{lstlisting} +Via the option \enquote{hdistance=length} and \enquote{vdistance=length} you can control the horizontal and vertical position of the challenger. By default this value is set to 1.5cm and \lstinline$\baselineskip$. + + +\subsection{Communicating with Challengers} +\index{\textbackslash bbrchallengerqryfrom} +\index{\textbackslash bbrchallengerqryto} +As challengers 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$\bbrchallengerqryfrom$ and \lstinline$\bbrchallengerqryto$. +\begin{lstlisting} +\bbrchallengerqryfrom{options} +\bbrchallengerqryto{options} +\end{lstlisting} +Here options allow you to specify where the label goes (top, bottom). In addition you can use +\lstinline$\bbrchallengerqryspace$ to generate extra space between oracle messages. Note +that challenger messages need to be added after the closing \lstinline$\end{bbrchallenger}$ command. + +\begin{bbrenv}{A} + \begin{bbrbox}[name=Adversary,minheight=2cm] + \pseudocode{ + \text{Do something} + } + + \end{bbrbox} + \bbrinput{input} + \bbroutput{output} + + \begin{bbrchallenger}{ChaA} + \begin{bbrbox}[name=Challenger,minheight=2cm] + + \end{bbrbox} + \end{bbrchallenger} + + \bbrchallengerqryfrom{top=$m$} + \bbrchallengerqryto{bottom=$b$} +\end{bbrenv} + +\begin{lstlisting} +\begin{bbrenv}{A} + \begin{bbrbox}[name=Adversary,minheight=2cm] + \pseudocode{ + \text{Do something} + } + + \end{bbrbox} + \bbrinput{input} + \bbroutput{output} + + \begin{bbrchallenger}{ChaA} + \begin{bbrbox}[name=Challenger,minheight=2cm] + + \end{bbrbox} + \end{bbrchallenger} + + \bbrchallengerqryfrom{top=$m$} + \bbrchallengerqryto{bottom=$b$} \end{bbrenv} \end{lstlisting} + \chapter{Known Issues} \section{Pseudocode KeepSpacing within Commands} @@ -3549,6 +3684,10 @@ with either the \enquote{sets} or the \enquote{probability} option. In order to \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}. +\section{Hyperref} +The hyperref package (\url{https://www.ctan.org/pkg/hyperref}) should be loaded before cryptocode. If this is not possible +call the \lstinline$\pcfixhyperref$ after \lstinline$\begin{document}$. + \printindex |