278 lines
16 KiB
TeX
278 lines
16 KiB
TeX
\documentclass{article}
|
||
\usepackage[utf8x]{inputenc}
|
||
\usepackage[margin=1in]{geometry} % Adjust margins
|
||
\usepackage{caption}
|
||
\usepackage{wrapfig}
|
||
\usepackage{subcaption}
|
||
\usepackage{parskip} % dont indent after paragraphs, figures
|
||
\usepackage{xcolor}
|
||
%\usepackage{csquotes} % Recommended for biblatex
|
||
\usepackage{tikz}
|
||
\usepackage{pgfplots}
|
||
\usetikzlibrary{positioning}
|
||
\usepackage{float}
|
||
\usepackage{amsmath}
|
||
\PassOptionsToPackage{hyphens}{url}
|
||
\usepackage{hyperref} % allows urls to follow line breaks of text
|
||
\usepackage[style=ieee, backend=biber, maxnames=1, minnames=1]{biblatex}
|
||
\addbibresource{crypto.bib}
|
||
\usepackage{glossaries}
|
||
|
||
\newcommand{\ub}[2]{\underbrace{\text{#1}}_{\text{#2}}}
|
||
\newcommand{\secret}[1]{\textcolor{red}{#1}}
|
||
\newcommand{\public}[1]{\textcolor{blue}{#1}}
|
||
\makeglossaries
|
||
\newacronym{DES}{DES}{Data Encryption Standard}
|
||
\newacronym{AES}{AES}{Advanced Encryption Standard}
|
||
\newacronym{RSA}{RSA}{Rivest–Shamir–Adleman}
|
||
\newacronym{mitm}{MITM}{Man-in-the-middle attack}
|
||
\newacronym{CA}{CA}{Certificate Authority}
|
||
|
||
|
||
|
||
|
||
\title{Cryptography}
|
||
\date{\today}
|
||
|
||
\begin{document}
|
||
\maketitle
|
||
\section{Introduction}
|
||
Cryptography is ubiquitous in our modern world.
|
||
While the origins of cryptography date back thousands of years, evidence of its use in ancient times is sparse.
|
||
\cite{luenberger}
|
||
Historically, most of its use seemed to be reserved for political and military leaders, e.g. notably Mary Queen of Scots,
|
||
who while in prison, plotted to kill Queen Elizabeth using encrypted letters \cite{enwiki:maryofscots}.
|
||
Much later, with the widespread adoption of the internet, the need for several cryptographical functions arose.
|
||
Due to its intended use as a trusted research network (ARPANET),
|
||
almost none of the original protocols were 'secure' in any sense of the word.
|
||
|
||
One of the most notable examples still today is SMTP, the \textit{Simple Mail Transfer Protocol}, used to send email to servers.
|
||
In its original implementation, it allowed attackers to intercept emails in transit to read and modify them
|
||
and even spoof the sender address to impersonate others.
|
||
SMTP today is secured using a combination of mitigations for these attacks, such as STARTTLS, SPF, DKIM and DMARC,
|
||
emphasizing the need for securely designed protocols.
|
||
|
||
\subsection{Security}
|
||
Common goals associated with security include the \textit{CIA triad}, consisting of
|
||
\begin{itemize}
|
||
\item Confidentiality: Prevent unauthorized reading
|
||
\item Integrity: Prevent unauthorized modification
|
||
\item Availability: Prevent denial of service
|
||
\end{itemize}
|
||
With further goals including Authenticity and Non-repudiation. Cryptography can help with all of the aforementioned goals
|
||
except availability.
|
||
This can be achieved using several different applications of cryptography:
|
||
\begin{itemize}
|
||
\item Encryption provides confidentiality by only saving / transmitting an encrypted message.
|
||
\item Hash functions ensure data has not been altered.
|
||
\item Digital signatures confirm a message was indeed sent by who we expect it to be, preventing man-in-the-middle attacks
|
||
where the message is simply swapped out before reaching its destination, as well as providing proof a message was sent (Non-repudiation).
|
||
\item Certificates confirm the sender's identity.
|
||
\end{itemize}
|
||
|
||
Importantly, Kerckhoff's principle \cite{enwiki:kerckhoff} is what allows us to go into detail on the following algorithms.
|
||
Embraced by researchers today, it holds that the security of a cryptosystem should only rely on the secrecy of the key,
|
||
allowing and encouraging the publication of cryptographic algorithms. \newline
|
||
It is closely related to Shannon's maxim, stating that
|
||
"one ought to design systems under the assumption that the enemy will immediately gain full familiarity with them".
|
||
This is opposed to \textit{security through obscurity}, which doesnt allow for verification of the cryptographic
|
||
algorithm through a scientific process in the public domain.
|
||
|
||
|
||
\subsection{Hash Functions}
|
||
A general hash function $h(m)$ is a function that takes a message $m$ of arbitrary and produces an output $h$ called \textit{hash}
|
||
of fixed length. However, not every mathematical function can be considered a hash function.
|
||
The main applications of hash functions include integrity checking and hash maps for efficient data retrieval.
|
||
Depending on the applications, different properties determine the usefulness of a function.
|
||
|
||
An obvious desired property is efficiency - every application benefits from faster computing times.
|
||
Also central to all applications of hash functions is a property called \textit{collision resistance}, where there should be no
|
||
efficient way, i.e. no better way than brute force to find $m_1 \neq m_2$ so that $h(m_1) = h(m_2)$.
|
||
Again, for encryption the importance is clear. If a password is stored in hashed form to obfuscate the clear text,
|
||
no security is gained if it is easy for an attacker to find a password that produces the same hash and thus passes the challenge.
|
||
A similar notion holds true for data retrieval. If it is too easy to find collisions, e.g. similar inputs produce similar outputs,
|
||
there will be an uneven distribution in the target domain and thus little to no efficiency gain.
|
||
|
||
Another desired property, specifically for encryption is what is usually used synonymously with a hash function: a \textit{one-way function}.
|
||
Given $h(m)$, there should be no method more efficient than brute force to find a matching $m$. \newline
|
||
As alluded to earlier, hash functions are readily used for integrity checking.
|
||
By generating a fixed-size hash value for a given input, they allow users to verify that data has not been altered,
|
||
whether intentionally or accidentally.
|
||
For example, when downloading a file, comparing its hash with a published checksum ensures the file's integrity.
|
||
They are also often used in combination with public key cryptography, allowing the sender to sign with his private key
|
||
to prove not only integrity but authenticity.
|
||
|
||
|
||
\subsection{Encryption}
|
||
Even though the properties of hash functions are similar to encryption, the fact that the input message is reduced to a fixed size hash
|
||
also means that inevitably information is lost by every hash function.
|
||
Fundamentally, encryption has the goal of only allowing authorized parties to read a message.
|
||
This is achieved by encoding the \textit{plaintext} into a \textit{ciphertext} and then transmitting/storing that ciphertext
|
||
separately from the necessary key to decrypt it.
|
||
|
||
Early encryptions intuitively demonstrate two concepts that can be employed to encode a message:
|
||
\textit{substitution} and \textit{transposition}.
|
||
|
||
\paragraph{Substitution} is used by
|
||
the simple Caesar cipher, often achieved by rotating two disks against each other, each with the alphabet written out on them.
|
||
\autoref{tab:caesar} shows a simple caesar cipher where the cipher alphabet is simply shifted by $+3$ positions from the plaintext alphabet.
|
||
In the process of encoding, A is therefore replaced (substituted) with D, B with E, and so on.
|
||
Upon reception of the message, the same process is done in reverse, i.e. shifted by $-3$.
|
||
|
||
\begin{table}[h]
|
||
\resizebox{\textwidth}{!}{
|
||
\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}
|
||
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
|
||
D&E&F&G&H&I&J&K&L&M&N&O&P&Q&R&S&T&U&V&W&X&Y&Z&A&B&C
|
||
|
||
\end{tabular}
|
||
}
|
||
\caption{A simple substitution cipher demonstrated by a 3-letter shift.}
|
||
\label{tab:caesar}
|
||
\end{table}
|
||
|
||
This simple encryption is easy to break however for several reasons.
|
||
Caesar ciphers in general only offer 26 different keys as further shifts only wrap around to e.g. $29 \mod 26 = 3$, with a shift of 26
|
||
being equal to the cleartext. \newline
|
||
Furter, by shifting every letter by the same amount,
|
||
properties of the source language such as word spacing and letter frequencies are retained in the ciphertext,
|
||
leaving it vulnerable to simple statistical attacks.
|
||
|
||
|
||
\paragraph{Transposition} is the process of reordering the plaintext to obtain a ciphertext.
|
||
Here, the key can be understood as instructions on how to re-order the ciphertext to obtain the original message.
|
||
The \textit{scytale} is one of the earliest implementations of a transposition cipher.
|
||
The implementation involves a rope or band of text as well as a stick of known circumference as the key.
|
||
The band is wrapped in a spiral around the stick and the message written across the spiral.
|
||
When the stick is removed and the band unwrapped, the letters on the band appear scrambled by a fixed offset determined
|
||
by the stick's circumference.
|
||
|
||
\paragraph{Diffusion} is one of two properties of a secure cipher introduced by Shannon in 1945.
|
||
It is closely related to the \textit{collision resistance} of hash functions
|
||
and means that for a 1-bit change of the plaintext, about half the bits of the ciphertext should change.
|
||
The purpose of diffusion is to hide the statistical statistical relationship between plaintext and ciphertext
|
||
exhibited by simple encryption methods.
|
||
% Block ciphers achieve this by "diffusing" the information about the plaintext's structure across the rows and columns of the cipher.
|
||
|
||
\paragraph{Confusion} similarly aims to obscure the connection of ciphertext and key,
|
||
requiring each bit of the ciphertext to depend on multiple parts of the key.
|
||
Confusion and diffusion are often mistaken for substitution and transposition, as block ciphers achieve
|
||
confusion through substitution boxes (S-box) and
|
||
diffusion through permutation boxes (P-box).
|
||
\cite{enwiki:confusion-diffusion}
|
||
|
||
\section{Symmetric Encryption}
|
||
\subsection{DES}\label{sec:des}
|
||
The \acrfull{DES} is a symmetric (or private-key) cipher developed in the 1970s at IBM as an archetypal block cipher.
|
||
It takes in a block of 64 bits and transforms it to a ciphertext using a key of equal length.
|
||
Despite suspicions of backdoors engineered into the algorithm due to the involvement of the NSA in the development of \acrshort{DES},
|
||
only minor weaknesses were found.
|
||
It was approved as a federal standard in the USA in 1976 and only retired due to its short key length,
|
||
for which the NSA however was directly responsible as well.
|
||
Nevertheless, it sparked public and scientific interest in the research of encryption algorithms, producing a large body of publications.
|
||
Extended versions of \acrshort{DES} such as Triple-DES (or 3DES) are still in use in embedded applications (chipcards).
|
||
|
||
In \acrshort{DES}, the message is encrypted in 16 rounds, as well as an initial and final permutation (IP and FP),
|
||
which are inverses. IP and FP were included to facilitate hardware loading of blocks.
|
||
After splitting the 64-Bit message into two 32-Bit blocks left (L) and right (R), the two halves are processed in the
|
||
16-round feistel network in a criss-cross pattern as follows:
|
||
\begin{itemize}
|
||
\item derive a 48-Bit \textit{round key} from the original 64-Bit \textit{main key} using a fixed \textit{key schedule}.
|
||
\item apply the \textit{Feistel function} to the R-block, which also applies the \textit{round key}.
|
||
\item XOR the right block to the left block.
|
||
\end{itemize}
|
||
Modern encryptions are commonly based on feistel networks as they make it easy to ensure bijection,
|
||
thus providing the necessary criterion for a cipher.
|
||
Further, due to the decryption process using the same algorithm with a reversed \textit{key schedule}
|
||
as well as the iterative nature of a feistel network,
|
||
they naturally lend themselves to hardware implementations.
|
||
|
||
\subsection{AES} %TODO
|
||
The \acrfull{AES} superseded \acrshort{DES} in 2001 after an official selection process.
|
||
Standardized under \verb|ISO 18033-3|, \acrshort{AES} supports key lengths of 128, 192 and 256 bits,
|
||
the underlying algorithm supports any key length that is a multiple of 32.
|
||
Developed as Rijndael, contrary to its predecessor it does not employ a Feistel network,
|
||
though it does use the familiar pattern of substitution and permutation boxes.
|
||
|
||
The key size used also specifies the number of rounds, as a round key is derived for each transformation round.
|
||
\begin{enumerate}
|
||
\item
|
||
\end{enumerate}
|
||
|
||
|
||
Though minor theoretical attacks exist, such as reducing the key search space by a factor of 4,
|
||
the algorithm can be considered secure even to quantum-computing supported attacks halving the key space,
|
||
as simply increasing the key length is a viable mitigation.
|
||
\cite{rijndael,enwiki:aes}
|
||
|
||
|
||
|
||
|
||
|
||
\section{Asymmetric Encryption}
|
||
Symmetric encryption however historically suffered from a key exchange problem;
|
||
because the same key is used for encryption and decryption, a secure channel is required to agree on a common key.
|
||
This chicken-and-egg problem can be solved in two major ways, both typically relying on the mathematical theory of
|
||
\textbf{galois fields}, employing either \textit{modular arithmetic} or \textit{elliptic curves}.
|
||
%NOTE section on galois fields/ modulo/elliptic curve?
|
||
|
||
\paragraph{The Difie-Hellman Key Exchange} is an algorithm allowing the communication parties to establish a shared secret using
|
||
properties of the discrete logarithm.
|
||
The algorithm is implemented by the following steps, with \public{public values} in blue and \secret{secret values} in red.
|
||
\begin{enumerate}
|
||
\item First, Alice and Bob publicly agree on prime numbers \public{$p$} and \public{$g$}.
|
||
\item Alice (and Bob, each on their own) choose their secret keys \secret{$a$} (\secret{$b$})
|
||
\item They then exchange
|
||
$\public{A} = \public{g}^{\secret{a}} \mod \public{p}$ and $\public{B} = \public{g}^{\secret{b}} \mod \public{p}$, respectively.
|
||
\item Both arrive at the same key $\secret{s}$ by computing $\secret{s} = \public{B}^{\secret{a}} \mod \public{p} =
|
||
\public{A}^{\secret{b}} \mod \public{p} $.
|
||
\end{enumerate}
|
||
|
||
Both methods however are still vulnerable to a \acrfull{mitm}, thus also requiring a trusted \acrfull{CA} for authentication. \cite{enwiki:mitm}
|
||
|
||
\subsection{RSA}\label{sec:rsa}
|
||
\acrfull{RSA} is the first asymmetric (or public-key) cryptographic algorithm and can thus be used for encryption and digital signing.
|
||
It was named after its eponymous inventors in \citeyear{rsa} after trying to disprove the existence of \textit{trapdoor functions},
|
||
a concept introduced by \citeauthor{diffiehellman} in their appropriately named pivotal paper \citetitle{diffiehellman} \cite{diffiehellman}.
|
||
|
||
|
||
The algorithm they came up with relies on modular arithmetic, which remains the most popular class of asymmetric cryptography.
|
||
|
||
\begin{enumerate}
|
||
\item Choose randomly and stochastically independet primes $\secret{p,q}$ of similar size so that
|
||
\newline$0.1 < | \log_2 p - \log_2 q | < 30 $.
|
||
\item Calculate $ \public{N}= \secret{p} \cdot \secret{q} $
|
||
\item Compute Euler's totient function of $ \secret{\varphi (N)} = (\secret{p}-1) \cdot (\secret{q}-1)$ which is kept secret.
|
||
\item Choose an integer $\public{e}$ so that $ 1 < \public{e} < \secret{\varphi (N)} $ and $\gcd(\public{e}, \secret{\varphi(N)}) =1$,
|
||
i.e. $\public{e}$ and $\secret{\varphi(N)}$ are coprime.
|
||
The most common choice here is $ e= 2^(16) +1 = 65537 $, as $\public{e}$ is released as part of the public key.
|
||
\item Calculate $ \secret{d} \equiv \public{e}^{-1}$, i.e. $\secret{d}\public{e} = 1\quad | \mod \secret{\varphi(N)}$
|
||
(modular multiplicative inverse).
|
||
\end{enumerate}
|
||
The \public{public key} consists of the modulus $N$ and the public exponent $e$.
|
||
The \secret{private key} consists of the private exponent $d$, as a result of which $p,q,\varphi(N)$ have to be kept secret as well.
|
||
|
||
In the encryption process, the ciphertext $c$ is obtained from the message $m$ by calculating $c \equiv m^e \mod N$.
|
||
After transmission, the message can then be recovered using the the private key exponent $d$ as follows:
|
||
\[ c^d \equiv (m^e)^d = m^{e*d} \equiv m^1 | \mod N \]
|
||
\clearpage
|
||
|
||
\section{Conclusion}
|
||
Trust on the web with untrusted channels fundamentally remains an unsolved issue,
|
||
though depending on the threat model, everyday communications can be considered relatively secure from non-APT actors.
|
||
A typical cipher suite employed by TLS to achieve this security could look like the following:
|
||
$$\ub{ECDHE}{Key exchange}-\ub{ECDSA}{authentication}-\ub{AES128}{encryption}-\ub{GCM}{Cipher operation mode}-\ub{SHA256}{hashing} $$
|
||
\begin{itemize}
|
||
\item \textbf{ECDHE} Elliptic Curve Diffie Hellman Exchange
|
||
\item \textbf{ECDSA} Elliptic Curve Digital Signing Algorithm
|
||
\item \textbf{AES128} 128-Bit \acrfull{AES} symmetric encryption
|
||
\item \textbf{GCM} Galois Counter Mode
|
||
\item \textbf{SHA256} Secure Hash Algorithm
|
||
\end{itemize}
|
||
\cite{enwiki:ciphersuite,enwiki:galoismode}
|
||
%\printglossary[type=\acronymtype]
|
||
%\printglossary
|
||
\printbibliography
|
||
\end{document}
|