密码学复习en(1)

14 阅读4分钟

Cryptography Final Exam Review - English Version

Part 1: Symmetric Tools

1. PRG -> Stream Cipher

1.1 Pseudo-Random Generator (PRG)

Exam Focus: Concept Explanation - What is PRG?

A pseudo-random generator (PRG) is a deterministic algorithm that expands a short random seed into a long sequence, such that this sequence is computationally indistinguishable from a truly random sequence. PRG is a fundamental building block in cryptography that solves the core problem of "how to generate a large amount of seemingly random data using a small amount of randomness."

Formal Definition: Let G:{0,1}n{0,1}lG: \{0,1\}^n \rightarrow \{0,1\}^l be a function where l>nl > n (expansion requirement). GG is a secure PRG if for all polynomial-time distinguishers DD, there exists a negligible function ϵ\epsilon such that: Pr[D(G(s))=1]Pr[D(r)=1]ϵ(n)|\Pr[D(G(s)) = 1] - \Pr[D(r) = 1]| \leq \epsilon(n) where s{0,1}ns \leftarrow \{0,1\}^n is a random seed and r{0,1}lr \leftarrow \{0,1\}^l is a truly random string.

Key Understanding:

  • Input: a short random seed ss (e.g., 128 bits), which is the only source of randomness
  • Output: a long pseudo-random sequence G(s)G(s) (e.g., 1GB), much longer than the input
  • Security: the output sequence is computationally indistinguishable from a truly random sequence, meaning no polynomial-time algorithm can distinguish G(s)G(s) from a truly random string rr
  • Deterministic: the same seed always produces the same output sequence

Why Do We Need PRG? In cryptography, we often need large amounts of random numbers (e.g., encryption key streams), but generating truly random numbers is expensive. PRG allows us to generate large amounts of "seemingly random" data using a small amount of true randomness (the seed), greatly reducing the randomness requirement.

Practical Applications:

  • Generating encryption key streams (for stream ciphers)
  • Generating session keys
  • Generating initialization vectors (IV)
  • As building blocks for other cryptographic primitives

Exam Focus: PRG Security Definition A distinguisher DD is an algorithm that attempts to distinguish PRG output from a truly random string. If DD outputs 1 to indicate it thinks the input is random, then:

  • Pr[D(G(s))=1]\Pr[D(G(s)) = 1] is the probability that the distinguisher thinks the PRG output is random
  • Pr[D(r)=1]\Pr[D(r) = 1] is the probability that the distinguisher thinks a truly random string is random
  • If the difference between these probabilities is negligible, it means the PRG output is indistinguishable from a truly random string
1.2 Stream Cipher

Exam Focus: Concept Explanation - How Stream Cipher Works

A stream cipher is a symmetric encryption scheme that uses a key stream generated by a PRG to perform bitwise XOR with the plaintext. The core idea of stream ciphers is: if the key stream is truly random, then the ciphertext is a "one-time pad," which is theoretically unbreakable encryption.

Detailed How It Works:

  1. Key Generation: Sender and receiver share a key kk (e.g., 128 bits)
  2. Initialization Vector: Choose a random or pseudo-random IVIV (initialization vector). IVIV need not be secret, but should be different for each encryption
  3. Key Stream Generation: Use PRG to generate key stream K=G(k,IV)K = G(k, IV), with length equal to plaintext length
  4. Encryption: Ciphertext is obtained by bitwise XOR: c=mKc = m \oplus K

Mathematical Representation: For the ii-th bit: ci=mikic_i = m_i \oplus k_i where mim_i is the ii-th bit of plaintext, kik_i is the ii-th bit of key stream, and cic_i is the ii-th bit of ciphertext.

Decryption Process: Due to the property of XOR (ABB=AA \oplus B \oplus B = A), decryption simply requires XOR again: mi=ciki=(miki)ki=mi(kiki)=mi0=mim_i = c_i \oplus k_i = (m_i \oplus k_i) \oplus k_i = m_i \oplus (k_i \oplus k_i) = m_i \oplus 0 = m_i

Calculation Problem: Stream Cipher Encryption/Decryption Example: Given plaintext m=10110101m = 10110101 and key stream k=11001011k = 11001011, calculate ciphertext cc and decrypted plaintext. Solution:

  • Encryption: c=mk=1011010111001011=01111110c = m \oplus k = 10110101 \oplus 11001011 = 01111110
  • Decryption: m=ck=0111111011001011=10110101=mm' = c \oplus k = 01111110 \oplus 11001011 = 10110101 = m

Security Requirements (Exam Focus):

  1. Key Stream Length: Key stream must be the same length as plaintext, neither shorter nor longer
  2. Non-Reusability: The same combination of key and IV must never be reused! If reused, an attacker can compute: c1c2=(m1k)(m2k)=m1m2c_1 \oplus c_2 = (m_1 \oplus k) \oplus (m_2 \oplus k) = m_1 \oplus m_2 This reveals the XOR of two plaintexts, leaking information
  3. PRG Security: The underlying PRG must be cryptographically secure, otherwise the key stream may be predictable
  4. IV Uniqueness: Each encryption must use a different IV to ensure different key streams

Scheme Design Problem: Why Do We Need IV? Without IV, the same plaintext always produces the same ciphertext, which is insecure. The role of IV is to ensure that even with the same key, each encryption produces a different key stream, thus producing different ciphertexts. IV can be a counter, random number, or timestamp, but must ensure uniqueness.

Advantages:

  • Fast encryption (only requires XOR operation)
  • Simple implementation (easy to implement in both hardware and software)
  • Suitable for real-time communication (can generate key stream while encrypting)
  • Errors do not propagate (one bit error only affects one bit)

Disadvantages:

  • Key stream cannot be reused (must ensure IV uniqueness)
  • Requires synchronized IV (sender and receiver must use the same IV)
  • Complex key management (need to securely share and store keys)

Proof Problem: CPA Security of Stream Cipher If PRG GG is secure, then the stream cipher based on GG is semantically secure under CPA. Proof Idea:

  1. Assume there exists an attacker AA that can break the stream cipher with non-negligible advantage
  2. Construct a distinguisher DD to distinguish PRG output from random strings
  3. If AA succeeds, then DD can also succeed in distinguishing, contradicting PRG security
  4. Therefore, the stream cipher is CPA secure

2. PRF -> Block Cipher

2.1 Pseudo-Random Function (PRF)

Exam Focus: Concept Explanation - Difference Between PRF and PRG

A pseudo-random function (PRF) is a deterministic function that takes a key and an input, producing an output, such that without knowing the key, it is impossible to distinguish this function from a truly random function. A PRF can be thought of as a "queryable random function table," where querying different inputs yields (seemingly) random outputs.

Formal Definition: Let F:{0,1}n×{0,1}m{0,1}nF: \{0,1\}^n \times \{0,1\}^m \rightarrow \{0,1\}^n be a function family, where the first parameter is the key and the second parameter is the input. FF is a secure PRF if for all polynomial-time distinguishers DD, there exists a negligible function ϵ\epsilon such that: Pr[DFk()=1]Pr[Df()=1]ϵ(n)|\Pr[D^{F_k(\cdot)} = 1] - \Pr[D^{f(\cdot)} = 1]| \leq \epsilon(n) where k{0,1}nk \leftarrow \{0,1\}^n is a random key and ff is a randomly chosen function from all functions {0,1}m{0,1}n\{0,1\}^m \rightarrow \{0,1\}^n (a truly random function).

Key Understanding:

  • Function Family: For different keys kk, FkF_k are different functions
  • Deterministic: The same input xx and key kk always produce the same output Fk(x)F_k(x)
  • Pseudo-randomness: Without knowing the key kk, the behavior of Fk()F_k(\cdot) is indistinguishable from a truly random function f()f(\cdot)
  • Queryability: The distinguisher can query the function on arbitrary inputs

