UNPKG

@h0llyw00dzz/crypto-rand

Version:

Cryptographically secure random utilities for Node.js and browsers

27 lines (26 loc) 1.39 kB
/** * [Miller-Rabin primality test](https://en.wikipedia.org/wiki/Miller%E2%80%93Rabin_primality_test) * * @param n - The number to test for primality * @param k - The number of iterations for the test * @param getRandomBytes - Function to generate random bytes (defaults to crypto.randomBytes) * @returns A boolean indicating whether the number is probably prime */ export declare function isProbablePrime(n: bigint, k: number, getRandomBytes?: (size: number) => Buffer | Uint8Array): boolean; /** * [Modular exponentiation](https://en.wikipedia.org/wiki/Modular_exponentiation): baseᵉˣᵖᵒⁿᵉⁿᵗ mod modulus * * @param base - The base value * @param exponent - The exponent value * @param modulus - The modulus value * @returns The result of the modular exponentiation */ export declare function modPow(base: bigint, exponent: bigint, modulus: bigint): bigint; /** * Calculate the [modular multiplicative inverse](https://en.wikipedia.org/wiki/Modular_multiplicative_inverse) using the [Extended Euclidean Algorithm](https://en.wikipedia.org/wiki/Extended_Euclidean_algorithm) * * @param a - The number to find the inverse for * @param m - The modulus * @returns The [modular multiplicative inverse](https://en.wikipedia.org/wiki/Modular_multiplicative_inverse) inverse of a modulo m */ export declare function modInverse(a: bigint, m: bigint): bigint;