Foundations of Security Week7 Lecture

2155 字
11 分钟
Foundations of Security Week7 Lecture

Lecture Outline#

  1. Limitations of symmetric key encryption
  2. Introduction to Diffie–Hellman key exchange
  3. Introduction to ElGamal encryption
  4. Key generation, encryption and decryption process of ElGamal
  5. Introduction to Digital signature and RSA signature
  6. Structure of the Feistel cipher

Learning Outcomes#

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

  1. Explain the key distribution problem in symmetric encryption
  2. Describe the purpose of the Diffie–Hellman key exchange
  3. Explain how two parties establish a shared secret using Diffie–Hellman
  4. Apply ElGamal encryption through practical examples
  5. Understand Digital Signature and How the RSA signature works
  6. Describe the structure and working principle of the Feistel cipher

Symmetric Key Encryption#

Symmetric Key Encryption is a cryptographic method where the same key is used for both encryption and decryption.

In this system, both the sender and the receiver share a secret key, and they use it to transform plaintext (original message) into ciphertext (encrypted message) and vice versa.

Problem with the Symmetric Key Encryption#

Symmetric Key Encryption#

Problem with the Symmetric Key Encryption#

  1. Transmission of secret key over a public channel is vulnerable to attacks.
  2. Attacker can intercept both the shared secret key (K) and ciphertext during transmission.
  3. If the secret key is compromised, all communication using that key is at risk.

Diffie-Hellman Key Exchange#

  • The Diffie–Hellman key exchange is a method for securely exchanging cryptographic keys over a public channel. It allows two parties to each generate a shared secret key without directly transmitting it over the network.
  • Introduced in 1976 by Whitfield Diffie and Martin Hellman.
  • It was the first practical method for establishing a shared secret over an unprotected communications channel.
  • It allows two parties who have never met before to securely establish a shared key, which can then be used to secure their communication.
  • It enables secure key exchange without transmitting the actual secret key

How it works#

Reading Assignment#

How to find a generator/primitive root#

Example#

Quiz#

Alice’s secret key: SA=3\textcolor{blue}{S_A} \mathbf{= 3}Bob’s secret key: SB=4\textcolor{blue}{S_B} \mathbf{= 4}

Task:

Users A and B are using the Diffie-Hellman key exchange method with a common prime P=11\textcolor{blue}{P=11} and a generator g=2\textcolor{blue}{g=2}. User A chooses her secret key SA=3\textcolor{blue}{S_A} \mathbf{= 3} and computes her public value CA=8\textcolor{blue}{C_A}\mathbf{=8}, which she sends to User B through the public channel. User B selects his secret key SB=4\textcolor{blue}{S_B}\mathbf{=4} and computes his public value CB=5\textcolor{blue}{C_B}\mathbf{=5}, which he sends to User A through the public channel. What is the common secret key shared between User A and User B?

ElGamal Encryption#

The ElGamal Encryption Algorithm is a public-key cryptosystem based on the difficulty of the discrete logarithm problem. It was developed by Taher ElGamal in 1985 and is used for secure data transmission.

Key Generation#

  1. Choose a large prime number, p\textcolor{blue}p.
  2. Select a generator (gg): Pick a number g\textcolor{blue}g (where 1<g<p11 < g < p−1) that is a generator/primitive root modulo pp. This ensures gg can generate all numbers from 11 to p1p−1 when raised to different powers.
  3. Pick a private key, x\textcolor{blue}x: Choose a random integer 𝑥 (where 1xp21 \leqslant x \leqslant p−2) as the private key.
  4. Compute the public key y\textcolor{blue}y: Calculate y=gxmodp\textcolor{blue}{y = g^x \bmod p}. The public key is the triplet (p,g,y\textcolor{red}{p,g,y}), while x\textcolor{red}x remains secret.

Encryption#

To encrypt a message m\textcolor{blue}m (where 0m<p0 \leqslant m < p):

  1. Obtain the recipient’s public key: Use their (p,g,y\textcolor{blue}{p,g,y})
  2. Choose a random number k\textcolor{blue}k: Select a random integer kk (where 1kp21 \leqslant k \leqslant p−2). This is the session key and should be unique for each encryption.
  3. Compute the ciphertext pair:
  4. c1=gkmodp\textcolor{blue}{c_1 = g^k \bmod p} (this hides 𝑘 and is sent as part of the ciphertext).
  5. c2=mykmodp\textcolor{blue}{c_2 = m \cdot y^k \bmod p} (this encrypts the message using the recipient’s public key).
  6. Send the ciphertext: The encrypted message is the pair (c1,c2\textcolor{blue}{c_1,c_2}).

