本系列为斯坦福 Dan Boneh教授的"密码学 I"的学习笔记 课程网址: www.coursera.org/lecture/cry…
0 Introduction
0.1 Course Overview
- Course objectives
- 密码原型(crypto primitives)如何工作
- how to use them correctly and reason about security
- 学习建议 recommendations
- take notes
- pause video frequently to think about the material
- 讲课速度比normal classroom快很多
- answer the in-video questions
- questions通常是just been covered, 所以should not be too difficult to answer
- encourage to do them
- Cryptography的应用 -- everywhere
-
加密通信 secure communiation
- cannot 被动eavesdrop + 主动 modify (tampering, 纂改)
- Secure Sockets Layer / TLS
- Two main parts
- Handshake protocal
- 使用公钥密码建立共享密钥
- Record layer
- 使用共享秘密钥传输数据
- ensure confidentiality and integrity
- Handshake protocal
- Two main parts
- web traffic: http
- wireless traffic: 802.11i, GSM, Bluetooth等
-
加密磁盘文件
- EFS, TrueCrypt
- 和secure communication很像:
- “今天的Alice”向"明天的Alice"传输信息
-
Content protection
- e.g., DVD, Blu-ray
- CSS, AACS
-
User authentication
-
- Cryptography的分类
- Building Block: sym. encryption
- E, D: cipher
- m, c: plaintext, ciphertext
- Building Block: sym. encryption
- Encryption algorithms are publicly known
- 加密方法是已知的
- 未知的只有密钥 key K
- 我们也只应该使用public的加密算法
- 这些public encryption alg.:
- peer-reviewed by a very large community of hundreds of people
- for many many years
- cannot be broken
- 但自定义的加密算法
- 没有经过证实,很有可能是危险的
- 这些public encryption alg.:
- Use cases 使用案例
- 单次使用的密钥 single use key (one time key)
- key 仅被用来加密one message
- email: 每一个email都有一个新的key
- key 仅被用来加密one message
- 多次使用的密钥 multi use key (many time key)
- Key used to encrypt multiple meaages
- 文件加密: one same key is used to encrypt many files
- Key used to encrypt multiple meaages
- 多次密钥比单次密钥:需要更多的机制 machinery
- 单次使用的密钥 single use key (one time key)
- Summary (THINGS TO REMEMBER)
- cryptography is:
- a tremendous/ fantistic tool
- the basis for many security mechanisms
- Cryptography is not
- 所有security problems的solution
- 例如防不了电信诈骗
- 还得靠反诈app
- 例如防不了电信诈骗
- need to implement and use properly
- 应该避免轻易自己"发明"
- 许多ad-hoc designs都被证明broken
- 所有security problems的solution
- cryptography is:
0.2 What is Cryptography
- Cryptography core 密码学核心
- step1 密钥交换
- secret key establishment
- step2 加密通信
- secure communication
- confidentiality and integrity
- step1 密钥交换
- 但密码学还有更多内容
- digital signatures 数字签名
- 真实签名 VS 数字签名
- 不同
- 真实世界的签名:所有文档的签名都一样;
- 数字签名:不能相同
- 否则一旦attacker获取一个签名,就能粘贴到其他文档伪造签名
- 相同:
- 目的一样,都是为了证实签名者对文档的认可
- 不同
- 真实签名 VS 数字签名
- anonymous communication
- mix net
- A send message to B:
- B不知道A是谁
- 但B可以回复A,并被A正确接收
- Anonymous digital cash
- 现金世界:戴好口罩付款买东西,店主并不知道你是谁
- 在数字世界可以实现吗?
- Can I spend a "digital coin" without anyone knowing who I am?
- How to prevent double spending?
- 提供匿名支付 ,同时避免"假币"
- Anonymity 和 security之间的矛盾
- digital signatures 数字签名
- Protocols 协议
-
Elections 选举
- winner = MAJ[votes]
- 要求:
- 统计选票,确定winner
- 每个选民最多投一票,不能假冒
- 但保密选民信息
- 解决方案
- 设立选举中心 -- election center
- 设立选举中心 -- election center
-
Private auctions 私密拍卖
- Vickery auction: winner是拍价最高者,但只需以次高拍卖价格支付
- 系统只统计有用的2个信息,保护其他信息
-
Secure multi-party comutation 安全多方计算
- 针对无可信第三方的情况下,如何安全地计算一个约定函数的问题
- 例如:
- Bob和Alice想弄清谁的薪资更高,但因为签署了保密协议而不能透露具体薪资。如果Bob和Alice分别将各自的薪资告诉离职员工Anne,这时Anne就能知道谁的薪资更高,并告诉Bob和Alice。这种方式就是需保证中间人Anne完全可信。
- 而通过MPC则可以设计一个协议,在这个协议中,算法取代中间人的角色,Alice和Bob的薪资以及比较的逻辑均交由算法处理,参与方只需执行计算协议,而不用依赖于一个完全可信的第三方
-
Goal: compute f(x1,x2,x3,x4)
- 函数f: 约定函数
- 选举:f输出为大多数票数方 (获胜者)
- 拍卖:f输出为第二高的金额 + 最高金额的编号
- 要求:只输出f值,其他信息完全保密
- 方法1: 朴素且呆板
-
引入 trusted authority
-
但凭啥相信 这个 aurhority
-
- 方法2:设计并使用协议
-
密码学一个"谚语":
- anything that can be done with trusted auth. can be also done without
-
即 trusted authority 总是可以被 协议 protocol 取代
- 经过协议,每个人都知道结果,但一点也不知道过程
-
- 函数f: 约定函数
-
- Crypto magic
- 一些无法归类,但的确很神奇的密码学应用
- privately outsourcing computation 私下外包计算
- 例如:
-
Google可以不知道query, 仅仅通过E[query]返回E[query]对应的搜索结果,但搜索者可以解密,得到正确的查询结果
- 整个过程Google也不知道search了什么,返回了什么,但确实search到了
-
- 例如:
- Zero Knowledge (proof of knowledge)
- 零知识
- 如零知识证明: 证明者能够在不向验证者提供任何有用的信息的情况下,使验证者相信某个论断是正确的
- Alice知道一个大数N = pq, 也知道p q
- Bob只知道N, 不知道p q
- 任务:使Bob相信Alice知道N q p, 也使Alice相信Bob确实只知道N
- 密码学:严密的科学 A rigorous science
- The three steps in cryptography
- Precisely specify threat model
- propose a construction
- Prove: No attacker can break the construction under the threat model
- The three steps in cryptography
0.3 History of Cryptography
相关书籍
- "The code breakers" -- 1996
- 从Babylonian era to present的密码学history
Symmetric Ciphers
- symmetric: the same key K
Few History Examples
- all badly broken
- Substitution cipher
- using substitution table(s)
- the Key is the table(s)
- Caesar Cipher
- key: shift by 3
- a --> d; b-->e; c-->f
- The key space (for 26 letters): 26!
- about
- it is still teribly insecure
- key: shift by 3
- The break methods:
- The most common letter in English: "E"
- Step 1: Use frequency of English letters
- prior knowledge: 'e' 12.7%, 't': 9.1% ....
- Step 2: Use frequency of pairs of letters (diagrams)
- match the most frequent pairs
- try and error
- get more and more elements in the key table
- The attack methods: ciphertext only
- the worst possible type of attack
- Vigener cipher (16 the century, Rome)
- The key is a word
- e.g.,
- k = C R Y P T O
- m = W H A T A N I C E D A Y T O D A Y
- c = (k + m) mode 26
- c = Z Z Z J U C L U D T U N W G C Q S
- attack methods:
-
assume: know the lenght of k
-
len(k) = 6, then divide the m to some branch of groups,长度也为k
-
c = Z Z Z J U C | L U D T U N | W G C Q S
-
the first letters: Z, L, W
-
他们分别是3个明文字符移动相同位置后的结果
-
即Z, L, W ... 这些set{相同位置的字母}与englist letters有着相同的分布
- 频率最高的为’e‘
- 退化为substitution encryption
-
之后,即可得到key #1
- repeat, and get the whole k
-
without knowing the lenght of key?
- just loop to search the lenght of the key!
-
- Rotor Machines (1870-1943)
-
Early example: the Herben machine (single rotor 转子)
-
每按一个按键,disc rotates by one notch, 更新一次substitution table
-
secret key: the Disc!
- encodes a substitution table
-
The Enigma (3-5 rotos)
- World War II
-
- Data Encryption Standard DES (1974)
- proposed by a group at IBM
- DES: # key = , block size = 64 bits
- 是分组加密,不像之前rotor machine那样stream cipher
- Today: AES (2001, 128 Bits key), Salsa20 (2008) etc.
0.4 Discrete Probablity
Basic Symbols and definitions
- U: finite set (e.g., )
- {0,1}^2 = {00, 01, 10, 11}
- Def: probability distribution P over U is a function P: U --> [0,1]
- such that P(x) = 1$
- examples:
- Uniform distribution: for all , P(x) = 1/|U|
- |U| is the size of the universe U
- Point distribution at : P(x0) = 1, 其他x: P(x) = 0
- Uniform distribution: for all , P(x) = 1/|U|
- Distribution vector:
- 有限集 (离散的概率分布)
- 可以write down每一个具体的probalibility
- 概率分布可以组成一个distribution vector
- 如 for U = {0,1}^3: (P(000), (P001), ... ,P(111))
- 有限集 (离散的概率分布)
Events
- For U的一个子集A,
- Pr[U] = 1
- Pr和P表示概率时的区别:
- 根据本页PPT,似乎P表示单个元素发生的概率,Pr表示多个元素所构成的事件event发生的概率
- 但找不到佐证!
- The set A is called an event
- 根据本页PPT,似乎P表示单个元素发生的概率,Pr表示多个元素所构成的事件event发生的概率
- Example:
- A = {all x in U such that lsb_2(x) = 11}
- Note:
- lsb_2(x) = 11: the two least siginicant bits of the byte = 11
- 也就是最低(最右)两bits 为 11
- Note:
- then, foe the uniform distribution on {0,1}^8,
- Pr[A] = ?
- 1/4
- A = {all x in U such that lsb_2(x) = 11}
The Union bound
- For events A1 and A2:
- Pr [A1 U A2] <= Pr[A1] + Pr[A2]
- Example
- Pr [A1 U A2] <= Pr[A1] + Pr[A2]
Random Variables
- Def: a random variable X is a function X: U --> V
- The set V: where the random variables takes its values
- 随机数的取值集合
- The set V: where the random variables takes its values
- example: X:{0,1}^n --> {0,1}; X(y) = lsb(y) {0,1}
- and for the uniform distribution on U:
- Pr[X=0] = 1/2; Pr[X=1] = 1/2
- Pr[X=0] = 1/2; Pr[X=1] = 1/2
- More generally:
- random variable X induces a distribution on V:
-
- sample a random element in the universe U
- then apply function X
- the output is = v的概率是多大?
- 即等式左侧
- 等式右侧:符合上述要求的U中的元素的概率
- 二者相等
-
- random variable X induces a distribution on V:
- and for the uniform distribution on U:
The uniform random variable
- Let U be some set, 如U = {0,1}^n
- write r: denote a uniform random variable over U
- : 表示随机变量r是从U中均匀采样得到的
- for all : Pr[r = a] = 1/ |U |
- Practice: Let r be a uniform random variable on {0,1}^2,
- Define the random variable X = r1 + r2
- Then, Pr[X=2] =?
- ans: 1/4
Randomized algorithms
-
Deterministic algorithms:
- the output y is always the same.
- the output y is always the same.
-
Randomized algorithm
- where
- output is a random variable
- example:
- A(m;k) = E(k,m),
- E(k,m): 定义了一个随机变量
- 其取值即为加密空间的可能值
- 随k (密钥)不同而不同
- E(k,m): 定义了一个随机变量
- A(m;k) = E(k,m),
- where
Recap 扼要重述
- finite Set U
- Prob. distr. P over U:
- a function P: U --> [0,1]
- is called an event
- Pr[A] = P(x) for
- Random variable: a function X: U--> V
- X takes values in V and defines a distribution on V
Independence
- Def: events A and B are independent if
- Pr [A and B] = Pr[A] Pr[B]
- means: 知道A的信息,对获取B的信息毫无帮助
- random variables X, Y taking values in V are independent if
- : Pr[X=a and X=b] = Pr[X=a] Pr[Y=b]
- means: even if you konw x = a, that tells nothing about the value of y
- Example: U = {0,1}^2 = {00,11,01,10} and
- Define r.v. (random variable) X and Y as:
- X = lsb(r), Y = msb(r)
- Pr[X = 1 and Y = 1] = 0.25
- Pr[X=1] = Pr[Y=1] = 1/2
- for all (0,1) pairs, the above Prs are right
- 知道lsb=1对判断msb毫无帮助
- 二者independent
- Define r.v. (random variable) X and Y as:
XOR
- Review
- XOR: bit-wise addition mod 2
- An important property of XOR
- 定理:Y是{0,1}^n上的一个随机变量,X是{0,1}^n上的一个独立均匀变量(indep. uniform var.)
- Then: Z:= Y XOR X 也是{0,1}^n上的一个均匀随机变量
- 解读:
- Y是{0,1}^n上的一个随机变量: means we know nothing about
- X关于Y独立,且均匀分布
- 无论Y是什么分布的,Z:= Y XOR X始终均匀分布!
- 即,if I take an arbitrarily malicious distribution and XOR with an indepentent uniform random variable, 就可以得到一个均匀分布的变量!
- 因此XOR非常重要
- Proof:
- for n = 1:
- Pr[Z = 0] = Pr[(X,y) = (0,0) or (X,Y) = (1,1)] = (p0+p1)/2
- Pr[Z = 1] = (p0+p1)/2
- therefore, Z is uniform var.
- for n = 1:
- 定理:Y是{0,1}^n上的一个随机变量,X是{0,1}^n上的一个独立均匀变量(indep. uniform var.)
The birthday paradox
- Thm: Let r1, r2, ..., rn be indep. identically distributed random vars
- when n = 1.2 * , then
- just need
- example:
- Let |U| = {0,1}^{128}
- after sampling about random messages from U, some two sampled messages will likely be the same
- paradox: 比预期小很多