# ElGamal加密

**ElGamal加密**是一种由塔赫尔·埃尔加马尔（Taher ElGamal）于1985年发表的公钥加密方案。在该方案中，发送方以Diffie-Hellman风格的密钥协商方式，非交互地针对接收方的公钥对消息进行加密。其安全性依赖于有限域上离散对数计算的困难性，同一篇1985年的论文还引入了ElGamal签名方案。<sup>[1](https://cmapsconverted.ihmc.us/rid%3D1V1Z782SW-WFVPBK-2WN/1985Elgamal%2C%2520T-%2520A%2520public%2520key%2520cryptosystem%2520and%2520a%2520signature%2520scheme%2520based%2520on%2520discrete%2520logarithms.pdf)</sup>

| 关键事实 | 详情 |
|---|---|
| 起源 | Taher ElGamal，"A Public Key Cryptosystem and a Signature Scheme Based on Discrete Logarithms"，*IEEE Transactions on Information Theory* 31(4): 469–472，1985年7月；1984年8月在圣巴巴拉Crypto '84会议上报告<sup>[2](https://cir.nii.ac.jp/crid/1360564063944713344)</sup><sup> • </sup><sup>[1](https://cmapsconverted.ihmc.us/rid%3D1V1Z782SW-WFVPBK-2WN/1985Elgamal%2C%2520T-%2520A%2520public%2520key%2520cryptosystem%2520and%2520a%2520signature%2520scheme%2520based%2520on%2520discrete%2520logarithms.pdf)</sup> |
| 基础 | Diffie-Hellman密钥分发方案的一种实现，实现了公钥密码体制；安全性依赖于有限域上离散对数计算的困难性<sup>[1](https://cmapsconverted.ihmc.us/rid%3D1V1Z782SW-WFVPBK-2WN/1985Elgamal%2C%2520T-%2520A%2520public%2520key%2520cryptosystem%2520and%2520a%2520signature%2520scheme%2520based%2520on%2520discrete%2520logarithms.pdf)</sup> |
| 密文 | 两个群元素 \( (c_1, c_2) = (g^y,\ h^y \cdot m) \)；解密计算 \( \hat{m} = c_2 \cdot c_1^{-x} \)<sup>[3](https://www.ee.iitb.ac.in/~sarva/courses/EE720/2024/slides/public-key-encryption.html)</sup> |
| 安全性保证 | 若判定性Diffie-Hellman（DDH）问题在所选的群中是困难的，则满足IND-CPA（语义）安全性<sup>[3](https://www.ee.iitb.ac.in/~sarva/courses/EE720/2024/slides/public-key-encryption.html)</sup> |
| 密文膨胀 | 在模运算设定下，密文长度为模数长度的两倍；在椭圆曲线上膨胀因子约为四，因为每个密文由四个元素组成<sup>[4](https://users.informatik.uni-halle.de/~ahyjb/krypto/English/4.3.1.en.html)</sup><sup> • </sup><sup>[5](https://mojoauth.com/security-guides/elgamal-variable-key-size-vs-ecc-256)</sup> |
| 标准化 | RFC 4880（2007年）要求OpenPGP中的加密必须实现该算法；RFC 9580（2024年7月）禁止生成Elgamal密钥并使用其加密<sup>[6](https://www.rfc-editor.org/info/rfc4880/)</sup><sup> • </sup><sup>[7](https://www.rfc-editor.org/info/rfc9580/)</sup> |
| 显著用途 | 乘法同态；门限ElGamal是混网和同态计票电子投票设计的基础<sup>[8](https://link.springer.com/chapter/10.1007/978-3-031-43756-4_2)</sup> |

## 方案的工作原理

该方案将Diffie-Hellman密钥交换转化为加密：发送方为每条消息创建一个一次性密钥对。密钥生成运行群生成器 \( \mathcal{G} \) 以获得一个阶为 \( q \)、生成元为 \( g \) 的循环群 \( G \)；接收方选取均匀随机的秘密 \( x \in \mathbb{Z}_q \) 并公开 \( h = g^x \)。密钥对由公开部分 \( \langle G, q, g, h \rangle \) 和私有部分 \( \langle G, q, g, x \rangle \) 组成，其中 \( G \) 是消息的取值集合。<sup>[3](https://www.ee.iitb.ac.in/~sarva/courses/EE720/2024/slides/public-key-encryption.html)</sup>

要加密消息 \( m \in G \)，发送方选取均匀随机的 \( y \in \mathbb{Z}_q \) 并输出二元组 \( \langle g^y,\ h^y \cdot m \rangle \)。元素 \( g^y \) 是发送方的一次性公钥，而 \( h^y = g^{xy} \) 是共享的Diffie-Hellman秘密，通过群乘法用作一次性密码本。接收方知道 \( x \)，计算 \( \hat{m} = c_2 \cdot c_1^{-x} \)，因为 \( c_1^{-x} = g^{-xy} \) 抵消了掩码。<sup>[3](https://www.ee.iitb.ac.in/~sarva/courses/EE720/2024/slides/public-key-encryption.html)</sup> 一份课程总结用一句话概括了这一设计：ElGamal就是以非交互方式运行的Diffie-Hellman加密。<sup>[9](https://staff.ie.cuhk.edu.hk/~smchow/4150/)</sup>

该方案并非最早的公钥加密方案；RSA出现更早，用伯克利一本密码学教材的话说，尽管Diffie-Hellman已经发表，RSA要复杂得多。<sup>[10](https://securitybook.eecs.berkeley.edu/chapters/lec10.html)</sup>

## 安全性

**DDH下的CPA安全性。** 核心定理指出，若判定性Diffie-Hellman问题相对于群生成器是困难的，则ElGamal加密是CPA安全的，即敌手即使拥有加密预言机的访问权限，也无法区分两个选定消息的加密结果。<sup>[3](https://www.ee.iitb.ac.in/~sarva/courses/EE720/2024/slides/public-key-encryption.html)</sup> 证明将真实加密 \( (g^y, g^{xy} \cdot m) \) 与一个掩码 \( g^z \) 独立于接收方密钥的修改方案进行比较；任何能区分两者的区分器都将解决DDH。<sup>[3](https://www.ee.iitb.ac.in/~sarva/courses/EE720/2024/slides/public-key-encryption.html)</sup> 显式需要DDH假设，因为在一般群中DDH强于离散对数假设，且存在DDH不成立而DL和CDH被认为成立的群。<sup>[11](https://kodu.ut.ee/~lipmaa/teaching/ucl/compga04/crypto2.pdf)</sup> 对于消息空间限制在 \( g \) 生成的子群中的教科书式ElGamal，IND-CPA安全性成立当且仅当DDH是困难的。<sup>[12](https://www.math.auckland.ac.nz/~sgal018/crypto-book/ch20.pdf)</sup>

**可延展性。** 教科书式ElGamal在选择密文攻击下是可延展的：攻击者可以将一个密文变换为相关消息的有效加密，例如 \( m' = m/t \) 的随机化加密。<sup>[13](https://citeseerx.ist.psu.edu/document?doi=396e13f043927ce7a850a3735c58bc088407440d&repid=rep1&type=pdf)</sup> 这一性质对一般加密而言是弱点，但恰恰是使该方案适用于投票的原因——在投票中密文必须在不解密的情况下进行组合。CCA安全的ElGamal型变体已被开发出来，包括哈希ElGamal，它用随机预言机哈希对共享秘密 \( g^{xy} \) 进行哈希，以导出用于认证加密方案的对称密钥。<sup>[10](https://securitybook.eecs.berkeley.edu/chapters/lec10.html)</sup><sup> • </sup><sup>[14](https://www.iacr.org/archive/pkc2009/54430381/54430381.pdf)</sup>

## 实例化与性能

原始方案位于乘法群 \( \mathbb{Z}^*_p \) 中；哈希ElGamal的定义使用 \( p \approx q \approx 2^{2048} \) 的Diffie-Hellman参数。<sup>[10](https://securitybook.eecs.berkeley.edu/chapters/lec10.html)</sup> 在实践中，ElGamal加密通常用椭圆曲线群而非 \( \mathbb{Z}^*_p \) 来实例化，一般原理不变。<sup>[10](https://securitybook.eecs.berkeley.edu/chapters/lec10.html)</sup> 建立椭圆曲线ElGamal系统需要计算曲线上的点数，这很困难，但得益于Schoof算法已有高效算法，然后需要找到一个离散对数问题在计算上难以求解的循环子群。<sup>[4](https://users.informatik.uni-halle.de/~ahyjb/krypto/English/4.3.1.en.html)</sup>

密文大小是一项实际成本。在模运算设定下，ElGamal密文长度是模数长度的两倍，而ECIES增加的开销不到100字节。<sup>[5](https://mojoauth.com/security-guides/elgamal-variable-key-size-vs-ecc-256)</sup> 在椭圆曲线上消息膨胀因子约为四，因为每个密文由四个元素组成，且明文空间由曲线点构成，当时尚无已知的便捷确定性方法来生成这些点。<sup>[4](https://users.informatik.uni-halle.de/~ahyjb/krypto/English/4.3.1.en.html)</sup> 一项2022年的实验比较测得1024位ElGamal的密钥生成耗时为0.258秒，加密为0.0093秒，解密为0.0049秒，产生的密文约为256字节；256位ECC与AES的混合方案在所有测试指标上均优于ElGamal，作者因此倾向于在安全消息传递、物联网网络和低功耗设备等快速处理场景中使用混合方案。<sup>[15](https://www.ijsat.org/research-paper.php?id=6334)</sup> 一项2017年的基准测试同样比较了RSA、ElGamal和ECIES在数据库加密中作为密钥大小函数的执行时间，发现算法复杂度增长会提高执行时间并降低应用性能。<sup>[16](https://ieeexplore.ieee.org/document/7968578/)</sup>

## 同态性与投票

ElGamal加密是乘法同态的：将两个密文逐分量相乘得到明文乘积的加密，配合指数编码可支持加密计票。<sup>[9](https://staff.ie.cuhk.edu.hk/~smchow/4150/)</sup> 结合重加密混网，这一性质被广泛用于电子投票。在门限ElGamal中，多个互不信任的参与方联合生成秘密密钥和公钥对，使得任何一方都不知道完整的秘密密钥，公钥则被公开；随后选票由混网服务器打乱并重加密，或进行同态计票，仅对最终结果解密。<sup>[8](https://link.springer.com/chapter/10.1007/978-3-031-43756-4_2)</sup> 关于密码学投票的综述文献将门限ElGamal和椭圆曲线ElGamal配合混网与同态计票列为反复出现的构建模块。<sup>[17](https://www.mdpi.com/2073-8994/14/5/858)</sup>

## OpenPGP中的标准化与弃用

ElGamal加密通过OpenPGP进入广泛部署。RFC 4880——2007年11月的OpenPGP消息格式标准——要求实现必须支持DSA用于签名和Elgamal用于加密，并为Elgamal加密或签名组合用途保留了算法ID 20。<sup>[6](https://www.rfc-editor.org/info/rfc4880/)</sup> GnuPG历史上在DSA主签名密钥之外创建一个ElGamal从属密钥对用于加密，ElGamal密钥允许任意大小，但不得低于768位。<sup>[18](https://gnupg.org/gph/en/manual.html)</sup>

现行标准已逆转了这一局面。2024年7月发布的RFC 9580指出，该文档中定义的Elgamal算法所使用的PKCS1-v1_5填充方案已不再推荐，并被NIST SP 800-131A弃用；实现不得生成Elgamal密钥，也不得使用Elgamal密钥加密，使用Elgamal秘密密钥解密的实现应警告该密钥对于现代使用而言过于脆弱。<sup>[7](https://www.rfc-editor.org/info/rfc9580/)</sup> 在早期OpenPGP版本中允许的算法ID 20的Elgamal签名也不再被允许。<sup>[7](https://www.rfc-editor.org/info/rfc9580/)</sup> 现代混合方案如HPKE（RFC 9180）则改用Diffie-Hellman KEM封装对称密钥，并用AEAD密码加密载荷，RFC将这种方法与传统的“用公钥加密对称密钥”组合方式进行了对比。<sup>[19](https://www.rfc-editor.org/info/rfc9180)</sup>

## 变体

基本方案衍生出了一个方案家族。哈希ElGamal对共享秘密应用随机预言机哈希，并用对称认证加密方案加密，允许任意大小的明文。<sup>[10](https://securitybook.eecs.berkeley.edu/chapters/lec10.html)</sup> Cramer-Shoup及其他IND-CCA安全的ElGamal型构造通过添加证明和校验和来弥补可延展性缺陷；一份PKC 2009的提案自称是ElGamal加密的插件式替代方案，能提供更高水平的抗选择密文攻击安全性。<sup>[14](https://www.iacr.org/archive/pkc2009/54430381/54430381.pdf)</sup> 一种带有明文感知修改的Schnorr签名ElGamal变体被提出以抵抗选择密文攻击。<sup>[20](https://eprint.iacr.org/2012/649.pdf)</sup> 在椭圆曲线上，EC-ElGamal已被用于无线传感器网络数据聚合中的加法同态加密。<sup>[21](https://arxiv.org/abs/0903.3900)</sup> 该方案还出现在同态加密库的比较中，与Paillier、RSA和全同态方案并列。<sup>[22](https://arxiv.org/abs/1812.02428)</sup>

## References

1. [Taher ElGamal (1985). A Public Key Cryptosystem and a Signature Scheme Based on Discrete Logarithms. IEEE Transactions on Information Theory 31(4): 469–472.](https://cmapsconverted.ihmc.us/rid%3D1V1Z782SW-WFVPBK-2WN/1985Elgamal%2C%2520T-%2520A%2520public%2520key%2520cryptosystem%2520and%2520a%2520signature%2520scheme%2520based%2520on%2520discrete%2520logarithms.pdf)
2. [CiNii Research record: A public key cryptosystem and a signature scheme based on discrete logarithms](https://cir.nii.ac.jp/crid/1360564063944713344)
3. [Public-Key Encryption lecture slides, EE720, IIT Bombay](https://www.ee.iitb.ac.in/~sarva/courses/EE720/2024/slides/public-key-encryption.html)
4. [ElGamal Cryptosystem on Elliptic Curves, Martin-Luther-Universität Halle-Wittenberg](https://users.informatik.uni-halle.de/~ahyjb/krypto/English/4.3.1.en.html)
5. [ElGamal vs ECC-256: Key Differences, MojoAuth Security Guides](https://mojoauth.com/security-guides/elgamal-variable-key-size-vs-ecc-256)
6. [RFC 4880: OpenPGP Message Format, RFC Editor](https://www.rfc-editor.org/info/rfc4880/)
7. [RFC 9580: OpenPGP, RFC Editor](https://www.rfc-editor.org/info/rfc9580/)
8. [openvoting:recoverability from failures in dual voting | springer nature link](https://link.springer.com/chapter/10.1007/978-3-031-43756-4_2)
9. [IERG4150 Introduction to Cryptography, CUHK](https://staff.ie.cuhk.edu.hk/~smchow/4150/)
10. [Key Exchange and Public-key Encryption, securitybook.eecs.berkeley.edu](https://securitybook.eecs.berkeley.edu/chapters/lec10.html)
11. [Helger Lipmaa, COMPGA4 Crypto II lecture notes, University of Tartu](https://kodu.ut.ee/~lipmaa/teaching/ucl/compga04/crypto2.pdf)
12. [The Diffie-Hellman Problem (crypto book chapter), University of Auckland](https://www.math.auckland.ac.nz/~sgal018/crypto-book/ch20.pdf)
13. [On the Security of ElGamal Based Encryption, CiteSeerX](https://citeseerx.ist.psu.edu/document?doi=396e13f043927ce7a850a3735c58bc088407440d&repid=rep1&type=pdf)
14. [Compact CCA-Secure Encryption, IACR PKC 2009](https://www.iacr.org/archive/pkc2009/54430381/54430381.pdf)
15. [A Comparative Performance Analysis of ElGamal and ECC-AES Hybrid Cryptosystems for Secure Communication, IJSAT](https://www.ijsat.org/research-paper.php?id=6334)
16. [Database Encryption Using Asymmetric Keys: A Case Study, IEEE CSCS 2017](https://ieeexplore.ieee.org/document/7968578/)
17. [A Review of Cryptographic Electronic Voting, MDPI Symmetry 14(5):858](https://www.mdpi.com/2073-8994/14/5/858)
18. [The GNU Privacy Handbook, GnuPG](https://gnupg.org/gph/en/manual.html)
19. [RFC 9180: Hybrid Public Key Encryption, RFC Editor](https://www.rfc-editor.org/info/rfc9180)
20. [A Robust and Plaintext-Aware Variant of Schnorr-Signed ElGamal Encryption, IACR ePrint 2012/649](https://eprint.iacr.org/2012/649.pdf)
21. [Optimized Implementation of Elliptic Curve Based Additive Homomorphic Encryption for Wireless Sensor Networks, arXiv:0903.3900](https://arxiv.org/abs/0903.3900)
22. [A Review of Homomorphic Encryption Libraries for Secure Computation, arXiv:1812.02428](https://arxiv.org/abs/1812.02428)

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

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

Copyright 2026 Edgepedia

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

Source: https://www.edgepedia.org/zh/elgamal-encryption

English original: https://www.edgepedia.org/elgamal-encryption
