All Files in ‘COSC362 (2021-S2)’ Merged

01. Introduction

Lecturer: Clementine Gritti.

Course weighting:

CIA Triad:

02. Course Overview

What is Cyber security?

The NIST (National Institute of Standards and Technology) computer security handbook defines it as protections afforded to an information system to preserve confidentiality, integrity, availability (CIA) of system resources.

Terminology:

Key questions:

Assets include:

Types of Attacks

Passive:

Active:

Inside:

Outside:

Fundamental Requirements

Information security management requires:

  1. Threat identification
  2. Classification by likelihood and severity
  3. Security controls applied based on cost-benefit analysis

Countermeasures to threats and vulnerabilities:

What is Information Security?

ISO security architecture defines:

Hence, information security is security where the assets/resources are information systems

Security Services and Mechanisms

OSI Security Architecture X.800: dated, but most definitions/terminology still relevant. Defines security threats, services, and mechanisms.

Security Services

A security service is processing/communication service that gives a specific kind of protection to system resources.

Security services include:

From Stack Exchange:

Security Mechanisms

A security mechanism is a method of implementing one or more security services.

Security mechanisms include:

03. Number Theory and Finite Fields

Discrete mathematics: cyroptology deals with finite objects (e.g. alphabets, blocks of characters)

Modular arithmetic; deals with finite number of values.

Basic Number Theory

Factorization

Z={,3,2,1,0,1,2,3,}\mathbb{Z} = \{ \dots, -3, -2, -1, 0, 1, 2, 3, \dots \} is the set of integers.

Given a,bZa, b \in \mathbb{Z}, aa divides bb if there exists kZk \in \mathbb{Z} such that ak=bak = b. In this case, aa is a factor of bb: aba|b.

An integer p>1p > 1 is prime iff its only divisors are 11 and pp.

Properties

If aba|b and aca|c, then a(b+c)a|(b+c).

If pp is prime and pabp|ab, pap|a OR pbp|b.

Division algorithm

Given a,bZa, b \in \mathbb{Z} such that a>ba > b, then there exists q,rZq, r \in \mathbb{Z} such that:

a=bq+r a = bq + r

qq is the quotient and 0r>b0 \ge r \gt b is the remainder. r<a2r \lt \frac{a}{2}.

Greatest Common Divisor

dd is the GCD of aa and bb; gcd(a,b)=dgcd(a, b) = d if:

aa and bb are relatively prime if gcd(a,b)=1gcd(a, b) = 1

Euclidean Algorithm

To find d=gcd(a,b)d = gcd(a, b):

a=bq1+r1 for 0>r1>bb=r1q2+r2 for 0>r2>r1r1=r2q3+r3 for 0>r3>r2rk2=rk1qk+rk for 0>rk>rk1rk1=rkqk+1 with rk+1=0 \begin{aligned} a &= bq_1 + r_1 \text{ for } 0 \gt r_1 \gt b \\ b &= r_1q_2 + r_2 \text{ for } 0 \gt r_2 \gt r_1 \\ r_1 &= r_2q_3 + r_3 \text{ for } 0 \gt r_3 \gt r_2 \\ & \dots \\ r_{k - 2} &= r_{k - 1}q_k + r_k \text{ for } 0 \gt r_k \gt r_{k - 1} \\ r_{k - 1} &= r_kq_{k + 1} \text{ with } r_{k + 1} = 0 \end{aligned}

Hence, d=rk=gcd(a,b)d = r_k = gcd(a, b).

In psuedo-code:

def gcd(a, b):
  r[-1] = a
  r[0] = b
  k = 0
  while r[k] != 0:
    q[k] = floor(r[k - 1]/r[k])
    r[r + 1] = r[k - 1] - q[k]r[k]
    k = k + 1
  
  k = k - 1
  return r[k]
Back-Substitution

Find xx, yy in ax+by=d=rkax + by = d = r_k.

rk3=rk2qk1+rk1 r_{k - 3} = r_{k - 2}q_{k - 1} + r_{k - 1}

Can be rewritten as:

rk1=rk3rk2qk1 r_{k - 1} = r_{k - 3} - r_{k - 2}q_{k - 1}

rk2=rk1qk+rkr_{k - 2} = r_{k - 1}q_k + r_k can be rewritten as rk=rk2rk1qkr_k = r_{k - 2} - r_{k - 1}q_k. rk1r_{k - 1} can be substituted with the value above. Hence, this process can be repeated until you have rk1r_{k - 1} in terms of the original values.

Example: gcd(17,3)gcd(17, 3):

17=3×5+23=2×1+12=1×2 \begin{aligned} 17 &= 3 \times 5 + 2 \\ 3 &= 2 \times 1 + 1 \\ 2 &= 1 \times 2 \end{aligned}

Back-substitution:

1=32×1=3(173×5)×1=17×1+3×6 \begin{aligned} 1 &= 3 - 2 \times 1 \\ &= 3 - (17 - 3 \times 5) \times 1 \\ &= 17 \times - 1 + 3 \times 6 \end{aligned}

The result shows that 316(mod17)3^{-1} \equiv 6 \pmod{17}.

Modular Arithmetic

bb is a residue of a(modn)a \pmod n if ab=kna - b = kn for some integer kk:

ab(modn)ab=kn a \equiv b \pmod n \Longleftrightarrow a - b = kn

Given ab(modn)a \equiv b \pmod n and cd(modn)c \equiv d \pmod n:

a+cb+d(modn)acbd(modn)kakb(modn) \begin{aligned} a + c &\equiv b + d \pmod n \\ ac &\equiv bd \pmod n \\ ka &\equiv kb \pmod n \end{aligned}

b(modn)b \pmod n denotes the unique value aa in the complete set of residues {0,1,,n1}\{ 0, 1, \dots, n-1\} such that:

ab(modn) a \equiv b \pmod n

In other words, b(modn)b \pmod n is the remainder after dividing aa by nn.

Residue Class

The set {r0,r1,,rn1}\{ r_0, r_1, \dots, r_{n - 1}\} is a complete set of residues modulo nn if for every aNa \in \mathbb{N}, ari(modn)a \equiv r_i \pmod n for exactly one rir_i.

The set {0,1,,n1}\{ 0, 1, \dots, n - 1\} is denoted as Zn\mathbb{Z}_n.

Groups

A group G\mathbb{G} is a set with binary operation \cdot and:

A group is abelian when it is the operation is commutative; ab=baa \cdot b = b\cdot a for a,bGa, b \in \mathbb{G}.

Cyclic Groups

The order G|\mathbb{G}| of a group G\mathbb{G} is the number of elements in G\mathbb{G}.

gkg^k denotes the repeated application of gGg \in \mathbb{G} using the group operation. e.g. g3=gggg^3 = g \cdot g \cdot g.

The order g|g| of gGg \in \mathbb{G} is the smallest integer kk such that gk=1g^k = 1.

gg is a generator for G\mathbb{G} if g=G|g| = |\mathbb{G}|.

A group is cyclic if it has a generator.

Computing Inverses Modulo nn

The inverse if aa (if it exists) is a value xx such that ax1(modn)ax \equiv 1 \pmod n; it is written as a1(modn)a^{-1} \pmod n. This means that aa must be coprime to nn.

Theorem: let 0>a>n0 \gt a \gt n; aa has an inverse modulo nn iff gcd(a,n)=1gcd(a, n) = 1.

The Euclidean algorithm can be used to find the inverse of aa.

If xx such that ax1(modn)ax \equiv 1 \pmod n, there is an integer yy such that ax=1+ynax = 1 + yn.

Hence, starting from gcd(a,n)=1gcd(a, n) = 1, use back substitution to find xx and yy in the equation ax+ny=1ax + ny = 1. the yy value gives the inverse.

Group of Primes Modulus Zp\mathbb{Z}^*_p

Zp=1,2,,p1\mathbb{Z}^*_p = {1, 2, \dots, p - 1} is a complete set of residues modulo the prime pp with the value 00 removed.

Properties:

It can be thought of as the multiplicative group of integers 1,2,,p11, 2, \dots, p - 1 which have inverses modulo pp.

Finding Generators

A generator of Zp\mathbb{Z}^*_p is an element of order p1p - 1

Lagrange theorem: the order of any element must exactly divide p1p - 1.

To find a generator of Zp\mathbb{Z}^*_p:

Example

Find a generator for Z11\mathbb{Z}_{11}^*.

Z11|\mathbb{Z}_{11}^*| is 1010 as 1111 is prime. 10=2510 = 2 \cdot 5, so to check if gZ11g \in \mathbb{Z}_{11}^* is a generator, check if g2≢1(mod11)g^2 \not\equiv 1 \pmod{11}, g5≢1(mod11)g^5 \not\equiv 1 \pmod{11}:

Groups of Composite Modulus Zp\mathbb{Z}^*_p

For any non-prime nn, Zn\mathbb{Z}_n^* is a group of residues that have an inverse under multiplication.

Properties:

e.g. Z6={1,5}\mathbb{Z}_6^* = \{1, 5\} (elements coprime to 66).

Example

Find a generator for Z9\mathbb{Z}_9^*.

Z9={1,2,4,5,7,8,}\mathbb{Z}_9^* = \{ 1, 2, 4, 5, 7, 8, \} so Z9=6|\mathbb{Z}_9^*| = 6

Fields

A field F\mathbb{F} is a set with two binary operations, ++ and \cdot, with the properties such that:

Theorem: only finite fields of size pnp^n exist, where pp is a prime and nn is any positive integer.

Finite Field GF(p)GF(p)

For a finite field GF(p)=ZpGF(p) = \mathbb{Z}_p:

Finite Field GF(2)GF(2)

GF(2)GF(2) is the simplest field with two elements, 00 and 11:

Finite Field GF(28)GF(2^8)

GF(28)GF(2^8) is the field used for calculations in AES (block cipher).

Arithmetic in this field is considered as polynomial arithmetic where the field elements are polynomials with binary coefficients. e.g. 00101101x5+x3+x2+10010 1101 \leftrightarrow x^5 + x^3 + x^2 + 1

Properties:

03. Classical Encryption

Terminology

Cryptography transforms data based on a secret called the key. It provides confidentiality and authentication:

Cryptosystems:

Symmetric key cipher (secret key cipher):

Asymmetric key cipher (public key cipher):

Notation for Symmetric Encryption Algorithms

Encryption: C=E(M,K)C = E(M, K)

Decryption: M=D(C,K)M = D(C, K)

Methods of Cryptanalysis

What resources are available to the adversary? Computational capabilities, inputs/outputs to the systems, etc.

What is the adversary aiming to achieve? Retrieving the whole secret key? Distinguishing between two messages?

Adversary tries all possible keys. Impossible to prevent such attacks; can only ensure there are enough keys to make exhaustive search too difficult computationally.

Note that the adversary may find the key without exhaustive search or even break the cryptosystem without finding the key.

Preventing exhaustive key search is a minimum standard.

Attack Classification

Ciphertext only attack: the attacker has access only to intercepted ciphertexts.

A cryptosystem is highly insecure if it can be practically attacked using only intercepted ciphertexts.

Known plaintext attack: the attacker knows a small amount of plaintexts and their corresponding ciphertexts.

Chosen plaintext attack: the attacker can obtain the ciphertext from some plaintext it has selected (attacker has ‘inside encryptor’).

Chosen ciphertext attack: the attacker can obtain the plaintext from some ciphertext it has selected (attacker has ‘inside decryptor’).

A cryptosystem should be secure against chosen plaintext and ciphertext attacks.

Kerckhoff’s Principle

Kerckoff’s Principle states the that the attacker has complete knowledge of the cipher; the decryption key is the only item unknown to the attacker.

Secret, non-standard algorithms are often flawed, providing mainly security through obscurity.

Alphabets

Historical ciphers: define alphabet for the plaintext and ciphertext

Roman alphabet: A,B,C,,ZA, B, C, \dots, Z

Statistical attacks depend on using the redundancy of the alphabet:

Basic Cipher Operations

Transposition: characters in plaintext are mixed up with each other (permutations)

Substitution: each character is replaced by a different character

Transposition Cipher

Permuting characters in a fixed period dd and permutation ff.

The plaintext is seen as a matrix with dd columns. For each row, the characters are mixed up in the order given by ff. The same permutation is used by each row.

Key is (d,f)(d, f), each block of dd characters being re-ordered using the permutation ff.

There are d!d! permutations of length dd.

Cryptanalysis

Frequency distribution of ciphertext and plaintext characters are the same.

If dd is small, transposition ciphers can be solved by hand using anagramming.

Knowledge of plaintext language digram/trigrams can help to optimize trials.

Simple Substitution Ciphers

Each character in plaintext alphabet replaced by character in ciphertext alphabet using a substitution table.

This is called a monoaphabetic substitution cipher.

Caesar cipher:

Random simple substitution cipher:

Polyalphabetic Substitution

Multiple mappings from plaintext to ciphertext: smoothens frequency distribution.

Typically periodic substitution ciphers based on a period dd.

Given dd ciphertext alphabets C0,C1,,cd1C_0, C_1, \dots, c_{d - 1}, let fi:ACif_i: A \rightarrow C_i.

A plaintext message:

