26 public override bool IsConfigured => this.curve is not
null;
33 public override bool Configure(Vector SecurityInfo)
35 if (!base.Configure(SecurityInfo))
38 if (!this.ParameterId.HasValue ||
39 this.ParameterId.Value <
int.MinValue ||
40 this.ParameterId.Value >
int.MaxValue)
45 switch ((
int)this.ParameterId.Value)
115 public override byte[] CreateNewKey(
byte[]? Seed, ref
int Index)
117 if (this.curve is
null)
118 throw new NotSupportedException(
"EEC Curve not configured.");
124 byte[] Secret = this.GenerateSecret(Seed, ref Index);
138 public byte[] GenerateSecret(
byte[]? Seed, ref
int Index)
145 System.Numerics.BigInteger D;
146 System.Numerics.BigInteger? Order;
155 B = H.
ComputeVariable(TravelDocumentsClient.CONCAT(Seed, BitConverter.GetBytes(Index++)));
156 B[this.curve.BigIntegerBytes - 1] &= this.curve.
MsbOrderMask;
160 while (D.IsZero || (Order.HasValue && D >= Order));
169 public override byte[] ImportKey(XmlDocument Xml)
171 if (this.curve is
null)
172 throw new NotSupportedException(
"EEC Curve not configured.");
174 if (Xml?.DocumentElement is
null)
175 throw new ArgumentNullException(nameof(Xml),
"Missing XML.");
177 if (Xml.DocumentElement.Name !=
"EllipticCurve" ||
178 Xml.DocumentElement.NamespaceURI !=
"http://waher.se/Schema/EllipticCurves.xsd")
180 throw new ArgumentException(
"Not an Elliptic Curve export XML document.", nameof(Xml));
183 if (
XML.
Attribute(Xml.DocumentElement,
"type") !=
this.curve.GetType().FullName)
184 throw new ArgumentException(
"Exported curve type does not match current curve.", nameof(Xml));
186 byte[] Secret = Convert.FromBase64String(
XML.
Attribute(Xml.DocumentElement,
"d"));
201 if (this.curve is not
null)
211 public void SetPrivateKey(
byte[] PrivateKey)
213 if (this.curve is
null)
214 throw new NotSupportedException(
"EEC Curve not configured.");
225 public override byte[] GetSharedSecret(
byte[] RemotePublicKey)
231 byte[] X = H.
X.ToByteArray();
232 byte[] Y = H.
Y.ToByteArray();
236 Array.Resize(ref X, c);
239 Array.Resize(ref Y, c);
244 byte[] Result =
new byte[c << 1];
246 Buffer.BlockCopy(X, 0, Result, 0, c);
247 Buffer.BlockCopy(Y, 0, Result, c, c);
259 public PointOnCurve GetGenericMap(
byte[] s,
byte[] RemotePublicKey)
264 byte[] s2 = (
byte[])s.Clone();
268 this.curve.
AddTo(ref Ĝ, H);
Helps with common XML-related tasks.
static string Attribute(XmlElement E, string Name)
Gets the value of an XML attribute.
Static class that dynamically manages types and interfaces available in the runtime environment.
static object Instantiate(Type Type, params object[] Arguments)
Returns an instance of the type Type . If one needs to be created, it is. If the constructor requires...
Brainpool P-192 Elliptic Curve, as defined in RFC5639: https://datatracker.ietf.org/doc/html/rfc5639
Brainpool P-224 Elliptic Curve, as defined in RFC5639: https://datatracker.ietf.org/doc/html/rfc5639
Brainpool P-256 Elliptic Curve, as defined in RFC5639: https://datatracker.ietf.org/doc/html/rfc5639
Brainpool P-320 Elliptic Curve, as defined in RFC5639: https://datatracker.ietf.org/doc/html/rfc5639
Brainpool P-384 Elliptic Curve, as defined in RFC5639: https://datatracker.ietf.org/doc/html/rfc5639
Brainpool P-512 Elliptic Curve, as defined in RFC5639: https://datatracker.ietf.org/doc/html/rfc5639
Abstract base class for elliptic curves.
abstract byte[] GenerateSecret()
Generates a new secret.
virtual byte[] PublicKeyBigEndian
Returns a big-endian representation of the public key.
BigInteger Order
Order of curve.
byte MsbOrderMask
Mask for most significant byte of scalars (as byte arrays of size BigIntegerBytes).
static BigInteger ToInt(byte[] Binary, bool BigEndian)
Converts a little-endian binary representation of a big integer to a BigInteger.
int OrderBytes
Number of bytes required to represent the order of the curve.
int BigIntegerBytes
Number of bytes required to represent coordinates using BigInteger of the curve. This number may diff...
void GenerateKeys()
Generates a new Private Key.
PointOnCurve GetSharedPoint(byte[] RemotePublicKey)
Gets a shared key, as a point, using the Elliptic Curve Diffie-Hellman (ECDH) algorithm.
PointOnCurve BasePoint
Base-point of curve.
virtual void SetPrivateKey(byte[] Secret)
Sets the private key (and therefore also the public key) of the curve.
abstract void AddTo(ref PointOnCurve P, PointOnCurve Q)
Adds Q to P .
PointOnCurve ScalarMultiplication(BigInteger N, PointOnCurve P, bool Normalize)
Performs the scalar multiplication of N *P .
NIST P-192 Elliptic Curve, as defined in NIST FIPS BUB 186-4: https://nvlpubs.nist....
NIST P-224 Elliptic Curve, as defined in NIST FIPS BUB 186-4: https://nvlpubs.nist....
NIST P-256 Elliptic Curve, as defined in NIST FIPS BUB 186-4: https://nvlpubs.nist....
NIST P-384 Elliptic Curve, as defined in NIST FIPS BUB 186-4: https://nvlpubs.nist....
NIST P-521 Elliptic Curve, as defined in NIST FIPS BUB 186-4: https://nvlpubs.nist....
Base class of Elliptic curves over a prime field.
byte[] ComputeVariable(byte[] N)
Computes the SPONGE function, as defined in section 4 of NIST FIPS 202.
Implements the SHA3 SHAKE256 extendable-output functions, as defined in section 6....
Basic interface for PACE protocols.
abstract class PaceEcdhProtocol()
Abstract base class for PACE protocols using Elliptic Curve Cryptography (EEC).
Represents a point on a curve.