DHKeyGeneratorHelperpublic 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.BigInteger | calculatePrivate(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.BigInteger | calculatePublic(java.math.BigInteger p, java.math.BigInteger g, java.math.BigInteger x)
return g.modPow(x, p);
| private java.math.BigInteger | createInRange(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;
|
|