ECNamedCurveTable.cs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. using System;
  3. using System.Collections;
  4. using Org.BouncyCastle.Asn1.Anssi;
  5. using Org.BouncyCastle.Asn1.Nist;
  6. using Org.BouncyCastle.Asn1.Sec;
  7. using Org.BouncyCastle.Asn1.TeleTrust;
  8. using Org.BouncyCastle.Utilities;
  9. using Org.BouncyCastle.Utilities.Collections;
  10. namespace Org.BouncyCastle.Asn1.X9
  11. {
  12. /**
  13. * A general class that reads all X9.62 style EC curve tables.
  14. */
  15. public class ECNamedCurveTable
  16. {
  17. /**
  18. * return a X9ECParameters object representing the passed in named
  19. * curve. The routine returns null if the curve is not present.
  20. *
  21. * @param name the name of the curve requested
  22. * @return an X9ECParameters object or null if the curve is not available.
  23. */
  24. public static X9ECParameters GetByName(string name)
  25. {
  26. X9ECParameters ecP = X962NamedCurves.GetByName(name);
  27. if (ecP == null)
  28. {
  29. ecP = SecNamedCurves.GetByName(name);
  30. }
  31. if (ecP == null)
  32. {
  33. ecP = NistNamedCurves.GetByName(name);
  34. }
  35. if (ecP == null)
  36. {
  37. ecP = TeleTrusTNamedCurves.GetByName(name);
  38. }
  39. if (ecP == null)
  40. {
  41. ecP = AnssiNamedCurves.GetByName(name);
  42. }
  43. return ecP;
  44. }
  45. public static string GetName(DerObjectIdentifier oid)
  46. {
  47. string name = X962NamedCurves.GetName(oid);
  48. if (name == null)
  49. {
  50. name = SecNamedCurves.GetName(oid);
  51. }
  52. if (name == null)
  53. {
  54. name = NistNamedCurves.GetName(oid);
  55. }
  56. if (name == null)
  57. {
  58. name = TeleTrusTNamedCurves.GetName(oid);
  59. }
  60. if (name == null)
  61. {
  62. name = AnssiNamedCurves.GetName(oid);
  63. }
  64. return name;
  65. }
  66. /**
  67. * return the object identifier signified by the passed in name. Null
  68. * if there is no object identifier associated with name.
  69. *
  70. * @return the object identifier associated with name, if present.
  71. */
  72. public static DerObjectIdentifier GetOid(string name)
  73. {
  74. DerObjectIdentifier oid = X962NamedCurves.GetOid(name);
  75. if (oid == null)
  76. {
  77. oid = SecNamedCurves.GetOid(name);
  78. }
  79. if (oid == null)
  80. {
  81. oid = NistNamedCurves.GetOid(name);
  82. }
  83. if (oid == null)
  84. {
  85. oid = TeleTrusTNamedCurves.GetOid(name);
  86. }
  87. if (oid == null)
  88. {
  89. oid = AnssiNamedCurves.GetOid(name);
  90. }
  91. return oid;
  92. }
  93. /**
  94. * return a X9ECParameters object representing the passed in named
  95. * curve.
  96. *
  97. * @param oid the object id of the curve requested
  98. * @return an X9ECParameters object or null if the curve is not available.
  99. */
  100. public static X9ECParameters GetByOid(DerObjectIdentifier oid)
  101. {
  102. X9ECParameters ecP = X962NamedCurves.GetByOid(oid);
  103. if (ecP == null)
  104. {
  105. ecP = SecNamedCurves.GetByOid(oid);
  106. }
  107. // NOTE: All the NIST curves are currently from SEC, so no point in redundant OID lookup
  108. if (ecP == null)
  109. {
  110. ecP = TeleTrusTNamedCurves.GetByOid(oid);
  111. }
  112. if (ecP == null)
  113. {
  114. ecP = AnssiNamedCurves.GetByOid(oid);
  115. }
  116. return ecP;
  117. }
  118. /**
  119. * return an enumeration of the names of the available curves.
  120. *
  121. * @return an enumeration of the names of the available curves.
  122. */
  123. public static IEnumerable Names
  124. {
  125. get
  126. {
  127. IList v = Org.BouncyCastle.Utilities.Platform.CreateArrayList();
  128. CollectionUtilities.AddRange(v, X962NamedCurves.Names);
  129. CollectionUtilities.AddRange(v, SecNamedCurves.Names);
  130. CollectionUtilities.AddRange(v, NistNamedCurves.Names);
  131. CollectionUtilities.AddRange(v, TeleTrusTNamedCurves.Names);
  132. CollectionUtilities.AddRange(v, AnssiNamedCurves.Names);
  133. return v;
  134. }
  135. }
  136. }
  137. }
  138. #endif