ElGamal encryption

(Redirected from ElGamal)

In cryptography, the ElGamal encryption system is an asymmetric key encryption algorithm for public-key cryptography which is based on the Diffie–Hellman key exchange. It was described by Taher Elgamal in 1985.[1] ElGamal encryption is used in the free GNU Privacy Guard software, recent versions of PGP, and other cryptosystems. The Digital Signature Algorithm (DSA) is a variant of the ElGamal signature scheme, which should not be confused with ElGamal encryption.

ElGamal encryption can be defined over any cyclic group ${\displaystyle G}$, like multiplicative group of integers modulo n. Its security depends upon the difficulty of a certain problem in ${\displaystyle G}$ related to computing discrete logarithms.

The algorithm

ElGamal encryption consists of three components: the key generator, the encryption algorithm, and the decryption algorithm.

Key generation

The first party, Alice, generates a key pair as follows:

• Generate an efficient description of a cyclic group ${\displaystyle G\,}$ of order ${\displaystyle q\,}$ with generator ${\displaystyle g}$. Let ${\displaystyle e}$ represent the unit element of ${\displaystyle G}$.
• Choose an integer ${\displaystyle x}$ randomly from ${\displaystyle \{1,\ldots ,q-1\}}$.
• Compute ${\displaystyle h:=g^{x}}$.
• The public key consists of the values ${\displaystyle (G,q,g,h)}$. Alice publishes this public key and retains ${\displaystyle x}$ as her private key, which must be kept secret.

Encryption

A second party, Bob, encrypts a message ${\displaystyle M}$ to Alice under her public key ${\displaystyle (G,q,g,h)}$ as follows:

• Map the message ${\displaystyle M}$ to an element ${\displaystyle m}$ of ${\displaystyle G}$ using a reversible mapping function.
• Choose an integer ${\displaystyle y}$ randomly from ${\displaystyle \{1,\ldots ,q-1\}}$.
• Compute ${\displaystyle s:=h^{y}}$. This is called the shared secret.
• Compute ${\displaystyle c_{1}:=g^{y}}$.
• Compute ${\displaystyle c_{2}:=m\cdot s}$.
• Bob sends the ciphertext ${\displaystyle (c_{1},c_{2})}$ to Alice.

Note that if one knows both the ciphertext ${\displaystyle (c_{1},c_{2})}$ and the plaintext ${\displaystyle m}$ one can easily find the shared secret ${\displaystyle s}$, since ${\displaystyle c_{2}\cdot m^{-1}=s}$. Therefore, a new ${\displaystyle y}$ and hence a new ${\displaystyle s}$ is generated for every message to improve security. For this reason, ${\displaystyle y}$ is also called an ephemeral key.

Decryption

Alice decrypts a ciphertext ${\displaystyle (c_{1},c_{2})}$ with her private key ${\displaystyle x}$ as follows:

• Compute ${\displaystyle s:=c_{1}^{x}}$. Since ${\displaystyle c_{1}=g^{y}}$, ${\displaystyle c_{1}^{x}=g^{xy}=h^{y}}$ and thus it is the same shared secret that was used by Bob in encryption.
• Compute ${\displaystyle s^{-1}}$, the inverse of ${\displaystyle s}$ in the group ${\displaystyle G}$. This can be computed in one of several ways. If ${\displaystyle G}$ is a subgroup of a multiplicative group of integers modulo n, the modular multiplicative inverse can be computed using the Extended Euclidean Algorithm. An alternative is to compute ${\displaystyle s^{-1}}$ as ${\displaystyle c_{1}^{q-x}}$. This is the inverse of ${\displaystyle s}$ because of Lagrange's theorem, since ${\displaystyle s\cdot c_{1}^{q-x}=g^{xy}\cdot g^{(q-x)y}=(g^{q})^{y}=e^{y}=e}$.
• Compute ${\displaystyle m:=c_{2}\cdot s^{-1}}$. This calculation produces the original message ${\displaystyle m}$, because ${\displaystyle c_{2}=m\cdot s}$; hence ${\displaystyle c_{2}\cdot s^{-1}=(m\cdot s)\cdot s^{-1}=m\cdot e=m}$.
• Map ${\displaystyle m}$ back to the plaintext message ${\displaystyle M}$.

Practical use

Like most public key systems, the ElGamal cryptosystem is usually used as part of a hybrid cryptosystem where the message itself is encrypted using a symmetric cryptosystem and ElGamal is then used to encrypt only the symmetric key. This is because asymmetric cryptosystems like ElGamal are usually slower than symmetric ones for the same level of security, so it is faster to encrypt the message, which can be arbitrarily large, with a symmetric cipher, and then use ElGamal only to encrypt the symmetric key, which usually is quite small compared to the size of the message.

Security

The security of the ElGamal scheme depends on the properties of the underlying group ${\displaystyle G}$ as well as any padding scheme used on the messages.

If the computational Diffie–Hellman assumption (CDH) holds in the underlying cyclic group ${\displaystyle G}$, then the encryption function is one-way.[2]

If the decisional Diffie–Hellman assumption (DDH) holds in ${\displaystyle G}$, then ElGamal achieves semantic security.[2][3] Semantic security is not implied by the computational Diffie–Hellman assumption alone.[4] See decisional Diffie–Hellman assumption for a discussion of groups where the assumption is believed to hold.

ElGamal encryption is unconditionally malleable, and therefore is not secure under chosen ciphertext attack. For example, given an encryption ${\displaystyle (c_{1},c_{2})}$ of some (possibly unknown) message ${\displaystyle m}$, one can easily construct a valid encryption ${\displaystyle (c_{1},2c_{2})}$ of the message ${\displaystyle 2m}$.

To achieve chosen-ciphertext security, the scheme must be further modified, or an appropriate padding scheme must be used. Depending on the modification, the DDH assumption may or may not be necessary.

Other schemes related to ElGamal which achieve security against chosen ciphertext attacks have also been proposed. The Cramer–Shoup cryptosystem is secure under chosen ciphertext attack assuming DDH holds for ${\displaystyle G}$. Its proof does not use the random oracle model. Another proposed scheme is DHAES,[4] whose proof requires an assumption that is weaker than the DDH assumption.

Efficiency

ElGamal encryption is probabilistic, meaning that a single plaintext can be encrypted to many possible ciphertexts, with the consequence that a general ElGamal encryption produces a 1:2 expansion in size from plaintext to ciphertext.

Encryption under ElGamal requires two exponentiations; however, these exponentiations are independent of the message and can be computed ahead of time if need be. Decryption requires one exponentiation and one computation of a group inverse which can however be easily combined into just one exponentiation.