Lecture 8
Lecture 8
COMP2300/6300
Week 8
September, 2023
1 / 66
Example Slide [1.1]
2 / 66
Public-Key Cryptosystems
3 / 66
Basic Elgamal Cryptosystem
4 / 66
Basic Elgamal Cryptosystem [16.1.2]
5 / 66
Discrete Logarithm Problem [3.1]
Example group:
Let p be a prime
Let G be the group Z∗p = {1, 2, . . . , p − 1} under multiplication modulo
p
Its order is p − 1
Identity element is 1
If g is a generator and i ∈ Zp−1 = {0, 1, . . . , p − 2}, then g i (mod p) is
a unique element in {1, 2, . . . , p − 1}
And g 0 ≡ g p−1 ≡ 1 (mod p)
6 / 66
Basic Elgamal Cryptosystem – Setup [16.1.2]
7 / 66
Basic Elgamal Cryptosystem – Keys [16.1.2]
Alice:
Private key: xA ← Zp−1 = {0, 1, . . . , p − 2}
Public key: hA = g xA (mod p)
Bob:
Private key: xB ← Zp−1 = {0, 1, . . . , p − 2}
Public key: hB = g xB (mod p)
Note: Finding private key from public key amounts to solving DLP
8 / 66
Basic Elgamal Cryptosystem – Encryption [16.1.2]
9 / 66
Basic Elgamal Cryptosystem – Decryption [16.1.2]
10 / 66
Basic Elgamal Cryptosystem – Example [16.1.2]
p = 809, g = 3, m = 100
? g = Mod(3, p);
? znorder(g)
%1 = 808 # (proof that) g has order p-1
? xB = 68; # Bob’s private key
? hB = g^xB # Bob’s public key
%2 = Mod(65, 809)
? xA = 117; # Alice’s private key
? hA = g^xA # Alice’s public key
%3 = Mod(59, 809)
? c = m*(hB^xA) # Encryption
%4 = Mod(769, 809)
? c/(hA^xB) # Decryption
%5 = Mod(100, 809)
11 / 66
Basic Elgamal Cryptosystem – Security
Eve learns g xA xB
Every subsequent message (b/w Alice and Bob) can be decrypted by
Eve
Without knowing the secret key!
12 / 66
(Randomized) Elgamal Cryptosystem
13 / 66
Elgamal Cryptosystem [16.1.2]
Problem with Basic Elgamal: same value used for encryption every
time:
Alice multiplies message by hBxA = g xA xB
Need to change this for every encryption (randomization)
14 / 66
Elgamal Cryptosystem – Encryption [16.1.2]
15 / 66
Elgamal Cryptosystem – Decryption [16.1.2]
Note: Alice’s private and public key never used for encryption and
decryption (respectively)
16 / 66
Elgamal Cryptosystem – Example [16.1.2]
p = 809, g = 3, m = 100
? g = Mod(3, p);
? xB = 68; # Bob’s private key
? hB = g^xB # Bob’s public key
%2 = Mod(65, 809)
? k = 69; # Random integer
? c1 = g^k # Encryption
%3 = Mod(195, 809)
? c2 = m*(hB^k)
%4 = Mod(184, 809)
? c2/(c1^xB) # Decryption
%5 = Mod(100, 809)
17 / 66
Elgamal Cryptosystem – Security [16.1.2]
18 / 66
Elgamal Cryptosystem – Security [16.1.2]
19 / 66
Elgamal Cryptosystem – Security [16.1.2]
Give h = g x and c1 = g k to A
Receive z = g xk from A
Compute m0 ≡ c2 · z −1 (mod p)
Output m0
As long as A is correct, we can break Elgamal.
20 / 66
Elgamal Cryptosystem – Security [16.1.2]
21 / 66
Elgamal Cryptosystem – Security [16.1.2]
22 / 66
Elgamal Cryptosystem – Security [16.1.2]
Give c1 = g k to A
Receive k 0 from A
0
Compute m0 ≡ c2 · (hk )−1 (mod p)
Output m0
As long as A is correct, we can break Elgamal.
23 / 66
Elgamal Cryptosystem – Security [16.1.2]
24 / 66
DLP Attack Algorithms: Pollard’s Rho Algorithm
25 / 66
Elgamal Cryptosystem [16.1.2]
26 / 66
Floyd’s Cycle-Finding Algorithm [3.4]
Consider the DLP: h ≡ g x (mod p)
over Z∗p of order n
Let S = Z∗p
Let f be a random map from S
to itself
Consider for i ≥ 0
xi+1 = f (xi )
27 / 66
Finding Collisions [3.4]
xi = xj ,
28 / 66
Cycles [3.4]
x8
xi = xj , x5
x9
Track
30 / 66
Floyd’s Cycle-Finding Algorithm [3.4]
√
We find a collision after m = O( n)
But we only require constant memory
We only store current pair (xi , x2i )
31 / 66
Pollard’s Rho Algorithm [3.4]
32 / 66
Pollard’s Rho Algorithm [3.4]
for integers ai , bi
We keep track of the tuple: (xi , ai , bi )
We start with: (x0 , a0 , b0 ) = (1, 0, 0)
33 / 66
Pollard’s Rho Algorithm [3.4]
modulo p
34 / 66
Some More Group Theory I
Theorem 3
If g t = e for any t > 1, then n divides t
Proof.
Suppose n - t, then t = kn + r , for integers k, r with 0 < r < n. We get
e = g t = g kn+r = (g n )k · g r = e k · g r = g r ,
35 / 66
Some More Group Theory II
Theorem 4
If g a = g b for some integers a, b then a ≡ b (mod n)
Proof.
g a = g b ⇒ g a · (g b )−1 = e ⇒ g a · g −b = e ⇒ g a−b = e.
By Theorem 3, n | (a − b), which means
a − b ≡ 0 (mod n) ⇒ a ≡ b (mod n)
36 / 66
Pollard’s Rho Algorithm [3.4]
37 / 66
Pollard’s Rho Algorithm – Example [3.4]
38 / 66
Discrete Logarithm Attacks
√
Pollard’s Rho Algorithm takes O( 2l )
l is size of group of order n (approximately same size as q, largest
prime factor of p − 1)
Other more efficient algorithms exist, e.g., Index Calculus [Sma16,
Section 3.5]
However, all take time exponential in input
Elgamal cryptosystem over Z∗p requires large key size, e.g., 2048-bit p
Similar key sizes to RSA
Are there groups where DLP is harder? Hence requiring smaller keys
39 / 66
Elliptic Curve Cryptography
40 / 66
Elliptic Curve Over a Field
y 2 = x 3 + ax + b,
Example 6
An elliptic curve over the field Zp , where p is prime:
y 2 = x 3 + ax + b (mod p),
and a, b ∈ Zp .
41 / 66
Example: Elliptic Curve Modulo p
E : y 2 = x 3 + 2x + 1 (mod p)
22 = 13 + 2 · 1 + 1
32 = 33 + 2 · 3 + 1 (mod 5)
42 / 66
The Elliptic Curve Abelian Group
43 / 66
Adding Two Different Points
Addition: P + Q = R
Q 6= ±P.
Draw a line through P and Q
𝑄
The line intersects the curve at
a third point. 𝑃
R is the reflection of this point
about the x-axis.
𝑅
44 / 66
Doubling: Adding the Same Point Twice
Doubling: P + P = 2P = R
Draw the tangent line at P
The line intersects the curve at 𝑃
a second point
R is the reflection of this point
about the x-axis.
𝑅
45 / 66
Inverse and Identity
Point at infinity: ∞
Negatives:
If P = (x1 , y1 )
Then −P = (x1 , −y1 )
Verify that −P is on the
curve
𝑃 = 𝑥$ , 𝑦$
Draw a line through P and −P
The line intersects the curve at −𝑃 = 𝑥$ , −𝑦$
46 / 66
Addition with the Point at Infinity
Point at infinity: ∞
P +∞=P
Why?
Draw a line through P and ∞
The line intersects the curve at 𝑃
a third point: −P
−𝑃
The result is the reflection of
−P about the x-axis, i.e., P
47 / 66
Algebraic Formulae
48 / 66
Algebraic Formulae
49 / 66
Algebraic Formulae: Example
E : y 2 = x 3 + 2x + 1 (mod 5)
P1 = (1, 2), P2 = (3, 3), and P3 = P1 + P2 = (x3 , y3 ).
Then:
50 / 66
Scalar Multiplication
Definition 7
Given an integer n and a point P on the curve, the scalar multiplication is
P added to itself n times:
| + ·{z
nP = P · · + P}
n times
Note: 0P = ∞.
Definition 8
The order of the point P is the smallest positive integer k such that
kP = ∞.
Consider: E : y 2 = x 3 + 2x + 1 (mod 5)
E = ellinit([2, 1], 5): Initialize curve
ellcard(E): Number of elements
P = [1, 2]: Defining the point P = (1, 2)
ellorder(E,P): Order of point P
ellisoncurve: Checking if a point is on the curve
elladd: Adding two points
ellmul: Scalar multiplication
52 / 66
Elliptic Curve Cryptography (ECC)
53 / 66
Elliptic Curve Cryptography – Efficiency
54 / 66
Elliptic Curves – Review
y 2 = x 3 + ax + b (mod p),
and a, b ∈ Zp .
55 / 66
Computing dP
56 / 66
Elliptic Curve Elgamal – Setup
57 / 66
Elliptic Curve Elgamal – Keys
58 / 66
Elliptic Curve Elgamal – Encryption
59 / 66
Elliptic Curve Elgamal – Decryption
Bob decodes M to m
60 / 66
Elliptic Curve Elgamal – Toy Example
Consider: E : y 2 = x 3 + 2x + 1 (mod 5)
We have a = 2, b = 1, p = 5, P = (1, 2)
message M = (3, 2)
61 / 66
Elliptic Curve Elgamal – Toy Example
Encryption
? k = 6 # Random integer
? C1 = ellmul(E,P,k) # C1 = kP
% = [Mod(1, 5), Mod(3, 5)] # C1 = (1, 3)
? Q1 = ellmul(E, Q, k) # kQ
% = [Mod(0, 5), Mod(1, 5)] # kQ = (0, 1)
? C2 = elladd(E, M, Q1) # C2 = M + kQ
% = [Mod(1, 5), Mod(2, 5)] # C2 = (1, 2)
62 / 66
Elliptic Curve Elgamal – Toy Example
Decryption
63 / 66
Elliptic Curve Elgamal
64 / 66
References
65 / 66
[HMV06] Darrel Hankerson, Alfred J Menezes, and Scott Vanstone.
Guide to elliptic curve cryptography.
Springer Science & Business Media, 2006.
[Kob87] Neal Koblitz.
Elliptic curve cryptosystems.
Mathematics of computation, 48(177):203–209, 1987.
[Mil85] Victor S Miller.
Use of elliptic curves in cryptography.
In Conference on the theory and application of cryptographic
techniques, pages 417–426. Springer, 1985.
[Sma16] Nigel P Smart.
Cryptography made simple, volume 481.
Springer, 2016.
66 / 66