Skip to content

Commit

Permalink
change TLS 13 handshaking
Browse files Browse the repository at this point in the history
  • Loading branch information
YuZhang committed Nov 2, 2021
1 parent 1e0b830 commit 00999a4
Show file tree
Hide file tree
Showing 10 changed files with 155 additions and 85 deletions.
73 changes: 67 additions & 6 deletions notes-Chinese/10 密码学协议动物园.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,72 @@
# 10 密码学协议动物园

1. 本节学习用于保护信息的完整性和真实性的消息认证码(MAC)和抗碰撞的哈希函数(CRHF)。

2. 目录:MAC、构建安全MAC、CBC-MAC、CRHF、HMAC、信息论上MAC。

3.

1. 本节学习密码学协议。这些协议以之前学习的密码学知识为基础实现了一些“奇妙”的事情!
2. 动物园地图
3. 目录:略。
4. 协议:
- **通信协议**是为了一个特定目的的数字消息格式与交换规则的形式化描述
- 协议之于通信,如同算法之于计算
- 每个人必须知道并同意服从协议
- 无歧义:每个步骤必须被明确定义且无误解的可能
- 完备性:对每个可能的情况都必须有一个明确的行为
- 密码学协议:除了上述属性,还应该不可能比协议中说明的做的更多或者知道的更多
5. 协议类型
- 仲裁协议:一个仲裁者是一个公正的可信第三方,帮助完成协议
- 审判协议:一个法官是也是一个公正的可信第三方。与仲裁者不同,其不直接参与协议,而是来审判协议是否正确执行
- 自强制协议:最佳的协议类型。协议本身保证公平性。
- 例子:两人平分蛋糕协议。
6. 对协议的攻击
- 被动攻击:攻击者不影响协议
- 主动攻击:攻击者更改协议以获得优势
- 作弊者:攻击者是协议中的一方
- 被动作弊者:按照协议执行,但试图获得比协议所设定的更多的信息
- 主动作弊者:在协议进程中干扰协议来作弊
7. 三次传递协议
- 目的:无共享密钥的通信
- 类比:同一个箱子来传递秘密。
9. 中间人攻击
- 水桶小队攻击
10. 互锁协议
- 抵御中间人攻击
11. 双线性图
- 两个循环群
- 双线性图:一个群中两个元素的运算结果,可以映射为另一个群中
- 定理:如果双线性图的映射是高效的,那么决定性DH问题在$G_1$上是容易的,因为可以通过检查映射后结果是否相等来判断
12. Jounx密钥交换协议
- Jounx的一轮、三方密钥协商协议,其中Alice计算密钥$e(bP, cP)^a = e(P, P)^{abc}$;
- 双线性DH(BDH)假设:给定$\left<P, aP, bP, cP \right>$,计算$e(P, P)^{abc}$是难题;
- 定理:给定BDH假设,Jounx协议是安全的
15. 基于身份的加密
- IBE:
16. Boneh-Franklin的IBE方案
17. 盲签名
18. 群签名
19. 环签名
20. 秘密共享
21. Shamir的秘密共享
22. 门限密码学
23. 承诺方案
24. 零知识证明
25. 一个玩具例子
26. 汉弥尔顿环路的零知识证明
24. 零知识证明和承诺
- 模拟范式:当一件事Y本来就可以从X得到,那么通过Y并不会从X额外获得什么
- 在关于是否知道RSA私钥的零知识证明中,验证者给一个密文C后,让证明者给出对应明文M,来验证证明者知道私钥
- 当没有承诺协议时,验证者可能在不知道明文M时直接给出一个密文C,而证明者返回的消息M令验证者额外知道了M;
- 当加入承诺后时,证明者在给出M之前,先给出对M的承诺,即不泄漏M,又对后面给出的M作出承诺;在验证者提供M后,证明者知道验证者已经知道M了,根据上面的模拟范式可知,之后验证者获得的M对于验证者也不是新信息。
25. Schnorr协议
26. 破解RSA能力的零知识证明
27. 健忘传输
28. Rabin的健忘传输协议
29. 二选一健忘传输
30. 安全多方计算
31. 同态加密
32. 端到端投票系统
33. 三票投票法
34. 量子密码学
35. 量子密码学现状
36. 量子密钥分发
37. 总结:克拉克三定律之一:任何足够先进的技术和魔法是不可区分的。



