3263 字
16 分钟
数据安全与密码学基础 Cheatsheet & Homework
2024-10-16

Reference & Analysis#

《Introduction to Modern Cryptography》

Introduction-to-modern-cryptography/现代密码学简介.pdf

Contest#

期中#

>

Cheatsheet#

需要证明的部分我会用🙈标出来

期中all in one paper#

*Intro of Crypto#

关于 Cryptography

kryptós /kryp.tós/ → /krypˈtos/ → /kripˈtos/ 表示 “hidden, secret”

把很多”不断加深的概念放在这里”

观念变化#

  • Gen,Enc,Dec不可泄露->可泄露
    • August Kerchoff 1884 密码系统只依赖密钥,方法可以公开
    • “攻击者不能获取额外信息”(关注某些位,长度这些额外信息)
  • 从Shannon和Perfect认为攻击者无限强,后来都认为A\mathcal A是PPT的
    • 不要求绝对均匀
  • 从知识先于零知识到零知识脱离于知识
    • Zero-Knowledge Proof, ZKP,陈述某种陈述的正确性,不泄漏任何陈述本身信息
    • 协议中重要作用
  • 传统密码学
    • 天才cracked game
    • Caesar Cipher (Gen无随机性)
    • Substitution Cipher 改成随机排列,那么我们引入

凯撒密码和变形

原则#

  • 可用性
    • P[Dec(Enc(x))=x]=1\mathbb P[\mathrm{Dec}(\mathrm{Enc}(x))=x]=1
  • 正确性
  • 安全性

对我们关注的Provable Security

  • Precise Definition of Security
  • Mathematic Assumpation
  • Security Proof——Reduction

Crypto Principles#

基础款加密系统定义

{Gen,Enc,Dec,M,K}\{\mathrm{Gen,Enc,Dec,M,K}\}

  • GEN(srand)=sk\mathrm{GEN}(srand)=sk (randomized from K)
  • ENC(sk,M)=C\mathrm {ENC}(sk,M)=C (R/D)
  • DECO(sk,C)=D\mathrm{DECO}(sk,C)=D (deterministic)

Secure Multi-Party Computation#

计算一个关于秘密输入 x1,,xnx_1, \dots, x_n 的函数 ff 。在计算 f(x1,,xn)f(x_1, \dots, x_n) 时,各方希望在不泄露任何额外信息的情况下完成计算,包括各方的秘密输入。针对 f 的 MPC 协议 π\pi 具有以下属性:

  • 正确性 (Correctness):执行协议 π\pi 后,所有参与方都能得出 f(x1,,xn)f(x_1, \dots, x_n) 的值。
  • .完美的、诚实但好奇的 t -串通安全性 (t-security):设 [n][n] 表示参与方集合 {1,,n}\{1, \dots, n\}tt 表示串通的对手方数量。

对于所有大小为 t 的集合 S[n]S \subseteq [n] ,存在一个模拟器 Sim\text{Sim} ,使得对于所有 x1,,xnx_1, \dots, x_n

ViewS(π(x1,,xn))Sim(xS,f(x1,,xn))\text{View}_S(\pi(x_1, \dots, x_n)) \equiv \text{Sim}(x_S, f(x_1, \dots, x_n))

其中,ViewS(π(x1,,xn))\text{View}_S(\pi(x_1, \dots, x_n))表示参与方 ii \in SS 在协议执行期间的可观测状态。

非诚勿扰的例子(?)

两个人出示0/1状态,如何设计协议使得两个人在诚信情况下仅能获取是否同为1的结果(舔狗如何保护自己)

设计表格

AB
10110
01001

然后按照 sa|1|sb 的方式连接成环

容易发现,只有11的情况是有长度为3的1连续段的

Shannon/Perfect Privacy#

介绍香农/完美安全互化,并陈述其局限性。本质是基于纯随机的等价概率分布的生成。

Shannon vs Perfect#

两个形式

