86f6a31e |
1 | % \begin{meta-comment} |
2 | % |
3 | % $Id: crypto.dtx,v 1.1 2002/02/03 20:49:03 mdw Exp $ |
4 | % |
5 | % Typesetting crypto papers |
6 | % |
7 | % (c) 2001 Mark Wooding |
8 | % |
9 | %----- Revision history ----------------------------------------------------- |
10 | % |
11 | % $Log: crypto.dtx,v $ |
12 | % Revision 1.1 2002/02/03 20:49:03 mdw |
13 | % Checkin for new build system. |
14 | % |
15 | % |
16 | % \end{meta-comment} |
17 | % |
18 | % \begin{meta-comment} <general public licence> |
19 | %% |
20 | %% crypto package -- useful macros for typesetting crypto papers |
21 | %% Copyright (c) 2001 Mark Wooding |
22 | %% |
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. |
27 | %% |
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. |
32 | %% |
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. |
36 | % \end{meta-comment} |
37 | % |
38 | % \begin{meta-comment} <Package preambles> |
39 | %<+package>\NeedsTeXFormat{LaTeX2e} |
40 | %<+package>\ProvidesPackage{crypto} |
41 | %<+package> [2001/09/16 1.0 Crypto typesetting] |
42 | % \end{meta-comment} |
43 | % |
44 | % \CheckSum{215} |
45 | %% \CharacterTable |
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 \~} |
60 | %% |
61 | % |
62 | % \begin{meta-comment} |
63 | % |
64 | %<*driver> |
65 | \input{mdwtools} |
66 | \describespackage{crypto} |
67 | \mdwdoc |
68 | %</driver> |
69 | % |
70 | % \end{meta-comment} |
71 | % |
72 | %^^A------------------------------------------------------------------------- |
73 | % \section{User guide} |
74 | % |
75 | % \subsection{Algorithm typesetting} |
76 | % |
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. |
80 | % |
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. |
86 | % |
87 | % \DescribeMacro\next |
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. |
93 | % |
94 | % \DescribeMacro\newline |
95 | % The |\newline| macro begins a new row of algorithm typesetting. A page |
96 | % break is possible at a |\newline|. |
97 | % |
98 | % \DescribeMacro\kw |
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. |
104 | % \begin{table} |
105 | % \centering |
106 | % \def\row#1{\texttt{\string#1} & #1 \\} |
107 | % \begin{tabular}{ll} |
108 | % \textbf{Command} & \textbf{Keyword} \\ |
109 | % \row\RETURN |
110 | % \row\IF |
111 | % \row\THEN |
112 | % \row\ELSE |
113 | % \row\REPEAT |
114 | % \row\WHILE |
115 | % \row\UNTIL |
116 | % \row\FOREVER |
117 | % \row\DO |
118 | % \row\FOR |
119 | % \row\FOREACH |
120 | % \row\FROM |
121 | % \row\IN |
122 | % \row\TO |
123 | % \row\ABORT |
124 | % \row\PARSE |
125 | % \row\AS |
126 | % \end{tabular} |
127 | % \caption{Keywords available for algorithm typesetting} |
128 | % \label{tab:kw} |
129 | % \end{table} |
130 | % |
131 | % \DescribeMacro\gets |
132 | % \DescribeMacro\getsr |
133 | % \DescribeMacro\inr |
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$'. |
142 | % |
143 | % \DescribeMacro\id |
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. |
149 | % |
150 | % \DescribeMacro\Xid |
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 |
155 | % hyphen `-'. |
156 | % |
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 |
161 | % |\cookie| command. |
162 | % |
163 | % \subsection{Other stuff} |
164 | % |
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. |
171 | % |
172 | % \DescribeMacro\Succ |
173 | % \DescribeMacro\Adv |
174 | % \DescribeMacro\InSec |
175 | % \DescribeMacro\Expt |
176 | % \begin{synshorts} |
177 | % Some standard `things' are provided: "\\Succ{"<notion>"}{"<scheme>"}", |
178 | % "\\Adv{"<notion>"}{"<scheme>"}", "\\InSec{"<notion>"}", and |
179 | % "\\Expt{"<notion>"}{"<scheme>"}". |
180 | % \end{synshorts} |
181 | % |
182 | % \DescribeMacro\G |
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'. |
188 | % |
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$ |
197 | % respectively. |
198 | % |
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. |
202 | % |
203 | % \implementation |
204 | % |
205 | % |
206 | %^^A------------------------------------------------------------------------- |
207 | % \section{Implementation} |
208 | % |
209 | % We need David Carlisle's handy \package{xspace} package and the AMS |\text| |
210 | % command. |
211 | % |
212 | % \begin{macrocode} |
213 | %<*package> |
214 | \RequirePackage{amstext} |
215 | \RequirePackage{xspace} |
216 | % \end{macrocode} |
217 | |
218 | % \subsection{Algorithm typsetting} |
219 | % |
220 | % \begin{macro}{\cookie} |
221 | % \begin{macro}{\kw} |
222 | % \begin{macro}{\id} |
223 | % |
224 | % First, some style issues. Note the |\xspace| at the end of |\kw|. |
225 | % |
226 | % \begin{macrocode} |
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\/}} |
230 | % \end{macrocode} |
231 | % |
232 | % \end{macro} |
233 | % \end{macro} |
234 | % \end{macro} |
235 | % |
236 | % \begin{macro}{\getsr} |
237 | % \begin{macro}{\inr} |
238 | % |
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 |
241 | % nicer. |
242 | % |
243 | % \begin{macrocode} |
244 | \def\inr{\mathrel{\in_R}} |
245 | \def\getsr{\mathrel{\mathop{\gets}\limits^{\scriptscriptstyle R}}} |
246 | % \end{macrocode} |
247 | % |
248 | % \end{macro} |
249 | % \end{macro} |
250 | % |
251 | % \begin{macro}{\Xid} |
252 | % |
253 | % The compound identifiers set by |\Xid| are easy. |
254 | % |
255 | % \begin{macrocode} |
256 | \def\Xid#1#2{\id{$#1$-#2}} |
257 | % \end{macrocode} |
258 | % |
259 | % \end{macro} |
260 | % |
261 | % Now for the various keywords. These are trivial, but useful. |
262 | % |
263 | % \begin{macrocode} |
264 | \def\RETURN{\kw{return}} |
265 | \def\IF{\kw{if}} |
266 | \def\THEN{\kw{then}} |
267 | \def\ELSE{\kw{else}} |
268 | \def\REPEAT{\kw{repeat}} |
269 | \def\WHILE{\kw{while}} |
270 | \def\UNTIL{\kw{until}} |
271 | \def\FOREVER{\kw{forever}} |
272 | \def\DO{\kw{do}} |
273 | \def\FOR{\kw{for}} |
274 | \def\FOREACH{\kw{for\,each}} |
275 | \def\FROM{\kw{from}} |
276 | \def\IN{\kw{in}} |
277 | \def\TO{\kw{in}} |
278 | \def\ABORT{\kw{abort}} |
279 | \def\PARSE{\kw{parse}} |
280 | \def\AS{\kw{as}} |
281 | % \end{macrocode} |
282 | % |
283 | % \begin{environment}{program} |
284 | % \begin{macro}{\next} |
285 | % \begin{macro}{\newline} |
286 | % |
287 | % Now for the \env{program} environment and its associated twiddling. This |
288 | % is actually a little fiddly. |
289 | % |
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. |
294 | % |
295 | % \begin{macrocode} |
296 | \def\program{% |
297 | \normalfont% |
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% |
303 | \program@startline% |
304 | } |
305 | % \end{macrocode} |
306 | % |
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. |
311 | % |
312 | % \begin{macrocode} |
313 | \def\endprogram{% |
314 | \program@endline\endtrivlist\endgroup% |
315 | \if@tempswa\noindent\fi\@ignoretrue% |
316 | } |
317 | % \end{macrocode} |
318 | % |
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. |
326 | % |
327 | % \begin{macrocode} |
328 | \def\program@begin{% |
329 | \begingroup% |
330 | \hfil% |
331 | \minipage[t]\z@% |
332 | \topsep\z@% |
333 | \itemsep\z@% |
334 | \parskip\z@\parsep\z@% |
335 | \partopsep\z@% |
336 | \tabbing% |
337 | % \end{macrocode} |
338 | % |
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 |
341 | % glue at the top. |
342 | % |
343 | % \begin{macrocode} |
344 | \quad\=dummy\\% |
345 | \@stopfield% |
346 | \begingroup% |
347 | \setbox\z@\lastbox\unskip\unskip\unskip\setbox\z@\lastbox\unskip% |
348 | \endgroup% |
349 | \prevdepth-\@m\p@% |
350 | \@startfield\strut% |
351 | } |
352 | % \end{macrocode} |
353 | % |
354 | % Ending a program has no discernable subtlety. |
355 | % |
356 | % \begin{macrocode} |
357 | \def\program@end{% |
358 | \endtabbing% |
359 | \endminipage% |
360 | \hfil% |
361 | \endgroup% |
362 | } |
363 | % \end{macrocode} |
364 | % |
365 | % Finally, the row setting is fairly easy. We have to ensure that we obey |
366 | % the prevailing list parameters. |
367 | % |
368 | % \begin{macrocode} |
369 | \def\program@startline{% |
370 | \moveright\@totalleftmargin% |
371 | \hb@xt@\linewidth\bgroup% |
372 | \program@begin% |
373 | } |
374 | \def\program@endline{% |
375 | \program@end% |
376 | \egroup% |
377 | } |
378 | % \end{macrocode} |
379 | % |
380 | % \end{macro} |
381 | % \end{macro} |
382 | % \end{environment} |
383 | % |
384 | % \subsection{Other stuff} |
385 | % |
386 | % \begin{macro}{\Thing} |
387 | % \begin{macro}{\Succ} |
388 | % \begin{macro}{\Adv} |
389 | % \begin{macro}{\InSec} |
390 | % \begin{macro}{\Expt} |
391 | % |
392 | % Typesetting |\Thing| is easy. This acts as a style hook for the rest of |
393 | % these things.. |
394 | % |
395 | % \begin{macrocode} |
396 | \def\Thing#1#2#3{\text{\normalfont\bfseries#1}^{\text{\normalfont#2}}_{#3}} |
397 | % \end{macrocode} |
398 | % |
399 | % And now here they are. |
400 | % |
401 | % \begin{macrocode} |
402 | \def\Succ{\Thing{Succ}} |
403 | \def\Adv{\Thing{Adv}} |
404 | \def\InSec#1{\Thing{InSec}{#1}{}} |
405 | \def\Expt{\Thing{Expt}} |
406 | % \end{macrocode} |
407 | % |
408 | % \end{macro} |
409 | % \end{macro} |
410 | % \end{macro} |
411 | % \end{macro} |
412 | % \end{macro} |
413 | % |
414 | % \begin{macro}{\G} |
415 | % |
416 | % The name of a game is typeset simply as |
417 | % |
418 | % \begin{macrocode} |
419 | \newcommand\G[2][G]{\mathbf{#1}_{#2}} |
420 | % \end{macrocode} |
421 | % |
422 | % \end{macro} |
423 | % |
424 | % \begin{macro}{\Func} |
425 | % \begin{macro}{\Perm} |
426 | % |
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. |
429 | % |
430 | % \begin{macrocode} |
431 | \def\Func#1#2{\mathcal{F}^{#1,#2}} |
432 | \def\Perm#1{\mathcal{P}^{#1}} |
433 | % \end{macrocode} |
434 | % |
435 | % \end{macro} |
436 | % \end{macro} |
437 | % |
438 | % \begin{macro}{\PKCS} |
439 | % |
440 | % Finally, I find that \PKCS{$n$} looks best typeset like this: |
441 | % |
442 | % \begin{macrocode} |
443 | \def\PKCS#1{PKCS\,\##1} |
444 | % \end{macrocode} |
445 | % |
446 | % \end{macro} |
447 | % |
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. |
451 | % |
452 | % \begin{macrocode} |
453 | %</package> |
454 | % \end{macrocode} |
455 | % \nopagebreak |
456 | % |
457 | % \hfill Mark Wooding, \today |
458 | % } |
459 | % \Finale |
460 | % |
461 | \endinput |