diff options
author | Roberto Tyley <roberto.tyley@gmail.com> | 2014-07-15 01:38:01 +0400 |
---|---|---|
committer | Roberto Tyley <roberto.tyley@gmail.com> | 2014-07-26 11:23:17 +0400 |
commit | 7cb752aaf746dc0b473afeb9e892b7fbc12666c5 (patch) | |
tree | cc4f91ddc18332b5adbe82e3fcb040d976c90105 /core/src/main/java/org/bouncycastle/crypto/generators/DSAKeyPairGenerator.java | |
parent | 551830f8ea5177042af2c7dd1fc90888bc67387d (diff) |
Execute become-spongy.sh
https://github.com/rtyley/spongycastle/blob/3040af/become-spongy.sh
Diffstat (limited to 'core/src/main/java/org/bouncycastle/crypto/generators/DSAKeyPairGenerator.java')
-rw-r--r-- | core/src/main/java/org/bouncycastle/crypto/generators/DSAKeyPairGenerator.java | 69 |
1 files changed, 0 insertions, 69 deletions
diff --git a/core/src/main/java/org/bouncycastle/crypto/generators/DSAKeyPairGenerator.java b/core/src/main/java/org/bouncycastle/crypto/generators/DSAKeyPairGenerator.java deleted file mode 100644 index ff3df358..00000000 --- a/core/src/main/java/org/bouncycastle/crypto/generators/DSAKeyPairGenerator.java +++ /dev/null @@ -1,69 +0,0 @@ -package org.bouncycastle.crypto.generators; - -import java.math.BigInteger; -import java.security.SecureRandom; - -import org.bouncycastle.crypto.AsymmetricCipherKeyPair; -import org.bouncycastle.crypto.AsymmetricCipherKeyPairGenerator; -import org.bouncycastle.crypto.KeyGenerationParameters; -import org.bouncycastle.crypto.params.DSAKeyGenerationParameters; -import org.bouncycastle.crypto.params.DSAParameters; -import org.bouncycastle.crypto.params.DSAPrivateKeyParameters; -import org.bouncycastle.crypto.params.DSAPublicKeyParameters; -import org.bouncycastle.math.ec.WNafUtil; -import org.bouncycastle.util.BigIntegers; - -/** - * a DSA key pair generator. - * - * This generates DSA keys in line with the method described - * in <i>FIPS 186-3 B.1 FFC Key Pair Generation</i>. - */ -public class DSAKeyPairGenerator - implements AsymmetricCipherKeyPairGenerator -{ - private static final BigInteger ONE = BigInteger.valueOf(1); - - private DSAKeyGenerationParameters param; - - public void init( - KeyGenerationParameters param) - { - this.param = (DSAKeyGenerationParameters)param; - } - - public AsymmetricCipherKeyPair generateKeyPair() - { - DSAParameters dsaParams = param.getParameters(); - - BigInteger x = generatePrivateKey(dsaParams.getQ(), param.getRandom()); - BigInteger y = calculatePublicKey(dsaParams.getP(), dsaParams.getG(), x); - - return new AsymmetricCipherKeyPair( - new DSAPublicKeyParameters(y, dsaParams), - new DSAPrivateKeyParameters(x, dsaParams)); - } - - private static BigInteger generatePrivateKey(BigInteger q, SecureRandom random) - { - // B.1.2 Key Pair Generation by Testing Candidates - int minWeight = q.bitLength() >>> 2; - for (;;) - { - // TODO Prefer this method? (change test cases that used fixed random) - // B.1.1 Key Pair Generation Using Extra Random Bits -// BigInteger x = new BigInteger(q.bitLength() + 64, random).mod(q.subtract(ONE)).add(ONE); - - BigInteger x = BigIntegers.createRandomInRange(ONE, q.subtract(ONE), random); - if (WNafUtil.getNafWeight(x) >= minWeight) - { - return x; - } - } - } - - private static BigInteger calculatePublicKey(BigInteger p, BigInteger g, BigInteger x) - { - return g.modPow(x, p); - } -} |