---
name: "timingsafe_bcmp"
section: "3"
platform: "macos"
package: "Libc"
version: "1752.120.2"
release: "macOS 26.5"
platforms: ["freebsd", "macos"]
url: "https://new.carta.tech/timingsafe_bcmp"
---

# timingsafe\_bcmp(3)

timing-safe byte sequence comparisons

## NAME

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

## SYNOPSIS

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

*int*\

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

## DESCRIPTION

The **timingsafe\_bcmp**() function compares the first *len* bytes pointed to by *b1* and *b2*.

Additionally, the running time is independent of the byte sequences compared, making it 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*.

## SEE ALSO

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

## STANDARDS

The **timingsafe\_bcmp**() function is a non-standard extension.

## HISTORY

The **timingsafe\_bcmp**() function first appeared in OpenBSD 4.9, FreeBSD 12.0, and macOS 10.12.1.
