Professor: Alfred Menezes | Term: Fall 2024

Chapter 1: Introduction to Cryptography

Cryptography is about securing communications in the presence of malicious adversaries.

Alice and Bob are communicating via an unsecured channel. Eve is eavesdropping (malicious). Communication should be

  • Confidential: Keep data secret from everyone not authorized to see it.
  • Data Integrity: Ensure data is not altered by others.
  • Data Origin Authentication: Corroborating the source of data.
  • Non-Repudiation: Preventing an entity from denying previous commitments or actions.

Transport Layer Security (TLS): The cryptographic protocol used by web browsers to securely communicate with websites (e.g. Facebook, Gmail).

TLS is used to assure an individual user of the authenticity of the website and establish a secure communications channel.

Symmetric-Key Cryptography: The client and server a priori share some secret information called a key.

They can encrypt their messages with AES and authenticate the resulting ciphertexts with HMAC.

Question

How do Alice and Bob share the shared secret ?

Public-key cryptography: The client and server a priori share some authenticated (but non-secret) information.

To establish a secret key, Alice selects the secret session key , and encrypts it with Bob’s RSA public key. Then only Bob can decrypt the resulting ciphertext with its RSA private key to recover .

Question

How does Alice obtain an authentic copy of Bob’s RSA public key?

Bob cannot send it to Alice over the internet because it can be intercepted.

Signature scheme: Bob’s RSA public key is signed by a Certification Authority (CA) using its secret signing key with the RSA signature scheme.

Alice can verify the signature using the CA’s RSA public verification key. In this way, Alice obtains an authentic copy of Bob’s RSA public key.

The CA’s RSA public key is embedded in Alice’s browser.

TLS potential vulnerabilities:

  • The cryptography is weak
  • Cryptography can be broken using quantum computers
  • Weak random number generation
  • Issuance of fraudulent certificates
  • Software bugs
  • Phishing attacks
  • TLS only protects data during transit. It does not protect data stored at the server

Definition

Cybersecurity is comprised of the concepts, technical measures, and administrative measures used to protect networks, computers, programs and data from deliberate or inadvertent unauthorized access, disclosure, manipulation, or use.

Cryptography Cybersecurity. Cryptography provides some mathematical tools that can assist with the provision of cybersecurity services. It is a small part of a complete security solution.

Security is a chain; weak links become targets.

Chapter 2: Symmetric-Key Encryption

Fundamental Concepts

Definition

Asymmetric-key encryption scheme (SKES) consists of:

  • - the plaintext space,
  • - the ciphertext space,
  • - they key space,
  • a family of encryption functions ,
  • a family of decryption functions ,

such that for all .

  1. Alice and Bob agree on a secret communicating over the secured channel
  2. Alice computes and sends the ciphertext to Bob over the unsecured channel.
  3. Bob retrieves the plaintext by computing

Note: The secret key might be used for a fixed time interval, or it might be used a fixed number of times.

Called symmetric-key encryption since the same key is used for encryption and decryption.

The Enigma and Lorenz Machines are examples.

Substitution Cipher

  • all English messages
  • all encrypted messages
  • all permutations of the English alphabet.
  • Apply permutation to , one letter at a time
  • Apply the inverse permutation to , one letter at a time

Security Model: Defined the computational abilities of the adversary, and how she interacts with the communicating parties.

Convention: We will always strive to model maximal adversary capabilities and minimal adversary goals.

Basic assumption: The adversary knows everything about the SKES, except the particular key chosen by Alice and Bob. Avoid security by obscurity.

Computational power of the adversary:

  • Information-theoretic security: Eve has infinite computational resources
  • Complexity-theoretic security: Eve is a “polynomial-time Turing machine”
  • Computational security: Eve has a bounded amount of computational power. We say Eve is computationally bounded.

Passive Attacks:

  • Ciphertext-only attack: The adversary knows some ciphertext
  • Known-plaintext attack: The adversary also knows some plaintext and the corresponding ciphertext. Active Attacks:
  • Chosen-plaintext attack: The adversary can also choose some plaintext and obtains the corresponding ciphertext
  • Clandestine attacks: bribery, blackmail (not covered in this course)