Shannon t,c,PmD[m=t]=PmD,skGen[m=tEnc(sk,m)=c]\forall t,c,\mathbb P_{m\leftarrow D}[m=t]=\mathbb P_{m\leftarrow D,sk\leftarrow \mathrm{Gen}}[m=t\mid \mathrm{Enc}(sk,m)=c]

Perfect m1,m2,PskGen[Enc(sk,m1)=c]=PskGen[Enc(sk,m2)=c]]\forall m_1,m_2,\mathbb P_{sk\leftarrow \mathrm{Gen}}[\mathrm{Enc}(sk,m1)=c]=\mathbb P_{sk\leftarrow \mathrm{Gen}}[\mathrm{Enc}(sk,m2)=c]]

Theorem

上述定义等价🙈

Hint:全概率展开

有一个推论

Shannon’s theorem

假设M=K=C|M|=|K|=|C|,则我们有完美安全等价于kk概率均匀分布,Enc(k,m)=c\mathrm{Enc}(k,m)=c,对于给定的m,cm,c,kk是唯一的

One Time pad#

M={0,1}n=KGen()sk,skKEnc(sk,m)=skmDec(sk,m)=skcM=\{0,1\}^n=K\\\mathrm{Gen}(\cdot)\to sk,sk\xleftarrow {\not\$}K\\\mathrm{Enc}(sk,m)=sk\oplus m\\\mathrm{Dec}(sk,m)=sk\oplus c

显然有Psk[skm=c]=Psk[sk=mc]\mathbb P_{sk}[sk\oplus m=c]=\mathbb P_{sk}[sk=m\oplus c],这里出一个问题,长密钥保护短内容

OTP是Shannon-secure的

Theorem

香农安全必定有KM|K|\geqslant |M|🙈

Hint:从映射不完全性出发

One-way function#

Turing machine 假设

M\mathcal M是一个图灵机T(M)T(\mathcal M)表示x{0,1}\forall \mathbf x\in \{0,1\}^*M\mathcal M会在T(x)T(|x|)内停下

A\mathcal Aadversary ,其满足PPT(随机性多项式时间),即攻击力有限

最后强调一下,nn是数据量规模,不是数据个数,大数的贡献是位数

  • Worst one-way function

    • easy to compute M(P),x{0,1},M(x)=f(x)\exist \mathcal M(P),\forall x\in\{0,1\}^*,\mathcal M(x)=f(x)
    • hard to invert, 不存在 A\mathcal A, P[A(f(x))=tf(x)=f(t)]=1\mathbb P[A(f(x))=t\mid f(x)=f(t)]=1
  • strong one-way function(默认均指这个)

    • Ar,Px,r[A(f(x))=tf(x)=f(t)]negl(n)\forall \mathcal A^r,\mathbb P_{x,r}[A(f(x))=t\mid f(x)=f(t)]\leqslant \mathtt {negl}(n)
  • *weak one-way function(其实不管,比较复杂,OWF是一个family)

    • Ar,Px,r[A(f(x))=tf(x)=f(t)]11poly\forall \mathcal A^r,\mathbb P_{x,r}[A(f(x))=t\mid f(x)=f(t)]\leqslant 1-\frac{1}{\mathrm{poly}}
eg

Pn\mathcal P_n 表示 P[2n1,2n1]\mathcal P \cap [2^{n-1},2^{n}-1]即二进制为nn位的素数集合

f:Pn×Pn{0,1}2nf:\mathcal P_n\times \mathcal P_n\to \{0,1\}^{2n}为一个OWF

由素数定理π(n)nlnn\pi(n)\approx\frac{n}{\ln n}

Pn=π(2n)2nn|\mathcal P_n|=\pi (2^n)\approx\frac{2^n}{n}

