NamedCurve.cs 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. #pragma warning disable
  3. using System;
  4. using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Sec;
  5. using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.X9;
  6. using BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto.Parameters;
  7. namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto.Tls
  8. {
  9. /// <summary>
  10. /// RFC 4492 5.1.1
  11. /// The named curves defined here are those specified in SEC 2 [13]. Note that many of
  12. /// these curves are also recommended in ANSI X9.62 [7] and FIPS 186-2 [11]. Values 0xFE00
  13. /// through 0xFEFF are reserved for private use. Values 0xFF01 and 0xFF02 indicate that the
  14. /// client supports arbitrary prime and characteristic-2 curves, respectively (the curve
  15. /// parameters must be encoded explicitly in ECParameters).
  16. /// </summary>
  17. public abstract class NamedCurve
  18. {
  19. public const int sect163k1 = 1;
  20. public const int sect163r1 = 2;
  21. public const int sect163r2 = 3;
  22. public const int sect193r1 = 4;
  23. public const int sect193r2 = 5;
  24. public const int sect233k1 = 6;
  25. public const int sect233r1 = 7;
  26. public const int sect239k1 = 8;
  27. public const int sect283k1 = 9;
  28. public const int sect283r1 = 10;
  29. public const int sect409k1 = 11;
  30. public const int sect409r1 = 12;
  31. public const int sect571k1 = 13;
  32. public const int sect571r1 = 14;
  33. public const int secp160k1 = 15;
  34. public const int secp160r1 = 16;
  35. public const int secp160r2 = 17;
  36. public const int secp192k1 = 18;
  37. public const int secp192r1 = 19;
  38. public const int secp224k1 = 20;
  39. public const int secp224r1 = 21;
  40. public const int secp256k1 = 22;
  41. public const int secp256r1 = 23;
  42. public const int secp384r1 = 24;
  43. public const int secp521r1 = 25;
  44. /*
  45. * RFC 7027
  46. */
  47. public const int brainpoolP256r1 = 26;
  48. public const int brainpoolP384r1 = 27;
  49. public const int brainpoolP512r1 = 28;
  50. /*
  51. * reserved (0xFE00..0xFEFF)
  52. */
  53. public const int arbitrary_explicit_prime_curves = 0xFF01;
  54. public const int arbitrary_explicit_char2_curves = 0xFF02;
  55. public static bool IsValid(int namedCurve)
  56. {
  57. return (namedCurve >= sect163k1 && namedCurve <= brainpoolP512r1)
  58. || (namedCurve >= arbitrary_explicit_prime_curves && namedCurve <= arbitrary_explicit_char2_curves);
  59. }
  60. public static bool RefersToASpecificNamedCurve(int namedCurve)
  61. {
  62. switch (namedCurve)
  63. {
  64. case arbitrary_explicit_prime_curves:
  65. case arbitrary_explicit_char2_curves:
  66. return false;
  67. default:
  68. return true;
  69. }
  70. }
  71. }
  72. }
  73. #pragma warning restore
  74. #endif