FileDocCategorySizeDatePackage
ElGamalParametersGenerator.javaAPI DocAzureus 3.0.3.41915Tue Jun 08 05:12:58 BST 2004org.bouncycastle.crypto.generators

ElGamalParametersGenerator

public class ElGamalParametersGenerator extends Object

Fields Summary
private int
size
private int
certainty
private SecureRandom
random
private static BigInteger
ONE
private static BigInteger
TWO
Constructors Summary
Methods Summary
public org.bouncycastle.crypto.params.ElGamalParametersgenerateParameters()
which generates the p and g values from the given parameters, returning the ElGamalParameters object.

Note: can take a while...

        BigInteger      g, p, q;
        int             qLength = size - 1;

        //
        // find a safe prime p where p = 2*q + 1, where p and q are prime.
        //
		for (;;)
		{
			q = new BigInteger(qLength, 1, random);
			
			if (q.bitLength() != qLength)
			{
				continue;
			}
			
			if (!q.isProbablePrime(certainty))
			{
				continue;
			}
			
            p = q.multiply(TWO).add(ONE);
            if (p.isProbablePrime(certainty))
            {
                break;
            }
		}

		//
		// calculate the generator g - the advantage of using the 2q+1 
        // approach is that we know the prime factorisation of (p - 1)...
	    //
        for (;;)
        {
            g = new BigInteger(qLength, random);

            if (g.modPow(TWO, p).equals(ONE))
            {
                continue;
            }

            if (g.modPow(q, p).equals(ONE))
            {
                continue;
            }

            break;
        }

        return new ElGamalParameters(p, g);
    
public voidinit(int size, int certainty, java.security.SecureRandom random)


      
                     
                     
            
    
        this.size = size;
        this.certainty = certainty;
        this.random = random;