Lecture Notes on RSA Cryptosystem and Chinese Remainder Theorem
Assignment Updates
- Assignment 3 grades are posted with comments available for review.
- Assignment 4 is due today.
- Assignment 5, focusing on the RSA cryptosystem's programming aspect, will be released today and will have undergraduate and graduate versions.
RSA Cryptosystem Recap
- Lectures covered:
- Introduction to public-key cryptosystems.
- Mathematical preliminaries.
- RSA cryptosystem description and correctness proof.
- The correctness proof had a minor issue that needs correction.
RSA Implementation Guidelines
- Use integer arithmetic exclusively. Avoid floating-point or real number arithmetic.
- Implement algorithms taught in the course yourself without using library functions.
RSA Key Generation Algorithm
- Bob selects two large prime numbers, p and q.
- Bob computes n=p×q.
- Bob computes ϕ(n)=(p−1)(q−1).
- Bob picks an integer b in Z<em>ϕ(n) such that gcd(b,ϕ(n))=1. This means b has an inverse in Z</em>ϕ(n).
- Bob computes the inverse of b mod ϕ(n).
- Public Key: (n,b)
- Private Key: Factorization of n into (p,q) and the decryption exponent a.
Encryption and Decryption Functions
- Encryption: E(x)=xbmodn, where x is the plaintext.
- Decryption: D(y)=yamodn, where y is the ciphertext.
- Both encryption and decryption involve modular exponentiation.
Toy Example of RSA
- p=7, q=11
- n=7×11=77
- ϕ(n)=(7−1)(11−1)=6×10=60
- Pick b=13 in Z60
- Check if 13 has an inverse in Z60 by computing gcd(13,60).
- gcd(13,60)=1
- Compute a, the inverse of b (13) mod 60, using the extended Euclidean algorithm. a=37
Public and Private Keys (Toy Example)
- Public Key: (77,13)
- Private Key: (7,11,37)
Plaintext and Ciphertext Space
Encryption Example with Small Numbers
- Plaintext x=15
- Encryption: 1513mod77
Modular Exponentiation Problem
- Direct computation of x13 requires 12 multiplications, which is inefficient.
Square and Multiply Algorithm (Russian Peasant Algorithm)
- Efficient method for modular exponentiation.
- Write the exponent in binary.
Example: Computing 1513mod77
- Binary representation of 13: 1101 (i.e., 13=8+4+1)
- Compute x2,x4,x8 through repeated squaring.
- x=15
- x2=152=225≡71mod77
- x4=712=5041≡36mod77
- x8=362=1296≡64mod77
- x13=x8×x4×x1=64×36×15≡64mod77
Decryption Example
- Ciphertext y=64
- Compute 6437mod77.
- Binary representation of 37: 100101 (i.e., 37=32+4+1)
- Compute successive powers of y.
- y=64
- y2=642≡15mod77
- y4=152≡71mod77
- y8=712≡36mod77
- y16=362≡64mod77
- y32=642≡15mod77
- y37=y32×y4×y1=15×71×64≡15mod77
- Goal: Compute xbmodn
- Write b in binary as b=b<em>l−1b</em>l−2…b0 (L bits).
- Initialize accumulator z=1.
- For i=l−1 down to 0:
- z=z2modn
- If bi=1, then z=z×xmodn
- Output z.
Complexity Analysis
- Naive method requires b−1 modular multiplications.
- Square and multiply requires O(l) multiplications.
- Significant improvement as l is proportional to log2(b).
Bit-Level Complexity
- Let k=⌊logn⌋+1 be the number of bits needed to represent any number in Zn.
- Addition/Subtraction: O(k)
- Multiplication: O(k2)
- Exponentiation: O(k3)
- RSA encryption and decryption can be performed in cubic time.
Practical Considerations
- RSA is slower than private key cryptosystems like DES.
- RSA may be 1,700 times slower than DES.
- Hybrid encryption is used in practice.
Hybrid Encryption
- Use both public key and private key cryptosystems.
- Alice wants to send message X to Bob.
- Bob's public key: kBob
- Bob's private key: kBob′
- Alice encrypts X using DES with key K: Y=DESK(X).
- Alice encrypts DES key K using Bob's public key: Z=E<em>k</em>Bob(KDES).
- Alice sends Y and Z to Bob.
- Bob decrypts Z using his private key to obtain DES key K: K<em>DES=D</em>kBob′(Z).
- Bob decrypts Y using DES with key K to obtain X: X=DESK−1(Y).
Correctness of RSA Cryptosystem and Chinese Remainder Theorem (CRT)
- Need to show that encryption followed by decryption yields the original message.
- RSA's plaintext space is Z<em>n, not just Z</em>n∗.
- Chinese Remainder Theorem is used to prove the correctness of RSA.
Chinese Remainder Theorem (CRT)
- Let m<em>1,m</em>2,…,mr be pairwise relatively prime numbers.
- Let M=m<em>1×m</em>2×…×mr.
- CRT states that there is a unique solution to the following system of congruences modulo M:
- x≡a<em>1modm</em>1
- x≡a<em>2modm</em>2
- ⋮
- x≡a<em>rmodm</em>r
Proof of Chinese Remainder Theorem (by Construction)
- Define M<em>i=M/m</em>i (product of all m's except mi).
- gcd(M<em>i,m</em>i)=1.
- Therefore, M<em>i has an inverse y</em>i in Z<em>m</em>i.
- x=∑<em>i=1ra</em>iM<em>iy</em>i is a solution to the system of congruences.
- To show this, consider the equation modulo mj:
- All terms except a<em>jM</em>jy<em>j vanish because they have m</em>j as a factor.
- Since M<em>jy</em>j≡1modm<em>j, we have x≡a</em>jmodmj.
Uniqueness of Solution
- Suppose X and Y are both solutions.
- Then x≡a<em>imodm</em>i and y≡a<em>imodm</em>i for all i.
- Therefore, x≡ymodmi for all i.
- This implies x−y≡0modmi for all i.
- Thus, mi divides x−y for all i.
- Since the m<em>i are pairwise relatively prime, M=m</em>1×m<em>2×…×m</em>r divides x−y.
- This means x≡ymodM, so the solution is unique up to modulo M.