M=M0Md1MdM2d1M2d M = M_0 \dots M_{d-1}M_d \dots M_{2d-1}M_{2d} \dots

it is encrypted to:

(K,M)=f0(M0)f1(M1)fd1(Md1)f0(Md)fd1(M2d1) (K, M) = f_0(M_0)f_1(M_1) \dots f_{d-1}(M_{d - 1})f_0(M_d) \dots f_{d - 1}(M_{2d - 1}) \dots

If d=1d = 1, the cipher is monoalphabetic - a simple substitution cipher.

Key generation:

Encryption: encrypt the iith character using the jjth substitution table such that ij(modd)i \equiv j \pmod d.

Decryption: use the same substitution table as encryption.

Vigenère Cipher

Based on shifted alphabets.

The key KK is a sequence of characters K=K0K1Kd1K = K_0 K_1 \dots K_{d - 1}.

Let MM be the plaintext character. for 0id10 \le i \le d - 1, KK gives the amount of shift in the iith character e.g. fi(M)=(M+Ki)modnf_i(M) = (M + K_i) \bmod n.

e.g. if K=LOCK={11,14,2,10}K= LOCK = \{ 11, 14, 2, 10 \}, the first character is shifted by 1111, the second is shifted by 1414, …, the fifth is shifted by 1111.

Cryptanalysis

Identifying period length:

Once period identified, the dd substitution tables can be attacked separately - there needs to be sufficient ciphertext to do this.

Autocorrelation

Given ciphertext CC, computed the correlation between CC and its shift CiC_i for all values ii of the period.

English is non-random; there is better correlation between two texts with the same shift size.

Find peaks in the value of CiC_i when ii is a multiple of the period; results can be plotted on a histogram.

Kasiski Method

If you identify sequences of characters that occur multiple times, find the distance between them; the period is likely to be a multiple of the period.

If you find multiple sequences with different distances, the period is likely to be a common divisor.

Once the period is found, the separate alphabets can be attacked separately; at this point, it is just a Caesar cipher.

Other Ciphers (for use by hand)

Beaufort cipher: like Vigenère, but fi(M)=(KiM)modnf_i(M) = (K_i - M) \bmod n

Autokey: starts off as the Vigenère cipher, but the plaintext defines the subsequent alphabet. Hence, the cipher is not periodic.

Running key cipher: practically infinite set of alphabets generated from a shared key. This is ofen an extract from a book called the book cipher.

Rotor Machines

Enigma: each character encrypted with a different alphabet with a period of ~17,000; would never repeat in the same message (in practice).

Hill Cipher

Polygram/polygraphic cipher: simple substitution of an extended alphabet consisting of multiple characters.

Has linearity, making known plaintext attacks easy.

Given dd plaintext characters:

Encryption: multiplying the d×dd \times d matrix KK by the block of plaintext MM: C=KMC = KM.

Decryption: multiplying the matrix K1K^{-1} by the block of ciphertext CC: M=K1CM = K^{-1}C.

Example

d=2d = 2; takes digrams as input/output blocks.

Each plaintext pair written as column vector. If there are insufficient letters, they are filled with uncommon letters (e.g. ZZ).

K=(4617),K1=(4121110) K = \begin{pmatrix} 4 & 6 \\ 1 & 7 \end{pmatrix}, K^{-1} = \begin{pmatrix} 4 & 12 \\ 11 & 10 \end{pmatrix}

Plaintext:

M=(EG)=(46) M = (EG) = \begin{pmatrix} 4 \\ 6 \end{pmatrix}

Encryption:

C=KM=(4617)(46)=(52mod2746mod27)=(2519)=ZT \begin{aligned} C &= KM \\ &= \begin{pmatrix} 4 & 6 \\ 1 & 7 \end{pmatrix} \begin{pmatrix} 4 \\ 6 \end{pmatrix} \\ &= \begin{pmatrix} 52 \bmod{27} \\ 46 \bmod{27} \end{pmatrix} \\ &= \begin{pmatrix} 25 \\ 19 \end{pmatrix} \\ &= ZT \\ \end{aligned}

Decryption:

M=K1C=(4121110)(2519)=(46)=(EG) \begin{aligned} M &= K^{-1}C \\ &= \begin{pmatrix} 4 & 12 \\ 11 & 10 \end{pmatrix} \begin{pmatrix} 25 \\ 19 \end{pmatrix} \\ &= \begin{pmatrix} 4 \\ 6 \end{pmatrix} \\ &= (EG) \end{aligned}

Cryptanalysis

Known plaintext attacks possible given dd plaintext-ciphertext matching blocks: given blocks (column vectors) MiM_i and CiC_i, 0id10 \le i \le d - 1:

CC , MM and KK are all d×dd \times d vectors

Then K1K^{-1} can be found to decrypt the ciphertext.

Comments:

05. Block Ciphers

Main bulk encryption algorithms used in commercial applications. AES is one example of such algorithm.

Principles

Block ciphers are symmetric key ciphers where each block of plaintext encrypted with the same key.

A block is a set of plaintext symbols of a fixed size, typically 64 to 256 bits in modern ciphers.

They are used in configurations called modes of operation.

Notation

Criteria

Shannon defined two encryption techniques:

Repeated use of techniques can be used using the concept of a product cipher.

Product & Iterated Ciphers

Product Cipher

Cryptosystem where encryption performed by applying/composing several sub-encryption algorithms: output of one block used as input to next block.

Often composed of simple functions fif_i for 1ir1 \le i \le r such that each fif_i has its own key KiK_i.

C=E(P,K)=fr((f2(f1(P,K1),K2)),Kr) C = E(P, K) = f_r(\dots(f_2(f_1(P, K_1), K_2)\dots), K_r)

Iterated Cipher

Special product ciphers called iterated ciphers where:

Encryption

Given plaintext block PP, round function gg, round keys K1,K2,,KrK-1, K_2, \dots, K_r, the ciphertext block CC is derived through rr rounds:

W0=PW1=g(W0,K1)W2=g(W1,K2)Wr=g(Wr1,Kr)=C \begin{aligned} W_0 &= P \\ W_1 &= g(W_0, K_1) \\ W_2 &= g(W_1, K_2) \\ \dots W_r &= g(W_{r - 1}, K_r) = C \end{aligned}

Decryption

There must be an inverse function g1g^{-1} such that g1(g(W,Ki),Ki)=Wg^{-1}(g(W, K_i), K_i) = W for all keys KiK_i and blocks WW.

Wr=CWr1=g1(Wr,Kr)Wr2=g1(Wr1,Kr1)W0=g1(W1,Kr)=P \begin{aligned} W_r &= C \\ W_{r - 1} &= g^{-1}(W_r, K_r) \\ W_{r - 2} &= g^{-1}(W_{r - 1}, K_{r - 1}) \\ \dots W_0 &= g^{-1}(W_1, K_r) = P \end{aligned}

Types of Iterated Ciphers

Substitution-Permutation Network (SPN) e.g. Advanced Encryption Standard (AES).

Feistel Cipher e.g. Data Encryption Standard (DES).

Substitution-Permutation Network

Block length nn must allow each block to be split into mm sub-blocks of length ll: n=lmn = lm.

Substitution πS\pi_S (called substitution box or S-box) operates on sub-blocks of length ll bits:

πS:{0,1}l{0,1}l \pi_S: \{ 0, 1 \}^l \rightarrow \{ 0, 1 \}^l

i.e. mapping some binary number of size ll bits to another.

Permutation πP\pi_P (called permutation-box or P-box) swaps the inputs from {1,,n}\{ 1, \dots, n \}:

πP:{1,,n}{1,,n} \pi_P: \{ 1, \dots, n \} \rightarrow \{ 1, \dots, n \}

i.e. swapping the order of bits in the entire block around.

Operation

  1. Round key KiK_i XORed with current state block WiW_i: KiWiK_i \oplus W_i
  2. Each sub-block substituted applying πS\pi_S
  3. The whole block permuted using πP\pi_P

Example

Substitution-Permutation Network

Feistel Cipher

Round function swaps the two halves of the block to form a new right hand half.

Encryption

Feistel Cipher Network

Plaintext block P=W0P = W_0 split into two halves (L0,R0)(L_0, R_0).

For each round:

The output is the ciphertext block C=WR=(Lr,Rr)C = W_R = (L_r, R_r).

Decryption

Split CC into two halves, (Lr,Rr)(L_r, R_r).

For each round:

ff does not need to be inverted: xx=0x \oplus x = 0, so applying by applying ff twice it can be decrypted.

The choice of ff is critical for security; is is the only non-linear part of the encryption.

Differential and Linear Cryptanalysis

Differential cryptanalysis: chosen plaintext attack using correlation in the differences between two input plaintexts and their corresponding ciphertexts.

Liner cryptanalysis: known plaintext attack that theoretically break DES.

Modern block ciphers normally immune to both attacks.

Avalanche Effects

Key avalanche: a small change in key (with the same plaintext) should result in a large change in ciphertext.

Plaintext avalanche: a small change in plaintext should result in a large change in ciphertext: changing one bit should change all bits in the ciphertext with a probability of 1/21/2.

Key avalanche is related to Shannon’s notion of confusion, plaintext avalanche to Shannon’s notion of diffusion.

DES

Designed by IBM researchers, became US standard in 1976. 16-round Feistel cipher with key length of 56 bits and data block length of 64 bits.

The key length is actually 64 bits, but the last bit of every byte is redundant.

Encryption

PP is an input plaintext block of 64 bits:

  1. All bits of PP permuted using an initial fixed permutation of IPIP
  2. 16 rounds of Feistel operations applied, denoted by function ff
    • Each round uses a different 48-bit subkey
    • The subkey is defined by a series of permutations and shifts
  3. A final fixed inverse permutation IP1IP^{-1} is applied

The 64-bit ciphertext block CC is the output.

Decryption requires only reversing the order in which the subkeys are applied.

Feistel Operation

  1. 32 bits expanded to 48 bits using a padding scheme which repeats some bits
  2. XOR the 48 bits with the 48-bit subkey
  3. Break 48 bits into 8 blocks of 6 bits
  4. Each block WiW_i transformed using substitution table SiS_i, resulting in blocks of length 44 and hence a total of 32 bits.
    • A transformation table is used to determine the output value
    • If the input block is W=x1x2x3x4x5x6W = x_1x_2x_3x_4x_5x_6, the row number is given by x1x6x_1x_6 and the column number by x2x3x4x5x_2x_3x_4x_5
  5. A permutation is applied to the result

Brute Force Attacks

Testing all the possible 2k2^k keys (where kk is the size of the key KK). k=56k = 56 is fairly small, requiring only 2k/2=2552^{k}/2 = 2^{55} trials on average - this was criticized from the start.

The key can be identified by using a small number of ciphertext blocks and looking for low entropy in the decrypted plaintext.

Double Encryption

Let K1K_1 and K2K_2 be two block cipher keys.

Encryption: C=E(E(P,K1),K2)C = E(E(P, K_1), K_2).

If both keys have length kk, exhaustive attacks require 22k12^{2k - 1} trials on average.

Meet-in-the-Middle Attack

Let (P,C)(P, C) is a single plaintext-ciphertext pair:

  1. For each key KK, store C=E(P,K)C' = E(P, K) in memory
  2. For any key KK', check if D(C,K)=CD(C, K') = C' (i.e. matches any ciphertext stored in memory)
    • If this is found, KK is K1K_1 and KK' is K2K_2
    • Check if key values work for other (P,C)(P, C) pairs

Requirements:

Expensive but still much cheaper than brute-forcing 21112^{111} keys.

Triple Encryption

Requires three keys: C=E(D(E(P,K1),K2),K3)C = E(D(E(P, K_1), K_2), K_3). (symmetric so decryption/encryption doesn’t matter? TODO)

This increases the computational requirements enough to make it secure against MITM attacks.

NIST SP 800-131A (2015) approves two-key triple DES, where K1=K3K_1 = K_3, only for legacy use. three-key triple DES is approved.

OpenSSL removed triple DES in 2016. Office 365 stopped using triple DES in 2018.

AES

Designed in an open competition after controversy over DES. Winning submission is ‘Rijndael’.

Algorithm

State Matrix

16-byte data block size arranged in a 4×44 \times 4 matrix.

Mixture of finite field operations in GF(28)GF(2^8) and bit string operations.

Round Transformation

Each round has four basic operations:

  1. ByteSub (non-linear substitution): substitute each byte wth a different value using a substitution table
  2. ShiftRow (permutation): rotate first row right by zero bytes, second row right by one byte… (bytes wrap to left)
  3. MixColumn (diffusion): each column is replaced with result of it being multiplied by a matrix
  4. AddRoundKey: XORs array with round key

Substitution-permutation network with block length of n=128n = 128 and sub-block length of l8l - 8.

S-box uses look-up table.

Key Schedule

Master key is 128/192/256 bits.

Each of the 10/12/14 rounds uses a 128-bit subkey. There is one subkey per round plus one initial subkey, all derived from the master key.

Security

Some weaknesses but no significant break; most serious real attacks can reduce effective key size by around two bits.

Vulnerable to related-key attack: attacker obtains a ciphertext encrypted with a key related to an actual key in a specified way.

