Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
ECCurve.cs
Go to the documentation of this file.
3
5
6[DebuggerDisplay("ECCurve: {Oid}")]
7[UnsupportedOSPlatform("browser")]
8public struct ECCurve
9{
19
20 public static class NamedCurves
21 {
22 public static ECCurve brainpoolP160r1 => CreateFromFriendlyName("brainpoolP160r1");
23
24 public static ECCurve brainpoolP160t1 => CreateFromFriendlyName("brainpoolP160t1");
25
26 public static ECCurve brainpoolP192r1 => CreateFromFriendlyName("brainpoolP192r1");
27
28 public static ECCurve brainpoolP192t1 => CreateFromFriendlyName("brainpoolP192t1");
29
30 public static ECCurve brainpoolP224r1 => CreateFromFriendlyName("brainpoolP224r1");
31
32 public static ECCurve brainpoolP224t1 => CreateFromFriendlyName("brainpoolP224t1");
33
34 public static ECCurve brainpoolP256r1 => CreateFromFriendlyName("brainpoolP256r1");
35
36 public static ECCurve brainpoolP256t1 => CreateFromFriendlyName("brainpoolP256t1");
37
38 public static ECCurve brainpoolP320r1 => CreateFromFriendlyName("brainpoolP320r1");
39
40 public static ECCurve brainpoolP320t1 => CreateFromFriendlyName("brainpoolP320t1");
41
42 public static ECCurve brainpoolP384r1 => CreateFromFriendlyName("brainpoolP384r1");
43
44 public static ECCurve brainpoolP384t1 => CreateFromFriendlyName("brainpoolP384t1");
45
46 public static ECCurve brainpoolP512r1 => CreateFromFriendlyName("brainpoolP512r1");
47
48 public static ECCurve brainpoolP512t1 => CreateFromFriendlyName("brainpoolP512t1");
49
50 public static ECCurve nistP256 => CreateFromValueAndName("1.2.840.10045.3.1.7", "nistP256");
51
52 public static ECCurve nistP384 => CreateFromValueAndName("1.3.132.0.34", "nistP384");
53
54 public static ECCurve nistP521 => CreateFromValueAndName("1.3.132.0.35", "nistP521");
55 }
56
57 public byte[]? A;
58
59 public byte[]? B;
60
61 public ECPoint G;
62
63 public byte[]? Order;
64
65 public byte[]? Cofactor;
66
67 public byte[]? Seed;
68
70
72
73 public byte[]? Polynomial;
74
75 public byte[]? Prime;
76
77 private Oid _oid;
78
79 public Oid Oid
80 {
81 get
82 {
83 return _oid;
84 }
85 private set
86 {
87 if (value == null)
88 {
89 throw new ArgumentNullException("Oid");
90 }
91 if (string.IsNullOrEmpty(value.Value) && string.IsNullOrEmpty(value.FriendlyName))
92 {
94 }
95 _oid = value;
96 }
97 }
98
99 public bool IsPrime
100 {
101 get
102 {
103 if (CurveType != ECCurveType.PrimeShortWeierstrass && CurveType != ECCurveType.PrimeMontgomery)
104 {
105 return CurveType == ECCurveType.PrimeTwistedEdwards;
106 }
107 return true;
108 }
109 }
110
111 public bool IsCharacteristic2 => CurveType == ECCurveType.Characteristic2;
112
113 public bool IsExplicit
114 {
115 get
116 {
117 if (!IsPrime)
118 {
119 return IsCharacteristic2;
120 }
121 return true;
122 }
123 }
124
125 public bool IsNamed => CurveType == ECCurveType.Named;
126
127 public static ECCurve CreateFromOid(Oid curveOid)
128 {
129 ECCurve result = default(ECCurve);
130 result.CurveType = ECCurveType.Named;
131 result.Oid = curveOid;
132 return result;
133 }
134
135 public static ECCurve CreateFromFriendlyName(string oidFriendlyName)
136 {
137 if (oidFriendlyName == null)
138 {
139 throw new ArgumentNullException("oidFriendlyName");
140 }
141 return CreateFromValueAndName(null, oidFriendlyName);
142 }
143
144 public static ECCurve CreateFromValue(string oidValue)
145 {
146 if (oidValue == null)
147 {
148 throw new ArgumentNullException("oidValue");
149 }
150 return CreateFromValueAndName(oidValue, null);
151 }
152
153 private static ECCurve CreateFromValueAndName(string oidValue, string oidFriendlyName)
154 {
155 Oid oid = null;
156 if (oidValue == null && oidFriendlyName != null)
157 {
158 try
159 {
160 oid = System.Security.Cryptography.Oid.FromFriendlyName(oidFriendlyName, OidGroup.PublicKeyAlgorithm);
161 }
163 {
164 }
165 }
166 if (oid == null)
167 {
168 oid = new Oid(oidValue, oidFriendlyName);
169 }
170 return CreateFromOid(oid);
171 }
172
173 public void Validate()
174 {
175 if (IsNamed)
176 {
178 {
180 }
181 if (Oid == null || (string.IsNullOrEmpty(Oid.FriendlyName) && string.IsNullOrEmpty(Oid.Value)))
182 {
184 }
185 }
186 else if (IsExplicit)
187 {
188 bool flag = false;
189 if (A == null || B == null || B.Length != A.Length || G.X == null || G.X.Length != A.Length || G.Y == null || G.Y.Length != A.Length || Order == null || Order.Length == 0 || Cofactor == null || Cofactor.Length == 0)
190 {
191 flag = true;
192 }
193 if (IsPrime)
194 {
195 if (!flag && (Prime == null || Prime.Length != A.Length))
196 {
197 flag = true;
198 }
199 if (flag)
200 {
202 }
203 }
204 else if (IsCharacteristic2)
205 {
206 if (!flag && (Polynomial == null || Polynomial.Length == 0))
207 {
208 flag = true;
209 }
210 if (flag)
211 {
213 }
214 }
215 }
216 else if (HasAnyExplicitParameters() || Oid != null)
217 {
219 }
220 }
221
223 {
224 if (A == null && B == null && G.X == null && G.Y == null && Order == null && Cofactor == null && Prime == null && Polynomial == null && Seed == null)
225 {
226 return Hash.HasValue;
227 }
228 return true;
229 }
230}
static string Cryptography_CurveNotSupported
Definition SR.cs:64
static string Format(string resourceFormat, object p1)
Definition SR.cs:118
static string Cryptography_InvalidECPrimeCurve
Definition SR.cs:88
static string Cryptography_InvalidECCharacteristic2Curve
Definition SR.cs:86
static string Cryptography_InvalidECNamedCurve
Definition SR.cs:90
static string Cryptography_InvalidCurveOid
Definition SR.cs:66
Definition SR.cs:7
static Oid FromFriendlyName(string friendlyName, OidGroup group)
Definition Oid.cs:106
static ECCurve CreateFromValue(string oidValue)
Definition ECCurve.cs:144
static ECCurve CreateFromOid(Oid curveOid)
Definition ECCurve.cs:127
static ECCurve CreateFromValueAndName(string oidValue, string oidFriendlyName)
Definition ECCurve.cs:153
static ECCurve CreateFromFriendlyName(string oidFriendlyName)
Definition ECCurve.cs:135