Skip to Content
Problem Solving

8-Cryptography

2019-07-21Original-language archivelegacy assets may be incomplete

概论

  • 密码系统:(K,M,C)(\mathcal{K}, \mathcal{M}, \mathcal{C})
    • K\mathcal{K} 所有可能秘钥组成的集合
    • M\mathcal{M} 所有可能明文组成的集合
    • C\mathcal{C} 所有可能密文组成的集合
  • 密码:(E,D)(E,D)
    • EE: 加密算法 M×KC\mathcal{M}\times\mathcal{K}\rightarrow\mathcal{C}
    • DD: 解密算法 D×KM\mathcal{D}\times\mathcal{K}\rightarrow\mathcal{M}
  • 一致性原则:mM,kK,D(k,E(k,m))=m\forall m\in M,k\in K,D(k,E(k,m))=m
    • 通常 EE 是一个随机化算法
    • DD 一定是一个确定化算法

OTP (One Time Pad)

  • K={0,1}nK=\{0,1\}^n
  • M={0,1}nM=\{0,1\}^n
  • C={0,1}n=MC=\{0,1\}^n=\mathcal{M}
  • E(m,k)=kmE(m,k)=k\oplus m
  • D(c,k)=kcD(c,k)=k\oplus c

PRG 伪随机数生成器

  • 高效,确定,不可预测

流密码

A stream cipher is a symmetric key cipher where plaintext digits are combined with a pseudorandom cipher digit stream (keystream). In a stream cipher, each plaintext digit is encrypted one at a time with the corresponding digit of the keystream, to give a digit of the ciphertext stream.

RC4

  • 初始化
    • 秘钥参与S盒的生成
  • 伪随机子密码生成算法
    • 按字节操作,每次通过一定算法定位S盒中一个元素,与输入异或得到密文

ChaCha

分组密码

a block cipher is a deterministic algorithm operating on fixed-length groups of bits, called a block, with an unvarying transformation that is specified by a symmetric key

DES

RC5

AES/Rijndael

Rijndael是一个分组密码算法族,其分组长度包括128比特、160比特、192比特、224比特、256比特,密钥长度也包括这五种长度,但是最终AES只选取了分组长度为128比特,密钥长度为128比特、192比特和256比特的三个版本

密码散列函数

单向函数,极其难以由散列函数输出的结果回推输入的数据是什么

MD-5

输出128位

SHA-1

1995,160位,已被攻破

SHA-2

2001, SHA-224、SHA-256、SHA-384、SHA-512、SHA-512/224、SHA-512/256

SHA-3

2015

非对称加密

RSA

ECC

圆锥曲线

代数编码

  • maximum-likelihood decoding: ee has the least weight
  • binary symmetric channel
    • XB(n,p)X\sim B(n,p)
  • Block codes
    • (n,m)(n,m)-block code
      • [n,m,d][n,m,d]-code
      • encoding function: E:Z2mZ2nE:\mathbb{Z}_2^m\rightarrow\mathbb{Z}_2^n
      • decoding function: D:Z2nZ2mD:\mathbb{Z}_2^n\rightarrow\mathbb{Z}_2^m
      • codeword: element in image of EE (nn)
    • Hamming distance: d(x,y)d(x,y)
    • weight: w(x)=d(x,0)w(x)=d(x,0)
      • w(x+y)=d(x,y)w(x+y)=d(x,y)
    • correcting: t=[dmin12]t=[\frac{d_{\min}-1}{2}]
    • detecting:e=dmin1e=d_{\min}-1
    • combined:dmint+e+1,(e>t)d_{\min}\geq t+e+1,(e>t)
    • 冗余度:nmm\frac{n-m}{m}
    • 编码率:mn\frac{m}{n}
  • Group code: code that is also a subgroup of Z2n\mathbb{Z}_2^n
    • dmin=min{w(x):x0}d_{\min}=\min\{w(x):x\not=0\}
  • Linear code: A linear code CC of length n is a linear subspace of the vector space Z2n\mathbb{Z}_2^n
    • Null(H),HMm×n(Z2)\text{Null}(H), H \in\mathbb{M}_{m\times n}(\mathbb{Z}_2)
      • C=Null(H)C=\text{Null}(H) is a group code
    • Col(Gn×k)=Null(H(nk)×n)\text{Col}(G_{n\times k})=\text{Null}(H_{(n-k)\times n})
      • Gx=y    Hy=0Gx=y\iff Hy=0
  • 循环码:线性码满足任一码字左移或右移一位后,得到的仍然是该码的一个码字
    • 码多项式:把码组中各码元作为多项式系数 T(x)=i=0n1aixiT(x)=\sum_{i=0}^{n-1}a_{i}x^i
    • (n,m) 循环码每个码字在以 xn+1x^n+1 为模运算的剩余类中某一类
    • 生成多项式 g(x)g(x)
      • 常数项为 11r=nmr=n-m 次多项式
      • xn+1x^n+1 的因式
      • 其它码多项式为其倍式
      • 不唯一

Parity-Check

  • canonical parity check matrix: H=(AIm),Am×(nm)H=(A|I_m),A_{m\times(n-m)}
    • HH give rise to an (n,nm)(n,n-m)-block code
  • standard generator matrix: Gn×(nm)=(InmA)G_{n\times(n-m)}=(\frac{I_{n-m}}{A})
    • HG=0HG=0
  • d(C)d(C) equals the minimum number of linearly dependent columns of HH
    • Null(H)\text{Null}(H) is a single error-detecting code if and only if no column of HH consists entirely of zeros
    • Null(H)\text{Null}(H) is a single error-correcting code if and only if HH does not contain any zero columns and no two columns of HH are identical
  • Syndrone Decoding
    • syndrone of xx: HxHx
    • x=c+e,Hx=Hex=c+e,Hx=He
    • if the syndrome of rr is equal to some column of HH, say the ith column, then the error has occurred in the ith bit
  • Coset Decoding (Standard Decoding)
    • (n,m)(n,m)-linear code has 2nm2^{n-m} cosets
    • coset leader: an n-tuple of least weight in a coset
    • xx and yy are in the same coset     Hx=Hy\iff Hx=Hy
  • Correcting one error: [2r1,2rr1,3]2[2^r − 1, 2^r − r − 1, 3]_2-code
  • Detecting one error: [r+1,r,2]2[r+1, r, 2]_2-code

卷积码

  • 卷积码 (n,k,N)(n,k,N)
    • 将当前 kk 比特信息编码为 nn 个比特
    • m=(N1)m=(N-1) 信息段
  • 解码
    • 代数解码:大数逻辑解码
    • 概率解码:维特比解码
      • 将接收到的信号序列和所有可能的发送信号序列比较,选择其中汉明距离最小的序列认为是当前发送信号序列
      • 最大似然
      • 动态规划