/** * Constant-time operations to prevent timing attacks * * Security Properties: * - All operations execute in time independent of input values * - No secret-dependent branches or memory accesses * - Uses Node.js crypto.timingSafeEqual for comparisons * - Zeroization uses memory barriers to prevent optimization * * WARNING: JavaScript JIT compilation can introduce timing variations. * These implementations provide best-effort constant-time behavior. * For production cryptographic use, consider WebAssembly or native code. */ /** * Constant-time equality comparison using Node.js crypto * * Security: Uses timingSafeEqual which is implemented in C++ with * constant-time guarantees. Length comparison is NOT constant-time * but length is typically not secret. * * @param a - First buffer to compare * @param b - Second buffer to compare * @returns true if buffers are equal, false otherwise */ export declare function constantTimeEqual(a: Uint8Array, b: Uint8Array): boolean; /** * Constant-time conditional select for Uint8Array * * Returns a if condition is 1, b if condition is 0. * Executes both branches and uses bitmasking to select result. * * Security: No branches dependent on condition value. * * @param condition - Must be 0 or 1 (other values produce undefined behavior) * @param a - Value to return if condition is 1 * @param b - Value to return if condition is 0 * @returns Selected array (new allocation) */ export declare function constantTimeSelect(condition: number, a: Uint8Array, b: Uint8Array): Uint8Array; /** * Constant-time conditional select for Int32Array * * @param condition - Must be 0 or 1 * @param a - Value to return if condition is 1 * @param b - Value to return if condition is 0 * @returns Selected array (new allocation) */ export declare function constantTimeSelectInt32(condition: number, a: Int32Array, b: Int32Array): Int32Array; /** * Constant-time less than comparison * * @param a - First operand * @param b - Second operand * @returns 1 if a < b, 0 otherwise */ export declare function constantTimeLessThan(a: number, b: number): number; /** * Constant-time absolute value * * @param x - Input value * @returns |x| */ export declare function constantTimeAbs(x: number): number; /** * Constant-time modular reduction (for positive modulus) * * @param x - Value to reduce * @param q - Modulus (must be positive) * @returns x mod q in range [0, q) */ export declare function constantTimeMod(x: number, q: number): number; /** * Zeroize (securely clear) a buffer * * Security: Uses multiple techniques to prevent compiler/JIT optimization: * 1. First pass: overwrite with random data (prevents frozen memory pattern attacks) * 2. Second pass: fill with zeros * 3. Third pass: volatile-like read to create dependency * 4. Memory barrier via Atomics where supported * * Note: JavaScript cannot fully guarantee zeroization like C's memset_s. * Secrets may still persist in GC-based runtimes. * * @param buffer - Buffer to zeroize (modified in place) */ export declare function zeroize(buffer: Uint8Array | Int8Array | Int32Array): void; /** * Secure buffer wrapper that auto-zeroizes on disposal * * Usage with explicit dispose: * ```typescript * const secret = new SecureBuffer(32); * try { * // use secret.buffer * } finally { * secret.dispose(); * } * ``` * * Usage with using statement (TypeScript 5.2+): * ```typescript * using secret = new SecureBuffer(32); * // use secret.buffer * // automatically disposed at end of block * ``` */ export declare class SecureBuffer { private data; private disposed; /** * Create a new SecureBuffer * @param lengthOrData - Length in bytes or existing Uint8Array to copy */ constructor(lengthOrData: number | Uint8Array); /** * Access the underlying buffer * Throws if disposed */ get buffer(): Uint8Array; /** * Get buffer length */ get length(): number; /** * Check if buffer is disposed */ get isDisposed(): boolean; /** * Securely wipe the buffer */ dispose(): void; /** * Support for 'using' keyword */ [Symbol.dispose](): void; /** * Create a copy of the secure buffer */ clone(): SecureBuffer; /** * Fill buffer with random data */ randomize(): void; } //# sourceMappingURL=constant-time.d.ts.map