Contents · Forum Home · StreamSec Tools 4.1.5.363 documentation

StreamSec.DSI.ArithTypes

Classes, interfaces and records

classeDSIError

inherits from Exception

Root of the DSI exception hierarchy. Every unit in the StreamSec.DSI.* layer raises a descendant of this class, so an application can catch the whole layer with a single handler:

try ... except on E: eDSIError do ... end;

It is declared here, in the deepest DSI unit, so that every other DSI unit reaches it without a new dependency. The stand-alone primitives that do not use the arithmetic layer (StreamSec.DSI.Argon2, StreamSec.DSI.Blake2) keep their own Exception descendants.

(no public members)

interfaceiGroup

(no public members)

interfaceiDSInteger

(no public members)

interfaceiGroupElement

inherits from IUnknown

function GetInstance: Pointer;
Raw pointer to the underlying fixed-size record (an EC point, an FFC/DH element, or an iDSInteger's limb array). Internal wiring used when marshalling the value into/out of an untyped buffer (see CloneToGlobal/CloneToLocal/GetAsLocal); application code normally works through the typed interface methods instead of this pointer.
function GetSize: UInt32;
Size, in 32-bit words, of the element's backing storage. Used by callers (e.g. key generators, signature code) to size scratch buffers before a Clone/CloneToGlobal/ CloneToLocal call; see the Size property below for the published form.
function Compare(const aSource: iGroupElement): Boolean;
Value equality check (not identity/reference equality) between two group elements (integers, EC points, or FFC/DH elements). Used wherever protocol code needs to compare a computed value against an expected one, e.g. verifying a recomputed signature value or a resumed public key.
function Clone: iGroupElement;
Duplicates Self into a new group-element instance from the current memory pool. Used when an algorithm needs an independent copy it can mutate (via the Into methods on iDSInteger) without disturbing the original value.
procedure CloneToGlobal(out aObj; aSize: UInt32 = 0);
Copies Self's raw representation into aObj, allocating aObj from the process-wide (cross-thread) memory pool. Used by low-level key/parameter storage code that must outlive the allocating thread; most application code should prefer Clone/CloneToLocal.
procedure CloneToLocal(out aObj; aSize: UInt32 = 0);
Copies Self's raw representation into aObj, allocating aObj from the calling thread's local (per-thread cached) memory pool -- cheaper than CloneToGlobal but the result must not be handed to another thread. Used for short-lived scratch values inside a single signing/key-agreement operation.
procedure GetAsLocal(out aObj);
Returns aObj as a local (per-thread) iDSInteger view of Self WITHOUT copying the magnitude data: if Self is already local it simply aliases Self, otherwise it allocates a lightweight local stub header that points back at Self (Self is AddRef'd to keep it alive). Full description »
function GroupOpIteration(const aIterationCount: iDSInteger; const aGroup : iGroup; var aResult) : Boolean;
Computes the repeated group operation Self^aIterationCount treating Self as the generator -- i.e. scalar multiplication (k*G) for elliptic-curve groups or modular exponentiation (g^k mod p) for finite-field (DH/DSA-style) groups. Full description »
function FixedGroupOpIteration(const aIterationCount: iDSInteger; const aGroup : iGroup; var aResult) : Boolean;
Fixed-time counterpart of GroupOpIteration (Self = generator): computes the same Self^aIterationCount (k*G for EC, g^k mod p for FFC), but with timing independent of the secret aIterationCount (constant-time ladder + blinding for EC; the already-fixed-time ExpModTo for FFC). Full description »
procedure GroupOperation(const aFactor: iGroupElement; const aGroup : iGroup; var aDest);
Combines Self with aFactor under the group's operation (EC point addition, or modular multiplication for FFC groups) into aDest. Lower-level building block used inside key-agreement and signature verification code (e.g. combining two partial results); rarely called directly by application code.
function GroupElementToInteger(const aGroup : iGroup; var aResult : iDSInteger) : Boolean;
Converts a group element (an EC point or FFC element) to its plain iDSInteger representation under aGroup -- e.g. extracting the x-coordinate of an EC point for use as an ECDSA/ECDH shared value. Internal wiring inside the signature and key-agreement engines; not normally called from application code directly.
property Size: UInt32 read GetSize;
Size, in 32-bit words, of the element's backing storage; the published form of GetSize, used the same way (sizing buffers before Clone/CloneToGlobal/CloneToLocal).

interfaceiDSIntegerConv

inherits from IUnknown

function ToBase16: AnsiString; function ToBase256: tBytes; overload; function ToBase256(aFixedOutputLen: UInt32): tBytes; overload; procedure ToBase256(var aBuf; aCount: UInt32); overload; procedure UToBase256(var aBuf; aCount: UInt32); function ToBaseB(aBase: UInt32; const aDigits: OctetString): OctetString; function ToBase10: AnsiString; function UToBase256LE(aFixedOutputLen: UInt32): tBytes;

interfaceiDSIPool

(no public members)

interfaceiDSInteger

inherits from iGroupElement

All Into methods are undefined if Result.MSB > (Self.Size+2)*32. All To methods return a new global instance if aLocal = False, otherwise a new local instance is returned. In principle, all Mod methods return a result in the interval 0..aModulus-1, but AddModSub and SubModAdd return results in this interval only if both Self and aTerm are in the same interval.

function GetDSIPool: iDSIPool;
Returns the memory pool (iDSIPool) that produced this integer, so a caller can allocate further iDSInteger values (via FromInt32/FromBase256/etc.) that are compatible with Self without having to already hold a separate reference to the pool. Rarely needed directly by application code, which usually already has the pool from wherever it obtained the first iDSInteger.
function AsIntegerConv: iDSIntegerConv;
Returns Self viewed through the iDSIntegerConv interface, which adds the encode-to-external-format methods (ToBase16/ToBase256/ToBase10/etc.). Used whenever code needs to serialize a big-integer value, e.g. writing an RSA/DSA/ DH key component or a signature value out to DER/PEM or wire format.
function GetSign: Int32;
Getter for Sign (see the Sign property below).
procedure SetSign(aValue: Int32);
Setter for Sign (see the Sign property below); used when constructing or adjusting a value's sign in place rather than via an arithmetic method.
function GetData(aIndex: Int32): UInt32;
Getter for a single 32-bit limb of the integer's magnitude at aIndex (see the Data property below).
procedure SetData(aIndex: Int32; aValue: UInt32);
Setter for a single 32-bit limb of the integer's magnitude at aIndex (see the Data property below); low-level, used when an algorithm builds up a value limb by limb rather than through the arithmetic methods.
function IsZero: Boolean;
True when Self is numerically zero (equality test against 0); the standard way to test for zero across all users of this bignum type (RSA/DSA/DH/EC key material, signatures, KDF outputs), in place of ad hoc comparisons.
function IsOne: Boolean;
True if Self equals one; used the same way as IsZero, e.g. to detect a degenerate GCD/InvMod result during key validation.
function IsOdd: Boolean;
True if Self is odd; used by algorithms that branch on parity, e.g. binary GCD/ modular-inverse implementations and prime-candidate sieving before Miller-Rabin.
function MSB: UInt32;
Position (in bits) of the most significant set bit, i.e. Self's bit length. Used throughout key generation and encoding to size buffers and to pick algorithm parameters (e.g. RSA/DSA/DH modulus size, EC scalar size).
function LegendreSymbol(const aPrime: iDSInteger): Int32;
Legendre symbol of Self modulo aPrime (aPrime must be an odd prime); used by the fixed/variable modular-square-root code (SqrtModPrimeInto/To) and quadratic- residue tests during EC point decompression and DSA/DH parameter validation.
function JacobiSymbol(const aModulus: iDSInteger): Int32;
Jacobi symbol of Self modulo aModulus (aModulus may be composite, odd); a generalisation of LegendreSymbol used by some primality tests and parameter validation code that needs a quadratic-residue-like test without requiring a prime modulus.
function IsPerfectSquare: Boolean;
True if Self is a perfect square; used by parameter-generation/validation code (e.g. rejecting degenerate DSA/DH parameters), not a general-purpose utility most application code needs directly.
function TrialDiv(aT: Int32): Boolean;
Trial division by small values up to aT; a cheap pre-filter used by the prime generators (see iPrimeGenerator/iStandardPrimeGenerator) before running the more expensive Miller-Rabin/Lucas tests, e.g. when generating fresh RSA/DSA/DH primes for a new key pair.
function FastMillerRabinTest(aT: UInt32): Boolean;
Faster, table-driven Miller-Rabin primality test variant with aT rounds; used by the prime generators during RSA/DSA/DH key-pair generation. Not a proof of primality by itself -- callers typically combine it with LucasTest for a Baillie-PSW-style compound test.
function MillerRabinTest(aT: UInt32): Boolean;
Standard Miller-Rabin primality test with aT rounds; used the same way as FastMillerRabinTest during prime generation for RSA/DSA/DH keys.
function LucasTest: Boolean;
Lucas probable-prime test; combined with Miller-Rabin by the prime generators to reduce the false-positive rate when generating RSA/DSA/DH primes.
function CmpOffset(const aValue: iDSInteger; aOffset: UInt32 = 0): Int32;
Signed comparison of Self to aValue, with aValue conceptually shifted left by aOffset limbs first; a general-purpose ordering primitive used by higher-level range/validation checks (e.g. verifying a parsed key component is within bounds).
function AbsCmpOffset(const aValue: iDSInteger; aOffset: UInt32 = 0): Int32;
Unsigned (magnitude-only) comparison of Self to aValue, with aValue shifted left by aOffset limbs first; used the same way as CmpOffset where sign should be ignored.
function NegInto: iDSInteger;
Self := Result := -Self. This "Into" form mutates Self in place and returns Self; it is the cheaper choice when the old value of Self is no longer needed. Basic bignum building block used throughout RSA/DSA/DH/EC key generation and signing on both client and server sides; application code normally reaches these via the higher-level key/signature units rather than calling them directly.
function NegTo(aLocal: Boolean = False): iDSInteger;
Result := -Self, Self unchanged. This "To" form allocates a new instance instead of mutating Self -- pass aLocal = True for a cheaper per-thread scratch value (see CloneToLocal), or leave False for a value that must outlive this thread.
function AddInt32Into(aTerm: Int32): iDSInteger;
Self := Result := Self + aTerm; in-place add of a native Int32 term.
function AddInt32To(aTerm: Int32; aLocal: Boolean = False): iDSInteger;
Result := Self + aTerm, Self unchanged; allocating add of a native Int32 term.
function AddInt64Into(aTerm: Int64): iDSInteger;
Self := Result := Self + aTerm; in-place add of a native Int64 term.
function AddInt64To(aTerm: Int64; aLocal: Boolean = False): iDSInteger;
Result := Self + aTerm, Self unchanged; allocating add of a native Int64 term.
function AddUInt32Into(aTerm: UInt32): iDSInteger;
Self := Result := Self + aTerm; in-place add of a native UInt32 term.
function AddUInt32To(aTerm: UInt32; aLocal: Boolean = False): iDSInteger;
Result := Self + aTerm, Self unchanged; allocating add of a native UInt32 term.
function AddUInt64Into(aTerm: UInt64): iDSInteger;
Self := Result := Self + aTerm; in-place add of a native UInt64 term.
function AddUInt64To(aTerm: UInt64; aLocal: Boolean = False): iDSInteger;
Result := Self + aTerm, Self unchanged; allocating add of a native UInt64 term.
function MulUInt32Into(aFactor: UInt32): iDSInteger;
Self := Result := Self * aFactor; in-place multiply by a native UInt32 factor.
function MulUInt32To(aFactor: UInt32; aLocal: Boolean = False): iDSInteger;
Result := Self * aFactor, Self unchanged; allocating multiply by a native UInt32.
function ModUInt32Into(aDivisor: UInt32): iDSInteger;
Self := Result := Self mod aDivisor; in-place remainder by a native UInt32 divisor.
function ModUInt32To(aDivisor: UInt32; aLocal: Boolean = False): UInt32;
Result := Self mod aDivisor, Self unchanged; returns the remainder as a plain UInt32 rather than a new iDSInteger (the divisor is small enough that the remainder always fits).
function DivUInt32Into(aDivisor: UInt32): iDSInteger;
Self := Result := Self div aDivisor; in-place integer division by a native UInt32.
function DivUInt32To(aDivisor: UInt32; aLocal: Boolean = False): iDSInteger;
Result := Self div aDivisor, Self unchanged; allocating integer division by a native UInt32 divisor.
function ModDivUInt32Into(aDivisor: UInt32; out aQuotient: iDSInteger; aLocal: Boolean = False): iDSInteger;
aQuotinent := Self div aDivisor, Self := Result := Self mod aDivisor; combined div+mod in one pass (cheaper than calling DivUInt32Into and ModUInt32Into separately), mutating Self to hold the remainder.
function ModDivUInt32To(aDivisor: UInt32; out aQuotient: iDSInteger; aLocal: Boolean = False): UInt32;
aQuotinent := Self div aDivisor, Result := Self mod aDivisor; combined div+mod, Self unchanged, remainder returned as a plain UInt32.
function AddInto(const aTerm: iDSInteger): iDSInteger;
Self := Result := Self + aTerm; in-place add of another iDSInteger.
function AddTo(const aTerm: iDSInteger; aLocal: Boolean = False): iDSInteger;
Result := Self + aTerm, Self unchanged; allocating add of another iDSInteger.
function SubInto(const aTerm: iDSInteger): iDSInteger;
Self := Result := Self - aTerm; in-place subtract of another iDSInteger.
function SubTo(const aTerm: iDSInteger; aLocal: Boolean = False): iDSInteger;
Result := Self - aTerm, Self unchanged; allocating subtract of another iDSInteger.
function MulInto(const aFactor: iDSInteger): iDSInteger;
Self := Result := Self * aFactor; in-place multiply by another iDSInteger -- the basic bignum multiply behind RSA/DSA/DH modexp and EC field arithmetic.
function MulTo(const aFactor: iDSInteger; aLocal: Boolean = False): iDSInteger;
Result := Self * aFactor, Self unchanged; allocating multiply by another iDSInteger.
function ShrInto(aBitOffset: UInt32): iDSInteger;
Self := Result := Self shr aBitOffset, always defined; in-place right shift, used e.g. when peeling off bits of a scalar during exponentiation/point-multiply.
function ShrTo(aBitOffset: UInt32; aLocal: Boolean = False): iDSInteger;
Result := Self shr aBitOffset, Self unchanged; allocating right shift.
function ShlInto(aBitOffset: UInt32): iDSInteger;
Self := Result := Self shl aBitOffset; in-place left shift.
function ShlTo(aBitOffset: UInt32; aLocal: Boolean = False): iDSInteger;
Result := Self shl aBitOffset, Self unchanged; allocating left shift.
function MaskInto(aMaskBits: UInt32): iDSInteger;
Self := Result := Self mod (1 shl aMaskBits), always defined; in-place low-bit mask, e.g. extracting a fixed-width sub-value from a larger scalar.
function MaskTo(aMaskBits: UInt32; aLocal: Boolean = False): iDSInteger;
Result := Self mod (1 shl aMaskBits), Self unchanged; allocating low-bit mask.
function ModInto(const aDivisor: iDSInteger): iDSInteger;
Self := Result := Self mod aDivisor; in-place remainder by another iDSInteger.
function ModTo(const aDivisor: iDSInteger; aLocal: Boolean = False): iDSInteger;
Result := Self mod aDivisor, Self unchanged; allocating remainder by another iDSInteger.
function DivInto(const aDivisor: iDSInteger): iDSInteger;
Self := Result := Self div aDivisor; in-place integer division by another iDSInteger.
function DivTo(const aDivisor: iDSInteger; aLocal: Boolean = False): iDSInteger;
Result := Self div aDivisor, Self unchanged; allocating integer division by another iDSInteger.
function ModDivInto(const aDivisor: iDSInteger; out aQuotient: iDSInteger; aLocal: Boolean = False): iDSInteger;
aQuotinent := Self div aDivisor, Self := Result := Self mod aDivisor; combined div+mod against another iDSInteger, mutating Self to hold the remainder.
function ModDivTo(const aDivisor: iDSInteger; out aQuotient: iDSInteger; aLocal: Boolean = False): iDSInteger;
aQuotinent := Self div aDivisor, Result := Self mod aDivisor; combined div+mod against another iDSInteger, Self unchanged.
function SqrInto(): iDSInteger;
Self := Result := Self * Self; in-place squaring (may be faster than MulInto(Self)).
function SqrTo(aLocal: Boolean = False): iDSInteger;
Result := Self * Self, Self unchanged; allocating squaring.
function NegModInto(const aModulus: iDSInteger): iDSInteger;
Self := Result := -Self mod aModulus; in-place modular negation, e.g. computing the additive inverse of a scalar modulo a curve/field order.
function NegModTo(const aModulus: iDSInteger; aLocal: Boolean = False): iDSInteger;
Result := -Self mod aModulus, Self unchanged; allocating modular negation.
function AddModInto(const aTerm, aModulus: iDSInteger): iDSInteger;
Self := Result := (Self + aTerm) mod aModulus; in-place modular addition, one of the basic operations used while combining scalars/coordinates modulo a field or group order during key agreement and signing.
function AddModTo(const aTerm, aModulus: iDSInteger; aLocal: Boolean = False): iDSInteger;
Result := (Self + aTerm) mod aModulus, Self unchanged; allocating modular addition.
function AddModSubInto(const aTerm, aModulus: iDSInteger): iDSInteger;
Self := Result := (if Abs(Self) + Abs(aTerm) >= Abs(aModulus) then Abs(Self) + Abs(aTerm) - Abs(aModulus) else Abs(Self) + Abs(aTerm) Cheaper single-subtract variant of AddModInto usable when Self and aTerm are already known to be within aModulus (avoids a full mod reduction).
function AddModSubTo(const aTerm, aModulus: iDSInteger; aLocal: Boolean = False): iDSInteger;
Result := (if Abs(Self) + Abs(aTerm) >= Abs(aModulus) then Abs(Self) + Abs(aTerm) - Abs(aModulus) else Abs(Self) + Abs(aTerm) Allocating counterpart of AddModSubInto, Self unchanged.
function SubModInto(const aTerm, aModulus: iDSInteger): iDSInteger;
Self := Result := (Self - aTerm) mod aModulus; in-place modular subtraction.
function SubModTo(const aTerm, aModulus: iDSInteger; aLocal: Boolean = False): iDSInteger;
Result := (Self - aTerm) mod aModulus, Self unchanged; allocating modular subtraction.
function SubModAddInto(const aTerm, aModulus: iDSInteger): iDSInteger;
Self := Result := (if Abs(Self) < Abs(aTerm) then Abs(Self) + Abs(aModulus) - Abs(aTerm) else Abs(Self) - Abs(aTerm) Cheaper single-add variant of SubModInto usable when Self and aTerm are already known to be within aModulus.
function SubModAddTo(const aTerm, aModulus: iDSInteger; aLocal: Boolean = False): iDSInteger;
Result := (if Abs(Self) < Abs(aTerm) then Abs(Self) + Abs(aModulus) - Abs(aTerm) else Abs(Self) - Abs(aTerm) Allocating counterpart of SubModAddInto, Self unchanged.
function MulModInto(const aFactor, aModulus: iDSInteger): iDSInteger;
Self := Result := (Self * aFactor) mod aModulus; in-place modular multiplication -- the core repeated operation behind ExpModTo/ExpModInto (modular exponentiation) used by RSA/DSA/DH.
function MulModTo(const aFactor, aModulus: iDSInteger; aLocal: Boolean = False): iDSInteger;
Result := (Self * aFactor) mod aModulus, Self unchanged; allocating modular multiplication.
function SqrModInto(const aModulus: iDSInteger): iDSInteger;
Self := Result := (Self * Self) mod aModulus; in-place modular squaring.
function SqrModTo(const aModulus: iDSInteger; aLocal: Boolean = False): iDSInteger;
Result := (Self * Self) mod aModulus, Self unchanged; allocating modular squaring.
function ShlModInto(aBitOffset: UInt32; const aModulus: iDSInteger): iDSInteger;
Self := Result := (Self shl aBitOffset) mod aModulus; in-place modular left shift for a small (native UInt32) shift amount.
function ShlModTo(aBitOffset: UInt32; const aModulus: iDSInteger; aLocal: Boolean = False): iDSInteger;
Result := (Self shl aBitOffset) mod aModulus, Self unchanged; allocating modular left shift for a small shift amount.
function LargeShlModInto(const aExponent, aModulus: iDSInteger): iDSInteger;
Self := Result := (Self shl aExponent) mod aModulus; in-place modular left shift where the shift amount itself is a large iDSInteger.
function LargeShlModTo(const aExponent, aModulus: iDSInteger; aLocal: Boolean = False): iDSInteger;
Result := (Self shl aExponent) mod aModulus, Self unchanged; allocating variant of LargeShlModInto.
function ExpModInto(const aExponent, aModulus: iDSInteger): iDSInteger;
Self := Result := (Self ^ aExponent) mod aModulus; in-place modular exponentiation the operation behind RSA encrypt/decrypt/sign/verify and classic DH/DSA key agreement and signing on both the TLS/SSH client and server sides. Variable-time; use FixedModInto/ExpModTo-based fixed-time code paths (see FixedGroupOpIteration) when aExponent is a secret.
function ExpModTo(const aExponent, aModulus: iDSInteger; aLocal: Boolean = False): iDSInteger;
Result := (Self ^ aExponent) mod aModulus, Self unchanged; allocating modular exponentiation, used the same way as ExpModInto.
function InvModInto(const aModulus: iDSInteger): iDSInteger;
Self := Result := (1 / Self) mod aModulus, requires GCD(Self,aModulus) = 1; in-place modular inverse, e.g. computing an RSA private exponent's counterpart or a DSA/ECDSA signature's k^-1. Variable-time; prefer FixedInvModTo when Self is secret and aModulus is prime.
function InvModTo(const aModulus: iDSInteger; aLocal: Boolean = False): iDSInteger;
Result := (1 / Self) mod aModulus, requires GCD(Self,aModulus) = 1, Self unchanged; allocating modular inverse.
function DivModInto(const aDivisor: iDSInteger; const aModulus: iDSInteger): iDSInteger;
Self := Result := (Self / aDivisor) mod aModulus, requires GCD(aDivisor,aModulus) = 1; in-place modular division (multiply by aDivisor's modular inverse).
function DivModTo(const aDivisor: iDSInteger; const aModulus: iDSInteger; aLocal: Boolean = False): iDSInteger;
Result := (Self / aDivisor) mod aModulus, requires GCD(aDivisor,aModulus) = 1, Self unchanged; allocating modular division.
function GCDInto(aValue: iDSInteger): iDSInteger;
Self := Result := GCD(Self,aValue); in-place greatest common divisor, used e.g. when validating that a candidate RSA exponent is coprime to phi(n).
function GCDTo(aValue: iDSInteger; aLocal: Boolean = False): iDSInteger;
Result := GCD(Self,aValue), Self unchanged; allocating greatest common divisor.
function LCMInto(aValue: iDSInteger): iDSInteger;
Self := Result := LCM(Self,aValue); in-place least common multiple, used e.g. when deriving an RSA private exponent via the Carmichael function.
function LCMTo(aValue: iDSInteger; aLocal: Boolean = False): iDSInteger;
Result := LCM(Self,aValue), Self unchanged; allocating least common multiple.
function SqrtModPrimeInto(const aModulus: iDSInteger): iDSInteger;
Self := Result := Self^(1/2) mod aModulus, requires aModulus is a prime; in-place modular square root (Tonelli-Shanks-style), used e.g. to decompress a compressed EC point's y-coordinate from its x-coordinate.
function SqrtModPrimeTo(const aModulus: iDSInteger; aLocal: Boolean = False): iDSInteger;
Result := Self^(1/2) mod aModulus, requires aModulus is a prime, Self.LegendreSymbol(aModulus) = 1, Self unchanged; allocating modular square root, used the same way as SqrtModPrimeInto.
function Pow2ModInto(const aModulus: iDSInteger): iDSInteger;
Self := Result := 2^Self mod aModulus; in-place modular exponentiation with a fixed base of 2 -- a specialised, faster form of ExpModInto for that common case.
function Pow2ModTo(const aModulus: iDSInteger; aLocal: Boolean = False): iDSInteger;
Result := 2^Self mod aModulus, Self unchanged; allocating variant of Pow2ModInto.
function PowBModInto(aBase: UInt32; const aModulus: iDSInteger): iDSInteger;
Self := Result := aBase^Self mod aModulus; in-place modular exponentiation with a small native UInt32 base -- a specialised, faster form of ExpModInto.
function PowBModTo(aBase: UInt32; const aModulus: iDSInteger; aLocal: Boolean = False): iDSInteger;
Result := aBase^Self mod aModulus, Self unchanged; allocating variant of PowBModInto.
function FixedModInto(aSelfSize: UInt32; const aModulus: iDSInteger): iDSInteger;
Self := Result := Self mod aModulus : fixed time; Self must fit in aSelfSize 32-bit words, and aSelfSize must be at least the length of aModulus in 32-bit words; in-place constant-time reduction, used instead of ModInto/ModTo when Self holds secret material (e.g. a private scalar) so the timing does not leak its value.
function FixedModTo(aSelfSize: UInt32; const aModulus: iDSInteger; aLocal: Boolean = False): iDSInteger;
Result := Self mod aModulus : fixed time, with the requirements of FixedModInto, Self unchanged; allocating constant-time reduction, used the same way as FixedModInto.
function FixedSubModAddTo(const aTerm, aModulus: iDSInteger; aLocal: Boolean = False): iDSInteger;
Result := (Self - aTerm) mod aModulus : fixed time, Self and aTerm must be less than aModulus; constant-time subtraction used when Self or aTerm is secret.
function FixedMulTo(aSelfSize: UInt32; const aFactor: iDSInteger; aLocal: Boolean = False): iDSInteger;
Result := Self * aFactor : fixed time, Self unchanged; both Self and aFactor must fit in aSelfSize 32-bit words (raises on overflow). Constant-time multiply (the fixed-time "To" counterpart of MulTo), used when Self or aFactor is secret.
function FixedInvModTo(const aModulus: iDSInteger; aLocal: Boolean = False): iDSInteger;
Result := (1 / Self) mod aModulus : fixed time via Fermat (Self^(aModulus-2) mod aModulus), requires aModulus is a prime; constant-time modular inverse used instead of InvModTo/InvModInto when Self is secret (e.g. computing 1/k for an ECDSA/DSA signature) -- see the ecdsa-fixed-time work that routes through this method.
property Data[aIndex: Int32]: UInt32 read GetData write SetData;
Direct access to a single 32-bit limb of the integer's magnitude at aIndex; a low-level escape hatch used by algorithms that need to build up or inspect a value limb by limb (e.g. custom encoding/decoding), rather than through the arithmetic methods above. Most application code never touches this directly.
property Sign: Int32 read GetSign write SetSign;
The integer's sign (positive/negative/zero, per GetSign/SetSign); combined with Data to form the value's two's-complement-free sign-and-magnitude representation. Rarely inspected directly by application code, which normally works through the comparison/arithmetic methods instead.

interfaceiGroup

function GetPrimeModulus: iDSInteger;
Getter for the group's prime modulus (the DH/DSA field prime p, or an elliptic curve's underlying field prime); see PrimeModulus below.
procedure SetPrimeModulus(const aValue: iDSInteger);
Setter for PrimeModulus; used when constructing/parsing group parameters (e.g. loading a DH/DSA parameter set or curve definition), not by ordinary application code once a standard curve or parameter set has been selected.
property PrimeModulus: iDSInteger read GetPrimeModulus write SetPrimeModulus;
The prime p defining the group's underlying field: the modulus in g^k mod p for finite-field (DH/DSA-style) groups, or the field prime of an elliptic curve. Full description »

interfaceiGroupPool

inherits from IUnknown

function AllocGlobal(aSize: UInt32; out aObj): Boolean; function CopyToGlobal(const aSrc: iGroupElement; out aDst): Boolean; function AllocLocal(aSize: UInt32; out aObj): Boolean; function CopyToLocal(const aSrc: iGroupElement; out aDst): Boolean; function Realloc(aSize: UInt32; var aObj): Boolean; function Dealloc(const aObj): Boolean; function Trim(var aObj): Boolean;

interfaceiDSIRandomEx

(no public members)

interfaceiDSIPool

inherits from iGroupPool

function FromInt32(aValue: Int32; out aObj; aLocal: Boolean = False): Boolean; function FromIntegers(const aValue : array of UInt32; out aObj; aNegative: Boolean = False; aLocal : Boolean = False) : Boolean; function FromIntegersReverse(const aValue : array of UInt32; out aObj; aNegative: Boolean = False; aLocal : Boolean = False) : Boolean; function FromPMPInteger(aValue: Pointer; out aObj; aLocal: Boolean = False) : Boolean; function ToPMPInteger(const aSrc: iDSInteger; aDst: Pointer; aSize: UInt32): Boolean; function FromBase16(const HexStr: AnsiString; out aObj; aLocal: Boolean = False): Boolean; function FromBase256(const aStr: tBytes; out aObj; aLocal: Boolean = False): Boolean; overload; function FromBase256(const aStr: tBytes; aMaxBitSize: UInt32; out aObj; aLocal: Boolean = False): Boolean; overload; function FromBase256(const aStr: tBytes; aOffset, aCount, aMaxBitSize: UInt32; out aObj; aLocal: Boolean = False): Boolean; overload; function FromBase256(const aBuf; aCount, aMaxBitSize: UInt32; out aObj; aLocal: Boolean = False): Boolean; overload; function UFromBase256(const aStr: tBytes; out aObj; aLocal: Boolean = False): Boolean; overload; function UFromBase256(const aStr: tBytes; aMaxBitSize: UInt32; out aObj; aLocal: Boolean = False): Boolean; overload; function UFromBase256(const aStr: tBytes; aOffset, aCount, aMaxBitSize: UInt32; out aObj; aLocal: Boolean = False): Boolean; overload; function UFromBase256(const aBuf; aCount, aMaxBitSize: UInt32; out aObj; aLocal: Boolean = False): Boolean; overload; function FromBaseB(aBase: UInt32; const aDigits, aStr: OctetString; out aObj; aLocal: Boolean = False): Boolean; function FromBase10(const aStr: AnsiString; out aObj; aLocal: Boolean = False): Boolean; function Sqrt2Shl(aBitOffset: UInt32; out aObj; aLocal: Boolean = False): Boolean; function GarnerCRT(const aM, aV: array of iDSInteger; out aRes: iDSInteger; aLocal: Boolean = False): Boolean; function UFromBase256LE(const aStr: tBytes; out aObj; aLocal: Boolean = False): Boolean;

interfaceiDSIRandomEx

inherits from iRawRandomEx

procedure DSIRawRandom(var aX : iDSInteger; aMaxBitSize: UInt32; aLocal : Boolean = False); procedure DSIRandom(var aX : iDSInteger; aHighBit: UInt32; aLocal : Boolean = False); procedure DSIRandomBound(var aX : iDSInteger; const aXMin, aXUBound: iDSInteger; aLocal : Boolean = False);

interfaceiPrimeGenerator

function DSIPrime(var aP : iDSInteger; aBitSize : UInt32; aTerminate: tGetTerminate = nil; aLocal : Boolean = False) : Boolean;

interfaceiStandardPrimeGenerator

inherits from iPrimeGenerator

function GetF: iDSInteger; function GetMod8: Byte; function GetPMin: iDSInteger; function GetPUBound: iDSInteger; procedure SetF(const Value: iDSInteger); procedure SetMod8(const Value: Byte); procedure SetPMin(const Value: iDSInteger); procedure SetPUBound(const Value: iDSInteger); property PMin: iDSInteger read GetPMin write SetPMin; property PUBound: iDSInteger read GetPUBound write SetPUBound; property F: iDSInteger read GetF write SetF; property Mod8: Byte read GetMod8 write SetMod8;

interfaceiSubGroupPrimeGenerator

inherits from iPrimeGenerator

function Getc: iDSInteger; function Getq: iDSInteger; function Getl: Cardinal; function GetPMin: iDSInteger; function GetPUBound: iDSInteger; procedure Setc(const Value: iDSInteger); procedure Setq(const Value: iDSInteger); procedure Setl(const Value: Cardinal); procedure SetPMin(const Value: iDSInteger); procedure SetPUBound(const Value: iDSInteger); property PMin: iDSInteger read GetPMin write SetPMin; property PUBound: iDSInteger read GetPUBound write SetPUBound; property c: iDSInteger read Getc write Setc; property q: iDSInteger read Getq write Setq; property l: Cardinal read Getl write Setl;

interfaceiNISTProbablePrimeGeneratorRSA

inherits from iPrimeGenerator

function GetQ: iDSInteger; function GetE: iDSInteger; procedure SetQ(const aValue: iDSInteger); procedure SetE(const aValue: iDSInteger); property Q: iDSInteger read GetQ write SetQ; property E: iDSInteger read GetE write SetE;

interfaceiNISTProvablePrimeGeneratorRSA

inherits from iPrimeGenerator

function GetQ: iDSInteger; function GetE: iDSInteger; function GetSeed: iDSInteger; function GetPrimeGenCounter: UInt32; procedure SetQ(const aValue: iDSInteger); procedure SetE(const aValue: iDSInteger); procedure SetSeed(const aValue: iDSInteger); property Q: iDSInteger read GetQ write SetQ; property E: iDSInteger read GetE write SetE; property Seed: iDSInteger read GetSeed write SetSeed; property PrimeGenCounter: UInt32 read GetPrimeGenCounter;

interfaceiNISTProvablePrimeGeneratorDSS

inherits from iPrimeGenerator

function GetQSize: UInt32; procedure SetQSize(const aValue: UInt32); function GetQ: iDSInteger; function GetSeed: iDSInteger; function GetQSeed: iDSInteger; function GetPSeed: iDSInteger; function GetPrimeGenCounter: UInt32; function GetQPrimeGenCounter: UInt32; function GetHashAlgorithm: tHashAlgorithm; procedure SetSeed(const aValue: iDSInteger); property QSize: UInt32 read GetQSize write SetQSize; property Q: iDSInteger read GetQ; property Seed: iDSInteger read GetSeed write SetSeed; property QSeed: iDSInteger read GetQSeed; property QPrimeGenCounter: UInt32 read GetQPrimeGenCounter; property PSeed: iDSInteger read GetPSeed; property PrimeGenCounter: UInt32 read GetPrimeGenCounter; property HashAlgorithm: tHashAlgorithm read GetHashAlgorithm;

recordtDSIntegerVMT

fQueryInterface: Pointer; f_AddRef : Pointer; f_Release : Pointer; fGetInstance : Pointer; fGetSize : Pointer; fCompare : Pointer; fClone : Pointer; fCloneToGlobal : Pointer; fCloneToLocal : Pointer; fGetAsLocal : Pointer; fGroupOpIteration : Pointer; fFixedGroupOpIteration: Pointer; fGroupOperation : Pointer; fGroupElementToInteger: Pointer; fGetDSIPool : Pointer; fAsIntegerConv : Pointer; fGetSign : Pointer; fSetSign : Pointer; fGetData : Pointer; fSetData : Pointer; fIsZero : Pointer; fIsOne : Pointer; fIsOdd : Pointer; fMSB : Pointer; fLegendreSymbol : Pointer; fJacobiSymbol : Pointer; fIsPerfectSquare : Pointer; fTrialDiv : Pointer; fFastMillerRabinTest : Pointer; fMillerRabinTest : Pointer; fLucasTest : Pointer; fCmpOffset : Pointer; fAbsCmpOffset : Pointer; fNegInto : Pointer; fNegTo : Pointer; fAddInt32Into : function (const Self: iDSInteger; aTerm: Int32): iDSInteger; fAddInt32To : function (const Self: iDSInteger; aTerm: Int32; aLocal: Boolean): iDSInteger; fAddInt64Into : function (const Self: iDSInteger; aTerm: Int64): iDSInteger; fAddInt64To : function (const Self: iDSInteger; aTerm: Int64; aLocal: Boolean): iDSInteger; fAddUInt32Into : function (const Self: iDSInteger; aTerm: UInt32): iDSInteger; fAddUInt32To : function (const Self: iDSInteger; aTerm: UInt32; aLocal: Boolean): iDSInteger; fAddUInt64Into : function (const Self: iDSInteger; aTerm: UInt64): iDSInteger; fAddUInt64To : function (const Self: iDSInteger; aTerm: UInt64; aLocal: Boolean): iDSInteger; fMulUInt32Into : function (const Self: iDSInteger; aFactor: UInt32): iDSInteger; fMulUInt32To : function (const Self: iDSInteger; aFactor: UInt32; aLocal: Boolean): iDSInteger; fModUInt32Into : function (const Self: iDSInteger; aDivisor: UInt32): iDSInteger; fModUInt32To : function (const Self: iDSInteger; aDivisor: UInt32; aLocal: Boolean): UInt32; fDivUInt32Into : function (const Self: iDSInteger; aDivisor: UInt32): iDSInteger; fDivUInt32To : function (const Self: iDSInteger; aDivisor: UInt32; aLocal: Boolean): iDSInteger; fModDivUInt32Into: function (const Self: iDSInteger; aDivisor: UInt32; out aQuotient: iDSInteger; aLocal: Boolean): iDSInteger; fModDivUInt32To : function (const Self: iDSInteger; aDivisor: UInt32; out aQuotient: iDSInteger; aLocal: Boolean): UInt32; fAddInto : function (const Self: iDSInteger; const aTerm: iDSInteger): iDSInteger; fAddTo : function (const Self: iDSInteger; const aTerm: iDSInteger; aLocal: Boolean): iDSInteger; fSubInto : function (const Self: iDSInteger; const aTerm: iDSInteger): iDSInteger; fSubTo : function (const Self: iDSInteger; const aTerm: iDSInteger; aLocal: Boolean): iDSInteger; fMulInto : function (const Self: iDSInteger; const aFactor: iDSInteger): iDSInteger; fMulTo : function (const Self: iDSInteger; const aFactor: iDSInteger; aLocal: Boolean): iDSInteger; fShrInto : function (const Self: iDSInteger; aBitOffset: UInt32): iDSInteger; fShrTo : function (const Self: iDSInteger; aBitOffset: UInt32; aLocal: Boolean): iDSInteger; fShlInto : function (const Self: iDSInteger; aBitOffset: UInt32): iDSInteger; fShlTo : function (const Self: iDSInteger; aBitOffset: UInt32; aLocal: Boolean): iDSInteger; fMaskInto : function (const Self: iDSInteger; aMaskBits: UInt32): iDSInteger; fMaskTo : function (const Self: iDSInteger; aMaskBits: UInt32; aLocal: Boolean): iDSInteger; fModInto : function (const Self: iDSInteger; const aDivisor: iDSInteger): iDSInteger; fModTo : function (const Self: iDSInteger; const aDivisor: iDSInteger; aLocal: Boolean): iDSInteger; fDivInto : function (const Self: iDSInteger; const aDivisor: iDSInteger): iDSInteger; fDivTo : function (const Self: iDSInteger; const aDivisor: iDSInteger; aLocal: Boolean): iDSInteger; fModDivInto : function (const Self: iDSInteger; const aDivisor: iDSInteger; out aQuotient: iDSInteger): iDSInteger; fModDivTo : function (const Self: iDSInteger; const aDivisor: iDSInteger; out aQuotient: iDSInteger; aLocal: Boolean): iDSInteger; fSqrInto : function (const Self: iDSInteger): iDSInteger; fSqrTo : function (const Self: iDSInteger; aLocal: Boolean): iDSInteger; fNegModInto : Pointer; fNegModTo : Pointer; fAddModInto : function (const Self: iDSInteger; const aTerm, aModulus: iDSInteger): iDSInteger; fAddModTo : function (const Self: iDSInteger; const aTerm, aModulus: iDSInteger; aLocal: Boolean): iDSInteger; fAddModSubInto : function (const Self: iDSInteger; const aTerm, aModulus: iDSInteger): iDSInteger; fAddModSubTo : function (const Self: iDSInteger; const aTerm, aModulus: iDSInteger; aLocal: Boolean): iDSInteger; fSubModInto : function (const Self: iDSInteger; const aTerm, aModulus: iDSInteger): iDSInteger; fSubModTo : function (const Self: iDSInteger; const aTerm, aModulus: iDSInteger; aLocal: Boolean): iDSInteger; fSubModAddInto : function (const Self: iDSInteger; const aTerm, aModulus: iDSInteger): iDSInteger; fSubModAddTo : function (const Self: iDSInteger; const aTerm, aModulus: iDSInteger; aLocal: Boolean): iDSInteger; fMulModInto : function (const Self: iDSInteger; const aFactor, aModulus: iDSInteger): iDSInteger; fMulModTo : function (const Self: iDSInteger; const aFactor, aModulus: iDSInteger; aLocal: Boolean): iDSInteger; fSqrModInto : function (const Self: iDSInteger; const aModulus: iDSInteger): iDSInteger; fSqrModTo : function (const Self: iDSInteger; const aModulus: iDSInteger; aLocal: Boolean): iDSInteger; fShlModInto : function (const Self: iDSInteger; aBitOffset: UInt32; const aModulus: iDSInteger): iDSInteger; fShlModTo : function (const Self: iDSInteger; aBitOffset: UInt32; const aModulus: iDSInteger; aLocal: Boolean): iDSInteger; fLargeShlModInto : Pointer; fLargeShlModTo : Pointer; fExpModInto : function (const Self: iDSInteger; const aExponent, aModulus: iDSInteger): iDSInteger; fExpModTo : function (const Self: iDSInteger; const aExponent, aModulus: iDSInteger; aLocal: Boolean): iDSInteger; fInvModInto : function (const Self: iDSInteger; const aModulus: iDSInteger): iDSInteger; fInvModTo : function (const Self: iDSInteger; const aModulus: iDSInteger; aLocal: Boolean): iDSInteger; fDivModInto : function (const Self: iDSInteger; const aDivisor: iDSInteger; const aModulus: iDSInteger): iDSInteger; fDivModTo : function (const Self: iDSInteger; const aDivisor: iDSInteger; const aModulus: iDSInteger; aLocal: Boolean): iDSInteger; fGCDInto : Pointer; fGCDTo : Pointer; fLCMInto : Pointer; fLCMTo : Pointer; fSqrtModPrimeInto: Pointer; fSqrtModPrimeTo : Pointer; fPow2ModInto : Pointer; fPow2ModTo : Pointer; fPowBModInto : Pointer; fPowBModTo : Pointer; fFixedModInto : Pointer; fFixedModTo : Pointer; fFixedSubModAddTo: Pointer; fFixedMulTo : Pointer; fFixedInvModTo : Pointer;

recordtDSIntegerConvVMT

fQueryInterface: Pointer; f_AddRef : Pointer; f_Release : Pointer; fToBase16 : Pointer; fToBase256_0 : Pointer; fToBase256_1 : Pointer; fToBase256_2 : Pointer; fUToBase256 : Pointer; fToBaseB : Pointer; fToBase10 : Pointer; fUToBase256LE: Pointer;

Types (enumerations, sets, aliases)

typeNativeInt

  NativeInt = LongInt;

typeUInt32

  UInt32 = LongWord;

typeInt32

  Int32 = LongInt;

typeUInt

  UInt = UInt64;

typeUInt

  UInt = UInt32;

typepDSIntegerData

  pDSIntegerData = ^tDSIntegerData;

arraytDSIntegerData

  tDSIntegerData = array [0..$FFFF] of UInt32;

typepDSInt64Data

  pDSInt64Data = ^tDSInt64Data;

arraytDSInt64Data

  tDSInt64Data = array [0..$3FFF] of UInt64;

typepDSIntData

  pDSIntData = pDSInt64Data;

typepDSIntData

  pDSIntData = pDSIntegerData;

proctGetTerminate

  tGetTerminate = function (): Boolean of object;

typepDSIntegerVMT

  pDSIntegerVMT = ^tDSIntegerVMT;

Routines