summary refs log tree commit diff
path: root/crypto/src/math/raw/Nat.cs
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2019-07-31 17:42:12 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2019-07-31 17:42:12 +0700
commite7e89cce762e32917c1eef745b05da636ed03bbb (patch)
tree063c1ad6b42b21b0c10afc8ed173a4675f286e13 /crypto/src/math/raw/Nat.cs
parentFix CMP tests failing to set body (diff)
downloadBouncyCastle.NET-ed25519-e7e89cce762e32917c1eef745b05da636ed03bbb.tar.xz
Accept only properly-sized BigInteger (no auto-reduction)
Diffstat (limited to 'crypto/src/math/raw/Nat.cs')
-rw-r--r--crypto/src/math/raw/Nat.cs16
1 files changed, 16 insertions, 0 deletions
diff --git a/crypto/src/math/raw/Nat.cs b/crypto/src/math/raw/Nat.cs
index f9e4e6714..5cf5fe218 100644
--- a/crypto/src/math/raw/Nat.cs
+++ b/crypto/src/math/raw/Nat.cs
@@ -384,6 +384,22 @@ namespace Org.BouncyCastle.Math.Raw
             return z;
         }
 
+        public static ulong[] FromBigInteger64(int bits, BigInteger x)
+        {
+            if (x.SignValue < 0 || x.BitLength > bits)
+                throw new ArgumentException();
+
+            int len = (bits + 63) >> 6;
+            ulong[] z = Create64(len);
+            int i = 0;
+            while (x.SignValue != 0)
+            {
+                z[i++] = (ulong)x.LongValue;
+                x = x.ShiftRight(64);
+            }
+            return z;
+        }
+
         public static uint GetBit(uint[] x, int bit)
         {
             if (bit == 0)