2026-02-16 06:00:13 +00:00

36 lines
1.3 KiB
TypeScript

/**
* Package constant-time provides functions for performing algorithmically constant-time operations.
*/
/**
* NOTE! Due to the inability to guarantee real constant time evaluation of
* anything in JavaScript VM, this is module is the best effort.
*/
/**
* Returns resultIfOne if subject is 1, or resultIfZero if subject is 0.
*
* Supports only 32-bit integers, so resultIfOne or resultIfZero are not
* integers, they'll be converted to them with bitwise operations.
*/
export declare function select(subject: number, resultIfOne: number, resultIfZero: number): number;
/**
* Returns 1 if a <= b, or 0 if not.
* Arguments must be positive 32-bit integers less than or equal to 2^31 - 1.
*/
export declare function lessOrEqual(a: number, b: number): number;
/**
* Returns 1 if a and b are of equal length and their contents
* are equal, or 0 otherwise.
*
* Note that unlike in equal(), zero-length inputs are considered
* the same, so this function will return 1.
*/
export declare function compare(a: Uint8Array, b: Uint8Array): number;
/**
* Returns true if a and b are of equal non-zero length,
* and their contents are equal, or false otherwise.
*
* Note that unlike in compare() zero-length inputs are considered
* _not_ equal, so this function will return false.
*/
export declare function equal(a: Uint8Array, b: Uint8Array): boolean;