summary refs log tree commit diff
path: root/crypto/src/math/ec
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2014-04-11 10:11:27 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2014-04-11 10:11:27 +0700
commit10a2318ac5f90a581a919e9d4de489c6d217f5a7 (patch)
tree4de4091d3bf2bab7097a509e55dd7310b1dbebc3 /crypto/src/math/ec
parentUpdate version to beta.4 following beta.3 release (diff)
downloadBouncyCastle.NET-ed25519-10a2318ac5f90a581a919e9d4de489c6d217f5a7.tar.xz
Check for low-weight numbers in DH parameter generation and RSA key generation
Diffstat (limited to 'crypto/src/math/ec')
-rw-r--r--crypto/src/math/ec/multiplier/WNafUtilities.cs11
1 files changed, 11 insertions, 0 deletions
diff --git a/crypto/src/math/ec/multiplier/WNafUtilities.cs b/crypto/src/math/ec/multiplier/WNafUtilities.cs

index 98e4f545f..865b9073e 100644 --- a/crypto/src/math/ec/multiplier/WNafUtilities.cs +++ b/crypto/src/math/ec/multiplier/WNafUtilities.cs
@@ -268,6 +268,17 @@ namespace Org.BouncyCastle.Math.EC.Multiplier return wnaf; } + public static int GetNafWeight(BigInteger k) + { + if (k.SignValue == 0) + return 0; + + BigInteger _3k = k.ShiftLeft(1).Add(k); + BigInteger diff = _3k.Xor(k); + + return diff.BitCount; + } + public static WNafPreCompInfo GetWNafPreCompInfo(ECPoint p) { return GetWNafPreCompInfo(p.Curve.GetPreCompInfo(p, PRECOMP_NAME));