Java implementation of RSA & ElGamal cryptosystems
Security of RSA depends on the difficulty of factoring large integers.
- Choose the size key (integer)
- Construct two random prime integer p and q as :
- 2[k/2]-1 ≤ p, q ≤ 2[k/2]-1 - 1
- N = p * q
- φ(N) = (p - 1)(q - 1) (Indicatrice d'Euler)
- Choose e in (Z/φ(N)Z)* and compute d as :
- ed ≡ 1 (mod φ(N))
public key | secret key |
---|---|
(N, e) | (d, p, q) |
A message m is in Z/NZ (the size of the message is less or equal to the size key)
- Alice has the public key (N, e)
- c = me (mod N)
- Bob has the private key (d, p, q)
- cd (mod N) = m
Security of the ElGamal algorithm depends on the difficulty of computing discrete logs in a large prime modulus
- Choose a random prime integer p as p = 2 p' + 1 with p' is prime
- Choose a random integer in (Z/pZ)* of order p'
- Choose a random integer x in [0, p' - 1]
- Compute h = gx in Z/pZ
public key | secret key |
---|---|
(p, g, h) | (p, x) |
- Choose a random r in [1, p' - 1]
- The encrypted message is (gr, m*hr)
ElGamal encryption is probabilistic, meaning that a single plaintext can be encrypted to many possible ciphertexts (but ElGamal encryption produces a 2:1 expansion in size from plaintext to ciphertext).
- Entry : (gr, m*hr)
- h = gx 1
- (gr)x = (gx)r = hr
- message = m*hr/hr
1
Cf. 4. of Key generation