ECNamedCurveTable.cs 5.8 KB

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