\definitionbox{Security Against Chosen-Plaintext Attacks (CPA Security)}{
Let $\Sigma$ be an encryption scheme, and let $\Sigma.\mathcal{C}(\ell)$ denote the set of possible ciphertexts for plaintexts of length $\ell$. If $\Sigma$ supports only plaintexts of a single length, we can simply write $\Sigma.\mathcal{C}$ to denote the entire set of ciphertexts.\footnote{i.e. ``just forget about the length''.}\\[0.5em]
$\Sigma$ has security against \textbf{chosen-plaintext attacks} if the following two libraries are indistinguishable:
}
\end{column}
\begin{column}{0.4\textwidth}
\sslinked{
\sslibrary{\Sigma}{cpa-real}{
$K \twoheadleftarrow\Sigma.\mathcal{K}$\\[1em]
\sslibrarysubroutine{cpa.enc}{M}{
$C \coloneq\Sigma.\texttt{Enc}(K, M)$\\
return $C$
}{1}
}{0.8}
}{\approxeq}{
\sslibrary{\Sigma}{cpa-rand}{
\sslibrarysubroutine{cpa.enc}{M}{
$C \twoheadleftarrow\Sigma.\mathcal{C}(|M|)$\\
return $C$
}{1}
}{0.8}
}
\end{column}
\end{columns}
\end{frame}
\begin{frame}{Why CPA security matters}
\begin{itemize}[<+->]
\item CPA security means: \textit{``even if I let you encrypt any message you want, you can't obtain any distinguisher regarding my scheme.''}
\item\textbf{Why this matters in real life:}
\begin{itemize}[<+->]
\item Attackers often can trick systems into encrypting data they choose.
\item Without CPA security, seeing these encryptions could reveal your secrets.
\item Example: If bank transactions always encrypt to the same ciphertexts, attackers could identify your purchases.
\end{itemize}
\item The only thing that's allowed to leak is the length of messages/ciphertext.
\item Most modern encryption is designed to have this important property.
\end{itemize}
\end{frame}
\begin{frame}{Message length: not important, not unimportant}
\begin{itemize}[<+->]
\item Even with CPA security, the \textbf{length} of messages is still leaked.
\item This seemingly minor leak can reveal surprising information:
\begin{itemize}[<+->]
\item\textbf{Encrypted VoIP calls}: Length patterns can reveal which language is spoken.
\item\textbf{Encrypted web traffic}: Sizes of requests/responses identify websites.
\item\textbf{Encrypted messages}: Length patterns can reveal the type of content (document, image, etc.)
\item\textbf{Encrypted commands}: Length often reveals which command was issued.
\end{itemize}
\item Mitigation typically involves padding messages to fixed lengths or standard increments.
\item This is why many secure protocols use fixed-size packets or add random padding.
\end{itemize}
\end{frame}
\begin{frame}{CPA security is why we avoid deterministic encryption}
\begin{columns}[c]
\begin{column}{0.5\textwidth}
\begin{itemize}[<+->]
\item Deterministic encryption will always fail CPA security!
\item If the same message always encrypts to the same ciphertext:
\begin{itemize}
\item Attacker can recognize repeat messages.
\item Can build a ``dictionary'' of known plaintexts.
\item etc.
\end{itemize}
\item ECB mode is a classic example of insecure deterministic encryption.
\item AES-CTR turns AES into a non-deterministic PRF...
\item AES-GCM even turns it into a non-deterministic authenticated cipher...\footnote{More on these later. An authenticated cipher is one where the ciphertext can't be modified by the adversary without that being detected.}
\item We can just as easily make a PRF non-deterministic:
\end{itemize}
\end{column}
\begin{column}{0.5\textwidth}
\sssubroutine{enc}{K, M}{
$R \twoheadleftarrow\bits^\lambda$\\
$S \coloneq F(K, R)\oplus M$\\
return $R\|S$
}{1}
\end{column}
\end{columns}
\end{frame}
\begin{frame}{...but it can be fragile}
\begin{columns}[c]
\begin{column}{0.5\textwidth}
\begin{itemize}[<+->]
\item We switch M and R's places in \lib{}{cpa-real}'s encryption function.
\item Is the scheme still secure?
\item\textbf{No!}
\end{itemize}
\end{column}
\begin{column}{0.5\textwidth}
\sslinked{
\sslibrary{}{cpa-real}{
$K \twoheadleftarrow\bits^\lambda$\\[1em]
\sslibrarysubroutine{cpa.enc}{M}{
$R \twoheadleftarrow\bits^\lambda$\\
$S \coloneq F(K, \hl{M})\oplus\hl{R}$\\
return $R\|S$
}{1}
}{1}
}{\overset{?}{\approxeq}}{
\sslibrary{}{cpa-rand}{
\sslibrarysubroutine{cpa.enc}{M}{
$R\|S \twoheadleftarrow\bits^{2\lambda}$\\
return $R\|S$
}{1}
}{1}
}
\end{column}
\end{columns}
\end{frame}
\begin{frame}{The Golden Rule of PRFs}
\definitionbox{The Golden Rule of PRFs}{
If a PRF $F$ is being used as a component in a larger construction $H$, then security usually rests on how well $H$ can ensure distinct inputs to $F$.
}
\begin{itemize}[<+->]
\item When analyzing PRF security, focus on input uniqueness.
\item Repeated inputs to a PRF create exploitable patterns.
\item Even if $F$ is secure, $H$ can be broken if it causes $F$ to receive duplicate inputs.
\item Don't try to directly distinguish $F$'s outputs from uniform.
\item Instead, exploit how $H$ uses $F$ incorrectly.
\item Find input patterns that force collisions within $F$.
\item IV is fancy name for ``random bytes used once''.\footnote{Also referred to as ``nonces'' for ``number used once'', although in some block cipher modes such as AES-CBC, they can technically be used multiple times without problems.}
\end{itemize}
\item IVs ensure the same plaintext encrypts differently each time.
\end{itemize}
\item Without a proper mode, AES is like ECB mode: predictable patterns
\item Scenario: victim using CTR mode decryption reveals if result contains a null character.
\item Information can leak through crashes, error messages, or behavior differences.
\item A single yes/no bit of information can be enough to break encryption!
\item Malleability: many encryption schemes allow attackers to make predictable changes to plaintexts by modifying ciphertexts.
\item CTR mode is especially vulnerable because XOR allows targeted bit-flipping.
\end{itemize}
\end{column}
\begin{column}{0.4\textwidth}
\sssubroutine{nulloracle}{C}{
$M \coloneq\texttt{CTR.Dec}(K, C)$\\
if $M$ contains $\bit{0}\bit{0}$ character:\\
$\quad$ return $\texttt{true}$\\
else return $\texttt{false}$
}{1}
\end{column}
\end{columns}
\end{frame}
\begin{frame}{Why is it called \func{nulloracle}{c}?}
\begin{columns}[c]
\begin{column}{0.5\textwidth}
\begin{itemize}
\item In mythology and colloquial language:
\begin{itemize}
\item An oracle was a mystic who answered questions on behalf of the gods.
\item Often gave enigmatic answers requiring interpretation.
\end{itemize}
\end{itemize}
\end{column}
\begin{column}{0.5\textwidth}
\vspace{-0.4cm}
\bigimagewithcaption{oracle_painting_zoom.jpg}{\textit{The Oracle} by Camillo Miola, 1880\footnote{Absolutely beautiful painting, well-worth viewing in high resolution: \url{https://upload.wikimedia.org/wikipedia/commons/9/94/Camillo_Miola_\%28Biacca\%29_-_The_Oracle_-_72.PA.32_-_J._Paul_Getty_Museum.jpg}}}
\end{column}
\end{columns}
\end{frame}
\begin{frame}{Why is it called \func{nulloracle}{c}?}
\begin{itemize}[<+->]
\item In cryptography and computer science:
\begin{itemize}
\item An oracle is an algorithm that solves a specific problem.
\item You can query it but can't see its internal workings.
\item Oracles are often used as theoretical tools in security proofs.
\end{itemize}
\item Our \func{nulloracle}{c} reveals only:
\begin{itemize}
\item Whether a decrypted ciphertext contains null (\bit{0}\bit{0}) characters.
\item Just a single bit of information (yes/no).
\end{itemize}
\end{itemize}
\end{frame}
\begin{frame}{Null-oracle attack}
\begin{columns}[c]
\begin{column}{0.6\textwidth}
\begin{itemize}[<+->]
\item An adversary who has access to \func{nulloracle}{C} can efficiently compute \texttt{Dec}$(K, C)$ for any $C$!
\item Yes, it really is enough.
\end{itemize}
\end{column}
\begin{column}{0.4\textwidth}
\sssubroutine{nulloracle}{C}{
$M \coloneq\texttt{CTR.Dec}(K, C)$\\
if $M$ contains $\bit{0}\bit{0}$ character:\\
$\quad$ return $\texttt{true}$\\
else return $\texttt{false}$
}{1}
\end{column}
\end{columns}
\end{frame}
\begin{frame}{CTR mode is malleable}{Defining malleability}
\begin{columns}[c]
\begin{column}{0.5\textwidth}
\definitionbox{Malleability}{
An encryption scheme is \textbf{malleable} if, given an encryption $C$ of an unknown plaintext $M$, it is possible to create a new ciphertext $C' \neq C$ where $M' =\texttt{Dec}(K, C')$ is somehow related to $M$, so that $M'$ reveals some information about $M$.
}
\end{column}
\begin{column}{0.5\textwidth}
\begin{itemize}[<+->]
\item In CTR mode: $C_i = F(K, C_0+ i -1)\oplus M_i$
\item Flipping a bit in $C_i$ flips exactly the same bit in $M_i$.
\item Attackers can make targeted modifications without knowing the key.
\item Example: change ``transfer \$100'' to ``transfer \$900'' by modifying just one byte.
\end{itemize}
\end{column}
\end{columns}
\end{frame}
\begin{frame}{CTR mode is malleable}{Defining malleability}
\begin{columns}[c]
\begin{column}{0.5\textwidth}
\begin{itemize}
\item In CTR mode: $C_i = F(K, C_0+ i -1)\oplus M_i$
\item Flipping a bit in $C_i$ flips exactly the same bit in $M_i$.
\item Attackers can make targeted modifications without knowing the key.
\item Example: change ``transfer \$100'' to ``transfer \$900'' by modifying just one byte.
\end{itemize}
\end{column}
\begin{column}{0.5\textwidth}
\imagewithcaption{ctr_dec.pdf}{CTR mode decryption.\\Source: The Joy of Cryptography}
\end{column}
\end{columns}
\end{frame}
\begin{frame}{CTR mode is malleable}{Defining malleability}
\begin{columns}[c]
\begin{column}{0.5\textwidth}
\begin{itemize}
\item In CTR mode: $C_i = F(K, C_0+ i -1)\oplus M_i$
\item Flipping a bit in $C_i$ flips exactly the same bit in $M_i$.
\item Attackers can make targeted modifications without knowing the key.
\item Example: change ``transfer \$100'' to ``transfer \$900'' by modifying just one byte.
\end{itemize}
\end{column}
\begin{column}{0.5\textwidth}
\imagewithcaption{ctr_dec_delta.pdf}{CTR mode decryption.\\Source: The Joy of Cryptography}
\end{column}
\end{columns}
\end{frame}
\begin{frame}{CTR mode is malleable}{The attack}
\begin{columns}[c]
\begin{column}{0.5\textwidth}
\begin{itemize}[<+->]
\item Suppose adversary captures ciphertext $C$ and wants to find plaintext $M =\texttt{Dec}(K, C)$.
\item Let's focus on discovering just the last byte of $M$.
\item If the last byte of $M$ is $b$, then $M = M' \| b$.
\item What if we modify the ciphertext by XORing the last byte with $b$?
\item This would turn the last byte of the plaintext into all zeros (null byte)!
\end{itemize}
\end{column}
\begin{column}{0.5\textwidth}
\begin{align*}
C \oplus (\ldots\bit{0}\bit{0}\| b) &\text{ decrypts to:}\\
& M \oplus (\ldots\bit{0}\bit{0}\| b) \\
& = (M' \| b) \oplus (\ldots\bit{0}\bit{0}\| b) \\
& = M' \| (b \oplus b) \\
& = M' \|\bit{0}\bit{0}
\end{align*}
\end{column}
\end{columns}
\end{frame}
\begin{frame}{CTR mode is malleable}{Finding one byte}
\begin{columns}[c]
\begin{column}{0.5\textwidth}
\begin{itemize}[<+->]
\item Problem: We don't know $b$ in advance!
\item Solution: Try all 255 possible values for $b$.
\item For each guess $g$, we:
\begin{itemize}
\item Create $C' = C \oplus(\ldots\bit{0}\bit{0}\| g)$
\item Send $C'$ to the \func{nulloracle}{}
\item If oracle returns \texttt{true}, then $g = b$!
\end{itemize}
\item When we find the right value, we've discovered the last byte of $M$.
\item This created an oracle revealing: ``Is $\texttt{Dec}(K, C)$ a valid gzip file?''\footnote{\url{https://appliedcryptography.page/papers/\#jhu-imessage}}
A MAC is a cryptographic function that takes a key $K$ and a message $M$ and produces a tag $T$ that authenticates the message. Only someone with the same key can verify the tag.
}
\end{column}
\begin{column}{0.5\textwidth}
\begin{itemize}[<+->]
\item A MAC provides \textbf{integrity} and \textbf{authenticity} for messages.
\item Unlike hash functions, MACs require a secret key
\item MACs address the malleability problem we saw with encryption schemes. Without a MAC, attackers could modify ciphertexts.
\item A secure MAC should be unforgeable, even after seeing MACs for chosen messages.
\end{itemize}
\end{column}
\end{columns}
\end{frame}
\begin{frame}{PRFs as MACs}
\begin{columns}[c]
\begin{column}{0.4\textwidth}
\begin{itemize}[<+->]
\item A pseudorandom function (PRF) can be used directly as a MAC!
\item The MAC key is the PRF key $K$.
\item To authenticate a message $X$:
\begin{itemize}
\item Compute the tag $T = F(K, X)$
\item Send both $X$ and $T$ to the recipient
\end{itemize}
\end{itemize}
\end{column}
\begin{column}{0.6\textwidth}
\begin{flushright}
\sslinked{
\sslibrary{}{mac-real}{
$K \twoheadleftarrow\bits^\lambda$\\[1em]
\sslibrarysubroutine{mac.guess}{X, Y}{
return $Y == F(K, X)$
}{1}\\[1em]
\sslibrarysubroutine{mac.reveal}{X}{
return $F(K, X)$
}{1}
}{0.75}
}{\approxeq}{
\sslibrary{}{mac-ideal}{
\sslibrarysubroutine{mac.guess}{X, Y}{
if $L[X]$ undefined: return $\texttt{false}$\\
return $Y == L[X]$
}{1}\\[1em]
\sslibrarysubroutine{mac.reveal}{X}{
if $L[X]$ undefined: $L[X]\twoheadleftarrow\bits^\lambda$\\
return $L[X]$
}{1}
}{0.75}
}
\end{flushright}
\end{column}
\end{columns}
\end{frame}
\begin{frame}{From CPA to CCA security}{The Encrypt-then-MAC approach}
\begin{itemize}[<+->]
\item CPA security isn't enough in the real world.
\item We need protection against chosen-ciphertext attacks.
\item Solution: combine encryption with a MAC!.
\item\textbf{Encrypt-then-MAC}:
\begin{itemize}
\item Encrypt the message normally.
\item Compute a MAC tag of the \textit{ciphertext}.
\item Send both ciphertext and tag.
\item Receiver verifies the tag before decrypting.
\end{itemize}
\item This prevents adversaries from creating valid modified ciphertexts.
\begin{frame}{Replay attacks}{Step 1: Alice sends original message}
\bigimagewithcaption{aead_scenario_1.pdf}{Source: The Joy of Cryptography}
\end{frame}
\begin{frame}{Replay attacks}{Step 2: Attacker replays message in a different context}
\bigimagewithcaption{aead_scenario_2.pdf}{Source: The Joy of Cryptography}
\end{frame}
\begin{frame}{Replay attacks}{Authenticated encryption didn't save us}
\begin{itemize}
\item Even with authenticated encryption, context matters!
\item Scenario: Alice sends Bob encrypted commands.
\begin{itemize}
\item Each ciphertext contains Alice's genuine intent.
\item Bob trusts any ciphertext that decrypts successfully.
\end{itemize}
\item Vulnerability: An adversary can replay legitimate ciphertexts.
\begin{itemize}
\item Alice once sent ``Delete temporary files''.
\item Adversary replays it when Alice meant to say ``Display files''.
\end{itemize}
\end{itemize}
\end{frame}
\begin{frame}{Associated data}
\begin{itemize}[<+->]
\item Solution 1: Include context in the plaintext
\begin{itemize}
\item ``\texttt{ACTION: DISPLAY}'' before the actual message.
\item Inefficient - increases message size.
\item Both parties already know the context.
\end{itemize}
\item Better solution: Associated Data (AD)
\begin{itemize}
\item Context that sender and receiver already know.
\item Used during encryption and decryption.
\item Doesn't increase ciphertext size.
\end{itemize}
\item How it works:
\begin{itemize}
\item$\texttt{Enc}(K, A, M)\rightarrow C$ where $A$ is associated data.
\item$\texttt{Dec}(K, A, C)\rightarrow M$ or $\texttt{err}$
\end{itemize}
\end{itemize}
\end{frame}
\begin{frame}{AEAD: formal definition}
\begin{columns}[c]
\begin{column}{0.5\textwidth}
\definitionbox{AEAD}{
An encryption scheme $\Sigma$ with associated data is a secure authenticated encryption with associated data (AEAD) scheme if the following two libraries are indistinguishable:
}
\end{column}
\begin{column}{0.5\textwidth}
\begin{flushright}
\sslinked{
\sslibrary{\Sigma}{aead-real}{
$K \twoheadleftarrow\Sigma.\mathcal{K}$\\[1em]
\sslibrarysubroutine{aead.enc}{A, M}{
return $\Sigma.\texttt{Enc}(K, A, M)$
}{1}\\[1em]
\sslibrarysubroutine{aead.dec}{A, C}{
return $\Sigma.\texttt{Dec}(K, A, C)$
}{1}
}{0.75}
}{\approxeq}{
\sslibrary{\Sigma}{aead-rand}{
\sslibrarysubroutine{aead.enc}{A, M}{
$C \twoheadleftarrow\Sigma.\mathcal{C}(|M|)$\\
$\mathcal{D}[A, C]\coloneq M$\\
return $C$
}{1}\\[1em]
\sslibrarysubroutine{aead.dec}{A, C}{
if $\mathcal{D}[A, C]$ defined:\\
\quad return $\mathcal{D}[A, C]$\\
else: return $\texttt{err}$
}{1}
}{0.75}
}
\end{flushright}
\end{column}
\end{columns}
\end{frame}
\begin{frame}{Usefulness of AEADs}
\begin{itemize}[<+->]
\item AEAD (Authenticated Encryption with Associated Data) scheme guarantees:
\begin{itemize}
\item Ciphertexts reveal nothing about plaintexts (confidentiality).
\item Only ciphertexts created by the legitimate sender will decrypt without error (authenticity).
\item Decryption only succeeds when the correct associated data is used (context binding).
\end{itemize}
\item What to use as associated data?
\begin{itemize}
\item Protocol information: ``\texttt{DISPLAY}'' vs ``\texttt{DELETE}''.
\item Session identifiers or timestamps.
\item Previous messages in the conversation.
\item Any contextual information both parties already know.
\end{itemize}
\item Use as much associated data as relevant - it's cryptographically ``free''!
\end{itemize}
\end{frame}
\begin{frame}{Solution: use associated data to provide context}
\bigimagewithcaption{aead_scenario_4.pdf}{Source: The Joy of Cryptography}