SecP160R1Curve.cs 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. using System;
  3. using Org.BouncyCastle.Utilities.Encoders;
  4. namespace Org.BouncyCastle.Math.EC.Custom.Sec
  5. {
  6. internal class SecP160R1Curve
  7. : AbstractFpCurve
  8. {
  9. public static readonly BigInteger q = new BigInteger(1,
  10. Hex.Decode("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF7FFFFFFF"));
  11. private const int SecP160R1_DEFAULT_COORDS = COORD_JACOBIAN;
  12. protected readonly SecP160R1Point m_infinity;
  13. public SecP160R1Curve()
  14. : base(q)
  15. {
  16. this.m_infinity = new SecP160R1Point(this, null, null);
  17. this.m_a = FromBigInteger(new BigInteger(1,
  18. Hex.Decode("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF7FFFFFFC")));
  19. this.m_b = FromBigInteger(new BigInteger(1,
  20. Hex.Decode("1C97BEFC54BD7A8B65ACF89F81D4D4ADC565FA45")));
  21. this.m_order = new BigInteger(1, Hex.Decode("0100000000000000000001F4C8F927AED3CA752257"));
  22. this.m_cofactor = BigInteger.One;
  23. this.m_coord = SecP160R1_DEFAULT_COORDS;
  24. }
  25. protected override ECCurve CloneCurve()
  26. {
  27. return new SecP160R1Curve();
  28. }
  29. public override bool SupportsCoordinateSystem(int coord)
  30. {
  31. switch (coord)
  32. {
  33. case COORD_JACOBIAN:
  34. return true;
  35. default:
  36. return false;
  37. }
  38. }
  39. public virtual BigInteger Q
  40. {
  41. get { return q; }
  42. }
  43. public override ECPoint Infinity
  44. {
  45. get { return m_infinity; }
  46. }
  47. public override int FieldSize
  48. {
  49. get { return q.BitLength; }
  50. }
  51. public override ECFieldElement FromBigInteger(BigInteger x)
  52. {
  53. return new SecP160R1FieldElement(x);
  54. }
  55. protected internal override ECPoint CreateRawPoint(ECFieldElement x, ECFieldElement y, bool withCompression)
  56. {
  57. return new SecP160R1Point(this, x, y, withCompression);
  58. }
  59. protected internal override ECPoint CreateRawPoint(ECFieldElement x, ECFieldElement y, ECFieldElement[] zs, bool withCompression)
  60. {
  61. return new SecP160R1Point(this, x, y, zs, withCompression);
  62. }
  63. }
  64. }
  65. #endif