2using System.Security.Cryptography;
12 private readonly BigInteger p58;
13 private readonly BigInteger twoP14;
42 this.p58 = (this.p - 5) / 8;
43 this.twoP14 = BigInteger.ModPow(
Two, (this.
p - 1) / 4, this.
p);
66 BigInteger G = this.
modP.
Add(D, C);
67 BigInteger H = this.
modP.
Add(B, A);
84 BigInteger A = P.Y - P.X;
87 BigInteger B = P.Y + P.X;
94 BigInteger G = this.
modP.
Add(D, C);
95 BigInteger H = this.
modP.
Add(B, A);
110 public override BigInteger
GetX(BigInteger Y,
bool X0)
113 BigInteger u = y2 - BigInteger.One;
117 BigInteger v = this.
modP.
Multiply(this.
d, y2) + BigInteger.One;
123 BigInteger.ModPow(
this.modP.Multiply(u, v7),
this.p58,
this.Prime));
132 if (Test == this.
Prime - u)
135 throw new ArgumentException(
"Not a valid point.", nameof(Y));
141 throw new ArgumentException(
"Not a valid point.", nameof(Y));
Base class of different types of Edwards curves over a prime field.
BigInteger d
Edwards curve coefficient
BigInteger d2
Edwards curve coefficient * 2 mod p
Base class of Twisted Edwards curves (-x²+y²=1+dx²y²) over a prime field.
override void AddTo(ref PointOnCurve P, PointOnCurve Q)
Adds Q to P .
EdwardsTwistedCurve(BigInteger Prime, PointOnCurve BasePoint, BigInteger d, BigInteger Order, int Cofactor, byte[] Secret)
Base class of Twisted Edwards curves (-x²+y²=1+dx²y²) over a prime field.
override BigInteger GetX(BigInteger Y, bool X0)
Gets the X-coordinate that corresponds to a given Y-coordainte, and the first bit of the X-coordinate...
override void Double(ref PointOnCurve P)
Doubles a point on the curve.
EdwardsTwistedCurve(BigInteger Prime, PointOnCurve BasePoint, BigInteger d, BigInteger Order, int Cofactor)
Base class of Twisted Edwards curves (-x²+y²=1+dx²y²) over a prime field.
BigInteger Order
Order of curve.
int Cofactor
Cofactor of curve.
static readonly BigInteger Two
2
PointOnCurve BasePoint
Base-point of curve.
BigInteger Multiply(BigInteger a, BigInteger b)
Multiplies two numbers, modulus p
BigInteger Add(BigInteger a, BigInteger b)
Adds two numbers, modulus p
BigInteger Subtract(BigInteger a, BigInteger b)
Subtracts two numbers, modulus p
readonly ModulusP modP
Arithmetic modulus p
BigInteger Prime
Prime of curve.
readonly BigInteger p
Prime p
Represents a point on a curve.
bool IsHomogeneous
If the point is in homogeneous coordinates.