ddn.crypto.key.rsa

RSA Keys, Primitives, and Key Generator.

Side-Channel Resistance: This module provides RSA blinding

for private key operations to prevent timing side-channel attacks. Use rsaDpBlinded instead of rsaDp for security-critical applications.

Types 3

RSA Public Key.

Fields
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
Destructors

RSA Private Key.

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 n, BigInt d, BigInt p = 0, BigInt q = 0, BigInt dP = 0, BigInt dQ = 0, BigInt qInv = 0, BigInt e = 0)
Destructors
Fields
private Random _random
private int _bitLength
private BigInt _e
Methods
KeyPair generateKeyPair()Generates a new RSA key pair using the stored parameters.
size_t keySize() @property const @safe pure nothrow @nogcReturns: The key size in bits.
KeyPair generate(int bitLength, BigInt e = BigInt(65_537))Generates an RSA key pair with the given parameters.
private BigInt generatePrime(int bits, BigInt e)
private bool millerRabin(BigInt n, int k)
private BigInt gcd(BigInt a, BigInt b)
Constructors
this(Random random, int bitLength = 2_048, BigInt e = BigInt(65_537))Constructs an RSAKeyPairGenerator.

Functions 16

private fnvoid zeroBigInt(ref BigInt val) nothrow @nogc @trusted
private fnubyte[] bigIntToBytes(BigInt val)Converts a non-negative BigInt to minimal big-endian unsigned bytes.
fnubyte[] encodeRsaSpki(RSAPublicKey key)Encodes an RSA public key as a DER-encoded SubjectPublicKeyInfo (SPKI).
fnRSAPublicKey decodeRsaSpki(const(ubyte)[] der)Decodes an RSA public key from DER-encoded SubjectPublicKeyInfo (SPKI).
fnubyte[] encodeRsaPkcs1(RSAPrivateKey key)Encodes an RSA private key in PKCS#1 format.
fnRSAPrivateKey decodeRsaPkcs1(const(ubyte)[] der)Decodes an RSA private key from PKCS#1 format.
fnubyte[] encodeRsaPkcs8(RSAPrivateKey key)Encodes an RSA private key in PKCS#8 format (PrivateKeyInfo).
fnRSAPrivateKey decodeRsaPkcs8(const(ubyte)[] der)Decodes an RSA private key from PKCS#8 format (PrivateKeyInfo).
fnBigInt os2ip(const(ubyte)[] octets)
fnubyte[] i2osp(BigInt x, size_t xLen)
fnBigInt rsaDp(RSAPrivateKey key, BigInt c)RSA decryption primitive (RSADP) - unblinded version.
fnBigInt rsaDpBlinded(RSAPrivateKey key, BigInt c, Random random)RSA decryption primitive with blinding for side-channel resistance.
private fnBigInt generateBlindingFactor(BigInt n, Random random)Generates a random blinding factor for RSA.
fnvoid mgf1(Hash hash, const(ubyte)[] seed, size_t maskLen, ubyte[] mask)