Skip to content

Commit

Permalink
update 3.1
Browse files Browse the repository at this point in the history
  • Loading branch information
YuZhang committed Sep 11, 2021
1 parent f6907ae commit 53cd85e
Show file tree
Hide file tree
Showing 8 changed files with 110 additions and 48 deletions.
2 changes: 1 addition & 1 deletion misc/tikztest/tikz-test.tex
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
\begin{frame}\frametitle{Tikz Test}
\begin{figure}
\begin{center}
\input{../../tikz/ellipticcurve}
\input{../../tikz/reduction-prg}
\end{center}
\end{figure}
\end{frame}
Expand Down
5 changes: 4 additions & 1 deletion notes-Chinese/2 完美保密.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

1. 在本节课程中,我们学习信息论下的安全——完美保密。

2. 目录:定义与属性,一次一密,完美保密的局限性,香农定理,窃听不可区分性
2. 目录:定义与属性,一次一密,完美保密的局限性,香农定理,窃听不可区分性。这里我们将学习若干等价的完美保密定义,从不同角度理解同一个理论。

3. 回顾加密词法

Expand Down Expand Up @@ -123,5 +123,8 @@
15. 总结

- 完美保密 = 完美不可区分 = 敌手不可区分
- 知道密文对猜测明文没有帮助
- 给定明文对推测密文没有帮助
- 任意明文加密成某个密文的概率是相同的
- 完美保密是可获得的。一次一密。
- 香农定理(可操作的完美保密)
44 changes: 28 additions & 16 deletions notes-Chinese/3.1 私钥加密与伪随机性-第一部分.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

- 一个算法是多项式时间的(polynomial time),如果存在一个多项式使得对于任意输入,算法都在该多项式步骤内结束。
- 一个算法可以在多项式时间内以任何多项式时间算法作为子历程来运行;
- 概率(probabiistic)算法有“掷硬币”的能力。其中,随机数生成器应该是为密码学用途来设计的,而不是C语言里的`random()`。相反地,没有随机性的算法就是确定性的;
- 概率(probabilistic)算法有“掷硬币”的能力。其中,随机数生成器应该是为密码学用途来设计的,而不是C语言里的`random()`。相反地,没有随机性的算法就是确定性的;
- 开放问题:概率性的敌手比确定性的敌手更强大吗?$\mathcal{P} = \mathcal{BPP}$ (限定错误的概率多项式)?

7. 可忽略的成功概率
Expand All @@ -43,7 +43,7 @@

8. 渐进方法(Asymptotic)

- 根据上面的基础,采用渐进方法来定义安全,所谓“渐进”是指不研究一个固定的问题的复杂性,而是研究时间复杂性随着问题参数$n$的变化而变化的规律;
- 根据上面的基础,采用渐进方法来定义安全,所谓“渐进”是指不研究一个参数固定的问题的复杂性,而是研究时间复杂性随着问题参数$n$的变化而变化的规律;
- 问题X(破解加密方案)是难的,若X不能由任何多项式时间算法以时间$t$解决,除非以可忽略的概率$\varepsilon$
- $t$和$\varepsilon$都描述为安全参数$n$(通常是密钥长度)的函数
- 注意:安全是对足够大的$n$值来说的
Expand Down Expand Up @@ -80,24 +80,24 @@
- 之前在导论部分有一个问题如何定义不泄漏“meaningful”的信息,下面引入语义安全的概念
- 直觉:没有关于明文的任何有意义的信息泄漏
- 关于明文的信息用明文的函数来表示,$h(m)$表示敌手预先了解的关于明文的外部信息,$f(m)$表示敌手希望获取的关于明文的有意义的信息
- 定义:加密方案是窃听者出现时语义上安全的,如果对于任意敌手,任意明文分布,任意$f$和$h$函数,一个敌手根据密文和$h(m)$获得$f(m)$,另一个敌手只根据$h(m)$获得$f(m)$,这两个敌手成功的概率之间的差异是可以忽略的
- 定义:加密方案是窃听者出现时语义上安全的,如果对于任意敌手,任意明文分布,任意函数$f$和$h$,一个敌手根据密文和$h(m)$获得$f(m)$,另一个敌手只根据$h(m)$获得$f(m)$,这两个敌手成功的概率之间的差异是可以忽略的
- 定理:一个私钥加密方案是窃听者不可区分的,当且仅当该方案是语义安全的。
- 证明略。直觉上,若敌手能够在不可区分实验中成功,则意味着根据密文获得了关于区分明文的某些信息;反之,若敌手能够获得获得关于明文的某些信息,那么可以利用这些信息来区分明文。
- 证明略。直觉上,从右到左:若敌手能够在不可区分实验中成功(不是不可区分的),则意味着根据密文获得了关于区分明文的某些信息(不是语义安全);反之,若敌手能够获得关于明文的某些信息(不是语义安全),那么可以利用这些信息来区分明文(不是不可区分的)

