2using System.Globalization;
14 private static readonly BigInteger p0 = BigInteger.Pow(2, 255) - 19;
15 private static readonly BigInteger A0 = 486662;
16 private static readonly BigInteger A24 = (A0 - 2) / 4;
17 private static readonly BigInteger n0 = BigInteger.Pow(2, 252) + BigInteger.Parse(
"14def9dea2f79cd65812631a5cf5d3ed", NumberStyles.HexNumber);
18 private static readonly BigInteger BasePointU = 9;
19 private static readonly BigInteger BasePointV = BigInteger.Parse(
"14781619447589544791020593568409986887264606134616475288964881837755586237401");
20 private static readonly BigInteger SqrtMinus486664 =
ModulusP.
SqrtModP(-486664, p0);
27 : base(p0, new
PointOnCurve(BasePointU, BasePointV), n0, 8)
37 : base(p0, new
PointOnCurve(BasePointU, BasePointV), n0, 8, Secret)
49 protected override BigInteger
A => A0;
60 BigInteger Y = this.
modP.
Divide(UV.
X - BigInteger.One, UV.
X + BigInteger.One);
79 BigInteger U = this.
modP.
Divide(XY.
Y + BigInteger.One, BigInteger.One - XY.
Y);
111 if (Bin.Length != 32)
118 return new Tuple<byte[], byte[]>(Bin,
null);
133 if (!PublicKeyXY.
Y.Equals(PublicKeyXY2.
Y))
134 throw new InvalidOperationException(
"Unable to create pair curve.");
144 public override byte[]
Sign(
byte[] Data)
146 throw new NotSupportedException(
"Signatures not supported.");
155 public override byte[]
Sign(Stream Data)
157 throw new NotSupportedException(
"Signatures not supported.");
182 throw new NotSupportedException(
"Signatures not supported.");
196 throw new NotSupportedException(
"Signatures not supported.");
Curve25519, as defined in RFC 7748: https://tools.ietf.org/html/rfc7748
override BigInteger A
a Coefficient in the definition of the curve E: v²=u³+A*u²+u
override byte[] Sign(byte[] Data)
Creates a signature of Data using the XEdDSA algorithm.
override Tuple< byte[], byte[]> CalculatePrivateKey(byte[] Secret)
Calculates a private key from a secret.
override EdwardsCurveBase CreatePair()
Creates the Edwards Curve pair.
override PointOnCurve ToXY(PointOnCurve UV)
Converts a pair of (U,V) coordinates to a pair of (X,Y) coordinates in the birational Edwards curve.
Curve25519(byte[] Secret)
Curve25519, as defined in RFC 7748: https://tools.ietf.org/html/rfc7748
override string CurveName
Name of curve.
override byte[] Sign(Stream Data)
Creates a signature of Data using the XEdDSA algorithm.
override bool Verify(Stream Data, byte[] PublicKey, byte[] Signature)
Verifies a signature of Data made by the EdDSA algorithm.
override BigInteger ScalarMultiplication(byte[] N, BigInteger U)
Performs the scalar multiplication of N *U .
Curve25519()
Curve25519, as defined in RFC 7748: https://tools.ietf.org/html/rfc7748
override PointOnCurve ToUV(PointOnCurve XY)
Converts a pair of (X,Y) coordinates for the birational Edwards curve to a pair of (U,...
override bool Verify(byte[] Data, byte[] PublicKey, byte[] Signature)
Verifies a signature of Data made by the EdDSA algorithm.
Edwards25519 Elliptic Curve, as defined in RFC7748 and RFC8032: https://tools.ietf....
Base class of different types of Edwards curves over a prime field.
virtual byte[] PublicKey
Encoded public key
byte[] PrivateKey
Private key
virtual PointOnCurve PublicKeyPoint
Public key, as a point on the elliptic curve.
Integer arithmetic, modulus a prime.
BigInteger Multiply(BigInteger a, BigInteger b)
Multiplies two numbers, modulus p
static BigInteger SqrtModP(BigInteger N, BigInteger p)
Computes sqrt(N) mod p.
BigInteger Divide(BigInteger a, BigInteger b)
Divides two numbers, modulus p
Base class of Montgomery curves (y²=x³+Ax²+x), with biratinal Edwards equivalent over a prime field.
static BigInteger XFunction(byte[] N, BigInteger U, BigInteger A24, BigInteger p, int Bits)
Performs the scalar multiplication of N *U .
override PointOnCurve PublicKeyPoint
Public key.
readonly ModulusP modP
Arithmetic modulus p
readonly BigInteger p
Prime p
Contains methods for simple hash calculations.
static byte[] ComputeSHA256Hash(byte[] Data)
Computes the SHA-256 hash of a block of binary data.
Represents a point on a curve.