ddn.bigint
BigInt Implementation for Cryptography.
This module provides a multiprecision integer implementation designed to replace std.bigint in cryptographic contexts. It focuses on control over memory and algorithmic correctness.
Types 2
structBigInt
Arbitrary precision integer. Stores data as an array of 64-bit words (limbs) in Little Endian order.
Fields
ulong[] limbsbool signMethods
BigInt opOpAssign(string op, T)(T exp) if (op == "^^" && isIntegral!T) ref pure @safePower assignment operator for BigInt ^^= integral exponent.BigInt opAssign(T)(T x) if (isIntegral!T) ref pure nothrow @safeAssignment operator from integral types.BigInt opBinary(string op, T)(T exp) if (op == "^^" && isIntegral!T) const pure @safePower operator for BigInt ^^ integral exponent.int opCmp(T)(const T y) if (isFloatingPoint!T) const nothrow @nogc @safeComparison with floating-point typesbool opEquals(T)(const T y) if (isFloatingPoint!T) const pure nothrow @nogc @safeEquality comparison with floating-point typesT getDigit(T = ulong)(size_t n) const pure nothrow @nogc @safeReturns the n-th digit (limb) of the BigInt magnitude.size_t ulongLength() @property const pure nothrow @nogc @safeReturns the number of 64-bit limbs (digits) in the BigInt.size_t uintLength() @property const pure nothrow @nogc @safeReturns the number of 32-bit limbs (digits) in the BigInt.BigInt opUnary(string op)() if (op == "+" || op == "-" || op == "~") const pure @safeImplements unary operators +, -, ~ for BigInt.BigInt opUnary(string op)() if (op == "++" || op == "--") ref pure @safeImplements pre-increment (++) and pre-decrement (--) operators for BigInt.T opCast(T)() if (isIntegral!T) const pure @safeCasts BigInt to integral types (int, long, ulong, etc.).T opCast(T)() if (isFloatingPoint!T) const @safe nothrow @nogcCasts BigInt to floating-point types (float, double, real).BigInt opBinaryRight(string op, T)(T y) if ((op == "+" || op == "*" || op == "|" || op == "&" || op == "^") && isIntegral!T) const pure @safeImplements right-hand commutative operators (+, *, |, &, ^).BigInt opBinaryRight(string op, T)(T y) if (op == "-" && isIntegral!T) const pure @safeImplements right-hand subtraction operator.T opBinaryRight(string op, T)(T y) if ((op == "/" || op == "%") && isIntegral!T) const pure @safeImplements right-hand division and modulus operators.private
ulong[] addLimbs(const(ulong)[] a, const(ulong)[] b, ulong[] res) pure nothrow @nogc @trustedprivate
BigInt bitwiseOr(ref const BigInt a, ref const BigInt b) pure @safePerforms bitwise OR operation on two BigInt values.private
BigInt bitwiseAnd(ref const BigInt a, ref const BigInt b) pure @safePerforms bitwise AND operation on two BigInt values.private
BigInt bitwiseXor(ref const BigInt a, ref const BigInt b) pure @safePerforms bitwise XOR operation on two BigInt values.private
BigInt pow(ref const BigInt base, ulong exp) pure @safeRaises a BigInt to an integral power using exponentiation by squaring.private
void mulLimbs(const(ulong)[] a, const(ulong)[] b, ulong[] res, ulong[] scratch = null) pure @safeprivate
void mulSchoolbook(const(ulong)[] a, const(ulong)[] b, ulong[] res) pure nothrow @nogc @safeprivate
void mulKaratsuba(const(ulong)[] a, const(ulong)[] b, ulong[] res, ulong[] scratch) pure @safeprivate
void redc(ulong[] T, const(ulong)[] mod, ulong modPrime, ulong[] res) pure nothrow @nogc @trustedMontgomery Reduction: res = T * R^-1 mod N.private
ulong mulSub(ulong[] dst, const(ulong)[] src, ulong mul, out bool extraBorrow) pure nothrow @nogc @trustedprivate
void shiftLeftLimbs(const(ulong)[] src, ulong[] dest, size_t shift) pure nothrow @nogc @safeprivate
void shiftRightLimbs(const(ulong)[] src, ulong[] dest, size_t shift) pure nothrow @nogc @safevoid toString(Writer)(scope ref Writer sink, scope const ref FormatSpec!char f) constConverts BigInt to string with format specifier.void toString(Writer)(scope ref Writer sink, string formatString) constConverts BigInt to string with format string.Nested Templates
DivResultaliaspowmod = powMod
Alias for compatibility with std.bigint (lowercase version)
Functions 15
fn
string toDecimalString(const BigInt x) pure @safeConverts a BigInt to its decimal string representation.fn
string toHex(const BigInt x) pure @safeConverts a BigInt to its hexadecimal string representation with underscores.fn
void divMod(const BigInt dividend, const BigInt divisor,
out BigInt quotient, out BigInt remainder) pure @safePerforms division with remainder on two BigInt values.fn
BigInt powMod(BigInt base, BigInt exp, BigInt mod)Computes modular exponentiation: base^exp mod mod.fn
auto absUnsign(T)(T x) if (isIntegral!T)Returns the absolute value of an integral type as an unsigned type.fn
BigInt powModOdd(BigInt base, BigInt exp, BigInt mod)Computes modular exponentiation for odd modulus using sliding window binary exponentiation with regular modular reduction.private fn
void redcDispatch(ulong[] T, const(ulong)[] mod, ulong nPrime, const(ulong)[] nPrimeBig, ulong[] res, ulong[] scratch) pure @safeprivate fn
void blockRedc(ulong[] T, const(ulong)[] mod, const(ulong)[] nPrimeBig, ulong[] res, ulong[] scratch) pure @safeprivate fn
ulong addLimbsWithCarry(const(ulong)[] a, const(ulong)[] b, ulong[] res, ulong carryIn) pure nothrow @nogc @safefn
BigInt powMod2k(BigInt base, BigInt exp, size_t k) pure @safeComputes modular exponentiation modulo a power of 2: base^exp mod 2^k.fn
BigInt invModPowerOf2(BigInt n, size_t k) pure @safeComputes the modular inverse of n modulo a power of 2: n^-1 mod 2^k.