Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/quite/humla-spongycastle.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2013-10-02 08:13:58 +0400
committerPeter Dettman <peter.dettman@bouncycastle.org>2013-10-02 08:13:58 +0400
commit1e5b98a08b5a2d45d77c6efb168da88bbdf0dc53 (patch)
treeaf4847e4472a4206110e9510f93f9ec36a6c1539 /core/src/main/java/org/bouncycastle/math
parent99459d27af4ac3072097e9c699329ff10a0705f4 (diff)
Some minor optimizations to modInverse
Diffstat (limited to 'core/src/main/java/org/bouncycastle/math')
-rw-r--r--core/src/main/java/org/bouncycastle/math/ec/IntArray.java16
1 files changed, 13 insertions, 3 deletions
diff --git a/core/src/main/java/org/bouncycastle/math/ec/IntArray.java b/core/src/main/java/org/bouncycastle/math/ec/IntArray.java
index 89e21a4b..5e61b799 100644
--- a/core/src/main/java/org/bouncycastle/math/ec/IntArray.java
+++ b/core/src/main/java/org/bouncycastle/math/ec/IntArray.java
@@ -577,6 +577,12 @@ class IntArray
// Input: A nonzero polynomial a(z) of degree at most m-1
// Output: a(z)^(-1) mod f(z)
+ int uzDegree = degree();
+ if (uzDegree == 1)
+ {
+ return this;
+ }
+
// u(z) := a(z)
IntArray uz = (IntArray)clone();
@@ -598,10 +604,10 @@ class IntArray
g1z.setBit(0);
IntArray g2z = new IntArray(t);
- while (!uz.isZero())
+ while (uzDegree != 0)
{
// j := deg(u(z)) - deg(v(z))
- int j = uz.degree() - vz.degree();
+ int j = uzDegree - vz.degree();
// If j < 0 then: u(z) <-> v(z), g1(z) <-> g2(z), j := -j
if (j < 0)
@@ -624,10 +630,14 @@ class IntArray
// = deg(u(z))
// uz = uz.xor(vz.shiftLeft(j));
uz.addShiftedByBits(vz, j);
+ uzDegree = uz.degree();
// g1(z) := g1(z) + z^j * g2(z)
// g1z = g1z.xor(g2z.shiftLeft(j));
- g1z.addShiftedByBits(g2z, j);
+ if (uzDegree != 0)
+ {
+ g1z.addShiftedByBits(g2z, j);
+ }
}
return g2z;
}