Skip to content

Commit ba99da5

Browse files
committed
Use utility method for random generation
1 parent 2c726a9 commit ba99da5

File tree

1 file changed

+1
-18
lines changed

1 file changed

+1
-18
lines changed

core/src/main/java/org/bouncycastle/crypto/signers/DSTU4145Signer.java

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public BigInteger[] generateSignature(byte[] message)
9191
{
9292
do
9393
{
94-
e = generateRandomInteger(n, random);
94+
e = BigIntegers.createRandomInRange(BigInteger.ONE, n.subtract(BigInteger.ONE), random);
9595
Fe = basePointMultiplier.multiply(ec.getG(), e).normalize().getAffineXCoord();
9696
}
9797
while (Fe.isZero());
@@ -148,23 +148,6 @@ protected ECMultiplier createBasePointMultiplier()
148148
return new FixedPointCombMultiplier();
149149
}
150150

151-
/**
152-
* Generates random integer such that its value is less than that of n
153-
*/
154-
private static BigInteger generateRandomInteger(BigInteger n, SecureRandom random)
155-
{
156-
int nBitLength = n.bitLength();
157-
158-
BigInteger k;
159-
do
160-
{
161-
k = BigIntegers.createRandomBigInteger(nBitLength, random);
162-
}
163-
while (k.equals(BigIntegers.ZERO) || k.compareTo(n) >= 0);
164-
165-
return k;
166-
}
167-
168151
private static ECFieldElement hash2FieldElement(ECCurve curve, byte[] hash)
169152
{
170153
byte[] data = Arrays.reverse(hash);

0 commit comments

Comments
 (0)