Decryption#

To decrypt the ciphertext (c1,c2\textcolor{blue}{c_1,c_2}) using the private key xx:

  1. Compute the shared secret: Calculate s=c1xmodp\textcolor{blue}{s= c_1^x} \bmod p. Since c1=gk\textcolor{blue}{c_1=g^k}, this becomes s=(gk)x=gkxmodp\textcolor{blue}{s=(g^k)^x=g^{kx} \bmod p}.
  2. Find the modular inverse of ss: Compute s1modp\textcolor{blue}{s^{−1} \bmod p} (the number such that ss11modp\textcolor{red}{s \cdot s^{−1} \equiv 1 \bmod p}).
  3. Recover the message: Calculate m=c2s1modp\textcolor{blue}{m = c_2 \cdot s^{−1} \bmod p}.

Why it works:
c2=myk=m(gx)k=mgkx\textcolor{blue}{c_2} = m \cdot y^k = m \cdot \textcolor{blue}{(g^x)^k} = m \cdot \textcolor{blue}{g^{kx}}, so
c2s1=(mgkx)(gkx)1=m\textcolor{blue}{c_2} \cdot \textcolor{blue}{s^{−1}} = (m \cdot \textcolor{blue}{g^{kx}}) \cdot (\textcolor{blue}{g^{kx}})^{−1} = m.

ElGamal Example#

ElGamal Encryption#

Quiz#

ElGamal Encryption Quiz -1#

ElGamal Encryption Quiz - 2#

Task:

Consider an ElGamal encryption scheme with a common prime p=23\textcolor{red}{p=23} and a primitive root (generator) g=5\textcolor{red}{g=5}. Given that the public key Y=4\textcolor{red}{Y=4} and User C chooses the random integer k=3\textcolor{red}{k=3}, what is the ciphertext for the message M=15\textcolor{red}{M=15}?

Digital Signature#

  • A digital signature is a cryptographic technique used to prove the authenticity and integrity of a digital message or document.
  • It is created using the sender’s private key and verified using the sender’s public key.
  • It provides assurance that the message has not been modified in transit.

Authentication
Confirms the identity of the sender
Integrity
Detects any change in the message
Non-repudiation

RSA Signature: Choosing Public and Private Keys

  • Choose two prime numbers: p=3p = 3 and q=17q = 17
  • Compute n=p×q=3×17=51n = p \times q = 3 \times 17 = 51
  • Compute ϕ(n)=(31)(171)=2×16=32\phi(n) = (3 − 1)(17 − 1) = 2 \times 16 = 32
  • Choose e such that 1<e<ϕ(n)1 < e < \phi(n) and gcd(e,ϕ(n))=1\gcd(e, \phi(n)) = 1. Let e=5\textcolor{blue}{e = 5}
  • Find d such that ed1(modϕ(n))e \cdot d \equiv 1 (\bmod \phi(n))
  • Here, 5×13=651(mod32)5 \times 13 = 65 \equiv 1 (\bmod 32), so d=13\textcolor{blue}{d = 13}
Public key
(e, n) = (5, 51)
Private key
(d, n) = (13, 51)
These keys are used
for signing and verifying

RSA Signature: Signing and Verifying the Signature

Sender uses private key to sign
  • Let the message hash be h = 2
  • Use the private key (d, n) = (13, 51)
  • Compute signature: s = hd mod n
s = 213 mod 51
 = 8192 mod 51
 = 32
The digital signature is s = 32
Receiver uses public key to verify
  • Receiver uses the public key (e, n) = (5, 51)
  • Verify signature s = 32 by computing
    h' = se mod n
  • If h' equals the original hash h = 2, the signature is valid
h' = 325 mod 51
  = 33554432 mod 51
  = 2
Since h' = 2 = h, the signature is valid

Feistel Cipher#

  • The Feistel Cipher is a symmetric encryption algorithm that uses a structure that divides the data into two halves and processes them through multiple rounds of permutation and substitution and then recombines them to produce the ciphertext.
  • Its decryption process is essentially the same as encryption, just with the key schedule reversed.

How it works#

  • Splitting the Input: The plaintext block (say, 64 bits) is divided into two equal halves: a left half (L) and a right half (R). Eg. if the block is 64 bits, L₀ and R₀ = 32 bits each.
  • Round Function:
    • The right half (R) is fed into a round function F, which takes R and a round-specific subkey Ki\textcolor{red}{K_i}(derived from the main encryption key) as inputs. This function involve substitution boxes, or S-boxes, and permutations that scrambles the data.
    • The output of F is XORed (exclusive OR) with the left half (L).
    • The halves swap places: the old R becomes the new L, and the XOR result becomes the new R.
  • Multiple Rounds: This process repeats for a set number of rounds (usally 16). Each round uses a different subkey, generated from the main key via a key schedule algorithm.
  • Final Step: After the last round, the halves are concatenated to form the ciphertext.