Comparisons with DES

06. Block Cipher Modes of Operation

Block ciphers encrypt single blocks of data, but many applications require multiple blocks to be encrypted sequentially and breaking the plaintext into blocks and encrypting them separately can be insecure.

Modes of operation are standardized with different security and efficiency characteristics.

NIST has many standards (e.g. SP 800-38 series) for this.

Important Features of Different Modes

Different modes can provide confidentiality, authentication (and integrity) or both.

Modes for confidentiality normally include randomization.

Different modes have different efficiency and communication properties.

Randomized Encryption

Problem: the same plaintext block is encrypted to the same ciphertext block every time - allows patterns to be found in long ciphertexts.

Prevention: randomizing encryption schemes by using an initialization vector (IV) which propagates through the entire ciphertext. It may need to be either random or unique.

Alternatively, there could be a variable state which is updated with each block.

Efficiency

Parallel processing: encrypting/decrypting multiple plaintext/ciphertext blocks in parallel.

Error propagation: a bit error in the ciphertext which results in multiple bit errors in the plaintext after decryption.

Padding

Requiring the plaintext to consist of complete blocks.

NIST suggested padding method: append a single 11 bit to the data string, then with 00s until the last block is completed.

Notation

Modes can be applied to any block cipher.

Confidentiality Modes

Electronic Code Book (ECB) Mode

A basic mode of a block cipher; each block is encrypted with a key, IV is not used.

Encryption

Ct=E(Pt,K) C_t = E(P_t, K)

Decryption

Pt=D(Ct,K) P_t = D(C_t, K)

Properties

Randomized Padding IV Parallel encryption Parallel decryption
No Required None Yes Yes

Error propagation: within blocks.

Cipher Block Chaining (CBC) Mode

Blocks chained together: the plaintext XORed with previous ciphertext (or IV for the first block) and then encrypted.

Encryption

Ct=E(PtCt1,K) C_t = E(P_t \oplus C_{t - 1}, K)

for 1tn1 \le t \le n where C0=IVC_0 = IV.

Decryption

Pt=D(Ct,K)Ct1 P_t = D(C_t, K) \oplus C_{t - 1}

Where C0=IVC_0 = IV.

Properties

Randomized Padding IV Parallel encryption Parallel decryption
Yes Required Random No Yes

Error propagation: within blocks and into specific bits in the next block.

Parallel decryption means that decryption does not require the plaintext of previous block. However, it does require the ciphertext of the previous block.

Commonly used for bulk encryption, was often used in TLS up to TLS 1.2.

Counter (CTR) Mode

Synchronous stream cipher mode.

Encryption

The counter and a nonce (IV) are initialized using a random value NN:

Tt=Nt T_t = N \| t

That is, TtT_t is the concatenation of the nonce NN with the block number tt.

Then, this result is encrypted with the key KK:

Ot=E(Tt,K) O_t = E(T_t, K)

Finally, it is XORed with the plaintext block PtP_t:

Ct=OtPt=E(Nt,K)Pt \begin{aligned} C_t &= O_t \oplus P_t \\ &= E(N \| t, K) \oplus P_t \end{aligned}

Decryption

Pt=OtCt P_t = O_t \oplus C_t

Properties

Randomized Padding IV Parallel encryption Parallel decryption
Yes Optional Unique Yes Yes

A one-bit change in ciphertext produces one-bit change in the plaintext at the same location.

This allows access to specific plaintext blocks without decrypting the whole stream.

CTR mode is the basis for authenticated encryption in TLS 1.2.

Authentication Mode

Message Integrity

Ensuring messages are not altered in transmission: preventing an adversary from re-ordering, replacing, replication and deleting message blocks to alter the received message.

Message integrity and authentication are treated as the same thing.

Proving message integrity is independent from using encryption for confidentiality.

Message Authentication Code (MAC)

T=MAC(M,K) T = \mathrm{MAC}(M, K)

Where MM is an arbitrary-length message and KK a secret key KK.

The output TT is a short, fixed-length tag.

Given both parties share the key KK:

MAC Properties

Only the sender and receiver can produce TT from MM.

If T=TT' = T, the receiver can conclude the message received is from the expected sender and has not been modified in transit. Otherwise, the receiver can conclude (M,T)(M', T) was not sent by the expected sender.

It has the basic security property of unforgeability: it is infeasible to produce MM and TT such that T=MAC(M,K)T = \mathrm{MAC}(M, K) without knowledge of KK.

Basic CBC-MAC

Using block cipher to create a MAC providing message integrity (but not confidentiality).

If PP is the message with nn blocks:

Ct=E(PtCt1,K) C_t = E(P_t \oplus C_{t - 1}, K)

For 1tn1 \le t \le n such that C0=IVC_0 = IV.

T=CBC-MAC(P,K)T = \mathrm{CBC\text{-}MAC}(P, K) is the last cyphertext: T=CnT = C_n.

It is unforgeable as long as the message length is fixed.

IVIV must be fixed and public (e.g. all zeroes): CBC-MAC with a random IV is NOT secure:

Cipher-based MAC (CMAC)

Standardized, NIST version of CBC-MAC. The IV is all zeroes. The below is as per RFC4493.

Two keys K1K_1 and K2K_2 are derived from the original key KK.

K1K_1 OR K2K_2 is XORed with MnM_n (with padding as necessary).

For 1tn11 \le t \le n - 1 and C0=IV=0000C_0 = IV = 00\dots00:

Ct=E(PtCt1,K) C_t = E(P_t \oplus C_{t - 1}, K)

For the final block:

