RSA

RSA算法

  1. 选择两个大素数\(P\)\(Q\)
  2. 计算\(n=P×Q\)\(φ⁡(n)=(P-1)(Q-1)\),其中\(φ⁡(n)\)\(n\)的欧拉函数
  3. 选择整数\(e\),满足\(1<e<φ⁡(n)\),且\(\mbox{gcd}⁡(φ⁡(n),e)=1\)
  4. 计算\(d\),满足\(d⋅e≡1 \pmod{φ⁡(n)}\),其中\(d\)\(e\)在模\(φ⁡(n)\)下的乘法逆元
  5. \({e,n}\)为公钥,\({d,n}\)为私钥

密文:\(c≡m^e \pmod{n}\)
明文:\(m≡c^d \pmod{n}\)

$c^d \pmod{n}≡m^{d⋅e} \pmod{n}≡m^{1 \pmod{φ⁡(n)}} \pmod{n}≡m^{k⋅φ⁡(n)+1} \pmod{n}$

欧拉定理
\(a,m∈N^+\),且\(\mbox{gcd}⁡(a,m)=1\),则有

\(a^{φ⁡(m)}≡1 \pmod{m}\)
其中,\(φ⁡(m)\)称为对模\(m\)缩系的元素个数(欧拉函数)。
证明:
设与\(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\}\)元素一一对应,进而
\(\left. {\prod\limits_{i = 1}^{\varphi{(m)}}A_{i}} \equiv a^{\varphi{(m)}}{\prod\limits_{i = 1}^{\varphi{(m)}}b_{i}} \equiv {\prod\limits_{i = 1}^{\varphi{(m)}}b_{i}}~\pmod{m}\Rightarrow a^{\varphi{(m)}} \equiv 1~\pmod{m} \right.\)

费马小定理
\(a∈N\)\(p\)为质数,则有

\(a^p≡a\pmod{p}\)

证明:
\(a=1\),显然有\(1^p≡1\pmod{p}\)
设当\(a=k\),有\(k^p≡k\pmod{p}⇒p|(k^p-k)\)成立。考虑\(a=k+1\)时,有
\(\left( {k + 1} \right)^{p} = {\sum\limits_{i = 0}^{p}{C_{p}^{i}k^{i}}} = {\sum\limits_{i = 1}^{p - 1}{C_{p}^{i}k^{i}}} + k^{p} + 1\)

由于\( \left. p \middle| {\sum\limits_{i = 1}^{p - 1}{C_{p}^{i}k^{i}}} \right.\)\(k^p≡k\pmod{p}\),故
\( \left( {k + 1} \right)^{p} = {\sum\limits_{i = 1}^{p - 1}{C_{p}^{i}k^{i}}} + k^{p} + 1 \equiv k + 1~\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}\)成立。

  1. \(\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.\)
  2. \(\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}\)
posted @ 2024-10-18 13:58  Miro'  阅读(12)  评论(0编辑  收藏  举报