Ar,Px,r[A(f(x))=tf(x)=f(t)]=P(p,q)$Pn×Pn[A(z)=(p,q)pq=pq=z] =P(p,q)$Pn×Pn[A(z)=pq]=negl(n)\begin{align*} \forall \mathcal A^r,\mathbb P_{x,r}[\mathcal A(f(x))=t\mid f(x)=f(t)]&=\mathbb P_{(p,q)\xleftarrow{\$}\mathcal P_n\times \mathcal P_n}[\mathcal A (z)=(p',q')\mid p'q'=pq=z]\ \\&=\mathbb P_{(p,q)\xleftarrow{\$}\mathcal P_n\times \mathcal P_n}[\mathcal A (z)=pq]=\mathtt {negl}(n) \end{align*}

也即大数分解的概率

这里张聪上课说错了,不能直接用素数密度定理直接说明这个OWF性质

换一个

g:{0,1}n×{0,1}n{0,1}2n:g(x,y)=xyg:\mathcal \{0,1\}^n \times \{0,1\}^n\to \{0,1\}^{2n}:g(x,y)=xy

这个显然就不是strong OWF

我们取Pn×Pn{0,1}n×{0,1}n\mathcal P_n\times \mathcal P_n\subseteq \{0,1\}^n\times \{0,1\}^n,这部分选取概率为

P[(x,y)Pn×Pn]=Pn222n14n2\mathbb P[(x,y)\in \mathcal P_n\times \mathcal P_n]=\frac{|\mathcal P_n|^2}{2^{2n}}\approx\frac{1}{4n^2}

P(p,q)${0,1}n×{0,1}n[A(z)=(p,q)pq=pq=z]114n2\mathbb P_{(p,q)\xleftarrow{\$}\{0,1\}^n\times \{0,1\}^n}[\mathcal A (z)=(p',q')\mid p'q'=pq=z]\leqslant 1-\frac{1}{4n^2}

这里我跳步了

hc

给定一个函数 ff ,若存在一个函数 hc:{0,1}{0,1}\text{hc} : \{0,1\}^* \rightarrow \{0,1\} 满足以下条件,则称 \text{hc} 是 f 的hard-core predict:

  • 可计算性

    hc\text{hc}

    可以在多项式时间内计算。

  • 难以预测性:对于任意概率多项式时间算法

    A\mathcal A

    ,存在一个可忽略函数

    negl(n)\text{negl}(n)

    ,使得

Px0,1n[A(1n,f(x))=hc(x)]12+negl(n)\mathbb P_{x \leftarrow {0,1}^n} \left[ \mathcal A(1^n, f(x)) = \text{hc}(x) \right] \leq \frac{1}{2} + \text{negl}(n)

PRG#

stream password

魔改OTP

Gen(1n)seed${0,1}nEnc(seed,m)skmDec(seed,c)skc\begin{align*}\mathrm{Gen}(1^n)&\to seed \overset{\$}{\leftarrow} \{0,1\}^n\\\mathrm{Enc}(seed,m)&\to sk\oplus m\\\mathrm{Dec}(seed,c)&\to sk\oplus c\end{align*}

这里需要一个混淆seed和sk的东西

引入一个补充概念

EAV-secure/Semantic Security
Ar,i,P[A(1n,Enc(sk,m))=mi]12+negl(n)\forall \mathcal A^r,i,\mathbb P[\mathcal A(1^n,\mathrm{Enc}(sk,m))=m_i]\leqslant \frac{1}{2}+\mathtt {negl}(n)

实质上就是我们不能够通过对于加密结果的分析获取对于数据任意字段的信息

简单描述下PRG基于的游戏过程

