3 % $Id: crypto.dtx,v 1.2 2003/09/05 16:13:14 mdw Exp $
5 % Typesetting crypto papers
7 % (c) 2001 Mark Wooding
11 % \begin{meta-comment} <general public licence>
13 %% crypto package -- useful macros for typesetting crypto papers
14 %% Copyright (c) 2001 Mark Wooding
16 %% This program is free software; you can redistribute it and/or modify
17 %% it under the terms of the GNU General Public License as published by
18 %% the Free Software Foundation; either version 2 of the License, or
19 %% (at your option) any later version.
21 %% This program is distributed in the hope that it will be useful,
22 %% but WITHOUT ANY WARRANTY; without even the implied warranty of
23 %% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 %% GNU General Public License for more details.
26 %% You should have received a copy of the GNU General Public License
27 %% along with this program; if not, write to the Free Software Foundation,
28 %% Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
31 % \begin{meta-comment} <Package preambles>
32 %<+package>\NeedsTeXFormat{LaTeX2e}
33 %<+package>\ProvidesPackage{crypto}
34 %<+package> [2001/09/16 1.0 Crypto typesetting]
39 %% {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
40 %% 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
41 %% Digits \0\1\2\3\4\5\6\7\8\9
42 %% Exclamation \! Double quote \" Hash (number) \#
43 %% Dollar \$ Percent \% Ampersand \&
44 %% Acute accent \' Left paren \( Right paren \)
45 %% Asterisk \* Plus \+ Comma \,
46 %% Minus \- Point \. Solidus \/
47 %% Colon \: Semicolon \; Less than \<
48 %% Equals \= Greater than \> Question mark \?
49 %% Commercial at \@ Left bracket \[ Backslash \\
50 %% Right bracket \] Circumflex \^ Underscore \_
51 %% Grave accent \` Left brace \{ Vertical bar \|
52 %% Right brace \} Tilde \~}
55 % \begin{meta-comment}
59 \describespackage{crypto}
65 %^^A-------------------------------------------------------------------------
66 % \section{User guide}
68 % \subsection{Algorithm typesetting}
70 % A lot of provable-security papers need to be able to typeset algorithms
71 % describing adversaries, schemes, oracle behaviour, etc. There is a
72 % (relatively) standard format for doing this which we support.
74 % \DescribeEnv{program}
75 % The \env{program} environment provides handy notation for describing
76 % algorithms formally. It gives a \env{tabbing} environment, so that things
77 % can be laid out nicely, and allows fragments of algorithms to be laid out
78 % in columns or rows, with separating rules.
81 % Within the \env{program} environment, the |\next| command stops typesetting
82 % the current column, typesets a vertical separator rule, and starts a new
83 % column. Adjacent columns are spaced out evenly across the page, with equal
84 % space around the rules rules and at the current margins. This means that
85 % the rules don't line up, but it still seems to provide a pleasing effect.
87 % \DescribeMacro\newline
88 % The |\newline| macro begins a new row of algorithm typesetting. A page
89 % break is possible at a |\newline|.
92 % A number of standard keywords are available, as shown in
93 % table~\ref{tab:kw}. The typsetting of these is done by the |\kw| command,
94 % which usually sets its argument in text bold face, but can be redefined.
95 % The standard definition uses |\xspace| so that you don't need to remember
96 % to say \verb*+\ + after a keyword command.
99 % \def\row#1{\texttt{\string#1} & #1 \\}
100 % \begin{tabular}{ll}
101 % \textbf{Command} & \textbf{Keyword} \\
121 % \caption{Keywords available for algorithm typesetting}
126 % Within a \env{program} environment, the |\ind| command shunts the indent
127 % level 1\,em to the right.
129 % \DescribeMacro\gets
130 % \DescribeMacro\getsr
132 % Assignment can be represented using the standard command |\gets|, which
133 % typesets a left-pointing arrow `$\gets$'. Random sampling -- the selection
134 % of a random element from a set or probability distribution -- can be
135 % represented using the new command |\getsr|, which typesets an arrow with a
136 % little `R' above it `$\getsr$'. Random membership -- showing that
137 % something is a random variable with some distribution -- can be represented
138 % using the |\inr| command, which just typesets an $\in$ sign with a
139 % subscript `R': `$\inr$'.
142 % Long identifiers can be typeset using the |\id| command. giving the
143 % identifier name as an argument. The |\id| command is only valid in maths
144 % mode. As currently set up, |\id| sets its argument in \emph{text} italics;
145 % this seems to look better in documents which use a PostScript body face and
146 % Computer Modern for maths.
149 % It's handy to be able to glue a bit of (possibly fancy) maths typesetting
150 % to an identifier, e.g., to construct $\Xid{H'}{list}$, or
151 % $\Xid{\mathcal{E}}{CTR$\$$}^F$. This is done using
152 % \syntax{"\\Xid{"<maths>"}{"<text>"}"}. The two bits are joined by a text
155 % \DescribeMacro\cookie
156 % Sometimes textual names are used for special `symbols', which have meaning
157 % to algorithms, e.g., the symbols $\cookie{find}$ and $\cookie{guess}$ in
158 % the standard indistinguishability game. These can be typeset using the
161 % \subsection{Other stuff}
163 % \DescribeMacro\Thing
164 % In the quantifiable-security world, there are standard symbols for
165 % advantage, success probability, insecurity, etc. The generic `style hook'
166 % for these is \syntax{"\\Thing{"<name>"}{"<notion>"}{"scheme"}"}, which
167 % typesets $\Thing{name}{notion}{scheme}$. It helps a lot if you have the
168 % \package{amstext} package loaded.
170 % \DescribeMacro\Succ
172 % \DescribeMacro\InSec
173 % \DescribeMacro\Expt
174 % \DescribeMacro\Game
176 % Some standard `things' are provided: "\\Succ{"<notion>"}{"<scheme>"}",
177 % "\\Adv{"<notion>"}{"<scheme>"}", "\\InSec{"<notion>"}",
178 % "\\Expt{"<notion>"}{"<scheme>"}", and "\\Game{"<notion>"}{"<scheme>"}".
182 % In proofs which proceed by varying the rules of the game played by the
183 % adversary and bounding the probability of it noticing at each step, game
184 % names are usually typeset as $\G n$ for small numbers $n$. The command
185 % \syntax{"\\G{"<n>"}"} command does this typesetting. There's an optional
186 % argument, which is a symbol to write instead of `G'.
188 % \DescribeMacro\Func
189 % \DescribeMacro\Perm
190 % When dealing with finite PRFs and PRPs, we need to talk about the set of
191 % \emph{all} functions (or permutations) over particular sets, usually
192 % $n$-vectors of bits. The macros \syntax{"\\Func{"<l>"}{"<L>"}"} and
193 % \syntax{"\\Perm{"<L>"}"} typeset $\Func{l}{L}$ and $\Perm{L}$ respectively,
194 % and are intended to denote the sets of all functions $F\colon \{0, 1\}^l
195 % \to \{0, 1\}^L$ and all permutations $\Pi\colon \{0, 1\}^L \to \{0, 1\}^L$
198 % \DescribeMacro\PKCS
199 % Finally, the |\PKCS| macro typesets `\PKCS{$n$}', allowing you to name RSA
200 % Security Inc.'s Public Key Cryptography Standards in a relatively nice way.
205 %^^A-------------------------------------------------------------------------
206 % \section{Implementation}
208 % We need David Carlisle's handy \package{xspace} package and the AMS |\text|
213 \RequirePackage{amstext}
214 \RequirePackage{xspace}
217 % \subsection{Algorithm typsetting}
219 % \begin{macro}{\cookie}
223 % First, some style issues. Note the |\xspace| at the end of |\kw|.
226 \def\cookie#1{\text{\normalfont\sffamily\/#1\/}}
227 \def\kw#1{\text{\normalfont\bfseries\/#1\/}\xspace}
228 \def\id#1{\text{\normalfont\itshape\/#1\/}}
235 % \begin{macro}{\getsr}
236 % \begin{macro}{\inr}
238 % The symbols for random selection and membership are fairly easy. The `R'
239 % over $\getsr$ is actually in scriptscript style, because that seems to look
243 \def\inr{\mathrel{\in_R}}
244 \def\getsr{\mathrel{\mathop{\gets}\limits^{\scriptscriptstyle R}}}
250 % \begin{macro}{\Xid}
252 % The compound identifiers set by |\Xid| are easy.
255 \def\Xid#1#2{\id{$#1$-#2}}
260 % Now for the various keywords. These are trivial, but useful.
263 \def\RETURN{\kw{return}}
267 \def\REPEAT{\kw{repeat}}
268 \def\WHILE{\kw{while}}
269 \def\UNTIL{\kw{until}}
270 \def\FOREVER{\kw{forever}}
273 \def\FOREACH{\kw{for\,each}}
277 \def\ABORT{\kw{abort}}
278 \def\PARSE{\kw{parse}}
280 \def\NEW{\ifmmode\mathop{\kw{new}}\else\kw{new}\fi}
283 % \begin{environment}{program}
284 % \begin{macro}{\next}
285 % \begin{macro}{\newline}
286 % \begin{macro}{\ind}
288 % Now for the \env{program} environment and its associated twiddling. This
289 % is actually a little fiddly.
291 % At the beginning, if we're in vertical mode -- i.e., there was a paragraph
292 % break before the start of the environment -- then remember this, because it
293 % affects the typesetting at the end. Set up |\next| and |\newline| in terms
294 % of the underlying machinery, and start a row of algorithm.
299 \@tempswatrue\ifvmode\@tempswafalse\fi%
300 \def\next{\program@end\vrule\program@begin}%
301 \def\newline{\program@endline\medskip\program@startline}%
302 \def\ind{\quad\=\+\kill}%
303 \ifdim\topsep<\parskip\topsep\parskip\fi%
304 \ifdim\@topsepadd<\z@\@topsepadd\z@\fi%
305 \begingroup\trivlist%
306 \advance\@topsep-\parskip\advance\@topsepadd-\parskip\item%
311 % Ending the environment is easy-ish. We stop the current row and leave a
312 % gap, matching the one that |\poem@startline| adds automatically. If we
313 % were initially in horizontal mode, then don't indent the next paragraph,
314 % and ignore spaces after the |\end{program}| command.
318 \program@endline\endtrivlist\endgroup%
319 \if@tempswa\@endparenv\fi\@ignoretrue%
323 % Now for the guts of all of this. First of all, we turn to the typesetting
324 % of a column, which is just hfil glue, a \env{minipage} with zero width and
325 % a \env{tabbing} environment. The first tab is already set 1\,em in from
326 % the margin. We use \env{minipage} to set up the list parameters correctly
327 % and manage the initial and final spacing. The zero width is OK because
328 % \env{tabbing} sets a list of hboxes rather than using outer horizontal
329 % mode, so the |\hsize| is irrelevant.
338 \parskip\z@\parsep\z@%
343 % This is rather messy. The |\item| from the \env{trivlist} messes up the
344 % spacing. We remove the box, and fix |\prevdepth| to ensure that there's no
351 \setbox\z@\lastbox\unskip\unskip\unskip\setbox\z@\lastbox\unskip%
354 \@startfield\strut\ignorespaces%
358 % Ending a program has no discernable subtlety.
369 % Finally, the row setting is fairly easy. We have to ensure that we obey
370 % the prevailing list parameters.
373 \def\program@startline{%
374 \moveright\@totalleftmargin%
375 \hb@xt@\linewidth\bgroup%
378 \def\program@endline{%
389 % \subsection{Other stuff}
391 % \begin{macro}{\Thing}
392 % \begin{macro}{\Succ}
393 % \begin{macro}{\Adv}
394 % \begin{macro}{\InSec}
395 % \begin{macro}{\Expt}
396 % \begin{macro}{\Game}
398 % Typesetting |\Thing| is easy. This acts as a style hook for the rest of
402 \def\Thing#1#2#3{\text{\normalfont\bfseries#1}^{\text{\normalfont#2}}_{#3}}
405 % And now here they are.
408 \def\Succ{\Thing{Succ}}
409 \def\Adv{\Thing{Adv}}
410 \def\InSec#1{\Thing{InSec}{#1}{}}
411 \def\Expt{\Thing{Expt}}
412 \def\Game{\Thing{Game}}
424 % The name of a game is typeset simply as
427 \newcommand\G[2][G]{\mathbf{#1}_{#2}}
432 % \begin{macro}{\Func}
433 % \begin{macro}{\Perm}
435 % The finite sets of functions and permutations are just a style choice. We
436 % choose to buck the standard trends and use caligraphic letters.
439 \def\Func#1#2{\mathcal{F}^{#1,#2}}
440 \def\Perm#1{\mathcal{P}^{#1}}
446 % \begin{macro}{\PKCS}
448 % Finally, I find that \PKCS{$n$} looks best typeset like this:
451 \def\PKCS#1{PKCS\,\##1}
456 % \vskip\parskip\vbox{ ^^A The best way I could find of keeping this lot
457 % ^^A together, I'm afraid.
458 % That's all there is. Byebye.
465 % \hfill Mark Wooding, \today