
\input{header}
\usepackage{tikz}
\usetikzlibrary{calc}
\title[]{{\bf{\LARGE Symmetric Encryption}}}
\usepackage{textcomp}
\usetikzlibrary{shapes,arrows}
\usepackage{tcolorbox}
\definecolor{mycolor}{rgb}{0.122, 0.435, 0.698}


%\newtcbox{\mybox}{nobeforeafter,colframe=red,colback=red!5!white,boxrule=0.5pt,arc=4pt,
%  boxsep=0pt,left=6pt,right=6pt,top=6pt,bottom=6pt,tcbox raise base}

\begin{document}
% *** title slide *** %

\begin{frame}
 \titlepage
\end{frame}

\setbeamertemplate{footline}
{
  \hbox{%
  \begin{beamercolorbox}[wd=.5\paperwidth,ht=1.00ex,dp=1ex,left]{title in head/foot}%
    \usebeamerfont{title in head/foot}
    %\insertshorttitle
    ~~~{\tiny  UFCFVN-30-M Computer and Network Security}
  \end{beamercolorbox}%
  \begin{beamercolorbox}[wd=.5\paperwidth,ht=1.00ex,dp=1ex,right]  {date in head/foot}%
    \usebeamerfont{date in head/foot}
   {\tiny \insertframenumber{}\hspace*{1ex} }
  \end{beamercolorbox}}%
  \vskip0pt%
}



\setbeamertemplate{enumerate item}[circle]
\setbeamertemplate{itemize item}[square]  
\setbeamertemplate{itemize subitem}[ball]
\setbeamertemplate{itemize subsubitem}[-]    
%----------------------------------------------------------------------------------


%------------------------------------------------------------------------------------

%----------------------------------------------------------------------------------------
%----------------------------------------------------------------------------------------
\begin{frame}
\frametitle{The Basic Problem}
%\begin{figure}[!h]
%\centering
%\includegraphics[width=.80\textwidth,height=.20\textheight]{./Images/Basicrequrire-crop.pdf}
%\end{figure}
\begin{figure}
		\begin{tikzpicture}[font=\small]
				\node[bob,female,minimum size=1.2cm] (A) {};
\node[below= 0.1cm of A]{{\bf Alice}};				
				\node[businessman,right=3.6cm of A,minimum size=1.2cm,mirrored] (B) {};
\node[below= 0.1cm of B]{{\bf Bob}};				
				
				\node[devil,above =0.4cm of {$(A)!0.45!(B)$},minimum size=0.8cm,mirrored] (CC) {};
				
\node[anchor=south west] at (B.east |- B.180) {\textcolor{red}{\scriptsize Secret Key ($K$)}};
				\node[anchor=north east] at (A.west |- A.45) {\scriptsize \textcolor{red}{Secret Key ($K$)}};

				\draw (A.0) edge[->,dashed] node[above] {} (B.180);
				
				\draw  (B.210) edge[->,dashed] node[above] {} (A.-30) ;

			\end{tikzpicture}
			%\caption{A secure coin flipping protocol constructed from bit commitment.}
			\label{fig:protocolexample}
		\end{figure}
\onslide<1->
{
\begin{itemize}
\item \headdw{Requirement:} Both parties share a secret
\begin{itemize}
\item Requires solution to
key-distribution problem
}
\end{itemize}
\onslide<2->
{\item \headdw{Goal:} Send a message confidentially
}
\end{itemize}
\end{frame}

