% merkle-damgard.tex
% 
% Merkle-Damgard hash-function construction
%
% Author: Peter Schwabe
% Public domain

\psset{unit=1.5cm} 
\begin{pspicture}(0,0)(11,3.75)
% M_0
\pspolygon(0,3)(0,3.4)(1,3.4)(1,3)
\rput(0.5,3.2){$M_0$}
% F block
\pspolygon[fillstyle=solid, fillcolor=cyan](1,0)(1,2.5)(2,1.5)(2,0)
\rput(1.5,1){$F$}
% IV
\pspolygon(0,0)(0,1.5)(0.4,1.5)(0.4,0)
\rput{90}(0.2,0.75){$IV$}
% Arrows
\psline[linearc=.25]{->}(0.5,3)(0.5,2)(1,2)
\psline{->}(0.4,0.75)(1,0.75)

% M_1
\pspolygon(2,3)(2,3.4)(3,3.4)(3,3)
\rput(2.5,3.2){$M_1$}
% F block
\pspolygon[fillstyle=solid, fillcolor=cyan](3,0)(3,2.5)(4,1.5)(4,0)
\rput(3.5,1){$F$}
% Arrows
\psline[linearc=.25]{->}(2.5,3)(2.5,2)(3,2)
\psline{->}(2,0.75)(3,0.75)

% M_2
\pspolygon(4,3)(4,3.4)(5,3.4)(5,3)
\rput(4.5,3.2){$M_2$}
% Arrows
\psline[linearc=.25]{->}(4.5,3)(4.5,2)(5,2)
\psline{->}(4,0.75)(5,0.75)
\rput(5.5,2){$\dots$}
\rput(5.5,0.75){$\dots$}
\rput(5.5,3.2){$\dots$}

% M_f
\pspolygon(6,3)(6,3.4)(7,3.4)(7,3)
\rput(6.4,3.2){$M_f$}
\pspolygon[linestyle=none, fillcolor=red, fillstyle=solid](6.7,3)(6.7,3.4)(7,3.4)(7,3)
% F block
\pspolygon[fillstyle=solid, fillcolor=cyan](7,0)(7,2.5)(8,1.5)(8,0)
\rput(7.5,1){$F$}
% Arrows
\psline[linearc=.25]{->}(6.5,3)(6.5,2)(7,2)
\psline{->}(6,0.75)(7,0.75)

% F block
\pspolygon[fillstyle=solid, fillcolor=cyan](9,0)(9,2.5)(10,1.5)(10,0)
\rput(9.5,1){$F$}
% Arrows
\psline[linearc=.25]{->}(8.5,3)(8.5,2)(9,2)
\psline{->}(8,0.75)(9,0.75)

\rput(7.7,3.6){\footnotesize{\red {$padding$}}}
\rput(9.7,3.3){\footnotesize{\darkgray {$message$}}}
\rput(9.7,3.1){\footnotesize{\darkgray {$length$}}}

% Out
\pspolygon(10.6,0)(10.6,1.5)(11,1.5)(11,0)
\rput{90}(10.8,0.75){$Out$}
\psline{->}(10,0.75)(10.6,0.75)

% padding
\pspolygon(8,3)(8,3.4)(9,3.4)(9,3)
\pspolygon[linewidth=0, fillcolor=red, fillstyle=solid](8,3)(8,3.4)(8.7,3.4)(8.7,3)
\pspolygon[linestyle=none, fillcolor=red, fillstyle=solid](8,3)(8,3.4)(8.7,3.4)(8.7,3)
\pspolygon[linestyle=none, fillcolor=darkgray, fillstyle=solid](8.7,3)(8.7,3.4)(9,3.4)(9,3)

\end{pspicture}