14. 伪随机性概念(Pseudorandomness)

- 回顾之前完美保密的局限性,密钥长度需要和明文一样长才安全;计算安全中放松了安全的定义,那密钥能不能短一些,或者说产生足够长但不完全随机的密钥?
- 真随机性不能由一个可描述的机制产生。这里的“可描述的机制”显然是不包括“掷骰子”,而是指确定性的机制;
- 伪随机对于不知道其机制的观察者来说看起来是真的随机;
- 一个固定的字符串谈不上是否是伪随机的,伪随机指的是一个分布;
- 问题:能否绝对地证明随机性?不能,因为我们可能就是不知道其机制的观察者
- 问题:能否绝对地证明随机性?不能,因为我们可能是不知道其机制的观察者

15. 区分器(Distinguisher):统计测试

- 区分是否随机的一类务实的方法是从一个随机生成器中得到多个随机序列并进行一套统计测试。
- 例如,序列中0和1的数量之差不应该太大,最大连续0的长度不应该太长等等。
- 伪随机性意味着**下一比特不可预测**(next-bit unpredictable),通过所有下一比特测试等且仅当通过所有统计测试。(这是姚期智的贡献)
- 问题是难以确定多少测试才足够
- 问题是难以确定多少测试才足够

16. 定义伪随机性的直觉

Expand All @@ -111,40 +111,52 @@
- 伪随机:对于任意PPT区分器$D$,$\left|\Pr[D(r)=1] - \Pr[D(G(s))=1]\right| \le \mathsf{negl}(n)$。其中,$r$是随机的,种子$s$随机的,$\ell(\cdot)$是延展因子。这里的意思是输出不同结果的概率差可以忽略,如果有一个区分器始终输出1,则两个概率都是1,差为0;另外,输出1并不需要表示特定含义,改成输出0也可以。
- 存在性:若单项函数存在或$\mathcal{P} \ne \mathcal{NP}$,则PRG存在。后面我们会进一步学习。

18. 关于PRG的一些问题
18. 真实案例

- C语言的random()
- Netscape早期版本的漏洞https://people.eecs.berkeley.edu/~daw/papers/ddj-netscape.html

19. 关于PRG的一些问题

- 利用下一比特不可预测,还有PRG的不可区分实验定义

19. 充分种子空间
20. 充分种子空间

- 稀疏输出:当扩展因子为$2n$时,在长度为$2n$的串中只会产生$2^{-n}$。
- 蛮力攻击:给定无穷的时间,通过枚举所有种子来产生所有串,能以较高的概率区分出伪随机串。
- 充分种子空间:种子必须长来抵抗蛮力攻击。

20. 一个安全的定长加密方案
21. 不充分的随机性

- 2008年,为了避免一个编译警告,Debian的一个发布版本中误删了一行代码,引起OpenSSL中关于随机生成器的漏洞。

22. 一个安全的定长加密方案

- $|G(k)| = \ell(|k|)$, $m \in \{0,1\}^{\ell(n)}$, 一个PRG以长度为$n$的密钥作为种子,输出与明文相同长度的pad;
- $\mathsf{Gen}$: $k \in \{0,1\}^n$,密钥作为种子,长度小于明文长度;
- $\mathsf{Enc}$: $c := G(k)\oplus m$,加密方法和一次一密一样;
- $\mathsf{Dec}$: $m := G(k)\oplus c$,解密也是;
- 定理:该定长加密方案是窃听下不可区分的。
- 直觉上,这个方案和一次一密是类似的,除了密钥更短并且用伪随机生成器生成的比特串来与明文异或。因为伪随机对于任何敌手都可以认为是真随机,所以对于敌手而言,该方案与一次一密是一样的。

