← Back to section · Foundations of Cryptography
ElGamal: Encryption Grown from the Discrete Logarithm, and Its Malleability
ElGamal turns the group operations of Diffie–Hellman into an encryption scheme: a clean construction, naturally randomized, and naturally malleable. This article walks through its construction, its kinship with DH, where its semantic security comes from and where it breaks down, and its descendants in signatures and homomorphic directions.
In 1985, Taher ElGamal published a construction that 「bent」 Diffie–Hellman key exchange into an encryption scheme. All of its parts are off-the-shelf group operations, yet together they formed the first practical randomized public-key encryption. To understand ElGamal is to understand, at once, the structure of DH, how semantic security is reduced, and the double-edged concept of 「malleability」 that runs through public-key cryptography.
The Construction: A One-Shot DH Plus a Lock in the Group
Let g be a generator of the group, the receiver’s private key x, and the public key h = g^x. To encrypt a message m, the sender picks a random ephemeral exponent r and computes the ciphertext (c1, c2) = (g^r, m · h^r). To decrypt, the receiver uses the private key to compute c1^x = g^(rx) = h^r — exactly the mask itself — and divides it out of c2 to recover m.
Disassembled, the construction is transparent: (g^r, h^r) is precisely the two halves of a DH exchange, and h^r is the shared secret the parties 「negotiate」 — except that here it is not hashed into a key but multiplied directly onto the message in the group. Every encryption draws a fresh r, so ciphertexts of the same message all differ — ElGamal satisfies public-key encryption’s randomization requirement by birth, which is exactly where it outclasses textbook RSA. The cost is written on its face: the ciphertext is twice the length of the plaintext (two group elements carry one), and the message must first be encoded as a group element.
The status of the random value r deserves a magnifying glass: it must be fresh, unpredictable, and never reused across two ciphertexts. If the same r encrypts two messages, both ciphertexts share the same mask, and dividing one c2 by the other yields the ratio of the two plaintexts — know one, and the other is immediately exposed. This 「ephemeral randomness is the lifeline」 fragility recurs throughout the DH family: it is not an implementation detail but a structural trait of such constructions. In engineering practice, r must come from a cryptographically secure random source; any corner-cutting counter, timestamp, or weak randomness takes the confidentiality of the entire scheme down with it. Writing randomness management into the threat model is lesson one for using any ephemeral-key construction.
The Security Reduction: DDH Is Its Lifeline
ElGamal’s semantic security reduces to the Decisional Diffie–Hellman assumption (DDH): given g^a and g^b, distinguishing g^(ab) from a random group element is computationally infeasible. The intuition: the mask h^r looks like a random group element, so a message multiplied by it is indistinguishable from random, and the attacker has nothing to tell apart.
The reduction simultaneously exposes the scheme’s range of validity. In groups where DDH does not hold, raw ElGamal fails outright: the canonical example is elliptic-curve groups equipped with a bilinear pairing, where the pairing efficiently decides DH triples and exposes a real mask versus a random element at a glance. Another classical subtlety is the choice of generator: working in the full multiplicative group modulo a prime rather than a prime-order subgroup lets the Legendre symbol leak one bit of the message — semantic security fails there too. Half of ElGamal’s teaching value lies here: it demonstrates that 「which assumption the reduction targets, and in which group it holds」 must be stated together with the construction; omit either and the account is incomplete.
Note also that the Computational Diffie–Hellman assumption (CDH — merely that g^(ab) cannot be computed) does not suffice for semantic security: being unable to compute the mask is not the same as the mask looking random — an attacker might be unable to recover h^r in full yet still judge whether it correlates with some candidate value, and thereby distinguish messages. It is exactly this gap that makes DDH the precisely fitting assumption for ElGamal, and it shows that 「hard」 in cryptography must be graded: hardness of solving and hardness of distinguishing are assertions of different strengths, and choosing the wrong level lets a proof quietly leak through seemingly rigorous prose.
A Family Tree: Signature Variants and a KEM Ancestor
ElGamal’s influence reaches far beyond encryption. The ElGamal signature he proposed in the same period erected the skeleton of 「random nonce + hash + group operations」 signatures, and DSA, Schnorr signatures, and ECDSA all carry this bloodline — with the confidentiality and non-reuse of the ephemeral nonce as the family’s shared lifeline, a point on which nonce-reuse accidents have leaked private keys again and again over the following decades.
On the encryption side, a slight modification of ElGamal’s structure is the direct ancestor of the modern KEM. Replace the message-as-group-element with 「a hash of the group element」, so the mask no longer multiplies the message directly but passes through a key-derivation function to become a symmetric key — this is hashed ElGamal, the core of DHIES/ECIES, whose security reduces to hash-Diffie–Hellman-type assumptions. Post-quantum schemes such as ML-KEM echo it at the interface level: encapsulation produces a shared secret, and the data is left to the symmetric layer. ElGamal, one might say, demonstrated all the basic moves of 「encrypting with a one-shot ephemeral key exchange」; later schemes mostly replaced its hardness foundation (the discrete logarithm does not survive quantum computing) rather than overturning its structure.
Malleability: One Character, Two Fates
ElGamal’s most thought-provoking property is its homomorphic malleability: given a ciphertext (c1, c2), anyone can compute (c1, c2 · t), whose decryption is exactly m · t; raising both components to a power yields an encryption of a power of m. The attacker does not know m at all, yet can manipulate it precisely. In a sealed-bid auction, this means someone can quietly double another bidder’s encrypted bid; in ballot counting, ballot weights can be scaled by known factors. Raw ElGamal therefore has only CPA security and crumbles before CCA.
Yet the same character is treasure in another setting. Re-randomization lets a third party refresh a ciphertext’s appearance without decrypting — the cornerstone of anonymous credentials, mix-nets, and verifiable e-voting tallying. Multiplicative homomorphism is the first rung on the ladder to fully homomorphic encryption. And ElGamal’s signature variants directly gave rise to the DSA and Schnorr lines. Cryptography holds few pure 「defects」: malleability, in ElGamal, reminds us that a property is neither good nor evil in itself — the security definition decides which side it stands on. When tamper resistance is required, it is a vulnerability; when computation over ciphertexts is required, it is the whole point. Which is why, when reading any new scheme, the mature question is never 「does it have malleability?」 but 「is the boundary of its malleability clearly characterized, and is it compatible with the target security definition?」
Tags: ElGamalDiscrete LogarithmMalleabilitySemantic Security