Foundations of Security Week5 Lecture

10920 字
55 分钟
Foundations of Security Week5 Lecture

Lecture Outline#

  1. Review of RSA cryptographic algorithm
  2. Public key and Private key generation in RSA
  3. RSA encryption and decryption process
  4. Introduction to Chosen Ciphertext Attack (CCA) on RSA
  5. Understanding how attackers exploit decryption systems

Learning Outcomes#

By the end of this lecture, students should be able to:

  1. Explain the RSA key generation process
  2. Identify the steps for generating public and private keys
  3. Apply the Extended Euclidean Algorithm to compute the private key
  4. Perform RSA encryption and decryption
  5. Explain the concept of chosen ciphertext attacks on RSA

Key Generation#

1. Select Primes2. Compute nn3. Calculate ϕ(n)\phi(n)4. Choose ee5. Compute dd
Choose two large prime numbers pp and qq. These must be kept secret.Calculate the modulus nn by multiplying p and q. This is part of both keys.Compute Euler’s totient function using the formula (p1)×(q1)(p-1) \times (q-1).Select public exponent ee where 1<e<ϕ(n)1 < e < \phi(n) and gcd(e,ϕ(n))=1\gcd(e, \phi(n)) = 1.Calculate private exponent dd as the modular multiplicative inverse of ee.
p,q=primesp, q = primesn=p×qn = p \times qϕ(n)=(p1)(q1)\phi(n) = (p-1)(q-1)1<e<ϕ(n)1 < e < \phi(n)
gcd(e,ϕ(n))=1\gcd(e, \phi(n)) = 1
(d×e)1modϕ(n)(d × e) \equiv 1 \bmod \phi(n)
Public KeyPrivate Key
(n, e)(n,~ e)
Share freely with anyone
(n, d)(n,~ d)
Keep secret at all times

Public Key Generation#

Public Keys of Alice#

🤵🏼‍♀️
Alice
Sender
💬 Wants to send a message
Alice needs to encrypt her message
so only Bob can read it.
🔑 Needs a key pair
She must generate public and
private keys for encryption.
📤 Shares public key
Her public key can be shared with
anyone, including Bob.
↔️
Secure Channel
End-to-end encryption
🤵🏻
Bob
Receiver
📩 Wants to receive message
Bob needs to decrypt Alice's message
securely.
🔑 Needs a key pair
He must also generate public and
private keys.
🔒 Keeps private key secret
His private key must never be shared
with anyone.

Public Keys of Alice & Bob#

Both parties generate their public keys simultaneously

👩
Alice
1 Select Prime Numbers
PA = 61,
QA = 53
2 Calculate modulus n
nA = PA × QA
= 61 × 53 = 3233
3 Choose Public Exponent e
eA must satisfy:
✓ 1 < eA < φ(nA)
✓ gcd(eA, φ(nA)) = 1
eA = 17
Calculate Euler's Totient Function
φ(nA) = (PA - 1) × (QA - 1)
= (61 - 1) × (53 - 1) = 60 × 52 = 3120
🔑 Alice's Public Key
(nA = 3233, eA = 17)
👨
Bob
1 Select Prime Numbers
PB = 3,
QB = 11
2 Calculate modulus n
nB = PB × QB
= 3 × 11 = 33
3 Choose Public Exponent e
eB must satisfy:
✓ 1 < eB < φ(nB)
✓ gcd(eB, φ(nB)) = 1
eB = 7
Calculate Euler's Totient Function
φ(nB) = (PB - 1) × (QB - 1)
= (3 - 1) × (11 - 1) = 2 × 10 = 20
🔑 Bob's Public Key
(nB = 33, eB = 7)

Public Keys of Alice#

Mathematical constraints for selecting the public exponent e

