CIS 5371 Cryptography 8. Asymmetric encryption- 1 Public Key Cryptography Alice Bob Alice and Bob want to exchange a private key in public. Public Key Cryptography The Diffie-Hellman protocol Let p is a large prime and ðïðð∗ . ïŽ The order â of ð is a factor of ð − 1. ïŽ ðð∗ has a generator for any factor h of ð − 1. ïŽ p is called a safe prime if h = 2q, with q a prime. Public Key Cryptography The Diffie-Hellman protocol Alice ga mod p Bob gb mod p The private key is: gab mod p where p is a prime and g is a generator of Zp* Example • p = 43, g = 3, • Alice and Bob share (p,g) = (43,3). • Alice picks her (secret) exponent: a random a = 8 ïU [0:42]. • Alice sends Bob: 38 ïš 25 (mod 43). • Bob picks his (secret) exponent: a random b = 37ïU [0:42]. • Bob sends Alice: 337 ïš 20 (mod 43). • The secret key agreed between the two is: 9 ïš 208 ïš 2537 (mod 43). Man-in-the-middle attack • Alice picks a ïU Zp* and sends Malice (“Bob”): ga (mod p) • Malice (“Alice”) picks m ï Zp* and sends Bob: gm (mod p) • Bob picks b ïU Zp* and sends Malice (“Bob) Bob: gb (mod p) • Malice (“Bob”) sends Alice: gm (mod p) • Alice computes: k1 ïŽ (gm)a (mod p) • Bob computes: k2 ïŽ (gm)b (mod p) The Computational Diffie-Hellman Problem, CDH • INPUT – The description of a finite cyclic group ðš of prime order q – A generator element ð of ðš – ðð , ðð ï ðš, for some integers 0 < ð, ð < ð. • OUTPUT – ððð The Computational Diffie-Hellman Assumption • A CDH solver is a PPT algorithm that solves the CDH problem. • The CDH Assumption is that, for any CDH solver there exists a negligible function negl such that: ï for an arbitrary instance of the CDH problem, the CDH solver will succeed with probability ïĢ negl for all sufficiently large inputs. The Decisional Diffie-Hellman Problem, DDH • INPUT – The description of a finite cyclic group G of prime order q – A generator element g of G – ga, gb, gc ï G, for some integers 0 < a,b,c < q. • OUTPUT – 1 Decision that gc = gab or – 0 Decision that gc ïđ gab The Decisional Diffie-Hellman Assumption • A DDH solver is a PPT algorithm that solves the DDH problem. • The DDH Assumption is that, for any DDH solver, there exists a negligible function negl such that: â for an arbitrary instance of the DDH problem, the DDH solver will succeed with probability ïĢ negl for all sufficiently large inputs. The Discrete Logarithm Problem The Discrete Logarithm Problem - DL • INPUT – The description of a finite cyclic group G of order q (say Zq*) – A generator element g of G – h ï G. • OUTPUT – The unique integer a < q such that h = ga mod q . We call the integer a the discrete logarithm of h in base g and write: a = logg h modq . The Discrete Logarithm Assumption • A DL solver is a PPT algorithm that solves the DL problem. • The DL Assumption is that, for any DL solver, there exists a negligible function negl such that: â for an arbitrary instance of the DL problem, the DDH solver will succeed with probability ïĢ negl for all sufficiently large inputs. The RSA cryptosystem Alice performs the following steps ï Choose p, q large primes with |p| ïŧ |q|. ï Compute N = pq. ï Compute ïŠ (N) = (p-1)(q-1). ï ï Choose a random integer e < ïŠ (N) such that gcd(e,ïŠ (N)) = 1 and compute the integer d such that ed = 1 (mod ïŠ (N)). Make (N,e) the public key, keep (N,d) as private key, and discard p,q and ïŠ (N). The RSA cryptosystem Encryption Let m < N be the confidential message that Bob wants to send to Alice. • • Bob computes the ciphertext: c ïŽ ðð (ððð ð). Bob sends Alice: c Decryption To decrypt the ciphertext c Alice computes: ð ← ð ð (ððð ð). Check We have: ïŽ ed = 1 (mod ïŠ (N)) , so ed = 1 + tïŠ (N). Therefore, ïŽ Dd (Ee (m)) = (me)d = m ed = m tïŠ(N)+1 = (mïŠ(n))t ïī m = 1ïīm = m mod n Example • Let p = 101, q = 113. Then N = 11413. • ïŠ (N) = 100 x 112 = 11200 = 26527 • For encryption use e = 3533. • Alice computes: d = 6531 such that ed =1 mod 11200 (using the Extended Euclidean Algorithm). • Alice publishes: N = 11413, e = 3533. • Suppose Bob wants to encrypt: 9726. • Bob computes 97263533 mod 11413 = 5761 • Bob sends Alice the ciphertext 5761. • To decrypt it Alice computes the plaintext: 57616597 (mod 11413) = 9726 Implementation 1. 2. 3. 4. 5. Generate two large primes: p,q N ï pq and ïŠ (N)= (p-1)(q-1) Choose random e: with 1 < e < ïŠ (N) & gcd(e,ïŠ (N))=1 d ï e -1 mod f (n) The public key is (N,e) and the private key is (N,d) Cost In Zn: ïŽ ïŽ Cost of a modular multiplication (xïīy) mod n is O (k2), where k = |log2n| Cost of a modular exponentiation xz (mod n) is O (k2 log2z) = O (k2 log2 n) Cryptanalysis of Public-key cryptosystems Active attacks on cryptosystems • Chosen-Plaintext Attack (CPA): – The attacker chooses plaintexts and obtains the corresponding ciphertexts: the task of the attacker is successful if he can decrypt a (new) target ciphertext. • Chosen-Ciphertext Attack (CCA1): – The attacker chooses a number of ciphertexts and obtains the corresponding plaintexts: the task of the attacker is successful if he can decrypt a (new) target ciphertext. • Adaptive Chosen-Ciphertext Attack (CCA2): – This is a CCS1 attack in which the attacker can adaptively choose ciphertexts: the task of the attacker is successful if he can decrypt a (new) target ciphertext. The RSA Problem • INPUT – N = pq with p,q prime nmbers. – e an integer such that gcd(e,(p-1)(q-1)) =1 – c ï ZN . • OUTPUT – The unique integer m ï ZN such that me ïš c (mod N ) The RSA Assumption • An RSA solver is a PPT algorithm that solves the RSA problem. • The RSA Assumption is that, for any RSA solver, there exists a negligible function negl such that: â for an arbitrary instance of the RSA problem, the RSA solver will succeed with probability ïĢ negl for all sufficiently large inputs. The Integer Factorization Problem The IF Problem (IF) • INPUT – N an odd composite integer with at least two distinct prime factors. • OUTPUT – A prime p such that p | N. The IF Assumption • An integer factorizer is a PPT algorithm that solves the IF problem. • The IF Assumption is that, for any IF solver, there exists a negligible function negl such that: â for an arbitrary instance of the IF problem, the IF solver will succeed with probability ïĢ negl for all sufficiently large inputs. Security of RSA 1. Relation to IF problem Recovering the plaintext m from an RSA ciphertext c is easy if factoring is possible. 2. Relation to RSA problem Recovering the plaintext m from an RSA ciphertext c is easy if the RSA problem is easy. 3. Relation between IF and RSA problems • • If the IF problem is easy then the RSA problem is easy. The converse is likely not to be true. The Rabin cryptosystem Alice performs the following steps ï Choose ð, ð large primes with |ð| = |ð|. ï Compute ð = ðð. ï Pick a random integer ð ï Make (ð, ð) public key, keep (ð, ð) as private key. ∗ ð ð ð The Rabin cryptosystem Encryption Let ð ðð∗ be the confidential message that Bob wants to send to Alice. • • Bob computes the ciphertext: ð Bob sends Alice: ð ð(ð + ð) ððð ð. Decryption To decrypt the ciphertext c Alice solves the quadratic equation: ð2 + ðð – ð 0 (ððð ð), for ð < ð. The Rabin cryptosystem Decryption From elementary arithmetic: ð = −ðïą Δ 2 where ï = ð2 − 4ð (ððð ð). Since m was chosen in ðð∗ , ï must be in QRN . Notice that if ð, ð are such that ð ð ïš 3 (ððð 4), then it is easier to compute square roots modulo N. Remarks • • • Suppose p ïš q ïš 3 (mod 4), n = pq. Let y ïš x2 (mod n). Then: (ïą y ( p ïŦ1) / 4 ) 2 ïš y ( p ïŦ1) / 2 ïš y ( p ï1) / 2 ïī y ïš y (mod p) Because y ( pï1) / 2 ïš 1 (mod p) . Remarks (continued) • It follows that: ïą y ( pïŦ1) / 4 (mod p) • • • is a square root of y modulo p. A similar argument applies for the other prime q. So we get the quadratic residues modulo p and modulo q. We then get the quadratic residue modulo n by using the Chinese Remainder Theorem. Example Suppose n = 77. Then e(x) = x 2 mod 77 d(y) = y mod 77 Suppose Bob wants to decrypt y = 23 ïą 23 ( 7 ïŦ1) / 4 ïš ïą2 ïš ïą4 mod 7 2 ïą 23(11ïŦ1) / 4 ïš ïą13 ïš ïą1 mod 11 Example, continued Using the Chinese Remainder Theorem we compute the 4 square roots of 23 modulo 77 to be: 10 mod 77, 67 mod 77 and 45 mod 77, 32 mod 77 The Rabin Problem • INPUT – N = pq with p,q prime numbers. – y = x 2 mod N, x ï ðð∗ • OUTPUT – z ï ðð∗ such that z = x 2 mod N. Security of Rabin 1. Relation to factoring. Recovering the plaintext ð from a Rabin ciphertext ð is easy if the IF problem is easy. 3. Relation between factoring and the Rabin problem • • Under eavesdropping attacks the Rabin system is secure iff the IF problem is hard. Under CCA attacks the Rabin problem is completely insecure. Security of Rabin Under CCA attacks the Rabin system is completely insecure. Proof: We show this for the case when ð = 0. The adversary picks an ð and computes ð = ð2 ððð ð Then he gets its decryption ð′. This is one of the 4 square roots of ð, and with probability ½, gcd ð′ ïąð, ð = ð or q. Then the adversary can decrypt any ciphertext. The ELGamal cryptosystem Alice performs the following steps ï Choose a large random primes p. ï Compute a random multiplicative generator g ï ðð∗ ï Pick x ï ðð−1 as private key ï Compute the public key y ï gx mod p. ï Make (p,g,y) public key, and keep (p,x) as private key. The ElGamal cryptosystem Encryption Let m < p be the confidential message that Bob wants to send to Alice. Bob picks k ï ðð−1 and computes the ciphertext (c1, c2) • c1 = gk mod p • c2 = yk m mod p Decryption To decrypt the ciphertext (c1, c2) Alice computes ð2 ð ≡ ðĨ (mod p). (ð1 ) The ElGamal cryptosystem Check: ð2 /(ð1 )ðĨ ≡ ðĶ ð ð/(ðð )ðĨ ≡ ðĶ ð ð/ðĶ ð ≡ ð ððð ð . Example Use p = 43, g =3, m = 14, x = 7, y = 37. Alice’s private key: x = 7 Alice’s public key: (p,g,y) = (43,3,37). Encryption with k = 26: • c1 = gk mod p = 326 mod 43 = 15. • c2 = yk m mod p = 3726 ×14 mod 43 = 31. Decryption: m ≡ c2/c1x (mod p) ≡ 31/157 (mod 43) = 14 . Security of ElGamal Relation to the DL Recovering the plaintext m from an ElGamal ciphertext c is easy if the DL problem is easy. 1. 2. ELGamal and the CDH problem For messages that are uniformly distributed, the ElGamal encryption system is secure against CPAs iff the CDA problem is hard. Security of ElGamal For messages that are uniformly distributed, the ElGamal encryption system is secure against CPAs iff the CDH problem is hard. Security of ElGamal Proof: Suppose there exists a PPT algorithm that breaks ElGamal with non negligible probability ïĨ > 0. Then since m = c2/c1x (mod p) can be computed, c2/m ≡ g (logg c1 logg y) (mod p) can also be computed. For an arbitrary CDH instance (p,g,g1,g2), take (p,g,g1) as the ElGamal public key and (c1=g2, c2) as ciphertext. Then the algorithm outputs c2/m = g (logg g2 logg g1) (mod p) which is a solution for the CDH instance.