\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}
\makeglossaries
\newacronym{DES}{DES}{Data Encryption Standard}
\newacronym{AES}{AES}{Advanced Encryption Standard}
\newacronym{RSA}{RSA}{Rivest–Shamir–Adleman}




\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.

Most notably 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{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},
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. \newline
Nevertheless, it sparked public and scientific interest in the research of encryption algorithms, producing a large body of publications.

\section{AES}
The \acrfull{AES} superseded \acrshort{DES} in 2001 after an official selection process.
Unlike its predecessor, it does not use a Feistel network.

\section{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}.


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 $p,q$ of similar size so that
        $0.1 < | \log_2 p - \log_2 q | < 30 $.
    \item Calculate $ N= p \cdot q $
    \item Compute Euler's totient function of $ \varphi (N) = (p-1) \cdot (q-1)$ which is kept secret.
    \item Choose an integer $e$ so that $ 1 < e < \varphi (N) $ and $\gcd(e, \varphi(N)) =1$, i.e. $e$ and $\varphi(N)$
        are coprime. The most common choice here is $ e= 2^(16) +1 = 65537 $, as $e$ is released as part of the public key.
    \item For the private key, % TODO
\end{enumerate}
\clearpage
%\printglossary[type=\acronymtype]
%\printglossary
\printbibliography
\end{document}