%----------------------------------------------------------------------------------------
%----------------------------------------------------------------------------------------
%----------------------------------------------------------------------------------------
\begin{frame}
  \frametitle{Encryption/Decryption}
   \tikzset{%
  block/.style    = {draw, thick, rectangle, minimum height = 3em,
    minimum width = 3em},
  sum/.style      = {draw, circle, node distance = 2cm}, % Adder
  input/.style    = {coordinate}, % Input
  output/.style   = {coordinate} % Output
}
% Defining string as labels of certain blocks.
\begin{tabular}{c}
\begin{minipage}{\textwidth}
\onslide<1>
{\begin{figure}[htb]
\centering
    \begin{tikzpicture}
        \node (key)[text width=4em,align=center]{\footnotesize{\color{red} Key ($K$)}};
        \node (enc)[minimum height=1.5cm, rounded corners=1ex,text width=2.5em,align=center,fill=yellow!15,draw]  [below of=key, node distance=1.5cm]{\footnotesize{\sc Enc}};
        \node (message) [text width=6em,align=center] [left of=enc, node distance=3cm] {\footnotesize{{\color{blue} Plaintext ($P$)}}};
        \node (ciphertext)[text width=6em,align=center] [right of=enc, node distance=3cm]{\footnotesize{{\color{purple} Ciphertext ($C$)}}};

        \draw[-latex] (key) -- (enc);
        \draw[-latex] ($(message.east)$) -- (enc);
        \draw[-latex] (enc) -- (ciphertext);
	\end{tikzpicture}
	
\caption{Encryption (${C}={\text{\sc Enc}}_{{K}}({P})$)}
\end{figure}
}
\end{minipage}
\\
\begin{minipage}{\textwidth}
\onslide<2>
{\begin{figure}
    \begin{tikzpicture}
        \node (key)[text width=4em,align=center]{\footnotesize{\color{red} Key ($K$)}};
        \node (dec)[minimum height=1.5cm, rounded corners=1ex,text width=2.5em,align=center,fill=yellow!15,draw]  [below of=key, node distance=1.5cm]{\footnotesize{\sc Dec}};
        \node (message) [text width=6em,align=center] [right of=enc, node distance=3cm] {\footnotesize{{\color{blue} Plaintext ($P$)}}};
        \node (ciphertext)[text width=6em,align=center] [left of=enc, node distance=3cm]{\footnotesize{{\color{purple} Ciphertext ($C$)}}};

        \draw[-latex] (key) -- (dec);
        \draw[-latex] (dec) -- ($(message.west)$);
        \draw[-latex] (ciphertext) -- (dec);
	\end{tikzpicture}
		\caption{Decryption ($\text{P}={\text{\sc Dec}}_{\text{K}}(\text{C})$)}
	\end{figure}
}
\end{minipage}
\end{tabular}
%---------------------------------------------------------------------
%---------------------------------------------------------------------
%---------------------------------------------------------------------
\end{frame}
%---------------------------------------------------------------------
%---------------------------------------------------------------------
%---------------------------------------------------------------------
\begin{frame}

