Information SecurityUnit 515 min read
Public Key Cryptography: RSA, ECC, Diffie-Hellman, Digital Signatures
Unit 5 of Information Security explores public key cryptography, covering RSA and ECC algorithms, key exchange protocols (Diffie-Hellman), digital signatures, and their applications in secure communication, authentication, and e-commerce.
TAKEAWAYS:
- Public key cryptography uses asymmetric keys (public/private pairs) to enable secure communication without pre-shared secrets.
- RSA and Elliptic Curve Cryptography (ECC) are widely used algorithms for encryption, digital signatures, and key exchange.
- Diffie-Hellman (DH) and its variants (ECDH) enable secure key exchange over insecure channels.
- Digital signatures provide non-repudiation and authentication using private keys and public key verification.
- Public key infrastructure (PKI) manages certificates to bind public keys to identities.
- Real-world applications include HTTPS (TLS/SSL), eSewa transactions, and Ncell digital signatures.
Core Concepts: Asymmetric Keys and Mathematical Foundations
Public key cryptography relies on mathematical problems that are easy to compute in one direction but hard to reverse. Unlike symmetric cryptography (Unit 4), it uses two keys:
- Public key: Shared openly (e.g., posted on a website or embedded in software).
- Private key: Kept secret by the owner.
Why Asymmetric Keys?
- No need to share secrets beforehand (unlike symmetric keys).
- Supports digital signatures (proof of identity and integrity).
- Scalability: One public key can encrypt messages for many recipients.
Mathematical Hard Problems
Public key cryptography is based on these one-way functions:
- Integer Factorization (used in RSA):
- Easy to multiply two large primes, but hard to factor their product.
- Example: , where and are large primes.
- Discrete Logarithm Problem (DLP) (used in Diffie-Hellman and ECC):
- Given , finding is computationally hard.
- Elliptic Curve Discrete Logarithm Problem (ECDLP) (used in ECC):
- Harder than DLP for the same security level, enabling smaller key sizes.
RSA: The Workhorse of Public Key Cryptography
RSA (Rivest-Shamir-Adleman) is the most widely used public key algorithm. It works as follows:
Key Generation
- Choose two large primes and (e.g., 1024+ bits).
- Compute (modulus).
- Compute Euler’s totient function .
- Choose a public exponent (typically 65537) such that and .
- Compute the private exponent as the modular inverse of :
- The public key is , and the private key is .
Encryption and Decryption
- Encryption: (where is the plaintext message).
- Decryption: .
Worked Example: RSA Encryption
Scenario: Ncell wants to securely send a message to a user. The user’s public key is . The message (represented as an integer).
- Encrypt :
- Decrypt using the private key : (In practice, this is computed using efficient algorithms like the square-and-multiply method.)
Real-World Tie-In: Ncell uses RSA to encrypt OTP (One-Time Password) tokens sent to users for authentication. The OTP is encrypted with Ncell’s public key, ensuring only the authorized server (with the private key) can decrypt it.
stateDiagram-v2
[*] --> RSA_KeyGen: Start
RSA_KeyGen --> ChoosePrimes: Pick p, q
ChoosePrimes --> ComputeN: n = p × q
ComputeN --> ComputePhi: φ(n) = (p-1)(q-1)
ComputePhi --> ChooseE: Pick e (gcd(e, φ(n)) = 1)
ChooseE --> ComputeD: d = e⁻¹ mod φ(n)
ComputeD --> PublicKey: (e, n)
ComputeD --> PrivateKey: (d, n)
PublicKey --> [*]
PrivateKey --> [*]Figure 1: RSA Key Generation Process
Elliptic Curve Cryptography (ECC): Smaller Keys, Stronger Security
ECC provides equivalent security to RSA but with smaller key sizes, making it efficient for mobile and IoT devices.
Why ECC?
- 160-bit ECC ≈ 1024-bit RSA in security.
- Faster computations and lower power consumption (critical for Pathao’s ride-hailing app or eSewa’s mobile payments).
- Used in Bitcoin, Signal, and TLS 1.3.
Mathematical Foundation
ECC relies on elliptic curves over finite fields. An elliptic curve is defined by: where .
Key Generation in ECC
- Choose a curve over a finite field .
- Select a base point on with large prime order .
- Choose a private key (a random integer ).
- Compute the public key (scalar multiplication).
Encryption (ElGamal-like)
- Encrypt a message with public key :
- Choose a random .
- Compute .
- Compute , where .
- Ciphertext: .
Digital Signatures (ECDSA)
ECC Digital Signature Algorithm (ECDSA) works similarly to RSA signatures but uses elliptic curve math.
classDiagram
class EllipticCurve {
+y² = x³ + ax + b (mod p)
+Point: (x, y)
}
class PrivateKey {
-d: integer
}
class PublicKey {
-Q = d × G
}
EllipticCurve "1" --> "1" PrivateKey : Defines field
PrivateKey --> PublicKey : Generates
PublicKey --> EllipticCurve : Lies on curveFigure 2: ECC Key Structure
Key Exchange: Diffie-Hellman and ECDH
Diffie-Hellman (DH) enables two parties to establish a shared secret over an insecure channel (e.g., the internet). It is the foundation of TLS/SSL (used in HTTPS) and VPNs.
How DH Works
- Agree on a prime and generator (public parameters).
- Alice picks a private key , computes , and sends to Bob.
- Bob picks a private key , computes , and sends to Alice.
- Both compute the shared secret:
- Alice: .
- Bob: .
Worked Example: DH Key Exchange
Scenario: Daraz wants to securely exchange a session key with a customer over an untrusted network.
- Public parameters: , .
- Alice (Daraz) picks , computes .
- Bob (Customer) picks , computes .
- Shared secret:
- Alice: .
- Bob: .
Real-World Tie-In: When you log into eSewa via HTTPS, your browser and eSewa’s server perform an ECDH (Elliptic Curve Diffie-Hellman) handshake to establish a symmetric session key for encrypting your transaction data. This prevents eavesdroppers from reading your payment details.
sequenceDiagram
participant Alice
participant Bob
participant Eavesdropper
Alice->>Bob: p, g (public)
Alice->>Bob: A = g^a mod p
Bob->>Alice: B = g^b mod p
Alice->>Alice: s = B^a mod p
Bob->>Bob: s = A^b mod p
Note over Alice,Bob: Shared secret s = g^(ab) mod p
Eavesdropper--)Alice: Sees A, B, p, g
Eavesdropper--)Bob: Cannot compute s (DLP hard)Figure 3: Diffie-Hellman Key Exchange
Digital Signatures: Non-Repudiation and Authentication
Digital signatures use public key cryptography to verify the authenticity and integrity of a message. They are used in:
- eSewa receipts (proving you made a payment).
- Ncell SIM registration (proving your identity).
- NEPSE stock trades (preventing fraud).
How Digital Signatures Work (RSA Example)
- Signing:
- Hash the message: .
- Encrypt the hash with the private key: .
- Signature: .
- Verification:
- Decrypt the signature with the public key: .
- Hash the received message: .
- If , the signature is valid.
Worked Example: Signing a NEPSE Trade Order
Scenario: You sign a stock trade order for NEPSE using your private key.
- Message "Buy 100 shares of NEPSE at 1000 NPR".
- Hash : .
- Sign with private key : .
- Send to NEPSE.
- NEPSE verifies using your public key :
- Compute .
- Check if .
Real-World Tie-In: When you submit a Khalti payment request, the merchant’s server verifies your digital signature to ensure the request hasn’t been tampered with and that it truly came from you.
sequenceDiagram
participant Sender
participant Receiver
Sender->>Sender: M = "Trade Order"
Sender->>Sender: h = Hash(M)
Sender->>Sender: σ = h^d mod n (sign)
Sender->>Receiver: (M, σ)
Receiver->>Receiver: h' = σ^e mod n
Receiver->>Receiver: h'' = Hash(M)
alt h' == h'' then
Receiver->>Receiver: Valid signature!
else
Receiver->>Receiver: Invalid or tampered!
endFigure 4: Digital Signature Process
Public Key Infrastructure (PKI): Managing Certificates
PKI is the system that binds public keys to identities using digital certificates. It includes:
- Certificate Authorities (CAs): Trusted entities that issue certificates (e.g., GlobalSign, DigiCert).
- Certificate Revocation Lists (CRL): Lists of invalidated certificates.
- Online Certificate Status Protocol (OCSP): Real-time certificate validation.
How PKI Works
- Certificate Request: A user generates a key pair and sends a Certificate Signing Request (CSR) to a CA.
- Certificate Issuance: The CA verifies the user’s identity and signs the certificate with its private key.
- Certificate Distribution: The CA issues the certificate to the user.
- Validation: Recipients verify the certificate using the CA’s public key.
Example: HTTPS Certificate for Daraz
When you visit Daraz.com, your browser:
- Checks if Daraz’s certificate is valid (not expired, not revoked).
- Verifies the certificate’s signature using the CA’s public key (e.g., Let’s Encrypt).
- Establishes a secure TLS connection using the public key.
erDiagram
CERTIFICATE ||--o{ USER : "Issued to"
CERTIFICATE ||--|| CA : "Issued by"
CA }|--|| TRUST_STORE : "Public key in"
USER ||--|| PUBLIC_KEY : "Owns"
USER ||--|| PRIVATE_KEY : "Owns"
CERTIFICATE {
string serialNumber
string subject
string issuer
date validityPeriod
string publicKey
string signature
}Figure 5: PKI Entity-Relationship Diagram
In the Real World
Public key cryptography is everywhere in Nepal’s digital economy. Here’s how it’s used:
eSewa and Khalti Payments:
- What it uses: RSA for encrypting payment details and ECDSA for digital signatures.
- How it works: When you pay via eSewa, your device generates an ephemeral ECDH key pair to establish a secure session with eSewa’s server. Your payment request is signed with your private key, and eSewa verifies it using your public key (stored in their PKI).
Ncell Digital Identity:
- What it uses: X.509 certificates (PKI) for authenticating SIM registrations.
- How it works: When you register a SIM, Ncell’s server issues you a digital certificate binding your identity to a public key. This certificate is used to sign all subsequent transactions (e.g., mobile money transfers).
NEPSE Secure Trading:
- What it uses: RSA and ECC for encrypting trade orders and digital signatures.
- How it works: Before you can trade stocks, you must register with NEPSE using a digital signature. Your trade orders are signed with your private key, and NEPSE verifies them using your public key to prevent fraud.
Pathao Driver-Verification:
- What it uses: TLS (which relies on DH/ECDH for key exchange and RSA/ECC for signatures).
- How it works: When a Pathao driver’s app connects to the server, they perform an ECDH handshake to establish a secure channel. The app’s identity is verified using a certificate issued by a CA.
Bank Internet Banking (e.g., NMB, Global IME):
- What it uses: PKI for user authentication and TLS for secure communication.
- How it works: When you log into your bank’s website, your browser presents a client certificate (stored on your token or smartphone) to prove your identity. The bank’s server verifies this certificate before allowing access.
Advantages and Disadvantages of Public Key Cryptography
| Advantages | Disadvantages |
|---|---|
| No need to share secrets beforehand. | Computationally slower than symmetric crypto. |
| Supports digital signatures. | Key management is complex (PKI required). |
| Scalable for large systems (e.g., internet). | Larger key sizes (though ECC mitigates this). |
| Provides non-repudiation. | Vulnerable to quantum attacks (Shor’s algorithm). |
Common Attacks on Public Key Cryptography
Understanding attacks helps in securing implementations:
Man-in-the-Middle (MITM) Attacks:
- Eavesdropper intercepts key exchange (e.g., DH) and impersonates both parties.
- Mitigation: Use authenticated DH (e.g., Signal Protocol) or certificates.
Brute Force Attacks:
- Trying all possible private keys (e.g., guessing in RSA).
- Mitigation: Use sufficiently large keys (e.g., 2048-bit RSA or 256-bit ECC).
Side-Channel Attacks:
- Exploiting implementation flaws (e.g., timing attacks on RSA decryption).
- Mitigation: Use constant-time algorithms and blinding techniques.
Quantum Attacks:
- Shor’s algorithm can break RSA and ECDH in polynomial time on a quantum computer.
- Mitigation: Research post-quantum cryptography (e.g., lattice-based schemes).
Exam Tip
This unit is heavily tested in TU exams, especially on:
RSA/ECC Math: Be able to derive keys, encrypt/decrypt small messages, and explain the math behind them.
- Example Question: "Given , compute the private key ."
- Solution: Compute , , then find such that . Use the Extended Euclidean Algorithm.
Diffie-Hellman Workings: Trace the key exchange step-by-step and compute shared secrets.
- Example Question: "Alice and Bob use . Alice picks , Bob picks . What is their shared secret?"
- Solution: , . Shared secret .
Digital Signatures: Explain how hashing + private key signing works, and how verification uses the public key.
- Example Question: "How does ECDSA prevent repudiation?"
- Answer: Only the private key holder can create a valid signature. The public key can verify it, proving the signer’s identity.
PKI and Certificates: Know the roles of CAs, CSRs, and how certificates are validated.
- Example Question: "What is the purpose of a Certificate Revocation List (CRL)?"
- Answer: To list certificates that should no longer be trusted (e.g., compromised or expired keys).
Real-World Applications: Relate concepts to eSewa, Ncell, NEPSE, or Pathao.
- Example Question: "How does Khalti use public key cryptography to secure payments?"
- Answer: Khalti uses TLS (with ECDH for key exchange and ECDSA for signatures) to encrypt transactions and authenticate users.
Final Checklist for Full Marks
- Explain the mathematical hardness behind RSA and ECC.
- Derive RSA keys from primes and compute encryption/decryption.
- Trace a Diffie-Hellman key exchange and compute shared secrets.
- Describe digital signatures and their role in non-repudiation.
- Draw a PKI diagram showing CAs, users, and certificates.
- Link concepts to Nepali examples (eSewa, Ncell, NEPSE, Pathao).
- Discuss attacks (MITM, brute force, quantum) and mitigations.
Based on the TU BIM syllabus for Information Security (IT244), unit 5.
Discussion
Loading…