Reference & Analysis# Cheatsheet# 我最后尝试画一个知识树
Crypto fundation# Secure Multi-Party Computation # Shannon/Perfect Privacy# One Time pad# One-way function# PRG# PRFs# PRP# 密码学作业# 第一次作业 One Time Pad & OWF & PRG# Question 1: A Flawed One-Time Pad# Description
Consider a variant of the one-time pad with message space { 0 , 1 } n \{0, 1\}^n { 0 , 1 } n , where n n n is an odd integer, and the secret key space is restricted to all n n n -bit strings with an even number of 1’s. Construct an efficient adversary that compromises perfect secrecy.
Answer:
Let the key set be denoted by K K K : ∣ K ∣ = ∑ i = 0 n − 1 ( n i ) = 2 n − 1 |K|=\sum _{i=0}^{n-1}\binom{n}{i}=2^{n-1} ∣ K ∣ = ∑ i = 0 n − 1 ( i n ) = 2 n − 1
For any m 1 m_1 m 1 with an odd number of 1’s and any m 2 m_2 m 2 with an even number of 1’s, since n n n is odd, we have
Pr s k [ m 1 ⊕ s k = c ] = { 1 2 n − 1 if pop_count ( c ) ≢ 0 m o d 2 0 if pop_count ( c ) ≡ 0 m o d 2 \Pr_{sk}[m_1 \oplus sk = c] = \begin{cases} \frac{1}{2^{n-1}} & \text{if } \text{pop\_count}(c) \not\equiv 0 \mod 2\\ 0 & \text{if } \text{pop\_count}(c) \equiv 0 \mod 2 \end{cases} s k Pr [ m 1 ⊕ s k = c ] = { 2 n − 1 1 0 if pop_count ( c ) ≡ 0 mod 2 if pop_count ( c ) ≡ 0 mod 2 Similarly,
Pr s k [ m 2 ⊕ s k = c ] = { 1 2 n − 1 if pop_count ( c ) ≡ 0 m o d 2 0 if pop_count ( c ) ≢ 0 m o d 2 \Pr_{sk}[m_2 \oplus sk = c] = \begin{cases} \frac{1}{2^{n-1}} & \text{if } \text{pop\_count}(c) \equiv 0 \mod 2\\ 0 & \text{if } \text{pop\_count}(c) \not\equiv 0 \mod 2 \end{cases} s k Pr [ m 2 ⊕ s k = c ] = { 2 n − 1 1 0 if pop_count ( c ) ≡ 0 mod 2 if pop_count ( c ) ≡ 0 mod 2 Thus, an adversary can determine the parity (odd or even) of the number of 1’s in the original message by examining the ciphertext c c c . This additional information compromises perfect secrecy.
Idea:
The original One-Time Pad encryption and decryption processes are defined as follows:
M = { 0 , 1 } n = K Gen ( ⋅ ) → s k , s k ← $ K Enc ( s k , m ) = s k ⊕ m Dec ( s k , c ) = s k ⊕ c M = \{0,1\}^n = K \\ \text{Gen}(\cdot) \to sk, sk \overset{\$}{\leftarrow} K\\ \text{Enc}(sk, m) = sk \oplus m \\ \text{Dec}(sk, c) = sk \oplus c M = { 0 , 1 } n = K Gen ( ⋅ ) → s k , s k ← $ K Enc ( s k , m ) = s k ⊕ m Dec ( s k , c ) = s k ⊕ c Under the condition that s k sk s k is uniformly random, the probability of encrypting m 1 m_1 m 1 and m 2 m_2 m 2 to the same ciphertext c c c is equal, i.e.,
Pr s k [ m 1 ⊕ s k = c ] = Pr s k [ m 2 ⊕ s k = c ] \Pr_{sk}[m_1 \oplus sk = c] = \Pr_{sk}[m_2 \oplus sk = c] s k Pr [ m 1 ⊕ s k = c ] = s k Pr [ m 2 ⊕ s k = c ] However, the modification to the definition of K K K leads to the issue where
Pr s k [ m 1 ⊕ s k = c ] ≠ Pr s k [ m 2 ⊕ s k = c ] if pop_count ( m 1 ) ≢ pop_count ( m 2 ) m o d 2 \Pr_{sk}[m_1 \oplus sk = c] \neq \Pr_{sk}[m_2 \oplus sk = c] \text{ if } \text{pop\_count}(m_1) \not\equiv \text{pop\_count}(m_2) \mod 2 s k Pr [ m 1 ⊕ s k = c ] = s k Pr [ m 2 ⊕ s k = c ] if pop_count ( m 1 ) ≡ pop_count ( m 2 ) mod 2 Question 2: One Way Functions vs Pseudorandom Generators# 2.1# Description
Let G G G be a PRG that maps n n n bits to 2 n 2n 2 n bits, prove that G G G is a (strong) one-way function.
Solution:
The definition of a PRG is that for any algorithm A A A , the probability that A A A can distinguish between the output of G : { 0 , 1 } n → { 0 , 1 } l ( n ) G:\{0,1\}^n\to \{0,1\}^{l(n)} G : { 0 , 1 } n → { 0 , 1 } l ( n ) (in this problem, l ( n ) = 2 n l(n)=2n l ( n ) = 2 n ) on a random input and a truly random string is negligible. Formally,
∣ Pr s ← { 0 , 1 } n , r ← G ( s ) [ A ( r ) = 1 ] − Pr r ← R { 0 , 1 } l ( n ) [ A ( r ) = 1 ] ∣ ≤ n e g l ( n ) |\Pr_{s \leftarrow \{0,1\}^n, r \leftarrow G(s)}[\mathcal A(r)=1]-\Pr_{r \xleftarrow{\mathbb{R}}\{0,1\}^{l(n)}}[\mathcal A(r)=1]| \leq \mathtt{negl}(n) ∣ s ← { 0 , 1 } n , r ← G ( s ) Pr [ A ( r ) = 1 ] − r R { 0 , 1 } l ( n ) Pr [ A ( r ) = 1 ] ∣ ≤ negl ( n ) If G G G is not a one-way function, there exists an efficient algorithm A \mathcal A A that can invert G G G .
Idea:
Assume G ∈ PRG [ { 0 , 1 } n → { 0 , 1 } 2 n ] G \in \text{PRG}[\{0,1\}^n \to \{0,1\}^{2n}] G ∈ PRG [{ 0 , 1 } n → { 0 , 1 } 2 n ] is not a one-way function, then there exists A 0 \mathcal A_0 A 0 such that
Pr x [ f ( A 0 ( G ( x ) ) = G ( x ) ] ⩾ 1 poly ( n ) \Pr_{x}[f(\mathcal A_0(G(x))=G(x)] \geqslant \frac{1}{\text{poly}(n)} x Pr [ f ( A 0 ( G ( x )) = G ( x )] ⩾ poly ( n ) 1 (G G G here is essentially the function f f f in the definition).
In this scenario, consider
A ′ : { 0 , 1 } 2 n → { 0 , 1 } ∣ A ′ ( r ) = [ G ( A 0 ( r ) ) = r ] \mathcal A':\{0,1\}^{2n}\to \{0,1\} \mid \mathcal A'(r)=[G(\mathcal A_0(r))=r] A ′ : { 0 , 1 } 2 n → { 0 , 1 } ∣ A ′ ( r ) = [ G ( A 0 ( r )) = r ] Then,
Pr s ← { 0 , 1 } n , r ← G ( s ) [ A ′ ( r ) = 1 ] = Pr s ← { 0 , 1 } n [ G ( A 0 ( G ( s ) ) ) = G ( s ) ] ⩾ 1 poly ( n ) \Pr_{s \leftarrow \{0,1\}^n, r \leftarrow G(s)}[\mathcal A'(r)=1] = \Pr_{s\leftarrow \{0,1\}^n}[G(\mathcal A_0(G(s)))=G(s)] \geqslant \frac{1}{\text{poly}(n)} s ← { 0 , 1 } n , r ← G ( s ) Pr [ A ′ ( r ) = 1 ] = s ← { 0 , 1 } n Pr [ G ( A 0 ( G ( s ))) = G ( s )] ⩾ poly ( n ) 1 and
Pr r ← R { 0 , 1 } 2 n [ A ′ ( r ) = 1 ] ≤ Pr r ← R { 0 , 1 } 2 n [ ∃ s ∈ { 0 , 1 } n , G ( s ) = r ] = 2 n 2 2 n = 1 2 n \Pr_{r \xleftarrow{\mathbb{R}}\{0,1\}^{2n}}[\mathcal A'(r)=1] \leq \Pr_{r\xleftarrow{\mathbb R}\{0,1\}^{2n}}[\exists s\in \{0,1\}^n,G(s)=r] = \frac{2^n}{2^{2n}} = \frac{1}{2^n} r R { 0 , 1 } 2 n Pr [ A ′ ( r ) = 1 ] ≤ r R { 0 , 1 } 2 n Pr [ ∃ s ∈ { 0 , 1 } n , G ( s ) = r ] = 2 2 n 2 n = 2 n 1 Thus,
∣ Pr s ← { 0 , 1 } n , r ← G ( s ) [ A ′ ( r ) = 1 ] − Pr r ← R { 0 , 1 } 2 n [ A ′ ( r ) = 1 ] ∣ ≥ ∣ 1 poly ( n ) − 1 2 n ∣ ≥ 1 poly’ ( n ) \left|\Pr_{s \leftarrow \{0,1\}^n, r \leftarrow G(s)}[\mathcal A'(r)=1]-\Pr_{r \xleftarrow{\mathbb{R}}\{0,1\}^{2n}}[\mathcal A'(r)=1]\right| \geq \left|\frac{1}{\text{poly}(n)}-\frac{1}{2^n}\right| \geq \frac{1}{\text{poly'}(n)} s ← { 0 , 1 } n , r ← G ( s ) Pr [ A ′ ( r ) = 1 ] − r R { 0 , 1 } 2 n Pr [ A ′ ( r ) = 1 ] ≥ poly ( n ) 1 − 2 n 1 ≥ poly’ ( n ) 1 Since 1 poly’ ( n ) ≠ n e g l ( n ) \frac{1}{\text{poly'}(n)} \neq \mathtt{negl}(n) poly’ ( n ) 1 = negl ( n ) , this contradicts the initial assumption. Therefore, G G G is a one-way function.
2.2# Description
Given that F F F is a one-way function, construct a function G G G such that:
G G G is a one-way function.G G G is not a pseudorandom generator (PRG).Solution:
Directly provide the construction: Let
F : { 0 , 1 } n → { 0 , 1 } l ( n ) F:\{0,1\}^n\to \{0,1\}^{l(n)} F : { 0 , 1 } n → { 0 , 1 } l ( n ) Construct
G : { 0 , 1 } n → { 0 , 1 } l ( n ) + 1 ∣ G ( r ) = concat ( F ( r ) , { 1 } ) G:\{0,1\}^n\to \{0,1\}^{l(n)+1} \mid G(r)=\text{concat}(F(r),\{\mathtt{1}\}) G : { 0 , 1 } n → { 0 , 1 } l ( n ) + 1 ∣ G ( r ) = concat ( F ( r ) , { 1 }) Here, concat \text{concat} concat denotes the sequential concatenation of two binary sequences. In other words, G G G appends a 1 1 1 to the end of F F F ‘s output.
Proof for OWF:
Since F F F satisfies
∀ A : { 0 , 1 } l ( n ) → { 0 , 1 } n , Pr x ← R { 0 , 1 } n [ F ( A ( F ( x ) ) ) = F ( x ) ] ⩽ n e g l ( x ) \forall \mathcal A:\{0,1\}^{l(n)}\to \{0,1\}^n, \Pr_{x \xleftarrow{\mathbb R}{} \{0,1\}^{n} }[F(\mathcal A(F(x)))=F(x)] \leqslant \mathtt{negl}(x) ∀ A : { 0 , 1 } l ( n ) → { 0 , 1 } n , x R { 0 , 1 } n Pr [ F ( A ( F ( x ))) = F ( x )] ⩽ negl ( x ) If G G G is not OWF, then there exists A 0 : { 0 , 1 } l ( n ) + 1 → { 0 , 1 } n , poly ( ⋅ ) \mathcal A_0:\{0,1\}^{l(n)+1}\to \{0,1\}^n,\text{poly}(\cdot) A 0 : { 0 , 1 } l ( n ) + 1 → { 0 , 1 } n , poly ( ⋅ ) such that
Pr x ← R { 0 , 1 } n [ G ( A 0 ( G ( x ) ) ) = G ( x ) ] ⩾ 1 poly ( n ) \Pr_{x \xleftarrow{\mathbb R}{} \{0,1\}^n}[G(\mathcal A_0(G(x)))=G(x)] \geqslant \frac{1}{\text{poly}(n)} x R { 0 , 1 } n Pr [ G ( A 0 ( G ( x ))) = G ( x )] ⩾ poly ( n ) 1 Then we construct A 0 ′ : 0 , 1 l ( n ) → 0 , 1 n ∣ A 0 ′ ( r ) = A 0 ( concat ( r , 1 ) ) \mathcal A'_0:{0,1}^{l(n)}\to {0,1}^{n} \mid \mathcal {A}'_0(r)=\mathcal A_0(\text{concat}(r,{\mathtt{1}})) A 0 ′ : 0 , 1 l ( n ) → 0 , 1 n ∣ A 0 ′ ( r ) = A 0 ( concat ( r , 1 ))
A 0 ′ \mathcal A_0' A 0 ′ satisfies
Pr x ← R { 0 , 1 } n [ F ( A 0 ′ ( F ( x ) ) ) = F ( x ) ] ⩾ 1 poly ( n ) \Pr_{x \xleftarrow{\mathbb R}{} \{0,1\}^n}[F(\mathcal A_0'(F(x)))=F(x)] \geqslant \frac{1}{\text{poly}(n)} x R { 0 , 1 } n Pr [ F ( A 0 ′ ( F ( x ))) = F ( x )] ⩾ poly ( n ) 1 This contradicts the fact that F F F is an OWF.
Proof for not PRG:
Construct
A ′ ′ : { 0 , 1 } l ( n ) + 1 → { 0 , 1 } ∣ { 1 r l ( n ) + 1 = 1 0 r l ( n ) + 1 = 0 \mathcal A'':\{0,1\}^{l(n)+1}\to \{0,1\} \mid \begin{cases}1 & r_{l(n)+1}=1\\ 0 & r_{l(n)+1}=0\end{cases} A ′′ : { 0 , 1 } l ( n ) + 1 → { 0 , 1 } ∣ { 1 0 r l ( n ) + 1 = 1 r l ( n ) + 1 = 0 Then
∣ Pr s ← { 0 , 1 } n , r ← G ( s ) [ A ( r ) = 1 ] − Pr r ← R { 0 , 1 } l ( n ) + 1 [ A ( r ) = 1 ] ∣ = 1 − 1 2 = 1 2 |\Pr_{s \leftarrow \{0,1\}^n, r \leftarrow G(s)}[\mathcal A(r)=1]-\Pr_{r \xleftarrow{\mathbb{R}}\{0,1\}^{l(n)+1}}[\mathcal A(r)=1]| = 1-\frac{1}{2} = \frac{1}{2} ∣ s ← { 0 , 1 } n , r ← G ( s ) Pr [ A ( r ) = 1 ] − r R { 0 , 1 } l ( n ) + 1 Pr [ A ( r ) = 1 ] ∣ = 1 − 2 1 = 2 1 Clearly, this contradicts the requirement for the PRG definition of being negligible.
In summary, the constructed G G G is a One-Way Function but not a PRG.br