RSA,DSA,ECDSA,EdDSA和Ed25519的差別
用過ssh的朋友都知道,ssh key的類型有很多種,比如dsa、rsa、 ecdsa、ed25519等,那這麼多種類型,我們要如何選擇呢?
說明
- 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 提供更好的安全性,并且具有更好的性能(人為注意)。
- 其他說明
- 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).
結論
- ssh key的類型有四種,分别是dsa、rsa、 ecdsa、ed25519。
- 根據數學特性,這四種類型又可以分為兩大類,dsa/rsa是一類,ecdsa/ed25519是一類,後者算法更先進。
- dsa因為安全問題,已不再使用了。
- ecdsa因為政治原因和技術原因,也不推薦使用。
- rsa是目前相容性最好的,應用最廣泛的key類型,在用ssh-keygen工具生成key的時候,預設使用的也是這種類型。不過在生成key時,如果指定的key size太小的話,也是有安全問題的,推薦key size是3072或更大。
- ed25519是目前最安全、加解密速度最快的key類型,由于其數學特性,它的key的長度比rsa小很多,優先推薦使用。它目前唯一的問題就是相容性,即在舊版本的ssh工具集中可能無法使用。不過據我目前測試,還沒有發現此類問題。
總結
優先選擇ed25519,否則選擇rsa
Reference
- https://qastack.cn/ubuntu/363207/what-is-the-difference-between-the-rsa-dsa-and-ecdsa-keys-that-ssh-uses
- https://segmentfault.com/a/1190000020166520