20 changes: 15 additions & 5 deletions notes-Chinese/8.3 DH问题与加密.md
Original file line number Diff line number Diff line change
Expand Up @@ -188,20 +188,30 @@
23. 椭圆曲线密码学

- 在椭圆曲线群上构造的离散对数问题
- 1985年被提出
- 比自然数域上更有效
- 其他密码学上的应用在1985年被提出
- 类比离散对数,DH密钥交换,ElGamal加密和DSA,在椭圆曲线上有,ECDL,ECDHKE,ElGamal ECC,ECDSA
- 比自然数域上更有效,密钥长度是所需蛮力搜索指数长度的二倍。
- 二倍的原因是,离散对数问题的蛮力搜索所需指数长度是群阶指数长度的一半

24. 椭圆曲线群

- 取模是关键,单位元是无穷远点
- 椭圆曲线群是在一个有限域中的一个平面代数曲线上的点之间“加法”操作
- 在有限域中取模是关键,单位元是无穷远点

25. 在椭圆曲线点上做加法构成循环群

- 三点成一线,那么三点之和为无穷远点
- 每条直线和曲线有三个交点
- 一条直线与曲线的切点算2次
- 垂直线上,无穷远点计做一个点
- 点上的加法
- 三点成一线,三点之和为无穷远点
- 密钥生成
- 私钥是$d$,公钥为$dP$

26. ECDHKE的一个例子

- 计算ECDHKE的密钥
- 计算ECDHKE的密钥,这里枚举了生成元为(3,4)的所有指数结果
- 密钥计算是从(7,6)开始,向后数5个点

27. 实践中的椭圆曲线密码系统

Expand Down
19 changes: 15 additions & 4 deletions notes-Chinese/9 数字签名.md
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,18 @@
- 优点:可靠,草根级
- 缺点:难以管理,难以对信任作出保证

24. 无效化证书
24. TLS 1.3 握手协议

- 目的:客户端与认证的服务器之间产生密钥
- 要求:客户端具有可信第三方的公钥,服务器具有由可信第三方发布的服务器公钥证书
- 协议主要步骤包括:
- 双方发送Hello消息,交换随机参数,各自DHKE公钥,同时也对所用的密码学套件和协议版本号进行协商;
- 分别根据交换信息根据DHKE生成共享秘密,进一步根据共享秘密和所有消息的哈希值派生出共享密钥
- 以下的消息都用上一步生成的对称密钥加密
- server端发送公钥证书,和用该公钥对应私钥来签名之前传递的消息(trans),以证明自己是证书的持有者;发送Finished结束消息,其中包含之前所有消息的HMAC;根据发送的所有消息和共享密钥生成应用密钥
- client验证证书和签名,并生成应用密钥

25. 无效化证书

- 当私钥泄漏发生时,需要更换公私钥对,并将之前旧的公钥证书无效化。

Expand All @@ -293,7 +304,7 @@

累积撤销:CA 产生证书撤销列表(Certificate revocation list,CRL)包含所有被撤销证书的序列号,并且带着当前日期一起签名。

25. 独占所有权(Exclusive Ownership)
26. 独占所有权(Exclusive Ownership)

- 独占所有权:给定任意公钥的签名,没有敌手能够使得该签名可以被另一个不同的公钥验证。
- 重复签名公钥选择攻击:
Expand All @@ -302,7 +313,7 @@
- 该攻击被用来在域名的所有权上欺骗Let‘s Encrypt系统。
- 防御:在验证之前检查公钥。

