diff options
author | Peter Dettman <peter.dettman@bouncycastle.org> | 2014-01-30 12:13:15 +0400 |
---|---|---|
committer | Peter Dettman <peter.dettman@bouncycastle.org> | 2014-01-30 12:13:15 +0400 |
commit | ad319cc8d6b105655b2f28de86b22f6e53619b26 (patch) | |
tree | 67c9820387811c8ebdea66834deb8ee01cb89617 /core/src/main/java/org/bouncycastle/math | |
parent | b44c044c1288cb1d445170d7946546bf3966396f (diff) |
Add squareN to perform repeated modular squaring
Diffstat (limited to 'core/src/main/java/org/bouncycastle/math')
-rw-r--r-- | core/src/main/java/org/bouncycastle/math/ec/custom/sec/SecP256K1Field.java | 15 | ||||
-rw-r--r-- | core/src/main/java/org/bouncycastle/math/ec/custom/sec/SecP256R1Field.java | 15 |
2 files changed, 30 insertions, 0 deletions
diff --git a/core/src/main/java/org/bouncycastle/math/ec/custom/sec/SecP256K1Field.java b/core/src/main/java/org/bouncycastle/math/ec/custom/sec/SecP256K1Field.java index 9299dcd9..3d1c45e1 100644 --- a/core/src/main/java/org/bouncycastle/math/ec/custom/sec/SecP256K1Field.java +++ b/core/src/main/java/org/bouncycastle/math/ec/custom/sec/SecP256K1Field.java @@ -113,6 +113,21 @@ public class SecP256K1Field reduce(tt, z); } + public static void squareN(int[] x, int n, int[] z) + { +// assert n > 0; + + int[] tt = Nat256.createExt(); + Nat256.square(x, tt); + reduce(tt, z); + + while (--n > 0) + { + Nat256.square(z, tt); + reduce(tt, z); + } + } + public static void subtract(int[] x, int[] y, int[] z) { int c = Nat256.sub(x, y, z); diff --git a/core/src/main/java/org/bouncycastle/math/ec/custom/sec/SecP256R1Field.java b/core/src/main/java/org/bouncycastle/math/ec/custom/sec/SecP256R1Field.java index 15412efe..94bbef69 100644 --- a/core/src/main/java/org/bouncycastle/math/ec/custom/sec/SecP256R1Field.java +++ b/core/src/main/java/org/bouncycastle/math/ec/custom/sec/SecP256R1Field.java @@ -146,6 +146,21 @@ public class SecP256R1Field reduce(tt, z); } + public static void squareN(int[] x, int n, int[] z) + { +// assert n > 0; + + int[] tt = Nat256.createExt(); + Nat256.square(x, tt); + reduce(tt, z); + + while (--n > 0) + { + Nat256.square(z, tt); + reduce(tt, z); + } + } + public static void subtract(int[] x, int[] y, int[] z) { int c = Nat256.sub(x, y, z); |