Adversary’s goal

  1. Recover the secret key
  2. Systematically recover plaintext from ciphertext, without necessarily learning .
  3. Learn some partial information about the plaintext from the ciphertext, other than its length

If the adversary can achieve 1 or 2, the SKES is said to be totally insecure.

If the adversary cannot learn any partial information about the plaintext from the ciphertext, the SKES is said to be partially secure.

Definition

A symmetric-key encryption scheme is said to be secure if it is semantically secure against chosen-plaintext attack by a computationally bounded adversary.

To break a symmetric-key encryption scheme, the adversary has to accomplish the following:

  1. The adversary is given a challenge ciphertext
  2. During its computation, the adversary can select arbitrary plaintext and obtain the corresponding ciphertexts
  3. After a feasible amount of computation, the adversary obtains some information about the plaintext corresponding to .

Desirable properties of a SKES

  1. Efficient algorithms should be known for computing and .
  2. The secret key should be small, but large enough to render exhaustive key search infeasible.
  3. The scheme should be secure.
  4. The scheme should be secure even against the designer of the system.

The simple substitution cipher is totally insecure against a chosen-plaintext attack.

Is exhaustive key search possible?

Number of keys to try is . This will take too long, even with many computers.

In this course:

  • operations is considered very easy.
  • operations is considered easy.
  • operations is considered feasible.
  • operations is considered barely feasible.
  • operations is considered infeasible.

The Bitcoin network is performing about hash operations per hour.

Definition

A cryptographic scheme is said to have a security level of bits if the fastest known attack on the scheme takes approximately operations. A security level of bits is desirable in practice.

Simple frequency analysis of ciphertext letters can be used to recover the secret key.

Vigenere Cipher

The secret key is an English word having no repeated letters, e.g. CRYPTO. We sum each letter in by to get . Here , and addition of letters is module . Decryption is subtraction module .

The Vigenere cipher is totally insecure against a chosen-plaintext attack.

It is also insecure against a cipher-text only attack.

Stream Ciphers

A stream cipher is a SKES that encrypts the plaintext one bit at a time. A block cipher is a SKES that encrypts the plaintext one block at a time.

One-time Pad

The secret key is a random string of letters with the same length as the message. We use the same process as the Vigenere.

The key should not be reused. If and , then . So, depends only on the plaintext (and not on the key ), and hence can leak information.

Convention: From now on, messages and keys will be assumed to be bit (binary) strings.

Notation: is bitwise exclusive-or (XOR) (bitwise addition mod ).

Example

Note that

So, for the one-time pad, encryption is and decryption is .

Perfect secrecy: The one-time pad is semantically secure against ciphertext-only attack by an adversary with infinite computational resources.

This can be formally proven using concepts from information theory. Shannon proved that if plaintexts are -bit strings, then any symmetric-key encryption with perfect secrecy must have . So perfect secrecy is useless in practice.

Basic Idea: Instead of using a random key in the one-time pad, use a “pseudorandom” key.

Definition

A pseudorandom bit generator (PRBG) is a deterministic algorithm that takes as input a (random) seed, and outputs a longer “pseudorandom” sequence called the keystream.

Stream cipher: uses a PRGB for encryption. The seed is the secret key shared by Alice and Bob.

No more perfect secrecy - security depends on the quality of the PRBG.

For a stream cipher to be secure:

  • Indistinguishability requirement: The keystream should be “indistinguishable” from a random sequence.
  • Unpredictability requirement: Given portions of the keystream, it should be computationally infeasible to learn any information about the remainder of the keystream
    • If an adversary knows a portion of ciphertext and the corresponding plaintext , then she can easily find the corresponding portion of the keystream.

Aside: Don’t use UNIX random number generators rand and srand for cryptographic purposes.

Now we introduce the ChaCha20 stream cipher. Designed by Dan Bernstein in 2008, the ChaCha20 is conceptually very simple. It is extremely fast in software an does not require and special hardware. No security weaknesses have been found.

Notation:

  • bit
  • bit constant
  • bit nonce
  • bit counter
  • A hexadecimal digit is a bit number.
  • A nonce is a non-repeating quantity

The initial state is:

More Notation:

  • xor
  • integer addition module
  • left-rotation by positions

Define : Quarter Round Function

