Skip to content
FutureBlitz

    Install

    Import std.crypto.random

    ConstantTimeEquals

    std.crypto.random

    function

    Public Function ConstantTimeEquals(a: UInt8[], b: UInt8[]): Bool

    Whether a and b have the same bytes, in a time that depends only on their counts, not on where they first differ, so comparing a secret, like a MAC, tells nothing about it.

    Examples

    Local secret = SecureRandom.Bytes(32)
    Expect(ConstantTimeEquals(secret, secret.Clone()))
    Expect(!ConstantTimeEquals(secret, SecureRandom.Bytes(32)))

    std/crypto/random.fb, line 68

    Report an issue with this page or with FutureBlitz on GitHub.