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.bool opEquals(T)(const T y) if (isFloatingPoint!T) const pure @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.void 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 10
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.fn
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.