Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
PointOnCurve.cs
1using System;
2using System.Text;
3using System.Numerics;
4
6{
10 public struct PointOnCurve
11 {
12 private BigInteger x;
13 private BigInteger y;
14 private BigInteger z;
15 private BigInteger t;
16 private bool nonzero;
17 private bool homogeneous;
18
24 {
25 this.x = P.x;
26 this.y = P.y;
27 this.z = P.z;
28 this.t = P.t;
29 this.nonzero = P.nonzero;
30 this.homogeneous = P.homogeneous;
31 }
32
38 public PointOnCurve(BigInteger X, BigInteger Y)
39 {
40 this.x = X;
41 this.y = Y;
42 this.z = BigInteger.One;
43 this.t = BigInteger.Zero;
44 this.nonzero = !X.IsZero || !Y.IsZero;
45 this.homogeneous = false;
46 }
47
54 public PointOnCurve(BigInteger X, BigInteger Y, BigInteger Z)
55 {
56 this.x = X;
57 this.y = Y;
58 this.z = Z;
59 this.t = BigInteger.Zero;
60 this.nonzero = !X.IsZero || !Y.IsZero;
61 this.homogeneous = true;
62 }
63
71 public PointOnCurve(BigInteger X, BigInteger Y, BigInteger Z, BigInteger T)
72 {
73 this.x = X;
74 this.y = Y;
75 this.z = Z;
76 this.t = T;
77 this.nonzero = !X.IsZero || !Y.IsZero;
78 this.homogeneous = true;
79 }
80
84 public BigInteger X
85 {
86 get => this.x;
87 internal set => this.x = value;
88 }
89
93 public BigInteger Y
94 {
95 get => this.y;
96 internal set => this.y = value;
97 }
98
102 public BigInteger Z
103 {
104 get => this.z;
105 internal set
106 {
107 this.z = value;
108 this.homogeneous = true;
109 }
110 }
111
115 public BigInteger T
116 {
117 get => this.t;
118 internal set
119 {
120 this.t = value;
121 this.homogeneous = true;
122 }
123 }
124
128 public bool NonZero
129 {
130 get => this.nonzero;
131 internal set => this.nonzero = value;
132 }
133
137 public bool IsHomogeneous
138 {
139 get => this.homogeneous;
140 internal set => this.homogeneous = value;
141 }
142
146 public bool IsXZero => this.x.IsZero;
147
151 public bool IsYZero => this.y.IsZero;
152
154 public override string ToString()
155 {
156 StringBuilder sb = new StringBuilder();
157
158 sb.Append('(');
159 sb.Append(this.x.ToString());
160 sb.Append(',');
161 sb.Append(this.y.ToString());
162
163 if (this.homogeneous)
164 {
165 sb.Append(',');
166 sb.Append(this.z.ToString());
167 sb.Append(',');
168 sb.Append(this.t.ToString());
169 }
170
171 sb.Append(')');
172
173 return sb.ToString();
174 }
175
177 public override bool Equals(object obj)
178 {
179 return obj is PointOnCurve P &&
180 this.x.Equals(P.x) &&
181 this.y.Equals(P.y) &&
182 this.z.Equals(P.z) &&
183 this.t.Equals(P.t) &&
184 this.nonzero.Equals(P.nonzero) &&
185 this.homogeneous.Equals(P.homogeneous);
186 }
187
189 public override int GetHashCode()
190 {
191 return
192 this.x.GetHashCode() ^
193 this.y.GetHashCode() ^
194 this.z.GetHashCode() ^
195 this.t.GetHashCode() ^
196 this.nonzero.GetHashCode() ^
197 this.homogeneous.GetHashCode();
198 }
199
204 public void CopyFrom(PointOnCurve C)
205 {
206 this.x = C.x;
207 this.y = C.y;
208 this.z = C.z;
209 this.t = C.t;
210 this.nonzero = C.nonzero;
211 this.homogeneous = C.homogeneous;
212 }
213
218 public void Normalize(PrimeFieldCurve Curve)
219 {
220 if (this.homogeneous)
221 {
222 this.x = Curve.ModulusP.Divide(this.x, this.z);
223 this.y = Curve.ModulusP.Divide(this.y, this.z);
224 this.z = BigInteger.One;
225 this.t = BigInteger.Zero;
226 this.homogeneous = false;
227 }
228
229 if (this.x.Sign < 0)
230 this.x += Curve.Prime;
231
232 if (this.y.Sign < 0)
233 this.y += Curve.Prime;
234 }
235 }
236}
BigInteger Divide(BigInteger a, BigInteger b)
Divides two numbers, modulus p
Definition: ModulusP.cs:91
Base class of Elliptic curves over a prime field.
ModulusP ModulusP
Arithmetic modulus p (the prime)
Represents a point on a curve.
Definition: PointOnCurve.cs:11
void Normalize(PrimeFieldCurve Curve)
Normalizes a point, if in homogeneous coorinates.
PointOnCurve(BigInteger X, BigInteger Y)
Represents a point on a curve.
Definition: PointOnCurve.cs:38
PointOnCurve(PointOnCurve P)
Represents a point on a curve.
Definition: PointOnCurve.cs:23
bool IsYZero
If the Y-coordinate is zero.
void CopyFrom(PointOnCurve C)
Copies the value from point C .
PointOnCurve(BigInteger X, BigInteger Y, BigInteger Z, BigInteger T)
Represents a point on a curve.
Definition: PointOnCurve.cs:71
bool IsXZero
If the X-coordinate is zero.
PointOnCurve(BigInteger X, BigInteger Y, BigInteger Z)
Represents a point on a curve.
Definition: PointOnCurve.cs:54
bool IsHomogeneous
If the point is in homogeneous coordinates.
bool NonZero
If the point is not zero (infinity).