![JAR search and dependency download from the Maven repository](/logo.png)
org.bouncycastle.math.ec.FixedPointUtil 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;
public class FixedPointUtil
{
public static final String PRECOMP_NAME = "bc_fixed_point";
public static int getCombSize(ECCurve c)
{
BigInteger order = c.getOrder(), cofactor = c.getCofactor();
if (!cofactor.equals(ECConstants.ONE))
{
order = order.multiply(cofactor);
}
return order.bitLength();
}
public static FixedPointPreCompInfo getFixedPointPreCompInfo(PreCompInfo preCompInfo)
{
return (preCompInfo instanceof FixedPointPreCompInfo) ? (FixedPointPreCompInfo)preCompInfo : null;
}
public static FixedPointPreCompInfo precompute(final ECPoint p)
{
final ECCurve c = p.getCurve();
return (FixedPointPreCompInfo)c.precompute(p, PRECOMP_NAME, new PreCompCallback()
{
public PreCompInfo precompute(PreCompInfo existing)
{
FixedPointPreCompInfo existingFP = (existing instanceof FixedPointPreCompInfo) ? (FixedPointPreCompInfo)existing : null;
int bits = getCombSize(c);
int minWidth = bits > 250 ? 6 : 5;
int n = 1 << minWidth;
if (checkExisting(existingFP, n))
{
return existingFP;
}
int d = (bits + minWidth - 1) / minWidth;
ECPoint[] pow2Table = new ECPoint[minWidth + 1];
pow2Table[0] = p;
for (int i = 1; i < minWidth; ++i)
{
pow2Table[i] = pow2Table[i - 1].timesPow2(d);
}
// This will be the 'offset' value
pow2Table[minWidth] = pow2Table[0].subtract(pow2Table[1]);
c.normalizeAll(pow2Table);
ECPoint[] lookupTable = new ECPoint[n];
lookupTable[0] = pow2Table[0];
for (int bit = minWidth - 1; bit >= 0; --bit)
{
ECPoint pow2 = pow2Table[bit];
int step = 1 << bit;
for (int i = step; i < n; i += (step << 1))
{
lookupTable[i] = lookupTable[i - step].add(pow2);
}
}
c.normalizeAll(lookupTable);
FixedPointPreCompInfo result = new FixedPointPreCompInfo();
result.setLookupTable(c.createCacheSafeLookupTable(lookupTable, 0, lookupTable.length));
result.setOffset(pow2Table[minWidth]);
result.setWidth(minWidth);
return result;
}
private boolean checkExisting(FixedPointPreCompInfo existingFP, int n)
{
return existingFP != null && checkTable(existingFP.getLookupTable(), n);
}
private boolean checkTable(ECLookupTable table, int n)
{
return table != null && table.getSize() >= n;
}
});
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy