diff options
author | Peter Dettman <peter.dettman@bouncycastle.org> | 2014-02-26 15:15:22 +0400 |
---|---|---|
committer | Peter Dettman <peter.dettman@bouncycastle.org> | 2014-02-26 15:15:22 +0400 |
commit | 4d170f8d5c258efba2b4e2af4a3bb2b970a7d12f (patch) | |
tree | 4b103251ed1335ddb22623ca3964f389a200663c /core/src/main/java/org/bouncycastle | |
parent | 6ada53e0da87703868d1b916dbc9c827237255da (diff) |
Refactoring in sqrt()
Diffstat (limited to 'core/src/main/java/org/bouncycastle')
-rw-r--r-- | core/src/main/java/org/bouncycastle/math/ec/ECFieldElement.java | 20 |
1 files changed, 6 insertions, 14 deletions
diff --git a/core/src/main/java/org/bouncycastle/math/ec/ECFieldElement.java b/core/src/main/java/org/bouncycastle/math/ec/ECFieldElement.java index 665470d3..434287d9 100644 --- a/core/src/main/java/org/bouncycastle/math/ec/ECFieldElement.java +++ b/core/src/main/java/org/bouncycastle/math/ec/ECFieldElement.java @@ -241,9 +241,7 @@ public abstract class ECFieldElement if (q.testBit(2)) // q == 8m + 5 { - BigInteger m = q.shiftRight(3); - - BigInteger t1 = x.modPow(m, q); + BigInteger t1 = x.modPow(q.shiftRight(3), q); BigInteger t2 = modMult(t1, x); BigInteger t3 = modMult(t2, t1); @@ -252,33 +250,27 @@ public abstract class ECFieldElement return checkSqrt(new Fp(q, r, t2)); } - BigInteger e = m.add(ECConstants.ONE); - // TODO This is constant and could be precomputed - BigInteger t4 = ECConstants.FOUR.modPow(e, q); -// BigInteger t4 = ECConstants.TWO.modPow(e.shiftLeft(1), q); + BigInteger t4 = ECConstants.TWO.modPow(q.shiftRight(2), q); BigInteger y = modMult(t2, t4); - return checkSqrt(new Fp(q, r, modHalfAbs(y))); + return checkSqrt(new Fp(q, r, y)); } // q == 8m + 1 - BigInteger qMinusOne = q.subtract(ECConstants.ONE); - - BigInteger legendreExponent = qMinusOne.shiftRight(1); + BigInteger legendreExponent = q.shiftRight(1); if (!(x.modPow(legendreExponent, q).equals(ECConstants.ONE))) { return null; } - BigInteger u = qMinusOne.shiftRight(2); - BigInteger k = u.shiftLeft(1).add(ECConstants.ONE); - BigInteger X = this.x; BigInteger fourX = modDouble(modDouble(X)); + BigInteger k = legendreExponent.add(ECConstants.ONE), qMinusOne = q.subtract(ECConstants.ONE); + BigInteger U, V; Random rand = new Random(); do |