init commit
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
namespace Org.BouncyCastle.Math.EC.Endo;
|
||||
|
||||
public interface ECEndomorphism
|
||||
{
|
||||
ECPointMap PointMap { get; }
|
||||
|
||||
bool HasEfficientPointMap { get; }
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
namespace Org.BouncyCastle.Math.EC.Endo;
|
||||
|
||||
public interface GlvEndomorphism : ECEndomorphism
|
||||
{
|
||||
BigInteger[] DecomposeScalar(BigInteger k);
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
namespace Org.BouncyCastle.Math.EC.Endo;
|
||||
|
||||
public class GlvTypeBEndomorphism : GlvEndomorphism, ECEndomorphism
|
||||
{
|
||||
protected readonly ECCurve m_curve;
|
||||
|
||||
protected readonly GlvTypeBParameters m_parameters;
|
||||
|
||||
protected readonly ECPointMap m_pointMap;
|
||||
|
||||
public virtual ECPointMap PointMap => m_pointMap;
|
||||
|
||||
public virtual bool HasEfficientPointMap => true;
|
||||
|
||||
public GlvTypeBEndomorphism(ECCurve curve, GlvTypeBParameters parameters)
|
||||
{
|
||||
m_curve = curve;
|
||||
m_parameters = parameters;
|
||||
m_pointMap = new ScaleXPointMap(curve.FromBigInteger(parameters.Beta));
|
||||
}
|
||||
|
||||
public virtual BigInteger[] DecomposeScalar(BigInteger k)
|
||||
{
|
||||
int bits = m_parameters.Bits;
|
||||
BigInteger bigInteger = CalculateB(k, m_parameters.G1, bits);
|
||||
BigInteger bigInteger2 = CalculateB(k, m_parameters.G2, bits);
|
||||
BigInteger[] v = m_parameters.V1;
|
||||
BigInteger[] v2 = m_parameters.V2;
|
||||
BigInteger bigInteger3 = k.Subtract(bigInteger.Multiply(v[0]).Add(bigInteger2.Multiply(v2[0])));
|
||||
BigInteger bigInteger4 = bigInteger.Multiply(v[1]).Add(bigInteger2.Multiply(v2[1])).Negate();
|
||||
return new BigInteger[2] { bigInteger3, bigInteger4 };
|
||||
}
|
||||
|
||||
protected virtual BigInteger CalculateB(BigInteger k, BigInteger g, int t)
|
||||
{
|
||||
bool flag = g.SignValue < 0;
|
||||
BigInteger bigInteger = k.Multiply(g.Abs());
|
||||
bool flag2 = bigInteger.TestBit(t - 1);
|
||||
bigInteger = bigInteger.ShiftRight(t);
|
||||
if (flag2)
|
||||
{
|
||||
bigInteger = bigInteger.Add(BigInteger.One);
|
||||
}
|
||||
if (!flag)
|
||||
{
|
||||
return bigInteger;
|
||||
}
|
||||
return bigInteger.Negate();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
namespace Org.BouncyCastle.Math.EC.Endo;
|
||||
|
||||
public class GlvTypeBParameters
|
||||
{
|
||||
protected readonly BigInteger m_beta;
|
||||
|
||||
protected readonly BigInteger m_lambda;
|
||||
|
||||
protected readonly BigInteger[] m_v1;
|
||||
|
||||
protected readonly BigInteger[] m_v2;
|
||||
|
||||
protected readonly BigInteger m_g1;
|
||||
|
||||
protected readonly BigInteger m_g2;
|
||||
|
||||
protected readonly int m_bits;
|
||||
|
||||
public virtual BigInteger Beta => m_beta;
|
||||
|
||||
public virtual BigInteger Lambda => m_lambda;
|
||||
|
||||
public virtual BigInteger[] V1 => m_v1;
|
||||
|
||||
public virtual BigInteger[] V2 => m_v2;
|
||||
|
||||
public virtual BigInteger G1 => m_g1;
|
||||
|
||||
public virtual BigInteger G2 => m_g2;
|
||||
|
||||
public virtual int Bits => m_bits;
|
||||
|
||||
public GlvTypeBParameters(BigInteger beta, BigInteger lambda, BigInteger[] v1, BigInteger[] v2, BigInteger g1, BigInteger g2, int bits)
|
||||
{
|
||||
m_beta = beta;
|
||||
m_lambda = lambda;
|
||||
m_v1 = v1;
|
||||
m_v2 = v2;
|
||||
m_g1 = g1;
|
||||
m_g2 = g2;
|
||||
m_bits = bits;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user