Cryptography Flashcards
(148 cards)
1
Q
Encryption
A
- Cryptographic Technique #1
- Only the intended recipient can understand the message
2
Q
Steganography
A
- Cryptographic Techinque #2
- Only the intended recipient is aware that there is a message
3
Q
Chaffing and Winnowing
A
- Cryptographic Techinque #3
- Only the intended recipient can find the real message
4
Q
Confidentiality
A
- Cryptographic Technique #4
- Keeping information a secret from those not authorised to have it
5
Q
Data Integrity
A
- Cryptographic Technique #5
- Ensuring information has not been altered by those not authorised to do so
6
Q
Authentication
A
- Cryptographic Technique #6
- Confirmation of the identity of an entity
7
Q
Message Authentication
A
- Cryptographic Technique #7
- Confirmation of the source of information
8
Q
Signature
A
- Cryptographic Techinque #8
- A way of binding information to an entity
9
Q
Certification
A
- Cryptographic Technique #9
- Endorsement of information by a trusted entity
10
Q
Non-repudiation
A
- Cryptographic Technique #10
- Preventing an entity from denying previous actions or commitments
11
Q
Revocation
A
- Cryptographic Technique #11
- Retracting certification or authorisation
12
Q
Cryptosytem
A
A five-tuple (P, C,K, Σ,D), where:
- P is a finite set of possible plaintexts
- C is a finite set of possible ciphertexts
- K is a finite set of possible keys called the keyspace
- For each key k ∈ K there is an encryption rule, ek ∈ Σ, ek : P →C and a corresponding decryption rule dk ∈ D, dk : C→P such that dk(ek(x)) = x for all plaintext elements x ∈ P
- For a cryptosystem, we need:
- to be able to efficiently compute the encryption and the decryption functions
- that an unauthorised party should not be able to determine the key or the plaintext
13
Q
Substitution cypher
A
- P = C = Z26
- K is the set of all permutations of the 26 symbols 0, 1, . . . , 25
- For each permutation π ∈ K, eπ(x) = π(x) and dπ(y) = π-1(y), where π-1 is the inverse permutation
14
Q
Shift cypher
A
- Shift the alphabet by a specific offset, where the offset is the key 0 ≤ k ≤ 25
- For example, a shift of 5 would be:
- Plain: ABCDEFGHIJKLMNOPQRSTUVWXYZ
- Cipher: FGHIJKLMNOPQRSTUVWXYZABCDE
15
Q
Vigenere cypher
A
- P = C = (Z26)m where m ∈ Z, m > 0
- K is the set of keys k = (k1, k2, . . . ,km)
- For each key k we have ek(x1, x2, . . . ,xm) = (x1+k1, x2+k2, . . . ,xm+km) and dk(y1, y2, . . . , ym) = (y1−k1, y2−k2, . . . , ym−km)
- Sidenote: (operations are modular 26, that is, in Z26).
16
Q
Permutation cypher
A
- P = C = (Z26)m, m ∈ Z, m > 0
- K is the set of permutations of {1, . . . ,m}
- For each permutation π (the key) we have eπ(x1,…,xm) = (xπ(1),…, xπ(m)), and dπ(y1, . .. , ym) = (yπ-1(1),…,yπ-1(m)), where π-1 is the inverse permutation
17
Q
Kirchoff’s considerata
A
- The system should be, if not theoretically unbreakable, unbreakable in practice
- Compromise of the system details should not inconvenience the correspondents
- The key should be rememberable without notes and easily changed
- The cryptogram should be transmissible by telegraphy
- The encryption apparatus should be portable and operable by a single person
- The system should be easy, requiring neither the knowledge of a long list of rules nor mental strain
18
Q
Ciphertext only attack
A
- Given: y1 = ek(x1), . . . , yi = ek(xi)
- Deduce:
- k,
- an algorithm that outputs xi+1 given yi+1 = ek(xi+1) or
- x1, . . . , xi
19
Q
Known plaintext attack
A
- Given: x1, y1 = ek(x1), . . . , x1, y1 = ek(xi)
- Deduce:
- k or
- an algorithm that outputs xi+1 given yi+1 = ek(xi+1)
20
Q
Chosen plaintext attack
A
- Given: x1, y1 = ek(x1), . . . , xi, yi = ek(xi) where the attacker has chosen x1, . . . , xi
- Deduce:
- k or
- an algorithm that outputs xi+1 given yi+1 = ek(xi+1)
- Adaptive chosen plaintext attack: a special case of this attack where the attacker can modify his choice of plaintexts based on the results of earlier pairs
21
Q
Computational security
A
- A cryptosystem is computationally secure if the best algorithm for breaking it requires a computational effort which is greater than the computational resources of the assumed attacker
- A measure of the computational effort is required to break the cryptosystem
- However, it’s hard to prove a system is computationally secure
against all attacks
22
Q
Unconditional security
A
- A cryptosystem is said to be unconditionally secure if an
attacker with infinite computational resources cannot
break the system
23
Q
Vernam Cipher
A
- P = C = Z2
- K = Z2 and we generate a keystream k1k2k3 . . . with ki ∈ K.
- We encrypt plaintext x = x1x2x3 . . . with the keystream thus
eki(xi) = (xi + ki) mod 2 (the exclusive-or of xi and ki this is also written xi ⊕ ki) and decrypt dki(yi) = (yi + ki) mod2
24
Q
One-time pad
A
- The Vernam cipher is referred to as a one-time pad if
the key stream k1k2k3 . . . is randomly chosen and never used again
25
Proof that one-time pad is unconditionally secure
Suppose (P, C,K, Σ, D) is a cryptosystem where |K| = |C| = |P|. Then the cryptosystem provides perfect secrecy if and only if every key is used with equal probability 1/|K|, and for every x ∈ P and every
y ∈ C, there is a unique key such that ek(x) = y.
26
Confusion and Diffusion
- According to Claude Shannon, an ideal cipher should
satisfy:
* Confusion: The relationship between the key and the ciphertext is as complex as possible
* Diffusion: The structure of the plaintext is dissipated over the entire ciphertext
27
More precise variant of confusion and diffusion
* Confusion: Flipping any fixed set of key bits causes the ith bit of ciphertext to change with probability 0.5.
* Diffusion: Flipping any fixed set of plaintext bits causes the ith bit of ciphertext to change with probability 0.5
28
Basic components
* Substitution to provide confusion
* Permutation to provide diffusion
* Other components might include: x-or, linear transformations, arithmetic operations, modular multiplication
29
Product cipher
A product cipher combines two or more components with the intention of producing a cipher that is more secure than the basic parts of which it is made
30
Substitution permutation network (SPN)
_Cryptosystem_
Let l,m,Nr be positive integers
* πS : {0, 1}l → {0, 1}l is an S-box
* πP : {1, . . . , lm} → {1, . . . , lm} is a permutation
* P = C = {0, 1}lm
* K ⊆ ({0, 1}lm)Nr+1 is the set of all key schedules that can be derived from an initial key k
* For a key schedule (k1, . . . , kNr+1) we encrypt using an iterated cipher composed of substitution, permutation and x-or operations
31
SPN encryption algorithm
- Inputs: plaintext block, πS, πP , (k1, . . . , kNr+1)
- Output: ciphertext block
- state = plaintext block
- for round r = 1 to Nr − 1 do
* x-or: state = state ⊕ kr
* substitutions: apply πS to m strings of l bits of state
* permutation: apply πP to lm bits of state
- end do
- x-or: state = state ⊕ kNr
- substitutions: apply πS to m strings of l bits of state
- ciphertext block = state ⊕ kNr+1
32
Example of SPN
Lecture 3, pp 32-56
33
Computational security against exhaustive key search
- A fixed key size defines an upper bound on the security of the cipher
- If the key k is a bitstring of length lk then there are 2lk keys
- Given a small number of plaintext-ciphertext pairs the attack has complexity of 2lk−1 operations
34
Computational security against exhaustive data analysis
- Text dictionary attack: For block size m, if an attacker has collected 2m plaintext-ciphertext pairs then they have a complete dictionary of the cipher
- Matching ciphertext attack: If you have collected 2m/2 blocks you expect to find matching ciphertext blocks within them
35
Differential cryptanalysis setup
- Chosen plaintext attack
- Plaintexts chosen in pairs x, x∗ such that x ⊕ x∗ = x′, a particular plaintext difference
- x′ is chosen such that, with high probability during encryption, a particular state difference will occur at the input to the last round of S-boxes
- Objective: Find targeted key bits
- Basic idea: Exploit a situation whereby a particular difference
between ciphertexts y′ occurs, given a particular
difference between plaintexts x′, with a very much
higher probability than is ideal
36
Differential cryptanalysis method
For each tuple (x, x∗, y, y∗):
1. For each candidate round key kNr+1 partially decrypt both ciphertexts producing state and state ∗
2. Find the state difference state′ = state ⊕ state∗
3. If state′ = expected difference then increment the counter for this candidate key
The candidate key with the highest count should have the correct values for the targeted key bits
37
Finding a differential trial
- Idea: Find the expected difference between statevand state∗ just before the final S-boxes
- Steps:
1. For each S-box consider all possible differentials: (a′, b′) = (input difference, output difference)
2. 2 Find the propagation ratio, the probability b′ occurs given a′
3. Combine high probability differentials to make a differential trail
38
Example of differential cryptanalysis
Lecture 4, pp. 34-50
39
Linear cryptanalysis
- Objective: Find targeted key bits.
- Known plaintext attack: attacker has a set of plaintext-ciphertext pairs encrypted with the same key k
- Using probabilistic analysis we find biased linear approximations for the S-boxes. We construct a linear approximation, with a large bias, of the SPN (excepting the final round) in terms of plaintext bits and state bits
- For each candidate key partially decrypt each ciphertext and see if the linear approximation holds for state, incrementing a counter for the key if it does
- The candidate key with largest bias (from |input pairs|/2) should contain the targeted key bits
40
Cost of differential cryptanalysis
If p is the propagation ratio of the differential trail then the attack is often successful if the number of tuples (x, x∗, y, y∗) is approximately c/p where c is some small constant
41
Cost of linear cryptanalysis
If p is the “bias” of the linear approximation then the attack is often successful if the number of plaintext-ciphertext pairs is approximately c/(p2) where c is some small constant
42
Feistel cipher
- A Feistel cipher is an iterated cipher in which the state on round i is divided into two halves of equal length: Li and Ri
- The round function g has the form g(Li−1, Ri−1, ki) = (Li, Ri) and for some function f, is computed:
* Li = Ri−1
* Ri = Li−1 ⊕ f(Ri−1, ki)
43
Feistel encryption algorithm
- Inputs: plaintext block (length m), (k1, . . . , kNr)
- Output: ciphertext block
Initialise state:
L0 = left m/2 bits of plaintext block
R0 = right m/2 bits of plaintext block
for round i = 1 to Nr do
* Call the round function:
* Li = Ri−1
* Ri = Li−1 ⊕ f(Ri−1, ki)
end do
Notice the output order of the state pair: ciphertext block = RNrLNr
44
DES the Feistel cipher
DES (Data Encryption Standard) is a 16 round Feistel cipher where:
- m = 64, Li and Ri are bitstrings of length 32
- k is 56 bits long, from this sixteen 48 bit round keys are produced consisting of a selection of bits of k, permuted
- There is a fixed initial permutation L0R0 = IP(x) before the first round
- The inverse permutation IP−1(R16L16) is applied after the last round
- f : {0, 1}32 × {0, 1}48 → {0, 1}32
- f consists of a substitution (S-box) followed by a fixed permutation.
45
DES f function
- Expand Ri−1 to 48 bits and x-or with ki: state = E(Ri−1) ⊕ ki
- Apply substitutions to state: map 6-bit substrings to 4-bit substrings
- Permute state: state = P(state)
46
Cost of attacks
47
Modes of operation
1. Electronic codebook mode (ECB)
2. Cipher block chaining mode (CBC)
3. Output feedback mode (OFB)
4. Cipher feedback mode (CFB)
48
Electronic codebook mode
49
Cipher block chaining mode
50
Output feedback mode
51
Cipher feedback mode
52
DES is not a group
- For a key k in the DES keyspace DES encryption defines a permutation of 64 bits
- There are 256 possible keys and hence up to 256 different permutations
- The set of 256 permutations defined by the 256 DES keys is not closed under function composition
53
Security of Double DES
- Attack model: known plaintext
- Naive exhaustive key search would then take 2112 operations
- However, since it's a product cipher, DES's structure can be attacked
54
Double DES
55
Meet in the middle attack
56
Triple DES
- The standard for DES, replacing Double DES in 1999
- AES will replace 3DES but they currently coexist as FIPS approved algorithms
57
Three Key Triple DES
- Naive exhaustive search: 2168 operations
- Meet in the middle attack: 2112 operations
- Differential and linear cryptanalysis become more
difficult
58
Two Key Triple DES
- Naive exhaustive search: 2112 operations
- Differential and linear cryptanalysis become more difficult
59
Criteria and evaluation of AES
Necessary criteria:
* Block length: 128 bit
* Support key lengths of 128, 192 and 256 bits
* Should be available worldwide on a royalty free basis
Evaluated according to:
* Security
* Cost
* Algorithm and implementation characteristics
60
Rijndael Cipher
- Iterated cipher with structure similar to an SPN
- Number of round depends on key size:
* Key size = 128, Nr = 10
* Key size = 192, Nr = 12
* Key size = 256, Nr = 14
61
Attacks on AES
- There are known side-channel attacks on AES, exploiting timing properties of its implementation on known
- In July 2009, researchers described di↵erent related key
attacks on AES. These are (variously):
1. Feasible for reduced-round versions of 256-bit AES
(245 complexity for a 10-round version)
2. Theoretically better than brute force but not
feasible (2119 complexity) for the full 14-round
version
- In 2011, a theoretical key-recovery attack on full AES
was published which is better than brute force by a
factor of about 4.
62
Hash function
- Informally, a hash function h is a function which has the
following properties:
1. Compression: h maps an input x to an output y = h(x) of fixed length
2. Computability: given h and x, h(x) is “easy” to compute
63
Unkeyed hash function definition
- An unkeyed hash function is a function h :X !Y where:
* X is the set of possible messages
* Y is a finite set of possible message digests
- A pair (x, y), x ∈ X, y ∈ Y is valid if h(x) = y
64
Keyed hash function family definition
- A family of keyed hash functions is a four-tuple (X,Y,K,H) where:
* X is the set of possible messages
* Y is a finite set of possible authentication tags
* For each k ∈ K, the finite set of possible keys, there is a hash function hk ∈ H such that hk: X → Y
- A pair (x, y), x ∈ X, y ∈ Y is valid under key k if hk(x) = y
65
Message digest code
- Message digest code = unkeyed hash function
- Applications:
* Integrity checking: Alice sends Bob the pair (x, h(x)) ∈ X x Y. Bob receives (x', y) x Y, and checks that h(x') = y
* Passwords: Alice chooses a password x 2 X for Bob.com, which stores h(x) 2 Y wth her username. At login, her attempt is hashed to y 2 Y and sent to Bob.com, who compare it to h(x)
* Message authenticity: Alice combines her message
m with a secret key k (shared with Bob), and
sends him (m, h(k,m)).
* Digital signature: Alice hashes her message, and
signs the hash with her private key
66
Hash function security problem
If a hash function is to be considered secure three problems are required to be difficult to solve:
* Preimage problem
* Second preimage problem
* Collision problem
67
Preimage problem
- Inputs: h: X → Y, y ∈ Y
- Find: x ∈ X such that h(x) = y
68
Example of preimage attack
- Message digests are also used to obscure passwords.
- There is a natural first preimage attack in this case:
1. Alice sets a new password p, the password isn’t stored on the system, the hash h(p) is stored.
2. If Alice wants to log in then her password is requested, the password she gives is hashed and compared with the stored value.
3. If Oscar had h(p) but not p then he has the input for a first preimage attack.
4. If Oscar can find some p' for which h(p') = h(p) then he can use p' as a password for Alice’s account and log in to the system as Alice.
69
Second preimage problem
- Inputs: h: X → Y, x ∈ X
- Find: x' ∈ X such that h(x') = h(x)
70
Example of second preimage attack
Consider a digital signature scheme where the signatory
signs the hash h(x) rather than x itself.
1. Alice prepares x, some agreement she has with Oscar, she calculates h(x) and signs it, sending x and the signed hash to Oscar.
2. Oscar has x and h(x).
3. If h is not second preimage resistant Oscar may be able to find x' such that h(x) = h(x').
4. He can now claim that Alice signed x'.
71
Collision problem
- Inputs: h: X → Y
- Find: x, x' ∈ X such that x ≠ x' and h(x) = h(x')
72
Example of collision problem
Now assume that Oscar is preparing the documents for
Alice to sign.
1. Oscar produces x and x', h(x) = h(x'). x is the agreement Alice expects and x' is some other agreement more favourable to Oscar.
2. Alice receives x, calculates h(x) and sends the signed hash to Oscar.
3. Oscar can now claim that Alice signed x'.
73
Naive attack
- h produces hashes of length n bits.
- Let y = h(x) for some message x.
- For random bitstrings x0 of bounded bitlength, calculate h(x') and check if h(x') = y
74
Collision upper bound
* Over K elements, there are K2−K / 2 distinct, unordered pairs
* If h: X → Y is uniformly distributed, the probability that any one pair is a collision is 1 / |Y|
* So a collision can be expected if K ≥ √(2|Y|) + 1 — i.e. (K − 1)2 ≥ 2|Y|, so (K2−K / 2|Y|) ≥ 1
* Let h: X → Y produce hashes y of length n bits and hence |Y| = 2n
* A collision is expected to be found by brute force in around 2n/2 operations
75
Hash function resistance
A n-bit unkeyed hash function is considered to be:
* Preimage resistant if producing a preimage or a second preimage requires approximately 2n operations
* Collision Resistant if producing a collision requires approximately 2n/2 operations
76
The Merkle-Damgard construction
- Theorem: Any collision resistant compression function can be
extended to a collision resistant hash function which
takes arbitrary length inputs
- This can be done efficiently by the Merkle-Damgard construction
77
Merkle-Damgard construction process
78
Merkle-Damgard construction algorithm
- Construct y = y1 || y2 || . . . || yr+1
- z0 = 0n for i = 1 to r + 1 do
* zi = compress(zi−1 || yi)
* end do
- return h(x) = zr+1
79
MD5 summary of status
- MD is also known as Message Digest
- April 1992: Described by Rivest in RFC 1321
- Mid-1990s: Collisions found in compression function
- 2004: Wang et al. produced a collision for MD5
- 2008: Chosen prefix collision attacks.
- 2012: Flame Malware attack uses a chosen prefix attack on MD5 to forge a Microsoft Terminal Server licensing certificate.and authenticate itself
80
SHA summary of status
- SHA (referred to as SHA-0), is considered insecure
- 2005: Wang et al. showed collisions can be found in SHA-1 in less than 263 steps. Collision published by Google/CWI Amsterdam — Feb 23 2017.
- Members of the SHA-2 family (SHA-256, SHA-384, SHA-512) are more complex than SHA-1. They are currently considered secure
-
81
SHA-3
- The hash function Keccak was chosen by NIST as the basis for a new standard - SHA-3 (2014).
- SHA-3 does not replace SHA-2 (which is still considered secure) but has some operational advantages
- It is based on an iterated sponge construction (not Merkle-Damgard): at each iteration, a block of the message is XORed into the current state, and then substitution and permutation operations are performed
82
Properties of a secure system
- Compression and computability
- In addition, given a description of the hash family and a
secret key k, computational resistance is required
83
Computation resistance
- Without prior knowledge of k, given zero or more pairs (xi, hk(xi)) it is computationally infeasible to compute (xi, hk(x)) for a new input x ≠ xi
84
MAC forgery
- If a MAC is not computation-resistant it is subject to MAC forgery
- Computation-resistance ⇒ key non-recovery
- key non-recovery ⇏ computation-resistance
85
Severity of a MAC forgery attack
- The attacker is able to produce a new valid pair (x, hk(x)):
* Existential Forgery for some message x.
* Selective Forgery for a predetermined message x.
* Universal Forgery For any message x.
for his choice (or partial choice) of x but has no control over the value of x
86
MAC key recovery by exhaustive search
- Input: (x, hk(x)), key of length l
- Output: k
- Compute n-bit MAC using all possible keys
* This requires 2l MAC operations.
* In an ideal MAC, 2l−n keys will remain as candidates
* Further valid pairs can test the remaining candidates
- A MAC key should not be recoverable in fewer
than 2l operations
87
Cost of guessing a MAC
- For an n-bit MAC we expect to guess a correct MAC
with probability 2−n.
- But we cannot check guesses without either the key or
an (adaptive) chosen-text scenario.
- We should not be able to produce MAC forgeries with probability higher than max(2−l, 2−n)
88
Suffix and postfix key
- The MAC key could be used as both a suffix and a postfix: hk(x) = h(k∥p∥x∥k), with padding to ensure that there is at least two
iterations in the computation of h
89
HMAC
- Known as a keyed-hash message authentication code
- Algorithm:
* Inputs: key k, MDC h
* Define ipad and opad each of length 512 bits:
* ipad = 3636. . . 36
* opad = 5C5C .. . 5C
* HMACk(x) = h(k ⊕ opad" || h((k ⊕ ipad) || x)"
- Keyed-Hash Message Authentication Code, FIPS standard 198, 2002
- h can be any approved unkeyed hash.
90
CBC-MAC
91
CBC-MAC algorithm
92
Public-key cryptosystem
- A public-key cryptosystem is a cryptosystem (P,C,K,E,D) where:
* For every k ∈ K, ek is the inverse of dk
* For every k ∈ K and for every x ∈ P or y ∈ C, ek(x) and dk(y) are easy to compute
* It is computationally infeasible (for almost all k ∈ K) to derive dk from ek
* For every k ∈ K it is feasible to compute ek and dk from k
93
One-way function
- A one-way function is a function f : X → Y such that for all x ∈ X it is easy to compute f(x) but for (almost) all y ∈ Y it is computationally infeasible to find an x such that f(x) = y
94
Trapped door one-way function
- A trap-door one-way function is a one-way function f : X → Y such that given some additional trap-door information it becomes feasible, for all y ∈ Y to find x ∈ X such that y = f(x).
95
Euler-phi function
- The number of integers less than n and relatively prime to n is denoted φ(n). This function is called the Euler phi-function
- Properties:
* If p is prime then φ(p) = p − 1
* The Euler phi-function is multiplicative, that is, if gcd(m, n) = 1 then φ(n · m) = φ(n) · φ(m)
* If n = p1e1, p2e2,..., pkek, k is the prime factorisation of n then:
96
Arithmetic modulo n
- The set of residues modulo n denoted Zn is a commutative ring
- b ∈ **Z**n has a multiplicative inverse if and only if gcd(n, b) = 1
- The number of positive integers b \< n relatively prime to n is φ(n)
- The set of residues modulo n which are relatively prime to n is denoted **Z**∗n
- This is an Abelian group under multiplication, b ∈ **Z**∗n have a multiplicative inverse b−1 ∈ **Z**∗n
97
Euclidean algorithm
98
Euclidean algorithm pseudocode
- Inputs: a, b ∈ N, a ≥ b
- Output: gcd(a, b)
- r0 = a, r1 = b, m = 1
- while rm ≠ 0 do
* qm = ⌊rm−1 / rm ⌋
* rm+1 = rm−1 − qmrm
* m = m + 1
- end do
- m = m − 1
- return rm
99
Extended Euclidean algorithm
- In the Euclidean algorithm there was: rm−2 = qm−1rm−1 + rm and gcd(r0, r1) = rm
- Unwind the steps writing each in terms of the inputs a and b:
* r2 = r0 − q1r1 = a − q1b
* r3=r1 − q2r2=b − q2(a − q1b)=b−q2a+q1q2b = −q2a+(1+q1q2)b
* ...
* ri−2 = si−2a + ti−2b
* ri−1 = si−1a + ti−1b
* ri = ri−2 − qi−1ri−1 = si−2a + ti−2b − qi−1(si−1a + ti−1b)
* = (si−2 − qi−1si−1)a + (ti−2 − qi−1ti−1)b = sia + tib
* ...
* rm = sma + tmb
* Hence sm, tm ∈ **Z** such that gcd(a,b) = sma + tmb can now be found
100
Idea of extended Euclidean algorithm
101
Extended Euclidean algorithm pseudocode
- Inputs: a, b ∈ **N**, a ≥ b
- Output: gcd(a, b) and s, t ∈ **Z** such that
* sa + tb = gcd(a, b)
* sold = 1, s = 0, told = 0, t = 1
* q = ⌊a/b⌋, r = a − qb
* while r \> 0 do
* tnew = told − qt, told = t, t = tnew
* snew = sold − qs, sold = s, s = snew
* a = b, b = r, q = ⌊a/b⌋, r = a − qb
* end do
* return (b, s, t)
102
Chinese remainder theorem
- Used to solve certain congruent systems
- Let m1,m2, ...,mr be pairwise relatively prime positive integers. Suppose a1, a2, . . . , ar ∈ **Z** and consider:
* x ≡ a1 (mod m1)
* x ≡ a2 (mod m2)
* ...
* x ≡ ar (mod mr)
- The Chinese remainder theorem states that this system
has a unique solution modulo M = m1, m2···, mr
103
Definition of the Chinese remainder theorem
104
Example of Chinese remainder theorem
105
Fermat's little theorem
- Suppose p is prime and b ∈ Z∗n then bp ≡ b (mod p)
- Euler generalises this theorem by stating: For all b ∈ Z∗n, bφ(n) ≡ 1 (mod n)
106
RSA cryptosystem
- RSA = Rivest, Shamir and Adleman
- Cryptosystem:
* Let n = pq, p, q prime
* P = C = **Z**n
* K = {(n, p, q, a, b) | ba ≡ 1 (mod φ(n))}
* For k = (n, p, q, a, b) ∈ K we have ek(x) = xb (mod n) and
dk(y) = ya (mod n) for x, y ∈ **Z**n
* (n, b) is called the public key and (p, q, a) is called the private key
107
Encryption and decryption are inverses
_Context_
- Alice sent a message x ∈ P encrypted with Bob’s public
key (n, b): ek(x) ≡ xb(mod n)
- Bob decrypts with his private key (p, q, a): dk(ek(x)) ≡ (xb)a (mod n) ≡ xba (mod n)
- Prove that xba ≡ x(mod n)
108
Proof that decryption is feasible
- Show that xba ≡ x (mod n)
- ba is defined by ba ≡ 1 (modφ(n))
- This can be rewritten as: ba = kφ(n) + 1 for some k ∈ **N** = k(p − 1)(q − 1) + 1
- If gcd(x, p) = 1 we have xp−1 ≡1 (mod p) by Fermat’s little theorem
- Raise both sides to the power k(q − 1), s.t. xk(p−1)(q−1) ≡ 1 (mod p), and multiplying both sides by x to get, for gcd(x, p) = 1, that: xk(p−1)(q−1) + 1 ≡ x (mod p)
* But if gcd(x, p) = p then this holds as both sides are
congruent to 0 (mod p)
* Hence for all x ∈ P
* xk(p−1)(q−1)+1 ≡ x (mod p) ⇒ xba ≡ x (mod p)
- By argument,we have xba ≡ x (mod q)
- Now, p and q are relatively prime and a system of congruences exists:
* xba ≡ x (mod p)
* xba ≡ x (mod q)
- Therefore, by Chinese remainder theorem and recalling that n = pq: xba ≡ x (mod n)
109
RSA parameter generation algorithm
* Generate two large primes p, q such that p ̸= q
* Calculate n = pq, φ(n) = (p − 1)(q − 1)
* Choose a random 1 \< b \< φ(n) such that gcd(b, φ(n)) = 1
* Calculate a = b−1 (mod φ(n))
* Set the public key to (n, b) and the private key to (p, q, a)
110
Generation of large primes
- Basic method: generate a large random number, test this for primality
- The large cost involved in the parameter generation is the calculation of a = b−1 (mod φ(n))
- However, the extended Euclidean algorithm can be used since it calculates in time O((log k)2)
111
Modular exponentiation of RSA
- Can be used in generation of large primes
- To calculate xb (mod n) can be:
* Very slow: b − 1 modular multiplications
* Faster: use the square and multiply algorithm
* Faster again: use Chinese remainder theorem
112
Integer factorisation problem
- The integer factorisation problem (FACTORING) states: given a positive integer n find its prime factorisation n = pe11 pe22··· pekk, where pi are distinct primes and ei ≥ 1
113
Strong prime
- p' is strong if:
* p − 1 has a large prime factor (denoted r)
* p + 1 has a large prime factor
* r − 1 has a large prime factor
- However, strong primes offer no protection against the Elliptic Curve Method
114
Elliptic curve method (ECM)
- A generalisation of Pollard’s p − 1 method
- Depends on an integer “close to” p having only
“small” prime factors.
- This is more likely than the situation required by Pollard’s p − 1 method
- Pollard’s method depends on a relation which holds in the group Z∗p
- ECM depends on a relation which involves groups defined on elliptic curves modulo p
- Tends to find smaller factors first
115
Asymptotic runtimes of modern factoring algorithms
116
Difference of two squares
- An idea proposed due to Fermat
- To factor n look for x, y ∈ Z such that x2 − y2 = n
- If such x, y can be found then d = gcd(x − y, n) is a non trivial factor of n
117
Factoring with congruent squares
- A modification of the idea of difference of two squares
- Congruent squares = to factor n look for x, y ∈ Z such that x2 ≡ y2 (mod n)
```
- Proposition: If we also have x ̸≡ ±y (mod n) then gcd(x − y, n)
and gcd(x + y, n) are non trivial factors of n
```
- Proof:
* x2 ≡ y2 (mod n) ⇒ x2 − y2 ≡ 0 (mod n) ⇒ n|(x2 − y2) ⇒ n|(x − y)(x + y)
* x ̸≡ ±y (mod n) ⇒ x − y ̸≡ 0 (mod n) and x + y ̸≡ 0 (mod n) ⇒ n ̸|(x − y), n ̸|(x + y)
118
Given a, factor n
- Imagine Oscar has Bob’s public key (n, b) and his decryption exponent a. Oscar can factor n.
- By definition ba ≡ 1 (mod φ(n)) and so ba − 1 = kφ(n) for some k ∈ N
- Hence, for all x ∈ Z∗n: xba−1 ≡ 1 (mod n)
- Take the square root: y1 = √(xba−1) = x(ba−1)/2 and then use
y21 ≡ 1 (mod n) to try to recover a factor from n
- If y1 ≡ 1 (mod n) then we take the square root of y1: y2 = √y1 = x(ba−1)/4
- It's already known that y22 ≡ y1 ≡ 1 (mod n) so it's again possible to attempt to factor n
- Continue the process until either:
* A non trivial factor of n is found
* (ba − 1)/2s is not divisible by 2
- Factor n with probability 1/2
-
119
Example of given a, factor n
120
Family of algorithms
- Proposition: If there is also a x ̸≡ ±y (mod n) then gcd(x − y, n) and gcd(x + y, n) are non trivial factors of n
- Proof:
* x2 ≡ y2 (mod n) ⇒ x2 − y2 ≡ 0 (mod n) ⇒ n|(x2 − y2) ⇒ n|(x − y)(x + y)
* x ̸≡ ±y (mod n) ⇒ x − y ̸≡ 0 (mod n) and x + y ̸≡ 0 (mod n) ⇒ n ̸|(x − y), n ̸|(x + y)
121
B-Smooth
- x ∈ N is said to be B-smooth if all prime factors of x are ≤ B
- Use a factor base, a set B of the primes below some bound B
- Find a collection of z ∈ Z such that each z2 (mod n) is B-smooth
- Find a subset of the z2 (mod n) such that each prime in the factor base is used an even number of times
- This will give a congruence of the type x2 ≡ y2 (mod n) as required.
122
Framework for algorithms in a family
* Select the factor base of primes p ≤ B.
* Collect relations between elements of the factor base producing squares
* z2j ≡ Π pivij (mod n), where p is the factor base
* Write each relation as a vector vj = (v1j, . . . , vij, . . .)
* Find dependencies: reduce vj modulo 2 and use
linear algebra to find a dependency modulo 2
* The dependency will give a subset S of relations whose vectors added together produce a vector with even coordinates, hence:
* Πzj2 ≡ Π pivij ≡ y2 (mod n)
123
Dixon's random squares
- In Dixon’s random squares algorithm, simply select z at random
- Although, it can be useful to look at integers of the form j + |√kn| which tend to be small when squared and reduced mod n
124
Basic RSA is not semantically secure
- Basic RSA is not semantically secure because the encryption function is deterministic
- The attacker can distinguish ciphertexts
- Example:
* Imagine all messages are either “Buy” or “Sell”. Call
these x1 and x2.
* Attacker sees a new message c being sent to Bob Ltd. with public RSA key (n, b)
* Attacker computes c1 = xb1 (mod n) and compares this with c.
* If they match then he knows I sent the message “Buy”.
125
Multiplicative properties of RSA
- Let x1, x2 be two plaintext messages. Notice that:
* ek(x1x2) ≡ (x1x2)b ≡ x1bx2b ≡ ek(x1)ek(x2) (mod n)
- The encryption of x = x1x2 is y = ek(x1)ek(x2)
- RSA is malleable: known plaintext can be altered without decryption
- This can be used to run an adaptive chosen ciphertext attack
126
Common modulus
- Trusted authority produces RSA key pairs (n, b), (n, a) for all users of a network
- Alice, Bob and Oscar are all legitimate users of the network and so receive keys
- The TA fixes n = pq and provides each user i with with unique bi and ai
- Alice encrypts x using Bob’s public key (n, b1) and sends y on the insecure network
127
Small private exponent
- A small private exponent can be used to increase the speed of decryption
- Wiener presented an attack that computes a from the
public key if 3a \< n1/4 and q \< p \< 2q
128
Small public exponent
- To reduce encryption time a small public exponent b is often used
- However, very small exponents, such as b = 3, are not secure
129
Example of vulnerability of a small public exponent
- Alice wants to broadcast a message x:
* y1 ≡ x3 (mod n1)
* y2 ≡ x3 (mod n2)
* y3 ≡ x3 (mod n3)
- Attacker can use the Chinese remainder theorem to
compute solution to:
* Y ≡ y1 (mod n1)
* Y ≡ y2 (mod n2)
* Y ≡ y3 (mod n3)
- Say the solution is Y (mod n1n2n3)
* But x3 \< n1n2n3 so there must be a Y = x3 and hence
x = Y1/3
130
Numerical example of vulnerability of a small public exponent
- Example: n1 = 319, n2 = 299, n3 = 323
- Let b = 3, broadcasting x = 7 leads to:
* y1 ≡ 73 ≡ 343 ≡ 24 (mod 319)
* y2 ≡ 73 ≡ 343 ≡ 44 (mod 299)
* y3 ≡ 73 ≡ 343 ≡ 20 (mod 323)
- The Chinese Remainder Theorem will give: M = 30808063
* 299 x 323 = 96577, 96577-1 ≡ 315 (mod 319)
* 319 x 323 = 103037, 103037-1 ≡ 38 (mod 299)
* 319 x 299 = 95381, 95381-1 ≡ 286 (mod 323)
- (24 x 96577 x 315 + 44 x 103037 x 38 + 20 x 95381 x 286) ≡ 343 (mod 30808063)
131
Relation between small public exponent and padding
- Ways to avoid the attack:
* Use larger RSA exponents
* Increase the amount of padding
* Make padding depend on the message e.g. hash the message and append this
* Spread random padding throughout message (some methods can still be attacked)
132
Optimal Asymmetric Encryption Padding
- There is a cryptographic primitive, that is, the “raw” or “basic” RSA
- In practice protocols built of many primitives to achieve secure communication are used, perhaps with data integrity build in
- The most important of these protocols is OAEP, a padding scheme due to Bellare and Rogaway
- OAEP is used in Public Key Cryptography Standards (PKCS) and hence most Internet protocols
- Assuming that the RSA problem of computing bth roots modulo n is computationally infeasible RSA-OAEP is semantically secure against adaptive chosen ciphertext attacks
133
Orders
- The order of a group is the number of elements in the
group
* If the order of a group is finite it is called a finite group
- Let G be a finite group. The order of an element g ∈ G is the smallest positive integer m such that gm = 1
134
Cyclic group
- Let G be a finite group of order m. G is said to be a cyclic group if there exists an element α ∈ G having order equal to m. α is called a generator of G.
- Z*p is a cyclic group
135
Primitive element modulo p
- An element α ∈ **Z***p with order p − 1 modulo p is called a primitive element modulo p
- It immediately follows that ↵ is a primitive element modulo p if and only if {αi | 0 ≤ i ≤ p − 2} = Z*p
136
Example of primitive element modulo p
- Let p = 7.
* We have φ(6) = φ(2 x 3) = φ(2) x φ(3) = 2 primitive elements modulo 7
- How to find?
* Lets see if 2 is a primitive element modulo 7:
* 20 (mod 7) = 1
* 21 (mod 7) = 2
* 22 (mod 7) = 4
* 23 (mod 7) = 1
* 2 has order 3
137
Second example of primitive element modulo p
- What about 3, with p = 7:
* 30 (mod 7) = 1
* 31 (mod 7) = 3
* 32 (mod 7) = 2
* 33 (mod 7) = 6
* 34 (mod 7) = 4
* 35 (mod 7) = 5
* And just to check: 36 (mod 7) = 1
- Since 3 is primitive we know that 3i is primitive if and only if gcd(i, 6) = 1
- Hence the primitive elements are 3 and 35 (mod 7) = 5
138
Stinson's proof of finding primitive elements
- Suppose that p \> 2 is prime and α ∈ Z*p. Then α is a primitive element modulo p if and only if, for all primes q|(p - 1):
* α(p-1)/q = 1 (mod p)
139
Discrete logarithm in Z*p
- Let p be prime and let α ∈ **Z***p be a primitive element modulo p
- If β ∈ **Z***p such that:
* αa ≡ β (mod p)
, then a is called the discrete logarithm of β and is denoted logαβ
140
DLog problem
- Given p prime, α a primitive element modulo p and β ∈ **Z***p find an element a, 0 ≤ a ≤ p − 2 such that αa ≡ β (mod p)
141
Diffie-Helmann key exchange
- Public parameters: p prime, and ↵, a primitive element
modulo p which has order p − 1.
1. Alice chooses 1 ≤ a ≤ p − 1 at random and computes A = αa (mod p) and sends A to Bob.
2. Bob chooses 1 ≤ b ≤ p − 1 at random and computes B = αb (mod p) and sends B to Alice.
3. Alice receives B and computes Ba = αab (mod p)
4. Bob received A and computes Ab = αab (mod p)
5. k = Ab = Ba = αab (mod p)
142
Computational Diffie-Hellman problem
- Also known as CDH
- Given p prime, α a primitive element modulo p and two elements β, γ ∈ Z*p find δ ∈ Z*p such that logαδ ≡ logαβ x logαγ (mod p)
- That is, given αa and αb, find αab
143
Generalised DLog problem
- Given a finite cyclic group G of order n, α a generator of G and β ∈ G find an element a, 0 ≤ a ≤ n − 1 such that αa = β
144
Exhaustive search
- Compute α, α2,α3, . . . until β = αa is found
- Compute a new term in the list by multiplying the previous term by α
- Only store the current element of the list
- Total time: O(n)
- Total space: O(1)
145
Shanks' algorithm
- It is a time-memory trade-off
- Let m = ⌈√n⌉
- If αa = β then we can write:
* β = αa = αmj+i for 0 ≤ j, i \< m
- It's now possible to write αmj+i = αmjαi, and hence β = αmjαi ⇒ βα−i = αmj
146
Pseudocode for Shanks' algorithm
1. m = ⌈√n⌉
2. Compute list L1: (0,α0), (1,αm), (2,α2m),...,(m − 1,α(m−1)m)
3. Sort list L1 of pairs (j, αmj) on the value of αmj
4. Compute list L2: (0,βα0), (1,βα−1), (2,βα−2), ...,(m−1,βα−(m−1))
5. Sort list L2 of pairs (i, βα−i) on the value of βα−i
6. Find (j, y) ∈ L1 and (i, y) ∈ L2
7. logαβ = (mj + i) (mod n)
147
The index calculus method
- Can not be used in all groups
- Faster than exhaustive search and Shanks
- Resembles a factoring algorithm such as Dixon’s random squares
- Under various “reasonable” assumptions the pre-computation phase has asymptotic running time: O(e(1+o(1))√(ln p ln ln p))
* And then to find a particular discrete logarithm: O(e(1/2+o(1))√(ln p ln ln p))
148
Pre-computation of index calculus method
1. Select the factor base of primes B = {p1, p2,..., pB}
2. Collect congruences modulo p of the form: αxj ≡ p1a1j, p2a2j, pBaBj (mod p) for 1 ≤ j ≤ C
* These can be written as relations among discrete logarithms of the factor base elements:
* xj ≡ a1j logαp1 +...+ aBjlogαpB (mod p − 1)
*