1
Range Constraint
e must be:
1 < e < φ(n)
Greater than 1
Less than φ(n) (Euler's totient)
Why: Ensures e is in the valid multiplicative group
2
Co-prime Condition
e must be co-prime with φ(n):
gcd(e, φ(n)) = 1
No common factors with φ(n)
Ensures multiplicative inverse exists
Why: Required for the decryption key to exist
3
Modular Inverse
e × d ≡ 1 (mod φ(n))
Must have a multiplicative inverse d
d is the private key
Found using Extended Euclidean Algorithm
Why: Enables encryption/decryption symmetry
Alice's φ(n)
φ(3233) = 3120
Bob's φ(n)
φ(33) = 20
💡
Formula: φ(n) = (p-1) × (q-1)

Private Key of Alice#

👩
Alice
Private Key Calculation
Public Values
nA = 3233
eA = 17
Prime Factors
PA = 61
QA = 53
Calculate Euler's Totient Function
φ(nA) = (PA - 1) × (QA - 1)
= (61 - 1) × (53 - 1) = 60 × 52 = 3120
Private Key
dA = 2753
Step-by-Step Calculation
1
Set Up the Congruence Equation
Find dA such that:
eA × dA ≡ 1 (mod φ(nA))
17 × dA ≡ 1 (mod 3120)
2
Apply Extended Euclidean Algorithm
3120 = 17(183) + 9
17 = 9(1) + 8
9 = 8(1) + 1
8 = 1(8) + 0
Working backwards to find the inverse...
1 = 9 + 8(-1)
1 = 9 + [17 + 9(-1) ] (-1)
1 = 9 + 17 (-1) + 9(1)
1 = 17 (-1) + 9(2)
1 = 17 (-1) + [3120 + 17(-183)](2)
1 = 17 (-1) + [3120(2) + 17(-366)]
1 = 17 (-1) + 3120(2) + 17(-366)
1 = 17 (-367) + 3120(2)
3120 + (-367) = 2753
3
Solution: Private Key
dA = 2753
Verification: 17 (2753) = 46801 mod 3120 = 3120(15) + 1  mod 3120
🔒
Alice's Private Key: dₐ = 2753 (Keep Secret!)
🔑 Used for decrypting messages

Private Key of Bob#

👨
Bob
Private Key Calculation
Public Values
nB = 33
eB = 7
Prime Factors
PB = 3
QB = 11
Calculate Euler's Totient Function
φ(nB) = (PB - 1) × (QB - 1)
= (3 - 1) × (11 - 1) = 2 × 10 = 20
Private Key
dB = 3
Step-by-Step Calculation
1
Set Up the Congruence Equation
Find dB such that:
eB × dB ≡ 1 (mod φ(nB))
7 × dB ≡ 1 (mod 20)
2
Apply Extended Euclidean Algorithm
20 = 7(2) + 6
7 = 6(1) + 1
6 = 1(6) + 0
Working backwards to find the inverse...
1 = 7 + 6(-1)
1 = 7 + [20 + 7(-2) ] (-1)
1 = 7 + [20(-1) + 7(2)]
1 = 7(3) + 20(-1)
3
Solution: Private Key
dB = 3
Verification: 7 (3) = 21 mod 20 = 1 mod 20
🔒
Bob's Private Key: dB = 3 (Keep Secret!)
🔑 Used for decrypting messages

Key Pairs Summary#

👩
Alice
🔓 Public Key SHARE
Modulus n 3233
Exponent e 17
🔒 Private Key SECRET
Exponent d 2753
Prime Factors (Secret)
p
61
q
53
👨
Bob
🔓 Public Key SHARE
Modulus n 33
Exponent e 7
🔒 Private Key SECRET
Exponent d 3
Prime Factors (Secret)
p
3
q
11

RSA Encryption & Decryption#

With their key pairs generated, Alice and Bob can now securely exchange encrypted messages. The foundation of RSA encryption is established.

👩
👨
✈️
Alice Encrypts
Using Bob's public key
↔️
Secure Transfer
Encrypted message sent
🔒
Bob Decrypts
Using his private key

Encryption & Decryption#

Encryption and Decryption Process#

🔒
Encryption
The sender uses the recipient's public key (n, e) to encrypt
the plaintext message M into ciphertext C.
Formula:
C = Me mod n
C
Ciphertext (encrypted message)
M
Plaintext message (as number)
e
Public exponent
n
Modulus (part of public key)
🔓
Decryption
The recipient uses their private key (n, d) to decrypt the
ciphertext C back into the original plaintext message M.
Formula:
M = Cd mod n
M
Recovered plaintext message
C
Ciphertext (encrypted message)
d
Private exponent (secret)
n
Modulus (same as public key)
Security Guarantee

Only the holder of the private key d can decrypt the message. Even if an attacker knows the public key (n, e) and intercepts the ciphertext C, they cannot compute d without factoring n into p and q — a computationally infeasible task for large keys.

Encryption and Decryption Process#

👤Alice's Keys
Public Key:
nA = 3233, eA = 17
Private Key:
dA = 2753
👤Bob's Keys
Public Key:
nB = 33, eB = 7
Private Key:
dB = 3
✉️Message to Send
M = 2
🔒Step 1: Encryption (Alice)
Alice uses Bob's public key to encrypt the message:
C = MeB mod nB
C = 27 mod 33

= 128 mod 33
= 29 mod 33
Ciphertext
C = 29
🔓Step 2: Decryption (Bob)
Bob uses his private key to decrypt:
M = CdB mod nB
M = 293 mod 33
= 24389 mod 33
= 2 mod 33
Recovered Message
M = 2

Quiz#

👤Alice's Keys
Public Key:
nA = 3233, eA = 17
Private Key:
dA = 2753
👤Bob's Keys
Public Key:
nB = 33, eB = 7
Private Key:
dB = 3
✉️Message to Send
M = 5
🔒Step 1: Encryption (Alice)
Alice uses Bob's public key to encrypt the message:
C = MeB mod nB
C = 57 mod 33
= 78125 mod 33
= 14 mod 33
Ciphertext
C = 14
🔓Step 2: Decryption (Bob)
Bob uses his private key to decrypt:
M = CdB mod nB
M = 143 mod 33
= 2744 mod 33
= 5 mod 33
Recovered Message
M = 5

Chosen Ciphertext Attacks (CCA) on RSA Algorithm#

The Chosen Ciphertext Attack (CCA) on the RSA algorithm is a type of cryptographic attack where the attacker uses the decryption capabilities of a system/users to decrypt messages by choosing a series of ciphertexts and using the results to deduce the plaintext or the encryption key.

Chosen Ciphertext Attack on RSA#

Normal RSA Communication Flow

👩
Alice
Sender
Has Bob's Public Key:
(eB, nB)
Message M
2
Encryption
C = MeB mod nB
Ciphertext C
29
☁️ Public Channel (Encrypted)
👨
Bob
Receiver
Has Private Key:
(dB, nB)
1
Encryption
Alice uses Bob's public key to encrypt
message M:
C = 27 mod 33 = 29
2
Transmission
Ciphertext C travels through the public channel.
Even if intercepted, it's unreadable without the
private key.
3
Decryption
Bob uses his private key to decrypt:
M = 293 mod 33 = 2

Public Keys of Alice#

👩
Alice
Sender
Key Generation
PA = 61, QA = 53
nA = 3233
φ(nA) = 3120
eA = 17
dA = 2753
Has Access To
🔑 Own keys
🌍 Bob's public key
Message to Send
M = 2
👤
Attacker
Adversary
Capabilities
👁️ Intercepts all traffic
📝 Modifies messages
🔑 Knows public keys
Attack Parameters
Chooses: r = 2
(coprime to nB = 33)
Goal
Recover M without dB
👨
Bob
Receiver
Key Generation
PB = 3, QB = 11
nB = 33
φ(nB) = 20
eB = 7
dB = 3
Has Access To
🔑 Own private key
🔓 Alice's public key
Receives
C' = 16
(not the original C)
Attack Setup

Alice wants to send message M=2 to Bob. The attacker intercepts the communication and substitutes ciphertext C with manipulated C’

Chosen Ciphertext Attack on RSA#



Attacker
Intercepts C
Alice's Public
(nA, eA)
Bob's Public
(nB, eB)
🔒 Step 2: Attacker computes fake message C'
Chooses random: r = 2 (coprime with nB(33) so it has an inverse)
Compute: C' = (C × reB mod nB)
        = 29 × 27 mod 33
        = 16 mod 33
Sends C' to Bob to decrypt:
C' = 16
🔒 Step 4: Attacker computes inverse to retrieve original message
Attacker knows: ResM' = 4 = C'dBmod nB
                  = (C×reB)dBmod nB
Deduce: M' = (MeB×reB)dBmod nB
         = (MeB×dBmod nB)×(reB×dBmod nB) = M1×r1
Compute inverse of r to get M: M1 × r1 (r-1)

Inverse: 2 (r-1) ≡ 1 mod nB
        = r-1 = 17
Retrieve M: Res × 17 mod nB
        = 4 × 17 mod 33
        = 68 mod 33
        = 2

1
Alice Encrypts
Alice encrypts M=2 using Bob's public key (eB=7, nB=33):
C = MeB mod nB
C = 27 mod 33 = 29
2
Attacker Intercepts
Attacker captures C=29 and chooses r=2 (coprime to 33):
C' = (C × reB) mod nB
C' = (29 × 27) mod 33
C' = (29 × 128) mod 33 = 16
3
Attacker Sends C'
Attacker forwards C' = 16 to Bob instead of the original C = 29
4
Bob Decrypts C'
Bob decrypts using his private key (dB=3, nB=33):
Res = C'dB mod nB
Res = 163 mod 33 = 4
5
Bob Sends Result
Bob sends Res=4 back (thinking it's related to the original message):
Res = 4
6
Attacker Recovers M
Attacker computes r-1 mod 33 = 17 using Extended Euclidean Algorithm:
M = Res × r-1 mod nB
M = 4 × 17 mod 33
M = 2 ✓
Original Message
M = 2
Attacker Recovered
M = 2
Attack Successful!

Assignment#

Assignment: Complete this exercise and submit during seminar class

Alice’s Public key: 𝑛𝐴=3233\textcolor{red}{𝑛_𝐴 = 3233} and 𝑒𝐴=17\textcolor{red}{𝑒_𝐴=17}
Alice’s Private key: 𝑑𝐴=2753\textcolor{blue}{𝑑_𝐴} = 2753
Bob’s Public key: 𝑛B=33\textcolor{red}{𝑛_B = 33} and 𝑒B=7\textcolor{red}{𝑒_B = 7}
Bob’s Private key: 𝑑B=3\textcolor{blue}{𝑑_B} = 3

Task:
If Alice wants to send the message 𝑀=5\textcolor{blue}{𝑀 = 5} to Bob, perform the chosen ciphertext attack and retrieve the original message if the attacker chooses random number r=2\textcolor{blue}{r = 2}. Show the following:
Modified Ciphertext (C′): _____________
Bob’s Response: _____________
Attacker’s Recover Process: _____________

Show how you computed your answers.
Only handwritten solutions.
No copy-paste will be accepted.

Security Strength & Key Sizes#

📏 NIST Recommendations for RSA Key Sizes
2048-bit RSA
Security: ~112 bits | Status: Acceptable until 2030
Current Standard
3072-bit RSA
Security: ~128 bits | Status: For beyond 2030
Recommended
4096-bit RSA
Security: Higher | Use: Long-term protection, root CAs
Maximum Security
🛡️ Security Foundation
RSA's security relies on the computational difficulty of factoring
large numbers
Easy: Multiply two 1024-bit primes
Hard: Factor the 2048-bit product
Time: Billions of years with classical computers
Quantum Computing Threat
RSA is vulnerable to Shor's algorithm, which can factor large numbers
efficiently on a quantum computer. Current estimates:
⚠️ Key Security Principles
Keep private keys absolutely secret
Use minimum 2048-bit keys
Rotate keys periodically
Use secure padding schemes (OAEP)

Applications#

🌐
HTTPS/SSL/TLS
RSA is used in X.509 certificates to secure web
browsing. When you see the padlock icon, RSA
is likely protecting your connection.
Usage: 90%+ of websites
ᝰ.
Digital Signatures
RSA provides authentication and
non-repudiation. Signers cannot deny their
signatures, and recipients can verify authenticity.
Usage: Code signing, document signing
✉️
Email Encryption
Protocols like S/MIME and PGP use RSA to
encrypt emails, ensuring only intended
recipients can read them.
Usage: Secure corporate email
🔄
Secure File Transfer
SFTP, FTPS, and VPNs use RSA for key
exchange and authentication, protecting data
in transit.
Usage: Enterprise file sharing
</>
Software Signing
Developers digitally sign software to prove
authenticity and integrity. Users can verify
software hasn't been tampered with.
Usage: OS updates, app stores
💡
Hybrid Approach
RSA is computationally intensive.
In practice, RSA encrypts symmetric keys
(like AES)
, which then encrypt large data
efficiently.
Benefit: Best of both worlds
INFO

This week dose have seminar class, which theme is phishing, but teacher didn’t provide seminar material, so no separate seminar article this week.

支持与分享

如果这篇文章对你有帮助,欢迎分享给更多人或赞助支持!

赞助
Foundations of Security Week5 Lecture
https://firefly.anka2.top/posts/obu/level5/semester2/fos/week5/lecture/
作者
🐦‍🔥不死鸟Anka
发布于
2026-04-07
许可协议
CC BY-NC-SA 4.0

评论区

Profile Image of the Author
A-n-k-a
Over the Frontier / Into the Front
看这里~
合作翻译官绝赞招募中!
音乐
封面

音乐

暂未播放

0:00 0:00
暂无歌词
分类
标签
站点统计
文章
59
分类
6
标签
20
总字数
550,118
运行时长
0
最后活动
0 天前

目录