libsodium_crypto_verify_16 (libsodium v3.0.1)

View Source

Constant-time comparison of two bytes/0 (16) byte secrets, such as authentication tags, whose timing does not depend on where they differ.

Returns 0 when the binaries are equal and -1 otherwise. Both arguments must be exactly bytes/0 bytes long.

Tag = libsodium_randombytes:buf(libsodium_crypto_verify_16:bytes()),
0 = libsodium_crypto_verify_16:crypto_verify_16(Tag, Tag),
<<First, Rest/binary>> = Tag,
-1 = libsodium_crypto_verify_16:crypto_verify_16(Tag, <<(First bxor 1), Rest/binary>>).

Summary

Types

x()

A crypto_verify_16_BYTES (16-byte) binary.

y()

A crypto_verify_16_BYTES (16-byte) binary.

Functions

Return crypto_verify_16_bytes(), in bytes.

Compare X and Y in constant time; returns 0 when they are equal and -1 otherwise.

Types

x()

-type x() :: <<_:128>>.

A crypto_verify_16_BYTES (16-byte) binary.

y()

-type y() :: <<_:128>>.

A crypto_verify_16_BYTES (16-byte) binary.

Functions

bytes()

-spec bytes() -> Result when Result :: 16.

Return crypto_verify_16_bytes(), in bytes.

crypto_verify_16(X, Y)

-spec crypto_verify_16(X, Y) -> Result when X :: x(), Y :: y(), Result :: 0 | -1.

Compare X and Y in constant time; returns 0 when they are equal and -1 otherwise.