# 椭圆曲线迪菲—赫尔曼

椭圆曲线迪菲—赫尔曼（ECDH）是一种密钥协商协议，双方在不安全的信道上通过交换椭圆曲线上的点来派生共享密钥，而不传输密钥本身。它为 TLS 的 ECC 密码套件计算 TLS 预主密钥，每一个符合规范的椭圆曲线密码 SSH 实现都必须支持 ECDH 密钥交换。<sup>[1](https://datatracker.ietf.org/doc/html/rfc4492)</sup><sup> • </sup><sup>[2](https://www.ietf.org/rfc/rfc5656.txt)</sup> 椭圆曲线是迪菲—赫尔曼交换中一种特别高效的群表示，这也是该协议出现在 TLS 和 SSH 中的原因。<sup>[3](https://www.ietf.org/rfc/rfc3766.html)</sup>

| 关键事实 | 详情 |
|---|---|
| 输出 | 一个共享密钥值，随后由 HKDF<sup>[4](https://sacworkshop.org/SAC20/files/slides/SAC-Summer-Smith-ECC-2.pdf)</sup> 等密钥派生函数扩展为会话密钥 |
| 困难性假设 | 椭圆曲线离散对数问题（ECDLP）<sup>[5](https://ocw.mit.edu/courses/18-704-seminar-in-algebra-and-number-theory-rational-points-on-elliptic-curves-fall-2004/da5a73284ad175ecbe2d1780e68310c2_haraksingh.pdf)</sup> |
| 密钥大小比较 | 128 位对称安全性：283 位 ECC 密钥对比 3072 位 RSA<sup>[1](https://datatracker.ietf.org/doc/html/rfc4492)</sup> |
| 临时变体 | ECDHE 在服务器密钥泄露时提供前向保密；静态 ECDH 则不能<sup>[1](https://datatracker.ietf.org/doc/html/rfc4492)</sup> |
| 标准化曲线 | curve25519 和 curve448，分别约在 128 位和 224 位安全级别<sup>[6](https://www.rfc-editor.org/rfc/rfc7748.html)</sup> |
| 抗量子配对 | TLS 1.3 混合组 X25519MLKEM768、SecP256r1MLKEM768 和 SecP384r1MLKEM1024<sup>[7](https://www.rfc-editor.org/rfc/rfc10024.html)</sup> |

## 工作原理

经典迪菲—赫尔曼在有限域的乘法群中工作：素数 p 和生成元 g 是公开的，甲方选取随机指数 a 并发送 \( g^{a} \)，乙方选取 b 并发送 \( g^{b} \)，双方计算共享值 \( g^{a \cdot b} \)。<sup>[8](https://datatracker.ietf.org/doc/html/rfc6090)</sup><sup> • </sup><sup>[9](https://link.springer.com/content/pdf/10.1007%2F3-540-39799-X_31.pdf)</sup> 同一协议在任何循环群中都能工作，而 ECDH 只是用椭圆曲线上的点群替换了乘法群。<sup>[8](https://datatracker.ietf.org/doc/html/rfc6090)</sup>

在椭圆曲线版本中，群运算是点加法，指数运算变为标量乘法：计算 \( k \cdot P \) 意味着将点 P 与自身相加 k 次。如果爱丽丝（Alice）的秘密是 \( k_{A} \)，鲍勃（Bob）的秘密是 \( k_{B} \)，P 是公开基点，双方计算相同的共享点 \( (k_{A} \cdot k_{B}) \cdot P = k_{A} \cdot (k_{B} \cdot P) = k_{B} \cdot (k_{A} \cdot P) \)。<sup>[5](https://ocw.mit.edu/courses/18-704-seminar-in-algebra-and-number-theory-rational-points-on-elliptic-curves-fall-2004/da5a73284ad175ecbe2d1780e68310c2_haraksingh.pdf)</sup> 窃听者看到 \( k_{A} \cdot P \) 和 \( k_{B} \cdot P \) 后，需要解决椭圆曲线离散对数问题，即从 P 和 k·P 中求出 k，才能恢复秘密。<sup>[5](https://ocw.mit.edu/courses/18-704-seminar-in-algebra-and-number-theory-rational-points-on-elliptic-curves-fall-2004/da5a73284ad175ecbe2d1780e68310c2_haraksingh.pdf)</sup>

实际实现使用蒙哥马利阶梯（Montgomery ladder）形式的标量乘法，它只作用于 x 坐标：从 (a, x(P)) 计算 x([a]P)，共享密钥为 \( S = x([a][b]P) \)。这之所以可行，是因为 x 坐标对 x(P) 和 x(Q) 决定了它们和与差的 x 坐标。<sup>[4](https://sacworkshop.org/SAC20/files/slides/SAC-Summer-Smith-ECC-2.pdf)</sup> 椭圆曲线相对于有限域群的安全优势在于，椭圆曲线离散对数没有已知的亚指数时间指数演算算法，因此较小的群和密钥就足够了。<sup>[10](https://eprint.iacr.org/2008/390.pdf)</sup>

## 实现方式

RFC 7748 中的具体 X25519 交换展示了完整流程。爱丽丝生成 32 个随机字节作为秘密标量 a，并发送 \( K_{A} = X25519(a, 9) \)，其中 9 是基点的 u 坐标，编码为一个值为 9 的字节后跟 31 个零字节。鲍勃用他的标量 b 做同样的事。然后每一方将对方的公开值再次输入函数，双方获得相同的共享密钥 \( K = X25519(a, X25519(b, 9)) = X25519(b, X25519(a, 9)) \)。<sup>[6](https://www.rfc-editor.org/rfc/rfc7748.html)</sup> X25519 和 X448 函数以标量和 u 坐标为输入，输出 u 坐标，X25519 使用 32 字节字符串，X448 使用 56 字节字符串。<sup>[6](https://www.rfc-editor.org/rfc/rfc7748.html)</sup>

原始共享密钥不直接用作密钥。双方运行密钥派生函数（如 HKDF），从 S 派生共享密码密钥。<sup>[4](https://sacworkshop.org/SAC20/files/slides/SAC-Summer-Smith-ECC-2.pdf)</sup> SEC 1 等标准规定了椭圆曲线迪菲—赫尔曼原语和余因子变体，并支持 ANSI-X9.63-KDF 密钥派生函数。<sup>[11](https://secg.org/sec1-v2.pdf)</sup> [认证](https://www.edgepedia.org/zh/authentication)是一个独立步骤：仅认证共享密钥会使协议容易受到操纵公钥的攻击，因此交换的公钥本身应被直接认证。<sup>[8](https://datatracker.ietf.org/doc/html/rfc6090)</sup>

## 起源

[公钥密码学](https://www.edgepedia.org/zh/public-key-cryptography)建立在模素数整数乘法群中的离散对数问题之上。<sup>[12](https://wstein.org/edu/Fall2001/124/misc/koblitz_ecc.pdf)</sup> RFC 6090 记载，马西（Massey）于 1983 年将交换推广到任意循环群，并且迪菲—赫尔曼协议已在椭圆曲线群上进行了分析。<sup>[8](https://datatracker.ietf.org/doc/html/rfc6090)</sup> 科布利茨（Koblitz）自己的综述指出，有限域上椭圆曲线的点群被提议用于离散对数密码系统，灵感来自伦斯特拉（Lenstra）的椭圆曲线因子分解算法。<sup>[10](https://eprint.iacr.org/2008/390.pdf)</sup>

标准化在此后数十年间跟进。ANSI X9.63 规定了使用椭圆曲线密码的密钥协商和密钥传输方案、针对小子群攻击的公钥验证以及 MQV 原语。<sup>[13](https://csrc.nist.gov/CSRC/media/Events/Key-Management-Workshop-2000/documents/x963_overview.pdf)</sup> SEC 1 规定了 ECDH 和余因子 ECDH 原语。<sup>[11](https://secg.org/sec1-v2.pdf)</sup> RFC 6090 记录了基本算法，RFC 7748 规定了 curve25519 和 curve448。<sup>[8](https://datatracker.ietf.org/doc/html/rfc6090)</sup><sup> • </sup><sup>[6](https://www.rfc-editor.org/rfc/rfc7748.html)</sup>

## 变体

**静态与临时。** 在静态 ECDH 中，每一方使用长期密钥对，因此服务器私钥泄露会暴露过去的会话。临时变体 ECDHE_ECDSA 和 ECDHE_RSA 为每个会话生成新密钥，在服务器密钥泄露时提供前向保密，而 ECDH_ECDSA 和 ECDH_RSA 则不能。<sup>[1](https://datatracker.ietf.org/doc/html/rfc4492)</sup>

**命名曲线。** RFC 7748 规定了 curve25519 和 curve448，专为常数时间实现和无异常标量乘法设计，可抵抗时序和缓存侧信道攻击，分别约在 128 位和 224 位安全级别；X25519 和 X448 函数是对应的迪菲—赫尔曼函数。<sup>[6](https://www.rfc-editor.org/rfc/rfc7748.html)</sup> X25519 基于 [Curve25519](https://www.edgepedia.org/zh/curve25519) 软件，于 2016 年在 RFC 7748 中正式化，与 TLS 1.2 及更早版本中使用的 NIST 素数阶曲线上的传统 ECDH 一起被标准化用于 [TLS 1.3](https://www.edgepedia.org/zh/tls-1-3)。<sup>[4](https://sacworkshop.org/SAC20/files/slides/SAC-Summer-Smith-ECC-2.pdf)</sup>

**密钥大小。** RFC 4492 列出了可比较的强度：80 位对称安全性需要 163 位 ECC 对比 1024 位 DH/DSA/RSA，128 位需要 283 位 ECC 对比 3072 位 RSA。<sup>[1](https://datatracker.ietf.org/doc/html/rfc4492)</sup>

**速度。** 在受限硬件上，优化的 X25519 在 AVR ATmega 8 位微控制器上以 13,900,397 个周期计算 128 位安全的共享密钥，在 16 MHz 下不到一秒，ARM Cortex-M0 实现运行 3,589,850 个周期，速度是之前的 128 位安全 ECDH 软件的 3 倍。<sup>[14](https://link.springer.com/article/10.1007/s10623-015-0087-1)</sup>

## 应用

在 TLS 中，五种 ECC 密钥交换算法——ECDH_ECDSA、ECDHE_ECDSA、ECDH_RSA、ECDHE_RSA 和 ECDH_anon——都使用 ECDH 计算 TLS 预主密钥。<sup>[1](https://datatracker.ietf.org/doc/html/rfc4492)</sup> TLS 1.3 将 X25519 与 NIST 曲线一起标准化。<sup>[4](https://sacworkshop.org/SAC20/files/slides/SAC-Summer-Smith-ECC-2.pdf)</sup> 在 SSH 中，ECDH 密钥交换方法从临时本地私钥和临时远程公钥生成共享密钥，通过对交换哈希的签名提供显式服务器认证，每一个符合规范的 SSH ECC 实现都必须实现它。<sup>[2](https://www.ietf.org/rfc/rfc5656.txt)</sup>

## 局限与替代方案

**无效曲线攻击和小子群攻击。** 在无效曲线攻击中，攻击者发送不同曲线上一个小阶的点；标准的短魏尔斯特拉斯（Weierstrass）标量乘法公式不涉及曲线的常数系数 b，因此受害者在错误的曲线上计算而不自知。对策是检查收到的点是否满足正确的曲线方程。<sup>[15](https://safecurves.cr.yp.to/twist.html)</sup> 这些攻击是实用的：针对 TLS-ECDH，它们已从使用 SunEC 提供者的 JSSE 以及使用 Bouncy Castle 库的服务器中提取了服务器的长期私钥。<sup>[16](https://dl.acm.org/doi/10.1007/978-3-319-24174-6_21)</sup> 当群的余因子不为 1 时，针对 ECDH 的额外攻击成为可能。<sup>[8](https://datatracker.ietf.org/doc/html/rfc6090)</sup> X25519 解决了一个方面：该函数在对应于阶整除余因子的小阶点的输入上输出全零共享密钥，实现可以检查全零值并中止。<sup>[6](https://www.rfc-editor.org/rfc/rfc7748.html)</sup>

**侧信道。** 常数时间实现要求内存访问和跳转模式不依赖于秘密标量的比特。<sup>[6](https://www.rfc-editor.org/rfc/rfc7748.html)</sup>

**认证。** 未认证的 ECDH 容易受到中间人操纵公钥的攻击；交换的公钥必须被直接认证，无论是通过 TLS 和 SSH 中的证书和签名，还是通过 ANSI X9.63 中规定的 MQV 原语等专用认证方案。<sup>[8](https://datatracker.ietf.org/doc/html/rfc6090)</sup><sup> • </sup><sup>[13](https://csrc.nist.gov/CSRC/media/Events/Key-Management-Workshop-2000/documents/x963_overview.pdf)</sup>

**抗量子替代方案。** ECDH 对足够大的量子计算机没有提供保护，因此 TLS 1.3 现在定义了将 ML-KEM 与临时 ECDHE 结合的混合组：X25519MLKEM768、SecP256r1MLKEM768 和 SecP384r1MLKEM1024。对于 X25519MLKEM768，共享密钥是 ML-KEM 共享密钥和 X25519 共享密钥的拼接。<sup>[7](https://www.rfc-editor.org/rfc/rfc10024.html)</sup> 所有现代浏览器都支持这三种混合组。<sup>[17](https://redsift.com/blog/post-quantum-key-establishment-ten-years-later)</sup>

## References

1. [RFC 4492: Elliptic Curve Cryptography (ECC) Cipher Suites for TLS](https://datatracker.ietf.org/doc/html/rfc4492)
2. [RFC 5656: Elliptic Curve Algorithm Integration in SSH](https://www.ietf.org/rfc/rfc5656.txt)
3. [RFC 3766: Determining Strengths for Public Keys Used for Exchanging Symmetric Keys](https://www.ietf.org/rfc/rfc3766.html)
4. [Modern Elliptic Curve Cryptography (SAC 2020 summer school slides)](https://sacworkshop.org/SAC20/files/slides/SAC-Summer-Smith-ECC-2.pdf)
5. [Elliptic Curves in Public Key Cryptography: The Diffie Hellman Key Exchange Protocol and its relationship to the Elliptic Curve Discrete Logarithm Problem (MIT OCW)](https://ocw.mit.edu/courses/18-704-seminar-in-algebra-and-number-theory-rational-points-on-elliptic-curves-fall-2004/da5a73284ad175ecbe2d1780e68310c2_haraksingh.pdf)
6. [RFC 7748: Elliptic Curves for Security](https://www.rfc-editor.org/rfc/rfc7748.html)
7. [RFC 10024: Post-Quantum Traditional (PQ/T) Hybrid Key Agreement Mechanisms for TLS 1.3](https://www.rfc-editor.org/rfc/rfc10024.html)
8. [RFC 6090: Fundamental Elliptic Curve Cryptography Algorithms](https://datatracker.ietf.org/doc/html/rfc6090)
9. [Use of Elliptic Curves in Cryptography (Springer, LNCS)](https://link.springer.com/content/pdf/10.1007%2F3-540-39799-X_31.pdf)
10. [Elliptic Curve Cryptography (survey by Koblitz)](https://eprint.iacr.org/2008/390.pdf)
11. [SEC 1: Elliptic Curve Cryptography (Standards for Efficient Cryptography Group)](https://secg.org/sec1-v2.pdf)
12. [A Survey of Elliptic Curve Cryptosystems (Koblitz)](https://wstein.org/edu/Fall2001/124/misc/koblitz_ecc.pdf)
13. [ANSI X9.63 Overview](https://csrc.nist.gov/CSRC/media/Events/Key-Management-Workshop-2000/documents/x963_overview.pdf)
14. [High-speed Curve25519 on 8-bit, 16-bit, and 32-bit microcontrollers (Designs, Codes and Cryptography)](https://link.springer.com/article/10.1007/s10623-015-0087-1)
15. [SafeCurves: Twist security](https://safecurves.cr.yp.to/twist.html)
16. [Practical Invalid Curve Attacks on TLS-ECDH (ESORICS 2015)](https://dl.acm.org/doi/10.1007/978-3-319-24174-6_21)
17. [Post-quantum key establishment, ten years later | Red Sift](https://redsift.com/blog/post-quantum-key-establishment-ten-years-later)

---
*Initially written Sep 29, 2026 · Reviewed: Sep 30, 2026 · Edited: Sep 30, 2026 · Last review: Sep 30, 2026*

Topic: 技术与人造世界 › 计算技术与数字系统 › 网络与安全 › Network defense and threats › TLS and transport-layer security

Copyright 2026 Edgepedia

License: Edgepedia Community License 1.0, https://www.edgepedia.org/edgepedia/license

Source: https://www.edgepedia.org/zh/elliptic-curve-diffie-hellman

English original: https://www.edgepedia.org/elliptic-curve-diffie-hellman