26. 签名加密(Signcryption)
27. 签名加密(Signcryption)

- 一群人相互直接通信,每个人生成两对密钥:$(ek, dk)$表示加密公钥和解密私钥;$(vk, sk)$表示验证公钥和签名私钥。大家知道彼此的两个公钥。当一个发送者$S$向接收者$R$发送一个消息$m$时,如何在CCA攻击下同时保证通信的机密性(其他人不能知道消息$m$)和完整性(接受者$R$确信消息来自发送者$S$)?
- 提示:下面的问题的关键在于“完整性”,即是否能能够伪装为其他人发送消息。
Expand All @@ -315,7 +326,7 @@
- 这里的关键之一是签名将消息,发送者,接收者绑定在一起
- 当将身份和消息一起加密时,先加密后认证的方法也可以保证安全。

27. 总结
28. 总结

- 数字签名提供了公开可验证的真实性和完整性
- 签名与只有某人知道的某物有关,这件事是可以公开验证的
Expand Down
Binary file modified pdf/10protocols.pdf
Binary file not shown.
Binary file modified pdf/9digital-sig.pdf
Binary file not shown.
63 changes: 8 additions & 55 deletions source/10protocols.tex
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@

\title{A Quick Tour of \\ Cryptographic Protocols Zoo}

\begin{document}
\begin{document}
\maketitle
\begin{frame}\frametitle{What's in the zoo?}
\begin{figure}
\begin{center}
%\input{tikz/ellipticcurve}
\includegraphics[width=105mm]{pic/zoo-cn.pdf}
\includegraphics[width=105mm]{pic/zoo-cn.pdf}
\end{center}
\end{figure}
\end{frame}
Expand All @@ -24,17 +23,18 @@ \section{Protocols}
\item Protocols are to communications what algorithms are to computations
\item Everyone must know it and agree to follow it
\end{itemize}
\item Unambiguous: each step must be well defined and there must be no chance of a misunderstanding
\item Complete: there must be a specified action for every possible situation
\item It should not be possible to do more or learn more than what is specified in the protocol
\item \textbf{Unambiguous}: each step must be well defined and there must be no chance of a misunderstanding
\item \textbf{Complete}: there must be a specified action for every possible situation
\item \textbf{Cryptographic protocol}: Additionally, it should not be possible to do more or learn more than what is specified in the protocol
\end{itemize}
\end{frame}
\begin{frame}\frametitle{Protocol Types}
\begin{itemize}
\item \textbf{Arbitrated protocols}: An arbitrator is a disinterested third party trusted to complete a protocol.
\item \textbf{Adjudicated protocols}: An adjudicator is also a disinterested and trusted third party. Unlike an arbitrator, he is not directly involved in every protocol.
\item \textbf{Adjudicated protocols}: An adjudicator is also a disinterested and trusted third party. Unlike an arbitrator, he is not directly involved in every protocol unless .
\item \textbf{Self-enforcing protocols}: the best type of protocol. The protocol itself guarantees fairness.
\end{itemize}
\begin{exampleblock}{How to split a cake equally between two kids?}\end{exampleblock}
\end{frame}
\begin{frame}\frametitle{Attacks against Protocols}
\begin{itemize}
Expand All @@ -47,17 +47,6 @@ \section{Protocols}
\item \textbf{Active cheaters}: disrupt the protocol in progress in an attempt to cheat.
\end{itemize}
\end{frame}
\section{SSL/TLS Handshaking}
\begin{frame}\frametitle{Simplified SSL/TLS Handshaking}
\textbf{Purpose}: generate 4 secret keys with authenticated server\\
\textbf{Requirement}: the client has the public key of Trusted Third Party\\
the server has the certificate of its own $pk$ issued by TTP
\begin{figure}
\begin{center}
\input{tikz/ssl}
\end{center}
\end{figure}
\end{frame}
\section{Three-Pass Protocol and Interlock Protocol}
\begin{frame}\frametitle{Three-Pass Protocol}
\textbf{Purpose}: communication without shared keys\\
Expand Down Expand Up @@ -115,42 +104,6 @@ \section{Pairing and Identity-Based Encryption}
\item \textbf{Theorem}: Given BDH assumption, Jounx's is secure.
\end{itemize}
\end{frame}
\begin{frame}\frametitle{Elliptic Curve Groups}
\textbf{Elliptic curve group}: points with ``addition'' operation.\\
Any \textbf{elliptic curve} is a plane algebraic curve:
\[ y^2 \equiv x^3 + Ax + B \pmod p\]
where $A,B \in \mathbb{Z}_p$ are constants with $4A^3 + 27B^2\not \equiv 0 \pmod p$.
$\hat{E}(\mathbb{Z}_p)$ is the set of pairs $(x,y) \in \mathbb{Z}_p \times \mathbb{Z}_p$:
\[ \hat{E}(\mathbb{Z}_p) \overset{\text{def}}{=} \{(x,y) \mid x,y\in \mathbb{Z}_p \land y^2 \equiv x^3 + Ax + B \pmod p \}\]
$E(\mathbb{Z}_p) \overset{\text{def}}{=} \hat{E}(\mathbb{Z}_p)\cup \{\mathcal{O}\}$, $\mathcal{O}$ is identity, ``\textbf{point at infinity}''.
\end{frame}
\begin{frame}\frametitle{``Addition'' on Points of Elliptic Curves}
\begin{columns}
\begin{column}{5cm}
\begin{figure}
\begin{center}
\input{tikz/ellipticcurve}
%\includegraphics[width=50mm]{pic/ecc.pdf}
\end{center}
\end{figure}
\end{column}
\begin{column}{5cm}
Every line intersects the curve in 3 points:
\begin{itemize}
\item count twice if tangent.
\item count $\mathcal{O}$ at the vertical infinity of $y$-axis.
\end{itemize}
``\textbf{Addition}'' on points:
\begin{itemize}
\item $P+\mathcal{O} = \mathcal{O} + P = P$.
\item If $P_1, P_2, P_3$ are co-linear, then $P_1 + P_2 + P_3 = \mathcal{O}$.
\end{itemize}
\end{column}
\end{columns}
Some equations: \newline
$-P=(x,-y)$, $P_1 + P_2 = -P_3$, $2P_4=-P_3$, $dP = P + (d-1)P$
\[\text{Key generation:} sk = (P,d); pk = (P,Q=dP)\]
\end{frame}
\begin{frame}\frametitle{Identity-Based Encryption}
\begin{itemize}
\item \textbf{IBE}: Anyone can directly use receiver's ID ($A$) as the pubic key with help of a TTP, aka KGC (Key Generation Center). The receiver obtains its private key from KGC.
Expand Down Expand Up @@ -322,7 +275,7 @@ \section{Zero Knowledge Proofs}
\begin{center}
\input{tikz/zkp-commitment}
\end{center}
\end{figure}
\end{figure}
\end{frame}
\begin{frame}\frametitle{Schnorr Protocol}
We have learned a ZKP as an identification scheme. Recall \textbf{Schnorr protocol}: Alice proves to Bob the knowledge of $x=\log_gy$ in the discrete log problem.
Expand Down
10 changes: 10 additions & 0 deletions source/9digital-sig.tex
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,16 @@ \section{Certificates and Public-Key Infrastructures}
\end{itemize}
\end{itemize}
\end{frame}
\begin{frame}\frametitle{TLS 1.3 Handshaking\footnote{https://tls13.ulfheim.net}}
\textbf{Purpose}: client generates secret keys with authenticated server\\
\textbf{Requirements}: the client has the public key of CA,
the server has the certificate of its own $S_{pk}$ issued by CA
\begin{figure}
\begin{center}
\input{tikz/tls13hs}
\end{center}
\end{figure}
\end{frame}
\begin{frame}\frametitle{Invalidating Certificates}
\begin{itemize}
\item \textbf{Expiration}: include an \emph{expiry date} in the certificate.
Expand Down
10 changes: 1 addition & 9 deletions tikz/ssl.tex
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
\node (3a) [below of=2a, node distance=0.5cm] {};
\node (3b) [below of=2b, node distance=0.5cm] {certificate of $pk$};
\draw[-latex] (3b) -- (3a) node [midway,above] {};
\node (4a) [below of=3a, node distance=0.5cm] {$E_{pk}$(premaster secret $s$)};
\node (4a) [below of=3a, node distance=0.5cm] {Verify the certificate // $E_{pk}$(premaster secret $s$)};
\node (4b) [below of=3b, node distance=0.5cm] {};
\draw[-latex] (4a) -- (4b) node [midway,above] {};
\node (5a) [below of=4a, node distance=0.5cm] {Hash of previous msgs};
Expand All @@ -23,12 +23,4 @@
\draw[-latex] (6b) -- (6a) node [midway,above] {};
\node (7a) [below of=6a, node distance=0.5cm] {session keys from $(a, b, s)$};
\node (7b) [below of=6b, node distance=0.5cm] {session keys from $(a, b, s)$};
%\draw[-latex] (7b) -- (7a) node [midway,above] {};
%\node (8a) [below of=7a, node distance=0.5cm] {};
%\node (8b) [below of=7b, node distance=0.5cm] {$c_{B2}$};
%\draw[-latex] (8b) -- (8a) node [midway,above] {};
%\node (9a) [below of=8a, node distance=0.5cm] {$c_B = (c_{B1}\| c_{B2})$};
%\node (9b) [below of=8b, node distance=0.5cm] {$c_A = (c_{A1}\| c_{A2})$};
%\node (10a) [below of=9a, node distance=0.5cm] {$m_B = \mathsf{Dec}_{pk_A}(c_B)$};
%\node (10b) [below of=9b, node distance=0.5cm] {$m_A = \mathsf{Dec}_{pk_B}(c_A)$};
\end{tikzpicture}
33 changes: 33 additions & 0 deletions tikz/tls13hs.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
\begin{tikzpicture}[font=\footnotesize, scale=0.8, every node/.style={scale=0.8},
ln/.style={text width = 3.5cm, align=left, rounded corners=1ex, draw},
rn/.style={text width = 3.5cm, align=left, rounded corners=1ex, draw},
cn/.style={text width = 6cm, align=center, rounded corners=1ex, draw}]
%\node (A) at (0,0) {\Lisa(Client)};
%\node (B) [right of = A, node distance = 4cm] {\Left\Bart(Server)};
\node (A) at (0,0) [minimum size=1cm] {}; \Alice{0}{0}{0.4}; \node at (1cm,0) {Client};
\node (B) [right of = A, node distance = 6.5cm, minimum size=1cm] {}; \Bob{6cm}{0}{0.4}; \node at (7cm,0) {Server};
\node (1a) [below of=A, node distance=1cm, ln] {gen random $r_c$ \& \\ client key $(sk_c, pk_c)$};
\node (1b) [below of=B, node distance=1cm] {};
\draw[-latex] (1a) -- +(4.6,0) node [midway,above] {Hello $r_c, pk_c$};
\node (2a) [below of=1a, node distance=0.8cm] {};
\node (2b) [below of=1b, node distance=0.8cm, rn] {gen random $r_s$ \& \\ server key $(sk_s, pk_s)$};
\draw[-latex] (2b) -- +(-4.6,0) node [midway,above] {Hello $r_s, pk_s$};
\node (3as) [below of=2a, node distance=1.2cm, ln] {gen shared keys $k^*$ w/ $sk_c, pk_s$, hash(trans)};
\node (3bs) [below of=2b, node distance=1.2cm, rn] {gen shared keys $k^*$ w/ $sk_s, pk_c$, hash(trans)};
%\draw[-latex] (3bs) -- (3as) node [midway,above] {};
\node (3a) [below of=3as, node distance=1.2cm, ln] {verfiy certificate and signature};
\node (3b) [below of=3bs, node distance=1.2cm, rn] { $\sigma$ = sign($S_{sk}$, trans) \\ $t_s$ = hmac($k^*_s$, trans)};
\draw[-latex] (3b) -- +(-4.6,0) node [midway,above,text width = 3cm, align=center] {\{certificate of $S_{pk}$\} \\ cert verfiy \{ $\sigma$ \} \\ finished \{ $t_s$ \}};
\node (4a) [below of=3a, node distance=2cm, ln] {$t_c$ = hmac($k^*_c$, trans)};
\node (4b) [below of=3b, node distance=2cm] {};
\draw[-latex] (4a) -- +(4.6,0) node [midway,above] {finished \{$t_c$\}};
\node (5a) at (3.1,-5.2) [cn] {gen application keys w/ $k^*$, hash(trans)};
% \node (5a) [below of=4a, node distance=1cm] {Hash of previous msgs};
% \node (5b) [below of=4b, node distance=1cm] {};
% \draw[-latex] (5a) -- (5b) node [midway,above] {};
% \node (6a) [below of=5a, node distance=0.5cm] {};
% \node (6b) [below of=5b, node distance=0.5cm] {Hash of previous msgs};
% \draw[-latex] (6b) -- (6a) node [midway,above] {};
% \node (7a) [below of=6a, node distance=0.5cm] {session keys from $(a, b, s)$};
% \node (7b) [below of=6b, node distance=0.5cm] {session keys from $(a, b, s)$};
\end{tikzpicture}
12 changes: 6 additions & 6 deletions tikz/zkp-commitment.tex
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@
\draw[-latex] (0b) -- (0a) node [midway,above] {$c$};
\node (1a) [below of=0a, node distance=0.5cm] {};
\node (1b) [below of=0b, node distance=0.5cm] {};
\node (2a) [below of=0a, node distance=1cm] {$h = \mathsf{commit}(m')$};
\node (2b) [below of=0b, node distance=1cm] {};
\node (2a) [below of=0a, node distance=0.8cm] {$h = \mathsf{commit}(m')$};
\node (2b) [below of=0b, node distance=0.8cm] {};
\draw[-latex] (2a) -- (2b) node [midway,above] {$h$};
\node (3a) [below of=2a, node distance=0.5cm] {$m \overset{?}{=} m'$};
\node (3b) [below of=2b, node distance=0.5cm] {};
\draw[-latex] (3b) -- (3a) node [midway,above] {$m$};
\node (4a) [below of=3a, node distance=0.5cm] {If No, stop;};
\node (4b) [below of=3b, node distance=0.5cm] {};
\node (5a) [below of=4a, node distance=1cm] {};
\node (5b) [below of=4b, node distance=1cm] {Accept if $m=m'$};
\node (5a) [below of=4a, node distance=0.8cm] {};
\node (5b) [below of=4b, node distance=0.8cm] {Accept if $m=m'$};
\draw[-latex] (5a) -- (5b) node [midway,above] {$m'$};
\node (6b) [below of=5b, node distance=0.5cm] {};
\node (11) at (1.5cm,-3cm) [minimum height=2cm, minimum width=6cm, dotted, draw,rounded corners=1ex] {};
%\node (6b) [below of=5b, node distance=0.5cm] {};
\node (11) at (1.5cm,-2.5cm) [minimum height=1.8cm, minimum width=6cm, dotted, draw,rounded corners=1ex] {};
\end{tikzpicture}

0 comments on commit 00999a4

Please sign in to comment.