diff --git a/src/crypto/public_key/dsa.js b/src/crypto/public_key/dsa.js index c98bfee4..f06db62c 100644 --- a/src/crypto/public_key/dsa.js +++ b/src/crypto/public_key/dsa.js @@ -49,7 +49,7 @@ function DSA() { // or s = 0 if signatures are generated properly. var k, s1, s2; while (true) { - k = random.getRandomBigIntegerInRange(BigInteger.ONE.add(BigInteger.ONE), q.subtract(BigInteger.ONE)); + k = random.getRandomBigIntegerInRange(BigInteger.ONE, q.subtract(BigInteger.ONE)); s1 = (g.modPow(k, p)).mod(q); s2 = (k.modInverse(q).multiply(hash.add(x.multiply(s1)))).mod(q); if (s1 != 0 && s2 != 0) { diff --git a/src/crypto/public_key/elgamal.js b/src/crypto/public_key/elgamal.js index 7638bd2e..2ba304fc 100644 --- a/src/crypto/public_key/elgamal.js +++ b/src/crypto/public_key/elgamal.js @@ -32,9 +32,8 @@ function Elgamal() { function encrypt(m, g, p, y) { // choose k in {2,...,p-2} - var two = BigInteger.ONE.add(BigInteger.ONE); - var pMinus2 = p.subtract(two); - var k = random.getRandomBigIntegerInRange(two, pMinus2); + var pMinus2 = p.subtract(BigInteger.TWO); + var k = random.getRandomBigIntegerInRange(BigInteger.ONE, pMinus2); k = k.mod(pMinus2).add(BigInteger.ONE); var c = []; c[0] = g.modPow(k, p); diff --git a/src/crypto/public_key/jsbn.js b/src/crypto/public_key/jsbn.js index ea6e87d4..948c9f31 100644 --- a/src/crypto/public_key/jsbn.js +++ b/src/crypto/public_key/jsbn.js @@ -730,6 +730,7 @@ BigInteger.prototype.modPowInt = bnModPowInt; // "constants" BigInteger.ZERO = nbv(0); BigInteger.ONE = nbv(1); +BigInteger.TWO = nbv(2); module.exports = BigInteger; diff --git a/src/crypto/public_key/rsa.js b/src/crypto/public_key/rsa.js index eb997605..ba8b330e 100644 --- a/src/crypto/public_key/rsa.js +++ b/src/crypto/public_key/rsa.js @@ -40,13 +40,12 @@ function SecureRandom() { var blinder = BigInteger.ZERO; var unblinder = BigInteger.ZERO; -var TWO = BigInteger.ONE.add(BigInteger.ONE); function blind(m, n, e) { if (unblinder.bitLength() === n.bitLength()) { unblinder = unblinder.square().mod(n); } else { - unblinder = random.getRandomBigIntegerInRange(TWO, n); + unblinder = random.getRandomBigIntegerInRange(BigInteger.TWO, n); } blinder = unblinder.modInverse(n).modPow(e, n); return m.multiply(blinder).mod(n);