Input: Four -bit words

Output:

ChaCha20 Keystream Generator

Select a nonce and initialize the counter to . While keystream bytes are required do:

  • Create the initial state , and make a copy of .
  • Update by repeating the following times:
  • Output ( keystream bytes).
  • Increment the counter

Encryption: The keystream bytes are xored with the plaintext bytes to produce ciphertext bytes. The nonce is appended to the ciphertext.

Block Ciphers: DES

Definition

A block cipher is a symmetric-key encryption scheme that breaks up the plaintext into blocks of a fixed length (e.g. bits), and encrypts the blocks one at a time.

In contrast, a stream cipher encrypts the plaintext one character (usually a bit) at a time.

A historically important example of a block cipher is the Data Encryption Standard (DES):

flowchart LR
key
key -- 56 bits --> DES
plaintext -- 64 bits --> DES
DES -- 64 bits --> ciphertext

Key length: bits, size of key space: , block length: bits.

Design principles articulated by Claude Shannon

Security:

  1. Diffusion: Each ciphertext bit should depend on all plaintext bits.
  2. Confusion: The relationship between key and ciphertext bits should be complicated.
  3. Key length: Should be small, but large enough to preclude exhausting key search.

Efficiency:

  1. Simplicity: Easier to implement and analyze.
  2. Speed: High encryption and decryption rates.
  3. Platform: Suitable for hardware and software.

The design principles of DES are still classified.

DES Problem #1: Small key size

Exhaustive search on the key space takes operations and can easily be parallelized.

DES Problem #2: Small block size

If plaintext blocks are distributed uniformly at random, then the expected number of ciphertext blocks observed before a collision occurs is . This is by the birthday paradox.

Birthday paradox: Suppose that an urn contains numbered balls. Suppose that balls are drawn from the urn, one at a time, with replacement. The expected number of draws before a ball is selected for the second time (called a collision) is approximately .

Thus the ciphertext reveals some information about the plaintext.

Block Ciphers: Triple-DES

Recall: The only substantial weaknesses known in DES are the obvious ones: small key length and small block length.

Question

How can one construct a more secure block cipher from DES?

Multiple encryption: Re-encrypt the ciphertext one or more times using independent keys. Hope that this increases the effective key length.

Note: Multiple encryption does not necessarily result in increased security.

Example

If denotes the encryption function for the simple substitution cipher with the key , then any more secure than ?

No, since

Encryption is: , where DES decryption.

The Double-DES key length is bits, so exhaustive key search takes operations.

Note: The block length is unchanged ( bits).

Meet-in-the-middle Attack on Double-DES

Input: 3 plaintext/ciphertext pairs Output: The secret key

  1. For each do: a. Compute and store
  2. For each do:
  3. Compute
  4. Search for in the table
  5. For each match in the table:
    1. Check if ; if so then:
      1. Check if ; if so then:
        1. Output and STOP.

The main idea is that

Question

How many plaintext/ciphertext pairs are needed for unique key determination?

Let be a block cipher with key space , and plaintext and ciphertext space .

Let be the secret key chosen by Alice and Bob, and let , be known plaintext/ciphertext pairs where the plaintext are distinct.

Question

So how large should be to ensure that there is only one key for which for all ?

We select so that where is the expected number of false keys.

For each , the encryption function is a permutation (bijection).

We make the heuristic assumption that for each is a random function, i.e. a randomly selected function. This assumption is certainly false since is not random, and because a random function is almost certainly not a permutation.

Now, fix .

The probability that for all is Thus, the expected number of false keys for which for all is

Time: The number of DES operations is

The security level of Double-DES is 57 bits, so Double-DES is not much more secure than DES.

A Triple-DES secret key is , where

Encryption is: , where DES encryption.

flowchart LR
k1
k2
k3
id1[DES]
id2[DES]
id3[DES]
k1 --> id1
k2 --> id2
k3 --> id3
m -- 64 bits --> id1
id1 -- 64 bits --> id2
id2 -- 64 bits --> id3 
id3 -- 64 bits --> c

Decryption is: , where DES decryption.

The Triple-DES key length is bits, so exhaustive key search takes operations (infeasible).

Meet-in-the-middle attack takes operations. So the security level of Triple-DES is 112 bits.

