Home  Trees  Indices  Help 



ElGamal publickey algorithm (randomized encryption and signature).
The security of the ElGamal signature scheme is based (like DSA) on the discrete logarithm problem (DLP). Given a cyclic group, a generator g, and an element h, it is hard to find an integer x such that g^x = h.
The group is the largest multiplicative subgroup of the integers modulo p, with p prime. The signer holds a value x (0<x<p1) as private key, and its public key (y where y=g^x mod p) is distributed.
The ElGamal signature is twice as big as p.
The security of the ElGamal encryption scheme is based on the computational DiffieHellman problem (CDH). Given a cyclic group, a generator g, and two integers a and b, it is difficult to find the element g^{ab} when only g^a and g^b are known, and not a and b.
As before, the group is the largest multiplicative subgroup of the integers modulo p, with p prime. The receiver holds a value a (0<a<p1) as private key, and its public key (b where b*=g^a) is given to the sender.
The ElGamal ciphertext is twice as big as p.
For both signature and encryption schemes, the values (p,g) are called domain parameters. They are not sensitive but must be distributed to all parties (senders and receivers). Different signers can share the same domain parameters, as can different recipients of encrypted messages.
Both DLP and CDH problem are believed to be difficult, and they have been proved such (and therefore secure) for more than 30 years.
The cryptographic strength is linked to the magnitude of p. In 2012, a sufficient size for p is deemed to be 2048 bits. For more information, see the most recent ECRYPT report.
Even though ElGamal algorithms are in theory reasonably secure for new designs, in practice there are no real good reasons for using them. The signature is four times larger than the equivalent DSA, and the ciphertext is two times larger than the equivalent RSA.
This module provides facilities for generating new ElGamal keys and for constructing them from known components. ElGamal keys allows you to perform basic signing, verification, encryption, and decryption.
>>> from Crypto import Random >>> from Crypto.Random import random >>> from Crypto.PublicKey import ElGamal >>> from Crypto.Util.number import GCD >>> from Crypto.Hash import SHA >>> >>> message = "Hello" >>> key = ElGamal.generate(1024, Random.new().read) >>> h = SHA.new(message).digest() >>> while 1: >>> k = random.StrongRandom().randint(1,key.p1) >>> if GCD(k,key.p1)==1: break >>> sig = key.sign(h,k) >>> ... >>> if key.verify(h,sig): >>> print "OK" >>> else: >>> print "Incorrect signature"
Classes  
error  
ElGamalobj Class defining an ElGamal key. 
Functions  



Function Details 
Randomly generate a fresh, new ElGamal key. The key will be safe for use for both encryption and signature (although it should be used for only one purpose).
Attention: You should always use a cryptographically secure random number generator, such as the one defined in the Crypto.Random module; don't just use the current time and the random module. 
Construct an ElGamal key from a tuple of valid ElGamal components. The modulus p must be a prime. The following conditions must apply:

Home  Trees  Indices  Help 


Generated by Epydoc 3.0.1 on Thu May 24 09:02:36 2012  http://epydoc.sourceforge.net 