RSA
RSA公開密鑰密碼體制。
所謂的公開密鑰密碼體制就是使用不同的加密密鑰與解密密鑰,是一種“由已知加密密鑰推導出解密密鑰在計算上是不可行的”密碼體制。
- Choose two distinct prime numbers p and q. 【兩個大質數】
- For security purposes, the integers p and q should be chosen at random, and should be of similar bit-length. Prime integers can be efficiently found using a primality test.
- Compute n = pq. 【n是兩個大質數p、q的積】
- n is used as the modulus for both the public and private keys
- Compute φ(n) = (p – 1)(q – 1), where φ is Euler's totient function.
- Choose an integer e such that 1 < e < φ(n) and greatest common divisor of (e, φ(n)) = 1; i.e., e and φ(n) are coprime. 【e 和 φ(n) 互質】
- e is released as the public key exponent. 【e是公鑰匙】
- e having a short bit-length and small Hamming weight results in more efficient encryption - most commonly 0x10001 = 65,537. However, small values of e (such as 3) have been shown to be less secure in some settings.[4]
- Determine d as:
-
-
-
i.e.,
d is the
multiplicative inverse of
e mod φ(n).
- This is more clearly stated as solve for d given (de) mod φ(n) = 1
- This is often computed using the extended Euclidean algorithm.
- d is kept as the private key exponent. 【d是秘匙】
-
He first turns M into an integer m, such that
by using an agreed-upon reversible protocol known as a padding scheme. He then computes the ciphertext
corresponding to
.
Alice can recover
from
by using her private key exponent
via computing
-
.
Given
, she can recover the original message M by reversing the padding scheme.
RSA的安全性依賴於大數分解,因此,模數n 必須選大一些,因具體適用情況而定。
由於進行的都是大數計算,使得RSA最快的情況也比DES慢上好幾倍,無論是軟件還是硬件實現。速度一直是RSA的缺陷。一般來說只用於少量數據加密。
http://baike.baidu.com/view/7520.htm
http://en.wikipedia.org/wiki/RSA_(algorithm)
DH
| Alice | Bob | |||||
|---|---|---|---|---|---|---|
| Secret | Public | Calculates | Sends | Calculates | Public | Secret |
| a | p, g | p,g![]() |
b | |||
| a | p, g, A | ga mod p = A | A![]() |
p, g | b | |
| a | p, g, A | B |
gb mod p = B | p, g, A, B | b | |
| a, s | p, g, A, B | Ba mod p = s | Ab mod p = s | p, g, A, B | b, s | |

安全性:
Diffie-Hellman密鑰交換算法的安全性依賴於這樣一個事實:雖然計算以一個素數為模的指數相對容易,但計算離散對數卻很困難。對於大的素數,計算出離散對數幾乎是不可能的。
在選擇了合適的G和g時,這個協議被認為是竊聽安全的。
如果Alice和Bob使用的隨機數生成器不能做到完全隨機並且從某種程度上講是可預測的,那么Eve的工作將簡單的多。
身份驗證
在最初的描述中,迪菲-赫爾曼密鑰交換本身並沒有提供通訊雙方的身份驗證服務,因此它很容易受到中間人攻擊。 一個中間人在信道的中央進行兩次迪菲-赫爾曼密鑰交換,一次和Alice另一次和Bob,就能夠成功的向Alice假裝自己是Bob,反之亦然。而攻擊者可以解密(讀取和存儲)任何一個人的信息並重新加密信息,然后傳遞給另一個人。因此通常都需要一個能夠驗證通訊雙方身份的機制來防止這類攻擊。
優缺點:
1、 僅當需要時才生成密鑰,減小了將密鑰存儲很長一段時間而致使遭受攻擊的機會。
然而,該技術也存在許多不足:
http://en.wikipedia.org/wiki/Diffie-Hellman_key_exchange
DSS/DSA算法
Digital Signature Algorithm
(DSA)是Schnorr和ElGamal簽名算法的變種,被美國NIST作為DSS(Digital SignatureStandard)。算法中應用了下述參數:
p:L bits長的素數。L是64的倍數,范圍是512到1024;
q:p - 1的160bits的素因子;
g:g = h^((p-1)/q) mod p,h滿足h < p - 1, h^((p-1)/q) mod p > 1;
x:x < q,x為私鑰 ;
y:y = g^x mod p ,( p, q, g, y )為公鑰;
H( x ):One-Way Hash函數。DSS中選用SHA( Secure Hash Algorithm )。
p, q,
g可由一組用戶共享,但在實際應用中,使用公共模數可能會帶來一定的威脅。簽名及驗證協議如下:
1. P產生隨機數k,k < q;
2. P計算 r = ( g^k mod p ) mod q
s = ( k^(-1) (H(m) + xr)) mod q
簽名結果是( m, r, s )。
3. 驗證時計算 w = s^(-1)mod q
u1 = ( H( m ) * w ) mod q
u2 = ( r * w ) mod q
v = (( g^u1 * y^u2 ) mod p ) mod q
若v = r,則認為簽名有效。
DSA是基於整數有限域離散對數難題的,其安全性與RSA相比差不多。DSA的一個重要特點是兩個素數公開,這樣,當使用別人的p和q時,即使不知道私鑰,你也能確認它們是否是隨機產生的,還是作了手腳。RSA算法卻作不到。

to

B