chn,Gen,Enc,DecAAm0,m1,m0=m1chchb{0,1},skGen(1n)Enc(sk,mb)AAbchch\xrightarrow []{n,\mathrm {Gen,Enc,Dec}}\mathcal A\\ \mathcal A\xrightarrow {m_0,m_1,|m_0|=|m_1|}ch\\ ch\xrightarrow [b\leftarrow \{0,1\},sk\leftarrow \mathrm{Gen}(1^n )]{\mathrm{Enc(sk,m_b)}}\mathcal A\\ \mathcal A \xrightarrow {b'}ch

一句话就是A无法依赖ch给出的加密范式,区分自己提供的(也就是任意的)密文加密后的结果

给予一些额外的数学原理我们右

EVA-another definition

π=(Enc,Dec)\pi = (\mathrm{Enc},\mathrm{Dec}) os EVA iff:

Ar,f:{0,1}n{0,1},D,AP[A(1n,Enc(sk,m))=f(m)]A(1n)=f(m)negl(n)\forall \mathcal A^r,f:\{0,1\}^n\to \{0,1\},\mathcal D,\exist \mathcal A' \\\left|\mathbb P[\mathcal A(1^n,\mathrm{Enc}(sk,m))=f(m)]-\mathcal A'(1^n)=f(m)\right|\leqslant \mathtt {negl}(n)

依赖上述过程我们可以给出PRG的标准定义

PRG def

G:1n1l(n)G:1^n\to 1^{l(n)} ,则其为一个伪随机生成器的充要条件为(这里我为了一致性,懒得区分这里的D\mathcal DA\mathcal A了,假设你乐意可以自行区分)

Ar:{0,1}l(n)PPT{0,1},Prs{0,1}n,rG(s)[A(r)=1]Prr${0,1}l(n)[A(r)=1]negl(n)\forall \mathcal A^r:\{0,1\}^{l(n)}\xrightarrow{PPT} \{0,1\},\left|\Pr_{s \leftarrow \{0,1\}^n, r \leftarrow G(s)}[\mathcal A(r)=1]-\Pr_{r \xleftarrow{\$}\{0,1\}^{l(n)}}[\mathcal A(r)=1]\right| \leq \mathtt{negl}(n)

这里有一个外包任务,我们可以依赖EVA-secure的游戏形式构造reduction

在PRG中,我们往这个有些一半丢均匀分布,一般丢G(x)G(x)生成的分布,A\mathcal A'的优势可忽略

image-20241105103551795

PRG chain(hybrid argument)#

这里我们先给出尽量严谨的论述

PRG可扩展定理

假设G:{0,1}n{0,1}n+1G:\{0,1\}^n\to \{0,1\}^{n+1},则我们可以对任意poly(n)\mathrm{poly}(n)生成G^:{0,1}n{0,1}poly(n)\hat G :\{0,1\}^n\to \{0,1\}^{\mathrm{poly(n)}}

这里我不知道为什么老师要取poly(n)=2n\mathrm {poly}(n)=2n,也不知道有什么特殊性,注意这里千万不要认为这个迭代过程可以无限,换句话这个迭代过程的次数关于nn为常数

image-20241105105554392

上述证明称为 hybrid argument 这里不做解释 (P282)

Multi-message-secure#

容易发现我们之前构造的流密码,缩短了sk但是还是只能一次一密,我们可以利用异或的可逆性构造冲撞,获取额外信息,考虑下面的游戏

chM0,M1Gen,Enc,DecAchEnc(sk,Mb)(M0,1M0,k),(M1,1M1,k)Achb{Enc(Mb,)}Ach\overset{\overset{\mathrm{ Gen,Enc,Dec}}{\to } }{\tiny{M_0,M_1}}A\\\\ch\overset{\overset{(M_{0,1}\cdots M_{0,k}),(M_{1,1}\cdots M_{1,k})}{\leftarrow}}{\tiny \mathrm {Enc}(sk,M_b)} A\\ch\xleftrightarrow[b']{\{\mathrm{Enc}(M_{b,*})\}}\mathcal A

当我们提供来选择的消息为阵列时,情况有所不同

下面给出了一种方案

Enc(sk,m,r)(G(skr)M,r)(c1,c2)Dec(sk,c1,c2)G(skc2)c1\mathrm{Enc}(sk,m,r)\to (G(sk||r)\oplus M,r)\to (c_1,c_2)\\ \mathrm{Dec}(sk,c_1,c_2)\to G(sk||c_2)\oplus c_1

在这个意义上,我们泄露了一部分sksk',达成了安全性

IND-CPA#

IND-CPA:indistinguishabable chosen-plaintext-attacks

从这个出发

  • Initial Phase
chGen,Enc,DecAch\xrightarrow {\mathrm{Gen,Enc,Dec}}A\\

然后执行多轮

chEncsk(mi)miAch\xleftrightarrow [\mathrm{Enc}_{sk}(m_i)]{m_i}A\\

这记为Phase1

  • challaenge Phase(注意这种二择一的只有一次)
chEncsk(mb)m1,m2Ach\xleftrightarrow [\mathrm{Enc}_{sk}(m^*_{b})]{m^*_{1},m_{2}^*}A\\
  • Phase2
chEncsk(mi)miAch\xleftrightarrow [\mathrm{Enc}_{sk}(m_i)]{m_i}A\\

最后猜bb'

下面我们考虑说明IND-CPA与Multi-Msg-Secure 的关系

回顾Multi-Msg PrivkA,IImult(n)\mathsf {Privk}^{\mathrm{mult}}_{\mathcal A,\mathrm{II}} (n)

chM0,M1Gen,Enc,DecAchEnc(sk,Mb)(M0,1M0,k),(M1,1M1,k)Ach\overset{\overset{\mathrm{ Gen,Enc,Dec}}{\to } }{\tiny{M_0,M_1}}A\\\\ch\overset{\overset{(M_{0,1}\cdots M_{0,k}),(M_{1,1}\cdots M_{1,k})}{\leftarrow}}{\tiny \mathrm {Enc}(sk,M_b)} A

在本题中的IND-CPA范式实际上可以用更强形式表示 CPA2

CPA2→Multi-Msg S显然

每次都可以问mi,0/1m_{i,0/1}然后回答Enc(mi,b)\mathrm{Enc}(m_{i,b})

换句话对这个CPA,其问题都形如

chEncsk(mi,b)mi,1,mi,2Ach\xleftrightarrow [\mathrm{Enc}_{sk}(m^*_{i,b})]{m^*_{i,1},m_{i,2}^*}A\\

CPA2→CPA可以直接将二择一的问变成确定问,这个reduce是显然的

CPA→CPA2是构造一个hybrid argument

1个power怎么扩展

用CPA来勾连b=0到b=1

这里我感性的描述下这个Game set

Game0:

分别问,(m10,m11),(mi0,mi1)(m_{10},m_{11}),\cdots(m_{i0},m_{i1}),全部回答bi=0b_i=0

Game1:

分别问,(m10,m11),(mi0,mi1)(m_{10},m_{11}),\cdots(m_{i0},m_{i1}),除了第一个全部回答bi=0b_i=0

Game2:

分别问,(m10,m11),(mi0,mi1)(m_{10},m_{11}),\cdots(m_{i0},m_{i1}),除了前两个全部回答bi=0b_i=0

一句话,你最后是希望区分全0和全1

上面GameiGame_iGamei+1Game_{i+1}本质上就是前缀的1多了一个一位,能利用CPA来分界搭桥(新引入的一位是challange phase),最后就能搭一个长桥

PRFs#

对于

F=F({0,1}n,{0,1}n)\mathcal F=F(\{0,1\}^n,\{0,1\}^n)

我们有F=(2n)2n|\mathcal F|=(2^n)^{2^n},这里我们希望能够随便选取一个FIF_I,但显然这个随机生成的代价太大,这里我们引入

PRFs

FI\mathcal F_I为一个被II索引的映射集合(题库),其是伪随机的当且仅当游戏成立

ch首先把FI\mathcal F_I给A

然后ch自己在II里面选一个sk,bb随便定

然后A反复问m1m_1,ch根据bb反复回答Fsk(mi)F_{sk}(m_i)yiy_i

P[b=b]=12+negl(n)\mathbb P[b=b']=\frac{1}{2}+\mathtt{negl}(n)

更形式化

P[D(Fsk(1n)=1)]P[D(f(1n)=1)]negl(n)\left|\mathbb P[\mathcal D(F_{sk}(1^n)=1)]-\mathbb P[\mathcal D(f(1^n)=1)]\right|\leqslant \mathtt{negl}(n)

IND-CPA 2 PRFs#

Gen(1)sk,{F}IEnc(sk,m,r)=(r,Fsk(r)m)Dec(sk,c1,c2)=c2Fsk(r)\mathrm{Gen}(1')\to sk,\{\mathcal F\}_I\\\mathrm{Enc}(sk,m,r)=(r,F_{sk}(r)\oplus m)\\\mathrm{Dec}(sk,c_1,c_2)=c_2\oplus F_{sk}(r)

PRFs 2 IND-CPA#

对Reduction层面

ch给R FI\mathcal F_I,自己生成sksk

R基于定义生成Gen.Enc,Dec\mathrm{Gen.Enc,Dec}给A

A丢回去m1m_1,R顺带给出r1r_1,ch回答str1str_1

然后R→(r1,str1m1)(r_1,str_1\oplus m_1)→A

来A发出一次灵魂challenge

m0,m1m_0^*,m_1^*,然后返回一个

Enc(md)\mathrm{Enc}(m_d^*),猜测正确与否对应b=0/1b'=0/1,再回去对照bb

PRG 2 PRFs#

还是hybrid argument

image-20241105112820050

相当于你需要从[0,2n)[0,2^n)0[0,2n)0→[0,2^n)全1

首先我们假定GG是PRG

Game0G

Game1但是层1反

Game1但是层1,2反

这里一个问题是Game n-1这个间隔有2n12^{n-1},是不能用hybrid argument

显然我们是求解具体一个O(q)\mathcal O(q)的发问,因此完善这部分即可

PRFs 2 PRG#

这个是显然的,一位一位即可

PRPs#

PRPs

PI\mathcal P_I为一个被II索引的映射集合(题库),其是伪随机的当且仅当游戏成立

ch首先把PI\mathcal P_I给A

然后ch自己在II里面选一个sk,bb随便定

然后A反复问(m0,P)(m_0,\mathcal P)或者(m1,P1)(m_1,\mathcal P^{-1}),然后A这边根据问题回答

P[b=b]=12+negl(n)\mathbb P[b=b']=\frac{1}{2}+\mathtt{negl}(n)

形式化定义如下

P[D(Psk(1n)=1)]P[D(π(1n)=1)]negl(n)P[D(Psk1(1n)=1)]P[D(π1(1n)=1)]negl(n)\left|\mathbb P[\mathcal D(P_{sk}(1^n)=1)]-\mathbb P[\mathcal D(\pi(1^n)=1)]\right|\leqslant \mathtt{negl}(n)\\ \left|\mathbb P[\mathcal D(P^{-1}_{sk}(1^n)=1)]-\mathbb P[\mathcal D(\pi^{-1}(1^n)=1)]\right|\leqslant \mathtt{negl}(n)

Cipher-Block-Chaining#

Enc(m,sk,r)=(r,Fskm)\mathrm {Enc}(m,sk,r)=(r,F_{sk}\oplus m)

我们希望节省sk生成的开销

一个循环利用的想法应运而生

Enc(sk,m1m2mt,r)=(r,Fsk(r)m1,Fsk(c1)m2,,Fsk(ct1)mt)\mathrm{Enc}(sk,m_1||m_2||\cdots m_t,r)=(r,F_{sk}(r)\oplus m_1,F_{sk}(c_1)\oplus m_2,\cdots,F_{sk}(c_{t-1})\oplus m_t)

但显然这里FF用到了异或可逆的性质,因此更一般的我们需要给出PRPs,实现(r,Pk(m,r))m(r,P_k(m,r))\leftrightarrow m

  • CBC
  • OFB
  • CTR

MAC#

这部分我们暂时不看机密性,我们开始关注可信性

MAC(sk,m)τ,(m,τ)\mathrm{MAC}(sk,m)\to \tau,(m,\tau)

真实的数字签名没有sk

攻击者必须仿造(m,τ)(m',\tau')

unforgeability chosen message attack(UCMA)

UCMA模型的安全性通常与数字签名的存在性不可伪造性(Existential Unforgeability)相关联。如果一个数字签名方案在UCMA模型下是安全的,那么可以认为该方案具有EUF-CMA(Existential Unforgeability under Chosen Message Attacks)的安全性

整体思路是设计

{Gen(1n)skMAC(sk,m)τVerify(sk,τ,m){0,1}\begin{cases}\mathrm{Gen}(1^n)\to sk\\\mathrm{MAC}(sk,m)\to \tau\\\mathrm{Verify}(sk,\tau,m)\in \{0,1\}\end{cases} chGen,MAC,VerifyAchMACsk(m1)/Verifysk(m1)m1/(m1,τ1)AchMACsk(mt)mtAchτmAch\xrightarrow {\mathrm{Gen,MAC,Verify}} \mathcal A\\ch\xleftrightharpoons[\mathrm{MAC}_{sk}(m_1)/\mathrm{Verify_{sk}}(m_1)]{\mathrm{m_1}/(m_1,\tau_1)} \mathcal A\\\cdots\\ch\xleftrightharpoons[\mathrm{MAC}_{sk}(m_t)]{\mathrm{m_t}} \mathcal A\\ch\xleftarrow[\tau^*]{\mathrm{m^*}} \mathcal A

P[A wins]=P[Verify(m,τ)=1]=negl(n)\mathbb P[A~wins]=\mathbb P[\mathrm{Verify(m^*,\tau^*)}=1]=\mathtt{negl}(n)

注意A\mathcal A这次开挂了,相当于本地可以一直跑,跑好了才找人

密码学作业#

第一次作业 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, where nn is an odd integer, and the secret key space is restricted to all nn-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 KK: K=i=0n1(ni)=2n1|K|=\sum _{i=0}^{n-1}\binom{n}{i}=2^{n-1}

For any m1m_1 with an odd number of 1’s and any m2m_2 with an even number of 1’s, since nn is odd, we have

Prsk[m1sk=c]={12n1if pop_count(c)≢0mod20if pop_count(c)0mod2\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}

Similarly,

Prsk[m2sk=c]={12n1if pop_count(c)0mod20if pop_count(c)≢0mod2\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}

Thus, an adversary can determine the parity (odd or even) of the number of 1’s in the original message by examining the ciphertext cc. This additional information compromises perfect secrecy.

Idea:

The original One-Time Pad encryption and decryption processes are defined as follows:

M={0,1}n=KGen()sk,sk$KEnc(sk,m)=skmDec(sk,c)=skcM = \{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

Under the condition that sksk is uniformly random, the probability of encrypting m1m_1 and m2m_2 to the same ciphertext cc is equal, i.e.,

Prsk[m1sk=c]=Prsk[m2sk=c]\Pr_{sk}[m_1 \oplus sk = c] = \Pr_{sk}[m_2 \oplus sk = c]

However, the modification to the definition of KK leads to the issue where

Prsk[m1sk=c]Prsk[m2sk=c] if pop_count(m1)≢pop_count(m2)mod2\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

Question 2: One Way Functions vs Pseudorandom Generators#

2.1#

Description

Let GG be a PRG that maps nn bits to 2n2n bits, prove that GG is a (strong) one-way function.

Solution:

The definition of a PRG is that for any algorithm AA, the probability that AA can distinguish between the output of G:{0,1}n{0,1}l(n)G:\{0,1\}^n\to \{0,1\}^{l(n)} (in this problem, l(n)=2nl(n)=2n) on a random input and a truly random string is negligible. Formally,

Prs{0,1}n,rG(s)[A(r)=1]PrrR{0,1}l(n)[A(r)=1]negl(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)

If GG is not a one-way function, there exists an efficient algorithm A\mathcal A that can invert GG.

Idea:

Assume GPRG[{0,1}n{0,1}2n]G \in \text{PRG}[\{0,1\}^n \to \{0,1\}^{2n}] is not a one-way function, then there exists A0\mathcal A_0 such that

Prx[f(A0(G(x))=G(x)]1poly(n)\Pr_{x}[f(\mathcal A_0(G(x))=G(x)] \geqslant \frac{1}{\text{poly}(n)}

(GG here is essentially the function ff in the definition).

In this scenario, consider

A:{0,1}2n{0,1}A(r)=[G(A0(r))=r]\mathcal A':\{0,1\}^{2n}\to \{0,1\} \mid \mathcal A'(r)=[G(\mathcal A_0(r))=r]

Then,

Prs{0,1}n,rG(s)[A(r)=1]=Prs{0,1}n[G(A0(G(s)))=G(s)]1poly(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)}

and

PrrR{0,1}2n[A(r)=1]PrrR{0,1}2n[s{0,1}n,G(s)=r]=2n22n=12n\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}

Thus,

Prs{0,1}n,rG(s)[A(r)=1]PrrR{0,1}2n[A(r)=1]1poly(n)12n1poly’(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)}

Since 1poly’(n)negl(n)\frac{1}{\text{poly'}(n)} \neq \mathtt{negl}(n), this contradicts the initial assumption. Therefore, GG is a one-way function.

2.2#

Description

Given that FF is a one-way function, construct a function GG such that:

  • GG is a one-way function.
  • GG 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)}

Construct

G:{0,1}n{0,1}l(n)+1G(r)=concat(F(r),{1})G:\{0,1\}^n\to \{0,1\}^{l(n)+1} \mid G(r)=\text{concat}(F(r),\{\mathtt{1}\})

Here, concat\text{concat} denotes the sequential concatenation of two binary sequences. In other words, GG appends a 11 to the end of FF‘s output.

Proof for OWF:

Since FF satisfies

A:{0,1}l(n){0,1}n,PrxR{0,1}n[F(A(F(x)))=F(x)]negl(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)

If GG is not OWF, then there exists A0:{0,1}l(n)+1{0,1}n,poly()\mathcal A_0:\{0,1\}^{l(n)+1}\to \{0,1\}^n,\text{poly}(\cdot) such that

PrxR{0,1}n[G(A0(G(x)))=G(x)]1poly(n)\Pr_{x \xleftarrow{\mathbb R}{} \{0,1\}^n}[G(\mathcal A_0(G(x)))=G(x)] \geqslant \frac{1}{\text{poly}(n)}

Then we construct A0:0,1l(n)0,1nA0(r)=A0(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}}))

A0\mathcal A_0' satisfies

PrxR{0,1}n[F(A0(F(x)))=F(x)]1poly(n)\Pr_{x \xleftarrow{\mathbb R}{} \{0,1\}^n}[F(\mathcal A_0'(F(x)))=F(x)] \geqslant \frac{1}{\text{poly}(n)}

This contradicts the fact that FF is an OWF.

Proof for not PRG:

Construct

A:{0,1}l(n)+1{0,1}{1rl(n)+1=10rl(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}

Then

Prs{0,1}n,rG(s)[A(r)=1]PrrR{0,1}l(n)+1[A(r)=1]=112=12|\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}

Clearly, this contradicts the requirement for the PRG definition of being negligible.

In summary, the constructed GG is a One-Way Function but not a PRG.br

数据安全与密码学基础 Cheatsheet & Homework
https://zzw4257.cn/posts/is-pro/密码学/
作者
zzw4257
发布于
2024-10-16
许可协议
CC BY-NC-SA 4.0