Creating cryptography box security games in Tikz

I am writing up some work on signature schemes and wanted to include some security proofs in Tikz which have similar form to the image below:

I can't find anything on this forum or elsewhere which has code to show how to produce an image like this in Tikz or another package. Any help would be greatly appreciated.

• Welcome to TeX.se. You might want to check out the cryptocode package, which seems to do this sort of thing. – Alan Munn Aug 28 '18 at 13:27

\documentclass[border=5pt,tikz]{standalone}
\usepackage{yfonts,amsmath,amssymb,amsfonts}
\usetikzlibrary{arrows,positioning,calc}
\begin{document}
\begin{tikzpicture}[>=latex]
\node[draw,inner sep=1.5cm] (a) {$A$};
\node at (-7,0) (pk) {\textfrak{pk}};
\draw[->] (pk) -- (a);
\node[below=.2 of pk] (ms) {$m^*,s^*$};
\draw[<-] (ms) --+ (5.35,0) node[midway,align=center,below,text width=4cm] {Win if \textsf{\textcolor{blue}{Verify$_{\textfrak{pk}}$}$(s^*,m^*)=\mathtt{valid}$ and $m^*\not\in\textcolor{red}{\mathcal{L}}$}};
\node (n) at ([yshift=-.5cm,xshift=.5cm]a) {$m\in\mathbb{P}$};
\draw[->] ($(n)+(1.15,0)$) --+ (2.8,0) node[midway,above] {$\mathcal{O}_{\textsf{Sig}_{\mathfrak{s\!k}}}$};
\node[right] at ($(n)+(3.85,0)$) {$\textcolor{red}{\mathcal{L}}\leftarrow\textcolor{red}{\mathcal{L}}\cup\{m\}$};
\draw[->] (4.4,-1) --+ (-2.75,0);
\node[yshift=-.5cm,right] at ($(n)+(3.85,0)$) {$t\leftarrow\textcolor{red}{\textsf{Sig}_{\textcolor{blue}{\mathfrak{sk}}}}(m)$};
\node[xshift=1.5cm,above=.5 of pk] {$(\textcolor{blue}{\mathfrak{pk}},\textcolor{red}{\mathfrak{sk}})\leftarrow\mathrm{KeyGen()}$};
\node[xshift=11cm,above=.5 of pk] {$\textcolor{red}{\mathcal{L}}\leftarrow\emptyset$};
\end{tikzpicture}
\end{document}


Here is the output:

• Just switch colors if they don't match … – current_user Aug 28 '18 at 13:45