-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathnotation.sty
320 lines (271 loc) · 10.4 KB
/
notation.sty
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
%Copyright 2018, Andrea Proietto
%Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
%
%The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
%
%THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
%=============================================
% This is a reduced version of a larger package, and contains an environment definition that enables quick drawing of cryptographic games, with the purpose of being as least intrusive, and most readable as possibile to the document writer/programmer.
% It is partially founded on the work of "asmeikal", found in GitHub: (https://github.com/asmeikal/crypto16)
\ProvidesPackage{notation}[2018/09/21 v1.0-crypto The Notation]
% Required for crypto games
\RequirePackage{tikz}
\usetikzlibrary{arrows,shadows} % shadows for the entities, arrows for the messages
\RequirePackage{xparse} % Improved macro/environment definition commands
% Cryptography
%
% Evaluate UAR [math mode]
\newcommand{\pickUAR}{\mathrel{{\leftarrow}\vcenter{\hbox{\scriptsize\rmfamily\upshape\!\!\textsf{\$}}}}}
% Default challenger
\newcommand{\challenger}{\textsf{C}}
% Default adversary
\newcommand{\adversary}{\textsf{A}}
% Default distinguisher
\newcommand{\distinguisher}{\textsf{D}}
% Cryptogame [math mode]
\NewDocumentCommand{\cryptog}{m O{\Pi} O{\adversary}}{\textsc{Game}^{\textsc{#1}}_{#2, #3}}
% Hybrid game [math mode]
\NewDocumentCommand{\hybridg}{m O{\Pi} O{\adversary}}{\textsc{Hyb}^{\textsc{#1}}_{#2, #3}}
% Acronyms
%
% Independent and Identically Distributed
\newcommand{\iid}{\textsc{iid}}
% Uniformly At Random
\newcommand{\uar}{\textsc{uar}}
% Probabilistic Polynomial Time
\newcommand{\ppt}{\textsc{ppt}}
% Secret Key Encryption
\newcommand{\ske}{\textsc{ske}}
% Public Key Encryption
\newcommand{\pke}{\textsc{pke}}
% Message Authentication Code
\newcommand{\mac}{\textsc{mac}}
% One-Way Function
\newcommand{\owf}{\textsc{owf}}
% One-Way Permutation
\newcommand{\owp}{\textsc{owp}}
% PseudoRandom Generator
\newcommand{\prg}{\textsc{prg}}
% PseudoRandom Function
\newcommand{\prf}{\textsc{prf}}
% PseudoRandom Permutation
\newcommand{\prp}{\textsc{prp}}
% TrapDoor Permutation
\newcommand{\tdp}{\textsc{tdp}}
% Chosen Plaintext Attack
\newcommand{\cpa}{\textsc{cpa}}
% Chosen Ciphertext Attack
\newcommand{\cca}{\textsc{cca}}
% Universally unForgeable from Chosen Message Attack
\newcommand{\ufcma}{\textsc{ufcma}}
% Discrete Logarithm assumption
\newcommand{\dl}{\textsc{dl}}
% Decisional Diffie-Hellman assumption
\newcommand{\ddh}{\textsc{ddh}}
% Computational Diffie-Hellman assumption
\newcommand{\cdh}{\textsc{cdh}}
% Goldreich-Goldwasser-Micali construct
\newcommand{\ggm}{\textsc{ggm}}
% Function classes and relations
%
% Computational indistinguishability
\newcommand{\compindist}{\approx_\textsc{c}}
% Statistical indistinguishability
\newcommand{\statindist}{\approx_\textsc{s}}
%%%%%%%%%%%%%%%%%%%%%%%%
% Cryptosequences
%%%%%%%%%%%%%%%%%%%%%%%%
% Define counters
\newcounter{preinstance}
\newcounter{instancecount}
\newcounter{sequencecursor}
\newcounter{intransientfigure}
\setcounter{intransientfigure}{0}
\newcounter{looplabel}
\newcommand{\cseqcraftfloat}{
\ifnum\@floatpenalty<0\relax
\else
\setcounter{intransientfigure}{1}
\begin{figure}[htbp]
\centering
\fi
}
% Styles
\tikzstyle{msgstyle}=[->, >=angle 60]
\tikzstyle{inststyle}=[rectangle, draw, anchor=west, minimum height=0.8cm, minimum width=1.6cm, fill=white, drop shadow={opacity=1,fill=black}]
% Internal commands
%
% Diagram spacing
\newcommand{\cseqdelay}{\stepcounter{sequencecursor}}
% Message: from, fromtext, msgtext, to, totext
\newcommand{\cseqmessager}[5]{
\stepcounter{sequencecursor}
\path (#1)+(0, -\thesequencecursor*\unitfactor-0.7*\unitfactor)
node (tail) {} node [anchor = east] {#2};
\path (#4)+(0, -\thesequencecursor*\unitfactor-0.7*\unitfactor)
node (head) {} node [anchor = west] {#5};
\draw [msgstyle] (tail) -- (head)
node [midway, above] {#3};
}
% Message: from, fromtext, msgtext, to, totext
\newcommand{\cseqmessagel}[5]{
\stepcounter{sequencecursor}
\path (#1)+(0, -\thesequencecursor*\unitfactor-0.7*\unitfactor)
node (tail) {} node [anchor = west] {#2};
\path (#4)+(0, -\thesequencecursor*\unitfactor-0.7*\unitfactor)
node (head) {} node [anchor = east] {#5};
\draw [msgstyle] (tail) -- (head)
node [midway, above] {#3};
}
% New participant
% \cseqentity[edge distance]{var}{name:class}
\newcommand{\cseqentity}[3][0]{
\stepcounter{instancecount}
\path (inst\thepreinstance.east)+(#1,0)
node[inststyle] (inst\theinstancecount) {#3};
\path (inst\theinstancecount)+(0,-0.5*\unitfactor)
node (#2) {};
\tikzstyle{instcolor#2}=[]
\stepcounter{preinstance}
}
% Entity computation
\newcommand{\cseqcompute}[3]{
\stepcounter{sequencecursor}
\path (#1)+(0,-\thesequencecursor*\unitfactor-0.7*\unitfactor)
node [anchor = #3] {#2};
}
% API Commands
%
% Challenger computation
\newcommand{\cseqchallenger}[1]{
\cseqcompute{C}{#1}{west};
}
% Adversary computation - optional orientation as first argument: [east|west]
\newcommand{\cseqadversary}[2][east]{
\cseqcompute{A}{#2}{#1};
}
% Distinguisher computation
\newcommand{\cseqdistinguisher}[1]{
\cseqcompute{D}{#1}{east};
}
% Message from adversary to challenger
\newcommand{\send}[3]{
\cseqmessager{A}{#1}{#2}{C}{#3}
}
% Message from challenger to adversary
\newcommand{\receive}[3]{
\cseqmessagel{C}{#1}{#2}{A}{#3}
}
% Message from adversary to distinguisher - cryptoredux only
\newcommand{\invoke}[3]{
\cseqmessagel{A}{#1}{#2}{D}{#3}
}
% Message from distinguisher to adversary - cryptoredux only
\newcommand{\return}[3]{
\cseqmessager{D}{#1}{#2}{A}{#3}
}
% Arguments: Identifier (used as label) | description | challengername
\NewDocumentEnvironment{cryptogame}{m m m O{2.2}}
{ % Crypto-game BEGIN
\cseqcraftfloat
\begin{tikzpicture}
% Set unit measurements
\setlength{\unitlength}{1cm}
\def\unitfactor{0.6}
% Set counters
\setcounter{preinstance}{0}
\setcounter{instancecount}{0}
\setcounter{sequencecursor}{0}
\node[coordinate] (inst0) {};
% Loop macros
\newcommand{\cseqbeginloop}{
\ifnum\thelooplabel=0
\setcounter{looplabel}{\thesequencecursor}
\stepcounter{looplabel}
\else \PackageError{notation}{Attempting to nest loops in a cryptosequence. Close the former loop first}
\fi
}
\newcommand{\cseqendloop}{
\ifnum\thelooplabel=0
\PackageError{notation}{No loop to close here}
\fi
\ifnum\thelooplabel>\thesequencecursor\relax
\PackageError{notation}{Closing an empty loop}
\fi
\draw[->](A)+(-0.2, -0.15-\thesequencecursor*\unitfactor-0.7*\unitfactor)
.. controls +(-0.6, -1.3)
and +(-0.6, +1.3)
.. +(-0.2, 0.15-\thelooplabel*\unitfactor-0.7*\unitfactor);
\setcounter{looplabel}{0}
}
% Add the game's participants
\cseqentity{A}{$\adversary$}
\cseqentity[#4]{C}{$\challenger^{\textsc{#3}}$}
}
{ % Crypto-game END
\ifnum\value{instancecount}>0
\foreach \t [evaluate=\t] in {1,...,\theinstancecount}{
\draw[dotted] (inst\t) -- ++(0,-\thesequencecursor*\unitfactor-2.2*\unitfactor);
}
\fi
\end{tikzpicture}
\ifnum\value{intransientfigure}=1
\caption{#2}
\label{cryptogame:#1}
\end{figure}
\setcounter{intransientfigure}{0}
\fi
}
% Arguments: Identifier (used as label) | description | challengername | Second adversary name
\NewDocumentEnvironment{cryptoredux}{m m m m O{2.2}}
{ % Crypto-game BEGIN
\cseqcraftfloat
\begin{tikzpicture}
% Set unit measurements
\setlength{\unitlength}{1cm}
\def\unitfactor{0.6}
% Set counters
\setcounter{preinstance}{0}
\setcounter{instancecount}{0}
\setcounter{sequencecursor}{0}
\node[coordinate] (inst0) {};
% Loop macros
\newcommand{\cseqbeginloop}{
\ifnum\thelooplabel=0
\setcounter{looplabel}{\thesequencecursor}
\stepcounter{looplabel}
\else \PackageError{notation}{Attempting to nest loops in a cryptosequence. Close the former loop first}
\fi
}
\newcommand{\cseqendloop}{
\ifnum\thelooplabel=0
\PackageError{notation}{No loop to close here}
\fi
\ifnum\thelooplabel>\thesequencecursor\relax
\PackageError{notation}{Closing an empty loop}
\fi
\draw[->](D)+(-0.2, -0.15-\thesequencecursor*\unitfactor-0.7*\unitfactor)
.. controls +(-0.6, -1.3)
and +(-0.6, +1.3)
.. +(-0.2, 0.15-\thelooplabel*\unitfactor-0.7*\unitfactor);
\setcounter{looplabel}{0}
}
% Add the reduction's participants
\cseqentity{D}{$\distinguisher^{\textsc{#4}}$}
\cseqentity[#5]{A}{$\adversary$}
\cseqentity[#5]{C}{$\challenger^{\textsc{#3}}$}
}
{ % Crypto-game END
\ifnum\value{instancecount}>0
\foreach \t [evaluate=\t] in {1,...,\theinstancecount}{
\draw[dotted] (inst\t) -- ++(0,-\thesequencecursor*\unitfactor-2.2*\unitfactor);
}
\fi
\end{tikzpicture}
\ifnum\value{intransientfigure}=1
\caption{#2}
\label{cryptoredux:#1}
\end{figure}
\setcounter{intransientfigure}{0}
\fi
}