Chapter 4 - Public Key Cryptography, Key Exchange

Updated 4 Oct 2026

Hardness of RSA: Based on factorization factor (prime number)
Hardness of ECC: Based on discrete logarithm

Motivation for Public Key Algorithm

Problems with Secret Keys (Symmetric Key)

  • Key Management Issues:
    • Use lots of keys for nn users
    • Distributing so many keys securely is difficult
    • Secure storage for the keys
    • User having nn keys cannot memorize them all
  • Question: Can we have a system with significantly fewer keys?
    • Answer: Yes!

The 1976 Breakthrough

  • 1976 — Diffie and Hellman introduced Key pairs: ⟨Kprivate,Kpublic⟩\langle K_{private}, K_{public} \rangle

Key Management Complexity

Conventional (Symmetric) System

  • For conventional (symmetric) system, there must be a common key between any pair of users
  • Thus, a lot of keys must be generated and maintained
  • There must be n(n−1)2\frac{n(n-1)}{2} keys for n users (for possible communication channels)

Analogy: Think of it like a group chat where everyone needs a separate secret language with everyone else. In a group of 10 people, you'd need 45 different secret languages! That's 10×9÷2 = 45 pairs.

Additional keys that must be generated if 1 user is added: increases quadratically


Public Key Cryptography Solution

The Two-Key Idea

  • Idea: have 2 keys
    • One key is inverse of the other key
    • The two keys can be interchanged

D(KPRIV,E(KPUB,P))=D(KPUB,E(KPRIV,P))\boxed{D(K_{PRIV}, E(K_{PUB}, P)) = D(K_{PUB}, E(K_{PRIV}, P))}

  • Each user owns one private key and shares the corresponding public key with n-1 remaining users
  • Only 2n keys for n users
  • Reduce from O(n2)O(n^2) to O(n)O(n)

Analogy: Instead of needing a unique secret language with everyone, you now have one "encoding language" (private) and one "decoding language" (public). Everyone can use your public decoder to talk to you, but only you can encode messages with your private encoder.


Public-Key Cryptosystem

  • Bob's public key ring contains public keys from Joy, Mike, Ted, and Alice
  • Encryption process:
    • Plaintext input → Encryption algorithm (e.g., RSA) using Alice's public key
    • Transmitted ciphertext sent over network
    • Decryption algorithm (reverse of encryption algorithm) using Alice's private key
    • Plaintext output