\frametitle{Symmetric Encryption}
\headdw{Kerckhoff's Principle}
\begin{itemize}
\item  The Encryption ({\sc Enc}) and Decryption ({\sc Dec}) algorithms are public knowledge 
\item Security relies entirely on the secrecy of the key
\end{itemize}
\end{frame}
%-------------------------------------------------
\begin{frame}
\frametitle{Adversary's Capabilities}
Attacks are classified according to what information an
adversary has access to:
%The attacker might have access to:
\begin{itemize}
\onslide<2>{
\item \headdwo{Known CipherText Attack:} Adversary knows a bunch of ciphertexts $C_1, \ldots, C_n$
}
\onslide<3>{
\item \headdwo{Known PlainText Attack:}
Adversary knows a bunch of corresponding 
plaintext/ciphertext pairs $(P_1,C_1), \ldots, (P_n,C_n)$
}
\onslide<4>{
\item \headdwo{Chosen PlainText Attack:} Adversary has an encryption oracle which she can query on any plaintext of her choice to get the corresponding ciphertext 
} 
\onslide<5>{
\item \headdwo{Chosen Ciphertext Attack:}  Adversary has an encryption oracle \& a decryption oracle which she can query on any ciphertext of her choice to get the corresponding plaintext  
}
\end{itemize}
\onslide<6>{
The more information the adversary gets, the stronger the security is
}
\end{frame}
%---------------------------------------------------------------------
%---------------------------------------------------------------------
\begin{frame}
\frametitle{Requirement of a Cipher}
\begin{itemize}
\onslide<1>
{\item \subheadwo{For Sender/Receiver:}
   \begin{itemize}
   \item Easy to encrypt/decrypt knowing the key
   \end{itemize}
  ~\\~\\
}
\onslide<2->{
\item \subheadwo{For Adversary:}
\begin{itemize}
\item Hard to encrypt/decrypt without the key 
~\\~\\
}
\onslide<3->{
\item Cannot do better than brute force (try all possible keys) to recover the key even given reasonable amount of plaintexts/ciphertexts
~\\~\\
}
\onslide<4->{
\item Hard to get any information about the plaintext
\end{itemize}
}
\end{itemize}
\end{frame}
%-------------------------------------------------
%-------------------------------------------------
%-------------------------------------------------
\begin{frame}
\frametitle{Examples of Insecure  Classical Ciphers}
\begin{itemize}
\item Caesar Cipher (Shift Cipher)
\begin{itemize}
\item e.g.~3-Caesar replaces \textcolor{red}{a} with \textcolor{blue}{d}, \textcolor{red}{b} with \textcolor{blue}{e}, \textcolor{red}{c} with \textcolor{blue}{f}, and so on
\end{itemize}	
\item General Monoalphabetic Substitution
Cipher 
\begin{itemize}
\item The key space is all permutations of $\{A, B, C,\ldots, Z\}$
\begin{itemize}
\item Encryption: Given a key $\pi$: replace each letter X in the plaintext with $\pi(X)$
\item Decryption: Given a key $\pi$:
 replace each letter X in the ciphertext with $\pi^{-1}(X)$
\end{itemize}
\examw~\\
{\footnotesize
\begin{tabular}{|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|}
%\hspace{-20mm}
\hline
A &B &C &D &E &F &G &H &I &J &K &L &M &N &O &P &Q &R &S &T &U &V &W &X &Y &Z\\
\hline
B & A& D& C& Z& H &W &Y &G &O &Q &X &S &V &T &R &N &M &S& K& J &I &P &F &E &U
\\
\hline
\end{tabular}
}
Cryptoanalysis: an historical example
 The monoalphabetic-substitution cipher maintains the
redundancy that is present in the cleartext
 It can be “easily” cryptoanalized with a ciphertext-only
attack based on language statistics
Frequency of
\end{itemize}
\end{itemize}
\end{frame}
%-------------------------------------------------
%-------------------------------------------------
%-------------------------------------------------
%Terms courtesy of Claude Shannon, father of Information Theory
%“Confusion” = Substitution
%a -> b
%Caesar cipher
%“Diffusion” = Transposition or Permutation
%abcd -> dacb
%DES
%-------------------------------------------------
\begin{frame}
\frametitle{One-Time Pad}
\begin{itemize}
\item \headdwo{Encryption:} $C=\text{\sc Enc}_K(P)=K \oplus P$
\item \headdwo{Decryption:} $P=\text{\sc Dec}_K(C)=K \oplus C$
\end{itemize}
\examw~\\
\begin{tabular}{cc}
\hspace{-8mm}
\begin{minipage}{4.5cm}
\begin{figure}
{\footnotesize
\begin{tabular}{c|c|c|c|c|c|c|c|c|}
\cline{2-9}
\textcolor{blue}{P} & \textcolor{blue}{1} &
\textcolor{blue}{0} & \textcolor{blue}{1} & \textcolor{blue}{0} & \textcolor{blue}{0} & \textcolor{blue}{1} & \textcolor{blue}{0} & \textcolor{blue}{1}\\
\cline{2-9}
\multicolumn{9}{c}{~~~~~$\oplus$}\\
\cline{2-9}
\textcolor{red}{K} & \textcolor{red}{0} &\textcolor{red}{0} & \textcolor{red}{1} & \textcolor{red}{0} & \textcolor{red}{1} & \textcolor{red}{1} & \textcolor{red}{1} & \textcolor{red}{0}\\
\cline{2-9}
%\multicolumn{9}{c}{~~}\\
%\hline
\multicolumn{9}{c}{~~~~=}\\
\cline{2-9}
\textcolor{purple}{C} & \textcolor{purple}{1} &\textcolor{purple}{0} & \textcolor{purple}{0} & \textcolor{purple}{0} & \textcolor{purple}{1} & \textcolor{purple}{0} & \textcolor{purple}{1} & \textcolor{purple}{1}\\
\cline{2-9}
\end{tabular}
}
\caption{Encryption}
\end{figure}
\end{minipage}
~~
&
~~
\begin{minipage}{4.5cm}
\begin{figure}
{\footnotesize
\begin{tabular}{c|c|c|c|c|c|c|c|c|}
\cline{2-9}
\textcolor{purple}{C} & \textcolor{purple}{1} &\textcolor{purple}{0} & \textcolor{purple}{0} & \textcolor{purple}{0} & \textcolor{purple}{1} & \textcolor{purple}{0} & \textcolor{purple}{1} & \textcolor{purple}{1}\\
\cline{2-9}
\multicolumn{9}{c}{~~~~~$\oplus$}\\
\cline{2-9}
\textcolor{red}{K} & \textcolor{red}{0} &\textcolor{red}{0} & \textcolor{red}{1} & \textcolor{red}{0} & \textcolor{red}{1} & \textcolor{red}{1} & \textcolor{red}{1} & \textcolor{red}{0}\\
\cline{2-9}
%\multicolumn{9}{c}{~~}\\
%\hline
\multicolumn{9}{c}{~~~~=}\\
\cline{2-9}
\textcolor{blue}{P} & \textcolor{blue}{1} &
\textcolor{blue}{0} & \textcolor{blue}{1} & \textcolor{blue}{0} & \textcolor{blue}{0} & \textcolor{blue}{1} & \textcolor{blue}{0} & \textcolor{blue}{1}\\
\cline{2-9}
\end{tabular}
}
\caption{Decryption}
\end{figure}
\end{minipage}
\end{tabular}
\end{frame}

%-------------------------------------------------
\begin{frame}
\frametitle{Pros \& Cons of One-Time Pad }
\begin{itemize}
\item \subheadwo{Pros of OTP:}
    \begin{itemize}
    \item Ciphertext reveals no information about the plaintext (perfect secrecy)
    ~\\~\\
    \end{itemize}
    
\item \subheadwo{Cons of OTP:}
\begin{itemize}
\item Key has to be as long as the plaintext
\item The key should not be guessable from an attacker
\begin{itemize}
\item Require  true randomness 
\end{itemize}
\item Insecure  against two-time pad (if same key used twice)
\mybox{$(P_1 \oplus K) \oplus (P_2 \oplus K) = P_1 \oplus P_2 $}
\end{itemize}
\end{itemize}
\end{frame}
%------------------------------------------------
%-------------------------------------------------
%------------------------------------------------
%-------------------------------------------------
\begin{frame}
\frametitle{Stream Ciphers}
The aim is to make One-Time Pad more practical~\\~\\
\headdw{The idea:} Use a \subheadwo{pseudorandom key} instead of a truly random key
\begin{itemize}
\item \subheadwo{Key is not truly random but looks random} 
\end{itemize}
\textcolor{red}{How{\Large{?}}}
Using a Pseudo Random Generator (PRG)

\begin{figure}[!h]
\centering
\includegraphics[width=.50\textwidth,height=.34\textheight]{./Images/PRG-crop.pdf}
\end{figure}
\begin{itemize}
\item \headdwo{Encryption:} $C={\text{\sc PGR}}(K) \oplus P$
\item \headdwo{Decryption:} $P={\text{\sc PGR}}(K) \oplus C$
\end{itemize}
\end{frame}
%------------------------------------------------
%-------------------------------------------------
\begin{frame}
\frametitle{Stream Ciphers}
\begin{itemize}
\item Insecure against two-time pad if no nonce is used \mybox{$(P_1 \oplus \text{\sc PGR}(K)) \oplus (P_2 \oplus \text{\sc PGR}(K)) = P_1 \oplus P_2 $}
\end{itemize}
\headdwo{Nonce:} A non-repeating value for a given key
~\\~\\
Modern stream ciphers use a nonce
\begin{itemize}
\item \headdwo{Encryption:} $C={\text{\sc PGR}}(K; r) \oplus P$
\item \headdwo{Decryption:} $P={\text{\sc PGR}}(K; r) \oplus C$
\end{itemize}
The pair $(K, r)$ is never used more than once
~\\~\\~\\
Stream Ciphers  include Trivium, RC4, ChaCha, Salsa20,  $\ldots$
\end{frame}
%----------------------------------------------------------------------------------------
%----------------------------------------------------------------------------------------
%------------------------------------------------
%-------------------------------------------------
\begin{frame}
\frametitle{Block Ciphers}
Plaintext is divided into blocks, e.g.~64 bits, 128 bits, etc. 
~\\
~\\
\begin{tabular}{c}
\begin{minipage}{\textwidth}
\begin{figure}[htb]
\centering
    \begin{tikzpicture}
        \node (key)[style = {draw, rectangle},text width=4em,align=center]{\footnotesize{\color{red} Key ($K$)}};
        \node (enc)[minimum height=0.8cm, rounded corners=1ex,text width=2.5em,align=center,fill=yellow!15,draw]  [below of=key, node distance=1cm]{\footnotesize{\sc Enc}};
        \node (message) [text width=6em,align=center] [left of=enc, node distance=3cm, style = {draw, rectangle}] {\footnotesize{{\color{blue} Plaintext ($P$)}}};
        \node (ciphertext)[text width=6em,align=center,style = {draw, rectangle}] [right of=enc, node distance=3cm]{\footnotesize{{\color{purple} Ciphertext ($C$)}}};

        \draw[-latex] (key) -- (enc);
        \draw[-latex] ($(message.east)$) -- (enc);
        \draw[-latex] (enc) -- (ciphertext);
\node[right = 0.1cm of ciphertext]{n bits};
\node[left = 0.1cm of message]{n bits};
\node[right = 0.1cm of key]{k bits};
\end{tikzpicture}
%\vspace{-2mm}
\caption{Encryption}
\end{figure}
\end{minipage}
\\
\begin{minipage}{\textwidth}
\begin{figure}
    \begin{tikzpicture}
        \node (key)[text width=4em,align=center,style = {draw, rectangle}]{\footnotesize{\color{red} Key ($K$)}};
        \node (dec)[minimum height=0.8cm, rounded corners=1ex,text width=2.5em,align=center,fill=yellow!15,draw]  [below of=key, node distance=1cm]{\footnotesize{\sc Dec}};
        \node (message) [text width=6em,align=center] [right of=enc, node distance=3cm,style = {draw, rectangle}] {\footnotesize{{\color{blue} Plaintext ($P$)}}};
        \node[right = 0.1cm of key]{k bits};
        \node (ciphertext)[text width=6em,align=center] [left of=enc, node distance=3cm,style = {draw, rectangle}]{\footnotesize{{\color{purple} Ciphertext ($C$)}}};
\node[left = 0.1cm of ciphertext]{n bits};
\node[right = 0.1cm of message]{n bits};

        \draw[-latex] (key) -- (dec);
        \draw[-latex] (dec) -- ($(message.west)$);
        \draw[-latex] (ciphertext) -- (dec);
	\end{tikzpicture}
%\vspace{-2mm}
\caption{Decryption}
	\end{figure}
\end{minipage}
\end{tabular}
%\vspace{-2mm}
\examw~\\
\begin{itemize}
\item AES Cipher: n=128 and k=128, 192 or 256
\item 3DES Cipher: n=64 and k=168
\end{itemize}

\end{frame}
%------------------------------------------------
%-------------------------------------------------
%------------------------------------------------
%-------------------------------------------------
\begin{frame}
\frametitle{Block Ciphers}
Block ciphers consist of a number of rounds ~\\
\begin{figure}[!h]
\centering
\includegraphics[width=.86\textwidth,height=.42\textheight]{./Images/Block-crop.pdf}
\end{figure}
\examw~\\
\begin{itemize}
\item 3DES: n=48
\item AES-128: n=10
\item AES-192: n=12
\item AES-256: n=14
\end{itemize}
\end{frame}
%----------------------------------------------------------------------------------------
%----------------------------------------------------------------------------------------
\begin{frame}
  \frametitle{Advenced Encryption Standard (AES)}
\begin{itemize}
\item In 2001 NIST adopted Rijndael (AES) as a replacement for 3DES 
\item Is a Substitution-Permutation network (not a Feistel
network)
\begin{itemize}
\item \subheadwo{Substitution (S-box):} Replace n-bits by another n-bits
\begin{itemize}
\item Provides Diffusion: One bit change in plaintext changes many bits in ciphertext.
\end{itemize}

\item \subheadwo{Permutation (P-box):} Bits are rearranged
\begin{itemize}
\item Provides Confusion: Make relationship between ciphertext and key complex 
\end{itemize}
\end{itemize}
\end{itemize}
\end{frame}

%>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
%>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
%>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

%>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
%>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
%>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
                              
                              

%----------------------------------------------------------------------------------------
%----------------------------------------------------------------------------------------
%----------------------------------------------------------------------------------------
%----------------------------------------------------------------------------------------
\begin{frame}
  \frametitle{AES Details}
The 128-bit plaintext block is arranged as a $4\times4$ matrix

{\small
\begin{figure}
\centering
\begin{tabular}{|c|c|c|c|}
\hline
$\text{Byte}_0$ & $\text{Byte}_4$ & $\text{Byte}_8$  & $\text{Byte}_{12}$\\
\hline
$\text{Byte}_1$ & $\text{Byte}_5$ & $\text{Byte}_9$  & $\text{Byte}_{13}$
\\
\hline
$\text{Byte}_2$ & $\text{Byte}_6$ & $\text{Byte}_{10}$  & $\text{Byte}_{14}$\\
\hline
$\text{Byte}_3$ & $\text{Byte}_{7}$ & $\text{Byte}_{11}$  & $\text{Byte}_{15}$\\
\hline
\end{tabular}
\end{figure}
}
We will refer to the plaintext block array as a state array $S$
~\\~\\~\\
Key is arranged as $4 \times k$ matrix and then expanded to obtain $n+1$ 128-bit keys ($n$ is number of rounds)
%-----------------------
\end{frame}
%----------------------------------------------------------------------------------------
%----------------------------------------------------------------------------------------
%----------------------------------------------------------------------------------------
%----------------------------------------------------------------------------------------
\begin{frame}
  \frametitle{AES-128 Semantic}
\begin{figure}[!h]
\vspace{-4mm}
\centering
\includegraphics[width=.92\textwidth,height=.56\textheight]{./Images/AESRounds-crop.pdf}
\vspace{-4mm}
\caption{AES-128}
\end{figure}
\end{frame}
%----------------------------------------------------------------------------------------
%----------------------------------------------------------------------------------------
%----------------------------------------------------------------------------------------
%----------------------------------------------------------------------------------------
\begin{frame}
  \frametitle{AES SubByte}
Replace each byte in the state matrix by the corresponding value in the S-Box (Operation is reversible)
\begin{itemize}
\item Use the hexadecimal value of the 4 least/most significant bits to index row/column,  respectively 
\end{itemize}
\only<1>
{\begin{figure}[!h]
\vspace{-4mm}
\centering
\includegraphics[width=.9\textwidth,height=.44\textheight]{./Images/S-Box1-crop.pdf}
\vspace{-4mm}
\caption{AES S-Box}
\end{figure}
}
\only<2>
{\begin{figure}[!h]
\vspace{-4mm}
\centering
\includegraphics[width=.9\textwidth,height=.44\textheight]{./Images/S-Box2-crop.pdf}
\vspace{-4mm}
\caption{AES S-Box}
\vspace{-6mm}
\end{figure}
\examw~\\
If the value in the cell is $4A$, its new value is \headdwo{$D6$}
}
\end{frame}



%----------------------------------------------------------------------------------------
%----------------------------------------------------------------------------------------
%----------------------------------------------------------------------------------------
\begin{frame}
  \frametitle{AES ShiftRows}
\begin{itemize}
\item Shift~\\
\only<1>
{{\begin{figure}[!h]
\vspace{-4mm}
\centering
\includegraphics[width=.34\textwidth,height=.3\textheight]{./Images/ShiftRows1-crop.pdf}
\vspace{-4mm}
\end{figure}
}
}
\only<2>
{{\begin{figure}[!h]
\vspace{-4mm}
\centering
\includegraphics[width=.6\textwidth,height=.3\textheight]{./Images/ShiftRows3-crop.pdf}
\vspace{-4mm}
\end{figure}
}
}


\end{itemize}

\end{frame}





%----------------------------------------------------------------------------------------
%----------------------------------------------------------------------------------------
%----------------------------------------------------------------------------------------

\begin{frame}
  \frametitle{AES MixColumns}
\begin{itemize}
  \item Provides diffusion
  \item Each byte is replaced by a value dependent on all 4 bytes in the column
 \item Effectively a matrix multiplication in GF($2^8$) using prime poly 
 $x^8+x^4+x^3+x+1$
 {\small
$$
\begin{array}{c} 
 \left [
 \begin{array}{c}
 2 w + 3 x +  y +  z\\
 w + 2 x + 3y + z\\
 w + x + 2 y + 3 z\\
 3 w + x +  y + 2 z 
  \end{array}
  \right]
    \\
  \textcolor{red}{\mbox{New Column}}
\end{array}
=
 \begin{array}{c}
 \left [
 \begin{array}{cccc}
 2 & 3 & 1 & 1 \\
 1 &  2 & 3 & 1 \\
 1 & 1 & 2 & 3 \\
 3 &  1 & 1 & 2 
  \end{array}
  \right]
  \\
  \textcolor{red}{\mbox{Constant Matrix}}
\end{array}
\times
\begin{array}{c}
\left [
 \begin{array}{c}
 w \\
 x\\
 y \\
 z  \\
 \end{array}
  \right]
  \\
  \textcolor{red}{\mbox{Original Column}}
 \end{array}
$$
}
\end{itemize}
Operation is reversible (just multiply by the inverse of the constant matrix)
\end{frame}
%----------------------------------------------------------------------------------
%----------------------------------------------------------------------------------
%-------------------------------------------------------------------
%----------------------------------------------------------------------------------
%----------------------------------------------------------------------------------
%-------------------------------------------------------------------
\begin{frame}
  \frametitle{AES Implementation Details}
\begin{itemize}
\item Algorithms used in AES are simple and can be easily implemented using cheap processors and a minimum amount of memory
~\\~\\
\item Very efficient
\begin{itemize}
\item Implementation was a key factor in its selection as the AES cipher
\end{itemize}
\end{itemize}
\end{frame}

%----------------------------------------------------------------------------------
%----------------------------------------------------------------------------------
%-------------------------------------------------------------------
%\tikzset{font={\fontsize{8.0pt}{12}\selectfont}}
\begin{frame}
  \frametitle{Modes of Encryption}
{\Large{Q:}} How to encrypt a message that is larger than the block size of the 
cipher{\textcolor{red}{\Large{?}}}~\\
{\Large{A:}} Divide it into multiple blocks and encrypt them using one of the \headdwo{Encryption Modes}~\\~\\
\headdw{Some Encryption Modes:}
\begin{itemize}
\item \subheadwo{Electronic Code Book (ECB) Mode:}
\begin{itemize}
\item Each block is encrypted separately using the block cipher
\end{itemize}
%----------------------------------
\item \subheadwo{Cipher Block Chaining (CBC) Mode:}
\begin{itemize}
\item Encrypt the XOR of the block with the ciphertext of the previous block
\end{itemize}
%----------------------------------
\item Counter Mode
\item \subheadwo{$\ldots$}
\end{itemize}
\end{frame}
%----------------------------------------------------------------------------------
%----------------------------------------------------------------------------------
%-------------------------------------------------------------------
%----------------------------------------------------------------------------------
%----------------------------------------------------------------------------------
%-------------------------------------------------------------------
\begin{frame}
  \frametitle{Modes of Encryption}
  \begin{itemize}
  \item ECB Encryption:
\begin{figure}
\shrinkfigg
	\begin{tikzpicture}
        \foreach \x in {0, 1, 2} {
            \node (f\x) at ($\x*(2cm,0)$) [minimum size=0.75cm,rounded corners=1ex,fill=red!20,draw] {{\sc Enc}};
            \node (m\x) [above of=f\x, node distance=1cm] {$P_\x$};
            \node (k\x) [left of=f\x, node distance=1cm] {$k$};
            \node (c\x) [below of=f\x, node distance=1cm] {$C_\x$};
            \draw[-latex] (m\x) -- (f\x);
            \draw[-latex] (k\x) -- (f\x);
            \draw[-latex] (f\x) -- (c\x);
        } 

        \begin{scope}
            \node at (5.4,0) {$\cdots$};
        \end{scope}
        \begin{scope}
            \node (f) at (7.4cm,0) [minimum size=0.75cm,rounded corners=1ex,fill=red!20,draw] {{\sc Enc}};
            \node (m) [above of=f, node distance=1cm] {$P_n$};
            \node (k) [left of=f, node distance=1cm] {$k$};
            \node (c) [below of=f, node distance=1cm] {$C_n$};
            \draw[-latex] (m) -- (f);
            \draw[-latex] (k) -- (f);
            \draw[-latex] (f) -- (c);
        \end{scope}
        
    \end{tikzpicture}
\end{figure}
\item CBC Encryption:
\begin{figure}
\shrinkfigg
\vspace{-4mm}
    \begin{tikzpicture}
        \foreach \x in {0, 1, 2} {
            \node (f\x) at ($\x*(2.1cm,0)$) [minimum size=0.75cm,rounded corners=1ex,fill=red!20,draw] {{\sc Enc}};
            \node (p\x) [above of=f\x, node distance=1cm, circle, draw] {};
            \node (m\x) [above of=p\x, node distance=0.90cm] {$P_\x$};
            \node (k\x) [left of=f\x, node distance=1cm] {$k$};
            \node (c\x) [below of=f\x, node distance=1.2cm] {$C_\x$};
            \draw[-] (p\x.north) -- (p\x.south);
            \draw[-] (p\x.east) -- (p\x.west);
            \draw[-latex] (m\x) -- (p\x);
            \draw[-latex] (p\x) -- (f\x);
            \draw[-latex] (k\x) -- (f\x);
            \draw[-latex] (f\x) -- (c\x);
        }
        \node (iv) [left of=p0, node distance=1.5cm] {$IV$};
        \draw[-latex] (iv) -- (p0);

        \foreach \x in {0, 1} {
        \draw[-latex] ($(c\x) + (0,0.7cm)$) -| +(0.8cm,1.5cm) -- ($(p\x) + (2cm,0)$);

        \begin{scope}
            \node at (5.4,0) {$\cdots$};
        \end{scope}

        \begin{scope}
            \node (f) at (8cm,0) [minimum size=0.75cm,rounded corners=1ex,fill=red!20,draw] {{\sc Enc}};
            \node (p) [above of=f, node distance=1cm, circle, draw] {};
            \node (m) [above of=p, node distance=0.90cm] {$P_n$};
            \node (k) [left of=f, node distance=1cm] {$k$};
            \node (c) [below of=f, node distance=1.2cm] {$C_n$};
            \draw[-] (p.north) -- (p.south);
            \draw[-] (p.east) -- (p.west);
            \draw[-latex] (m) -- (p);
            \draw[-latex] (p) -- (f);
            \draw[-latex] (k) -- (f);
            \draw[-latex] (f) -- (c);
            \draw[-] ($(c) + (-2.5,0.7cm)$) -- ($(c) + (-1.7,0.7cm)$);
            \draw[-latex] ($(c) + (-1.7,0.7cm)$) |- + (0cm,1.5cm) -- (p);
        \end{scope}
        }
\end{tikzpicture}
\end{figure}
\end{itemize}
\end{frame}
%----------------------------------------------------------------------------------
%----------------------------------------------------------------------------------
%-------------------------------------------------------------------
\begin{frame}
  \frametitle{Modes of Encryption}
\begin{figure}
  \shrinkfigg
    \begin{tikzpicture}
        \foreach \x in {0, 1, 2} {
            \node (f\x) at ($\x*(2.5cm,0)$) [minimum size=1cm,rounded corners=1ex,fill=red!20,draw] {{\sc Enc}};
            \node (n\x) [above =0.75cm of f\x, node distance=1.5cm] {Nonce, Ctr};
            \node (c\x) [below =1.5cm of f\x, node distance=2.5cm] {$P_\x$};
            \node (k\x) [left of=f\x, node distance=1.5cm] {$k$};
            \node (p\x) [below of=f\x, node distance=1.5cm, circle, draw] {};
            \node (m\x) [left of=p\x, node distance=1.0cm] {$C_\x$};
            \draw[-] (p\x.north) -- (p\x.south);
            \draw[-] (p\x.east) -- (p\x.west);
            \draw[-latex] (m\x) -- (p\x);
            \draw[-latex] (n\x) -- (f\x);
            \draw[-latex] (f\x) -- (p\x);
            \draw[-latex] (k\x) -- (f\x);
            \draw[-latex] (p\x) -- (c\x);
        }

        \begin{scope}
            \node at (6.5,0) {$\cdots\cdots$};
        \end{scope}

        \begin{scope}
            \node (f) at (8.8cm,0) [minimum size=1.25cm,rounded corners=1ex,fill=red!20,draw] {{\sc Enc}};
            \node (n) [above of=f, node distance=1.5cm] {Nonce, Ctr};
            \node (c) [below of=f, node distance=2.5cm] {$P_n$};
            \node (k) [left of=f, node distance=1.5cm] {$k$};
            \node (p) [below of=f, node distance=1.5cm, circle, draw] {};
            \node (m) [left of=p, node distance=1.0cm] {$C_n$};
            \draw[-] (p.north) -- (p.south);
            \draw[-] (p.east) -- (p.west);
            \draw[-latex] (m) -- (p);
            \draw[-latex] (n) -- (f);
            \draw[-latex] (f) -- (p);
            \draw[-latex] (k) -- (f);
            \draw[-latex] (p) -- (c);
        \end{scope}

    \end{tikzpicture}
\end{figure}
\end{frame}
%----------------------------------------------------------------------------------
%----------------------------------------------------------------------------------
%-------------------------------------------------------------------
\begin{frame}
  \frametitle{CBC vs.~ECB}

\begin{figure}
\centering
\includegraphics[width=.38\textwidth,height=.20\textheight]{./Images/ImgPlain.jpg}
\caption{Original Image [Wiki]}
\end{figure}
\begin{figure}
    \centering
    \begin{subfigure}[b]{0.48\textwidth}
        \centering
        \includegraphics[width=.60\textwidth,height=.20\textheight]{./Images/ImgECB.jpg}
        \caption{AES-ECB [Wiki]}
        \label{fig:gull}
    \end{subfigure}
    \begin{subfigure}[b]{0.48\textwidth}
        \centering
        \includegraphics[width=.60\textwidth,height=.20\textheight]{./Images/ImgCBC.jpg}
        \caption{AES-CBC [Wiki]}
        \label{fig:mouse}
    \end{subfigure}
\end{figure}
\textcolor{red}{\bf{Note:}} 
In ECB Mode similar plaintext blocks produce similar ciphertext blocks (not good!)
\end{frame}

%----------------------------------------------------------------------------------
%----------------------------------------------------------------------------------
%----------------------------------------------------------------------------------
%-------------------------------------------------------------------
%-------------------------------------------------------------------

\begin{frame}
  \frametitle{What is Next?}
 \begin{itemize}
 \item {Hash Functions \& MACs}
 \end{itemize}

\end{frame}
%-------------------------------------------------------------------
%-------------------------------------------------------------------
%-------------------------------------------------------------------
%-------------------------------------------------------------------
\end{document}

