Learn › Blockchain & Access Control › Module 2 · Public-key cryptography
ElGamal and elliptic-curve foundations
ElGamal encryption modulo a prime with a full example and why it is randomised, then elliptic curves: the Weierstrass form, non-singularity, the point at infinity, chord-and-tangent addition and the group laws.
ElGamal encryption (1985)
Turns Diffie–Hellman into encryption; security rests on the DLP in Zp*. Encryption is randomised: a fresh secret k each time means the same plaintext gives different ciphertexts. The ciphertext is twice the plaintext size.
Keys: prime p, primitive root α, secret a, public β = αa mod p.
Encrypt x with random k: y1 = αk, y2 = x·βk (mod p).
Decrypt: x = y2·(y1a)−1 mod p, since y1a = βk.
Worked example
p = 2579, α = 2, a = 765 ⇒ β = 949. x = 1299, k = 853: y1 = 435, y2 = 2396. Bob computes 2396·(435765)−1 mod 2579 = 1299.
Never reuse k: two ciphertexts with the same k reveal x1/x2. GnuPG supports ElGamal for wrapping session keys.
Elliptic curves: intuition
A finite set of points with an addition rule that stays on the curve. Scalar multiplication kG = G + … + G is fast (double-and-add). Recovering k from G and kG is the elliptic-curve discrete logarithm problem (ECDLP); no sub-exponential (index-calculus-type) attack is known for well-chosen curves.
Weierstrass form: y2 = x3 + ax + b, with 4a3 + 27b2 ≠ 0.
If the discriminant is zero the curve is singular (a cusp such as y2 = x3, or a node such as y2 = x3 − 3x + 2) and unsuitable. The point at infinity O is the identity; E(a, b) is the curve’s points plus O.
Chord-and-tangent addition
Draw the line through P and Q; it meets the cubic at a third point R′; reflect R′ in the x-axis to get P + Q. The inverse of (x, y) is (x, −y).
| Case | Rule |
|---|---|
| P + O | P |
| x1 ≠ x2 | λ = (y2 − y1)/(x2 − x1) |
| Q = −P (vertical line) | P + Q = O |
| P = Q, y1 ≠ 0 (tangent) | λ = (3x12 + a)/(2y1) |
| Result | x3 = λ2 − x1 − x2; y3 = λ(x1 − x3) − y1 |
Worked example over the reals
y2 = x3 − 4x (discriminant −256 ≠ 0). P = (−2, 0), Q = (0, 0): λ = 0, x3 = 2, y3 = 0, so P + Q = (2, 0) — all three lie on y = 0. Doubling (2, 0): y = 0 gives a vertical tangent, so 2(2, 0) = O.
Group properties
(E, +) is an abelian group: closure, associativity, identity O, inverse (x, −y), commutativity (the line through P and Q is the line through Q and P). Bitcoin and Ethereum use secp256k1, y2 = x3 + 7 over a 256-bit prime field: the private key is a random 256-bit k, the public key is kG.