summary refs log tree commit diff
path: root/crypto/src/util/BigIntegers.cs
diff options
context:
space:
mode:
Diffstat (limited to 'crypto/src/util/BigIntegers.cs')
-rw-r--r--crypto/src/util/BigIntegers.cs40
1 files changed, 21 insertions, 19 deletions
diff --git a/crypto/src/util/BigIntegers.cs b/crypto/src/util/BigIntegers.cs
index 668d92246..9c5477e6a 100644
--- a/crypto/src/util/BigIntegers.cs
+++ b/crypto/src/util/BigIntegers.cs
@@ -139,11 +139,7 @@ namespace Org.BouncyCastle.Utilities
         * @param random the source of randomness
         * @return a random BigInteger value in the range [min,max]
         */
-        public static BigInteger CreateRandomInRange(
-            BigInteger		min,
-            BigInteger		max,
-            // TODO Should have been just Random class
-            SecureRandom	random)
+        public static BigInteger CreateRandomInRange(BigInteger min, BigInteger max, SecureRandom random)
         {
             int cmp = min.CompareTo(max);
             if (cmp >= 0)
@@ -155,23 +151,39 @@ namespace Org.BouncyCastle.Utilities
             }
 
             if (min.BitLength > max.BitLength / 2)
-            {
                 return CreateRandomInRange(BigInteger.Zero, max.Subtract(min), random).Add(min);
-            }
 
             for (int i = 0; i < MaxIterations; ++i)
             {
                 BigInteger x = new BigInteger(max.BitLength, random);
                 if (x.CompareTo(min) >= 0 && x.CompareTo(max) <= 0)
-                {
                     return x;
-                }
             }
 
             // fall back to a faster (restricted) method
             return new BigInteger(max.Subtract(min).BitLength - 1, random).Add(min);
         }
 
+        public static BigInteger FromUnsignedByteArray(byte[] buf)
+        {
+            return new BigInteger(1, buf);
+        }
+
+        public static BigInteger FromUnsignedByteArray(byte[] buf, int off, int length)
+        {
+            return new BigInteger(1, buf, off, length);
+        }
+
+        public static int GetByteLength(BigInteger n)
+        {
+            return n.GetLengthofByteArray();
+        }
+
+        public static int GetUnsignedByteLength(BigInteger n)
+        {
+            return n.GetLengthofByteArrayUnsigned();
+        }
+
         public static BigInteger ModOddInverse(BigInteger M, BigInteger X)
         {
             if (!M.TestBit(0))
@@ -253,15 +265,5 @@ namespace Org.BouncyCastle.Utilities
                 return Nat.ToBigInteger(len, z);
             }
         }
-
-        public static int GetByteLength(BigInteger n)
-        {
-            return n.GetLengthofByteArray();
-        }
-
-        public static int GetUnsignedByteLength(BigInteger n)
-        {
-            return n.GetLengthofByteArrayUnsigned();
-        }
     }
 }