AbstractECMultiplier.cs 903 B

12345678910111213141516171819202122232425262728
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. namespace Org.BouncyCastle.Math.EC.Multiplier
  3. {
  4. public abstract class AbstractECMultiplier
  5. : ECMultiplier
  6. {
  7. public virtual ECPoint Multiply(ECPoint p, BigInteger k)
  8. {
  9. int sign = k.SignValue;
  10. if (sign == 0 || p.IsInfinity)
  11. return p.Curve.Infinity;
  12. ECPoint positive = MultiplyPositive(p, k.Abs());
  13. ECPoint result = sign > 0 ? positive : positive.Negate();
  14. /*
  15. * Although the various multipliers ought not to produce invalid output under normal
  16. * circumstances, a final check here is advised to guard against fault attacks.
  17. */
  18. return ECAlgorithms.ValidatePoint(result);
  19. }
  20. protected abstract ECPoint MultiplyPositive(ECPoint p, BigInteger k);
  21. }
  22. }
  23. #endif