RSA
RSA算法
- 选择两个大素数\(P\)和\(Q\)
- 计算\(n=P×Q\),\(φ(n)=(P-1)(Q-1)\),其中\(φ(n)\)是\(n\)的欧拉函数
- 选择整数\(e\),满足\(1<e<φ(n)\),且\(\mbox{gcd}(φ(n),e)=1\)
- 计算\(d\),满足\(d⋅e≡1 \pmod{φ(n)}\),其中\(d\)是\(e\)在模\(φ(n)\)下的乘法逆元
- \({e,n}\)为公钥,\({d,n}\)为私钥
密文:\(c≡m^e \pmod{n}\)
明文:\(m≡c^d \pmod{n}\)
欧拉定理
设\(a,m∈N^+\),且\(\mbox{gcd}(a,m)=1\),则有
证明:
设与\(m\)互质的数为数列\(\{b_n\}=\{b_1,b_2,…,b_{φ(m)}\}\)。由于\(\mbox{gcd}(a,m)=1\),故\(\mbox{gcd}(a,b_i)=1\),因此数列\(\{A_n\}=\{ab_1,ab_2,…,ab_{φ(m)}\}\)有\(\mbox{gcd}(m,A_i)=1\)且\(A_i≠A_j \pmod{m}\),即有\(\{b_n\}\)与\(\{A_n\}\)元素一一对应,进而
费马小定理
设\(a∈N\),\(p\)为质数,则有
证明:
当\(a=1\),显然有\(1^p≡1\pmod{p}\)。
设当\(a=k\),有\(k^p≡k\pmod{p}⇒p|(k^p-k)\)成立。考虑\(a=k+1\)时,有
由于\( \left. p \middle| {\sum\limits_{i = 1}^{p - 1}{C_{p}^{i}k^{i}}} \right.\)且\(k^p≡k\pmod{p}\),故
根据数学归纳法,对\(∀a∈N\),有\(a^p≡a\pmod{p}\)成立,证毕。
RSA算法证明
证\(m≡c^d\pmod{n}≡(m^e\pmod{n})^d\pmod{n}≡m^ed\pmod{n}\)成立。由于\(e⋅d≡1\pmod{φ(n)}⇒e⋅d=k⋅φ(n)+1\),即证\(m^{k⋅φ(n)+1}≡m\pmod{n}\)成立。
- \(\mbox{gcd}(n,m)=1\)
\(\left. \overset{Euler~Theorem}{\Rightarrow}m^{\varphi{(n)}} \equiv 1~\pmod{n}\Rightarrow m^{k \cdot {\varphi{(n)}}} \equiv 1~\pmod{n}\Rightarrow m^{k \cdot {\varphi{(n)}} + 1} \equiv m~\pmod{n}\Rightarrow m^{ed} \equiv m~\pmod{n} \right.\) - \(\mbox{gcd}(n,m)≠1\)
由于\(n=p⋅q\)且\(n>m\),令\(m=α⋅p\),其中\(1<α<q\),可知\(\begin{array}{cl} & {{\gcd\left( {\alpha,q} \right)} = 1} \\ \overset{Fermat's~Little~Theorem}{\Rightarrow} & {\left( {\alpha \cdot p} \right)^{q - 1} \equiv 1~\pmod{n}} \\ \Rightarrow & {\left( {\alpha \cdot p} \right)^{{({q - 1})} \cdot {({p - 1})} \cdot k} \cdot \left( {\alpha \cdot p} \right) \equiv \alpha \cdot p~\pmod{n}} \end{array}\)
又因\(φ(n)=(p-1)⋅(q-1)\)且\(e⋅d=k⋅φ(n)+1\),进而\( \begin{array}{ll} & {\left( {\alpha \cdot p} \right)^{ed} \equiv \alpha \cdot p~\pmod{n}} \\ \Rightarrow & {\left( {\alpha \cdot p} \right)^{ed} = \beta \cdot q + \alpha \cdot p} \\ \Rightarrow & {\left( {\alpha \cdot p} \right)\left( {\left( {\alpha \cdot p} \right)^{ed - 1} - 1} \right) = \beta \cdot q} \\ \Rightarrow & \left. \alpha \cdot p \middle| \beta \cdot q \right. \\ \Rightarrow & \left. p \middle| \beta \cdot q \right. \\ \Rightarrow & \left. p \middle| t \right. \end{array}\)
令\(t=γ⋅p\),即有\(\begin{array}{ll} & {\left( {\alpha \cdot p} \right)^{ed} = \gamma \cdot p \cdot q + \alpha \cdot p} \\ \Rightarrow & {m^{ed} = \gamma \cdot n + m} \\ \Rightarrow & {m^{ed} \equiv m~\pmod{n}} \end{array}\)