Key Exchange

  • To share symmetric key/session key
    • Key kk is generated
    • Alice needs to share kk to Bob (using PKE)
      1. Enc_RSA(k, Bob’s Public Key) = CTk
      2. Dec_RSA(CTk, Bob's Private Key) = k

This is the secure way to share key!

Practical Data Encryption (Hybrid Encryption)

  • Key sizes (practical)
    • AES: 128 / 256 bits (symmetric key)
    • RSA: 2048 bits (1024 is deprecated)

Data Encryption (Alice → Bob)

  1. Key Generation
    • Alice generates a random symmetric key: kAES←SecureRandom()k_{AES} \leftarrow \text{SecureRandom}()
  2. Data Encryption (AES)
    • Alice encrypts the message ( M ) using AES: CTM=EncAES(kAES,M)CT_M = \text{Enc}_{AES}(k_{AES}, M)
  3. Key Encryption (RSA)
    • Alice encrypts the AES key using Bob’s public key: CTK=EncRSA(PKBob,kAES)CT_K = \text{Enc}_{RSA}(PK_{Bob}, k_{AES})
  4. Transmission
    • Alice sends: (CTK,CTM)(CT_K, CT_M)

Data Decryption (Bob)

  1. Key Decryption (RSA)
    • Bob recovers the AES key using his private key: kAES=DecRSA(SKBob,CTK)k_{AES} = \text{Dec}_{RSA}(SK_{Bob}, CT_K)
  2. Data Decryption (AES)
    • Bob decrypts the message: M=DecAES(kAES,CTM)M = \text{Dec}_{AES}(k_{AES}, CT_M)

But this way, Bob cannot verify really that the message come from Alice → Digital signature (Later!)


Key Insight (important)

  • AES encrypts the data
  • RSA encrypts the AES key
  • This is called Hybrid Encryption

RSA is slow → encrypt only the key
AES is fast → encrypt the actual data


Public Key Algorithm Requirements

Three Critical Requirements:

  1. Computational Ease: It must be computationally easy to encipher or decipher a message given the appropriate key
  2. Key Derivation Hardness: It must be computationally infeasible to derive KPRIVK_{PRIV} from KPUBK_{PUB}
  3. Chosen Plaintext Security: It must be computationally infeasible to determine KPRIVK_{PRIV} from a chosen plaintext

Mathematical Foundation

Public Key Cryptosystem Basis

Based on modular arithmetic:

  • Modular addition
  • Modular multiplication
  • Modular exponentiation

They are also based on the fact about prime numbers


Prime Numbers

Definition and Examples

  • An integer n>1n > 1 is called a prime number if its positive divisors are only 1 and n
  • Prime numbers are central to number theory

Prime numbers less than 200:

2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61,
67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131,
137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199

Modular Arithmetic

Basic Definition

For any integers, aa and nn:

  • a mod na \bmod n = remainder when aa is divided by nn
  • a=q⋅n+ra = q \cdot n + r where 0≤r<n0 \leq r < n

Congruence

Two integers aa and bb are said to be congruent modulo n, if:

  • (a mod n)=(b mod n)(a \bmod n) = (b \bmod n), or can be written as

a≡b(modn)\boxed{a \equiv b \pmod{n}}
Definition: a≡b(modn)a \equiv b \pmod{n} if and only if n∣(a−b)n \mid (a - b)

Using the definition of "divides", n∣(a−b)n \mid (a - b) can be translated to a−b=kna - b = kn for some integer kk.

Example: 100≡34(mod11)100 \equiv 34 \pmod{11}

  • อันนี้ก็จะคือ 100%11=1100 \% 11 = 1, 34%11=134\% 11 = 1

Properties

  • bb is called the residue of a mod na \bmod n
  • All integers can always write: a=qn+ba = qn + b
  • Usually have 0≤b≤n−10 \leq b \leq n-1

Example: −12 mod 7≡−5 mod 7≡2 mod 7≡9 mod 7-12 \bmod 7 \equiv -5 \bmod 7 \equiv 2 \bmod 7 \equiv 9 \bmod 7

Note: Mod of negative number, the result must be positive number.

  • e.g., −12 mod 7→(−2×7)+2-12 \bmod 7 \rightarrow (-2 \times 7) + 2, thus the result is 2
  • e.g., −5 mod 7→(−1×7)+2-5 \bmod 7 \rightarrow (-1 \times 7) + 2, thus the result is 2

Exercise - Modular Arithmetic

Calculate the following:

  • 3 mod 7=3 \bmod 7 = 3
  • 5 mod 7=5 \bmod 7 = 5
  • 5 mod 5=5 \bmod 5 = 0
  • −10 mod 7=-10 \bmod 7 = 4
  • 8 mod 5=8 \bmod 5 = 3
  • −8 mod 5=-8 \bmod 5 = 2
  • −7 mod 3=-7 \bmod 3 = 2
  • −5 mod 1=-5 \bmod 1 = 0

Title


End for Class 3


Modular Multiplication

Multiplicative Inverse

Multiplicative inverse of xx (written as x−1x^{-1})

  • Multiplication mod nn yields 1
  • e.g., inverse of 4 mod 7 is 2
    • since (4×2) mod 7=8 mod 7=1 mod 7(4 \times 2) \bmod 7 = 8 \bmod 7 = 1 \bmod 7

Important Properties

Some numbers have no inverse

  • e.g., 4 has no inverse under mod 8

Finding Inverse:

  • Use Extended Euclidian algorithm to find inverse
  • Given xx, nn, find yy such that xy=1 mod nxy = 1 \bmod n

Key Rule:

  • Only the numbers relatively prime to nn will have multiplicative inverse mod nn

Greatest Common Divisor (GCD, ห.ร.ม)

Definition

GCD of aa and bb is the greatest common value which divides both aa and bb. It is usually defined as gcd⁡(a,b)\gcd(a,b)

Example: gcd⁡(60,24)=12\gcd(60, 24) = 12

Relatively Prime

Two integers, aa and bb, are relatively prime if their only common divisor is 1
gcd⁡(a,b)=1\boxed{\gcd(a, b) = 1}


Useful Theorems

Important Number Theory Theorems

NOTE

Theorem 1: Zn∗Z_n^* is called group of elements that are coprime of n
Zn∗={a∣1<a<n and gcd⁡(a,n)=1}\boxed{Z_n^* = \{a \mid 1 < a < n \text{ and } \gcd(a,n) = 1\}}
Example: Z10∗={1,3,7,9}Z_{10}^* = \{1, 3, 7, 9\}

NOTE

Theorem 2: ϕ(n)\phi(n) is the size of Zn∗Z_n^* which is called Euler's totient function or Phi function
ϕ(n)=∣Zn∗∣\boxed{\phi(n) = |Z_n^*|}

Theorem 3: If pp is prime s.t. ∣Zp∗∣=p−1|Z_p^*| = p-1

Theorem 4: ∀a∈Zp∗\forall a \in Z_p^* s.t. ∀aϕ(p)=1 mod p\forall a^{\phi(p)} = 1 \bmod p

Theorem 5: Let pp and qq are prime and p≠qp \neq q;

ϕ(pq)=ϕ(p)⋅ϕ(q)\boxed{\phi(pq) = \phi(p) \cdot \phi(q)}

Theorem 6: Extended Euclidean algorithm says if there is gcd⁡(a,b)=1\gcd(a, b) = 1;

∃m,n∈Z; s.t. ma−nb=1 where a>b\boxed{\exists m, n \in Z; \text{ s.t. } ma - nb = 1 \text{ where } a > b}


RSA (Rivest, Shamir, Adleman)

Overview

  • It's a public key encryption algorithm
  • Support both encryption and digital signature
    • Digital signature (only public key encryption can only be used to compute one.)
    • Symmetric key ให้แบบนี้กับคุณไม่ได้นะ

Theoretical Basis

Assumption/theoretical basis:

  • Factoring a big number is hard

P(Q)=1252151251235234234125P(Q)=1252151251235234234125. If we want to break RSA จะต้อง Factor out ให้ได้ ออกเป็น Prime number สองตัว!!

Key Characteristics

  • Variable key length (usually 512, 1024, 2048 bits)
    • 1024 ควรจะเป็น minimum แล้วตอนนี้!
  • Variable plaintext block size
    • Plaintext block must be "smaller" than modulus
    • Ciphertext block size is also smaller than modulus
  • Slower to compute than AES → mostly used to encrypt a secret key

RSA Key Selection

Key Generation Process

To generate a key pair (one public key and its corresponding private key):

  1. Select large primes, pp and qq which are almost same size (≈n\approx \sqrt{n})
  2. Compute n=pqn = pq and ϕ(n)=(p−1)(q−1)\phi(n) = (p-1)(q-1) (Theorem 3, 5)
  3. Keep pp and qq with yourself! (เก็บไว้ในใจ)

Mathematical Foundation

Before going to Step 4, understand this:

Suppose x∈Zpq∗x \in Z_{pq}^*, we know that:

x(p−1)(q−1)=1 mod pq\boxed{x^{(p-1)(q-1)} = 1 \bmod pq}

(Theorem 4)

  1. Choose ee that is relatively prime to (p−1)(q−1)(p-1)(q-1) and 1<e<(p−1)(q−1)1 < e < (p-1)(q-1)

We know from Theorem 6 that:

∃d,k∈Z; s.t. de−k(p−1)(q−1)=1\exists d, k \in Z; \text{ s.t. } de - k(p-1)(q-1) = 1

Therefore:

de=1+k(p−1)(q−1)\boxed{de = 1 + k(p-1)(q-1)}

Suppose we have xex^e where x∈Zpq∗x \in Z_{pq}^*, we can retrieve xx from xex^e by powering it with dd then modulo by pqpq:

xde=x1+k(p−1)(q−1) mod pq≡x mod pq\boxed{x^{de} = x^{1+k(p-1)(q-1)} \bmod pq \equiv x \bmod pq}

  1. Keep ee then find dd which is de=1 mod pq=1 mod nde = 1 \bmod pq = 1 \bmod n
  2. Securely delete pp and qq since we don't need to use them anymore
  3. Send pair of ee and nn: ⟨e,n⟩\langle e, n \rangle as a public key for encryption
  4. Keep ⟨d,n⟩\langle d, n \rangle as private key for decryption

RSA Key Generation Algorithm

Summary of Key Generation Steps

  1. Generate two large random primes, pp and qq, of approximately equal size such that their product n=pqn = pq is of the required bit length, e.g. 1024 bits
  2. Compute n=pqn = pq and (phi) ϕ=(p−1)(q−1)\phi = (p-1)(q-1)
  3. Choose an integer ee, 1<e<ϕ1 < e < \phi, such that gcd⁡(e,ϕ)=1\gcd(e, \phi) = 1
  4. Compute the secret exponent dd, 1<d<ϕ1 < d < \phi, such that ed≡1(modϕ)ed \equiv 1 \pmod{\phi}
    • → d=e−1 mod ϕd = e^{-1} \bmod \phi
  5. The public key is (n,e)(n, e) and the private key (d,p,q)(d, p, q). Keep all the values dd, pp, qq and ϕ\phi secret.
    • We prefer sometimes to write the private key as (n,d)(n, d) because you need the value of nn when using dd. Other times we might write the key pair as ((N,e),d)((N, e), d).

Terminology

  • nn is known as the modulus
  • ee is known as the public exponent or encryption exponent or just the exponent
  • dd is known as the secret exponent or decryption exponent

How Hard is RSA?

Security Analysis

  • We know that RSA uses product of two primes to generate nn (suppose pp and qq)
  • Since we have to randomly choose ee as the encrypt exponent and send ⟨e,n⟩\langle e, n \rangle as the encryption key.
  • Let the attacker knows ⟨e,n⟩\langle e, n \rangle and he also knows that there is dd which gcd⁡(d,e)=1\gcd(d, e) = 1 used for decryption.

However:

  • It is very hard for attacker to guess what dd is used without knowing pp and qq
  • (since there are many possible integers which gcd⁡(X,e)=1\gcd(X, e) = 1; d∈Xd \in X)

Analogy: It's like knowing someone mixed red and blue paint to get purple, but you don't know the exact amounts. Even though you know the result (purple/n) and one method (red/e), figuring out the exact recipe (blue/d) without knowing the original amounts (p and q) is incredibly difficult when the numbers are huge.


Naive RSA Encryption/Decryption

Encryption Process

To encrypt a message MM by the sender:

  • Obtains public key of recipient, Pub-key = ⟨e,n⟩\langle e, n \rangle
  • Computes:

C=Me mod n\boxed{C = M^e \bmod n}

where M∈Zpq∗M \in Z_{pq}^* and n=pqn = pq

Decryption Process

To decrypt the ciphertext CC by the receiver:

  • Uses their private key, Pri-key = ⟨d,n⟩\langle d, n \rangle
  • Computes:

M=Cd mod n\boxed{M = C^d \bmod n}


RSA Demo

YouTube Demo Link:
https://www.youtube.com/watch?v=9sY57iwNDJw


Security of RSA

Possible Approaches to Attacking RSA:

  1. Brute force key search (infeasible given size of numbers)
  2. Mathematical attacks (based on difficulty of computing ϕ(n)\phi(n), by factoring modulus nn)
  3. Timing attacks (on running of decryption)
  4. Chosen ciphertext attacks (given properties of RSA)
  5. Shor's algorithm on quantum computing can break any cryptographic algorithms which use integer factorization as a hard problem to secure their Pri-key and Pub-key. RSA is included!

Other Public-Key Cryptosystems

Elliptic Curve Cryptography (ECC)

  • At same security level of RSA, ==ECC needs smaller key size==
  • Instead of using integer factorization as RSA, ECC uses discrete logarithm problem as a hard problem for security

Elgamal Encryption

  • Faster than RSA for decryption, a bit slower for encryption
  • Elgamal was not patented but RSA was (in USA)
    • (now RSA's patent is already expired)

Exercise – RSA Encryption/Decryption

Online Tool:
https://www.devglan.com/online-tools/rsa-encryption-decryption


Elliptic Curve Cryptography (ECC)

ECC Introduction

Motivation for ECC

The Problem

Problem: Asymmetric schemes like RSA and Elgamal require exponentiations in integer rings and fields with parameters of more than 1000 bits.

  • High computational effort on CPUs with 32-bit or 64-bit arithmetic
  • Large parameter sizes critical for storage on small and embedded devices

The Motivation

Motivation: Smaller field sizes providing equivalent security are desirable

The Solution

Solution: Elliptic Curve Cryptography uses a group of points (instead of integers) for cryptographic schemes with coefficient sizes of 160-256 bits, reducing significantly the computational effort.

Analogy: Instead of working with giant numbers (like RSA's 1024+ bits), ECC works with points on a curve using much smaller numbers (160-256 bits). It's like using a complex 3D map (ECC) instead of a really, really long street address (RSA) - both get you to the destination securely, but one is more compact.


Computations on Elliptic Curves

Weierstraß Equation

Elliptic curves are polynomials that define points based on the (simplified) Weierstraß (VY-er-shtrass) equation:
y2=x3+ax+b\boxed{y^2 = x^3 + ax + b}
for parameters a,ba, b that specify the exact shape of the curve

Curve Characteristics

  • On the real numbers and with parameters a,b∈Ra, b \in \mathbb{R}, an elliptic curve looks like the diagram shown (a smooth curve with symmetry about the x-axis)
  • Elliptic curves can not just be defined over the real numbers R\mathbb{R} but over many other types of finite fields

Example: y2=x3−3x+3y^2 = x^3 - 3x + 3 over R\mathbb{R}


Finite Field

Definition

  • A finite field, also known as a Galois field, is a mathematical field that contains a finite number of elements
  • A field is a set equipped with two operations, addition and multiplication, that satisfy the basic field properties:
    • Associativity
    • Commutativity
    • Distributivity
    • Existence of identity elements
    • Inverses

Common Examples

The most common examples of finite fields are given by the integers mod p when pp is a prime number.


Computations on Elliptic Curves (continued)

In Cryptography

In cryptography, we are interested in elliptic curves modulo a prime pp:

Definition: Elliptic Curves over prime fields

The elliptic curve over ZpZ_p, p>3p > 3 is the set of all pairs (x,y)∈Zp(x, y) \in Z_p which fulfill
y2=x3+ax+b mod p\boxed{y^2 = x^3 + ax + b \bmod p}
together with an imaginary point of infinity θ\theta, where a,b∈Zpa, b \in Z_p and the condition
4a3+27b2≠0 mod p\boxed{4a^3 + 27b^2 \neq 0 \bmod p}
Note that Zp={0,1,...,p−1}Z_p = \{0, 1, ..., p-1\} is a set of integers with modulo p arithmetic


Computations on Elliptic Curves (continued)

Special Considerations


Some special considerations are required to convert elliptic curves into a group of points

  • In any group, a special element is required to allow for the identity operation, i.e., given P∈EP \in E: P+θ=P=θ+PP + \theta = P = \theta + P

  • This identity point (which is not on the curve) is additionally added to the group definition

  • This (infinite) identity point is denoted by θ\theta

Symmetric = fold paper along horizontal axis

Symmetry Properties

Elliptic Curve are symmetric along the x-axis

  • Up to two solutions yy and −y-y exist for each quadratic residue xx of the elliptic curve

  • For each point P=(x,y)P = (x, y), the inverse or negative point is defined as −P=(x,−y)-P = (x, -y)

Analogy: Think of the elliptic curve like a butterfly - it's perfectly symmetric about the x-axis. If you have a point P above the x-axis, its "mirror image" -P is directly below it at the same x-coordinate. The point at infinity θ is like a meeting point where parallel lines meet - an abstract concept that makes the math work.


Computations on Elliptic Curves (continued)

Point Addition Operation

Generating a group of points on elliptic curves based on point addition operation P+Q=RP + Q = R, i.e., (xP,yP)+(xQ,yQ)=(xR,yR)(x_P, y_P) + (x_Q, y_Q) = (x_R, y_R)

Geometric Interpretation of Point Addition Operation

  • Draw straight line through P and Q; if P=Q use tangent line instead
  • Mirror third intersection point of drawn line with the elliptic curve along the x-axis

Elliptic Curve Point Addition and Doubling Formulas

x3=s2−x1−x2 mod p and y3=s(x1−x3)−y1 mod p\boxed{x_3 = s^2 - x_1 - x_2 \bmod p \text{ and } y_3 = s(x_1 - x_3) - y_1 \bmod p}
where

\frac{y_2 - y_1}{x_2 - x_1} \bmod p & \text{; if } P \neq Q \text{ (point addition)} \\ \frac{3x_1^2 + a}{2y_1} \bmod p & \text{; if } P = Q \text{ (point doubling) } = P + P \end{cases}$$ https://blog.cloudflare.com/a-relatively-easy-to-understand-primer-on-elliptic-curve-cryptography/ อ่านหน่อย! ___ ## Visual Example of Point Addition Image description from slide 32: Shows geometric representation of point addition P + Q = R on an elliptic curve, where a line L(x) passes through points P, Q, and R ![[Pasted image 20260127134424.png|center|300]] --- ## Example $8^*G$ Image description from slide 33: Visual demonstration of computing 8G through repeated doubling and addition operations on an elliptic curve ![[Pasted image 20260127134527.png|center|300]] --- ## Computations on Elliptic Curves (continued) ### Example Problem **Example:** Given $E: y^2 = x^3 + 2x + 2 \bmod 17$ and point $P = (5, 1)$ **Goal:** Compute $2P = P + P = (5, 1) + (5, 1) = (x_3, y_3)$ **Solution:** $$s = \frac{3x_1^2 + a}{2y_1} = (2 \cdot 1)^{-1}(3 \cdot 5^2 + 2) = 2^{-1} \cdot 9 \equiv 9 \cdot 9 \equiv 13 \bmod 17$$ $$x_3 = s^2 - x_1 - x_2 = 13^2 - 5 - 5 = 159 \equiv 6 \bmod 17$$ $$y_3 = s(x_1 - x_3) - y_1 = 13(5 - 6) - 1 = -14 \equiv 3 \bmod 17$$ **Finally:** $2P = (5, 1) + (5, 1) = (6, 3)$ --- ## Computations on Elliptic Curves (continued) ### Complete Point Generation Example **The points on an elliptic curve and the point at infinity** $\theta$ **form cyclic subgroups** Given starting point $P = (5, 1)$: | Computation | Result | |------------|--------| | $2P = (5,1)+(5,1)$ | $(6,3)$ | | $3P = 2P+P$ | $(10,6)$ | | $4P$ | $(3,1)$ | | $5P$ | $(9,16)$ | | $6P$ | $(16,13)$ | | $7P$ | $(0,6)$ | | $8P$ | $(13,7)$ | | $9P$ | $(7,6)$ | | $10P$ | $(7,11)$ | | Computation | Result | |------------|--------| | $11P$ | $(13,10)$ | | $12P$ | $(0,11)$ | | $13P$ | $(16,4)$ | | $14P$ | $(9,1)$ | | $15P$ | $(3,16)$ | | $16P$ | $(10,11)$ | | $17P$ | $(6,14)$ | | $18P$ | $(5,16)$ | | $19P$ | $\theta$ | **This elliptic curve has order** $\#E = |E| = 19$ **since it contains 19 points in its cyclic group.** > **Analogy:** It's like a clock with 19 hours instead of 12. Starting from point P, you keep "adding hours" (adding P to itself) until you complete the full cycle and return to the starting position (the point at infinity θ). ___ ## Number of Points on an Elliptic Curve ### The Question **How many points can be on an arbitrary elliptic curve?** - Consider previous example: $E: y^2 = x^3 + 2x + 2 \bmod 17$ has 19 points - However, determining the point count on elliptic curves in general is hard ### Hasse's Theorem **But Hasse's theorem bounds the number of points to a restricted interval** **Definition: Hasse's Theorem:** Given an elliptic curve module $p$, the number of points on the curve is denoted by $\#E$ and is bounded by $$\boxed{p + 1 - 2\sqrt{p} \leq \#E \leq p + 1 + 2\sqrt{p}}$$ ### Interpretation - **Interpretation:** ==The number of points is "close to" the prime $p$== - **Example:** To generate a curve with about $2^{160}$ points, a prime with a length of about 160 bits is required ___ ## Elliptic Curve Discrete Logarithm Problem ### Foundation of Security **Cryptosystems rely on the hardness of the Elliptic Curve Discrete Logarithm Problem (ECDLP)** **Definition: Elliptic Curve Discrete Logarithm Problem (ECDLP)** Given a primitive element $P$ and another element $T$ on an elliptic curve $E$. The ECDL problem is finding the integer $d$, where $1 \leq d \leq \#E$ such that $$\boxed{\underbrace{P + P + ... + P}_{d \text{ times}} = dP = T}$$ ### Cryptographic Implications - **Cryptosystems are based on the idea that** $d$ **is large and kept secret** and attackers cannot compute it easily - **If** $d$ **is known**, an efficient method to compute the point multiplication $dP$ is required to create a reasonable cryptosystem - Known **Square-and-Multiply Method** can be adapted to Elliptic Curves - The method for efficient point multiplication on elliptic curves: **Double-and-Add Algorithm** > **Analogy:** It's like knowing someone got to the 1000th floor by taking an elevator (the result T), and you know which floor they started on (P), but you don't know which button they pressed (d). Finding d without trying all possibilities is extremely hard when the numbers are large. ___ ## Double-and-Add Algorithm for Point Multiplication ### Overview The **Double-and-Add Algorithm** is a method used for **scalar multiplication** on an elliptic curve. Given an elliptic curve $E$, a point $P$ on the curve, and a scalar $d$, the algorithm efficiently computes $T = dP$ by iterating through the bits of $d$. ### Algorithm **Input:** - Elliptic curve $E$ - Point $P$ on $E$ - Scalar $d$ represented as binary $(d_n, d_{n-1}, ..., d_0)$ **Output:** - $T = dP$, the scalar multiple of $P$ ### Steps: 1. **Initialize** $T = 0$ (the identity element of the elliptic curve) 2. **Loop through bits of** $d$**, starting from the most significant bit (MSB) to the least significant bit (LSB):** - **Double** $T$ (i.e., compute $T = 2T$) - **If the bit** $d_i = 1$**, add** $P$ **to** $T$ (i.e., compute $T = T + P$) 3. **Return** $T$ ___ ## Example of Double-and-Add Algorithm ### Example: Suppose $d = 13$ and is represented as **(1101)** in binary. 1. **Start with** $T = 0$ 2. **Read bits from left to right (MSB first):** $1 \rightarrow 1 \rightarrow 0 \rightarrow 1$ - **Step 1 (bit = 1)** → $T = 0$, double 0 (remains 0), add $P$: $T = P$ - **Step 2 (bit = 1)** → double $P$ $(2P)$, add $P$: $T = 3P$ - **Step 3 (bit = 0)** → double $3P$: $T = 6P$ - **Step 4 (bit = 1)** → double $6P$ $(12P)$, add $P$: $T = 13P$ Thus, the result is $T = 13P$. --- ## Complexity Analysis ### Performance Analysis - The **number of doublings** is $O(\log d)$ (since $d$ has $\log_2 d$ bits) - The **number of additions** depends on the number of **1s** in the binary representation of $d$ - The worst-case complexity is $O(\log d)$ for both **doubling** and **addition** ___ ## Why is Double-and-Add Efficient? ### Efficiency Reasons - It **reduces the number of elliptic curve operations** - Instead of computing $dP$ with repeated additions, it **leverages the binary representation** of $d$ to speed up computations - Used in cryptographic applications such as **ECDSA**, **ECDH**, and **Elliptic Curve Cryptography (ECC)** --- ## Private Key, Public Key and the Generator Point in ECC ### Key Concepts in ECC In the **ECC**, when we multiply a fixed EC point **G** (the **generator** point) by certain **integer k** (**k** can be considered as **private key**), we obtain an EC point **P** (its corresponding **public key**). Consequently, in ECC we have: - **Elliptic curve (EC)** over finite field $\mathbb{F}_p$ - **G == generator point** (fixed constant, a base point on the EC) - **k == private key** (integer) - **P == public key** (point) ### Key Generation It is **very fast** to calculate $P = k * G$, using the well-known ECC multiplication algorithms in time $log_2(k)$, e.g. the "double-and-add algorithm". For 256-bit curves, it will take just a few hundreds simple EC operations. >จะ calculate public key ก็แค่เอา private คือ * point ใด point นึงใน curve (CHECK!!) ### Private Key Format The **private keys** in the ECC are integers (in the range of the curve's field size, typically **256-bit** integers). Example of 256-bit ECC private key (hex encoded, 32 bytes, 64 hex digits) is: ``` 0x51897b64e85c3f714bba707e867914295a1377a7463a9dae8ea6a8b914246319 ``` ### Key Generation Process The **key generation** in the ECC cryptography is as simple as securely generating a **random integer** in certain range, so it is extremely fast. Any number within the range is valid ECC private key. ___ ## The Elliptic Curve Diffie-Hellman Key Exchange (ECDH) ### Setup **Given a prime** $p$**, a suitable elliptic curve** $E$ **and a point** $P=(x_P, y_P)$ **The Elliptic Curve Diffie-Hellman Key Exchange is defined by the following protocol:** ### Protocol **Alice:** - Choose $k_{PrA} = a \in \{2, 3, ..., \#E-1\}$ - Compute $k_{PubA} = A = aP = (x_A, y_A)$ - Send $A$ → - Receive ← $B$ - Compute $aB = T_{ab}$ **Bob:** - Choose $k_{PrB} = b \in \{2, 3, ..., \#E-1\}$ - Compute $k_{PubB} = B = bP = (x_B, y_B)$ - Receive $A$ - Send $B$ → - Compute $bA = T_{ab}$ ### Shared Secret **Joint secret between Alice and Bob:** $T_{AB} = (x_{AB}, y_{AB})$ **Proof for correctness:** - Alice computes $aB = a(bP) = abP$ - Bob computes $bA = b(aP) = abP$ since group is associative >The ECC secret key can be used as a session key for AES encryption. **One of the coordinates of the point** $T_{AB}$ **(usually the x-coordinate) can be used as session key (often after applying a hash function)** > **Analogy:** Alice and Bob each have a secret number (a and b). They each multiply a public starting point P by their secret number and share the results. Then they each take what the other shared and multiply by their own secret. Both end up at the same final point - that's their shared secret! It's like two people starting from the same location, taking different paths, but meeting at the same destination. ### ECDH for Symmetric Encryption **The ECDH is often used to derive session keys for (symmetric) encryption** **One of the coordinates of the point** $T_{AB}$ **(usually the x-coordinate) is taken as session key** ### Complete Protocol with Encryption **Alice:** - Choose $k_{PrA} = a \in \{2, 3, ..., \#E-1\}$ - Compute $k_{PubA} = A = aP = (x_A, y_A)$ - Send $A$ → - Receive ← $B$ - Compute $aB = T_{ab} = (x_T, y_T)$ - Define key $k_{AES} = x_T$ - Given a message $m$: - Encrypt $c = AES_{k_{AES}}(m)$ - Send $c$ → **Bob:** - Choose $k_{PrB} = b \in \{2, 3, ..., \#E-1\}$ - Compute $k_{PubB} = B = bP = (x_B, y_B)$ - Receive $A$ - Send $B$ → - Compute $bA = T_{ab} = (x_T, y_T)$ - Define key $k_{AES} = x_T$ - Received ciphertext $c$: - Decrypt $m = AES^{-1}_{k_{AES}}(c)$ **Stages:** - **ECDH** (top section) - **Symmetric encryption/decryption** (bottom section) --- ## ECDH Demo **Interactive Demo:** http://www-cs-students.stanford.edu/~tjw/jsbn/ecdh.html ___ ## Security Aspects ### Why Smaller Parameters? **Why are parameters significantly smaller for elliptic curves (160-256 bit) than for RSA (1024-3076 bit)?** - **Attacks on groups of elliptic curves are weaker** than available factoring algorithms or integer DL attacks - **Best known attacks** on elliptic curves (chosen according to cryptographic criterions) are the **Baby-Step Giant-Step** and **Pollard-Rho method** - **Complexity of these methods:** on average, roughly $\sqrt{p}$ steps are required before the ECDLP can be successfully solved ### Implications to Practical Parameter Sizes **Implications to practical parameter sizes for elliptic curves:** - An elliptic curve using a prime $p$ with **160 bit** (and roughly $2^{160}$ points) provides a security of $2^{80}$ steps that required by an attacker (on average) - An elliptic curve using a prime $p$ with **256 bit** (roughly $2^{256}$ points) provides a security of $2^{128}$ steps on average > **Analogy:** Breaking RSA is like factoring a huge number into two prime factors - hard but getting easier with better algorithms. Breaking ECC is like finding a specific point on a curve by trial and error - the best known method still requires checking roughly the square root of all possibilities, which keeps the problem hard even with smaller numbers. --- ## ECC vs RSA Security Comparison Image description from slide 48: Shows that 256-bit ECC encryption provides the same security as 3072-bit RSA encryption, illustrated with lock icons ![[Pasted image 20260127140516.png|center|500]] --- ## Key Size Ratio and Cost Ratio for ECC and RSA ### Comparison Table | ECC Key Size (bits) | RSA Key Size (bits) | Key Size Ratio | Cost Ratio | |---------------------|---------------------|----------------|------------| | 160 | 1024 | 1:7 | 1:3 | | 224 | 2048 | 1:10 | 1:6 | | 256 | 3072 | 1:12 | 1:10 | | 384 | 7680 | 1:20 | 1:32 | | 521 | 15360 | 1:30 | 1:64 | The table values prove that **ECC can provide same security level of RSA with shorter key length**. The advantage of ECC over RSA is very obvious. **Reference:** https://www.researchgate.net/publication/305913586 ___ ## Implementations in Hardware and Software ### Four-Layer Structure **Elliptic curve computations usually regarded as consisting of four layers:** ![[Pasted image 20260127140535.png|center|250]] ``` ┌─────────────────────────────────┐ │ Protocol (ECDSA) │ ├─────────────────────────────────┤ │ Point Multiplication (k·P) │ ├─────────────────────────────────┤ │ Group Operation P+Q, 2·P │ ├─────────────────────────────────┤ │ Modular Arithmetic (+,-,×,÷) │ └─────────────────────────────────┘ ``` ### Optimization Focus - **Basic modular arithmetic operations** are computationally most expensive - **Group operation** implements point doubling and point addition - **Point multiplication** can be implemented using the Double-and-Add method - **Upper layer protocols** like ECDH and ECDSA **Most efforts should go in optimizations of the modular arithmetic operations, such as:** - Modular addition and subtraction - Modular multiplication - Modular inversion ### Software Implementations ![[Pasted image 20260127140642.png|center|200]] - **Optimized 256-bit ECC implementation** on 3GHz 64-bit CPU requires about **2 ms** per point multiplication - **Less powerful microprocessors** (e.g., on SmartCards or cell phones) even take significantly longer (**>10 ms**) ### Hardware Implementations - **High-performance implementations** with 256-bit special primes can compute a point multiplication in a **few hundred microseconds** on reconfigurable hardware - **Dedicated chips** for ECC can compute a point multiplication even in a **few ten microseconds** > **Analogy:** Software implementations are like doing complex math by hand - even with a calculator (CPU), it takes time. Hardware implementations are like having a special-purpose machine built just for that calculation - much faster because it's optimized for that specific task. ___ ## Lessons Learned ### Key Takeaways - **Elliptic Curve Cryptography (ECC)** is based on the discrete logarithm problem. It requires, for instance, arithmetic modulo a prime. - **ECC can be used** for key exchange, for digital signatures and for encryption. - **ECC provides the same level of security** as RSA or discrete logarithm systems over $Z_p$ with considerably shorter operands (approximately **160–256 bit vs. 1024–3072 bit**), which results in shorter ciphertexts and signatures. - **In many cases ECC has performance advantages** over other public-key algorithms. - **ECC is slowly gaining popularity** in applications, compared to other public-key schemes, i.e., many new applications, especially on embedded platforms, make use of elliptic curve cryptography. --- ## Summary: RSA vs ECC ### RSA (Rivest-Shamir-Adleman) **Security Basis:** Integer factorization (hard to factor large numbers) **Key Sizes:** 1024-3072 bits for adequate security **Speed:** Slower than ECC for equivalent security **Use Cases:** - Widely deployed and trusted - Digital signatures - Key exchange - Encryption ### ECC (Elliptic Curve Cryptography) **Security Basis:** Elliptic Curve Discrete Logarithm Problem (ECDLP) **Key Sizes:** 160-256 bits for equivalent security to RSA **Speed:** Faster with smaller keys **Use Cases:** - Mobile devices and embedded systems - Modern applications requiring efficiency - Digital signatures (ECDSA) - Key exchange (ECDH) ### Quick Comparison | Feature | RSA | ECC | |---------|-----|-----| | Security Level | 128-bit | 128-bit | | Key Size | 3072 bits | 256 bits | | Relative Speed | 1× | 10× faster | | Bandwidth | High | Low | | Best For | Established systems | Resource-constrained devices |