I5020 Computer Security
Session 3 Hash Function, Asymmetric Encryption and Signature
Sébastien Combéfis Fall 2019
Session 3 Hash Function, Asymmetric Encryption and Signature - - PowerPoint PPT Presentation
I5020 Computer Security Session 3 Hash Function, Asymmetric Encryption and Signature Sbastien Combfis Fall 2019 This work is licensed under a Creative Commons Attribution NonCommercial NoDerivatives 4.0 International License.
Sébastien Combéfis Fall 2019
This work is licensed under a Creative Commons Attribution – NonCommercial – NoDerivatives 4.0 International License.
Iterated hash functions, SHA-1 and CBC-MAC
Comparing shared key with public/private key pairs RSA, Rabin and ElGamal cryptosystems
Signature schemes and certificate
3
Construction of a short fingerprint of data (message digest)
The data x is a binary string of any length
Storing x and h(x) at different places The fingerprint h(x) must be stored in a secure place
5
Often used for message authentication code (MAC)
Alice and Bob know the hash function hK Sending the pair (x, y) with y = hK(x) on an insecure channel Computing y = hK(x) to check that x and y has not changed
No need to securely store the fingerprint that can be transmitted
6
1 X set of possible messages 2 Y finite set of possible message digests/authentication tags 3 K finite set of possible keys
(keyspace)
4 ∀K ∈ K : ∃(hK : X → Y) ∈ H
We assume that |X| > |Y|, or even |X| ≥ 2|Y|
7
It means that y is a message digest/authentication tag for x
Preimage Given h(·) and y, find x such that h(x) = y
((x, y) valid)
Second preimage Given h(·) and x, find x′ such that x′ = x et h(x′) = h(x)
((x ′, h(x)) valid)
Collision Given h(·), find x, x′ such that x′ = x and h(x′) = h(x)
8
Even if we already have several computed hashes h(x1), h(x2)...
h : Zn × Zn → Zn : (x, y) → ax + by mod n (a, b ∈ Zn and n ≥ 2)
Let h(x1, y1) = z1 and h(x2, y2) = z2 Let r, s ∈ Zn, we have that: h(rx1 + sx2 mod n, ry1 + sy2 mod n) = rh(x1, y1) + sh(x2, y2) mod n = rz1 + sz2 mod n
9
Compared to compression function for which X is finite
1 Preprocessing for x with |x| ≥ m + t + 1, we construct:
y = y1y2...yr, with |y| ≡ 0 (mod t) and |yi| = t (1 ≤ i ≤ r)
2 Processing with IV , public bistring of length m:
z0 ← IV z1 ← c(z0y1) ... zr ← c(zr−1yr)
3 Optional output transformation h(x) = g(zr)
with public function g : {0, 1}m → {0, 1}ℓ
10
IV = 101 (m = 3), y = 111001 and t = 2 c : {0, 1}5 → {0, 1}3 : x → (x1 ⊕ x3, x2 ⊕ x4, x3 ⊕ x5) g : {0, 1}3 → {0, 1}3 : x → x
1 Preprocessing y = 111001 2 Processing
z0 ← 101 z1 ← c(10111) = 010 z2 ← c(01010) = 000 z3 ← c(00001) = 001
3 Optional output transformation h(001) = 001 11
y = xpad(x)
Avoiding collision and finding x = x′ with y = y ′ Note that it results in |y| = rt ≥ |x|
12
As long as the compression function is good
x = x1x2...xk with |x1| = ... = |xk−1| = t − 1 |xk| = t − 1 − d
(where 0 ≤ d ≤ t − 2)
h will be collision resistant if c also resists to collisions
13
Algorithm 1: Merkle-Damgård Construction Function MD(x) n ← |x| k ← ⌈n/(t − 1)⌉ d ← k(t − 1) − n for i ← 1 to k − 1 do yi ← xi yk ← xk0d yk+1 ← the binary representation of d g1 ← c(0m+1y1) for i ← 1 to k do gi+1 ← c(gi1yi+1) return gk+1
14
160-bit message digest, operations on 32-bit words
Padding function fills with 0 to reach 64 bits
Algorithm 2: SHA-1 Padding Function Function SHA-1-PAD(x) d ← (447 − |x|) mod 512 ℓ ← the binary representation of |x| (where |ℓ| = 64) y ← x10dℓ return y
15
y = M1M2...Mn
ft(B, C, D) = (B ∧ C) ∨ ((¬B) ∧ D) if 0 ≤ t ≤ 19 B ⊕ C ⊕ D if 20 ≤ t ≤ 39 (B ∧ C) ∨ (B ∧ D) ∨ (C ∧ D) if 40 ≤ t ≤ 59 B ⊕ C ⊕ D if 60 ≤ t ≤ 79
Ki = 5A827999 if 0 ≤ t ≤ 19 6ED9EBA1 if 20 ≤ t ≤ 39 8F1BBCDC if 40 ≤ t ≤ 59 CA62C1D6 if 60 ≤ t ≤ 79
16
Algorithm 3: SHA-1 Function SHA-1(x) y ← SHA-1-PAD(x)
(Mi a 512-bits block)
Given y = M1M2...Mn H ← [67452301, EFCDAB89, 98BADCFE, 10325476, C3D2E1F0] for i ← 1 to n do Given Mi = W0W1...W15
(Wi a 32-bit word)
for t ← 16 to 79 do Wt ← ROTL1(Wt−3 ⊕ Wt−8 ⊕ Wt−14 ⊕ Wt−16) (A, B, C, D, E) ← (H0, H1, H2, H3, H4) for t ← 0 to 79 do temp ← ROTL5(A) + ft(B, C, D) + E + Wt + Kt (E, D, C, B, A) ← (D, C, ROTL30(B), A, temp) (H0, H1, H2, H3, H4) ← (H0 + A, H1 + B, H2 + C, H3 + D, H4 + E) return H0H1H2H3H4
17
Cannot be included anywhere to avoid attacks
Given a message x and the corresponding MAC hK(x) Given a bitstring x′ with length t and the message xx′ The computed tag is hK(xx′) = c(hK(x)x′) Length extension attack allows attacker to find hK(xx′)...
19
Families X, Y, K, G and Y, Z, L, H parametrised by keys
M = K × L and G ◦ H = {g ◦ h : g ∈ G, h ∈ H} where (g ◦ h)(K,L)(x) = hL(gK(x))
Y, Z, L, H is secure as a MAC, given fixed (unknown) key X, Y, K, G is collision resistant, given fixed (unknown) key
20
Algorithm proposed in a FIPS standard in March, 2002
Using a 512-bit key denoted K, and 512-bit constants: ipad = 3636...36 and opad = 5C5C...5C
HMACK(x) = SHA-1((K ⊕ opad)SHA-1((K ⊕ ipad)x))
21
With a fixed (public) initialisation vector
yi = eK(yi−1 ⊕ xi)
Algorithm 4: CBC-MAC Function CBC-MAC(x, K) Given x = x1...xn IV ← 00...0 y0 ← IV for i ← 1 to n do yi ← eK(yi−1 ⊕ xi) return yn
22
Provide secrecy and data integrity at the same time
MAC-and-encrypt: transmit (eK2(x), hK1(x)) MAC-then-encrypt: transmit y = eK2(xhK1(x)) encrypt-then-MAC: transmit (y, hK1(y)) with y = eK2(x)
Claimed to be secure if its components are secure Avoid unnecessary decryption if message has been modified
23
The key defines the encryption eK and decryption dK functions
Also, eK and dK are typically very close
Very difficult if they live far away or do not know each other
25
Public key eK to encrypt a plaintext Private key dK to decrypt a ciphertext
Only Bob can decrypt a plaintext encrypted with eK
Diffie-Hellman, RSA and ElGamal (and their variants)
26
Testing all possible messages x until obtaining y = eK(x)
The eK function must be easily computable Computing the inverse function should be hard
(one-way)
Should be invertible given a secret information
(trapdoor)
f (x) = xb mod n supposed to be (if n product of primes)
27
Also, we define φ(n) = (p − 1)(q − 1)
P = C = Zn K = {(n, p, q, a, b) | ab ≡ 1 (mod φ(n))} e(n,p,q,a,b)(x) = xb mod n d(n,p,q,a,b)(y) = y a mod n
28
Choosing p = 101, q = 113, that is, n = 11413, φ(n) = 11200 Choosing b = 3533, so a ≡ b−1 ≡ 6597 (mod 11200) Public key (11413, 3533) and private key (101, 113, 6597)
Message: x = 9726 Encryption: y = 97263533 mod 11413 = 5761 Decryption: x = 57616597 mod 11413 = 9726
29
Impossible for an opponent to decrypt a ciphertext
Can compute φ(n) and then obtain a ≡ b−1 (mod φ(n))
It is important that n is large enough to make it difficult
Time complexity of x c mod n in O(ℓk2) (with k-bit x and ℓ-bit c)
30
Each speaker must generate their own key pair
In particular because of the pseudo-random number generator
Algorithm 5: RSA Parameters Generation Function Gen-RSA-Params() Generate two large prime numbers p, q such that p = q n ← pq φ(n) ← (p − 1)(q − 1) Choose a random b (1 < b < φ(n)) s.t. gcd(b, φ(n)) = 1 a ← b−1 mod φ(n) return public key (n, b) and private key (p, q, a)
31
Provided that the modulus n = pq cannot be factored
P = C = Z∗
n
K = {(n, p, q) | n = pq, p, q primes and p, q ≡ 3 (mod 4)} e(n,p,q)(x) = x2 mod n d(n,p,q)(y) = √y mod n
32
Decryption cannot be done in an unambiguous fashion There are four square roots of y modulo n
x2 ≡ y (mod n)
Solving the two congruences z2 ≡ y (mod p) and z2 ≡ y (mod q)
33
Encryption: eK(x) = x2 mod 77 Decryption: dK(y) = √y mod 77
Ciphertext: y = 23 Square roots of 23 modulo 7 and 11: 23(7+1)/4 ≡ 22 ≡ 4 (mod 7) and 23(11+1)/4 ≡ 13 (mod 11) and so ±10, ±32 (mod 77) Four possible plaintext: x = 10, 32, 45 and 67
34
Suitable and fast enough for “long” messages
Suitable for very short messages because slow
1 Alice chooses L and computes y = eL(x) 2 Alice computes z = eKBob(L) and then transmits (y, z) 3 Bob computes L = dKBob(z) 4 Bob computes x = dL(y) 35
Given a multiplicative group (G, ·) Given an element α ∈ G having order n and a β ∈ α = {αi | 0 ≤ i ≤ n − 1}
(cyclic subgroup of G)
Find the unique integer a, with 0 ≤ a ≤ n − 1 such that αa = β
(will be denoted a = logα β)
But inverse operation of exponentiation efficient
37
p, ·) difficult
Moreover, we take a primitive element α ∈ Z∗
p
P = Z∗
p et C = Z∗ p × Z∗ p
K = {(p, α, a, β) | β ≡ αa (mod p)} e(p,α,a,β)(x, k) = (αk mod p, xβk mod p)
(k ∈ Zp−1 secret)
d(p,α,a,β)(y1, y2) = y2(y a
1 )−1 mod p
And secret random number k ∈ Zp−1 chosen at encryption
38
β is found by solving β = 2765 mod 2579 = 949
Plaintext: x = 1299 and secret value k = 853 Ciphertext: (2853 mod 2579, 1299 · 949853 mod 2579) = (435, 2396) Plaintext: x = 2396 · (435765)−1 mod 2579 = 1299
39
Provided that the discrete logarithm problem is infeasible
Let a, b ∈ R constants such that 4a3 + 27b2 = 0 Set E of solutions (x, y) ∈ R × R of the equation y 2 = x3 + ax + b together with special point O
(point at infinity)
40
Replacing all the operations over R by operations in Zp
Let a, b ∈ Zp constants such that 4a3 + 27b2 ≡ 0 (mod p) Set E of solutions (x, y) ∈ Zp × Zp of the equation y 2 = x3 + ax + b together with special point O
(point at infinity)
41
Adding the signature to the message, not “writing on top of it”
How is it possible to compare a signature with the “original” one
For example, authorisation for an action (withdraw 100 euros)
43
Verification for (x, y) if y valid signature for x or not
P finite set of possible messages A finite set of possible signatures K finite set of possible keys
(keyspace)
∀K ∈ K : ∃(sigK : P → A) ∈ S,
(signing algorithm)
(verK : P × A → {true, false}) ∈ V :
(verification algorithm)
∀x ∈ P, y ∈ A : verK(x, y) =
si y = sigK(x) false si y = sigK(x)
44
To be used “upside down” to have RSA signature scheme
Given n = pq with p, q primes and P = A = Zn K = {(n, p, q, a, b) | ab ≡ 1 (mod φ(n))} sig(n,p,q,a,b)(x) = xa mod n ver(n,p,q,a,b)(x, y) = true ⇐ ⇒ x ≡ y b (mod n)
Both should be polynomial-time functions
45
Choosing a random signature y and computes x = eK(y)
Key-only attack: Alice’s verK Known message attack: List of signed messages (xi, yi) Chosen message attack: Alice’s sig to sign list of messages
Testing all possible signatures y ∈ A
46
1 Message x to be sent is hashed z = h(x) 2 Signature is computed on the hash: y = sigK(z) 3 Alice send the pair (x, y) to Bob 4 Bob computes z = h(x) and checks the signature verK(z, y)
Same conditions than in the previous applications
47
Require some kind of Public Key Infrastructure (PKI)
Signs the public keys of all people in the network Verification key verCA known “by magic” by everyone
Name, email, address, list of public keys
48
Recommended method is called the “sign-then-encrypt”
1 Alice signs y = sigA(x) then encrypts z = eB(x, y) 2 The ciphertext z is transmitted to Bob 3 Bob decrypts (x, y) = dB(z) then verifies verA(x, y)
Decrypts (x, y) = dB(z), send z′ = eC(x, y)
49
1 Alice encrypts z = eB(x) then signs y = sigA(z) 2 The pair (z, y) is transmitted to Bob 3 Bob verifies verA(z, y) then decrypts x = dB(z)
Intercepts (z, y) and replace by (x, sigE(z))
50
Before encrypting, concatenate ID for the sender Before signing, concatenate ID for the receiver
y = sigA(x, ID(B)), z = eB(x, y, ID(A)) and sends z
z = eB(x, ID(A)), y = sigA(z, ID(B)) and sends (z, y, ID(A))
51
Douglas R. Stinson, & Maura B. Paterson, Cryptography: Theory and Practice (Fourth Edition), CRC Press, 2017.
(ISBN: 978-1-138-19701-5)
Daniel, Cryptographic Hash Functions Explained: A Beginner?s Guide, August 14, 2018.
https://komodoplatform.com/cryptographic-hash-function
Tim Fisher, Cryptographic Hash Function: Use a cryptographic hash function to verify the authenticity of data, August 11, 2019. https://www.lifewire.com/cryptographic-hash-function-2625832 ConsenSys, Are you really using SHA-3 or old code?, January 12, 2016.
https://medium.com/@ConsenSys/are-you-really-using-sha-3-or-old-code-c5df31ad2b0
Erik Ringsmuth, Encrypt-then-MAC: How I learned AES encryption does not tamper-proof data, June 15, 2014.
https://medium.com/@ErikRingsmuth/encrypt-then-mac-fc5db94794a4
Short Tech Stories, How does RSA work?, June 23, 2017. https://hackernoon.com/how-does-rsa-work-f44918df914b Josh Lake, What is RSA encryption and how does it work?, December 10, 2018.
https://www.comparitech.com/blog/information-security/rsa-encryption
Nick Sullivan, A (relatively easy to understand) primer on elliptic curve cryptography, October 24, 2013.
https://arstechnica.com/information-technology/2013/10/a-relatively-easy-to-understand-primer-on-elliptic-curve-cryptography
Credits Blockchain, Digital signature: Introduction, June 20, 2018.
https://medium.com/@credits/digital-signature-26897c00cf74
52
Icons from https://icons8.com/icons. stu_spivack, March 3, 2010, https://www.flickr.com/photos/stuart_spivack/4425612269. Avinash Kumar, August 30, 2009, https://www.flickr.com/photos/avifotos/3889188265. Dan Backman, June 19, 2010, https://www.flickr.com/photos/dbackmansfo/4716003831. Ian Foss, March 18, 2006, https://www.flickr.com/photos/badboy69/2093177318. Sebastien Wiertz, April 29, 2010, https://www.flickr.com/photos/wiertz/4563720850.
53