3 % $Id: crypto.dtx,v 1.1 2002/02/03 20:49:03 mdw Exp $
5 % Typesetting crypto papers
7 % (c) 2001 Mark Wooding
9 %----- Revision history -----------------------------------------------------
11 % $Log: crypto.dtx,v $
12 % Revision 1.1 2002/02/03 20:49:03 mdw
13 % Checkin for new build system.
18 % \begin{meta-comment} <general public licence>
20 %% crypto package -- useful macros for typesetting crypto papers
21 %% Copyright (c) 2001 Mark Wooding
23 %% This program is free software; you can redistribute it and/or modify
24 %% it under the terms of the GNU General Public License as published by
25 %% the Free Software Foundation; either version 2 of the License, or
26 %% (at your option) any later version.
28 %% This program is distributed in the hope that it will be useful,
29 %% but WITHOUT ANY WARRANTY; without even the implied warranty of
30 %% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31 %% GNU General Public License for more details.
33 %% You should have received a copy of the GNU General Public License
34 %% along with this program; if not, write to the Free Software Foundation,
35 %% Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
38 % \begin{meta-comment} <Package preambles>
39 %<+package>\NeedsTeXFormat{LaTeX2e}
40 %<+package>\ProvidesPackage{crypto}
41 %<+package> [2001/09/16 1.0 Crypto typesetting]
46 %% {Upper-case \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
47 %% Lower-case \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z
48 %% Digits \0\1\2\3\4\5\6\7\8\9
49 %% Exclamation \! Double quote \" Hash (number) \#
50 %% Dollar \$ Percent \% Ampersand \&
51 %% Acute accent \' Left paren \( Right paren \)
52 %% Asterisk \* Plus \+ Comma \,
53 %% Minus \- Point \. Solidus \/
54 %% Colon \: Semicolon \; Less than \<
55 %% Equals \= Greater than \> Question mark \?
56 %% Commercial at \@ Left bracket \[ Backslash \\
57 %% Right bracket \] Circumflex \^ Underscore \_
58 %% Grave accent \` Left brace \{ Vertical bar \|
59 %% Right brace \} Tilde \~}
62 % \begin{meta-comment}
66 \describespackage{crypto}
72 %^^A-------------------------------------------------------------------------
73 % \section{User guide}
75 % \subsection{Algorithm typesetting}
77 % A lot of provable-security papers need to be able to typeset algorithms
78 % describing adversaries, schemes, oracle behaviour, etc. There is a
79 % (relatively) standard format for doing this which we support.
81 % \DescribeEnv{program}
82 % The \env{program} environment provides handy notation for describing
83 % algorithms formally. It gives a \env{tabbing} environment, so that things
84 % can be laid out nicely, and allows fragments of algorithms to be laid out
85 % in columns or rows, with separating rules.
88 % Within the \env{program} environment, the |\next| command stops typesetting
89 % the current column, typesets a vertical separator rule, and starts a new
90 % column. Adjacent columns are spaced out evenly across the page, with equal
91 % space around the rules rules and at the current margins. This means that
92 % the rules don't line up, but it still seems to provide a pleasing effect.
94 % \DescribeMacro\newline
95 % The |\newline| macro begins a new row of algorithm typesetting. A page
96 % break is possible at a |\newline|.
99 % A number of standard keywords are available, as shown in
100 % table~\ref{tab:kw}. The typsetting of these is done by the |\kw| command,
101 % which usually sets its argument in text bold face, but can be redefined.
102 % The standard definition uses |\xspace| so that you don't need to remember
103 % to say \verb*+\ *+ after a keyword command.
106 % \def\row#1{\texttt{\string#1} & #1 \\}
107 % \begin{tabular}{ll}
108 % \textbf{Command} & \textbf{Keyword} \\
127 % \caption{Keywords available for algorithm typesetting}
131 % \DescribeMacro\gets
132 % \DescribeMacro\getsr
134 % Assignment can be represented using the standard command |\gets|, which
135 % typesets a left-pointing arrow `$\gets$'. Random sampling -- the selection
136 % of a random element from a set or probability distribution -- can be
137 % represented using the new command |\getsr|, which typesets an arrow with a
138 % little `R' above it `$\getsr$'. Random membership -- showing that
139 % something is a random variable with some distribution -- can be represented
140 % using the |\inr| command, which just typesets an $\in$ sign with a
141 % subscript `R': `$\inr$'.
144 % Long identifiers can be typeset using the |\id| command. giving the
145 % identifier name as an argument. The |\id| command is only valid in maths
146 % mode. As currently set up, |\id| sets its argument in \emph{text} italics;
147 % this seems to look better in documents which use a PostScript body face and
148 % Computer Modern for maths.
151 % It's handy to be able to glue a bit of (possibly fancy) maths typesetting
152 % to an identifier, e.g., to construct $\Xid{H'}{list}$, or
153 % $\Xid{\mathcal{E}}{CTR$\$$}^F$. This is done using
154 % \syntax{"\\Xid{"<maths>"}{"<text>"}"}. The two bits are joined by a text
157 % \DescribeMacro\cookie
158 % Sometimes textual names are used for special `symbols', which have meaning
159 % to algorithms, e.g., the symbols $\cookie{find}$ and $\cookie{guess}$ in
160 % the standard indistinguishability game. These can be typeset using the
163 % \subsection{Other stuff}
165 % \DescribeMacro\Thing
166 % In the quantifiable-security world, there are standard symbols for
167 % advantage, success probability, insecurity, etc. The generic `style hook'
168 % for these is \syntax{"\\Thing{"<name>"}{"<notion>"}{"scheme"}"}, which
169 % typesets $\Thing{name}{notion}{scheme}$. It helps a lot if you have the
170 % \package{amstext} package loaded.
172 % \DescribeMacro\Succ
174 % \DescribeMacro\InSec
175 % \DescribeMacro\Expt
177 % Some standard `things' are provided: "\\Succ{"<notion>"}{"<scheme>"}",
178 % "\\Adv{"<notion>"}{"<scheme>"}", "\\InSec{"<notion>"}", and
179 % "\\Expt{"<notion>"}{"<scheme>"}".
183 % In proofs which proceed by varying the rules of the game played by the
184 % adversary and bounding the probability of it noticing at each step, game
185 % names are usually typeset as $\G n$ for small numbers $n$. The command
186 % \syntax{"\\G{"<n>"}"} command does this typesetting. There's an optional
187 % argument, which is a symbol to write instead of `G'.
189 % \DescribeMacro\Func
190 % \DescribeMacro\Perm
191 % When dealing with finite PRFs and PRPs, we need to talk about the set of
192 % \emph{all} functions (or permutations) over particular sets, usually
193 % $n$-vectors of bits. The macros \syntax{"\\Func{"<l>"}{"<L>"}"} and
194 % \syntax{"\\Perm{"<L>"}"} typeset $\Func{l}{L}$ and $\Perm{L}$ respectively,
195 % and are intended to denote the sets of all functions $F\colon \{0, 1\}^l
196 % \to \{0, 1\}^L$ and all permutations $\Pi\colon \{0, 1\}^L \to \{0, 1\}^L$
199 % \DescribeMacro\PKCS
200 % Finally, the |\PKCS| macro typesets `\PKCS{$n$}', allowing you to name RSA
201 % Security Inc.'s Public Key Cryptography Standards in a relatively nice way.
206 %^^A-------------------------------------------------------------------------
207 % \section{Implementation}
209 % We need David Carlisle's handy \package{xspace} package and the AMS |\text|
214 \RequirePackage{amstext}
215 \RequirePackage{xspace}
218 % \subsection{Algorithm typsetting}
220 % \begin{macro}{\cookie}
224 % First, some style issues. Note the |\xspace| at the end of |\kw|.
227 \def\cookie#1{\text{\normalfont\sffamily\/#1\/}}
228 \def\kw#1{\text{\normalfont\bfseries\/#1\/}\xspace}
229 \def\id#1{\text{\normalfont\itshape\/#1\/}}
236 % \begin{macro}{\getsr}
237 % \begin{macro}{\inr}
239 % The symbols for random selection and membership are fairly easy. The `R'
240 % over $\getsr$ is actually in scriptscript style, because that seems to look
244 \def\inr{\mathrel{\in_R}}
245 \def\getsr{\mathrel{\mathop{\gets}\limits^{\scriptscriptstyle R}}}
251 % \begin{macro}{\Xid}
253 % The compound identifiers set by |\Xid| are easy.
256 \def\Xid#1#2{\id{$#1$-#2}}
261 % Now for the various keywords. These are trivial, but useful.
264 \def\RETURN{\kw{return}}
268 \def\REPEAT{\kw{repeat}}
269 \def\WHILE{\kw{while}}
270 \def\UNTIL{\kw{until}}
271 \def\FOREVER{\kw{forever}}
274 \def\FOREACH{\kw{for\,each}}
278 \def\ABORT{\kw{abort}}
279 \def\PARSE{\kw{parse}}
283 % \begin{environment}{program}
284 % \begin{macro}{\next}
285 % \begin{macro}{\newline}
287 % Now for the \env{program} environment and its associated twiddling. This
288 % is actually a little fiddly.
290 % At the beginning, if we're in vertical mode -- i.e., there was a paragraph
291 % break before the start of the environment -- then remember this, because it
292 % affects the typesetting at the end. Set up |\next| and |\newline| in terms
293 % of the underlying machinery, and start a row of algorithm.
298 \@tempswatrue\ifvmode\@tempswafalse\fi%
299 \def\next{\program@end\vrule\program@begin}%
300 \def\newline{\program@endline\medskip\program@startline}%
301 \begingroup\trivlist%
302 \advance\@topsep-\parskip\advance\@topsepadd-\parskip\item%
307 % Ending the environment is easy-ish. We stop the current row and leave a
308 % gap, matching the one that |\poem@startline| adds automatically. If we
309 % were initially in horizontal mode, then don't indent the next paragraph,
310 % and ignore spaces after the |\end{program}| command.
314 \program@endline\endtrivlist\endgroup%
315 \if@tempswa\noindent\fi\@ignoretrue%
319 % Now for the guts of all of this. First of all, we turn to the typesetting
320 % of a column, which is just hfil glue, a \env{minipage} with zero width and
321 % a \env{tabbing} environment. The first tab is already set 1\,em in from
322 % the margin. We use \env{minipage} to set up the list parameters correctly
323 % and manage the initial and final spacing. The zero width is OK because
324 % \env{tabbing} sets a list of hboxes rather than using outer horizontal
325 % mode, so the |\hsize| is irrelevant.
334 \parskip\z@\parsep\z@%
339 % This is rather messy. The |\item| from the \env{trivlist} messes up the
340 % spacing. We remove the box, and fix |\prevdepth| to ensure that there's no
347 \setbox\z@\lastbox\unskip\unskip\unskip\setbox\z@\lastbox\unskip%
354 % Ending a program has no discernable subtlety.
365 % Finally, the row setting is fairly easy. We have to ensure that we obey
366 % the prevailing list parameters.
369 \def\program@startline{%
370 \moveright\@totalleftmargin%
371 \hb@xt@\linewidth\bgroup%
374 \def\program@endline{%
384 % \subsection{Other stuff}
386 % \begin{macro}{\Thing}
387 % \begin{macro}{\Succ}
388 % \begin{macro}{\Adv}
389 % \begin{macro}{\InSec}
390 % \begin{macro}{\Expt}
392 % Typesetting |\Thing| is easy. This acts as a style hook for the rest of
396 \def\Thing#1#2#3{\text{\normalfont\bfseries#1}^{\text{\normalfont#2}}_{#3}}
399 % And now here they are.
402 \def\Succ{\Thing{Succ}}
403 \def\Adv{\Thing{Adv}}
404 \def\InSec#1{\Thing{InSec}{#1}{}}
405 \def\Expt{\Thing{Expt}}
416 % The name of a game is typeset simply as
419 \newcommand\G[2][G]{\mathbf{#1}_{#2}}
424 % \begin{macro}{\Func}
425 % \begin{macro}{\Perm}
427 % The finite sets of functions and permutations are just a style choice. We
428 % choose to buck the standard trends and use caligraphic letters.
431 \def\Func#1#2{\mathcal{F}^{#1,#2}}
432 \def\Perm#1{\mathcal{P}^{#1}}
438 % \begin{macro}{\PKCS}
440 % Finally, I find that \PKCS{$n$} looks best typeset like this:
443 \def\PKCS#1{PKCS\,\##1}
448 % \vskip\parskip\vbox{ ^^A The best way I could find of keeping this lot
449 % ^^A together, I'm afraid.
450 % That's all there is. Byebye.
457 % \hfill Mark Wooding, \today