Example#

2 ROUNDS

  • Plaintext: 16-bit plaintext
    1010 1100 0110 0011
  • Subkeys: Two 8-bit
    • Round 1 subkey (K1K_1):
      1100 1010
    • Round 2 subkey (K2K_2):
      0011 0101
  • Round Function (F):
    Define F(R, K) as R XOR K followed by a left circular shift of 2 bits.

How it works#

Round 1#

  1. Apply FF to R0R_0:
    • R0=0110 0011R_0 \textcolor{red}= 0110 ~ 0011
    • K1=1100 1010K_1 \textcolor{red}= 1100 ~ 1010
    • R0 XOR K1=0110 00111100 1010=1010 1001R_0 ~ XOR ~ K_1 \textcolor{red}= 0110 ~ 0011 \textcolor{red}\oplus 1100 ~ 1010 \textcolor{red}= 1010 ~ 1001 (decimal 169)
    • Left shift 2 bits: 1010 10011010 ~ 1001 1010 01101010 ~ 0110 (decimal 166)
    • So, F(R0, K1)=1010 0110F(R_0,~ K_1) \textcolor{red}= 1010 ~ 0110
  2. XOR with L0L_0:
    • L0=1010 1100L_0 \textcolor{red}= 1010 ~ 1100
    • F(R0, K1)=1010 0110F(R_0,~ K_1) \textcolor{red}= 1010 ~ 0110
    • L0F(R0, K1)=1010 11001010 0110=0000 1010L_0 \oplus F(R_0,~ K_1) \textcolor{red}= 1010 ~ 1100 \textcolor{red}\oplus 1010 ~ 0110 \textcolor{red}= 0000 ~ 1010 (decimal 10)
  3. Swap:
    • New L1=R0=0110 0011L_1 = R_0 \textcolor{red}= 0110 ~ 0011
    • New R1=L0F(R0, K1)=0000 1010R_1 = L_0 \oplus F(R_0,~ K_1) \textcolor{red}= 0000 ~ 1010

After Round 1: L1=0110 0011, R1=0000 1010L_1 \textcolor{red}= 0110 ~ 0011,~ R_1 \textcolor{red}= 0000 ~ 1010

Round 2#

  1. Apply FF to R1R_1:

    • R1=0000 1010R_1 \textcolor{red}= 0000\ 1010
    • K2=0011 0101K_2 \textcolor{red}= 0011\ 0101
    • R1 XOR K2=0000 10100011 0101=0011 1111R_1\ XOR\ K_2 = 0000\ 1010 \textcolor{red}\oplus 0011\ 0101 = 0011\ 1111 (decimal 63)
    • Left shift 2 bits: 0011 11110011\ 1111 1111 11001111\ 1100 (decimal 252)
    • So, F(R1,K2)=1111 1100F(R_1, K_2) = 1111\ 1100
  2. XOR with L1L_1:

    • L1=0110 0011L_1 \textcolor{red}= 0110\ 0011
    • F(R1,K2)=1111 1100F(R_1, K_2) \textcolor{red}= 1111\ 1100
    • L1F(R1,K2)=0110 00111111 1100=1001 1111L_1 \oplus F(R_1, K_2) \textcolor{red}= 0110\ 0011 \textcolor{red}\oplus 1111\ 1100 \textcolor{red}= 1001\ 1111 (decimal 159)
  3. Swap:

    • New L2=R1=0000 1010L_2 = R_1 \textcolor{red}= 0000\ 1010
    • New R2=L1F(R1,K2)=1001 1111R_2 = L_1 \oplus F(R_1, K_2) \textcolor{red}= 1001\ 1111

After Round 2: L2=0000 1010, R2=1001 1111L_2 \textcolor{red}= 0000\ 1010,\ R_2 \textcolor{red}= 1001\ 1111

Output#

  • Ciphertext: Concatenate L2L_2 and R2R_2:
    • L2R2=0000 1010 1001 1111L_2 \mathbin{\|} R_2 = 0000\ 1010\ 1001\ 1111 (16 bits, decimal 175)

支持与分享

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

赞助
Foundations of Security Week7 Lecture
https://firefly.anka2.top/posts/obu/level5/semester2/fos/week7/lecture/
作者
🐦‍🔥不死鸟Anka
发布于
2026-04-21
许可协议
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 天前

目录