- Initial commit
This commit is contained in:
45
Runtime/3rdParty/BouncyCastle/math/ec/multiplier/GlvMultiplier.cs
vendored
Normal file
45
Runtime/3rdParty/BouncyCastle/math/ec/multiplier/GlvMultiplier.cs
vendored
Normal file
@ -0,0 +1,45 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Math.EC.Endo;
|
||||
|
||||
namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Math.EC.Multiplier
|
||||
{
|
||||
public class GlvMultiplier
|
||||
: AbstractECMultiplier
|
||||
{
|
||||
protected readonly ECCurve curve;
|
||||
protected readonly GlvEndomorphism glvEndomorphism;
|
||||
|
||||
public GlvMultiplier(ECCurve curve, GlvEndomorphism glvEndomorphism)
|
||||
{
|
||||
if (curve == null || curve.Order == null)
|
||||
throw new ArgumentException("Need curve with known group order", "curve");
|
||||
|
||||
this.curve = curve;
|
||||
this.glvEndomorphism = glvEndomorphism;
|
||||
}
|
||||
|
||||
protected override ECPoint MultiplyPositive(ECPoint p, BigInteger k)
|
||||
{
|
||||
if (!curve.Equals(p.Curve))
|
||||
throw new InvalidOperationException();
|
||||
|
||||
BigInteger n = p.Curve.Order;
|
||||
BigInteger[] ab = glvEndomorphism.DecomposeScalar(k.Mod(n));
|
||||
BigInteger a = ab[0], b = ab[1];
|
||||
|
||||
if (glvEndomorphism.HasEfficientPointMap)
|
||||
{
|
||||
return ECAlgorithms.ImplShamirsTrickWNaf(glvEndomorphism, p, a, b);
|
||||
}
|
||||
|
||||
ECPoint q = EndoUtilities.MapPoint(glvEndomorphism, p);
|
||||
|
||||
return ECAlgorithms.ImplShamirsTrickWNaf(p, a, q, b);
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
Reference in New Issue
Block a user