21. 规约法(**Reduction**
23. 规约法(**Reduction**

- 规约法是将一个问题A变换为另一个问题B。变换的意思可以理解为,A可以通过解决B来解决;
- 规约$A \le_m B$:$A$可规约为B,如果B的解存在并且给定该解时A可解,其中$m$表示映射规约;这里可以将规约理解为A对B的子函数调用,除了子函数B是一个黑盒,解决A的步骤都应该是明确的。
- 解决A不能比解决B更难,因为A可以通过解决B来得到解决;
- 例题,测量矩形面积可规约到测量矩形边长,计算一个数的平方可规约到两个数乘积。

22. 规约证明
24. 规约证明

- 为了证明一个加密方案$\Pi$在假设$X$下是安全的,将解决假设$X$问题的算法$\mathcal{A}'$规约到破解$\Pi$的算法$\mathcal{A}$。如果加密方案可以被破解,则假设问题也可以解决。然而,由于假设问题是难以解决的,这导致矛盾,说明加密方案不可以被破解。
- 先令一个概率多项式时间的算法$\mathcal{A}$可以以概率$\varepsilon(n)$破解$\Pi$ ;
- 我们现在站在敌手的角色来思考,希望解决“破解”加密方案这个问题,并且在此之前我们已经知道有个一“假设”问题是不可解决的;
- 为了证明一个加密方案$\Pi$在假设$X$下是安全的,就是证明“破解”问题不可解。
- 将解决“假设”$X$问题的算法$\mathcal{A}'$规约到“破解”$\Pi$的算法$\mathcal{A}$。如果加密方案可以被破解,则假设问题也可以解决。然而,由于假设问题是难以解决的,这导致矛盾,说明加密方案不可以被破解。
- 先令一个概率多项式时间的算法$\mathcal{A}$能够以概率$\varepsilon(n)$破解$\Pi$ ;
- 假设:一个问题$X$是难以解决的,即不存在多项式时间算法来解决$X$;$\mathcal{A}'$是一个解决$X$的概率算法;
- 规约:解决假设问题$X$可以通过破解加密方案$\Pi$,即将$\mathcal{A}'$规约到$\mathcal{A}$,$\mathcal{A}'$通过以$\mathcal{A}$作为子函数可以以概率$1/p(n)$有效地解决问题$X$;
- 矛盾:若加密方案可以被有效破解,即$\varepsilon(n)$是不可忽略的,则$\mathcal{A}'$可以以不可忽略的概率$\varepsilon(n)/p(n)$解决问题$X$,这与假设矛盾,因而$\varepsilon(n)$一定是可忽略的。

23. 证明不可区分加密方案
25. 证明不可区分加密方案

- 思路:区分伪随机性为难题假设,破解加密方案为规约的子函数。针对伪随机生成器$G$的区分器$D$以$\mathcal{A}$为子函数,使得当$\mathcal{A}$破解了$\Pi$则$D$可以区分出$G$,与$G$的伪随机性矛盾。注意这里我们用了符号$\tilde{\Pi}$来表示$\Pi$的一个变体,来刻画加密方案中可能使用了真随机串来加密;
- 回顾针对伪随机生成器的区分器$D$的问题是,输入一个串$w$,输出一个比特;这里关键问题是输出的比特从何而来?
Expand All @@ -163,11 +175,11 @@
- 所以$\varepsilon(n)$是可忽略的,即$\Pi$是窃听者不可区分的。
- 小结:通过规约将$\mathcal{A}$的不可区分实验成功的概率与$D$的区分器实验输出1的概率建立等式;分析输入真随机串时$D$输出1的概率(即不可区分实验成功概率)是1/2;根据PRG的定义,输入伪随机串时$D$输出1的概率(1/2+$\varepsilon(n)$)与输入真随机串时$D$输出1的概率(1/2)的差异时可忽略的。

24. 处理变长消息
26. 处理变长消息

- 对于一个变长输出的伪随机生成器,前面的加密方案和安全性都成立;这是作业,其中一个关键是条件2,短串是长串的前缀。

25. 计算安全与信息安全
27. 计算安全与信息安全

- 敌手:PPT窃听者,无限算力窃听者;
- 定义:不可区分性$\frac{1}{2} + \mathsf{negl}$,不可区分性 $\frac{1}{2}$;
Expand Down
Binary file modified pdf/3.1privatekey.pdf
Binary file not shown.
Binary file modified pdf/3.2privatekey.pdf
Binary file not shown.
Binary file added pic/holes.pdf
Binary file not shown.
97 changes: 67 additions & 30 deletions source/3.1privatekey.tex
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ \section{A Computational Approach to Cryptography}
$n=500$ & more than 200 years with probability $2^{-500}$. \\
\end{tabular}\\

\alert{Q: What if under Moore's Law?}
\alert{Q: Under Moore's Law, who has more advantages? Adversary or Alice?}
\end{exampleblock}
\end{frame}

Expand Down Expand Up @@ -240,23 +240,35 @@ \section{Pseudorandomness}
\item \textbf{Existence}: Under the weak assumption that \emph{one-way functions} exists, or $\mathcal{P} \ne \mathcal{NP}$
\end{itemize}
\end{frame}

\begin{frame}\frametitle{Problems on PRG}
\begin{exampleblock}{Is $G$ PRG?}
\begin{itemize}
\item $G: s \to \{0,1\}^n$ is such that for all $s$: $XOR(G(s)) = 1$
\item glibc random(): $r[i] = (r[i-3] + r[i-31])\%2^{32}$
\end{itemize}
\begin{frame}[fragile]\frametitle{Real world cases}
\begin{exampleblock}{glibc random()}
$r[i] = (r[i-3] + r[i-31])\%2^{32}$
\end{exampleblock}
\begin{exampleblock}{Netscape (by reverse-engineering)}
\begin{verbatim}
global variable seed;
RNG_CreateContext();
(seconds, microseconds) = time of day;
pid = process ID; ppid = parent process ID;
a = mklcpr(microseconds);
b = mklcpr(pid + seconds + (ppid << 12));
seed = MD5(a, b);
mklcpr(x)
return ((0xDEECE66D * x + 0x2BBB62DC) >> 1);
\end{verbatim}
\end{exampleblock}
\end{frame}
\begin{frame}\frametitle{Problems on PRG}
\begin{exampleblock}{$F$ is PRG. Is $G$ PRG?}
\begin{itemize}
\item $G(s)=F(s)\oplus 1^{n}$
\item $G(s)$ is such that $XOR(G(s)) = 1$
\item $G(s)=F(0)$
\item $G(s)=F(s)\| 0$
\item $G(s)=F(s\oplus 1^{\abs{s}})$
\item $G(s)=F(s)\| F(s)$
\item $G(s\| s')=F(s)\| F(s')$
\item $G: s \gets \{0,1\}^{20}, G(s) = F(s)$ (see next slide)
\item $G(s)=F(s\|0)$
\item $G: s \gets \{0,1\}^{20}, G(s) = F(s)$
\end{itemize}
\end{exampleblock}
\end{frame}
Expand All @@ -268,31 +280,15 @@ \section{Pseudorandomness}
\item \textbf{Sufficient seed space}: $s$ must be long enough against brute force attack.
\end{itemize}
\end{frame}
\section{Constructing Secure Encryption Schemes}
\begin{frame}\frametitle{A Secure Fixed-Length Encryption Scheme}
\begin{columns}[t]
\begin{column}{4cm}
\begin{frame}\frametitle{Bad randomness [xkcd:424]}
In 2008, the Debian project announced that a vulnerability in the OpenSSL package. The bug was caused by the removal of the line of code from md\_rand.c. (CVE-2008-0166)
\begin{figure}
\begin{center}
\input{tikz/encryptionwithpg}
\includegraphics[width=60mm]{pic/holes}
\end{center}
\end{figure}
\end{column}
\begin{column}{6cm}
\begin{construction}\label{con:fl}
\begin{itemize}
\item $|G(k)| = \ell(|k|)$, $m \in \{0,1\}^{\ell(n)}$.
\item $\mathsf{Gen}$: $k \in \{0,1\}^n$.
\item $\mathsf{Enc}$: $c := G(k)\oplus m$.
\item $\mathsf{Dec}$: $m := G(k)\oplus c$.
\end{itemize}
\end{construction}
\begin{theorem}\label{the:flt}
This fixed-length encryption scheme has indistinguishable encryptions in the presence of an eavesdropper.
\end{theorem}
\end{column}
\end{columns}
\end{frame}
\section{Proof By Reduction}
\begin{frame}\frametitle{Reduction (Complexity)}
A \textbf{reduction} is a transformation of one problem $A$ into another problem $B$.
\newline
Expand Down Expand Up @@ -320,6 +316,47 @@ \section{Constructing Secure Encryption Schemes}
\item \textbf{Contradiction}: If $\varepsilon(n)$ is non-negligible, then $\mathcal{A'}$ solves $\mathsf{X}$ efficiently with non-negligible probability $\varepsilon(n)/p(n)$.
\end{itemize}
\end{frame}
\begin{frame}\frametitle{Proof of PRG}
\begin{exampleblock}{If $F(s)$ is PRG, so is $G(s)=F(s)\oplus 1^{\abs{n}}$ ?}
\begin{itemize}
\item Problem A (Assumption): to distinguish $F(s)$ from $r$
\item Problem B (Break the scheme): to distinguish $G(s)$ from $r$
\end{itemize}
\textbf{Idea}: Reduce A to B. As $F(s)$ is distinguishable, so is $G(s)$.
\begin{figure}
\begin{center}
\input{tikz/reduction-prg}
\end{center}
\end{figure}
$\Pr[D'(F)=1]=\Pr[D(G)=1]$,$\Pr[D'(r)=1]=\Pr[D(r)=1]$ \\
$\mathsf{Adv}(D'(F)) = \mathsf{Adv}(D(G)) \le \mathsf{negl}(n) $
\end{exampleblock}
\end{frame}
\section{Constructing Secure Encryption Schemes}
\begin{frame}\frametitle{A Secure Fixed-Length Encryption Scheme}
\begin{columns}[t]
\begin{column}{4cm}
\begin{figure}
\begin{center}
\input{tikz/encryptionwithpg}
\end{center}
\end{figure}
\end{column}
\begin{column}{6cm}
\begin{construction}\label{con:fl}
\begin{itemize}
\item $|G(k)| = \ell(|k|)$, $m \in \{0,1\}^{\ell(n)}$.
\item $\mathsf{Gen}$: $k \in \{0,1\}^n$.
\item $\mathsf{Enc}$: $c := G(k)\oplus m$.
\item $\mathsf{Dec}$: $m := G(k)\oplus c$.
\end{itemize}
\end{construction}
\begin{theorem}\label{the:flt}
This fixed-length encryption scheme has indistinguishable encryptions in the presence of an eavesdropper.
\end{theorem}
\end{column}
\end{columns}
\end{frame}
\begin{frame}\frametitle{Proof of Indistinguishable Encryptions}
\textbf{Idea}: Use $\mathcal{A}$ to construct $D$ for $G$, so that $D$ distinguishes $G$ when $\mathcal{A}$ breaks $\tilde{\Pi}$. Since $D$ cannot distinguish $G$, so that $\mathcal{A}$ cannot break $\tilde{\Pi}$.
\begin{proof}
Expand Down
10 changes: 10 additions & 0 deletions tikz/reduction-prg.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
\begin{tikzpicture}[scale=0.7, every node/.style={scale=0.7}]
\draw (0,0) rectangle (5,4);
\draw (3,0.5) rectangle (4.5,3);
\draw[-latex] (-3,3) -- (0,3) node [midway, above] {input $:= r$ or $G(s)$} node [midway, below] {};
\draw[-latex] (0,0.3) -- (-3,0.3) node [midway, above] {output};
\draw (1.8,3.5) node {\Large \textbf{$D'$} for $F$};
\draw (3.75,1.75) node {\Large $D$ for $G$};
\draw[-latex] (0.5,2.5) -- (3,2.5) node [midway, above] {input $\oplus 1^{n}$ } node [midway, below] {};
\draw[-latex] (3,1) -- (0.3,1) node [midway, above] {output $= 0$ or $1$};
\end{tikzpicture}

0 comments on commit 53cd85e

Please sign in to comment.