EL GAMAL Enchryption
EL GAMAL Enchryption
The ElGamal encryption system is a public key encryption algorithm by Taher Elgamal in 1985
that is based on the Diffie-Hellman key exchange.
This encryption system use both symmetric and asymmetric cryptographic techniques
We assume that the message M that Bob encrypts and sends to Alice is an integer. A sending
message is encoded into integers.
We describe the three components of ElGamal encryption, namely
key generation,
Encryption of message using public key, and shared secret key
Decryption of message using private key
2
Why ElGamal Works
k
As K = yA mod q
x
• yA= a A mod q
x k
• K = a A mod q
k
• C1 = a mod q
xA
• K = (C1) mod q
• Next, C2 = KM mod q
• OR, C2K-1= M mod q = M
• If we calculate K-1, we can recover the M
3
ElGamal Encryption/Decryption Example 1
The modular inverse of A mod C is
the B value that makes A * B mod C =
Let q=19 and a=10
1
Alice computes her key: Only the numbers coprime to C
A chooses xA=5 & computes yA= a A mod q
x (numbers that share no prime factors
5
with C) have a modular inverse (mod
yA=10 mod 19 = 3 C)
Example: A=3, C=7
Bob send message M=17 as (C1, C2::11,5) by Step 1. Calculate A * B mod C for B
chosing random k=6 values 0 through C-1
k 6
computing K = yA mod q = 3 mod 19 = 7 3 * 0 ≡ 0 (mod 7)
k 6 3 * 1 ≡ 3 (mod 7)
computing C1 = a mod q = 10 mod 19 = 11;
3 * 2 ≡ 6 (mod 7)
C2 = KM mod q = 7*17 mod 19 = 5 3 * 3 ≡ 9 ≡ 2 (mod 7)
3 * 4 ≡ 12 ≡ 5 (mod 7)
Alice recovers original message by computing: 3 * 5 ≡ 15 (mod 7) ≡ 1 (mod 7) <------
5
recover K = C1xA mod q = 11 mod 19 = 7
FOUND INVERSE!
3 * 6 ≡ 18 (mod 7) ≡ 4 (mod 7)
Modular Multiplicative Inverse K-1 = 7-1 = 11
recover M = C2 K-1 mod q = 5*11 mod 19 = 17
4
ElGamal Encryption/Decryption Example2
6
ElGamal Digital Signature Scheme
Key Generation – each user (eg. A) generates their key
• chooses a secret key (number): 1 < xA< q-1
x
• compute their public key: yA= a A mod q
• A’s private key = xA public key = {q, a, yA}
• Signing
• To sign a message m, first its hash m = H(m) is computed, such that 1<=m<=q-1
• chose random integer K with 1<=K<=q-1 & gcd(K, q-1) = 1
• Compute the signature pair (S1, S2) as follow:
k
• S1 = a mod q (same as computing C1)
• Also, Compute K-1 mod(q-1), such that K.K-1 mod q-1 = 1
• S2 = K-1(m- XAS1) mod (q-1)
• Send (m, S1, S2)
• Verification
m
• Compute V1 = a mod q
S1 S2
• Compute V2 = (yA) (S1) mod q
• The signature is valid if V1 = V2
7
ElGamal Digital Signature Scheme – How it works
• Lets assume that V1 = V2
m S1 S2
• a mod q = (yA) (S1) mod q
xA k
• Substitute YA = a mod q & S1 = a mod q
m xA S1 K S2
• a mod q = (a ) (a ) mod q
m - XAS1 KS2
• a mod q = a mod q
• m - XAS1 = KS2
• m - XAS1 = m- XAS1
8
ElGamal Digital Signature Scheme – Example
Let q=19 and a=10