Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/quite/humla-spongycastle.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Hook <dgh@cryptoworkshop.com>2014-04-13 04:23:49 +0400
committerDavid Hook <dgh@cryptoworkshop.com>2014-04-13 04:23:49 +0400
commit26f3b83df76b466a390691c6dd68beea9cc9386c (patch)
tree6069a639fc4a132f4bf6e44567befd8087e29ea0
parent28e9b63e1e1a90be8e955181944cd53f7c641ef6 (diff)
parentb352297b10de180b9f70099ee8b88fac41b3ef23 (diff)
Merge remote-tracking branch 'origin/master'
-rw-r--r--core/src/main/java/org/bouncycastle/crypto/generators/RSAKeyPairGenerator.java25
-rw-r--r--core/src/main/java/org/bouncycastle/math/ec/WNafUtil.java12
2 files changed, 13 insertions, 24 deletions
diff --git a/core/src/main/java/org/bouncycastle/crypto/generators/RSAKeyPairGenerator.java b/core/src/main/java/org/bouncycastle/crypto/generators/RSAKeyPairGenerator.java
index f5945b5f..928c6a6e 100644
--- a/core/src/main/java/org/bouncycastle/crypto/generators/RSAKeyPairGenerator.java
+++ b/core/src/main/java/org/bouncycastle/crypto/generators/RSAKeyPairGenerator.java
@@ -20,38 +20,37 @@ public class RSAKeyPairGenerator
private RSAKeyGenerationParameters param;
- public void init(
- KeyGenerationParameters param)
+ public void init(KeyGenerationParameters param)
{
this.param = (RSAKeyGenerationParameters)param;
}
public AsymmetricCipherKeyPair generateKeyPair()
{
- BigInteger p, q, n, d, e, pSub1, qSub1, phi;
+ BigInteger p, q, n, d, e, pSub1, qSub1, phi;
//
// p and q values should have a length of half the strength in bits
//
int strength = param.getStrength();
- int pbitlength = (strength + 1) / 2;
- int qbitlength = strength - pbitlength;
+ int qBitlength = strength >>> 1;
+ int pBitlength = strength - qBitlength;
int mindiffbits = strength / 3;
- int minWeight = strength >> 2;
+ int minWeight = strength >>> 2;
e = param.getPublicExponent();
// TODO Consider generating safe primes for p, q (see DHParametersHelper.generateSafePrimes)
// (then p-1 and q-1 will not consist of only small factors - see "Pollard's algorithm")
- p = chooseRandomPrime(pbitlength, e);
+ p = chooseRandomPrime(pBitlength, e);
//
// generate a modulus of the required length
//
for (;;)
{
- q = chooseRandomPrime(qbitlength, e);
+ q = chooseRandomPrime(qBitlength, e);
// p and q should not be too close together (or equal!)
BigInteger diff = q.subtract(p).abs();
@@ -83,7 +82,7 @@ public class RSAKeyPairGenerator
*/
if (WNafUtil.getNafWeight(n) < minWeight)
{
- p = chooseRandomPrime(pbitlength, e);
+ p = chooseRandomPrime(pBitlength, e);
continue;
}
@@ -109,15 +108,15 @@ public class RSAKeyPairGenerator
//
// calculate the CRT factors
//
- BigInteger dP, dQ, qInv;
+ BigInteger dP, dQ, qInv;
dP = d.remainder(pSub1);
dQ = d.remainder(qSub1);
qInv = q.modInverse(p);
return new AsymmetricCipherKeyPair(
- new RSAKeyParameters(false, n, e),
- new RSAPrivateCrtKeyParameters(n, e, d, p, q, dP, dQ, qInv));
+ new RSAKeyParameters(false, n, e),
+ new RSAPrivateCrtKeyParameters(n, e, d, p, q, dP, dQ, qInv));
}
/**
@@ -125,7 +124,7 @@ public class RSAKeyPairGenerator
*
* @param bitlength the bit-length of the returned prime
* @param e the RSA public exponent
- * @return A prime p, with (p-1) relatively prime to e
+ * @return a prime p, with (p-1) relatively prime to e
*/
protected BigInteger chooseRandomPrime(int bitlength, BigInteger e)
{
diff --git a/core/src/main/java/org/bouncycastle/math/ec/WNafUtil.java b/core/src/main/java/org/bouncycastle/math/ec/WNafUtil.java
index 7db5c1de..7ac3160c 100644
--- a/core/src/main/java/org/bouncycastle/math/ec/WNafUtil.java
+++ b/core/src/main/java/org/bouncycastle/math/ec/WNafUtil.java
@@ -293,17 +293,7 @@ public abstract class WNafUtil
BigInteger _3k = k.shiftLeft(1).add(k);
BigInteger diff = _3k.xor(k);
- int highBit = _3k.bitLength() - 1, length = 1;
- for (int i = 1; i < highBit; ++i)
- {
- if (diff.testBit(i))
- {
- ++length;
- ++i;
- }
- }
-
- return length;
+ return diff.bitCount();
}
public static WNafPreCompInfo getWNafPreCompInfo(ECPoint p)