1 files changed, 26 insertions, 0 deletions
diff --git a/crypto/src/math/ec/Mod.cs b/crypto/src/math/ec/Mod.cs
index a05ff77aa..37958e57e 100644
--- a/crypto/src/math/ec/Mod.cs
+++ b/crypto/src/math/ec/Mod.cs
@@ -1,6 +1,7 @@
using System;
using System.Diagnostics;
+using Org.BouncyCastle.Crypto.Utilities;
using Org.BouncyCastle.Utilities;
namespace Org.BouncyCastle.Math.EC
@@ -73,6 +74,31 @@ namespace Org.BouncyCastle.Math.EC
}
}
+ public static uint[] Random(uint[] p)
+ {
+ int len = p.Length;
+ Random rand = new Random();
+ uint[] s = Nat.Create(len);
+
+ uint m = p[len - 1];
+ m |= m >> 1;
+ m |= m >> 2;
+ m |= m >> 4;
+ m |= m >> 8;
+ m |= m >> 16;
+
+ do
+ {
+ byte[] bytes = new byte[len << 2];
+ rand.NextBytes(bytes);
+ Pack.BE_To_UInt32(bytes, 0, s);
+ s[len - 1] &= m;
+ }
+ while (Nat.Gte(len, s, p));
+
+ return s;
+ }
+
public static void Subtract(uint[] p, uint[] x, uint[] y, uint[] z)
{
int len = p.Length;
|