Pn={K1Pn,block completeK2(Pn100002),block incomplete P_n' = \begin{cases} K_1 \oplus P_n , & \text{block complete} \\ K_2 \oplus (P_n \| 100\dots00_2), & \text{block incomplete} \end{cases}

(That is, PnP_n concatenated with 1 and then enough zeros to fill up a block)

Then do the same operation as with the previous blocks , except that PnP_n' is used:

Cn=E(PnCn1,K) C_n = E(P_n' \oplus C_{n - 1}, K)

Finally, CMAC(P,K)=MSBTlen(Cn)\mathrm{CMAC}(P, K) = \mathrm{MSB}_{Tlen}(C_n)​​

NIST allows the length of the tag, TlenTlen,​ to be any number of bits, although 64 bits or greater is recommended.

The standard recommends the MAC tag TT to be of at least length log2(lim/R)\mathrm{log}_2(lim/R) where:

Authenticated Encrypted Mode

Two types of input data:

NIST specifies two modes:

Both use CTR mode but add integrity in different ways.

Both are used in TLS 1.2 and 1.3.

Counter with CBC-MAC (CCM) Mode

CBC-MAC for authentication of all data, CTR mode encryption for the payload.

Inputs:

Compute the CBC-MAC tag, getting TT with length TlenTlen.

Split the message MM into blocks of 128128 bits. That is, into m=Plen/128m = \lceil Plen/128 \rceil blocks:

S=S0S1Sm S = S_0 \| S_1 \| \dots S_m

Then, use CTR mode to compute blocks.

C=(PMSBPlen(S))(TMSBTlen(S0)) C = (P \oplus \mathrm{MSB}_{Plen}(S)) \| (T \oplus \mathrm{MSB}_{Tlen}(S_0))

From RFC3610:

CCM Mode Format

Lengths of NN and PP are included in the first block.

If AA is non-zero, then formatted from the second block onwards, including its length.

e.g. TLS 1.2: TT 8 bytes, NN 12 octets, max payload size 22412^{24} - 1 bytes.

07. Pseudorandom Numbers and Stream Ciphers

Random Numbers

Randomness: want any specific string of bits is exactly as random as any other string.

True random number generator (TRNG): physical process which outputs each valid string independently with equal probability.

Pseudorandom number generator (PRNG): deterministic algorithm which approximates a TRNG.

For practically, TRNGs are often used to provide a seed for a PRNG.

Pseudorandom Number Generator (PRNG)/Deterministic Random Bit Generator (DRBG)

Entropy source includes:

Periodic health tests required to ensure reliable operation.

Each generator takes a seed as an input, outputting a bit string before updating its state.

The seed should be updated after some number of calls.

DRBGs expose some functions:

The DDRBG should prevent an attacker from being able to reliably distinguish between its output and a truly random string. There are two types of resistance:

CTR_DRBG

Block cipher in counter (CTR) mode - AES with 128-bit keys recommended.

DRBG initialized with seed whose length is equal to key length PLUS block length.

Seed defines a key KK and counter value ctrctr (no separate nonce).

CTR run iteratively with no plaintext.

Update Function

Each request to the DRBG generates up to 2192^{19} bits.

State (K,ctr)(K, ctr) must be updated after each Generate request by generating two blocks using the current key to obtain a new key and counter; provides backtracking resistance.

Up to 2482^{48} requests to the Generate function are allowed before re-seeding is required; provides forwards prediction and backtracking resistance.

Dual_EC_DRBG

Older standard based on elliptic curve discrete logarithm problem and with many flaws.

Much slower than other DRBGs.

Secret deal between NSA and RSA Security to use this as the default PRNG in their software was reported in 2013.

Stream Ciphers

Generates keystream using a short key and initialization vector IVIV.

Each element of the keystream is used to successively encrypt one or more ciphertext characters.

Stream ciphers are usually symmetric.

Synchronous Stream Ciphers

Keystream is generated independently of the plaintext; both the sender and receiver need to generate the same keystream and be synchronized.

Keystream and plaintext are XORed together, so receiver simply needs to XOR the ciphertext with the keystream to decrypt.

Vigenère cipher can be seen as a periodic synchronous stream cipher where each shift is defined by a key letter.

CTR mode of operation for a block cipher can be used to generate a keystream.

Binary Synchronous Stream Ciphers

For each time interval tt:

Encryption: c(t)=p(t)s(t)c(t) = p(t) \oplus s(t).

Decryption: p(t)=c(t)s(t)p(t) = c(t) \oplus s(t).

One-Time Pad

Key is random sequence of characters such that each is independently generated.

Each character in the key is only used once; this provides perfect secrecy.

Alphabet can be of any length but is usually either binary or a natural language alphabet.

Perfect Secrecy

Shannon’s definition:

The ciphertext should be independent of the plaintext

One-Time Pad Perfect Secrecy

Let a ciphertext CjC_j be observed.

The probability that MiM_i was sent given that CjC_j is observed is the probability that MiM_i is chosen, weighted by the probability that the right keystream is chosen.

As each keystream is chosen with equal probability, Pr(MiCj)=Pr(Mi)\mathrm{Pr}(M_i | C_j) = \mathrm{Pr}(M_i).

Any keystream is possible and so given any plaintext, every possible ciphertext is generated with equal probability.

Vernam Binary One-Time Pad

Properties

Shannon showed that any ciphertext with perfect secrecy must have as many keys as there are messages. Hence, one-time pad is the only unbreakable cipher.

However, this requires secure communication between fixed parties and secure key generation, transportation, synchronization, and destruction which are all difficult due to the size of the keys.

Visual Cryptography

Encryption splits an image into two shares, each pixel being shared in a random way (similar to splitting a bit in a one-time pad).

Each share alone reveals no information about the image, but the two images can be overlayed to reveal the plaintext.

Prominent Stream Ciphers

A5 Cipher

Binary synchronous stream cipher applied in most GSM communications. Three variants:

A5/1 Design

Three linear feedback shift registers (LFSRs) whose outputs are combined.

The LFSRs are irregularly clocked, making the overall output non-linear.

It has a 64-bit keystream such that 10 bits are fixed to zero; hence, the effective key length is 54 bits.

RC4 Cipher

Ron’s code #4 . Originally owned by RSA but leaked in 1994. Too weak to use in real systems nowadays, but was was widely deployed in TLS before 2013.

ChaCha Algorithm

Possible replacement of RC4 designed in 2008.

Faster than AES; as few as 4 cycles/byte on x84 processors.

Number Theory for Public Key Cryptography

Chinese Remainder Theorem (CRT)

Let pp, qq be relatively prime.

Let n=pqn = pq be the modulus.

Given integers c1c_1 and c2c_2 there exists a unique integer 0x<n0 \le x \lt n such that:

xc1(modp)xc2(modq) \begin{aligned} x &\equiv c_1 \pmod p \\ x &\equiv c_2 \pmod q \end{aligned}
xnpy1c1+nqy2c2(modn) x \equiv \frac{n}{p}y_1c_1 + \frac{n}{q}y_2c_2 \pmod n

Where:

y1(np)1(modp)q1(modp)y2(nq)1(modq)p1(modq) \begin{aligned} y_1 \equiv \left(\frac{n}{p}\right)^{-1} \pmod p \equiv q^{-1} \pmod p \\ y_2 \equiv \left(\frac{n}{q}\right)^{-1} \pmod q \equiv p^{-1} \pmod q \end{aligned}

Condensed Equation:

xqc1(q1(modp))+pc2(p1(modq))(modpq) x \equiv qc_1(q^{-1} \pmod p) + pc_2(p^{-1} \pmod q) \pmod{pq}

Example

Find xx such that x5(mod6)x \equiv 5 \pmod 6 and x33(mod35)x \equiv 33 \pmod {35}:

For y1y_1:

2106y11(mod6)35y11(mod6)5y11(mod6)y15(mod6) \begin{aligned} \frac{210}{6}y_1 &\equiv 1 \pmod 6 \\ 35y_1 &\equiv 1 \pmod 6 \\ 5y_1 &\equiv 1 \pmod 6 \\ y_1 &\equiv 5 \pmod 6 \end{aligned}

Make sure you replace qq with qmodpq \bmod p (assuming q>pq \gt p): otherwise instead of finding 51(mod6)5^{-1} \pmod 6, you will find 61mod356^{-1} \bmod{35}.

For y2y_2:

21035y11(mod35)6y11(mod35)y16(mod35) \begin{aligned} \frac{210}{35}y_1 &\equiv 1 \pmod {35} \\ 6y_1 &\equiv 1 \pmod {35} \\ y_1 &\equiv 6 \pmod {35} \end{aligned}
xnpy1c1+nqy2c2(modn)(3555)+(6633)(mod210)173(mod210) \begin{aligned} x &\equiv \frac{n}{p}y_1c_1 + \frac{n}{q}y_2c_2 \pmod n \\ &\equiv (35 \cdot 5 \cdot 5) + (6 \cdot 6 \cdot 33) \pmod {210} \\ &\equiv 173 \pmod {210} \end{aligned}

Example 2

Find xx such that x5(mod7)x \equiv 5 \pmod{7} and x7(mod10)x \equiv 7 \pmod{10}

gcd(7,10)=1\mathrm{gcd}(7, 10) = 1; pp and qq are relatively prime. Hence, CRT applies.

Hence n=710=70n = 7 \cdot 10 = 70

x10y15+7y27(mod70)50y1+49y2(mod70) \begin{aligned} x &\equiv 10 \cdot y_1 \cdot 5 + 7 \cdot y_2 \cdot 7 &\pmod{70} \\ &\equiv 50 y_1 + 49 y_2 &\pmod{70} \end{aligned}

Where:

Hence:

x50y1+49y2(mod70)505+493(mod70)250+147(mod70)40+7(mod70)47(mod70) \begin{aligned} x &\equiv 50 y_1 + 49 y_2 &\pmod{70} \\ &\equiv 50 \cdot 5 + 49 \cdot 3 &\pmod{70} \\ &\equiv 250 + 147 &\pmod{70} \\ &\equiv 40 + 7 &\pmod{70} \\ &\equiv 47 &\pmod{70} \end{aligned}

Test:

Euler Function

Given the positive integer nn, the Euler function ϕ(n)\phi(n) denotes the number of positive integers less than nn and relatively prime to nn.

e.g. ϕ(10)=4\phi(10) = 4 as Z10={1,3,7,9}\mathbb{Z}^{*}_{10} = \{ 1, 3, 7, 9 \}.

Properties

ϕ(p)=p1\phi(p) = p - 1 where pp is prime.

ϕ(pq)=(p1)(q1)\phi(pq) = (p - 1)(q - 1) where pp and qq are distinct primes.

if n=p1e1ptetn = p_1^{e_1} \dots p_t^{e_t} where pip_i are distinct primes, then:

ϕ(n)=i=1tpiei1(pi1) \phi(n) = \prod_{i = 1}^{t}{p_i^{e_i - 1}(p_i - 1)}

e.g. for 24=233124 = 2^3 \cdot 3^1, ϕ(24)=22(21)30(31)=42=8\phi(24) = 2^2(2 - 1) \cdot 3^0(3 - 1) = 4 \cdot 2 = 8

Fermat’s Theorem

Let pp be a prime; for any integer aa such that 1<ap11 \lt a \le p - 1:

ap1modp=1 a^{p - 1} \mod p = 1

Euler’s Theorem

More general case of Fermat’s theorem.

If gcd(a,n)=1\mathrm{gcd}(a, n) = 1 (i.e. aa and nn coprime) then:

aϕ(n)modn=1 a^{\phi(n)} \mod n = 1

Primality Tests

Testing for primality by trial division not practical for large numbers.

There are many probabilistic methods, although these may fail in exceptional circumstances.

Agrawal, Saxena, Kayal 2002: polynomial time deterministic primality test, although still impractical.

Fermat Primality Test

Fermat’s little theorem: if pp is prime, ap1modp=1a^{p - 1} \mod p = 1 for all aa such that gcd(a,p)=1\mathrm{gcd}(a, p) = 1.

If an1modn1a^{n - 1} \mod n \neq 1, nn is NOT a prime.

The probability of failure can be reduced by repeating the test with different base values of aa.

Given the number nn to test for primality and kk, the number of times to run the test:

Some composite numbers such as 561561 and 11051105 are called Carmichael numbers; the Fermat primality test always returns these numbers as being probable primes.

Example

Check if 517517 is prime, running the test at most four times with values a=2,3,11,17a = 2, 3, 11, 17.

n1=5171=516=43322n - 1 = 517 - 1 = 516 = 43 \cdot 3 \cdot 2^2

Using a=2a = 2:

2516mod517=(243mod517)12mod517=(382)12mod517=((382)3mod517)4mod517=(28)4mod517=4601 \begin{aligned} 2^{516} \bmod{517} &= \left(2^{43} \bmod{517}\right)^{12} \bmod{517} \\ &= (382)^{12} \bmod{517} \\ &= \left((382)^3 \bmod{517}\right)^4 \bmod{517} \\ &= (28)^{4} \bmod{517} \\ &= 460 \neq 1 \end{aligned}

Hence it is composite, so we do not need to make further checks.

Miller-Rabin Test

Most widely used test for generating large prime numbers. It is guaranteed to detect composite numbers of the test is run sufficiently many times.

Modular square root of 11: a number xx such that x2modn=1x^2 \mod n = 1. In other words, the root of the equation x21(x1)(x+1)0(modn)x^2 - 1 \equiv (x - 1)(x + 1) \equiv 0 \pmod n.

There are four square roots of 11 when n=pqn = pq (i.e. composite):

If xx is a non-trivial square root of 11 then gcd(x1,n)\mathrm{gcd}(x - 1, n) is a non-trivial factor of nn. Hence, nn must be composite.

Miller-Rabin Algorithm

Let nn and uu be odd and find vv such that n1=2vun - 1 = 2^v u. Then:

  1. Pick aa at random such that 1<a<n11 \lt a \lt n - 1
  2. Set b=aumodnb = a^u \mod n
  3. If b=1b = 1, return probable prime
  4. For j=0j = 0 to v1v - 1:
    • If b=1b = -1, return probable prime
    • Else, set b=b2modnb = b^2 \mod n
  5. Return composite

If the test returns probable prime, nn may be composite.

If nn is composite then then test returns probable prime with at most a probability of 0.250.25.

As the algorithm is run kk times, it outputs probable prime when nn is composite with a probability of no more than 0.25k0.25^k.

In practice, the error probability is smaller: when aa is given the first seven primes, the smallest composite the algorithm returns as being a probable prime is 341,550,071,728,321341,550,071,728,321

Why The Miller-Rabin Test Works

Given a random aa such that 0<a<n10 \lt a \lt n - 1, with n1n - 1 being equal to 2vu2^v u.

Hence, bb can be given the values {aumodn,a2umodn,,a2vumodn}\{ a^u \mod n, a^{2u} \mod n, \dots, a^{2^{v}u} \mod n \}.

Each number on the sequence is the square of the previous number (modulo nn).

If nn is prime, a2vumodn=an1=1a^{2^v u} \mod n = a^{n - 1} = 1 (Fermat’s theorem). Hence:

If a non-trivial square root of 11 is found, nn must be composite.

Example

Let n=1729n = 1729 (a Charmichael number)

n1=1728=64×27=26×27n - 1 = 1728 = 64 \times 27 = 2^6 \times 27. Hence, v=6v = 6, u=27u = 27.

  1. Choose a=2a = 2
  2. b=227mod1729=645b = 2^{27} \bmod{1729} = 645
  3. b1b \neq 1 so:
    • b=6452modn=1065b = 645^2 \bmod n = 1065
    • b=10652modn=1b = 1065^2 \bmod n = 1
    • b=12modn=1b = 1^2 \bmod n = 1
    • \dots
    • Hence, b=1=n1b = -1 = n - 1 will never occur
    • Hence, nn must be composite

NB: 10641064 is a non-trivial square root of 11 modulo 17291729: gcd(1729,1064)=133\mathrm{gcd}(1729, 1064) = 133 is a factor of 17291729.

Example 2

Let n=17n = 17.

n1=16=2vun - 1 = 16 = 2^vu.

16=2516 = 2^5 and uu must be odd. Hence, the only valid values are u=1u = 1 and v=5v = 5.

Let 1<a<n11 < a < n - 1 be a prime. Pick a=3a = 3:

Hence, 1717 is a probable prime. Repeat for other values of aa until satisfied.

Generation of Large Primes

  1. Choose a random odd integer nn of the same number of bits as the required prime
  2. Test if rr is divisible by any of a small list of primes
  3. If not:
    • Apply the Miller-Rabin test five random or fixed based values of aa
    • If rr fails any test, set r=r+2r = r + 2 and return to step 2

This incremental method does not produce completely random primes. If this is an issue start from step 1 if rr is found to be composite.

Basic Complexity Theory

Two aspects:

Express this complexity using ‘big O’ notation; in terms of the space and time required to solve the problem for a given size.

Hard Problems

Integer factorization: given an integer of mm bits, find its prime factors.

Discrete logarithm problem (base 2): given a prime pp of mm bits and an integer 0<y<p0 \lt y \lt p, find xx such that y=2xmodpy = 2^x \mod p

There are no known polynomial algorithms to solve the problems; the best known algorithms are sub-exponential.

Factorization Problem

Trial by division: exponential time algorithm

Some fast methods exist, although they only apply to integers with particular properties.

Bets known general method: number field sieve, a sub-exponential algorithm.

As n=pqn = pq, nn is large even with small keys; brute force search of 128-bit AES keys takes roughly the same computational effort as factorization of a 3072-bit number with two factors of roughly equal size.

Discrete Logarithm Problem

Given a prime pp and generator gg of Zp\mathbb{Z}_p^*, the discrete logarithm is:

Given yZpy \in \mathbb{Z}_p^*, find xx such that y=gxmodpy = g^x \bmod p.

(i.e. find the power given the remainder)

This can be written as x=logg(y)(modp)x = log_g(y) \pmod p.

If pp is large enough, the problem is hard. Given the same length, the security level is equal RSA (and hence should be at least 2048 bits).

Example

Find xx such that 2x=3mod52^x = 3 \bmod 5:

1:21mod5=22:22mod5=4mod5=43:23mod5=8mod5=3 \begin{aligned} 1&: 2^1 \bmod 5 = 2 \\ 2&: 2^{2} \bmod 5 = 4 \bmod 5 = 4 \\ 3&: 2^{3} \bmod 5 = 8 \bmod 5 = 3 \\ \end{aligned}

Hence x=3x = 3.

Example 2

Find the discrete logarithm of the number 44 with regard to base 22 for the modulus p=7p = 7.

i.e. solve 2x=4mod72^x = 4 \bmod 7.

1:212(mod7)2:22224(mod7)3:234281(mod7)4:24122(mod7)5:24224(mod7) \begin{aligned} 1&: 2^1 &\equiv 2 &\pmod 7 \\ 2&: 2^2 \equiv 2 \cdot 2 &\equiv 4 &\pmod 7 \\ 3&: 2^3 \equiv 4 \cdot 2 \equiv 8 &\equiv 1 &\pmod 7 \\ 4&: 2^4 \equiv 1 \cdot 2 &\equiv 2 &\pmod 7 \\ 5&: 2^4 \equiv 2 \cdot 2 &\equiv 4 &\pmod 7 \end{aligned}

There is a cycle with powers of 22 modulo 77 taking on the values 2,4,12, 4, 1. Hence, x=2x = 2.

09. Hash Functions and MACs

Hash Functions

A public function HH such that:

Security Properties

If an attacker can break second-preimage resistance, they can also break collision resistance.

Birthday Paradox

If there is a group of 23 people, there is over a 50% chance that at least two people have the same birthday.

If choosing S\sqrt{|S|} values from a set SS, the probability of getting two values the same is about half (n2Spcollisionn \approx \sqrt{2|S| \cdot p_\text{collision}}).

Hence, if HH is a hash function with an output size of kk bits, 2k/22^{k/2} trials will be enough to find a collision half the time (assuming HH is a random function).

Today, 21282^{128} trials is considered infeasible so hash functions should have an output of at least 256 bits for collision resistance.

In comparison, to get a 50% change of guessing the key of a block cipher requires only 2k12^{k - 1} trials, so hash functions require about double the number of bits compared to block ciphers for the same security.

Iterated Hash Functions

Iterated hash functions splits the input into fixed-size blocks and operates on them sequentially.

Merkle-Damgård Construction

A compression function hh taking fixed-sized inputs and applies them to the blocks of the message.

The compression function takes two nn-bit input strings x1x_1 and x2x_2 and produces an nn-bit output string yy:

m = m_1 || m_2 || m_3 || … || m_l

       m_1    m_2    m_3       m_l pad+len
        |      |      |         |     |
        |      |      |         |     |
        v      v      v         v     v
IV ---> h ---> h ---> h --...-> h---> h ---> H(m)

Security: if the compression function hh is collision-resistant, then so is HH.

Weaknesses:

The Merkle-Damgård construction is used in MD5, SHA-1 and SHA-2.

Standardized Hash Functions

MDx Family

Proposed by Ron Rivest, widely used in the 1990s.

128-bit output, all broken.

Secure Hash Algorithm (SHA)

Based on MDx family, more complex design with 160 bit output.

SHA-0 introduced 1993, SHA-1 in 1995 with minor changes. Both broken.

SHA-2 Family

Standardized 2015.

Hash sizes of 224, 256, 384 or 512 bits.

Minimum recommended is SHA-256 (256 bit hash, 512 bit blocks) - same security as AES-128.

Most secure is SHA-512: 512 bit hash, 1024 bit blocks.

Padding:

SHA-3

MDx, SHA families based on the same basic design which were vulnerable to a few unexpected attacks.

Keccak function picked by NIST in 2015 as as SHA-3: uses sponge function instead of compression.

Using Hash Functions

Hash functions do not depend a key; anyone can calculate it so it is not encryption.

However, it does help to provide data authentication:

Password storage:

Message Authentication Code

Ensures message integrity. takes in a message MM of arbitrary length and secret key KK and outputs a fixed-sized tag T=MAC(M,K)T = \mathrm{MAC}(M, K).

The tag TT is appended to the message and the recipient can compute TT' with the message they receive and their shared secret, checking to ensure that T=TT' = T.

Unforgeability: not feasible to produce a valid pair (M,T)(M, T) such that T=MAC(M,K)T = \mathrm{MAC}(M, K) without knowledge of KK.

Unforgeability under chosen message attack: even with access to an oracle that can calculate the MAC for an input message of the attacker’s choosing, they cannot create a valid tag themselves (i.e. guess the private key from tags they ask the oracle to generate).

MAC from Hash Function (HMAC)

Proposed by Bellare, Canetti and Krawczyk in 1996.

Can be built from any iterated hash function HH.

With a key KK that has been padded with zeroes to be the required block size and two fixed strings:

HMAC(M,K)=H((Kopad)H((Kipad)M)) \mathrm{HMAC}(M, K) = H((K \oplus \mathrm{opad}) \| H((K \oplus \mathrm{ipad}) \| M))

HMAC is secure if HH is collision resistant or HH is a pseudorandom function. It is designed to resist length-extension attacks, even if HH is a Merkle-Damgård construct.

HMAC is often used as a pseudorandom function to derive subkeys.

Authenticated Encryption

A and B share a key KK and AA wishes to send a message MM with confidentiality and authenticity/integrity.

Two options:

Combining Encryption and MAC

Three options:

Encrypt-then-MAC is the safest option: C=E(M,K1)C = E(M, K_1), T=MAC(C,K2)T = \mathrm{MAC}(C, K_2), send CTC \| T

MAC-then-encrypt was used in older versions of TLS while newer versions use authentication encryption modes.

https://crypto.stackexchange.com/questions/202/should-we-mac-then-encrypt-or-encrypt-then-mac

CTR Mode for Block Ciphers

Synchronous stream cipher. Counter initialized with random nonce NN, keystream generated by encrypting successive values of the counter:

Ot=E(Nt,K) O_t = E(N||t, K)

where tt is the block number.

Encryption and decryption is simply XORing the plain/ciphertext with OtO_t.

Galois Counter Mode (GCM)

CCM mode cannot be used for processing of streaming data: formatting function for NN, AA and PP requires knowledge of the length of AA and PP.

Combines CTR mode on the block cipher EE with a special keyed hash function GHASH (uses multiplication in finite field GF(2128)\mathrm{GF}(2^{128}).

GCM diagram

GHASH:

GASH diagram

HK=E(0128,K)HK = E(0^{128}, K) is the hash subkey. \cdot is multiplication in the finite field.

Output is Ym=GHASHHK(X1,,Xm)Y_m = \mathrm{GHASH}_{HK}(X_1, \dots, X_m)

Decryption:

10. Public Key Cryptography

Public key cryptography (PKC) has some features that symmetric key cryptography (SKC) does not and is applied for key management in protocols such as TLS and IPsec.

Discrete log-based ciphers are alternatives to PKC.

One-Way Functions

A function is one-way if f(x)=yf(x) = y is easily computed given xx, but f1(y)=xf^{-1}(y) = x is hard to computed given yy.

It is not known if one-way functions exist, but there are many functions that are believed to be one-way:

Trapdoor One-Way Functions

A function such that f1(y)f^{-1}(y) is easily computed given additional information, called a trapdoor.

Example: let f(x)=xemodnf(x) = x^e \bmod n for any xx co-prime to nn:

Asymmetric Cryptography

Another word to describe public key cryptography.

Public key cryptosystems, such as the Diffie-Hellman key exchange, are designed by using a trapdoor one-way function: the trapdoor is the decryption key.

This allows a public key to be stored in a public directory: anyone can obtain the public key and use it to form an encrypted message that only a person with the private key can decrypt.

Asymmetry: encryption and decryption keys are different. Encryption key is public and known to anybody; the decryption key is private and known only to its owner.

Finding the private key from the public key must be a hard computational problem.

Advantages of shared key/symmetric cryptography:

RSA

Designed in 1977 by Rivest, Shamir, and Adleman from MIT (patent expired 2000).

It is based on integer factorization problem.

Algorithm

Key generation:

Encryption:

Decryption:

Any message must be pre-processed:

Numerical Example

Key generation:

Encryption:

Decryption:

Numerical Example 2

Key generation:

Encryption:

Decryption:

Correctness

Decrypting an encrypted message: does (Me)dmodn=M(M^e)^d \bmod n = M?

As d=e1modϕ(n)d = e^{-1} \bmod \phi(n), edmodϕ(n)=1ed \bmod \phi(n) = 1: this can be written as being some integer kk such that ed=1+kϕ(n)ed = 1 + k\phi(n).

Hence, (Me)dmodn=Medmodn=M1+kϕ(n)modn(M^e)^d \bmod n = M^{ed} \bmod n = M^{1 + k\phi(n)} \bmod n.

Now we must show that M1+kϕ(n)modn=MM^{1 + k\phi(n)} \bmod n = M. There are two cases:

Case 1: Coprime to n

gcd(M,n)=1\mathrm{gcd}(M, n) = 1. In this case, we can apply Euler’s theorem, Mϕ(n)modn=1M^{\phi(n)} \bmod n = 1:

M1+kϕ(n)modn=M(Mϕ(n))kmodn=M1kmodn=M \begin{aligned} M^{1 + k\phi(n)} \bmod n &= M \cdot (M^{\phi(n)})^k \bmod n \\ &= M \cdot 1^k \bmod n \\ &= M \end{aligned}
Case 2: Multiple of p or q

Since pp and qq are prime and M<pqM < pq, if gcd(M,n)1\mathrm{gcd}(M, n) \neq 1, MM must be a multiple of either pp and qq and hence coprime to the other prime.

Supposing that gcd(M,p)=1\mathrm{gcd}(M, p) = 1, gcd(M,q)=q\mathrm{gcd}(M, q) = q and hence, there is some integer ll such that M=lqM = lq.

Applying Fermat’s theorem, Mϕ(p)modp=Mp1modp=1M^{\phi(p)} \bmod p = M^{p - 1} \bmod p = 1:

M1+kϕ(n)modp=M(Mϕ(n))kmodp=M(Mp1)k(q1)modp=M1k(q1)modp=Mmodp \begin{aligned} M^{1 + k\phi(n)} \bmod p &= M \cdot \left(M^{\phi(n)}\right)^k &\bmod p \\ &= M \cdot \left(M^{p - 1}\right)^{k(q - 1)} &\bmod p \\ &= M \cdot 1^{k(q - 1)} &\bmod p \\ &= M &\bmod p \end{aligned}

As M=lqM = lq M1+kϕ(n)modq=0M^{1 + k\phi(n)} \bmod q = 0. As n=pqn = pq and pp and qq are primes, we can use the Chinese Remainder Theorem:

Applications

Implementation

A few implementation details

Key Generation

Generating large primes pp and qq:

Choice of ee:

Encryption/decryption

Fast Exponentiation

A square-and-multiply modular exponentiation algorithm.

In binary, e=e020+e121++ek2ke = e_0 \cdot 2^0 + e_1 \cdot 2^1 + \dots + e_k \cdot 2^k, where eie_i are bits.

If MM is the plaintext, Me=Me0(M2)e1(M2k)ekM^e = M^{e_0} \cdot (M^2)^{e_1} \cdot \dots \cdot (M^{2^k})^{e_k} where (M2i)ei(M^{2^i})^{e_i} is zero when ei=0e_i = 0 and M2iM^{2^i} when ei=1e_i = 1.

Code:

// 2^66 % 100
M = 2   // base
n = 100 // modulus
e = [0, 1, 0, 0, 0, 0, 1] // exponent as bits, LSB first
z = 1; // Result - M^e \bmod n
for(let i = 0; i < e.length - 1; i++) {
  if(e[i] == 1) {
    z = (z * M) % n;
    // z = 1 initially so first multiplication is unnecessary
    // Hence e.filter(i => i == 1).length - 1 multiplications
  }
  
  M = (M * M) % n; // equals base^{2^{i + 1}}
  // When i = 0, M = base^1 - right for the next iteration
  // Does not need to be calculated for the i + 1 == e.length
  // as the value is used for the next iteration
}

Cost:

Faster Decryption Using CRT

Decrypting CC with respect to pp and qq separately.

Compute Mp=Cdmod(p1)(modp)M_p = C^{d \bmod (p - 1)} \pmod p and Mq=Cdmod(q1)(modq)M_q = C^{d \bmod (q - 1)} \pmod q

Solve MmodnM \bmod n using CRT. d=(dmod(p1))+k(p1)d = (d \bmod (p - 1)) + k(p - 1) for some kk. Hence:

Mmodp=Cdmodnmodp=Cdmodp=Cdmod(p1)Ck(p1)modp=Cdmod(p1)=Mp \begin{aligned} M \bmod p &= C^{d \bmod n} \bmod p = C^d \bmod p \\ &= C^{d \bmod (p - 1)} C^{k(p - 1)} \bmod p = C^{d \bmod (p - 1)} \\ &= M_p \end{aligned}

Hence, MMpmodpM \equiv M_p \bmod p and similarly, MMqmodqM \equiv M_q \bmod q.

Then we can output M=q(q1modp)Mp+p(p1modq)MqmodnM = q\cdot (q^{-1} \bmod p) \cdot M_p + p \cdot (p^{-1} \bmod q) \cdot M_q \bmod n.

Speedup

Exponents dmod(p1)d \bmod (p - 1) and dmod(q1)d \bmod (q - 1) are about half the length of dd and the complexity of exponentiation with square-and-multiply increases with the cube of input length.

Hence, computing each of MpM_p and MqM_q uses about an eighth of the computation, leading to four times less computation.

Hence, storing pp and qq instead of just nn allows for faster decryption.

Padding

Encryption directly on the message encoded as a number is bad as it is vulnerable to attacks:

Hence, a padding mechanism must be used to prepare the message for encryption, adding redundancy and randomness.

Håstad’s Attack

The same message MM is encrypted without padding to three different ciphertexts C1C_1, C2C_2, C3C_3 with the public exponent e=3e = 3 being used by all recipients.

C1=M3modn1C2=M3modn2C3=M3modn3 \begin{aligned} C_1 = M^3 \bmod n_1 \\ C_2 = M^3 \bmod n_2 \\ C_3 = M^3 \bmod n_3 \end{aligned}

Equations can be solved using the CRT to obtain M3M^3 in the ordinary (non-modular integers). The attacker can then simply take the cube root to find MM.

Padding Types

Security

Attacks

Mostly avoided through the use of standardized padding mechanisms.

Possible attacks:

Practical Problems with Key Generation

Diffie-Hellman Key Exchange

Two users sharing a secret using only public communication.

Public elements:

Alice and Bob randomly select values aa and bb respectively, where 1<a,b<p1 < a, b < p.

Over an insecure channel, Alice sends gag^a, Bob sends gbg^b.

Both compute the secret key Z=gabmodpZ = g^{ab} \bmod p: (gb)a(ga)b)(modp)(g^b)^a \equiv (g^a)^b) \pmod p.

Example

Let p=181p = 181, g=2g = 2, a=50a = 50, b=33b = 33.

Both compute Z=(gb)amodp=(ga)bmodp=3050mod181=11633mod181=49Z = (g^b)^a \bmod p = (g^a)^b \bmod p = 30^{50} \bmod{181} = 116^{33} \bmod{181} = 49

Properties

Security

Relies on the difficulty of the discrete logarithm problem.

If an attacker intercepts gamodpg^a \bmod p and take the discrete logarithm to find aa, they can compute (gb)a(g^b)^a in the same way as Bob.

There is no better known way for a passive adversary to find the shared secret.

Authenticated Diffie-Hellman

In the basic protocol, messages are not authenticated: a man-in-the-middle-attack is possible where the attacker acts as a proxy between the two parties, decrypting messages from one party and then re-encrypting messages to send to the other party with the other key.

Both parties must know each other’s public signature verification keys, AA and BB (identity + public key).

Static and Ephemeral Diffie-Hellman

The above protocol uses ephemeral keys: keys are used once. In the static protocol:

Elgamal Cryptosystem

Proposed by Elgamal in 1985, turning the Diffie-Hellman protocol into a cryptosystem for encryption and for signature.

Alice combines her ephemeral private key with Bob’s long-term public key

Algorithms

Key generation:

Encryption:

Decryption:

Correctness

Example

Key generation:

Encryption:

Decryption:

Security

Elliptic Curves

Algebraic structures formed from cubic equations.

Curves are defined over any field.

e.g. set of all (x,y)(x, y) pairs which satisfy y2=x3+ax+bmodpy^2 = x^3 + ax + b \bmod p, then creates a curve over the field Zp\mathbb{Z}_p.

A point on the curve is the identity element, and by defining a binary operation on the points (e.g. multiplication), we can form a group over elliptic curve’s points: the elliptic curve group.

Any elliptic curve can be used but most applications use standardized curves generated in a verifiably random way (e.g. NIST curve P-192 has curve of nn points over Zp\mathbb{Z}_p with generator (Gx,Gy)(G_x, G_y) and equation y2=x33x+bmodpy^2 = x^3 - 3x + b \bmod p with a defined random values for pp, nn, bb, GxG_x, GyG_y and seed ss.

Discrete log defined on elliptic curve groups: if elliptic curve operation operation denoted as multiplication, definition is the same as in Zp\mathbb{Z}_p^*.

Elliptic curve implementations require smaller keys compared to RSA:

Symmetric key RSA modulus EC element length
80 1024 160
128 3072 256
192 7680 384
256 15360 512

From Ars:

11. Digital Signatures

MACs allow entities with shared secrets to generate valid tags, providing data integrity and authentication.

Digital signatures use public key cryptography to provide additional properties: only the owner of a private signing key can generate a valid signature.

Non-repudiation: the signer cannot deny they have signed a message.

Properties

Algorithms: Key & signature generation, signature verification.

Key generation algorithm outputs a private signing key, KSK_S and public verification key, KVK_V.

Signature generation: s=Sig(M,KS)s = \mathrm{Sig}(M, K_S), where MM is a message of any length to sign. Only the owner should be able to generate a valid signature. The signature is usually a fixed size (and if there are multiple possible signatures for the same message, they will all be the same length).

Signature verification: Ver(M,s,KV)\mathrm{Ver}(M, s, K_V) outputs true or false.

Correctness: if s=Sig(M,KS)s = \mathrm{Sig}(M, K_S), then Ver(M,s,KV)=true\mathrm{Ver}(M, s, K_V) = \mathrm{true} (for matching KSK_S and KVK_V).

Unforgeability: computationally infeasible to generate signature for any message without key. Note that the signing algorithm may be randomized - many possible signatures for a message.

Stronger security definition: forging a new signature should be difficult even if they can obtain signatures for messages of their choice (chosen message oracle).

Security Goals

Key recovery: recovering the private signing key KSK_S fom the public verification key KVK_V and some known signatures.

Selective forgery: choosing a message and obtaining a signature for that message.

Existential forgery: forging a signature on any message not previously signed (even a meaningless message).

Modern digital signatures should be able to resist existential forgery under a chosen message attack.

RSA Signatures

Key Generation

Key generation is the same as for encryption keys:

A fixed public parameter, the hash function hh, is also required (e.g. SHA-256).

Signature Generation and Verification

Given message MM, modulus nn and private exponent dd, the signature is s=h(M)dmodns = h(M)^d \bmod n. (M,s)(M, s) is the signature.

Given claimed signature (M,s)(M, s), modulus nn and public exponent ee, check if semodn=h(M)s^e \bmod n = h(M)

Discrete Logarithm Signatures

Three versions:

  1. Original Elgamal signatures in Zp\mathbb{Z}_p^* (1985)
  2. Digital signature algorithm (DSA) standardized by NIST
  3. DSA based on elliptic curve groups: ECDSA

Elgamal Elements in Zp\mathbb{Z}_p^*

pp, gg and yy form the public verification key.

Signature generation:

Signature verification: check if

gMyrrs(modp) g^M \equiv y^r r^s \pmod p

Correctness

Fermat’s Little Theorem

Fermat’s little theorem: given a prime pp, for any integer a<pa < p:

apa=npa(ap11)=np \begin{aligned} a^p - a &= np \\ a(a^{p - 1} - 1) &= np \end{aligned}

if gcd(a,p)=1\mathrm{gcd}(a, p) = 1, anpa \neq np and hence:

ap11=npap11(modp) \begin{aligned} a^{p - 1} - 1 &= np \\ \therefore a^{p - 1} &\equiv 1 \pmod p \end{aligned}
Proving Correctness

Let My(modp1)M \equiv y \pmod{p - 1}:

aMaMan(p1)(modp)aM+n(p1)(modp)aMmod(p1)(modp)ay(modp) \begin{aligned} a^M &\equiv a^M \cdot a^{n(p - 1)} &\pmod{p} \\ &\equiv a^{M + n(p - 1)} &\pmod{p} \\ &\equiv a^{M \,\bmod{(p - 1)}} &\pmod{p} \\ &\equiv a^y &\pmod{p} \end{aligned}

Hence, coming back to the Elgamal signature verification equation (and noting that gg is a generator and hence relatively prime to pp:

gMgsk+xr(modp)gskgxr(modp)gskgxr(modp)(gk)s(gx)r(modp)rsyr(modp) \begin{aligned} g^M &\equiv g^{sk + xr} &\pmod p \\ &\equiv g^{sk}g^{xr} &\pmod p \\ &\equiv g^{sk}g^{xr} &\pmod p \\ &\equiv (g^k)^s(g^x)^r &\pmod p \\ &\equiv r^s y^r &\pmod p\\ \end{aligned}

as required.

Digital Signature Algorithm (DSA)

Published by NIST in 1994. Based on Elgamal signatures but calculations are simpler and signatures shorter: done in a subgroup of Zp\mathbb{Z}_p^* or an elliptic curve group. Also prevents attacks Elgamal signatures were vulnerable to.

Prime pp chosen such that p1p - 1 has a prime divisor qq that is much smaller.

Generator gg from Elgamal signatures is replaced by:

g=hp1qmodp g = h^{\frac{p - 1}{q}} \bmod p

where hh is a generator.

gg has order qq as gqmodp=1g^q \bmod p = 1 (by Fermat’s theorem, gqmodp=(hp1q)qmodp=hp1modp=1g^q \bmod p = \left(h^\frac{p - 1}{q}\right)^q \bmod p = h^{p - 1} \bmod p = 1). Hence, all exponents can be reduced modulo qq before exponentiation.

Let HH be a standard SHA hash algorithm such that the output is NN bits long (the same size as qq).

gH(M)yrrsmodpg^{H(M)} \equiv y^r r^s \bmod p so rearranged, we get the verification equation:

(gH(M))s1(yr)s1r(modp) \left(g^{H(M)}\right)^{s^{-1}} \left(y^{-r}\right)^{s^{-1}} \equiv r \pmod p

Both sides of the equation are reduced modulo qq.

pp is a LL-bit long prime modulus, qq a NN bit long a prime divisor of p1p - 1. There are several approved combinations for (L,N,Hash fn)(L, N, \text{Hash fn}): (1024,160,SHA-1)(1024, 160, \text{SHA-1}), (2048,224,SHA-224)(2048, 224, \text{SHA-224}), (2048,256,SHA-256)(2048, 256, \text{SHA-256}), (3072,256,SHA-256)(3072, 256, \text{SHA-256}). The first option may be insecure.

Key generation:

Signature generation:

Signature verification:

Verification equation is the same as with Elgamal except that all exponents and the final result is reduced modulo qq. Signature size is also smaller at 2N2N bits.

Correctness

Fermat’s Little Theorem

Where pp and qq are primes and gcd(p1,q)=m1\text{gcd}(p - 1, q) = m \neq 1, let nn be any integer.

ab+nqmodp=ab+np1mmodp=ab(ap1)nmmodp=ab1nmmodp=abmodp \begin{aligned} & a^{b + nq} &\bmod p \\ =& a^{b + n \cdot \frac{p - 1}{m}} &\bmod p \\ =& a^{b} \left(a^{p - 1}\right)^{\frac{n}{m}} &\bmod p \\ =& a^{b} \cdot 1^{\frac{n}{m}} &\bmod p \\ =& a^b &\bmod p \end{aligned}

Hence abmodqmodpabmodpa^{b \,\bmod q} \bmod p \equiv a^b \bmod p

Proving Correctness

Let My(modp1)M \equiv y \pmod{p - 1}:

aMaMan(p1)(modp)aM+n(p1)(modp)aMmod(p1)(modp)ay(modp) \begin{aligned} a^M &\equiv a^M \cdot a^{n(p - 1)} &\pmod{p} \\ &\equiv a^{M + n(p - 1)} &\pmod{p} \\ &\equiv a^{M \,\bmod{(p - 1)}} &\pmod{p} \\ &\equiv a^y &\pmod{p} \end{aligned}

Hence, coming back to the Elgamal signature verification equation (and noting that gg is a generator and hence relatively prime to pp:

gMgsk+xr(modp)gskgxr(modp)gskgxr(modp)(gk)s(gx)r(modp)rsyr(modp) \begin{aligned} g^M &\equiv g^{sk + xr} &\pmod p \\ &\equiv g^{sk}g^{xr} &\pmod p \\ &\equiv g^{sk}g^{xr} &\pmod p \\ &\equiv (g^k)^s(g^x)^r &\pmod p \\ &\equiv r^s y^r &\pmod p\\ \end{aligned}

as required.

Elliptic Curve DSA (ECDSA)

Similar to DSA except that:

Compared to DSA, public keys are shorter but signatures are not (326 to 1142 bits).

12. Public Key Infrastructure and Certificates

Public Key Infrastructure (PKI)

NIST: “… key management environment for public key information of a public key cryptographic system”

Must consider:

Digital Certificates

How do you confirm the relationship between the public key and the claimed owner of that key? Through the use of digital certificates:

Certificates are signed by a certification authority (that should be trusted by the certificate verifier).

Certification Authority

A CA creates, issues and revokes certificates for subscribers and other CAs.

A CA has a certification practice statement (CPS) which covers processes such as checks before issuing certificates, physical/procedural security controls, revocation processes.

X.509 Certificate

Now RFC 5280, currently on version 3.

Important fields:

Verification:

Certification paths: CAs can issue certificates to other CAs. Hence, as long as there is a chain of CAs leading to a trusted root CA, the last CA can be trusted and hence the certificate can be validated.

Phishing: attacker can make URL and interface similar to a genuine site

Extended validation certificates: certificate issued by only some CAs after they have validated the entity’s legal identity. Different icon in browsers, but mostly ignored by users.

Revocation:

Public Key Pinning:

PKI Examples

Hierarchical PKI:

   R           Root
  / \
 /   Y Intermediate
A     \         CAs
       Z
      / \
      B  C    Users

CA certifies public key of entity below. If non-hierarchical, certification can be done between any CAs.

Browser PKI:

OpenPGP PKI:

13. Key Establishment

Distribution of cryptographic keys to protect subsequent sessions. In TLS, public keys allow clients/servers to share a new communication key.

Kerberos: key establishment without public keys.

Key Management

Key management has four phases:

Hierarchy

Keys often organized into a hierarchy. In a two-level hierarchy, there are long- and short-term keys:

Key Establishment

Symmetric keys with ciphers (e.g. AES, MAC) are used in practice for session keys as as they are more efficient than public key algorithms.

Long-term keys can be symmetric or asymmetric.

Key Distribution Security Goals

Authentication: they should be able to authenticate that the receiver is the party they intended to send the key to.

Confidentiality: no adversary can obtain the session key accepted by a particular party.

In formal models, the protocol is broken if the adversary can distinguish the session key from a random string.

Mutual and Unilateral Authentication

Mutual authentication: both parties achieve the authentication goal.

Unilateral authentication: only one party achieves the authentication goal. This is done by most real-world key establishment protocols: typically clients authenticate the server with client authentication happening later.

Adversary Capabilities

A strong adversary knows the details of the cryptographic algorithms and can:

Distribution of Pre-Shared Keys

A trusted authority (TA) generates and distributes long-term keys to all users when they join the system. Their involvement ends here in the pre-distribution phase so if there are no new users they can go offline.

A simple scheme is to assign a secret key for each pair of users, but this will not scale well as the number of keys grows quadratically.

Probabilistic schemes reduce key material at each party by forwarding messages to other parties that hopefully have a link to the final receiver. Hence, it offers only a high probability of a secure channel between any two parties and requires other nodes to be trusted as they must decrypt and re-encrypt the message. This is suitable for sensor networks.

Key Distribution using Symmetric Keys

Key distribution with online server.

A TA shares a long-term shared key with each user. They distribute session keys to users when requested and hence, the TA is highly trusted and is a single point of attack. Scalability may also be a problem.

Needham-Schroeder Protocol

Widely-known key establishment protocol published 1978. Found vulnerable to replay attacks in 1981 - attacker can replay old messages that a honest party will accept an old session key.

Notation:

Protocol:

1.AS:IDA,IDB,NA2.SA:{KAB,IDA,IDB,NA,{KAB,IDA,IDB}KBS}KAS3.AB:{KAB,IDA,IDB}KBS,IDA4.BA:{NB}KAB5.AB:{NB1}KAB \begin{aligned} \text{1.}\>& A \to S: \mathrm{ID}_A, \mathrm{ID}_B, N_A \\ \text{2.}\>& S \to A: \left\{ K_{AB}, \mathrm{ID}_A, \mathrm{ID}_B, N_A, \left\{ K_{AB}, \mathrm{ID}_A, \mathrm{ID}_B \right\}_{K_{BS}} \right\}_{K_{AS}} \\ \text{3.}\>& A \to B: \left\{ K_{AB}, \mathrm{ID}_A, \mathrm{ID}_B \right\}_{K_{BS}}, \mathrm{ID}_A \\ \text{4.}\>& B \to A: \{ N_B \}_{K_{AB}} \\ \text{5.}\>& A \to B: \{ N_B - 1 \}_{K_{AB}} \end{aligned}
Replay Attacks

If an attacker CC gets a previous session key KABK'_{AB}, they can masquarade as AA and persuade BB to use the old key (steps 3-5).

To defend against this, the established key must be fresh for each session:

The repaired protocol uses random challenges. After AA establishes request for connection with BB:

1.BA:IDB,NB2.AS:IDA,IDB,NA,NB3.SA:{KAB,IDA,IDB,NA}KAS,{KAB,IDA,IDB,NB}KBS4.AB:{KAB,IDA,IDB,NB}KBS \begin{aligned} \text{1.}\>& B \to A: \mathrm{ID}_B, N_B \\ \text{2.}\>& A \to S: \mathrm{ID}_A, \mathrm{ID}_B, N_A, N_B \\ \text{3.}\>& S \to A: \left\{ K_{AB}, \mathrm{ID}_A, \mathrm{ID}_B, N_A \right\}_{K_{AS}}, \left\{ K_{AB}, \mathrm{ID}_A, \mathrm{ID}_B, N_B \right\}_{K_{BS}} \\ \text{4.}\>& A \to B: \left\{ K_{AB}, \mathrm{ID}_A, \mathrm{ID}_B, N_B \right\}_{K_{BS}} \end{aligned}

Tickets can also be used: if AA wishes to communicate with BB, SS generates ticket {KAB,IDA,IDB,TB}KBS\left\{ K_{AB}, \mathrm{ID}_A, \mathrm{ID}_B, T_B \right\}_{K_{BS}} where TBT_B is a validity period - AA can use the ticket for this duration.

1.AS:IDA,IDB,NA2.SA:{KAB,IDA,IDB,NA}KAS,ticket3.AB:ticket \begin{aligned} \text{1.}\>& A \to S: \mathrm{ID}_A, \mathrm{ID}_B, N_A \\ \text{2.}\>& S \to A: \left\{ K_{AB}, \mathrm{ID}_A, \mathrm{ID}_B, N_A \right\}_{K_{AS}}, \text{ticket} \\ \text{3.}\>& A \to B: \text{ticket} \end{aligned}

Kerberos

Now on V5, released 1995. Standardized as RFC 4120. Used in Windows as the default domain authentication method.

Kerberos allows:

It is a 3-level protocol:

Level 1

Client CC interacts with authentication server ASAS to obtain a ticket-granting ticket at the start of a session.

1.CAS:IDC,IDTGS,N12.ASC:{KC,TGS,IDTGS,N1}KC,ticketTGS \begin{aligned} \text{1.}\> C \to AS&: \mathrm{ID}_C, \mathrm{ID}_{TGS}, N_1 \\ \text{2.}\> AS \to C&: \left\{ K_{C, TGS}, \mathrm{ID}_{TGS}, N_1 \right\}_{K_{C}}, \text{ticket}_{TGS} \end{aligned}

Where:

At the end of this exchange, CC has a ticket-granting ticket that can be used to obtain different service-granting tickets from the ticket-granting server.

Level 2

Client CC interacts with ticket granting server TGSTGS:

1.CTGS:IDV,N2,ticketTGS,authenticatorTGS2.TGSC:IDC,ticketV,{KC,V,N2,IDV}KC,TGS \begin{aligned} \text{1.}\> C \to TGS&: \mathrm{ID}_V, N_2, \text{ticket}_{TGS}, \text{authenticator}_{TGS} \\ \text{2.}\> TGS \to C &: \mathrm{ID}_C, \text{ticket}_V, \{ K_{C, V}, N_2, \mathrm{ID}_V \}_{K_{C, TGS}} \end{aligned}

Where:

The ticket-granting server must also check that the client has permission to access the service VV.

In practice, the AS and TGS are the same machine.

Level 3

Client CC interacts with application server VV:

1.CV:ticketV,authenticatorV2.VC:{TS2}KC,V \begin{aligned} \text{1.}\> C \to V&: \text{ticket}_V, \text{authenticator}_V \\ \text{2.}\> V \to C&: \left\{ TS_2 \right\}_{K_{C, V}} \end{aligned}

Where:

The reply from VV is intended to provide mutual authentication, allowing CC to verify they are talking to the right VV.

Limitations

Realms (domains over which an authentication server has authority to authenticate a user) must share keys with every other realm, so although multiple realms are supported it has limited scalability.

KCK_{C} is derived from the user’s password, so offline password guessing is possible.

Key Distribution using Asymmetric Cryptography

No online TA is required. Instead, public keys (managed by PKI - certificates and CAs) is used for authentication. Users are trusted to generate good session keys (so hopefully each party has a good PRNG).

Key transport: user chooses key material and sends it to another party (encrypted, possibly signed). Does NOT provide forward secrecy.

Key agreement: Diffie-Hellman or some other protocol where both parties provide input to the key. The messages are signed, providing authentication. Provides forwards secrecy.

TLS supports both key transport and agreement.

Forward Secrecy

If a long-term key is compromised, the attacker can now claim to be the owner of the key. If key transport is used, all previous session keys will be compromised.

A protocol provides (perfect) forwards secrecy if compromise of the long-term secret keys do not reveal session keys previously agreed using the long-term keys.

Signed Diffie-Hellman

Computations done in Zp\mathbb{Z}_p^*. Notation:

Protocol:

  1. AA sends IDA\mathrm{ID}_A, gag^a
  2. BB sends IDB\mathrm{ID}_B, gbg^b and SignB(IDAIDAgbga)\mathrm{Sign}_B(\mathrm{ID}_A \| \mathrm{ID}_A \| g^b || g^a)
    • AA checks signature. If valid, computes session key KAB=(gb)a=gabK_{AB} = (g^b)^a = g^{ab}
  3. A sends SignB(IDAIDBgagb)\mathrm{Sign}_B(\mathrm{ID}_A \| \mathrm{ID}_B \| g^a || g^b)
    • BB checks signature. If valid, computes session key KAB=(ga)b=gabK_{AB} = (g^a)^b = g^{ab}

14. Transport Layer Security Protocol

The most widely used security protocol.

History:

Overview

Three higher-level protocols:

TLS record protocol provides basic services to the higher-level protocols. Stack:

|----------------------------------------|
| TLS       | TLS change |  TLS  | HTTP/ |
| Handshake |   cipher   | alert | Other |
|----------------------------------------|
|           TLS record protocol          |
|----------------------------------------|
|                  TCP                   |
|----------------------------------------|
|                  IP                    |
|----------------------------------------|

TLS Record Protocol

TLS offers:

These services may be provided by a symmetric encryption algorithm (confidentiality) and MAC (authentication/integrity). TLS 1.2 and above offer authenticated encryption modes (CCM, GCM), combining these two services into one.

The handshake protocol establishes the symmetric session keys used by the record protocol.

The record protocol also deals with dividing messages into blocks and re-assembling received blocks and possibly with compressing/decompressing block contents.

Format

                HEADER
|--------------------------------------|
| Content |  Major  |  Minor  | Length |
|  type   | version | version |        |
|--------------------------------------|

          ENCRYPTED CONTENTS
|--------------------------------------|
|              Plaintext               |
|        (possibly compressed)         |
|      (not available in TLS 1.3)      |
|--------------------------------------|
|                 MAC                  |
|  (unless authentication encryption)  |
|--------------------------------------|

Content type can be change-cipher-spec, alert, handshake or application-data.

TLS 1.3 does not allow the cipher suite to be changed to prevent downgrade attacks - a new session must be created.

Major version is 3 for TLS and minor version 1 to 4 for TLS 1.0 to 1.3.

Length of data is in octets.

Operation

MAC algorithm:

Encryption algorithm:

Authenticated encryption algorithm:

TLS Handshake Protocol

For:

Many variations supported - many were dropped to in TLS 1.3.

Phases

Cipher Suites

Specify the public key algorithms used for key establishment and symmetric algorithms used for authenticated encryption/key computation.

There were over 300 standardized cipher suites, many of which were discarded in TLS 1.3.

TLS 1.3 requires cipher suites to be Authenticated Encryption with Associated Data (AEAD). AEAD means that there is some associated data that must be sent in plain text (not confidential) but should be authenticated - for example, sequence numbers and other header information.

e.g. TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384:

e.g. TLS_RSA_WITH_3DES_EDE_CBC_SHA:

Handshake algorithms:

DH-RSA: permanent DH parameters part of the server certificate (signed with RSA), so there is no forwards secrecy.

Record algorithms:

Forwards Secrecy:

Handshake

Client hello (phase 1):

Server hello (phase 1):

Server key exchange (phase 2):

Client key exchange (phase 3):

Change cipher suite (phase 4):

Ephemeral Diffie-Hellman Handshake Variant

Server key exchange; server sends:

The response is signed by the server using their private key. The client must check this.

Client key exchange; client sends their ephemeral Diffie-Hellman value. Signed if the client has their own certificate.

Pre-master secret (pms\text{pms}) is the shared Diffie-Hellman secret that both parties have computed from the key exchange.

Steps:

  1. Client hello: TLS version, supported cipher suites, client nonce NCN_C
  2. Server hello: server certificate, chosen cipher suite, server nonce NSN_S
  3. Server signature: NCN_C, NSN_S and server’s DH parameter signed using server private key
  4. Client checks server signature, sends client’s DH parameter
  5. Pre-master secret calculated using DH parameters
  6. Session keys computed with PRF
  7. Client finished message: encrypted with session key
  8. Server finished message: encrypted with session key

RSA Handshake Variant

  1. Client hello: TLS version, supported cipher suites, client nonce NCN_C
  2. Server hello: server certificate, chosen cipher suite, server nonce NSN_S
  3. Client checks server certificate
  4. Pre-master secret key transport: client randomly chooses pre-master secret pms\text{pms}, encrypted with server’s public key
  5. Session keys computed with PRF
  6. Client finished message: encrypted with session key
  7. Server finished message: encrypted with session key

Other Handshake Variants

Diffie-Hellman: static/fixed Diffie-Hellman with certified keys. If the client does not have a certificate, they use an ephemeral Diffie-Hellman key.

Anonymous Diffie-Hellman: ephemeral Diffie-Hellman, but keys are not signed at all - only protects against passive eavesdropping.

Session Key Generation

Master secret ms\text{ms} generated using the pre-master secret and a pseudorandom function PRF\mathrm{PRF}:

ms=PRF(pms,“master secret”,NCNS) \text{ms} = \mathrm{PRF}(\text{pms}, \text{\textquotedblleft master secret\textquotedblright}, N_C \| N_S)

The pms\text{pms} to ms\text{ms} conversion is required to ensure the ms\text{ms} is in the right format as pms\text{pms} may vary depending on the key transfer algorithm.

To generate the key material (the amount depends on cipher suite):

k=PRF(ms,“key expansion”,NCNS) k = \mathrm{PRF}(\text{ms}, \text{\textquotedblleft key expansion\textquotedblright}, N_C \| N_S)

Independent session keys are partitioned from kk in each direction; a write key and a read key are used on each side.

Depending on cipher suite, key material may include encryption key, MAC key and IV.

The PRF\mathrm{PRF} is built from a HMAC specified by the TLS standard - SHA-2 in TLS 1.2 and a combination of MD5 and SHA-1 in TLS 1.0/1.1.

e.g. for TLS 1.2:

A(i)={nonce,i=0HMAC(key,A(i1)),otherwise A(i) = \begin{cases} \text{nonce}, & i = 0 \\ \mathrm{HMAC}(\text{key}, A(i - 1)), & \text{otherwise} \end{cases}
PRF(key,label,nonce)=HMAC(key,A(1)labelnonce)HMAC(key,A(2)labelnonce) \begin{aligned} \mathrm{PRF}(\text{key}, \text{label}, \text{nonce}) = & \mathrm{HMAC}(\text{key}, A(1) \| \text{label} \| \text{nonce}) \| \\ & \mathrm{HMAC}(\text{key}, A(2) \| \text{label} \| \text{nonce}) \| \\ & \vdots \end{aligned}

TLS Alert Protocol

Alert messages of varying degrees of severity:

If alert messages are handled improperly, users may be vulnerable to truncation attacks.

Attacks

Backwards Compatibility

Insecure versions of TLS are depreciated slowly:

TLS 1.2 is secure as long as a good cipher suite is used:

TLS 1.2 supported by 99.5% of websites, TLS 1.3 (released 2018) ~50% as of August 2021. See SSL Pulse for up-to-date statistics.

BEAST (Browser Exploit Against SSL/TLS)

Exploits non-standardized IV use in CBC mode encryption: IVs are chained from previous ciphertexts; attack could recover plaintext byte-by-byte.

Theoretical attack found in 2002 but required the full block to be guessed. In 2011 researchers found a method where they could have all but one byte in the block to be known, requiring only that byte to be guessed.

TLS 1.1 requires random IVs, and most browsers added mitigation strategies by putting only one byte of data in the first block (and padding the rest with random data) and the remaining bytes into the second block, forcing a randomized IV.

CRIME (Compression Ratio Info-leak Made Easy) and BREACH (Browser Reconnaissance and Exfiltration via Adaptive Compression of Hypertext)

Side channel attacks based on compression: different inputs result in different amounts of compression.

CRIME is based on compression in the TLS level, BREACH on compression at the HTTP level.

CRIME: attacker has ability to control part of request. If request gets smaller, the attacker-controlled content is probably matches part of source content (e.g. cookies).

TLS 1.3 does not allow compression. Disabling compression at a HTTP level results in a large performance hit.

POODLE (Padding Oracle On Downgraded Legacy Encryption)

A padding oracle enables an attacker to know if a message in a ciphertext was correctly padded.

Encryption in CBC mode can provide a padding oracle due to its error propagation properties: servers (after decrypt all blocks and validating the padding) may sometimes return an ‘invalid padding’ error.

Main mitigation is to have a uniform error response so that attacker cannot distinguish between padding and MAC errors.

Theoretical in 2002, practical in 2014 with POODLE, which forced a downgrade into SSL 3.0.

Heartbleed

Implementation error in OpenSSL found in 2014: improper input validation due to missing bounds check in heartbeat messages allowed memory leakage.

Heartbeats allow clients/servers to send a few bytes of data that the partner should echo back: OpenSSL did not validate that the length field matched actual length of the heartbeat, so the allocated memory could include freed data that contained sensitive data (e.g usernames/passwords, private keys).

Other Attacks

TLS 1.3

Drafted 2014, adopted as RFC 8446 in August 2018.

TLS 1.3 did a large spring cleaning, removing:

TLS 1.3 also added:

Handshake:

  1. Client hello:
    • TLS version, supported cipher suites
    • Key share:
      • Guesses selected cipher suite (s), sends key share (s)
      • If guess was wrong, server sends retry hello request
  2. Server hello:
    • Selected TLS version, cipher suite
    • Key share
      • Everything after this in the handshake can be encrypted
    • Server certificate (and optionally the certificates up the chain)
    • Hash of handshake messages signed with server certificate
  3. Client handshake finished
    • Hash of handshake messages signed with session key

0-RTT Overview

Even faster handshakes using pre-shared key (resumption master secret) obtained for the purpose of 0-RTT after a previous (and recent) connection.

TLS 1.3 1-RTT (with ephemeral Diffie-Hellman key exchange):

TLS 1.2 1-RTT session resumption:

TLS 1.3 0-RTT:

Limitations:

15. IPsec and VPN

IP security: framework for ensuring secure communications over IP networks; similar security services as TLS, but running at a lower level of the protocol stack.

VPNs: extending a private network across a public network.

IP Layer Security

TLS runs at the transport layer; IPsec runs at the network layer. Hence, it allows protection for any higher levels, including TCP and UDP.

Provides encryption, authentication and key management algorithms.

Standardized in 2005 with RFC 4301-4305; commonly used to provide VPNs.

Security services:

Architectures

Gateway-to-Gateway Architecture:

Host-to-Gateway Architecture:

Host-to-Host Architecture:

Protocols

Encapsulating security payload (ESP): provides confidentiality, authentication, integrity and reply protection.

Authentication header (AH) (depreciated): authentication, integrity and reply protection, but NOT confidentiality.

Internet key exchange (IKE): negotiation, creation and management of session keys in security associations (SAs).

IPsec Connection Setup

With the IKEv2 protocol (RFC 7296, 2014):

Security Associations (SA)

Runs after connection setup allows keys to be established.

SAs contain information needed to support an IPsec connection.

It may include:

SAs tells the endpoint how it should process inbound IPsec packets and/or generate outbound packets.

SAs are unidirectional: there is one SA for each direction.

Cryptographic Suites

Cryptographic suites in IPsec are:

Modes of Operation

ESH and AH can run in two different modes:

Transport Mode ESP

ESP components:

----------------------------------------------------------
| IP header | ESP header | Data | ESP trailer | ESP Auth |
-------------------------|--------------------|-----------
                         |     encrypted      |
            |         authenticated           |

Outbound packet processing:

Tunnel Mode ESP
--------------------------------------------------------------------------
| New IP header | ESP header | IP header | Data | ESP trailer | ESP Auth |
--------------------------------------------------------------|-----------
                             |           encrypted            |
                |                authenticated                |

Outbound packet processing:

Security

Virtual Private Networks

Secure channel over insecure connection.

Types:

Internet VPN: Branch Office Interconnect

Enterprise | Firewall | Internet | Firewall | Branch |
                    <---- VPN ----->

Extranet VPN: Supplier Network

Enterprise | Firewall | Internet | Firewall | Supplier Clients |
                    <---------- VPN --------->

Remote Access

ISPs can provide VPN services across the un-trusted internet.

16. Email Security

Email Security Requirements

SMTP (Single Message Transfer Protocol, RFC 5321) used to transmit email.

Message user agent (MUA) connects client to a mail system, using POP/IMAP to retrieve mail from message store (MS) and SMTP to send mail to a message submission agent (MSA).

The message handling system (MHS) transfers messages from the MSA to the MS via one or more message transfer agents (MTAs).

 Message Transfer    ...     Message Transfer
   Agent (MTA) 1   -------->   Agent (MTA) n
        ^                            |
        |                            | (Local SMTP)
        |                            v
Message Submission             Mail Delivery
    Agent (MSA)                 Agent (MDA)
        ^                            |
        |      Message Handling      |
        |        System (MHS)        |
- - - - - - - - - - - - - - - - - - - - - - - - - - -
        |                            | (Local SMTP)
        |                            v
        |                         Message
        |                       Store (MS)
        |                            |
        |                            | (IMAP/POP)
        |                            v
   Message User                Message User
    Agent (MUA)                 Agent (MUA)

Email content should be confidential and/or authenticated. The email service should also have a high level of availability.

Spam:

DomainKeys Identified Mail (DKIM)

Domain-to-domain security.

Standard which provides email authentication. RFC 6376.

Sending mail domain signs outgoing emails with its RSA signatures, verified by receiving domain.

Public key of sending domain stored in a DNS record.

Widely used to prevent email spoofing, spam, phishing.

The email contains:

STARTTLS

Extension of SMTP/POP (RFC 2595) and IMAP (RFC 3207) to run over TLS.

Link-by-link security; not end-to-end. However, use of TLS means forwards secrecy may availlable, although this doesn’t help if an attacker controls on of the links.

Link-to-link security allows metadata information (e.g. email destination) to be protected since most nodes provide transmit email for many users (ala VPN), making it hard to determine where a specific email is going from observing network traffic.

Opportunistic use of TLS; use if possible, continue if not available. This makes it vulnerable to STRIPTLS attacks where an attacker interrupts TLS negotiations, making it fail and fall back to plaintext.

End-to-End Security

Client-to-client security.

Pretty Good Privacy (PGP)

Email authentication and encryption for message contents.

Hybrid encryption:

Optional authentication:

Then packaging: content encoded with radix-64 so that binary strings can be sent.

Web of Trust:

Usability:

Criticisms:

Secure/Multipurpose Internet Mail Extension (S/MIME)

Has similar features to PGP, providing authentication, integrity, non-repudiation and confidentiality of the message body, but it cannot interoperate with PGP.

It includes the sender’s public key in each message, keys being X.509 certificates issued by CAs. It is supported by most popular mail clients.

Authentication:

Confidentiality:

The use of symmetric cryptography makes the process more efficient. By using a new ‘session key’ each time (one-time-mechanism), the encryption approach can be strengthened.

17. Malware and Cyber Attacks

Methods

Many different methods to gain access to a target computer:

Social Engineering

Persuading an authorized user to disclose sensitive information:

Spear phishing:

Hacking/Cracking

Password discovery: default passwords.

Password cracking tools also readily available for many systems (e.g. zip files, Windows password files).

Password attacks:

Denial of Service Attacks

Makes network services unavailable to users by overloading servers.

Financial incentive (DOS for hire services) and/or for extortion (stop attack when ransom paid).

No magic solution: use a properly-configured firewall to filter out illegitimate requests, and add more servers.

e.g. TCP SYN-ACK flood:

Rootkits

Collection of programs used to mask intrusion and obtain admin access.

After gaining user-level access to a target system, attacker can install rootkits through known vulnerabilities, password cracking etc.

They may collect user IDs and passwords from other machines on the network. e.g.

Once installed they may:

Blended Threats

Combination of attacks using different vulnerabilities:

Zero Day Attacks

Taking advantages of software vulnerabilities before the manufacturer can release a patch/fix.

Blaster worm (Windows 2000):

Nachi worm:

Time available to install updates shrinks over time and may be negative in some cases.

Attack Methods

Buffer Overflow

Exploits inadequate buffer boundary checking.

It often involves overwriting return addresses on the stack, making the machine run attacker-controlled code. However, it could also leak memory contents to the attacker.

Heartbleed was an example of the latter:

COSC362 Exam Notes

CIA: Confidentiality, Integrity, Availability

Maths

Groups:

Finding Generators:

Field F\mathbb{F}: set with two operations:

Chinese Remainder Theorem:

Euler function:

Fermat Primality Test:

Miller-Rabin test:

Returns probable prime for composite numbers with a maximum probability of 25%.

Discrete logarithm problem:

Classical Encryption

Confidentiality: reading message requires key.

Authentication: creating message requires key.

Attack classes:

Kerckhoff’s Principle: the only thing the attacker doesn’t know is the key.

Systems:

Modern Encryption

Hash Functions/MACs

Properties:

Birthday paradox:

Merkle-Damgård Construction:

Standards:

MACs:

HMAC:

Encryption and MAC:

Block Cipher

Key sizes and equivalents for symmetric algorithms (block ciphers), factoring modulus (e.g. RSA’s nn), discrete logarithm key (exponent) and group (pp), elliptic curve, hashes: https://www.keylength.com/en/4/

Product cipher: chain simple functions together, each using its own key.

Iterated cipher: product cipher but each round uses the same function using a key derived from a master key (using key schedule).

Substitution-Permutation Network (SPN):

Feistel Cipher:

Shannon:

DES:

AES:

Block Modes of Operation

ECB (Electronic Code Book):

CBC (Cipher Block Chaining)

CTR (Counter Mode):

Authentication/Integrity

Tag TT of message MM is unforgeable - impossible to produce T=MAC(M,K)T = \mathrm{MAC}(M, K) without KK.

CBC-MAC:

CMAC (Cipher-Based MAC):

Authenticated Encryption

Data fits into one of two buckets:

This is called AEAD - Authenticated Encryption with Associated Data.

CCM (Counter with CBC-MAC): If hh collision resistant, whole hash function is collision resistan

GCM (Galois Counter Mode):

RNGs

Seed obtained from true RNG; used in PRNG/deterministic random bit generator (DRBG).

DRBGs should have:

CTR_DRBG:

Dual_EC_DRBG:

Synchronous Stream Ciphers:

Public Key Cryptography

One-way function:

RSA:

Diffie-Hellman:

Authenticated Diffie-Hellman:

Static Diffie Hellman: aa and gag^a are the long-term private/public keys

Elgamal Cryptosystem:

Digital Signatures

Unforgeability: infeasible to generate a valid signature for any message without key.

Provides non-repudiation.

RSA signatures:

DSA signatures:

Public Key Infrastructure

Trusted certification authority (CA) (CA public key required by clients) issues/signs and revokes certificates.

Certificates (e.g. X.509 v3) contain:

Usually signed with RSA since RSA verification is faster than ECDSA.

Revocation: each CA has list of revoked certificates.

Key Management

Key management phases:

Mutual vs unilateral authentication:

Pre-Shared Keys:

With symmetric keys:

With asymmetric keys:

TLS

MAC:

Encryption:

Authenticated-Encryption:

Protocols:

DH Handshake:

RSA: client generates PMS and encrypts with server’s public key. No forwards secrecy.

Anonymous DH: against passive eavesdropping.

Attacks:

IPSec

Services:

Architectures:

Protocols:

Modes of operation: ESH/AH operate in:

Email

Actors and systems:

Link security:

End-to-end security:

TODO 17. Malware and Cyber Attacks