![JAR search and dependency download from the Maven repository](/logo.png)
org.bouncycastle.math.ec.WNafL2RMultiplier Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of bc-fips-debug Show documentation
Show all versions of bc-fips-debug Show documentation
The FIPS 140-2 Bouncy Castle Crypto package is a Java implementation of cryptographic algorithms certified to FIPS 140-2 level 1. This jar contains the debug version JCE provider and low-level API for the BC-FJA version 1.0.2.3, FIPS Certificate #3514. Please note the debug jar is not certified.
/***************************************************************/
/****** DO NOT EDIT THIS CLASS bc-java SOURCE FILE ******/
/***************************************************************/
package org.bouncycastle.math.ec;
import java.math.BigInteger;
import org.bouncycastle.util.Integers;
/**
* Class implementing the WNAF (Window Non-Adjacent Form) multiplication
* algorithm.
*/
public class WNafL2RMultiplier extends AbstractECMultiplier
{
/**
* Multiplies this
by an integer k
using the
* Window NAF method.
* @param k The integer by which this
is multiplied.
* @return A new ECPoint
which equals this
* multiplied by k
.
*/
protected ECPoint multiplyPositive(ECPoint p, BigInteger k)
{
int minWidth = WNafUtil.getWindowSize(k.bitLength());
WNafPreCompInfo info = WNafUtil.precompute(p, minWidth, true);
ECPoint[] preComp = info.getPreComp();
ECPoint[] preCompNeg = info.getPreCompNeg();
int width = info.getWidth();
int[] wnaf = WNafUtil.generateCompactWindowNaf(width, k);
ECPoint R = p.getCurve().getInfinity();
int i = wnaf.length;
/*
* NOTE: We try to optimize the first window using the precomputed points to substitute an
* addition for 2 or more doublings.
*/
if (i > 1)
{
int wi = wnaf[--i];
int digit = wi >> 16, zeroes = wi & 0xFFFF;
int n = Math.abs(digit);
ECPoint[] table = digit < 0 ? preCompNeg : preComp;
// Optimization can only be used for values in the lower half of the table
if ((n << 2) < (1 << width))
{
int highest = 32 - Integers.numberOfLeadingZeros(n);
// TODO Get addition/doubling cost ratio from curve and compare to 'scale' to see if worth substituting?
int scale = width - highest;
int lowBits = n ^ (1 << (highest - 1));
int i1 = ((1 << (width - 1)) - 1);
int i2 = (lowBits << scale) + 1;
R = table[i1 >>> 1].add(table[i2 >>> 1]);
zeroes -= scale;
}
else
{
R = table[n >>> 1];
}
R = R.timesPow2(zeroes);
}
while (i > 0)
{
int wi = wnaf[--i];
int digit = wi >> 16, zeroes = wi & 0xFFFF;
int n = Math.abs(digit);
ECPoint[] table = digit < 0 ? preCompNeg : preComp;
ECPoint r = table[n >>> 1];
R = R.twicePlus(r);
R = R.timesPow2(zeroes);
}
return R;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy