Public-Key Cryptography
Symmetric vs. Asymmetric
Symmetric (Private Key):
- Same key for encryption and decryption
- Key must be shared secretly
- Fast but key distribution is hard
Asymmetric (Public Key):
- Different keys: public (encrypt) and private (decrypt)
- Public key can be shared openly
- RSA is the most famous example
RSA Algorithm
Key Generation
- Choose two large distinct primes and
- Compute (the modulus)
- Compute
- Choose with and
- Compute
Public key: Private key:
Encryption
To encrypt message (as integer, ):
Decryption
To decrypt ciphertext :
Why It Works
Since :
By Euler's theorem (if ):
Example
Key Generation
- ,
- Choose (coprime to 3120)
Public key: Private key:
Encryption
Message:
Decryption
Security of RSA
Based on Factoring
Security relies on the difficulty of factoring .
If attacker can factor , they can compute and find .
Key Size
- 512-bit: Insecure (can be factored)
- 1024-bit: Weak, not recommended
- 2048-bit: Currently standard
- 4096-bit: High security
Attacks
Factoring attacks: Number Field Sieve, Quadratic Sieve
Side-channel attacks: Timing, power analysis
Small exponent attacks: If is too small and same message sent to multiple recipients
Digital Signatures
RSA can also create digital signatures.
Signing
Sign message with private key:
Verification
Verify signature with public key:
If , signature is valid.
Why It Works
Only the private key holder can create such that .
Practical Considerations
Message Padding
Never encrypt raw messages. Use padding schemes like:
- OAEP (Optimal Asymmetric Encryption Padding)
- PKCS#1
Hybrid Encryption
RSA is slow for large data. In practice:
- Generate random symmetric key
- Encrypt data with (using AES, etc.)
- Encrypt with RSA
Fast Exponentiation
Use square-and-multiply algorithm for .
Chinese Remainder Theorem Speedup
For decryption, compute:
Then combine using CRT. About 4× faster.
Mathematical Prerequisites
Euler's Theorem
when
Extended Euclidean Algorithm
To find
Fast Modular Exponentiation
To compute efficiently
Comparison with Other Systems
| System | Security Basis | Key Size (equivalent to 128-bit symmetric) |
|---|---|---|
| RSA | Factoring | 3072 bits |
| Diffie-Hellman | Discrete log | 3072 bits |
| ECC | Elliptic curve discrete log | 256 bits |
ECC provides same security with smaller keys.