# Diffie–Hellman密钥交换

**Diffie–Hellman密钥交换**是一种密码学协议，两个此前从未通信过的参与方可以通过公开信道建立一个共享密钥，而无需传输密钥本身。该协议由[Whitfield Diffie](https://www.edgepedia.org/zh/whitfield-diffie)和Martin E. Hellman在论文《密码学的新方向》中发表，刊于《IEEE信息论汇刊》第IT-22卷第6期，1976年11月，第644–654页<sup>[1](https://janmr.com/refs/diffie-hellman76/)</sup>。这一交换是公钥密码学的奠基性范例，至今仍是TLS、SSH及其他安全协议的标准组成部分<sup>[1](https://janmr.com/refs/diffie-hellman76/)</sup><sup> • </sup><sup>[2](https://www.rfc-editor.org/info/rfc8446/)</sup>。

| 关键事实 | 详情 |
|---|---|
| 原始发表 | Diffie与Hellman，《密码学的新方向》，《IEEE信息论汇刊》IT-22(6)，1976年11月，第644–654页<sup>[1](https://janmr.com/refs/diffie-hellman76/)</sup> |
| 安全基础 | 有限域或椭圆曲线上的离散对数问题<sup>[3](https://tsapps.nist.gov/publication/get_pdf.cfm?pub_id=934896)</sup> |
| 主要变体 | 有限域DH、椭圆曲线Diffie-Hellman（ECDH），以及MQV系列相关方案<sup>[4](https://tsapps.nist.gov/publication/get_pdf.cfm?pub_id=934860)</sup><sup> • </sup><sup>[5](https://csrc.nist.rip/publications/detail/sp/800-56a/rev-2/final)</sup> |
| 协议部署 | TLS 1.3的密钥交换以群上的Diffie-Hellman形式表述；SSH最初要求的必需方法为diffie-hellman-group1-sha1和diffie-hellman-group14-sha1<sup>[6](https://www.rfc-editor.org/rfc/rfc9954.html)</sup><sup> • </sup><sup>[7](https://www.rfc-editor.org/info/rfc4253/)</sup> |
| 前向保密 | 临时DH每次会话使用新的公钥，意味着服务器长期签名密钥的泄露不会暴露过去的会话<sup>[8](https://wiki.openssl.org/index.php/Diffie_Hellman)</sup> |
| 主要弱点 | 未经认证的DH容易受到中间人攻击；需要通过签名或证书进行认证<sup>[9](https://pmc.ncbi.nlm.nih.gov/articles/PMC5551094/)</sup> |
| 量子威胁 | Shor算法可在大型量子计算机上高效求解其底层问题；NIST于2024年8月将基于格的ML-KEM标准化为替代方案<sup>[3](https://tsapps.nist.gov/publication/get_pdf.cfm?pub_id=934896)</sup><sup> • </sup><sup>[10](https://csrc.nist.gov/pubs/fips/203/final)</sup> |

## 交换的工作原理

该协议在一个群中运行，其中指数运算容易，但其逆运算——离散对数——在计算上是困难的。在SSH所使用的有限域形式中，各方首先就公开参数达成一致：一个大素数p和一个生成元g。一方生成随机秘密x并发送e = g^x mod p；另一方生成秘密y并发送f = g^y mod p。随后各自计算出相同的共享密钥，第一方计算K = f^x mod p，第二方计算K = e^y mod p，因为两者都等于g^(xy) mod p<sup>[7](https://www.rfc-editor.org/info/rfc4253/)</sup>。窃听者若看到e、f、p和g，必须计算离散对数才能恢复x或y，这正是安全性所依赖的问题<sup>[3](https://tsapps.nist.gov/publication/get_pdf.cfm?pub_id=934896)</sup>。

RFC 9954以现代术语描述了同样的结构：密钥生成对应于选择指数x作为私钥并计算公钥g^x，封装对应于选择y并计算g^y及共享密钥g^(xy)，解封装则对应于从接收到的公开值计算出该共享密钥<sup>[6](https://www.rfc-editor.org/rfc/rfc9954.html)</sup>。

参数与算法同等重要。参数生成代价高昂，因此p和g的一组值通常只生成一次，然后在多次交换中重复使用<sup>[8](https://wiki.openssl.org/index.php/Diffie_Hellman)</sup>。SSH最初要求的两种方法分别使用1024位MODP群（Oakley第2组，尽管名称为“group1”）和2048位MODP群（Oakley第14组），两者均以SHA-1作为哈希函数<sup>[7](https://www.rfc-editor.org/info/rfc4253/)</sup>。在TLS中，关于服务器应提供哪些有限域群、客户端应接受哪些群的模糊性导致了安全和互操作性问题，RFC 7919于2016年8月通过在TLS支持群注册表中分配命名的、定义明确的有限域DH群解决了这一问题<sup>[11](https://www.rfc-editor.org/info/rfc7919/)</sup>。

## 认证与中间人问题

裸交换不认证任何东西。一个主动攻击者拦截每一方的公开值并替换为自己的值，就可以与每个参与者分别建立共享密钥，然后读取、甚至可能修改他们之间的所有流量，而每一方都以为自己在与对方通信<sup>[12](https://www.cs.utexas.edu/~byoung/cs361c/slides3-cryptography.pdf)</sup>。这一漏洞的存在是因为Diffie-Hellman不认证参与者<sup>[12](https://www.cs.utexas.edu/~byoung/cs361c/slides3-cryptography.pdf)</sup>。

标准的补救方法是将交换绑定到可信身份上。由证书颁发机构和公钥基础设施支持的对交换值的数字签名可以防止替换；在SSH中，服务器对交换哈希H进行签名，H由两个标识字符串、主机密钥和交换值计算得出，客户端验证该签名<sup>[9](https://pmc.ncbi.nlm.nih.gov/articles/PMC5551094/)</sup><sup> • </sup><sup>[7](https://www.rfc-editor.org/info/rfc4253/)</sup>。[TLS 1.3](https://www.edgepedia.org/zh/tls-1-3)被规定为一种认证密钥交换协议，其中握手在建立密钥材料的同时认证服务器，并可选地认证客户端<sup>[2](https://www.rfc-editor.org/info/rfc8446/)</sup>。

## 前向保密与部署

**临时密钥。** 当协议的每次运行都使用新生成的公钥时，该交换提供完美前向保密：由于公钥是临时的，服务器长期签名密钥的泄露不会危及过去会话的隐私。每个临时密钥的真实性通过检查其上的签名来验证<sup>[8](https://wiki.openssl.org/index.php/Diffie_Hellman)</sup>。TLS 1.3支持三种基本密钥交换模式：有限域或椭圆曲线上的(EC)DHE、仅PSK，以及PSK结合(EC)DHE，规范并不要求临时公钥仅用于单次会话，不过重用会限制前向保密性<sup>[2](https://www.rfc-editor.org/info/rfc8446/)</sup><sup> • </sup><sup>[6](https://www.rfc-editor.org/rfc/rfc9954.html)</sup>。

**椭圆曲线变体。** 用椭圆曲线乘法替代模乘法便得到ECDH，据信它在密钥尺寸小得多的情况下即可抵御经典攻击，这是一个重要的性能优势<sup>[4](https://tsapps.nist.gov/publication/get_pdf.cfm?pub_id=934860)</sup>。对轻量级密钥交换算法的基准测试发现，标准NIST P-256曲线比Curve25519慢数倍，而FourQ比[Curve25519](https://www.edgepedia.org/zh/curve25519)快近2倍<sup>[9](https://pmc.ncbi.nlm.nih.gov/articles/PMC5551094/)</sup>。NIST SP 800-56A Rev. 2于2013年5月发布，阐述了基于有限域和椭圆曲线上离散对数问题的密钥建立方案，涵盖多种Diffie-Hellman变体以及Menezes-Qu-Vanstone（MQV）方案<sup>[5](https://csrc.nist.rip/publications/detail/sp/800-56a/rev-2/final)</sup>。

**实践中的弱参数。** 2015年的Logjam研究表明短参数的代价。两个广泛分布的512位素数——一个从2.1.5版到2.4.7版硬编码在Apache httpd中，被排名前100万的网站中7%的站点用于DHE_EXPORT[密码套件](https://www.edgepedia.org/zh/cipher-suite)；另一个自1995年SSLeay 0.5.1a起捆绑在OpenSSL中——在使用CADO-NFS数域筛法进行两周预计算后被破解；在付出这一一次性代价之后，任何使用这些素数的密钥交换都可以在几分钟内被破解，作为演示，一段记录到的与tips.fbi.gov的连接被解密<sup>[13](https://weakdh.org/logjam.html)</sup>。RFC 7919的指导正是源于这类结果：实现应使用常数时间模幂运算，修订版应弃用那些估计工作量因子不再提供所需安全裕度的群<sup>[11](https://www.rfc-editor.org/info/rfc7919/)</sup>。

## 历史

1976年的论文考察了密码学中的几种新可能性：无需事先建立密钥信道的系统、不可伪造的数字签名，以及利用复杂性理论研究安全性<sup>[14](https://www-ee.stanford.edu/~hellman/publications/32.pdf)</sup>。同样两位作者较早的论文《多用户密码技术》于1976年6月7日至10日在纽约全国计算机会议上发表，描述了在不通过外部信道发送密钥的情况下实现网络用户之间安全首次接触的两种方法<sup>[14](https://www-ee.stanford.edu/~hellman/publications/32.pdf)</sup>。

独立发现先于公开发表，但处于保密状态。James Ellis是一位出生于澳大利亚的数学家和计算机科学家，1952年加入GCHQ，在阅读了二战时期贝尔实验室一篇关于语音通信保护的论文后，想到了“非秘密加密”——即现在所称的公钥密码学——的可能性；英国国家网络安全中心将这一构想的提出时间定在1970年<sup>[15](https://www.gchq.gov.uk/person/james-ellis)</sup><sup> • </sup><sup>[16](https://www.ncsc.gov.uk/information/our-history)</sup>。Ellis与GCHQ同事Clifford Cocks合作，开发了后来被称为RSA算法的方案，GCHQ数学家Malcolm Williamson则开创了一种密钥交换过程。1973年的发现长期处于机密状态，最初仅用于官方政府通信<sup>[15](https://www.gchq.gov.uk/person/james-ellis)</sup>。[Ralph Merkle](https://www.edgepedia.org/zh/ralph-merkle)也独立于Diffie和Hellman提出了公钥分发的概念，发表于1978年《ACM通讯》上关于不安全信道上安全通信的论文<sup>[14](https://www-ee.stanford.edu/~hellman/publications/32.pdf)</sup>。

## 后量子过渡

Diffie-Hellman的安全性依赖于离散对数问题的困难性，而有了足够大的量子计算机，Shor算法将高效求解该问题，使依赖它的密码学安全陷入危机<sup>[3](https://tsapps.nist.gov/publication/get_pdf.cfm?pub_id=934896)</sup>。威胁在此类计算机存在之前就已存在：今天记录加密流量的对手可以等到足够大的量子计算机可用时再解密，因此那些需要一直保密到此类计算机出现之后的数据已经处于风险之中<sup>[3](https://tsapps.nist.gov/publication/get_pdf.cfm?pub_id=934896)</sup>。

替代路径通过密钥封装实现。2024年8月13日，NIST最终确定了[FIPS 203](https://www.edgepedia.org/zh/fips-203)，规定了ML-KEM——一种基于格的密钥封装机制，其安全性关联于模误差学习问题，据信即使面对拥有量子计算机的对手也是安全的，参数集为ML-KEM-512、ML-KEM-768和ML-KEM-1024<sup>[10](https://csrc.nist.gov/pubs/fips/203/final)</sup>。2024年11月的NIST IR 8547草案指出，ML-KEM目前是唯一获批的基于公钥密码学的后量子密钥建立方案<sup>[17](https://nvlpubs.nist.gov/nistpubs/ir/2024/NIST.IR.8547.ipd.pdf)</sup>。在传输方面，RFC 9954为TLS 1.3规定了混合密钥交换，将经典Diffie-Hellman与后量子KEM配对；该文件指出，尽管Diffie-Hellman在被视为KEM时未能正式满足IND-CCA2安全性，但它在TLS 1.3的临时密钥交换中仍然是安全的<sup>[6](https://www.rfc-editor.org/rfc/rfc9954.html)</sup>。

## References

1. [Diffie Hellman (1976), "New directions in cryptography," journal reference, janmr.com](https://janmr.com/refs/diffie-hellman76/)
2. [RFC 8446: The Transport Layer Security (TLS) Protocol Version 1.3, RFC Editor](https://www.rfc-editor.org/info/rfc8446/)
3. [Cryptographic Standards in a Post-Quantum Era, NIST](https://tsapps.nist.gov/publication/get_pdf.cfm?pub_id=934896)
4. [Network Security: Private Communication in a Public World, 3rd Edition, NIST](https://tsapps.nist.gov/publication/get_pdf.cfm?pub_id=934860)
5. [SP 800-56A Rev. 2, Pair-Wise Key-Establishment Schemes Using Discrete Log Cryptography, NIST CSRC](https://csrc.nist.rip/publications/detail/sp/800-56a/rev-2/final)
6. [RFC 9954: Hybrid Key Exchange in TLS 1.3, RFC Editor](https://www.rfc-editor.org/rfc/rfc9954.html)
7. [RFC 4253: The Secure Shell (SSH) Transport Layer Protocol, RFC Editor](https://www.rfc-editor.org/info/rfc4253/)
8. [Diffie Hellman, OpenSSL Wiki](https://wiki.openssl.org/index.php/Diffie_Hellman)
9. [Algorithms for Lightweight Key Exchange, PMC](https://pmc.ncbi.nlm.nih.gov/articles/PMC5551094/)
10. [FIPS 203, Module-Lattice-Based Key-Encapsulation Mechanism Standard, NIST CSRC](https://csrc.nist.gov/pubs/fips/203/final)
11. [RFC 7919: Negotiated Finite Field Diffie-Hellman Ephemeral Parameters for TLS, RFC Editor](https://www.rfc-editor.org/info/rfc7919/)
12. [CS361C Information Assurance and Security: Cryptography slides, University of Texas at Austin](https://www.cs.utexas.edu/~byoung/cs361c/slides3-cryptography.pdf)
13. [Logjam TLS Attack, weakdh.org](https://weakdh.org/logjam.html)
14. [Diffie and Hellman, "An Introduction to Cryptography" (annotated bibliography), Stanford](https://www-ee.stanford.edu/~hellman/publications/32.pdf)
15. [James Ellis, GCHQ](https://www.gchq.gov.uk/person/james-ellis)
16. [Our history, National Cyber Security Centre](https://www.ncsc.gov.uk/information/our-history)
17. [NIST IR 8547 initial public draft, Transition to Post-Quantum Cryptography Standards, NIST](https://nvlpubs.nist.gov/nistpubs/ir/2024/NIST.IR.8547.ipd.pdf)

---
*Initially written Sep 17, 2026 · Reviewed: Sep 19, 2026; Sep 30, 2026; Oct 15, 2026 · Edited: Sep 19, 2026; Sep 30, 2026; Oct 15, 2026 · Last review: Oct 15, 2026*

Topic: 技术与人造世界 › 计算技术与数字系统 › 网络与安全 › Security governance and internet policy › Cryptographic protocols › Key management

Copyright 2026 Edgepedia

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

Source: https://www.edgepedia.org/zh/diffie-hellman-key-exchange

English original: https://www.edgepedia.org/diffie-hellman-key-exchange