Difference Between PRF and PRG (Exam Focus):

PropertyPRGPRF
InputFixed-length seedKey + arbitrary input
OutputLong sequenceFixed-length output
QueryGenerate entire sequence at onceCan query arbitrary inputs on demand
ApplicationStream cipherBlock cipher, MAC

Core Properties:

  1. Deterministic: Same input and key always produce same output, i.e., Fk(x)=Fk(x)F_k(x) = F_k(x)
  2. Pseudo-randomness: Without knowing the key, output appears random
  3. Efficiency: Fast computation, can be computed in polynomial time
  4. Reversibility: PRF itself may not be reversible, but can be used to construct reversible block ciphers

Practical Applications:

  • Constructing block ciphers (e.g., AES)
  • Constructing message authentication codes (MAC)
  • Constructing key derivation functions
  • As building blocks for other cryptographic primitives
2.2 Block Cipher

Exam Focus: Concept Explanation - What is Block Cipher?

A block cipher is a symmetric encryption scheme that encrypts a fixed-length plaintext block (e.g., 128 bits) into a ciphertext block of the same length. Block ciphers are one of the most fundamental and widely used cryptographic primitives.

Basic Structure: Block ciphers are typically constructed based on PRF, with AES (Advanced Encryption Standard) being the most famous example. The core of a block cipher is designing a reversible, pseudo-random permutation, i.e., for each key, the encryption function is a bijection from all possible plaintext blocks to all possible ciphertext blocks.

How AES Works (Detailed): AES treats a 128-bit plaintext block as a 4×44 \times 4 byte matrix (each byte is 8 bits, total 16 bytes = 128 bits).

  1. Input: 128-bit plaintext block PP and 128/192/256-bit key kk
  2. Key Expansion: Expand the key into multiple round keys
  3. Initial Round Key Addition (AddRoundKey): XOR plaintext with first round key State=PRoundKey0State = P \oplus RoundKey_0
  4. Multiple Rounds (depending on key length: 10 rounds for 128-bit key, 12 for 192-bit, 14 for 256-bit):
    • SubBytes (Byte Substitution): Use S-box (Substitution Box) to perform nonlinear substitution on each byte, providing confusion
    • ShiftRows (Row Shifting): Cyclically shift each row of the matrix by different amounts, providing diffusion
    • MixColumns (Column Mixing): Perform linear transformation on each column (omitted in last round), further providing diffusion
    • AddRoundKey (Round Key Addition): XOR with current round key
  5. Last Round: Omit MixColumns operation
  6. Output: 128-bit ciphertext block CC

Mathematical Representation: C=Ek(P)C = E_k(P) where PP is the plaintext block, kk is the key, EkE_k is the encryption function, and CC is the ciphertext block.

Decryption Process: P=Dk(C)=Ek1(C)P = D_k(C) = E_k^{-1}(C) where DkD_k is the decryption function, the inverse of the encryption function. AES decryption uses inverse operations: InvSubBytes, InvShiftRows, InvMixColumns.

Calculation Problem: AES Encryption Calculation Example: Given AES-128 key kk and plaintext block PP, describe the encryption process (no need for specific values, but explain each step). Solution Points:

  1. Key expansion: Generate 11 round keys (1 initial + 10 round keys)
  2. Initial round key addition: State=PRoundKey0State = P \oplus RoundKey_0
  3. 10 rounds of transformation: Each round includes SubBytes, ShiftRows, MixColumns (except round 10), AddRoundKey
  4. Output ciphertext block

Security Analysis (Exam Focus):

  • Single Block Security: Block ciphers themselves only provide encryption for a single block. If the plaintext is exactly one block, encryption is secure
  • Multiple Blocks Problem: Directly using block ciphers to encrypt multiple blocks is insecure! Identical plaintext blocks produce identical ciphertext blocks, which leaks information
  • Encryption Modes Needed: Must use encryption modes (such as CBC, CTR) to securely encrypt multiple blocks

Proof Problem: Why Directly Using Block Cipher to Encrypt Multiple Blocks is Insecure? Proof Idea: Assume directly using EkE_k to encrypt multiple blocks: Ci=Ek(Pi)C_i = E_k(P_i) If Pi=PjP_i = P_j (iji \neq j), then Ci=Ek(Pi)=Ek(Pj)=CjC_i = E_k(P_i) = E_k(P_j) = C_j An attacker observing Ci=CjC_i = C_j can infer Pi=PjP_i = P_j, which leaks plaintext information. Therefore, directly using block ciphers to encrypt multiple blocks is not semantically secure.

3. How to Use Block Cipher? -> Encryption Modes

Scheme Design Problem: Why Do We Need Encryption Modes?

Directly using block ciphers to encrypt multiple blocks is insecure because identical plaintext blocks produce identical ciphertext blocks, which leaks information. Encryption modes define how to use block ciphers to securely encrypt messages of arbitrary length (which may contain multiple blocks).

Core Problem: Block cipher EkE_k can only encrypt fixed-length blocks (e.g., 128 bits). To encrypt longer messages, we need:

  1. Split the message into multiple blocks
  2. Use some method to combine the encryption of these blocks
  3. Ensure the combination method does not leak information
3.1 ECB Mode (Electronic Codebook Mode)

Exam Focus: Concept Explanation - How ECB Mode Works and Its Security

ECB (Electronic Codebook) mode is the simplest encryption mode, where each plaintext block is encrypted independently without affecting others.

How It Works:

  1. Split plaintext mm into blocks: P1,P2,,PnP_1, P_2, \ldots, P_n (each block length equals the block cipher block length)
  2. Encrypt each block independently: Ci=Ek(Pi)for i=1,2,,nC_i = E_k(P_i) \quad \text{for } i = 1, 2, \ldots, n
  3. Ciphertext is: C=C1C2CnC = C_1 || C_2 || \ldots || C_n

Decryption: Pi=Dk(Ci)=Ek1(Ci)P_i = D_k(C_i) = E_k^{-1}(C_i)

