2using System.Globalization;
3using System.Reflection;
34 Client?.
Error(
"No ECDSA public key provided or found.");
56 System.Numerics.BigInteger Order =
PublicKey.Order;
57 System.Numerics.BigInteger Cofactor =
PublicKey.CoFactor;
58 System.Numerics.BigInteger A =
PublicKey.A;
59 System.Numerics.BigInteger B =
PublicKey.B;
65 Obj is not Vector SignatureVector ||
66 SignatureVector.Length != 2 ||
67 SignatureVector.FirstElement is not
System.Numerics.BigInteger R ||
68 SignatureVector[1] is not
System.Numerics.BigInteger S)
76 StringBuilder? Msg = HasSniffer ?
new StringBuilder() :
null;
80 Msg!.AppendLine(
"ECDSA signature verification parameters:");
81 Msg.Append(
"A (dec): ");
82 Msg.AppendLine(A.ToString(CultureInfo.InvariantCulture));
83 Msg.Append(
"B (dec): ");
84 Msg.AppendLine(B.ToString(CultureInfo.InvariantCulture));
85 Msg.Append(
"Order (dec): ");
86 Msg.AppendLine(Order.ToString(CultureInfo.InvariantCulture));
87 Msg.Append(
"Cofactor (dec): ");
88 Msg.AppendLine(Cofactor.ToString(CultureInfo.InvariantCulture));
89 Msg.Append(
"BasePoint.X (dec): ");
90 Msg.AppendLine(BasePoint.
X.ToString(CultureInfo.InvariantCulture));
91 Msg.Append(
"BasePoint.Y (dec): ");
92 Msg.AppendLine(BasePoint.
Y.ToString(CultureInfo.InvariantCulture));
93 Msg.Append(
"PublicKey.X (dec): ");
94 Msg.AppendLine(PublicKeyPoint.
X.ToString(CultureInfo.InvariantCulture));
95 Msg.Append(
"PublicKey.Y (dec): ");
96 Msg.AppendLine(PublicKeyPoint.
Y.ToString(CultureInfo.InvariantCulture));
97 Msg.Append(
"S (Signature, hex): ");
99 Msg.Append(
"R (dec): ");
100 Msg.AppendLine(R.ToString(CultureInfo.InvariantCulture));
101 Msg.Append(
"S (dec): ");
102 Msg.AppendLine(S.ToString(CultureInfo.InvariantCulture));
103 Msg.Append(
"Hash function: ");
105 Msg.Append(
"Message (hex): ");
120 Client.
Error(
"Named curve not supported by ECDSA: " +
PublicKey.NamedCurve.CurveName);
132 if (EC.
Order != Order ||
173 if (Selected is
null)
176 Msg!.AppendLine(
"Elliptic Curve not recognized. A custom Weierstras curve will be used.");
178 if (Cofactor < int.MinValue || Cofactor >
int.MaxValue)
183 Client.
Error(
"Unsupported cofactor.");
197 Msg!.Append(
"Elliptic Curve Hash algorithm not standard: ");
199 Msg.Append(
" (instead of ");
213 Client.
Error(
"Curve field type not supported: " +
PublicKey.Field.GetType().FullName);
223 Msg!.Append(
"Curve used for signature: ");
225 Msg.Append(
" (implemented by ");
226 Msg.Append(Selected.GetType().FullName);
230 if (!Selected.
IsPoint(PublicKeyPoint))
235 Client.
Error(
"Public key not a point on curve.");
246 Client.
Error(
"ECDSA validation failed.");
258 private static readonly
EllipticCurve[] curves = GetEllipticCurves();
274 EllipticCurves.
Add(Curve);
282 return [.. EllipticCurves];
Static class for parsing and decoding security objects encoded using Abstract Syntax Notation 1 (ASN....
static bool TryDecodeDer(byte[] Data, out object? Value)
Decodes a DER-encoded object.
static int ReportAlgorithmUse(string Name)
Records an Elliptic Curve has been used.
Abstract base class for field types.
BigInteger Prime
Prime number used to define the prime field.
Elliptic Curve Public Key
Abstract base class for public keys.
ECDSA Signature algorithm
override bool VerifySignature(byte[] Data, byte[] Signature, IPublicKey PublicKey, ICommunicationLayer? Client)
Verifies a digital signature.
abstract HashFunctionStream HashAlgorithmStream
Hash algorithm to use for streams of data.
abstract HashFunctionArray HashAlgorithm
Hash algorithm to use for in-memory blocks of data.
static bool VerifySignature(byte[] Data, byte[] Signature, EllipticCurvePublicKey PublicKey, HashFunctionArray HashAlgorithm, HashFunctionStream HashAlgorithmStream, ICommunicationLayer? Client)
Verifies a digital signature using the ECDSA algorithm.
Abstract base class for signature algorithms, as defined in RFC 5280.
override string ToString()
Static class managing the application event log. Applications and services log events on this static ...
static void Exception(Exception Exception, string Object, string Actor, string EventId, EventLevel Level, string Facility, string Module, params KeyValuePair< string, object >[] Tags)
Logs an exception. Event type will be determined by the severity of the exception.
A chunked list is a linked list of chunks of objects of type T .
void Add(T Item)
Adds an item to the collection.
Static class that dynamically manages types and interfaces available in the runtime environment.
static object[] NoParameters
Contains an empty array of parameter values.
static Type[] GetTypesImplementingInterface(string InterfaceFullName)
Gets all types implementing a given interface.
static ConstructorInfo GetDefaultConstructor(Type Type)
Gets the default constructor of a type, if one exists.
Custom Weierstrass curves (y²=x³+ax+b) over a prime field.
Implements the Elliptic Curve Digital Signature Algorithm (ECDSA).
static bool Verify(byte[] Data, byte[] PublicKey, bool BigEndian, HashFunctionArray HashFunction, PrimeFieldCurve Curve, byte[] Signature)
Verifies a signature of Data made by the ECDSA algorithm.
BigInteger D
d coefficient of Edwards curve.
Base class of Edwards curves (x²+y²=1+dx²y²) over a prime field.
Base class of Twisted Edwards curves (-x²+y²=1+dx²y²) over a prime field.
Abstract base class for elliptic curves.
abstract string CurveName
Name of curve.
BigInteger Order
Order of curve.
virtual bool IsPoint(byte[] Point)
Checks if an encoded point is on the curve.
int Cofactor
Cofactor of curve.
PointOnCurve BasePoint
Base-point of curve.
Base class of Montgomery curves (y²=x³+Ax²+x), with birational Edwards equivalent over a prime field.
BigInteger A
Coefficient a.
Base class of Elliptic curves over a prime field.
BigInteger Prime
Prime of curve.
virtual HashFunctionStream HashFunctionStream
Hash function to use in signatures for data streams.
virtual HashFunctionArray HashFunction
Hash function to use in signatures for binary blocks of data in memory.
Base class of Weierstrass curves (y²=x³+ax+b) over a prime field.
BigInteger A
Coefficient a.
BigInteger B
Coefficient b.
Contains methods for simple hash calculations.
static string BinaryToString(byte[] Data)
Converts an array of bytes to a string with their hexadecimal representations (in lower case).
Interface for public keys.
void Information(string Comment)
Called to inform the viewer of something.
void Error(string Error)
Called to inform the viewer of an error state.
Interface for observable classes implementing communication protocols.
bool HasSniffers
If there are sniffers registered on the object.
Interface for digital signature algorithms.
delegate byte[] HashFunctionStream(Stream Data)
Delegate to hash function.
delegate byte[] HashFunctionArray(byte[] Data)
Delegate to hash function.
Represents a point on a curve.