NamedCurve.cs 2.7 KB

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