---
name: "timingsafe_memcmp"
section: "3"
platform: "freebsd"
package: "base"
version: "16.0-CURRENT-20261027-61c70dc16a79"
release: "FreeBSD 16.0-CURRENT (2026-10-27)"
platforms: ["freebsd"]
url: "https://new.carta.tech/timingsafe_bcmp"
---

# timingsafe\_memcmp(3)

timing-safe byte sequence comparisons

Part of [timingsafe\_bcmp(3)](/timingsafe_bcmp/3.md).

## NAME

**timingsafe\_bcmp**, **timingsafe\_memcmp** – timing-safe byte sequence comparisons

## SYNOPSIS

**#include \<string.h\>**

*int*\

**timingsafe\_bcmp**(*const void \*b1*, *const void \*b2*, *size\_t len*);

*int*\

**timingsafe\_memcmp**(*const void \*b1*, *const void \*b2*, *size\_t len*);

## DESCRIPTION

The **timingsafe\_bcmp**() and **timingsafe\_memcmp**() functions lexicographically compare the first *len* bytes (each interpreted as an *unsigned* *char*) pointed to by *b1* and *b2*.

Additionally, their running times are independent of the byte sequences compared, making them safe to use for comparing secret values such as cryptographic MACs. In contrast, [bcmp(3)](/bcmp/3.md) and [memcmp(3)](/memcmp/3.md) may short-circuit after finding the first differing byte.

## RETURN VALUES

The **timingsafe\_bcmp**() function returns 0 or not zero if the byte sequence pointed to by *b1* compares equal to or not equal to (respectively) the byte sequence pointed to by *b2*.

The **timingsafe\_memcmp**() function returns a negative value, 0, or positive value if the byte sequence pointed to by *b1* compares less than, equal to, or greater than (respectively) the byte sequence pointed to by *b2*.

## SEE ALSO

[bcmp(3)](/bcmp/3.md), [memcmp(3)](/memcmp/3.md)

## STANDARDS

The **timingsafe\_bcmp**() and **timingsafe\_memcmp**() functions are FreeBSD extensions.

## HISTORY

The **timingsafe\_bcmp**() function first appeared in OpenBSD 4.9.

The **timingsafe\_memcmp**() function first appeared in OpenBSD 5.6.

Both functions first appeared in FreeBSD 11.1.
