FileDocCategorySizeDatePackage
DHKeyGeneratorHelper.javaAPI DocAndroid 1.5 API1654Wed May 06 22:41:06 BST 2009org.bouncycastle.crypto.generators

DHKeyGeneratorHelper

public class DHKeyGeneratorHelper extends Object

Fields Summary
private static final int
MAX_ITERATIONS
static final DHKeyGeneratorHelper
INSTANCE
private static BigInteger
ZERO
private static BigInteger
TWO
Constructors Summary
private DHKeyGeneratorHelper()

    
     
    
    
Methods Summary
java.math.BigIntegercalculatePrivate(java.math.BigInteger p, java.security.SecureRandom random, int limit)

        //
        // calculate the private key
        //
        BigInteger pSub2 = p.subtract(TWO);
        BigInteger x;
        
        if (limit == 0)
        {
            x = createInRange(pSub2, random);
        }
        else
        {
            do
            {
                x = new BigInteger(limit, random);
            }
            while (x.equals(ZERO));
        }
        
        return x;
    
java.math.BigIntegercalculatePublic(java.math.BigInteger p, java.math.BigInteger g, java.math.BigInteger x)

        return g.modPow(x, p);
    
private java.math.BigIntegercreateInRange(java.math.BigInteger max, java.security.SecureRandom random)

        BigInteger x;
        int maxLength = max.bitLength();
        int count = 0;
        
        do
        {
            x = new BigInteger(maxLength, random);
            count++;
        }
        while ((x.equals(ZERO) || x.compareTo(max) > 0) && count != MAX_ITERATIONS);
        
        if (count == MAX_ITERATIONS)  // fall back to a faster (restricted) method
        {
            return new BigInteger(maxLength - 1, random).setBit(0);
        }
        
        return x;