diff options
author | Peter Dettman <peter.dettman@bouncycastle.org> | 2014-03-03 12:12:42 +0400 |
---|---|---|
committer | Peter Dettman <peter.dettman@bouncycastle.org> | 2014-03-03 12:12:42 +0400 |
commit | a82d1f6bf794088c7d0b4d6fba80398a3a3307a7 (patch) | |
tree | db33dda30a590fa2730d6dcc421313cf103dc1bf /core/src/main/java/org | |
parent | 0d4373f8e7dcb57b6bb820eb35267e05cac2cc8c (diff) |
Share single temp variable across calls in sqrt()
Diffstat (limited to 'core/src/main/java/org')
-rw-r--r-- | core/src/main/java/org/bouncycastle/math/ec/custom/sec/SecP224R1FieldElement.java | 19 |
1 files changed, 9 insertions, 10 deletions
diff --git a/core/src/main/java/org/bouncycastle/math/ec/custom/sec/SecP224R1FieldElement.java b/core/src/main/java/org/bouncycastle/math/ec/custom/sec/SecP224R1FieldElement.java index e9c7d78b..74ebc047 100644 --- a/core/src/main/java/org/bouncycastle/math/ec/custom/sec/SecP224R1FieldElement.java +++ b/core/src/main/java/org/bouncycastle/math/ec/custom/sec/SecP224R1FieldElement.java @@ -138,6 +138,7 @@ public class SecP224R1FieldElement extends ECFieldElement SecP224R1Field.negate(c, nc); int[] r = Mod.random(SecP224R1Field.P); + int[] t = Nat224.create(); for (;;) { @@ -146,7 +147,7 @@ public class SecP224R1FieldElement extends ECFieldElement int[] e1 = Nat224.create(); e1[0] = 1; int[] f1 = Nat224.create(); - RP(nc, d1, e1, f1); + RP(nc, d1, e1, f1, t); int[] d0 = Nat224.create(); int[] e0 = Nat224.create(); @@ -156,7 +157,7 @@ public class SecP224R1FieldElement extends ECFieldElement Nat224.copy(d1, d0); Nat224.copy(e1, e0); - RS(d1, e1, f1); + RS(d1, e1, f1, t); if (Nat224.isZero(d1)) { @@ -195,9 +196,8 @@ public class SecP224R1FieldElement extends ECFieldElement return Q.hashCode() ^ Arrays.hashCode(x, 0, 7); } - private static void RM(int[] nc, int[] d0, int[] e0, int[] d1, int[] e1, int[] f1) + private static void RM(int[] nc, int[] d0, int[] e0, int[] d1, int[] e1, int[] f1, int[] t) { - int[] t = Nat224.create(); SecP224R1Field.multiply(e1, e0, t); SecP224R1Field.multiply(t, nc, t); SecP224R1Field.multiply(d1, d0, f1); @@ -210,7 +210,7 @@ public class SecP224R1FieldElement extends ECFieldElement SecP224R1Field.multiply(f1, nc, f1); } - private static void RP(int[] nc, int[] d1, int[] e1, int[] f1) + private static void RP(int[] nc, int[] d1, int[] e1, int[] f1, int[] t) { Nat224.copy(nc, f1); @@ -225,20 +225,19 @@ public class SecP224R1FieldElement extends ECFieldElement int j = 1 << i; while (--j >= 0) { - RS(d1, e1, f1); + RS(d1, e1, f1, t); } - RM(nc, d0, e0, d1, e1, f1); + RM(nc, d0, e0, d1, e1, f1, t); } } - private static void RS(int[] d, int[] e, int[] f) + private static void RS(int[] d, int[] e, int[] f, int[] t) { SecP224R1Field.multiply(e, d, e); - int[] t = Nat224.create(); + SecP224R1Field.twice(e, e); SecP224R1Field.square(d, t); SecP224R1Field.add(f, t, d); - SecP224R1Field.twice(e, e); SecP224R1Field.multiply(f, t, f); int c = Nat.shiftUpBits(7, f, 2, 0); SecP224R1Field.reduce32(c, f); |