Block Ciphers: AES

The Advanced Encryption Standard (AES)

Key lengths: , and bits.

Block length: bits

2024: No attacks have been found on AES that are faster than exhaustive key search.

AES is an example of a substitution-permutation network.

Definition

A substitution-permutation network (SPN) is an iterated block cipher where a round consists of a substitution operation followed by a permutation operation

Components of an SPN cipher:

  • : the block length (in bits)
  • : the key length (in bits)
  • : the number of rounds
  • A fixed invertible function called substitution, where is a divisor of .
  • A fixed permutation on .
  • A key scheduling algorithm that determines subkeys from a key . Note: and the key scheduling algorithm are public.

The encryption looks like: plaintext for do ciphertext

Decryption is the reverse of encryption.

AES is an SPN, where the permutation operation is comprised of two invertible linear transformations.

All operations are byte oriented, e.g., so the box maps bits to bits. This facilitates fast implementations on software platforms.

The block length of AES is . Each subkey is bits.

AES accepts three key lengths. The number of rounds depends on the key length.

Each round updates a variable called State which consists of a array of bytes (note , the block length).

State is initialized with the plaintext.

Add AES round uses four invertible operations:

  1. AddRoundKey (key-mixing)
  2. SubBytes (S-box)
  3. ShiftRows (permutation)
  4. MixColumns (linear transformation)

After rounds are completed, a final subkey is XORed with State, the result being the ciphertext.

Definition

The elements of the finite filed are the polynomials of degree at most in , with addition and multiplication performed module the irreducible polynomial ( is the set of polynomials in with coefficients from ). We interpret an bit string as coefficients of the polynomial and vice versa.

Example

Let and , so and .

Addition: , so .

Multiplication: , which leaves a remainder of upon division by . Hence in , or .

Inversion: since .

Definition (S-box)

Let , and consider as an element of .

  1. Let if , and if
  2. Define
  3. Compute
  1. Then

ShiftRows: Permute the bytes of State by applying a cyclic shift to each row.

