SecP256R1Curve.cs 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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 SecP256R1Curve
  7. : AbstractFpCurve
  8. {
  9. public static readonly BigInteger q = new BigInteger(1,
  10. Hex.Decode("FFFFFFFF00000001000000000000000000000000FFFFFFFFFFFFFFFFFFFFFFFF"));
  11. private const int SecP256R1_DEFAULT_COORDS = COORD_JACOBIAN;
  12. protected readonly SecP256R1Point m_infinity;
  13. public SecP256R1Curve()
  14. : base(q)
  15. {
  16. this.m_infinity = new SecP256R1Point(this, null, null);
  17. this.m_a = FromBigInteger(new BigInteger(1,
  18. Hex.Decode("FFFFFFFF00000001000000000000000000000000FFFFFFFFFFFFFFFFFFFFFFFC")));
  19. this.m_b = FromBigInteger(new BigInteger(1,
  20. Hex.Decode("5AC635D8AA3A93E7B3EBBD55769886BC651D06B0CC53B0F63BCE3C3E27D2604B")));
  21. this.m_order = new BigInteger(1, Hex.Decode("FFFFFFFF00000000FFFFFFFFFFFFFFFFBCE6FAADA7179E84F3B9CAC2FC632551"));
  22. this.m_cofactor = BigInteger.One;
  23. this.m_coord = SecP256R1_DEFAULT_COORDS;
  24. }
  25. protected override ECCurve CloneCurve()
  26. {
  27. return new SecP256R1Curve();
  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 SecP256R1FieldElement(x);
  54. }
  55. protected internal override ECPoint CreateRawPoint(ECFieldElement x, ECFieldElement y, bool withCompression)
  56. {
  57. return new SecP256R1Point(this, x, y, withCompression);
  58. }
  59. protected internal override ECPoint CreateRawPoint(ECFieldElement x, ECFieldElement y, ECFieldElement[] zs, bool withCompression)
  60. {
  61. return new SecP256R1Point(this, x, y, zs, withCompression);
  62. }
  63. }
  64. }
  65. #endif