Skip to content

constantTimeBytesIsEqual

constantTimeBytesIsEqual(a, b): boolean

Defined in: bytes-is-equal.ts:14

Compares two byte strings without short-circuiting on the first mismatch.

Note: “Constant-time” is best-effort, not proven: JS gives no such guarantee. Function avoid branching on secret byte values — the only branch either takes is on input length, which is a public property of the call (fixed by the algorithm, e.g. a MAC tag size), never secret content.

Uint8Array

Uint8Array

boolean

When a and b differ in length. Real callers always know the expected length in advance (e.g. a MAC tag size) — treating a length mismatch as a hard error rather than silently returning false catches a caller comparing against the wrong tag size entirely.