Cryptography/ElGamal

From Wikibooks, open books for an open world
Jump to navigation Jump to search

ElGamal is one of the simplest cryptosystems based on the discrete logarithm problem. A quick reminder of the discrete logarithm problem - given , such that , find . This is a hard problem when dealing with finite sets. ElGamal has a set of public parameters which can be shared by a number of users of the system. These are referred to as the domain parameters. These parameters are:

-  - a large prime of around 1024 bits (currently) such that  is divisible by another prime  of around 160 bits.
-  - an element of the finite field  with order divisible by , that is .

The domain parameters create a public group with a prime order and a generator . In other words, we create a large but finite group, and a method of ordering that group (the generator), and we know that it will contain a prime number of elements. These are the properties we are after. These parameters are public, and the security of the system depends on the public and private key pair, which we shall generate next.

The private key is a randomly-chosen integer. The public key is .

In order to encrypt a message we generate a random ephemeral key , and calculate:

This gives us the ciphertext .

In order to decrypt a ciphertext we compute:

As you can see from the decryption method, the message 0 will encrypt to itself, so not a good choice of message. In addition to this, as a result of using the ephemeral key , which will change every time you can see that the same message will encrypt to many different ciphertexts.

Since the ciphertext is expressed as 2 integers of the same length as the message, we end up with ciphertexts being twice as large as the message they're encrypting.