ddn.crypto.key.ecdsa

ECDSA Keys and Curve Parameters.

Types 5

Holds the domain parameters for a named elliptic curve.

Curve parameters are accessed via lazy-initialisation functions

curveP256, curveP384, and curveP521, each of

which returns a ref CurveParams. This avoids both DMD's unreliable static member initialisation and the module-level static this() construction-order problems that caused curve parameters to appear as zero when accessed from other modules' unittests.

Fields
BigInt pThe field prime modulus.
BigInt aThe Weierstrass coefficient a (always −3 for NIST P-curves).
BigInt bThe Weierstrass coefficient b.
BigInt gxThe base-point (generator) x-coordinate.
BigInt gyThe base-point (generator) y-coordinate.
BigInt nThe order of the base point.
Methods
bool isValid(BigInt x, BigInt y)Verifies that the point x, y lies on this curve.

Lightweight curve descriptor returned by getCurveDescriptor.

Holds the domain parameters for a named elliptic curve so that curve-agnostic code can look up the prime modulus p, coefficient a, base-point coordinates gx/gy, and order n by name rather than referring to a specific CurveParams instance.

Fields
string nameThe standard curve name (e.g. "P-256", "P-384", "P-521").
BigInt pThe field prime modulus.
BigInt aThe Weierstrass coefficient a (always −3 for NIST P-curves).
BigInt bThe Weierstrass coefficient b.
BigInt gxThe base-point (generator) x-coordinate.
BigInt gyThe base-point (generator) y-coordinate.
BigInt nThe order of the base point.
structPoint
Fields
bool infinity

ECDSA Public Key. Represents a point Q = d * G on the curve.

Fields
string curveName
Methods
string algorithm() @property const nothrow @safe @nogc pure
string format() @property const nothrow @safe @nogc pure
const(ubyte)[] encoded() @property const
size_t toHash() const
bool opEquals(const Key other) const
Constructors
this(BigInt x, BigInt y, string curveName = "P-256")
Destructors

ECDSA Private Key. Represents the secret multiplier d.

Fields
string curveName
Methods
string algorithm() @property const nothrow @safe @nogc pure
string format() @property const nothrow @safe @nogc pure
const(ubyte)[] encoded() @property const
size_t toHash() const
bool opEquals(const Key other) const
Constructors
this(BigInt d, string curveName = "P-256")
Destructors

Functions 14

private fnvoid zeroBigInt(ref BigInt val) nothrow @nogc @trusted
private fnubyte[] bigIntToBytes(BigInt val) @safeConverts a non-negative BigInt to minimal big-endian unsigned bytes.
private fnBigInt bytesToBigInt(const(ubyte)[] bytes) @safeConverts big-endian unsigned bytes to a BigInt.
fnstring curveNameToOid(string name) @safeMaps a curve name to its standard OID string.
fnstring oidToCurveName(string oid) @safeMaps an OID string to a standard curve name.
private fnsize_t curveFieldLength(string name) pure @safeReturns the byte length of the curve field element.
fnCurveParams curveP256() ref @trustedReturns the P-256 (secp256r1) curve parameters, initialising on first call. `p = 2^256 − 2^224 + 2^192 + 2^96 − 1`.
fnCurveParams curveP384() ref @trustedReturns the P-384 (secp384r1) curve parameters, initialising on first call. `p = 2^384 − 2^128 − 2^96 + 2^32 − 1`.
fnCurveParams curveP521() ref @trustedReturns the P-521 (secp521r1) curve parameters, initialising on first call. `p = 2^521 − 1` (Mersenne prime).
fnCurveDescriptor getCurveDescriptor(string name) @safeLooks up the domain parameters for a named elliptic curve.
fnubyte[] encodeEcdsaSpki(ECDSAPublicKey key)Encodes an ECDSA public key as a DER-encoded SubjectPublicKeyInfo (SPKI) per RFC 5480.
fnECDSAPublicKey decodeEcdsaSpki(const(ubyte)[] der)Decodes an ECDSA public key from DER-encoded SubjectPublicKeyInfo (SPKI).
fnubyte[] encodeEcdsaPrivateKey(ECDSAPrivateKey key, ECDSAPublicKey publicKey = null)Encodes an ECDSA private key in SEC 1 / RFC 5915 format.
fnECDSAPrivateKey decodeEcdsaPrivateKey(const(ubyte)[] der)Decodes an ECDSA private key from SEC 1 / RFC 5915 format.

Variables 6

private varCurveParams curveP256Cache_
private varbool curveP256Init_
private varCurveParams curveP384Cache_
private varbool curveP384Init_
private varCurveParams curveP521Cache_
private varbool curveP521Init_