Unit 5: Public Key Cryptography
Public-key (asymmetric) cryptography, introduced by Diffie and Hellman (1976), replaces the single shared secret of symmetric ciphers with a mathematically linked key pair: a public key that anyone may use to encrypt or verify, and a private key held only by the owner. Its security rests on one-way functions with trapdoors — operations easy to compute but computationally infeasible to invert without secret information. The number-theoretic hard problems below underpin every scheme in this unit.
- Key pair: each user owns
(public key, private key); the public key is published, the private key never leaves the owner. - Trapdoor one-way function:
f(x)is easy,f⁻¹(y)is infeasible unless a secret (the trapdoor) is known — e.g. multiplying primes is easy, factoring their product is hard. - Discrete logarithm problem (DLP): given
g,p, andg^x mod p, recoveringxis infeasible for large primep. - Integer factorisation problem (IFP): given
n = p·qfor large primesp, q, recoveringpandqis infeasible. - Convention: all arithmetic is modular;
moddenotes remainder,gcdthe greatest common divisor, andφ(n)Euler's totient (count of integers< ncoprime ton).
II. Diffie–Hellman Key Exchange — Establishing a shared secret over a public channel
A protocol (not an encryption scheme) that lets two parties agree on a common secret key without ever transmitting it, its security resting on the DLP.
A. Introduction to Public-Key Cryptography
The founding idea that a secret can be built from public exchanges.
- Break with symmetric crypto: removes the need for a pre-shared key distributed over a secure channel — the central weakness of symmetric systems.
- Public parameters: a large prime
pand a primitive root (generator)gof the multiplicative group modpare agreed openly. - Asymmetry of effort: computing
g^a mod pis fast (square-and-multiply); reversing it to findarequires solving the DLP. - Scope: produces a shared key for later symmetric encryption; it does not itself encrypt messages.
B. Diffie–Hellman Key Exchange
The protocol steps and the algebraic identity that makes both sides arrive at the same value.
- Setup: public
p(prime) andg(generator modp). - Private choices: Alice picks secret
a, Bob picks secretb. - Public exchange: each sends a power of
g:
Alice computes A = g^a mod p → sends A to Bob
Bob computes B = g^b mod p → sends B to Alice- Shared secret: each raises the received value to their own secret:
Alice: K = B^a mod p = (g^b)^a mod p = g^(ab) mod p
Bob: K = A^b mod p = (g^a)^b mod p = g^(ab) mod p- Symbols:
pprime modulus;ggenerator;a, bprivate exponents;A, Bpublic values;Kshared keyg^(ab) mod p. - Worked example: let
p = 23,g = 5,a = 6,b = 15.A = 5^6 mod 23 = 8;B = 5^15 mod 23 = 19.- Alice:
19^6 mod 23 = 2; Bob:8^15 mod 23 = 2. Shared keyK = 2.
- Limitation — man-in-the-middle: an attacker who intercepts
AandBcan substitute their own values, since the protocol offers no authentication; it must be paired with signatures or certificates.
III. The RSA Cryptosystem — Encryption and signatures from the hardness of factoring
The first practical public-key encryption scheme (Rivest, Shamir, Adleman, 1977), whose trapdoor is the difficulty of factoring n = p·q.
A. The RSA Cryptosystem (Key Generation)
RSA's security follows from the fact that knowing n does not reveal φ(n) without the factors p and q.
- Choose primes: select two large distinct primes
pandq. - Compute modulus:
n = p·q— published as part of the public key. - Compute totient:
φ(n) = (p−1)(q−1)— kept secret; its secrecy is equivalent to factoringn. - Choose public exponent: pick
ewith1 < e < φ(n)andgcd(e, φ(n)) = 1(commonlye = 65537). - Compute private exponent:
d ≡ e⁻¹ mod φ(n), i.e.e·d ≡ 1 (mod φ(n)), found via the extended Euclidean algorithm. - Key pair: public key
(e, n); private key(d, n)(withp, q, φ(n)discarded or secured). - Symbols:
p, qprimes;nmodulus;φ(n)totient;eencryption exponent;ddecryption exponent.
B. RSA Encryption
Turning a message into ciphertext using only the recipient's public key.
- Message encoding: represent the plaintext as an integer
mwith0 ≤ m < n. - Encryption rule:
c = m^e mod n- Public operation: anyone with
(e, n)can encrypt; no secret is needed to producec. - Symbols:
mplaintext integer;cciphertext;(e, n)public key. - Why it is hard to invert: recovering
mfromcwithoutdrequires taking ane-th root modn, believed as hard as factoringn. - Practical note: raw ("textbook") RSA is deterministic and insecure; real use applies padding (e.g. OAEP) so identical messages do not yield identical ciphertexts.
C. RSA Decryption
Recovering the plaintext with the private exponent, justified by Euler's theorem.
- Decryption rule:
m = c^d mod n- Correctness: since
e·d ≡ 1 (mod φ(n)), we havee·d = 1 + k·φ(n), soc^d = m^(ed) = m^(1+kφ(n)) = m·(m^φ(n))^k ≡ m (mod n)by Euler's theorem. - Symbols:
cciphertext;dprivate exponent;nmodulus;mrecovered plaintext. - Efficiency: decryption is sped up using the Chinese Remainder Theorem, computing
m mod pandm mod qseparately then recombining — roughly four times faster. - Worked example:
p = 5,q = 11→n = 55,φ(n) = 40. Choosee = 3(gcd(3,40)=1); thend = 27(3·27 = 81 ≡ 1 mod 40).- Encrypt
m = 7:c = 7^3 mod 55 = 343 mod 55 = 13. - Decrypt:
m = 13^27 mod 55 = 7. ✓
- Encrypt
D. Applications and Limitations
The reach and constraints of RSA in practice.
- Confidentiality and signatures: encrypting with the public key gives secrecy; "encrypting" a hash with the private key gives a verifiable digital signature.
- Speed: slow relative to symmetric ciphers, so RSA typically encrypts only a symmetric session key (hybrid encryption).
- Key size: requires ≈2048–3072-bit
nfor current security; keys grow as factoring methods improve. - Vulnerabilities: small
ewith unpadded messages, shared moduli, or poor prime generation break the scheme — hence mandatory padding.
IV. The ElGamal Cryptosystem — Public-key encryption from the discrete logarithm
An encryption scheme (Taher ElGamal, 1985) built directly on the DLP, extending the Diffie–Hellman idea from key agreement to full message encryption.
A. The ElGamal Cryptosystem (Structure and Keys)
ElGamal encrypts by masking the message with a freshly generated Diffie–Hellman-style secret each time.
- Public parameters: large prime
pand generatorgof the group modp. - Key generation: recipient picks private key
x(1 < x < p−1) and computes public keyh = g^x mod p. - Key pair: public
(p, g, h); privatex. - Randomised encryption — the sender chooses a fresh ephemeral key
kper message:
c1 = g^k mod p
c2 = m · h^k mod p (m = plaintext, 0 ≤ m < p)
ciphertext is the pair (c1, c2).
- Decryption — recover the mask, then divide it out:
s = c1^x mod p = g^(kx) mod p
m = c2 · s⁻¹ mod p
since c2 = m·(g^x)^k = m·g^(kx) and s = g^(kx), the factor cancels.
- Symbols:
xprivate key;hpublic key;kephemeral secret;(c1, c2)ciphertext pair;sshared mask;s⁻¹its modular inverse.
B. Comparison and Limitations
How ElGamal contrasts with RSA and where it is weak.
- RSA: based on factoring (IFP); deterministic without padding; ciphertext is a single value the size of
n. - ElGamal: based on the DLP; inherently randomised via
k, so the same plaintext yields different ciphertexts; ciphertext is a pair, doubling its size.- Ephemeral-key rule: a fresh, unpredictable
kis essential — reusingkacross messages leaks relationships and can expose plaintexts. - Ciphertext expansion: encrypted output is twice the plaintext length, a cost of the randomisation.
- Foundation for other schemes: its structure generalises to elliptic-curve encryption and to the Digital Signature Algorithm (DSA), giving it lasting theoretical importance.
- Ephemeral-key rule: a fresh, unpredictable
Did this save you a night before the exam?
LPU Notes is free, and it stays free. Ads cover part of the server bill. The rest comes out of a student's own pocket: the domain, the storage, and keeping the site up through the weeks everyone needs it at once.
The payment button didn't load. An ad blocker or a filtered network is the usual reason. to try again.
Nothing here is ever locked, and nothing unlocks. Chip in only if it was worth it. What it pays for →