MixColumns:

  1. Read column of State as a polynomial (interpret the coefficients as elements of the finite field .
  2. Multiply this polynomial with the constant polynomial with the constant polynomial and reduce module . This gives a new polynomial

The operation.

Let , where each .

Let , where 01, 02, 03 are elements in (written in hex).

To compute do:

  • Compute (polynomial multiplication where coefficient arithmetic is in ).
  • Divide by to find the remainder polynomial . Equivalently, replace by , by , and by , and simplify.
  • Then

AES Encryption

From the key derive subkeys .

State plaintext

State State

for do

	State ← SubBytes(State)
	State ← ShiftRows(State)
	State ← MixColumns(State)
	State ← State ⊕ k_i

State SubBytes(State)

State ShiftRows(State)

State State

ciphertext State

AES Decryption

From the key derive subkeys

State ciphertext

State State

State InvShiftRows(State)

State InvSubBytes(State)

for do

	State ← State ⊕ k_i
	State ← InvMixColumns(State)
	State ← InvShiftRows(State)
	State ← InvSubBytes(State)

State State

plaintext State

For 128-bit keys, AES has 10 rounds, so we need 11 subkeys.

  • The first subkey is is the actual AES key.
  • The second subkey is
  • The third subkey is
  • The eleventh subkey is

The function are defined as follows:

  1. The input is divided into four bytes:
  2. Left-rotate the bytes:
  3. Apply the AES S-box to each byte:
  4. XOR the leftmost byte with the constant , and output the result:

The constants (in hex):

Modes of Operation

In practice, one usually wishes to encrypt a large quantity of data. The plaintext message is where each is an bit block.

Question

How should we use a block cipher to encrypt ?

Some modes of operation: ECB, CBC, CTR, GCM, CCM.

Suppose that the plaintext message is

Electronic Codebook Mode (ECB): encrypts the blocks independently, one at a time. Drawback: Identical plaintext result in identical ciphertext blocks.

Cipher Block Chaining (CBC) mode:

Encryption: Select ( is a random non-secret IV), and then compute for . The ciphertext is .

Decryption: for .

Identical plaintexts with different IVs result in different ciphertexts.

Chapter 3: Hash Functions

Fundamental Concepts

Hash functions play a fundamental role in cryptography. They are used in a variety of cryptographic primitives and protocols.

They are very difficult to design because of stringent security and performance requirements.

The most commonly used hash functions are:

  • SHA-1
  • SHA-2 family: SHA-224, SHA-256, SHA-384, SHA-512
  • SHA-3 family

SHA-256

SHA-256: SHA-256(“Hello there”) =

Definition

A hash function is a mapping such that:

  1. maps binary messages of arbitrary lengths to outputs of a fixed length : . ( is usually large, e.g., , whereas is small, e.g. )
  2. can be efficiently computed for all

is called an bit hash function. is called the hash or message digest of .

Notes:

  • The description of a hash function is public; there are no secret keys.
  • For simplicity, we will usually write instead of
  • More generally, a hash function is an efficiently computable function from a set to a set .

Consider to be a hash function mapping a bitstring to its last two digits.

is a preimage of .

is a collision. is a second preimage of .

Hash functions are used in all kind of applications. One reason for the widespread use of hash functions is speed.

Definition

A hash function is preimage resistant if, given a hash value , it is computationally infeasible to find (with non-negligible success probability) any with . ( is called a preimage of .)

Password protection on a multi-user computer system:

  • The server stores userid, (password)
  • If the attacker obtains a copy of the password file, they do not learn any passwords.
  • This requires preimage resistance.

Definition

A hash function is 2nd preimage resistant if, given , it is computationally infeasible to find (with non-negligible success probability) any with and

Modification Detection Codes (MDC’s):

  • To ensure that a message is not modified by unauthorized means, one computes and protects from unauthorized modification.
  • This is useful protection and requires 2nd preimage resistance.

Definition

A hash function is collision resistant if it is computationally infeasible to find with and . Such a pair is called a collision for .

Message digests for digital signature schemes:

  • For reasons of efficiency, instead of signing a long message , the (much shorter) message digest is signed.
  • This application requires preimage-resistance, 2nd preimage resistance, and collision resistance.
  • To see why collision resistance is required, suppose that the legitimate signer Alice can find a collision for . Alice can sign and later claimed to have signed .

Other applications:

  • Message Authentication Codes
  • Pseudorandom bit generation
  • Key derivation functions
  • Proof-of-work
  • Quantum-safe signature schemes

Relationships between PR, 2PR, CP

Breaking preimage resistance (PR):

Given:

Required: with .

Breaking 2nd preimage resistance (2PR):

Given: $x \in_{R} {0,1}^*

Required: with and

Breaking collision resistance (CR):

Given:

Required: with and

Claim : If is CR, then is 2PR

Proof: Suppose that is not 2PR.

We’ll show that is not CR.

Select . Since is not 2PR, we can efficiently find , with .

Thus, is a collision for that we have efficiently found, showing that is not CR.

Note: This proof established the contrapositive statement.

Claim : CR does not guarantee PR

Proof: Suppose that is CR.

Consider the hash function defined by

Then is CR (since is).

And is not PR since preimages can be efficiently found for at least half of all , namely the hash values that begin with .

Note: The hash function is rather contrived. For somewhat uniform hash functions, i.e., hash functions for which all hash values have roughly the same number of preimages, CR does not guarantee PR.

Claim : Suppose is somewhat uniform. If is CR, then is PR

Proof: Suppose that is not PR.

We’ll show that is not CR.

Select and compute . Since is not PR, we can efficiently find with . Since is somewhat uniform, we expect that has many preimages, and thus with very high probability. Thus, is a collision for that we have efficiently found, so is not CR.

Claim : PR does not guarantee 2PR

Proof: Suppose that is PR.

Define by for all .

Then is PR. However is not 2PR.

Claim : Suppose is somewhat uniform. If is 2PR, then is PR

Proof: Suppose that is not PR.

We will show that is not 2PR.

So, suppose we are given . We compute .

Since is not PR, we can efficiently find with .

Since is somewhat uniform, we expect that with very high probability. Hence, is a second preimage of that we have efficiently found.

Thus is not 2PR.

Claim : 2PR does not guarantee CR

Proof: Suppose that is 2PR.

Consider defined by if , and .

  • Then is not CR, since is a collision for
  • Suppose now that is not 2PR. We’ll show that is not 2PR.

So, we are given . Since is not 2PR, we can efficiently find , with . With probability essentially , we can assume that . Hence, .

Now, if , then

And, if , then .

In either case, we have efficiently found a second preimage for with respect to .

Hence, is not 2PR, a contradiction. Thus, is 2PR.

Generic Attacks

Definition

A generic attack on hash functions does not exploit any properties that the specific hash function might have.

In the analysis of a generic attack, we view as a random function in the sense that for each , the hash value was defined by selecting .

A random function is an ideal hash function (from a security point-of-view). However they are not practical.

Attack

Given , repeatedly select arbitrary until .

The expected number of hash operations is .

This generic attack is infeasible if .

Attack

Select arbitrary and store in a table sorted by first entry. Repeat until a collision is found.

Analysis: By the birthday paradox, the expected number of hash operations is

This generic attack is infeasible if .

This generic attack for finding collisions is optimal. The expected space required is .

VW: van Oorschot & Wiener parallel collision search.

The expected number of hash operations: . The expected space required is negligible.

It is easy to parallelize, -fold speedup with processors.

The VW collision-finding algorithm can easily be modified to find meaningful collisions.

If collision resistance is desired, then use an -bit hash function with .

Parallel Collision search (VW method)

Problem: Find a collision for .

Assumption: is a random function.

Notation: Let .

Define a sequence by for .

Let be the smallest index for which for some ; such a must exist. Then for all . By the birthday paradox, . In fact, and .

Now, with overwhelming probability, in which event is a collision for .

Question

How to find without using much storage?

We only store distinguished points.

Distinguished points: Select an easily-testable distinguishing property for elements of , e.g. leading 32 bits are all 0.

Let be the proportion of elements of that are distinguished.

VW method: Compute the sequence and only store the points that are distinguished.

VW Collision Finding

Stage 1: Detecting a collision

  1. Select
  2. Store in a sorted table.
  3. ( = last point stored)
  4. For do:
  5. Compute
  6. If is distinguished then
    1. If is already in the table, say where , then go to Stage 2
    2. Store in the table.

Stage 2: Finding a collision

  1. Set
  2. Suppose , and set $k \gets \ell_1 - \ell_2
  3. Compute
  4. For do:
  5. Compute
  6. Until
  7. The collision is

VW Analysis

Stage 1: Expected number of -evaluations is:

Stage 2: Expected number of evaluations is

Overall expected running time:

Expected storage: bits

Example

Consider . Take . Then the expected run time of VW collision search is evaluations (feasible), and the expected storage is 192 gigabytes (negligible).

Iterated Hash Functions

Merkle's Meta Method

Components:

  • Fixed initializing value
  • Efficiently-computable compression function

To compute where has bitlength do:

  1. Break up into bit blocks, , padding the last block with bits as necessary.
  2. Define , the length-block, to hold the right-justified binary representation of .
  3. Define .
  4. Compute for . (The $H_{i}‘s are called chaining variables).
  5. Define

Theorem (Merkle)

If the compression function is collision resistant, then the iterated hash function is also collision resistant.

Merkle’s theorem reduces the problem of designing collision-resistant hash functions to that of designing collision-resistant compression functions.

A major theme in cryptographic research is to formula precise security definitions and assumptions, and then prove that a protocol is secure.

A proof of security is certainly desirable since it rules out the possibility of attacks being discovered in the future.

However, it isn’t always easy to asses the practical security assurances (if any) that a security proof provides).

  • Assumptions might be unrealistic, or false, or circular.
  • The security model might not account for certain kinds of realistic attacks.
  • The security proof might be asymptotic.

Proof of Merkle’s Theorem ( is CR is CR)

Suppose that is not CR. We’ll show that is not CR.

Since is not R, we can efficiently find messages , with and .

Let , = bit-length(), length block.

Let , = bit-length(), length block.

We can efficiently compute:

Since , we have

Case 1: Now, if then . Thus, is a collision for that we have efficiently found.

Case 2: Suppose next that . Then and

  • Let be the largest index, , for which . Such an must exist since .
  • Then , so is a collision for that we have efficiently found.

Thus, is not collision resistant