-
Notifications
You must be signed in to change notification settings - Fork 0
/
notation.sty
379 lines (325 loc) · 12 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
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
%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 personal undertaking which aims to uniformize and disambiguate mathematical notation between all its branches
\ProvidesPackage{notation}[2018/09/21 v0.3 The Notation]
% binom macro
\RequirePackage{amsmath}
% mathbb command, complement symbol and others
\RequirePackage{amssymb}
% More blackboard symbols
\RequirePackage{bbm}
% Required for crypto games
\RequirePackage{tikz} % duh...
\usetikzlibrary{arrows,shadows} % shadow for the entities, arrow for the messages
\RequirePackage{xparse} % Improved environment definition
% These definiions relate to numerical sets
%
% The prime numbers
\newcommand{\primenum}{\mathbb{P}}
% The natural (non-negative) numbers
% NOTE: \natural is already defined as a musical symbol, hence the \nonneg name
\newcommand{\nonneg}{\mathbb{N}}
% The integers
\newcommand{\integer}{\mathbb{Z}}
% The rationals
\newcommand{\rational}{\mathbb{Q}}
% The real numbers
\newcommand{\real}{\mathbb{R}}
%
% NOTE: Generic n-size sets are represented by their corresponding blackboard number, as the following macros suggest.
% This package implements the first two immediately because of their widespread use, though the logic should remain consistent for all such sets
%
% The generic singleton, to be interpreted as {0}
\newcommand{\singleton}{\mathbbm{1}}
% The generic doubleton, or binary set, to be interpreted as {0, 1}
\newcommand{\binary}{\mathbbm{2}}
% Comfort macros
%
\newcommand{\oneover}[1]{\frac{1}{#1}}
\newcommand{\half}{\frac{1}{2}}
% Some most-used functions
%
% Expected value of a RV [math mode]
\newcommand{\expect}{\mathcal{E}}
% Power set of a set [math mode]
\newcommand{\powerset}{\mathcal{P}}
% Probability distributions
%
% Generic distribution
\newcommand{\probdist}{\mathcal{R}and}
% Uniform distribution
\newcommand{\unifdist}{\mathcal{U}nif}
% Binomial distribution
\newcommand{\binomdist}{\mathcal{B}inom}
% Bernoulli distribution, or coin
\newcommand{\berdist}{\mathcal{B}er}
\newcommand{\coin}{\berdist}
% Independency relation
\newcommand{\indep}{\perp\!\!\!\!\perp}
% Similarities
\newcommand{\jaccsim}{\mathcal{J}\textit{acc}}
\newcommand{\hammsim}{\mathcal{H}\textit{amm}}
% Function classes and relations
%
% Comutational indistinguishability
\newcommand{\compindist}{\approx_\textsc{c}}
% Statistical indistinguishability
\newcommand{\statindist}{\approx_\textsc{s}}
% Polynomial function
\newcommand{\poly}{\mathcal{P}\textit{oly}}
% Negligible function
\newcommand{\negl}{\mathcal{N}\textit{egl}}
% Permutation, or ordering
\newcommand{\permut}{\mathcal{P}\textit{erm}}
\newcommand{\order}{\permut}
% 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}}
% Universally unforgeable from chosen message attack
\newcommand{\ufcma}{\textsc{uf-cma}}
% Decisional Diffie-Hellman
\newcommand{\ddh}{\textsc{ddh}}
% Computational Diffie-Hellman
\newcommand{\cdh}{\textsc{cdh}}
% Secret Key Encryption
\newcommand{\ske}{\textsc{ske}}
% Public Key Encryption
\newcommand{\pke}{\textsc{pke}}
% Chosen Plaintext Attack
\newcommand{\cpa}{\textsc{cpa}}
% Chosen Ciphertext Attack
\newcommand{\cca}{\textsc{cca}}
% One-Way Function
\newcommand{\owf}{\textsc{owf}}
% PseudoRandom Generator
\newcommand{\prg}{\textsc{prg}}
% PseudoRandom Function
\newcommand{\prf}{\textsc{prf}}
% PseudoRandom Permutation
\newcommand{\prp}{\textsc{prp}}
%%%%%%%%%%%%%%%%%%%%%%%%
% 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}
{ % 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[2.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{cryptogame:#1}
\end{figure}
\setcounter{intransientfigure}{0}
\fi
}
% Arguments: Identifier (used as label) | description | challengername | Second adversary name
\NewDocumentEnvironment{cryptoredux}{m m m m}
{ % 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[2.2]{A}{$\adversary$}
\cseqentity[2.2]{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
}
% Apply paragraph spacing
%\setlength{\parskip}{1em}
%\usepackage{indentfirst}
% Put all formulae in display style for fractions, binomial coefficients, etc.
%\everymath{\displaystyle}