Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/quite/humla-spongycastle.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2014-04-10 16:51:13 +0400
committerPeter Dettman <peter.dettman@bouncycastle.org>2014-04-10 16:51:13 +0400
commite897041d02aac63df7181ceaa1c9af1dfcb48c4a (patch)
treed558a5819b02318085acce8acc00bd6600dbe1f3
parent83be99efd17ab048494e2756b95e45f23c62cdbc (diff)
Missed from previous commit
-rw-r--r--core/src/main/java/org/bouncycastle/math/ec/WNafUtil.java23
1 files changed, 23 insertions, 0 deletions
diff --git a/core/src/main/java/org/bouncycastle/math/ec/WNafUtil.java b/core/src/main/java/org/bouncycastle/math/ec/WNafUtil.java
index e1868f4d..7db5c1de 100644
--- a/core/src/main/java/org/bouncycastle/math/ec/WNafUtil.java
+++ b/core/src/main/java/org/bouncycastle/math/ec/WNafUtil.java
@@ -283,6 +283,29 @@ public abstract class WNafUtil
return wnaf;
}
+ public static int getNafWeight(BigInteger k)
+ {
+ if (k.signum() == 0)
+ {
+ return 0;
+ }
+
+ BigInteger _3k = k.shiftLeft(1).add(k);
+ BigInteger diff = _3k.xor(k);
+
+ int highBit = _3k.bitLength() - 1, length = 1;
+ for (int i = 1; i < highBit; ++i)
+ {
+ if (diff.testBit(i))
+ {
+ ++length;
+ ++i;
+ }
+ }
+
+ return length;
+ }
+
public static WNafPreCompInfo getWNafPreCompInfo(ECPoint p)
{
return getWNafPreCompInfo(p.getCurve().getPreCompInfo(p, PRECOMP_NAME));