1. 程式人生 > 其它 >RSA,DSA,ECDSA,EdDSA和Ed25519的區別

RSA,DSA,ECDSA,EdDSA和Ed25519的區別

RSA,DSA,ECDSA,EdDSA和Ed25519的區別

用過ssh的朋友都知道,ssh key的型別有很多種,比如dsa、rsa、 ecdsa、ed25519等,那這麼多種型別,我們要如何選擇呢?

說明

  1. RSA,DSA,ECDSA,EdDSA和Ed25519都用於數字簽名,但只有RSA也可以用於加密。

    • RSA(Rivest–Shamir–Adleman)是最早的公鑰密碼系統之一,被廣泛用於安全資料傳輸。它的安全性取決於整數分解,因此永遠不需要安全的RNG(隨機數生成器)。與DSA相比,RSA的簽名驗證速度更快,但生成速度較慢。

    • DSA(數字簽名演算法)是用於數字簽名的聯邦資訊處理標準。它的安全性取決於離散的對數問題。與RSA相比,DSA的簽名生成速度更快,但驗證速度較慢。如果使用錯誤的數字生成器,可能會破壞安全性。

    • ECDSA(橢圓曲線數字簽名演算法)是DSA(數字簽名演算法)的橢圓曲線實現。橢圓曲線密碼術能夠以較小的金鑰提供與RSA相對相同的安全級別。它還具有DSA對不良RNG敏感的缺點。

    • EdDSA(愛德華茲曲線數字簽名演算法)是一種使用基於扭曲愛德華茲曲線的Schnorr簽名變體的數字簽名方案。簽名建立在EdDSA中是確定性的,其安全性是基於某些離散對數問題的難處理性,因此它比DSA和ECDSA更安全,後者要求每個簽名都具有高質量的隨機性。

    • Ed25519是EdDSA簽名方案,但使用SHA-512 / 256和Curve25519;它是一條安全的橢圓形曲線,比DSA,ECDSA和EdDSA 提供更好的安全性,並且具有更好的效能(人為注意)。

  2. 其他說明

    • RSA金鑰使用最廣泛,因此似乎得到最好的支援。

    • ECDSA(在OpenSSH v5.7中引入)在計算上比DSA輕,但是除非您有一臺處理能力非常低的機器,否則差異並不明顯。

    • 從OpenSSH 7.0開始,預設情況下SSH不再支援DSA金鑰(ssh-dss)。根據SSH標準(RFC 4251及更高版本),DSA金鑰可用於任何地方。

    • Ed25519在openSSH 6.5中引入。

    • 相關文章

      OpenSSH supports several signing algorithms (for authentication keys) which can be divided in two groups depending on the mathematical properties they exploit:
      
      DSA and RSA, which rely on the practical difficulty of factoring the product of two large prime numbers,
      ECDSA and Ed25519, which rely on the elliptic curve discrete logarithm problem. (example)
      Elliptic curve cryptography (ECC) algorithms are a more recent addition to public key cryptosystems. One of their main advantages is their ability to provide the same level of security with smaller keys, which makes for less computationally intensive operations (i.e. faster key creation, encryption and decryption) and reduced storage and transmission requirements.
      
      OpenSSH 7.0 deprecated and disabled support for DSA keys due to discovered vulnerabilities, therefore the choice of cryptosystem lies within RSA or one of the two types of ECC.
      
      #RSA keys will give you the greatest portability, while #Ed25519 will give you the best security but requires recent versions of client & server[2]. #ECDSA is likely more compatible than Ed25519 (though still less than RSA), but suspicions exist about its security (see below).
      

結論

  1. ssh key的型別有四種,分別是dsa、rsa、 ecdsa、ed25519。

  2. 根據數學特性,這四種類型又可以分為兩大類,dsa/rsa是一類,ecdsa/ed25519是一類,後者演算法更先進。

  3. dsa因為安全問題,已不再使用了。

  4. ecdsa因為政治原因和技術原因,也不推薦使用。

  5. rsa是目前相容性最好的,應用最廣泛的key型別,在用ssh-keygen工具生成key的時候,預設使用的也是這種型別。不過在生成key時,如果指定的key size太小的話,也是有安全問題的,推薦key size是3072或更大。

  6. ed25519是目前最安全、加解密速度最快的key型別,由於其數學特性,它的key的長度比rsa小很多,優先推薦使用。它目前唯一的問題就是相容性,即在舊版本的ssh工具集中可能無法使用。不過據我目前測試,還沒有發現此類問題。

總結

    優先選擇ed25519,否則選擇rsa 



Reference