summary refs log tree commit diff
path: root/crypto
diff options
context:
space:
mode:
Diffstat (limited to 'crypto')
-rw-r--r--crypto/src/math/BigInteger.cs6
-rw-r--r--crypto/src/math/ec/abc/Tnaf.cs4
2 files changed, 7 insertions, 3 deletions
diff --git a/crypto/src/math/BigInteger.cs b/crypto/src/math/BigInteger.cs
index 42b5b5089..e5ab22e92 100644
--- a/crypto/src/math/BigInteger.cs
+++ b/crypto/src/math/BigInteger.cs
@@ -1719,6 +1719,8 @@ namespace Org.BouncyCastle.Math
             return (biggie.sign >= 0 ? biggie : biggie.Add(m));
         }
 
+        public BigInteger ModDivide(BigInteger y, BigInteger m) => ModMultiply(y.ModInverse(m), m);
+
         public BigInteger ModInverse(
             BigInteger m)
         {
@@ -1875,6 +1877,10 @@ namespace Org.BouncyCastle.Math
             Array.Clear(x, 0, x.Length);
         }
 
+        public BigInteger ModMultiply(BigInteger y, BigInteger m) => Multiply(y).Mod(m);
+
+        public BigInteger ModSquare(BigInteger m) => Square().Mod(m);
+
         public BigInteger ModPow(BigInteger e, BigInteger m)
         {
             if (m.sign < 1)
diff --git a/crypto/src/math/ec/abc/Tnaf.cs b/crypto/src/math/ec/abc/Tnaf.cs
index d8e9b6ae0..3707a974a 100644
--- a/crypto/src/math/ec/abc/Tnaf.cs
+++ b/crypto/src/math/ec/abc/Tnaf.cs
@@ -512,9 +512,7 @@ namespace Org.BouncyCastle.Math.EC.Abc
             {
                 // For w <> 4, the values must be computed
                 BigInteger[] us = GetLucas(mu, w, false);
-                BigInteger twoToW = BigInteger.Zero.SetBit(w);
-                BigInteger u1invert = us[1].ModInverse(twoToW);
-                return us[0].ShiftLeft(1).Multiply(u1invert).Mod(twoToW);
+                return us[0].ShiftLeft(1).ModDivide(us[1], BigInteger.One.ShiftLeft(w));
             }
         }