-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwarp.sty
199 lines (179 loc) · 8.42 KB
/
warp.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
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{warp}[2022/01/21 Utils for illustrating the WARP block cipher]
%%% PREREQUISITES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\RequirePackage{amsmath,amsfonts,amssymb,xspace}
\RequirePackage{etoolbox,ifthen}
\RequirePackage{tikz}
\usetikzlibrary{positioning,calc,cipher}
%%% GENERAL CRYPTO UTILS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\providecommand{\cipher}[1]{\textsf{#1}}
%%% WARP TIKZ STYLES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\def\diffusion_length{7}
\tikzset{warpfig/.style={warpscale,
very thin,>=latex,
every node/.style={font=\tiny,inner sep=1pt}},
warpscale/.style={warpscaleprint},
warpscaleprint/.style={xscale=.5,yscale=.4},
warpscalelncs/.style={xscale=.38,yscale=.38},
warpscaletosc/.style={xscale=.42,yscale=.36},
markpath/.style={blue,thick},
markupperpath/.style={red, thick},
marklowerpath/.style={blue, thick},
markmidupperpath/.style={double=none, red, thin, double distance=.5pt},
markmidlowerpath/.style={double=none, blue, semithick},
}
%%% WARP TIKZ MACROS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newcommand{\warpround}[1]{%
\begin{tikzpicture}[warpfig]
\coordinate (ptop) at (0,-3);
\coordinate (pbot) at (0,-5.5);
\foreach \z [evaluate=\z as \zz using int(2*\z), evaluate=\z as \zzz using int(2*\z+1)] in {0,...,15} {
\draw (\zz,0) node[above] {$X_{\!\zz}$} ++(-.25,0) coordinate (t\zz);
\draw (\zzz,0) node[above] {$X_{\!\zzz}$} ++( .25,0) coordinate (t\zzz);
\draw (\zz,-6) %node[below] {$X'_{\!\zz}$}
++(-.25,0) coordinate (b\zz);
\draw (\zzz,-6) %node[below] {$X'_{\!\zzz}$}
++( .25,0) coordinate (b\zzz);
\node[box,minimum size=1pt,rounded corners=1pt] (s\z) at (\z*2+.5,-1) {$S$};
\coordinate[tee, scale=0.5] (tee\zz) at (s\z-|t\zz) ;
\coordinate[xor, scale=0.5] (xor\z) at (s\z-|t\zzz) ;
\coordinate[xor, scale=0.5, yshift=-.75cm] (tee\zzz) at (xor\z);
\node (rk\z) at (s\z|-tee\zzz) {$K_{\z}^b$\!\!\null};
\draw[-] (s\z) -- (xor\z);
\draw[->] (t\zz) |- (s\z);
\draw[->] (t\zzz) -- (xor\z);
\draw[->] (xor\z) -- (tee\zzz);
\draw[-] (rk\z) -- (tee\zzz);
}
\foreach \z [evaluate=\z as \zzz using int(2*\z+1)] in {0,1} {
\coordinate[xor, scale=0.5, yshift=-.5cm] (tec\zzz) at (tee\zzz);
\node (rc\z) at (s\z|-tec\zzz) {$\text{rc}_{\z}$\!\!\null};
\draw[-] (rc\z) -- (tec\zzz);
}
\foreach \z/\pz in {0/31, 1/6, 2/29, 3/14, 4/1, 5/12, 6/21, 7/8, 8/27, 9/2, 10/3, 11/0, 12/25, 13/4, 14/23, 15/10, 16/15, 17/22, 18/13, 19/30, 20/17, 21/28, 22/5, 23/24, 24/11, 25/18, 26/19, 27/16, 28/9, 29/20, 30/7, 31/26} {
\draw[->,rounded corners=2pt] (tee\z) -- (tee\z|-ptop) -- (b\pz|-pbot) -- (b\pz);
}
#1
\end{tikzpicture}%
}
\newcommand{\warproundwokey}[1]{%
\begin{tikzpicture}[warpfig]
\coordinate (ptop) at (0,-2);
\coordinate (pbot) at (0,-\diffusion_length);
\foreach \z [evaluate=\z as \zz using int(2*\z), evaluate=\z as \zzz using int(2*\z+1)] in {0,...,15} {
\draw (\zz,0) node[above] {$X_{\!\zz}$} ++(-.25, 0) coordinate (t\zz);
\draw (\zzz,0) node[above] {$X_{\!\zzz}$} ++(.25,0) coordinate (t\zzz);
\draw (\zz,{-\diffusion_length - 0.6}) %node[below] {$X'_{\!\zz}$}
++(-.25,0) coordinate (b\zz);
\draw (\zzz,{-\diffusion_length - 0.6}) %node[below] {$X'_{\!\zzz}$}
++( .25,0) coordinate (b\zzz);
\node[box,minimum size=1pt,rounded corners=1pt] (s\z) at (\z*2+.5,-1) {$S$};
\coordinate[tee, scale=0.5] (tee\zz) at (s\z-|t\zz);
\coordinate[xor, scale=0.5] (xor\z) at (s\z-|t\zzz);
\coordinate[] (tee\zzz) at (xor\z);
\draw[-] (s\z) -- (xor\z);
\draw[->] (t\zz) |- (s\z);
\draw[-] (t\zzz) -- (xor\z);
}
\foreach \z/\pz in {0/31, 1/6, 2/29, 3/14, 4/1, 5/12, 6/21, 7/8, 8/27, 9/2, 10/3, 11/0, 12/25, 13/4, 14/23, 15/10, 16/15, 17/22, 18/13, 19/30, 20/17, 21/28, 22/5, 23/24, 24/11, 25/18, 26/19, 27/16, 28/9, 29/20, 30/7, 31/26} {
\draw[-,rounded corners=2pt] (tee\z) -- (tee\z|-ptop) -- (b\pz|-pbot) -- (b\pz);
}
#1
\end{tikzpicture}%
}
\newcommand{\warproundfinal}[1]{%
\begin{tikzpicture}[warpfig]
\coordinate (ptop) at (0,-3);
\coordinate (pbot) at (0,-3);
\foreach \z [evaluate=\z as \zz using int(2*\z), evaluate=\z as \zzz using int(2*\z+1)] in {0,...,15} {
\draw (\zz,0) node[above] {$X_{\!\zz}$} ++(-.25,0) coordinate (t\zz);
\draw (\zzz,0) node[above] {$X_{\!\zzz}$} ++( .25,0) coordinate (t\zzz);
\draw (\zz,-3) node[below] {$X'_{\!\zz}$} ++(-.25,0) coordinate (b\zz);
\draw (\zzz,-3) node[below] {$X'_{\!\zzz}$} ++( .25,0) coordinate (b\zzz);
\node[box,minimum size=1pt,rounded corners=1pt] (s\z) at (\z*2+.5,-1) {$S$};
\coordinate[tee, scale=0.5] (tee\zz) at (s\z-|t\zz) ;
\coordinate[xor, scale=0.5] (xor\z) at (s\z-|t\zzz) ;
\coordinate[xor, scale=0.5, yshift=-.75cm] (tee\zzz) at (xor\z);
\node (rk\z) at (s\z|-tee\zzz) {$K_{\z}^b$\!\!\null};
\draw[-] (s\z) -- (xor\z);
\draw[->] (t\zz) |- (s\z);
\draw[->] (t\zzz) -- (xor\z);
\draw[->] (xor\z) -- (tee\zzz);
\draw[-] (rk\z) -- (tee\zzz);
}
\foreach \z [evaluate=\z as \zzz using int(2*\z+1)] in {0,1} {
\coordinate[xor, scale=0.5, yshift=-.5cm] (tec\zzz) at (tee\zzz);
\node (rc\z) at (s\z|-tec\zzz) {$\text{rc}_{\z}$\!\!\null};
\draw[-] (rc\z) -- (tec\zzz);
}
\foreach \z/\pz in {0/31, 1/6, 2/29, 3/14, 4/1, 5/12, 6/21, 7/8, 8/27, 9/2, 10/3, 11/0, 12/25, 13/4, 14/23, 15/10, 16/15, 17/22, 18/13, 19/30, 20/17, 21/28, 22/5, 23/24, 24/11, 25/18, 26/19, 27/16, 28/9, 29/20, 30/7, 31/26} {
\draw[->,rounded corners=2pt] (tee\z) -- (b\z);
}
#1
\end{tikzpicture}
}
\newcommand{\markbranches}[1]{%
\foreach \z/\pz in {#1} {
\draw[markpath,->,rounded corners=2pt] (t\z) -- (tee\z|-ptop) -- (b\pz|-pbot) -- (b\pz);
\node[markpath,fill,fill opacity=.2,above] at (\z,0) {\phantom{$X_{\!00}$}};
}
}
\newcommand{\marksboxes}[1]{%
\foreach \s/\z/\pz in {#1} {
\draw[markpath] (s\s) -- (xor\s);
\node[markpath,box,minimum size=1pt,rounded corners=1pt] at (s\s) {$S$};
\draw[markpath,->,rounded corners=2pt] (s\s) -- (tee\z) coordinate[tee, scale=.5] -- (tee\z|-ptop) -- (b\pz|-pbot) -- (b\pz);
\node[markpath,circle,draw,draw opacity=.5] at (rk\s) {$K_{\s}^b$\!\!\null};
\draw[markpath] (xor\s) coordinate[xor,scale=0.5];
\draw[markpath] (xor\s|-rk\s) coordinate[xor,scale=0.5] -- (rk\s);
}
}
\newcommand{\markoutputs}[1]{%
\foreach \z in {#1} {
\node[markpath,fill,fill opacity=.2,below] at (\z,-6.6) {\phantom{$X'_{\!00}$}};
}
}
\newcommand{\markoutputdiff}[1]{%
\foreach \z in {#1} {
\node[blue,fill,fill opacity=.2, below] at (\z,{-\diffusion_length - 0.6}) {\phantom{$X_{\!00}$}};
}
\foreach \z in {0, ..., 31} {
\draw (\z,{-\diffusion_length - 0.6}) node[below] {$X_{\!\z}$};
}
}
\newcommand{\markcommonactivesboxes}[1]{%
\foreach \z in {#1} {
\fill[yellow, very thick, fill opacity=.5, draw] (s\z) circle (0.5cm);
}
}
\newcommand{\markuppercrossingdifferences}[1]{%
\foreach \z in {#1} {
\node[red, thick,fill,fill opacity=.2,above] at (\z,0) {\phantom{$X_{\!00}$}};
}
}
\newcommand{\markevenbranches}[3]{%
%1: branch number (should be even)
%2: markupperpath or marklowerpath
%3: -> or <-
\foreach \z/\pz [evaluate=\z as \s using int(\z/2)] in {#1} {
\draw[#2,#3,rounded corners=2pt] (t\z) -- (tee\z|-ptop) -- (b\pz|-pbot) -- (b\pz);
\node[#2,fill,fill opacity=.2,above] at (\z,0) {\phantom{$X_{\!00}$}};
\node[#2,box,minimum size=1pt,rounded corners=1pt] at (s\s) {$S$};
%\coordinate[tee, scale=0.5] (tee\zz) at (s\z-|t\z);
\draw[#2, ->] (tee\z) -- (s\s);
\draw[#2] (s\s) -- (xor\s);
%\draw[#2] (xor\s) coordinate[xor,scale=0.5];
}
}
\newcommand{\markoddbranchbeforexor}[2]{%
\foreach \z [evaluate=\z as \zz using int(\z/2)] in {#1} {
\draw[#2] (t\z) -- (xor\zz);
\node[#2,fill,fill opacity=.2,above] at (\z,0) {\phantom{$X_{\!00}$}};
}
}
\newcommand{\markoddbranchafterxor}[3]{%
\foreach \z/\pz [evaluate=\z as \zz using int(\z/2)] in {#1} {
\draw[#2,#3,rounded corners=2pt] (xor\zz) -- (tee\z|-ptop) -- (b\pz|-pbot) -- (b\pz);
%\node[#2,fill,fill opacity=.2,above] at (\z,0) {\phantom{$X_{\!00}$}};
}
}