This is the mail archive of the
java-patches@gcc.gnu.org
mailing list for the Java project.
BigInteger.modInverse() fix
- From: Mark Wielaard <mark at klomp dot org>
- To: java-patches at gcc dot gnu dot org
- Cc: raif at fl dot net dot au
- Date: 15 Dec 2002 16:35:34 +0100
- Subject: BigInteger.modInverse() fix
- Organization:
Hi,
The following patch comes from Raif Naffah the GNU Crypto maintainer.
He also made a Mauve test for this case which succeeds with this patch.
All GNU Crypto regression tests also succeed after this patch.
2002-12-15 Raif Naffah <raif@fl.net.au>
* java/math/BigInteger.java (euclidInv): Make sure quot and rem are in
canonical form after divide().
(modInverse): Likewise.
OK to commit to branch and mainline?
Cheers,
Mark
--- java/math/BigInteger.java.orig 2002-12-03 21:40:33.000000000 +0100
+++ java/math/BigInteger.java 2002-12-15 15:37:45.000000000 +0100
@@ -1113,6 +1113,9 @@
BigInteger rem = new BigInteger();
BigInteger quot = new BigInteger();
divide(a, b, quot, rem, FLOOR);
+ // quot and rem may not be in canonical form. ensure
+ rem.canonicalize();
+ quot.canonicalize();
xy = euclidInv(b, rem, quot);
}
@@ -1192,6 +1195,9 @@
BigInteger rem = new BigInteger();
BigInteger quot = new BigInteger();
divide(x, y, quot, rem, FLOOR);
+ // quot and rem may not be in canonical form. ensure
+ rem.canonicalize();
+ quot.canonicalize();
result = euclidInv(y, rem, quot)[swapped ? 0 : 1];
// Result can't be negative, so make it positive by adding the