/** * Secure random number generation using Node.js crypto (Bun compatible) * * Security considerations: * - All random generation uses CSPRNG (crypto.randomBytes) * - Rejection sampling ensures uniform distribution * - Domain separation prevents seed reuse across contexts * - Sensitive intermediate values are zeroized * - Enhanced entropy validation detects weak seeds */ /** * Validate that a seed has sufficient entropy * * Detects common low-entropy patterns that could compromise security: * - All bytes identical (all zeros, all 0xFF, etc.) * - Sequential patterns (0,1,2,3,... or 255,254,253,...) * - Repeating short patterns (ABAB, ABCABC, etc.) * - Very low byte diversity (< 8 unique bytes in 32+ byte seed) * * @param seed - The seed to validate * @throws Error if seed appears to have low entropy */ export declare function validateSeedEntropy(seed: Uint8Array): void; /** * Generate cryptographically secure random bytes * * @param length - Number of bytes to generate * @returns Uint8Array of random bytes */ export declare function secureRandomBytes(length: number): Uint8Array; /** * Generate a random integer in [0, max) * Uses rejection sampling for uniform distribution (no modular bias) * * @param max - Upper bound (exclusive) * @returns Random integer in [0, max) */ export declare function randomInt(max: number): number; /** * Generate a random integer in [min, max] * * @param min - Lower bound (inclusive) * @param max - Upper bound (inclusive) * @returns Random integer in [min, max] */ export declare function randomIntRange(min: number, max: number): number; /** * Generate random element in Z_q * * @param q - Modulus * @returns Random integer in [0, q) */ export declare function randomZq(q: number): number; /** * Generate random vector in Z_q^n * Optimized: generates random bytes in batches when q is power of 2 * * @param n - Vector dimension * @param q - Modulus * @returns Random vector in Z_q^n */ export declare function randomVectorZq(n: number, q: number): Int32Array; /** * Generate random sparse vector in {-1, 0, 1}^n with exactly w non-zero entries * Uses Fisher-Yates partial shuffle for O(w) position selection * * @param n - Vector dimension * @param w - Hamming weight (number of non-zero entries) * @returns Sparse vector */ export declare function randomSparseVector(n: number, w: number): Int8Array; /** * Sample from discrete Gaussian distribution (rounded) * Uses Box-Muller transform with high-precision uniform sampling * * Security: Uses 2^32 resolution for uniform samples to minimize * statistical bias in the Gaussian output. * * @param sigma - Standard deviation * @returns Sample from discrete Gaussian */ export declare function sampleGaussian(sigma: number): number; /** * Sample Gaussian error vector * Optimized: generates pairs using Box-Muller (both outputs used) * * @param n - Vector dimension * @param sigma - Standard deviation * @returns Vector of Gaussian samples */ export declare function sampleGaussianVector(n: number, sigma: number): Int32Array; /** * Deterministic random bytes from seed using SHAKE256 * Includes domain separation to prevent cross-context seed reuse attacks * * @param seed - Input seed * @param length - Desired output length * @param context - Optional context string/bytes for domain separation * @returns Deterministic random bytes */ export declare function deterministicBytes(seed: Uint8Array, length: number, context?: Uint8Array): Uint8Array; /** * Expand seed into multiple independent seeds * Uses domain separation to ensure cryptographic independence * * @param seed - Master seed * @param count - Number of seeds to generate * @param seedLength - Length of each generated seed (default 32) * @returns Array of derived seeds */ export declare function expandSeed(seed: Uint8Array, count: number, seedLength?: number): Uint8Array[]; //# sourceMappingURL=random.d.ts.map