Jump to content

Elliptic-curve Diffie–Hellman: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
the introduction text was encrypted funnily enough. So copied back the text for the description section that existed on May 10th 2022 as it seemed to have been changed in error
Tag: Reverted
Kr0ndstat (talk | contribs)
m →‎Diffie-Hellman Key Agreement on Montgomery Curves: Linked first occurrence of Daniel J. Bernstein
 
(19 intermediate revisions by 14 users not shown)
Line 1: Line 1:
{{Short description|Key agreement protocol}}
Elliptic-curve Diffie–Hellman (ECDH) is a key agreement protocol that allows two parties, each having an elliptic-curve public–private key pair, to establish a shared secret over an insecure channel.[1][2][3] This shared secret may be directly used as a key, or to derive another key. The key, or the derived key, can then be used to encrypt subsequent communications using a symmetric-key cipher. It is a variant of the Diffie–Hellman protocol using elliptic-curve cryptography.
'''Elliptic-curve Diffie–Hellman''' ('''ECDH''') is a [[key agreement]] protocol that allows two parties, each having an [[Elliptic curve|elliptic-curve]] public–private key pair, to establish a [[shared secret]] over an [[insecure channel]].<ref>NIST, [http://csrc.nist.gov/publications/nistpubs/800-56A/SP800-56A_Revision1_Mar08-2007.pdf Special Publication 800-56A, Recommendation for Pair-Wise Key Establishment Schemes Using Discrete Logarithm Cryptography], March, 2006.</ref><ref>Certicom Research, [http://www.secg.org/sec1-v2.pdf Standards for efficient cryptography, SEC 1: Elliptic Curve Cryptography], Version 2.0, May 21, 2009.</ref><ref>NSA Suite B Cryptography, [http://www.nsa.gov/ia/_files/SuiteB_Implementer_G-113808.pdf Suite B Implementers' Guide to NIST SP 800-56A] {{Webarchive|url=https://web.archive.org/web/20160306033416/http://www.nsa.gov/ia/_files/SuiteB_Implementer_G-113808.pdf |date=2016-03-06 }}, July 28, 2009.</ref> This shared secret may be directly used as a key, or to [[Key derivation function|derive another key]]. The key, or the derived key, can then be used to encrypt subsequent communications using a [[Symmetric-key algorithm|symmetric-key cipher]]. It is a variant of the [[Diffie–Hellman key exchange|Diffie–Hellman]] protocol using [[elliptic-curve cryptography]].


==Key establishment protocol==
==Key establishment protocol==
Line 13: Line 14:


If Alice maliciously chooses invalid curve points for her key and Bob does not validate that Alice's points are part of the selected group, she can collect enough residues of Bob's key to derive his private key. Several [[Transport Layer Security|TLS]] libraries were found to be vulnerable to this attack.<ref>{{cite journal
If Alice maliciously chooses invalid curve points for her key and Bob does not validate that Alice's points are part of the selected group, she can collect enough residues of Bob's key to derive his private key. Several [[Transport Layer Security|TLS]] libraries were found to be vulnerable to this attack.<ref>{{cite journal
| url = https://www.ei.ruhr-uni-bochum.de/media/nds/veroeffentlichungen/2015/09/14/main-full.pdf
| url = https://www.nds.ruhr-uni-bochum.de/media/nds/veroeffentlichungen/2015/09/14/main-full.pdf
| title = Practical Invalid Curve Attacks on TLS-ECDH
| title = Practical Invalid Curve Attacks on TLS-ECDH
| author1 = Tibor Jager
| author1 = Tibor Jager
Line 22: Line 23:
}}</ref>
}}</ref>


While the shared secret may be used directly as a key, it can be desirable to hash the secret to remove weak bits due to the Diffie–Hellman exchange.
The shared secret is uniformly distributed on a subset of <math>[0, p)</math> of size <math>(n+1)/2</math>. For this reason, the secret should not be used directly as a symmetric key, but it can be used as entropy for a key derivation function.

===Diffie-Hellman Key Agreement on Montgomery Curves===
Let <math>A, B \in F_p</math> such that <math>B(A^2 - 4) \neq 0</math>. The Montgomery form elliptic curve <math>E_{M,A,B}</math> is the set of all <math>(x,y) \in F_p \times F_p</math> satisfying the equation <math>By^2 = x(x^2 + Ax + 1)</math> along with the point at infinity denoted as <math>\infty</math>. This is called the affine form of the curve. The set of all <math>F_p</math>-rational points of <math>E_{M,A,B}</math>, denoted as <math>E_{M,A,B}(F_p)</math> is the set of all <math>(x,y) \in F_p \times F_p</math> satisfying <math>By^2 = x(x^2 + Ax + 1)</math>
along with <math>\infty</math>. Under a suitably defined addition operation, <math>E_{M,A,B}(F_p)</math> is a group with <math>\infty</math> as the identity element. It is known that the order of this group is a multiple of 4. In fact, it is usually possible to obtain <math>A</math> and <math>B</math> such that the order of <math>E_{M,A,B}</math> is <math>4q</math> for a prime <math>q</math>. For more extensive discussions of Montgomery curves and their arithmetic one may follow.<ref name="plmont">{{cite web |last1=Montgomery |first1=Peter L. |title=Speeding the Pollard and elliptic curve methods of factorization |url=https://www.ams.org/journals/mcom/1987-48-177/S0025-5718-1987-0866113-7/S0025-5718-1987-0866113-7.pdf |publisher=Mathematics of Computation, 48(177):243–264, 1987}}</ref><ref name="djbmont">{{cite web |last1=Bernstein |first1=Daniel J. |last2=Lange |first2=Tanja |title=Montgomery curves and the Montgomery ladder |url=https://eprint.iacr.org/2017/293 |publisher=In Joppe W. Bos and Arjen K. Lenstra, editors, Topics in Computational Number Theory inspired by Peter L. Montgomery, pages 82–115. Cambridge University Press, 2017.}}</ref><ref name ="costellomont">{{cite web |last1=Costello |first1=Craig |last2=Smith |first2=Benjamin |title=Montgomery curves and their arithmetic - the case of large characteristic fields |url=https://link.springer.com/article/10.1007/s13389-017-0157-6 |publisher=J. Cryptographic Engineering, 8(3):227–240, 2018.}}</ref>

For computational efficiency, it is preferable to work with projective coordinates. The projective form of the Montgomery curve <math>E_{M,A,B}</math> is <math>BY^2Z = X(X^2 + AXZ + Z^2)</math>. For a point <math>P = [ X : Y : Z ]</math> on <math>E_{M,A,B}</math>, the <math>x</math>-coordinate map <math>x</math> is the following:<ref name ="costellomont"/> <math>x(P) = [ X : Z ]</math> if <math>Z \neq 0</math> and <math>x(P) = [ 1 : 0 ]</math> if <math>P = [ 0 : 1 : 0 ]</math> . [[Daniel J. Bernstein|Bernstein]]<ref>{{cite web |last1=Bernstein |first1=Daniel J. |title=Can we avoid tests for zero in fast elliptic-curve arithmetic? |url=https://cr.yp.to/ecdh/curvezero-20060726.pdf}}</ref><ref name=curve25519/> introduced the map <math>x_0</math> as follows: <math>x_0(X : Z) = XZ^{p - 2}</math> which is defined for all values of <math>X</math> and <math>Z</math> in <math>F_p</math>. Following Miller,<ref>{{cite web |last1=Miller |first1=Victor S. |title=Use of elliptic curves in cryptography |url=https://link.springer.com/chapter/10.1007/3-540-39799-X_31 |publisher=In Advances in Cryptology - CRYPTO’85, Santa Barbara, California, USA, August 18-22, 1985, Proceedings, pages 417–426. Springer Berlin Heidelberg, 1985}}</ref> Montgomery<ref name ="plmont" /> and Bernstein,<ref name = "curve25519">{{cite web |last1=Bernstein |first1=Daniel J. |title=Curve25519: New Diffie-Hellman Speed Records |url=https://doi.org/10.1007/11745853_14 |publisher=In: Yung, M., Dodis, Y., Kiayias, A., Malkin, T. (eds) Public Key Cryptography - PKC 2006. Lecture Notes in Computer Science, vol 3958. Springer, Berlin, Heidelberg}}</ref> the Diffie-Hellman key agreement can be carried out on a Montgomery curve as follows. Let <math>Q</math> be a generator of a prime order subgroup of
<math>E_{M,A,B}(F_p)</math>. Alice chooses a secret key <math>s</math> and has public key <math>x_0(sQ)</math>;
Bob chooses a secret key <math>t</math> and has public key <math>x_0(tQ)</math>. The shared secret key of Alice and Bob is <math>x_0(stQ)</math>. Using classical computers, the best known method of obtaining <math>x_0(stQ)</math> from <math>Q,x_0(sQ)</math> and <math>x_0(tQ)</math> requires about <math>O(p^{1/2})</math> time using the Pollards rho algorithm.<ref>{{cite web |last1=Pollard |first1=John M. |title=Monte Carlo methods for index computation mod p |url=https://www.ams.org/journals/mcom/1978-32-143/S0025-5718-1978-0491431-9/S0025-5718-1978-0491431-9.pdf |publisher=Mathematics of Computation, 32:918–924, 1978}}</ref>

The most famous example of Montgomery curve is [[Curve25519]] which was introduced by Bernstein.<ref name="curve25519"/> For Curve25519, <math>p = 2^{255} - 19, A = 486662</math> and <math>B = 1</math>.
The other Montgomery curve which is part of TLS 1.3 is [[Curve448]] which was introduced
by Hamburg.<ref>{{cite web |last1=Hamburg |first1=Mike |title=Ed448-goldilocks, a new elliptic curve |url=https://eprint.iacr.org/2015/625 |publisher=ACR Cryptology ePrint Archive, 2015:625, 2015}}</ref> For Curve448, <math>p = 2^{448} - 2^{224} - 1, A = 156326</math> and <math>B = 1</math>. Couple of Montgomery curves named M[4698] and M[4058] competitive to [[Curve25519]] and [[Curve448]] respectively have been proposed in.<ref name="knpsjec2022">{{cite web |last1=Nath |first1=Kaushik |last2=Sarkar |first2=Palash |title=Security and Efficiency Trade-offs for Elliptic Curve Diffie-Hellman at the 128- and 224-bit Security Levels |url=https://link.springer.com/article/10.1007/s13389-021-00261-y |publisher= J Cryptogr Eng 12, 107–121 (2022)}}, Code available at https://github.com/kn-cs/x25519</ref> For M[4698], <math>p = 2^{251} - 9, A = 4698, B = 1</math> and for M[4058], <math>p = 2^{444} - 17, A = 4058, B = 1</math>. At 256-bit security level, three Montgomery curves named M[996558], M[952902] and M[1504058] have been proposed in.<ref>{{cite web |last1=Nath |first1=Kaushik |last2=Sarkar |first2=Palash |title=Efficient Elliptic Curve Diffie-Hellman Computation at the 256-bit Security Level |url=https://doi.org/10.1049/iet-ifs.2019.0620 |publisher=IET Information Security, 14(6):633640, 2020}}, Code available at https://github.com/kn-cs/mont256-dh and https://github.com/kn-cs/mont256-vec</ref> For M[996558], <math>p = 2^{506} - 45, A = 996558, B = 1</math>, for M[952902], <math>p = 2^{510} - 75, A = 952902, B = 1</math> and for M[1504058], <math>p = 2^{521} - 1, A = 1504058, B = 1</math> respectively. Apart from these two, other proposals of Montgomery curves can be found at.<ref>{{cite web |last1=Bernstein |first1=Daniel J. |last2=Lange |first2=Tanja |title=Safecurves: choosing safe curves for elliptic- curve cryptography |url=https://safecurves.cr.yp.to/equation.html |access-date=April 15, 2024}}</ref>


== Software ==
== Software ==
* [[Curve25519]] is a popular set of elliptic curve parameters and reference implementation by [[Daniel J. Bernstein]] in [[C language|C]]. [[Language binding|Binding]]s and alternative implementations are also available.
* [[Curve25519]] is a popular set of elliptic curve parameters and reference implementation by [[Daniel J. Bernstein]] in [[C language|C]]. [[Language binding|Binding]]s and alternative implementations are also available.
* [[Line (software)|LINE messenger app]] has used the ECDH protocol for its "Letter Sealing" [[end-to-end encryption]] of all messages sent through said app since October 2015.<ref name="linecorp-letter-sealing">{{cite web|author1=JI|title=New generation of safe messaging: "Letter Sealing"|url=https://engineering.linecorp.com/en/blog/detail/65/|website=LINE Engineers' Blog|publisher=LINE Corporation|access-date=5 February 2018|date=13 October 2015}}</ref>
* [[Line (software)|LINE messenger app]] has used the ECDH protocol for its "Letter Sealing" [[end-to-end encryption]] of all messages sent through said app since October 2015.<ref name="linecorp-letter-sealing">{{cite web|author1=JI|title=New generation of safe messaging: "Letter Sealing"|url=https://engineering.linecorp.com/en/blog/detail/65/|website=LINE Engineers' Blog|publisher=LINE Corporation|access-date=5 February 2018|date=13 October 2015|archive-date=1 February 2019|archive-url=https://web.archive.org/web/20190201120244/https://engineering.linecorp.com/en/blog/detail/65/|url-status=dead}}</ref>
* [[Signal Protocol]] uses ECDH to obtain post-compromise security. Implementations of this protocol are found in [[Signal (software)|Signal]], [[WhatsApp]], [[Facebook Messenger]] and [[Skype]].
* [[Signal Protocol]] uses ECDH to obtain post-compromise security. Implementations of this protocol are found in [[Signal (messaging app)|Signal]], [[WhatsApp]], [[Facebook Messenger]] and [[Skype]].


== See also ==
== See also ==

Latest revision as of 09:16, 27 May 2024

Elliptic-curve Diffie–Hellman (ECDH) is a key agreement protocol that allows two parties, each having an elliptic-curve public–private key pair, to establish a shared secret over an insecure channel.[1][2][3] This shared secret may be directly used as a key, or to derive another key. The key, or the derived key, can then be used to encrypt subsequent communications using a symmetric-key cipher. It is a variant of the Diffie–Hellman protocol using elliptic-curve cryptography.

Key establishment protocol[edit]

The following example illustrates how a shared key is established. Suppose Alice wants to establish a shared key with Bob, but the only channel available for them may be eavesdropped by a third party. Initially, the domain parameters (that is, in the prime case or in the binary case) must be agreed upon. Also, each party must have a key pair suitable for elliptic curve cryptography, consisting of a private key (a randomly selected integer in the interval ) and a public key represented by a point (where , that is, the result of adding to itself times). Let Alice's key pair be and Bob's key pair be . Each party must know the other party's public key prior to execution of the protocol.

Alice computes point . Bob computes point . The shared secret is (the x coordinate of the point). Most standardized protocols based on ECDH derive a symmetric key from using some hash-based key derivation function.

The shared secret calculated by both parties is equal, because .

The only information about her key that Alice initially exposes is her public key. So, no party except Alice can determine Alice's private key (Alice of course knows it by having selected it), unless that party can solve the elliptic curve discrete logarithm problem. Bob's private key is similarly secure. No party other than Alice or Bob can compute the shared secret, unless that party can solve the elliptic curve Diffie–Hellman problem.

The public keys are either static (and trusted, say via a certificate) or ephemeral (also known as ECDHE, where final 'E' stands for "ephemeral"). Ephemeral keys are temporary and not necessarily authenticated, so if authentication is desired, authenticity assurances must be obtained by other means. Authentication is necessary to avoid man-in-the-middle attacks. If one of either Alice's or Bob's public keys is static, then man-in-the-middle attacks are thwarted. Static public keys provide neither forward secrecy nor key-compromise impersonation resilience, among other advanced security properties. Holders of static private keys should validate the other public key, and should apply a secure key derivation function to the raw Diffie–Hellman shared secret to avoid leaking information about the static private key. For schemes with other security properties, see MQV.

If Alice maliciously chooses invalid curve points for her key and Bob does not validate that Alice's points are part of the selected group, she can collect enough residues of Bob's key to derive his private key. Several TLS libraries were found to be vulnerable to this attack.[4]

The shared secret is uniformly distributed on a subset of of size . For this reason, the secret should not be used directly as a symmetric key, but it can be used as entropy for a key derivation function.

Diffie-Hellman Key Agreement on Montgomery Curves[edit]

Let such that . The Montgomery form elliptic curve is the set of all satisfying the equation along with the point at infinity denoted as . This is called the affine form of the curve. The set of all -rational points of , denoted as is the set of all satisfying along with . Under a suitably defined addition operation, is a group with as the identity element. It is known that the order of this group is a multiple of 4. In fact, it is usually possible to obtain and such that the order of is for a prime . For more extensive discussions of Montgomery curves and their arithmetic one may follow.[5][6][7]

For computational efficiency, it is preferable to work with projective coordinates. The projective form of the Montgomery curve is . For a point on , the -coordinate map is the following:[7] if and if . Bernstein[8][9] introduced the map as follows: which is defined for all values of and in . Following Miller,[10] Montgomery[5] and Bernstein,[9] the Diffie-Hellman key agreement can be carried out on a Montgomery curve as follows. Let be a generator of a prime order subgroup of . Alice chooses a secret key and has public key ; Bob chooses a secret key and has public key . The shared secret key of Alice and Bob is . Using classical computers, the best known method of obtaining from and requires about time using the Pollards rho algorithm.[11]

The most famous example of Montgomery curve is Curve25519 which was introduced by Bernstein.[9] For Curve25519, and . The other Montgomery curve which is part of TLS 1.3 is Curve448 which was introduced by Hamburg.[12] For Curve448, and . Couple of Montgomery curves named M[4698] and M[4058] competitive to Curve25519 and Curve448 respectively have been proposed in.[13] For M[4698], and for M[4058], . At 256-bit security level, three Montgomery curves named M[996558], M[952902] and M[1504058] have been proposed in.[14] For M[996558], , for M[952902], and for M[1504058], respectively. Apart from these two, other proposals of Montgomery curves can be found at.[15]

Software[edit]

See also[edit]

References[edit]

  1. ^ NIST, Special Publication 800-56A, Recommendation for Pair-Wise Key Establishment Schemes Using Discrete Logarithm Cryptography, March, 2006.
  2. ^ Certicom Research, Standards for efficient cryptography, SEC 1: Elliptic Curve Cryptography, Version 2.0, May 21, 2009.
  3. ^ NSA Suite B Cryptography, Suite B Implementers' Guide to NIST SP 800-56A Archived 2016-03-06 at the Wayback Machine, July 28, 2009.
  4. ^ Tibor Jager; Jorg Schwenk; Juraj Somorovsky (2015-09-04). "Practical Invalid Curve Attacks on TLS-ECDH" (PDF). European Symposium on Research in Computer Security (ESORICS'15).
  5. ^ a b Montgomery, Peter L. "Speeding the Pollard and elliptic curve methods of factorization" (PDF). Mathematics of Computation, 48(177):243–264, 1987.
  6. ^ Bernstein, Daniel J.; Lange, Tanja. "Montgomery curves and the Montgomery ladder". In Joppe W. Bos and Arjen K. Lenstra, editors, Topics in Computational Number Theory inspired by Peter L. Montgomery, pages 82–115. Cambridge University Press, 2017.
  7. ^ a b Costello, Craig; Smith, Benjamin. "Montgomery curves and their arithmetic - the case of large characteristic fields". J. Cryptographic Engineering, 8(3):227–240, 2018.
  8. ^ Bernstein, Daniel J. "Can we avoid tests for zero in fast elliptic-curve arithmetic?" (PDF).
  9. ^ a b c Bernstein, Daniel J. "Curve25519: New Diffie-Hellman Speed Records". In: Yung, M., Dodis, Y., Kiayias, A., Malkin, T. (eds) Public Key Cryptography - PKC 2006. Lecture Notes in Computer Science, vol 3958. Springer, Berlin, Heidelberg.
  10. ^ Miller, Victor S. "Use of elliptic curves in cryptography". In Advances in Cryptology - CRYPTO’85, Santa Barbara, California, USA, August 18-22, 1985, Proceedings, pages 417–426. Springer Berlin Heidelberg, 1985.
  11. ^ Pollard, John M. "Monte Carlo methods for index computation mod p" (PDF). Mathematics of Computation, 32:918–924, 1978.
  12. ^ Hamburg, Mike. "Ed448-goldilocks, a new elliptic curve". ACR Cryptology ePrint Archive, 2015:625, 2015.
  13. ^ Nath, Kaushik; Sarkar, Palash. "Security and Efficiency Trade-offs for Elliptic Curve Diffie-Hellman at the 128- and 224-bit Security Levels". J Cryptogr Eng 12, 107–121 (2022)., Code available at https://github.com/kn-cs/x25519
  14. ^ Nath, Kaushik; Sarkar, Palash. "Efficient Elliptic Curve Diffie-Hellman Computation at the 256-bit Security Level". IET Information Security, 14(6):633640, 2020., Code available at https://github.com/kn-cs/mont256-dh and https://github.com/kn-cs/mont256-vec
  15. ^ Bernstein, Daniel J.; Lange, Tanja. "Safecurves: choosing safe curves for elliptic- curve cryptography". Retrieved April 15, 2024.
  16. ^ JI (13 October 2015). "New generation of safe messaging: "Letter Sealing"". LINE Engineers' Blog. LINE Corporation. Archived from the original on 1 February 2019. Retrieved 5 February 2018.