ch09 Public Key Encryption
ch09 Public Key Encryption
Information Security
Nguyễn Đăng Quang
Fall 2022
Goals
• Modular Arithmetic,
• RSA Encryption,
• Discrete logarithm
• Diffie - Hellman
Introduction to Modular Arithmetic
• Modulo
Subtraction
Multiplication
Exponentiation
𝑎𝜑(𝑛) ≡ 1 (𝑚𝑜𝑑 𝑛)
Example:
3 * 0 ≡ 0 (mod 7)
3 * 1 ≡ 3 (mod 7)
3 * 2 ≡ 6 (mod 7)
3 * 3 ≡ 9 ≡ 2 (mod 7)
3 * 4 ≡ 12 ≡ 5 (mod 7)
3 * 5 ≡ 15 (mod 7) ≡ 1 (mod 7) <------ FOUND INVERSE!
3 * 6 ≡ 18 (mod 7) ≡ 4 (mod 7)
RSA
• Named after its inventors (Rivest, Shamir, Adleman).
• RSA is the most widely used public key algorithm, supports both public key
encryption and digital signature.
• The security strength of RSA is based on the hypothesis that, factoring a very large
number into two primes is a very hard problem.
Encryption, Decryption, and key
generation in RSA
RSA Algorithm
• Select two prime numbers, p and q
• Determine d such that de ≡ 1 (mod 160) and d 6 160. The correct value is d = 23,
because 23 * 7 = 161 = (1 * 160) + 1;
2. Compute n = ?
3. Compute (n) = ?
4. Assume e = 7, compute d = ?
View the Private key: openssl rsa –in private.pem –noout –text
Extract the Public key: openssl rsa –in private.pem –pubout > public.pem
View: openssl rsa –in public.pem –pubin –text
key Plaintext
Recipient’s
Public key
RSA AES
Signer’s
Private
Key Hashing
Data function
Equal?
Data
Hash
Code
Signer’s
Public
Key
Digital signature with Openssl
• Generating hash
openssl sha256 –binary msg.txt > msg.sha256
• Signing and Verifying
Signing:
openssl rsautl –sign –inkey private.pem –in msg.sha256 –out msg.sig
Verify the signature:
openssl rsautl –verify –inkey public.pem –in msg.sig –pubin –raw |xxd
Other applications
Public-key based Authentication
A B
Challenge R
A’s private key A’s public key
Symmetric-key encryption
Credit Cards
Card Authentication
Card’s
preloaded
public key
Card’s public key
certificate signed public key certificate
by issuer
preloaded Verify the certificate
Card’s private
key
Signature
Signature Verify the signature
Transaction Authentication
Card’s private
Card’s public key
key
Signature
Signature Verify the signature
Diffie-Hellman Key Exchange
• First published public-key algorithm.
• By Diffie and Hellman in 1976 along with the public key concepts.
• Practical method to exchange a secret key securely that can be used for subsequent
encryption messages.
• These two numbers do not need to be confidential. They can be sent publicly
through the Internet;
Key Exchange protocol steps
1. Alice chooses a large random number x (0 ≤ x ≤ p − 1) and calculates R1 = gx mod p.
5. Alice calculates K = (R2) x mod p. Bob also calculates K = (R1) y mod p. K is the
symmetric key for the session
Alice: (R2)x mod p = (gy mod p) x mod p = (gy) x mod p = KA
KA=KB
Bob: (R1)y mod p= (gx mod p)y mod p = (gx)y mod p = KB
Symmetric-Key Agreement
Diffie-Hellman Key Agreement
Turn DH to public-key encryption
1. Alice & Bob agree on g,p
3. Bob computes (gx mod p)y mod p = gxy mod p which is the common key to decrypt