Calculation Problem: ECB Mode Encryption Calculation Example: Encrypt message m="HELLOWORLD"m = "HELLO WORLD" using AES-128 (block length 128 bits) in ECB mode (assume padded to block length multiple). If Ek("HELLO")=C1E_k("HELLO") = C_1, Ek("WORL")=C2E_k(" WORL") = C_2, Ek("D...")=C3E_k("D...") = C_3, write the encryption process. Solution:

  • Split: P1="HELLO"P_1 = "HELLO", P2="WORL"P_2 = " WORL", $P_3 = "D..."`
  • Encrypt: C1=Ek(P1)C_1 = E_k(P_1), C2=Ek(P2)C_2 = E_k(P_2), C3=Ek(P3)C_3 = E_k(P_3)
  • Ciphertext: C=C1C2C3C = C_1 || C_2 || C_3

Security Analysis (Exam Focus): ECB mode has serious security problems:

  1. Identical plaintext blocks produce identical ciphertext blocks: If Pi=PjP_i = P_j, then Ci=Ek(Pi)=Ek(Pj)=CjC_i = E_k(P_i) = E_k(P_j) = C_j
  2. Does not hide patterns: Repetitive patterns in plaintext are reflected in ciphertext
  3. Not CPA secure: Attackers can observe which blocks are identical, inferring plaintext information

Proof Problem: Prove ECB Mode is Not CPA Secure Proof Idea: Construct attacker AA:

  1. AA chooses two plaintexts m0=PPm_0 = P || P (two identical blocks) and m1=PQm_1 = P || Q (two different blocks, PQP \neq Q)
  2. AA queries encryption oracle, receives challenge ciphertext cc^*
  3. If the first two blocks of cc^* are identical, AA outputs b=0b' = 0; otherwise outputs b=1b' = 1
  4. AA's success probability is 1 (perfect distinguishing), therefore ECB is not CPA secure

Practical Example: If an image is encrypted using ECB mode, even after encryption, the general outline of the image remains visible because identical pixel blocks produce identical ciphertext blocks.

Conclusion: ECB mode should not be used in practical applications!

3.2 CBC Mode (Cipher Block Chaining Mode)

Exam Focus: Concept Explanation - How CBC Mode Solves ECB's Problems

CBC (Cipher Block Chaining) mode solves the problem of identical plaintext blocks producing identical ciphertext blocks by XORing each plaintext block with the previous ciphertext block.

How It Works:

  1. Choose IV: Choose a random initialization vector IVIV (length equals block length, e.g., 128 bits)
  2. First Block: First plaintext block XORed with IVIV then encrypted C1=Ek(P1IV)C_1 = E_k(P_1 \oplus IV)
  3. Subsequent Blocks: Each plaintext block XORed with previous ciphertext block then encrypted Ci=Ek(PiCi1)for i2C_i = E_k(P_i \oplus C_{i-1}) \quad \text{for } i \geq 2

Complete Encryption Formula: C0=IVC_0 = IV Ci=Ek(PiCi1)for i1C_i = E_k(P_i \oplus C_{i-1}) \quad \text{for } i \geq 1

Decryption Process:

  1. Decrypt first block: P1=Dk(C1)IV=Dk(C1)C0P_1 = D_k(C_1) \oplus IV = D_k(C_1) \oplus C_0
  2. Decrypt subsequent blocks: Pi=Dk(Ci)Ci1for i2P_i = D_k(C_i) \oplus C_{i-1} \quad \text{for } i \geq 2

Calculation Problem: CBC Mode Encryption/Decryption Calculation Example: In CBC mode, given IV=1010IV = 1010, P1=1100P_1 = 1100, P2=0110P_2 = 0110, key kk, assuming Ek(0010)=1111E_k(0010) = 1111, Ek(1001)=0101E_k(1001) = 0101, calculate C1C_1 and C2C_2, then verify decryption. Solution:

  • Encryption:
    • C1=Ek(P1IV)=Ek(11001010)=Ek(0110)C_1 = E_k(P_1 \oplus IV) = E_k(1100 \oplus 1010) = E_k(0110) (need to know value of Ek(0110)E_k(0110))
    • Assume Ek(0110)=1110E_k(0110) = 1110, then C1=1110C_1 = 1110
    • C2=Ek(P2C1)=Ek(01101110)=Ek(1000)C_2 = E_k(P_2 \oplus C_1) = E_k(0110 \oplus 1110) = E_k(1000)
    • Assume Ek(1000)=0001E_k(1000) = 0001, then C2=0001C_2 = 0001
  • Decryption Verification:
    • P1=Dk(C1)IV=Dk(1110)1010=01101010=1100=P1P_1' = D_k(C_1) \oplus IV = D_k(1110) \oplus 1010 = 0110 \oplus 1010 = 1100 = P_1
    • P2=Dk(C2)C1=Dk(0001)1110=10001110=0110=P2P_2' = D_k(C_2) \oplus C_1 = D_k(0001) \oplus 1110 = 1000 \oplus 1110 = 0110 = P_2

Key Characteristics (Exam Focus):

  1. Requires IV: Must have an initialization vector, usually transmitted together with the first ciphertext block
  2. Properties of IV:
    • IVIV should be random (or pseudo-random)
    • IVIV need not be secret, can be transmitted in plaintext
    • Each encryption should use a different IVIV (to ensure semantic security)
  3. Different Ciphertexts for Same Plaintext: Even if Pi=PjP_i = P_j, if Ci1Cj1C_{i-1} \neq C_{j-1}, then CiCjC_i \neq C_j
  4. Parallelism:
    • Encryption is sequential: Must wait for previous block encryption to complete before encrypting next block (cannot parallelize)
    • Decryption can be parallelized: All blocks can be decrypted simultaneously because Ci1C_{i-1} is already known

Scheme Design Problem: Why Does IV Not Need to Be Secret? Even if the attacker knows IVIV, as long as IVIV is random, CBC mode is still CPA secure. The role of IVIV is to ensure each encryption produces different ciphertexts, not to provide confidentiality. Confidentiality is provided by the encryption function EkE_k.

Security: CBC mode is semantically secure under CPA (Chosen Plaintext Attack), provided:

  1. The underlying block cipher EkE_k is a pseudo-random permutation (PRP)
  2. IVIV is randomly chosen (different for each encryption)

Proof Problem: CPA Security of CBC Mode (Simplified Proof Idea) Proof Idea:

  1. Assume the underlying block cipher EkE_k is a pseudo-random permutation
  2. If IVIV is random, then each block's input (PiCi1P_i \oplus C_{i-1}) appears random
  3. Since EkE_k is pseudo-random, output CiC_i also appears random
  4. Therefore, the entire ciphertext appears random, cannot distinguish encryptions of two plaintexts
  5. Therefore, CBC mode is CPA secure
3.3 CTR Mode (Counter Mode)

Exam Focus: Concept Explanation - Relationship Between CTR Mode and Stream Cipher

CTR (Counter) mode uses a counter to generate a key stream, then XORs with plaintext. CTR mode essentially converts a block cipher into a stream cipher.

How It Works:

  1. Choose IV: Choose an initial value IVIV (usually a random number or counter starting value)
  2. Generate Key Stream: Apply block cipher to each counter value IV+iIV + i (i=0,1,2,i = 0, 1, 2, \ldots) to generate key stream blocks: Ki=Ek(IV+i)K_i = E_k(IV + i)
  3. Encryption: Plaintext block XORed with corresponding key stream block: Ci=PiKi=PiEk(IV+i)C_i = P_i \oplus K_i = P_i \oplus E_k(IV + i)
  4. Decryption: XOR ciphertext with same key stream block: Pi=CiKi=CiEk(IV+i)P_i = C_i \oplus K_i = C_i \oplus E_k(IV + i)

Mathematical Representation: Ci=PiEk(IV+i)C_i = P_i \oplus E_k(IV + i) Pi=CiEk(IV+i)P_i = C_i \oplus E_k(IV + i)

Calculation Problem: CTR Mode Encryption Calculation Example: In CTR mode, given IV=5IV = 5, P1=1010P_1 = 1010, P2=1100P_2 = 1100, key kk, assuming Ek(5)=1111E_k(5) = 1111, Ek(6)=0101E_k(6) = 0101, calculate C1C_1 and C2C_2. Solution:

  • K1=Ek(IV+0)=Ek(5)=1111K_1 = E_k(IV + 0) = E_k(5) = 1111
  • C1=P1K1=10101111=0101C_1 = P_1 \oplus K_1 = 1010 \oplus 1111 = 0101
  • K2=Ek(IV+1)=Ek(6)=0101K_2 = E_k(IV + 1) = E_k(6) = 0101
  • C2=P2K2=11000101=1001C_2 = P_2 \oplus K_2 = 1100 \oplus 0101 = 1001

Key Characteristics (Exam Focus):

  1. Encryption and Decryption Are Identical: Both encryption and decryption use XOR operation, exactly the same operation
  2. Fully Parallelizable: Can encrypt/decrypt all blocks simultaneously because each Ki=Ek(IV+i)K_i = E_k(IV + i) can be computed independently
  3. No Padding Needed: Can handle arbitrary length data without padding to block length multiples
  4. Similar to Stream Cipher: CTR mode behaves similarly to stream cipher but based on block cipher rather than PRG
  5. Random Access: Can decrypt arbitrary block without decrypting previous blocks (just need to know IVIV and block index)

Scheme Design Problem: CTR Mode vs CBC Mode

PropertyCBC ModeCTR Mode
Parallel Encryption❌ Sequential✅ Fully parallel
Parallel Decryption✅ Can parallelize✅ Fully parallel
Random Access❌ Need previous blocks✅ Can directly access
Padding✅ Required❌ Not needed
Error Propagation✅ One bit error affects subsequent blocks❌ Errors do not propagate
Implementation ComplexityMediumSimple

Security: CTR mode is semantically secure under CPA, provided:

  1. The underlying block cipher EkE_k is a pseudo-random permutation (PRP)
  2. IVIV is randomly chosen, and IV+iIV + i values do not repeat (counter does not wrap around)

Proof Problem: CPA Security of CTR Mode Proof Idea:

  1. If EkE_k is a pseudo-random permutation, then Ek(IV+i)E_k(IV + i) output appears random
  2. Key stream Ki=Ek(IV+i)K_i = E_k(IV + i) appears to be a truly random string
  3. Therefore, Ci=PiKiC_i = P_i \oplus K_i appears to be "one-time pad" encryption
  4. "One-time pad" is theoretically unbreakable, therefore CTR mode is CPA secure

Practical Applications: CTR mode is widely used in modern cryptography because it supports parallel processing, suitable for high-speed encryption scenarios.

3.4 CPA Secure Semantic Security

Exam Focus: Concept Explanation - Complete Definition of CPA Security

Chosen Plaintext Attack (CPA): In a chosen plaintext attack, the attacker can choose arbitrary plaintexts and obtain corresponding ciphertexts. This models real-world scenarios where attackers can observe encrypted communications.

Semantic Security: Semantic security means that even if the attacker knows some information about the plaintext (such as length, format, etc.), they cannot obtain additional information from the ciphertext. In other words, the ciphertext does not leak any information about the plaintext (except public information like length).

Formal Definition: An encryption scheme (Gen,Enc,Dec)(Gen, Enc, Dec) is CPA secure if for all polynomial-time attackers AA, there exists a negligible function ϵ\epsilon such that: Pr[CPA-Game(A)=1]12+ϵ(n)\Pr[\text{CPA-Game}(A) = 1] \leq \frac{1}{2} + \epsilon(n) where CPA-Game(A)\text{CPA-Game}(A) is the CPA game, outputting 1 when attacker AA wins.

CPA Game (Detailed Steps):

  1. Initialization: Challenger generates key kGen(1n)k \leftarrow Gen(1^n), where nn is the security parameter
  2. Learning Phase 1: Attacker AA can query encryption oracle Enck()Enc_k(\cdot) arbitrarily many polynomial times, obtaining (mi,Enck(mi))(m_i, Enc_k(m_i)) pairs
  3. Challenge Phase:
    • Attacker chooses two equal-length plaintexts m0,m1m_0, m_1 (m0=m1|m_0| = |m_1|)
    • Challenger randomly chooses b{0,1}b \leftarrow \{0,1\} (uniformly random)
    • Challenger computes and returns challenge ciphertext c=Enck(mb)c^* = Enc_k(m_b)
  4. Learning Phase 2: Attacker AA can continue to query encryption oracle Enck()Enc_k(\cdot) arbitrarily many polynomial times (but cannot query decryption of cc^*)
  5. Guess Phase: Attacker outputs b{0,1}b' \in \{0,1\}
  6. Decision: If b=bb' = b, attacker wins, game outputs 1; otherwise outputs 0

Attacker's Advantage: Attacker's advantage is defined as: AdvCPA(A)=Pr[CPA-Game(A)=1]12\text{Adv}_{CPA}(A) = |\Pr[\text{CPA-Game}(A) = 1] - \frac{1}{2}| If AdvCPA(A)ϵ(n)\text{Adv}_{CPA}(A) \leq \epsilon(n) (negligible function), then the encryption scheme is CPA secure.

Proof Problem: Prove ECB Mode is Not CPA Secure Proof: Construct attacker AA:

  1. AA chooses m0=PPm_0 = P || P (two identical blocks) and m1=PQm_1 = P || Q (two different blocks, PQP \neq Q)
  2. AA queries encryption oracle, receives challenge ciphertext c=c1c2c^* = c_1^* || c_2^*
  3. AA checks: if c1=c2c_1^* = c_2^*, output b=0b' = 0; otherwise output b=1b' = 1

Analysis:

  • If b=0b = 0 (encrypt m0m_0), then c1=Ek(P)c_1^* = E_k(P), c2=Ek(P)c_2^* = E_k(P), so c1=c2c_1^* = c_2^*
  • If b=1b = 1 (encrypt m1m_1), then c1=Ek(P)c_1^* = E_k(P), c2=Ek(Q)c_2^* = E_k(Q), since PQP \neq Q and EkE_k is a permutation, so c1c2c_1^* \neq c_2^*
  • Therefore, AA can always correctly guess bb with success probability 1
  • AdvCPA(A)=112=12\text{Adv}_{CPA}(A) = |1 - \frac{1}{2}| = \frac{1}{2}, which is non-negligible
  • Therefore, ECB mode is not CPA secure

Proof Problem: Prove CBC Mode is CPA Secure (Simplified Idea) Proof Idea (based on ideal cipher model):

  1. Assume the underlying block cipher EkE_k is a pseudo-random permutation (PRP)
  2. In ideal case, if IVIV is random, then each block's input PiCi1P_i \oplus C_{i-1} appears random
  3. Since EkE_k is pseudo-random, output CiC_i also appears random
  4. Therefore, the entire ciphertext appears random, cannot distinguish encryptions of m0m_0 and m1m_1
  5. Any attacker's advantage is negligible
  6. Therefore, CBC mode is CPA secure

Important Conclusions (Exam Focus):

  • CBC Mode: Semantically secure under CPA (if IVIV is random)
  • CTR Mode: Semantically secure under CPA (if IVIV is random)
  • ECB Mode: Not CPA secure, should not be used
  • CPA security is a fundamental security requirement in modern cryptography: Any practical encryption scheme must be CPA secure

4. Hash Function

Exam Focus: Concept Explanation - Three Security Properties and Their Relationships

A hash function maps inputs of arbitrary length to fixed-length outputs. Hash functions are fundamental tools in cryptography, used for data integrity verification, digital signatures, password storage, etc.

Formal Definition: Let H:{0,1}{0,1}nH: \{0,1\}^* \rightarrow \{0,1\}^n be a function, where {0,1}\{0,1\}^* represents binary strings of arbitrary length and {0,1}n\{0,1\}^n represents binary strings of fixed length nn.

Basic Properties:

  1. Compression: Fixed output length (e.g., SHA-256 outputs 256 bits), regardless of input length
  2. Efficiency: Fast computation, can be computed in polynomial time
  3. Deterministic: Same input always produces same output, i.e., H(x)=H(x)H(x) = H(x)

Security Requirements (Exam Focus):

1. Preimage Resistance (One-Wayness) Definition: Given hash value yy, finding xx such that H(x)=yH(x) = y is computationally infeasible. Formal: For all polynomial-time attackers AA, there exists a negligible function ϵ\epsilon such that: Pr[x{0,1},y=H(x),A(y)=x and H(x)=y]ϵ(n)\Pr[x \leftarrow \{0,1\}^*, y = H(x), A(y) = x' \text{ and } H(x') = y] \leq \epsilon(n) Intuitive Understanding: Given a hash value, computing the preimage is difficult (one-way function property).

2. Second Preimage Resistance Definition: Given xx, finding xxx' \neq x such that H(x)=H(x)H(x) = H(x') is computationally infeasible. Formal: For all polynomial-time attackers AA, there exists a negligible function ϵ\epsilon such that: Pr[x{0,1},A(x)=xx and H(x)=H(x)]ϵ(n)\Pr[x \leftarrow \{0,1\}^*, A(x) = x' \neq x \text{ and } H(x') = H(x)] \leq \epsilon(n) Intuitive Understanding: Given an input, finding another input that produces the same hash value is difficult.

3. Collision Resistance Definition: Finding any x,xx, x' such that xxx \neq x' but H(x)=H(x)H(x) = H(x') is computationally infeasible. Formal: For all polynomial-time attackers AA, there exists a negligible function ϵ\epsilon such that: Pr[A()=(x,x) and xx and H(x)=H(x)]ϵ(n)\Pr[A() = (x, x') \text{ and } x \neq x' \text{ and } H(x) = H(x')] \leq \epsilon(n) Intuitive Understanding: Finding any pair of collisions is difficult.

Proof Problem: Relationships Between Three Security Properties Theorem:

  1. Collision Resistance \Rightarrow Second Preimage Resistance
  2. Second Preimage Resistance \Rightarrow Preimage Resistance (under random oracle model)
  3. But Preimage Resistance ⇏\not\Rightarrow Second Preimage Resistance
  4. Second Preimage Resistance ⇏\not\Rightarrow Collision Resistance

Proof Idea 1: Collision Resistance \Rightarrow Second Preimage Resistance

  • Assume there exists attacker A2A_2 that can find second preimage with non-negligible probability
  • Construct attacker A1A_1 to find collision:
    1. Randomly choose xx
    2. Call A2(x)A_2(x) to get xxx' \neq x such that H(x)=H(x)H(x') = H(x)
    3. Output (x,x)(x, x') as collision
  • If A2A_2 succeeds, then A1A_1 also succeeds, contradiction

Calculation Problem: Birthday Attack (Collision Finding) Birthday Paradox: In a room with NN people, what is the probability that at least two people share the same birthday?

  • When N2×365×ln223N \approx \sqrt{2 \times 365 \times \ln 2} \approx 23, probability is about 50%

Birthday Attack: For a hash function with output length nn bits, finding a collision requires approximately O(2n/2)O(2^{n/2}) hash computations. Example: SHA-256 outputs 256 bits, how many hash computations are needed to find a collision using birthday attack? Solution: 2256/2=21282^{256/2} = 2^{128} hash computations (still computationally infeasible)

Practical Applications:

  1. Digital Signatures: Hash message before signing, rather than signing entire message directly (efficient)
  2. Message Authentication Codes: As building block for MAC (e.g., HMAC)
  3. Password Storage: Store hash of password rather than plaintext password
  4. Blockchain: Merkle trees, proof of work (PoW)
  5. Data Integrity Verification: Verify whether files have been tampered with

Common Hash Functions:

  • SHA-256: 256-bit output, currently secure, widely used
  • SHA-512: 512-bit output, more secure but slightly slower
  • SHA-3: Based on Keccak, different design from SHA-2
  • MD5: 128-bit output, insecure, should not be used (collisions found)
  • SHA-1: 160-bit output, insecure, should not be used (collisions found)

Scheme Design Problem: How to Use Hash Function to Verify File Integrity? Scheme:

  1. Sender computes file hash value h=H(file)h = H(file)
  2. Sender sends (file,h)(file, h) through secure channel (e.g., digital signature)
  3. Receiver computes h=H(file)h' = H(file') after receiving
  4. If h=hh' = h, file is intact; otherwise file has been tampered with

Why This Design?

  • If attacker modifies file, hash value changes
  • Due to preimage resistance, attacker cannot find different file producing same hash value
  • Therefore, any tampering can be detected

5. Message Authentication Code (MAC)

Exam Focus: Concept Explanation - Difference Between MAC and Digital Signature

Message authentication codes (MAC) are used to ensure message integrity and authenticity. MAC uses symmetric keys, so sender and receiver must share the same key.

Basic Idea:

  1. Key Sharing: Sender and receiver pre-share a key kk (through secure channel)
  2. Generate Tag: Sender computes tag=MACk(m)tag = MAC_k(m) and sends (m,tag)(m, tag)
  3. Verify Tag: Receiver computes tag=MACk(m)tag' = MAC_k(m) and checks if tag=tagtag' = tag
  4. Decision: If tag=tagtag' = tag, message is intact and from sender; otherwise reject message

Formal Definition: A MAC scheme consists of three algorithms:

  • Key Generation: Gen(1n)kGen(1^n) \rightarrow k, generates key kk
  • Tag Generation: MACk(m)tagMAC_k(m) \rightarrow tag, computes tag for message mm
  • Verification: Verifyk(m,tag){0,1}Verify_k(m, tag) \rightarrow \{0, 1\}, verifies tag, outputs 1 (valid) or 0 (invalid)

Usually Verifyk(m,tag)=1Verify_k(m, tag) = 1 if and only if MACk(m)=tagMAC_k(m) = tag.

Security Requirements (Exam Focus):

Unforgeability MAC must be unforgeable, meaning even if the attacker sees many (mi,tagi)(m_i, tag_i) pairs, they cannot generate a valid tag tagtag^* for a new message mm^*.

Formal Security Definition: For all polynomial-time attackers AA, there exists a negligible function ϵ\epsilon such that: Pr[AMACk() outputs (m,tag) and Verifyk(m,tag)=1]ϵ(n)\Pr[A^{MAC_k(\cdot)} \text{ outputs } (m^*, tag^*) \text{ and } Verify_k(m^*, tag^*) = 1] \leq \epsilon(n) where mm^* is not a message that AA has queried (i.e., m{m1,m2,,mq}m^* \notin \{m_1, m_2, \ldots, m_q\}, where qq is the number of queries).

MAC Security Game:

  1. Challenger generates key kGen(1n)k \leftarrow Gen(1^n)
  2. Attacker can query MAC oracle MACk()MAC_k(\cdot) arbitrarily many polynomial times, obtaining (mi,tagi)(m_i, tag_i) pairs
  3. Attacker outputs (m,tag)(m^*, tag^*), where mm^* is not a queried message
  4. If Verifyk(m,tag)=1Verify_k(m^*, tag^*) = 1, attacker wins

Proof Problem: Why Is Simple MACk(m)=H(km)MAC_k(m) = H(k || m) Possibly Insecure? Problem: If attacker knows (m,tag)(m, tag), they may be able to construct new valid tags. Attack Example (Length Extension Attack):

  • If MACk(m)=H(km)MAC_k(m) = H(k || m), attacker can compute MACk(mm)=H(kmm)MAC_k(m || m') = H(k || m || m') without knowing kk
  • Attacker queries MACk(m)MAC_k(m) to get tag=H(km)tag = H(k || m)
  • Then attacker can compute H(tagm)H(tag || m') (in some hash functions, this equals H(kmm)H(k || m || m'))
  • Therefore attacker can generate valid tag for mmm || m' without knowing kk

Common MAC Constructions:

1. HMAC (MAC Based on Hash Function) HMACk(m)=H(kopadH(kipadm))HMAC_k(m) = H(k \oplus opad || H(k \oplus ipad || m)) where:

  • opadopad = 0x5c5c5c... (outer padding)
  • ipadipad = 0x363636... (inner padding)
  • || represents concatenation

Calculation Problem: HMAC Calculation Example: Given key kk and message mm, describe HMAC computation steps. Solution:

  1. If k>|k| > block length, then k=H(k)k = H(k)
  2. If k<|k| < block length, then right-pad kk with 0s
  3. Compute inner=H(kipadm)inner = H(k \oplus ipad || m)
  4. Compute HMACk(m)=H(kopadinner)HMAC_k(m) = H(k \oplus opad || inner)

2. CBC-MAC (MAC Based on Block Cipher) Encrypt message using CBC mode, use the last ciphertext block as MAC.

How It Works:

  1. Split message mm into blocks: m1,m2,,mnm_1, m_2, \ldots, m_n
  2. Encrypt using CBC mode (usually IV=0IV = 0): C1=Ek(m1)C_1 = E_k(m_1) Ci=Ek(miCi1)for i2C_i = E_k(m_i \oplus C_{i-1}) \quad \text{for } i \geq 2
  3. MAC is the last ciphertext block: tag=Cntag = C_n

Note: CBC-MAC is only secure for fixed-length messages. For variable-length messages, other techniques are needed (e.g., encrypt the length of the last block).

MAC vs Digital Signature (Exam Focus):

PropertyMACDigital Signature
Key TypeSymmetric key (shared key)Asymmetric key (public/private key pair)
Key ManagementNeed to securely share keyPublic key can be public
Non-repudiation❌ Both parties can generate tags✅ Only private key holder can sign
VerifierMust know keyOnly needs public key
EfficiencyFastSlower
ApplicationTwo-party communicationPublic verification, non-repudiation

Scheme Design Problem: Design a Secure MAC Scheme Requirements: Ensure message integrity and authenticity. Scheme:

  1. Choose secure hash function HH (e.g., SHA-256)
  2. Use HMAC: tag=HMACk(m)=H(kopadH(kipadm))tag = HMAC_k(m) = H(k \oplus opad || H(k \oplus ipad || m))
  3. Send (m,tag)(m, tag)
  4. Receiver verifies: Compute tag=HMACk(m)tag' = HMAC_k(m), check if tag=tagtag' = tag

Why This Design?

  • HMAC resists length extension attacks
  • Based on secure hash function, provides unforgeability
  • Computationally efficient

6. Authenticated Encryption

Exam Focus: Concept Explanation - Why Do We Need Authenticated Encryption?

Authenticated encryption provides both confidentiality and integrity/authenticity. This is one of the most important security goals in modern cryptography.

Two Security Goals:

  1. Confidentiality (Confidentiality): Attacker cannot obtain any information about plaintext, even when seeing ciphertext
  2. Integrity/Authenticity (Integrity/Authenticity): Attacker cannot forge or modify messages without being detected

Why Authenticated Encryption is Needed: Encryption alone (such as CBC, CTR) only provides confidentiality, not integrity. This leads to serious security problems:

Attack Example:

  1. Attacker intercepts ciphertext c=Enck(m)c = Enc_k(m)
  2. Attacker modifies ciphertext to get cc' (e.g., flip some bits)
  3. Receiver decrypts to get m=Deck(c)m' = Dec_k(c')
  4. Receiver cannot detect that mm' is not the original message mm (because decryption may produce valid plaintext, but not the original message)

Practical Attack Scenarios:

  • Padding Oracle Attack: Attacker gains information by observing whether decryption succeeds
  • Ciphertext Modification Attack: Attacker modifies ciphertext, may cause predictable plaintext changes

Construction Methods (Exam Focus):

1. Encrypt-then-MAC (Recommended) Steps:

  1. Encrypt first: c=Enck1(m)c = Enc_{k_1}(m)
  2. Compute MAC: tag=MACk2(c)tag = MAC_{k_2}(c)
  3. Send (c,tag)(c, tag)

Verification:

  1. Verify MAC: Check if MACk2(c)=tagMAC_{k_2}(c) = tag
  2. If MAC is valid, decrypt: m=Deck1(c)m = Dec_{k_1}(c)

Advantages:

  • Best security (under standard assumptions)
  • MAC protects entire ciphertext, including integrity of encryption scheme

2. MAC-then-Encrypt Steps:

  1. Compute MAC first: tag=MACk2(m)tag = MAC_{k_2}(m)
  2. Encrypt: c=Enck1(mtag)c = Enc_{k_1}(m || tag)
  3. Send cc

Verification:

  1. Decrypt: mtag=Deck1(c)m || tag = Dec_{k_1}(c)
  2. Verify MAC: Check if MACk2(m)=tagMAC_{k_2}(m) = tag

Disadvantages:

  • May be insecure if encryption scheme has vulnerabilities (e.g., padding oracle)
  • Not recommended

3. Encrypt-and-MAC Steps:

  1. Encrypt and compute MAC simultaneously: c=Enck1(m)c = Enc_{k_1}(m), tag=MACk2(m)tag = MAC_{k_2}(m)
  2. Send (c,tag)(c, tag)

Verification:

  1. Verify MAC: Check if MACk2(m)=tagMAC_{k_2}(m') = tag (need to decrypt first to get mm')
  2. If MAC is valid, accept mm'

Disadvantages:

  • MAC protects plaintext, not ciphertext
  • May be insecure if encryption and MAC use the same key

Scheme Design Problem: Design an Authenticated Encryption Scheme Requirements: Provide both confidentiality and integrity. Recommended Scheme (Encrypt-then-MAC):

  1. Choose CPA-secure encryption scheme (e.g., AES-CTR)
  2. Choose secure MAC scheme (e.g., HMAC-SHA256)
  3. Use two independent keys: k1k_1 (encryption) and k2k_2 (MAC)
  4. Encrypt: c=Enck1(m)c = Enc_{k_1}(m)
  5. Compute MAC: tag=MACk2(c)tag = MAC_{k_2}(c)
  6. Send (c,tag)(c, tag)
  7. Receiver verifies: First verify MACk2(c)=tagMAC_{k_2}(c) = tag, if valid then decrypt m=Deck1(c)m = Dec_{k_1}(c)

Why Use Two Independent Keys?

  • If using the same key, may lead to security problems
  • Key separation is a best practice in cryptography

CCA Secure Semantic Security

Exam Focus: Concept Explanation - Difference Between CCA Security and CPA Security

Chosen Ciphertext Attack (CCA): In a chosen ciphertext attack, the attacker can choose arbitrary ciphertexts and obtain corresponding plaintexts (or verification failure). This models real-world scenarios where attackers can send modified ciphertexts and observe decryption results.

CCA Security: An encryption scheme is CCA secure if the attacker cannot distinguish encryptions of two plaintexts even when they can query a decryption oracle.

Formal Definition: For all polynomial-time attackers AA, there exists a negligible function ϵ\epsilon such that: Pr[CCA-Game(A)=1]12+ϵ(n)\Pr[\text{CCA-Game}(A) = 1] \leq \frac{1}{2} + \epsilon(n)

CCA Game (Detailed Steps):

  1. Initialization: Challenger generates key kGen(1n)k \leftarrow Gen(1^n)
  2. Learning Phase 1: Attacker can query:
    • Encryption oracle Enck()Enc_k(\cdot): Obtain (mi,Enck(mi))(m_i, Enc_k(m_i))
    • Decryption oracle Deck()Dec_k(\cdot): Obtain (ci,Deck(ci))(c_i, Dec_k(c_i))
  3. Challenge Phase:
    • Attacker chooses two equal-length plaintexts m0,m1m_0, m_1
    • Challenger randomly chooses b{0,1}b \leftarrow \{0,1\}
    • Challenger returns challenge ciphertext c=Enck(mb)c^* = Enc_k(m_b)
  4. Learning Phase 2: Attacker can continue to query encryption and decryption oracles, but cannot query decryption of cc^*
  5. Guess Phase: Attacker outputs b{0,1}b' \in \{0,1\}
  6. Decision: If b=bb' = b, attacker wins

Proof Problem: Why Are Encryption Modes Alone (Such as CBC, CTR) Not CCA Secure? Proof Idea (using CBC as example): Construct attacker AA:

  1. AA chooses m0=P1P2m_0 = P_1 || P_2 and m1=Q1Q2m_1 = Q_1 || Q_2 (two blocks)
  2. AA queries encryption oracle, receives challenge ciphertext c=c1c2c^* = c_1^* || c_2^*
  3. AA constructs new ciphertext c=c1c2c3c' = c_1^* || c_2^* || c_3' (add a random block)
  4. AA queries decryption oracle Deck(c)Dec_k(c'), obtains m=m1m2m3m' = m_1' || m_2' || m_3'
  5. Due to CBC mode properties, AA can infer information about mbm_b from mm'
  6. Therefore AA can distinguish encryptions of m0m_0 and m1m_1

Important Conclusions (Exam Focus):

  • Authenticated Encryption: Typically provides CCA security (e.g., Encrypt-then-MAC)
  • Encryption Modes Alone (CBC, CTR): Not CCA secure
  • CCA security is stronger than CPA security: CCA security implies CPA security, but not vice versa
  • Modern applications must use authenticated encryption: Encryption alone is insufficient to provide complete security

Practical Applications:

  • TLS/SSL Protocols: Use authenticated encryption to protect Web communications
  • SSH Protocol: Use authenticated encryption to protect remote login
  • Modern Encrypted Communication: All secure communication protocols use authenticated encryption

Calculation Problem: Complete Flow of Authenticated Encryption Example: Implement Encrypt-then-MAC using AES-128-CTR and HMAC-SHA256. Given: Key k1=0x1234...k_1 = 0x1234... (128 bits), k2=0x5678...k_2 = 0x5678... (256 bits), message m="HelloWorld"m = "Hello World" Solution Steps:

  1. Encryption: c=AES-CTRk1(m)c = AES\text{-}CTR_{k_1}(m)
    • Choose random IVIV
    • Generate key stream: Ki=AESk1(IV+i)K_i = AES_{k_1}(IV + i)
    • Encrypt: c=mKc = m \oplus K
  2. Compute MAC: tag=HMACk2(c)tag = HMAC_{k_2}(c)
    • tag=SHA256(k2opadSHA256(k2ipadc))tag = SHA256(k_2 \oplus opad || SHA256(k_2 \oplus ipad || c))
  3. Send: (IV,c,tag)(IV, c, tag)
  4. Receiver verifies:
    • Verify HMACk2(c)=tagHMAC_{k_2}(c) = tag
    • If valid, decrypt m=AES-CTRk11(c)m = AES\text{-}CTR_{k_1}^{-1}(c)

Part 2: Public Key Cryptography

1. Public Key Encryption from Trapdoor Permutations

1.1 RSA Encryption Scheme

Exam Focus: Concept Explanation - What is a Trapdoor Permutation?

A trapdoor permutation is a family of functions with the following properties:

  1. Forward computation is easy: Given public key pkpk and input xx, computing fpk(x)f_{pk}(x) is easy
  2. Reverse computation is hard: Without trapdoor information, computing xx from fpk(x)f_{pk}(x) is hard
  3. Reverse computation is easy (with trapdoor): Given private key (trapdoor) sksk, computing xx from fpk(x)f_{pk}(x) is easy

RSA is a classic example of a trapdoor permutation.

RSA Key Generation Algorithm:

  1. Choose two large primes pp and qq (typically 1024 bits or larger each)
  2. Compute n=p×qn = p \times q (modulus)
  3. Compute Euler's totient function ϕ(n)=(p1)(q1)\phi(n) = (p-1)(q-1)
  4. Choose integer ee such that 1<e<ϕ(n)1 < e < \phi(n) and gcd(e,ϕ(n))=1\gcd(e, \phi(n)) = 1 (ee is public exponent, often 65537)
  5. Compute dd such that ed1(modϕ(n))ed \equiv 1 \pmod{\phi(n)} (dd is private exponent)
  6. Public key: pk=(n,e)pk = (n, e)
  7. Private key: sk=(n,d)sk = (n, d) (or (p,q,d)(p, q, d))

RSA Encryption (Textbook Version): Given public key (n,e)(n, e) and plaintext mZnm \in \mathbb{Z}_n (0m<n0 \leq m < n), ciphertext is: c=memodnc = m^e \bmod n

RSA Decryption: Given private key (n,d)(n, d) and ciphertext cc, plaintext is: m=cdmodnm = c^d \bmod n

Correctness Proof: Since ed1(modϕ(n))ed \equiv 1 \pmod{\phi(n)}, there exists integer kk such that ed=1+kϕ(n)ed = 1 + k\phi(n). By Euler's theorem, if gcd(m,n)=1\gcd(m, n) = 1, then mϕ(n)1(modn)m^{\phi(n)} \equiv 1 \pmod{n}. Therefore: cd(me)dmedm1+kϕ(n)m(mϕ(n))km1km(modn)c^d \equiv (m^e)^d \equiv m^{ed} \equiv m^{1+k\phi(n)} \equiv m \cdot (m^{\phi(n)})^k \equiv m \cdot 1^k \equiv m \pmod{n}

Calculation Problem: Complete RSA Encryption/Decryption Calculation

Problem 1: Given RSA parameters: p=11p = 11, q=13q = 13, e=7e = 7, plaintext m=5m = 5. (1) Compute public and private keys (2) Compute ciphertext cc (3) Verify decryption process

Detailed Solution:

Step 1: Compute modulus and Euler's totient function

  • n=p×q=11×13=143n = p \times q = 11 \times 13 = 143
  • ϕ(n)=(p1)(q1)=10×12=120\phi(n) = (p-1)(q-1) = 10 \times 12 = 120

Step 2: Verify ee is coprime with ϕ(n)\phi(n)

  • gcd(7,120)=1\gcd(7, 120) = 1 ✓ (since 7 is prime and 7 does not divide 120)

Step 3: Compute private exponent dd Need to find dd such that 7d1(mod120)7d \equiv 1 \pmod{120}, i.e., 7d=1+120k7d = 1 + 120k for some integer kk.

Using extended Euclidean algorithm:

  • 120=7×17+1120 = 7 \times 17 + 1
  • 7=1×7+07 = 1 \times 7 + 0

Back substitution:

  • 1=1207×171 = 120 - 7 \times 17
  • Therefore d=17103(mod120)d = -17 \equiv 103 \pmod{120}

Verify: 7×103=721=6×120+11(mod120)7 \times 103 = 721 = 6 \times 120 + 1 \equiv 1 \pmod{120}

Step 4: Determine keys

  • Public key: pk=(n,e)=(143,7)pk = (n, e) = (143, 7)
  • Private key: sk=(n,d)=(143,103)sk = (n, d) = (143, 103)

Step 5: Encryption

  • Plaintext: m=5m = 5
  • Ciphertext: c=memodn=57mod143c = m^e \bmod n = 5^7 \bmod 143

Compute 57mod1435^7 \bmod 143:

  • 52=25mod143=255^2 = 25 \bmod 143 = 25
  • 54=(52)2=252=625mod143=6254×143=625572=535^4 = (5^2)^2 = 25^2 = 625 \bmod 143 = 625 - 4 \times 143 = 625 - 572 = 53
  • 57=54×52×5=53×25×5=6625mod1435^7 = 5^4 \times 5^2 \times 5 = 53 \times 25 \times 5 = 6625 \bmod 143

Compute 6625mod1436625 \bmod 143:

  • 143×46=6578143 \times 46 = 6578
  • 66256578=476625 - 6578 = 47
  • Therefore c=47c = 47

Step 6: Decryption verification

  • Ciphertext: c=47c = 47
  • Plaintext: m=cdmodn=47103mod143m = c^d \bmod n = 47^{103} \bmod 143

Since 103103 is large, use modular exponentiation:

  • 103=64+32+4+2+1=26+25+22+21+20103 = 64 + 32 + 4 + 2 + 1 = 2^6 + 2^5 + 2^2 + 2^1 + 2^0

Compute 472imod14347^{2^i} \bmod 143:

  • 47147(mod143)47^1 \equiv 47 \pmod{143}
  • 472=2209mod143=220915×143=22092145=6447^2 = 2209 \bmod 143 = 2209 - 15 \times 143 = 2209 - 2145 = 64
  • 474=(472)2=642=4096mod143=409628×143=40964004=9247^4 = (47^2)^2 = 64^2 = 4096 \bmod 143 = 4096 - 28 \times 143 = 4096 - 4004 = 92
  • 478=(474)2=922=8464mod143=846459×143=84648437=2747^8 = (47^4)^2 = 92^2 = 8464 \bmod 143 = 8464 - 59 \times 143 = 8464 - 8437 = 27
  • 4716=(478)2=272=729mod143=7295×143=729715=1447^{16} = (47^8)^2 = 27^2 = 729 \bmod 143 = 729 - 5 \times 143 = 729 - 715 = 14
  • 4732=(4716)2=142=196mod143=196143=5347^{32} = (47^{16})^2 = 14^2 = 196 \bmod 143 = 196 - 143 = 53
  • 4764=(4732)2=532=2809mod143=280919×143=28092717=9247^{64} = (47^{32})^2 = 53^2 = 2809 \bmod 143 = 2809 - 19 \times 143 = 2809 - 2717 = 92

Now compute 4710347^{103}: 47103=4764×4732×474×472×47147^{103} = 47^{64} \times 47^{32} \times 47^4 \times 47^2 \times 47^1 =92×53×92×64×47(mod143)= 92 \times 53 \times 92 \times 64 \times 47 \pmod{143}

Compute step by step:

  • 92×53=4876mod143=487634×143=48764862=1492 \times 53 = 4876 \bmod 143 = 4876 - 34 \times 143 = 4876 - 4862 = 14
  • 14×92=1288mod143=12889×143=12881287=114 \times 92 = 1288 \bmod 143 = 1288 - 9 \times 143 = 1288 - 1287 = 1
  • 1×64=641 \times 64 = 64
  • 64×47=3008mod143=300821×143=30083003=564 \times 47 = 3008 \bmod 143 = 3008 - 21 \times 143 = 3008 - 3003 = 5

Therefore m=5m = 5, matching the original plaintext ✓

Problem 2: Given RSA public key (n,e)=(143,7)(n, e) = (143, 7), encrypt message m=100m = 100, compute ciphertext.

Detailed Solution:

  • Plaintext: m=100m = 100
  • Check: 100<143100 < 143, so mZ143m \in \mathbb{Z}_{143}
  • Ciphertext: c=memodn=1007mod143c = m^e \bmod n = 100^7 \bmod 143

Compute 1007mod143100^7 \bmod 143:

  • 1002=10000mod143=1000069×143=100009867=133100^2 = 10000 \bmod 143 = 10000 - 69 \times 143 = 10000 - 9867 = 133
  • 1004=(1002)2=1332=17689mod143=17689123×143=1768917589=100100^4 = (100^2)^2 = 133^2 = 17689 \bmod 143 = 17689 - 123 \times 143 = 17689 - 17589 = 100
  • 1007=1004×1002×100=100×133×100=1330000mod143100^7 = 100^4 \times 100^2 \times 100 = 100 \times 133 \times 100 = 1330000 \bmod 143

Compute 1330000mod1431330000 \bmod 143:

  • 133mod143=133133 \bmod 143 = 133 (since 133<143133 < 143)
  • 1330000=133×100001330000 = 133 \times 10000
  • 10000mod143=1000069×143=13310000 \bmod 143 = 10000 - 69 \times 143 = 133
  • Therefore 1330000mod143=133×133mod143=17689mod143=1001330000 \bmod 143 = 133 \times 133 \bmod 143 = 17689 \bmod 143 = 100

So c=100c = 100

Note: In this example mem(modn)m^e \equiv m \pmod{n}, which is due to special properties of m=100m = 100. This generally does not occur.

1.2 RSA Textbook Version vs CPA Secure Version

Exam Focus: Concept Explanation - Why is RSA Textbook Version Insecure?

RSA textbook version has the following security problems:

  1. Deterministic encryption: Same plaintext always produces same ciphertext, attackers can observe patterns
  2. Not CPA secure: Attackers can query encryption oracle, obtaining (mi,miemodn)(m_i, m_i^e \bmod n) pairs, potentially inferring information
  3. Small plaintext attack: If plaintext mm is small (me<nm^e < n), then c=mec = m^e (no modular reduction), attackers can directly compute m=cem = \sqrt[e]{c}
  4. Common modulus attack: If multiple users use same nn but different ee, may be attacked
  5. Low encryption exponent attack: If ee is small and plaintexts are same, may be attacked

Proof Problem: Prove RSA Textbook Version is Not CPA Secure

Proof: Construct attacker AA:

  1. AA chooses two plaintexts m0=0m_0 = 0 and m1=1m_1 = 1
  2. AA queries encryption oracle, receives challenge ciphertext cc^*
  3. If c=0c^* = 0, AA outputs b=0b' = 0; if c=1c^* = 1, AA outputs b=1b' = 1; otherwise AA outputs random guess

Analysis:

  • If b=0b = 0 (encrypt m0=0m_0 = 0), then c=0emodn=0c^* = 0^e \bmod n = 0
  • If b=1b = 1 (encrypt m1=1m_1 = 1), then c=1emodn=1c^* = 1^e \bmod n = 1
  • Therefore AA can perfectly distinguish with success probability 1
  • Therefore RSA textbook version is not CPA secure

CPA Secure RSA (RSA-OAEP):

To achieve CPA security, padding schemes are needed, most commonly OAEP (Optimal Asymmetric Encryption Padding).

RSA-OAEP Encryption Process:

  1. Use OAEP padding to convert plaintext mm to MM (padded message)
  2. Encrypt: c=Memodnc = M^e \bmod n

OAEP Padding (Simplified Description):

  • Use random number rr and hash functions
  • Ensures same plaintext produces different ciphertexts each encryption
  • Provides semantic security

Scheme Design Problem: Design a CPA Secure RSA Encryption Scheme

Scheme: Use RSA-OAEP

Detailed Steps:

  1. Key Generation: Use standard RSA key generation, obtain (n,e,d)(n, e, d)
  2. Encryption:
    • Choose random number r{0,1}kr \leftarrow \{0,1\}^k (kk is security parameter)
    • Use hash functions GG and HH (e.g., SHA-256)
    • Compute X=m0kG(r)X = m || 0^k \oplus G(r) (0k0^k is kk zeros padding)
    • Compute Y=rH(X)Y = r \oplus H(X)
    • Set M=XYM = X || Y
    • If MnM \geq n, reselect rr and repeat
    • Encrypt: c=Memodnc = M^e \bmod n
  3. Decryption:
    • Decrypt: M=cdmodnM = c^d \bmod n
    • Split: M=XYM = X || Y
    • Recover: r=YH(X)r = Y \oplus H(X)
    • Recover: m0k=XG(r)m || 0^k = X \oplus G(r)
    • Verify padding and extract mm

Why is this design CPA secure?

  • Random number rr ensures same plaintext produces different ciphertexts
  • Hash functions provide randomness
  • Under random oracle model, RSA-OAEP can be proven CPA secure