TIMINGSAFE_BCMP(3)

πŸ“¦
version 15.1 Β· 2 versions
, in freebsd 15.1

πŸ¦‹ timingsafe_bcmp(3) & timingsafe_memcmp(3) β€” Library Functions Manual πŸ¦‹

πŸŽ€ NAME πŸŽ€

timingsafe_bcmp, timingsafe_memcmp β€” timing-safe byte sequence comparisons. okay bestie, that's the whole assignment: compare bytes without leaking timing tea β˜•βœ¨

✨ SYNOPSIS ✨

okay so first you literally include this:

#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 πŸ’–

okay so timingsafe_bcmp() and timingsafe_memcmp() lexicographically compare the first len bytes (each interpreted as an unsigned char) pointed to by b1 and b2. the way that's so specific and so iconic ✨

and the main-character part? their running times are independent of the byte sequences compared, making them safe to use for comparing secret values such as cryptographic MACs. that's the whole point, bestie 🫢

in contrast, bcmp(3) and memcmp(3) may short-circuit after finding the first differing byte β€” which is giving leaky timing energy πŸ’€πŸ™ˆ

🫢 RETURN VALUES 🫢

  • timingsafe_bcmp() β€” returns 0 if the byte sequence pointed to by b1 compares equal to the byte sequence pointed to by b2, or not zero if it compares not equal. respectively, no cap ✨
  • timingsafe_memcmp() β€” returns a negative value if the byte sequence pointed to by b1 compares less than the byte sequence pointed to by b2, 0 if it compares equal, or a positive value if it compares greater. again, respectively πŸ’…

🌈 SEE ALSO 🌈

πŸ‘‘ STANDARDS πŸ‘‘

timingsafe_bcmp() and timingsafe_memcmp() are FreeBSD extensions. periodt. πŸ‘‘

πŸ•°οΈ HISTORY πŸ•°οΈ

  • timingsafe_bcmp() first appeared in OpenBSD 4.9.
  • timingsafe_memcmp() first appeared in OpenBSD 5.6.
  • both functions first appeared in FreeBSD 11.1.

xoxo, your Debian bestie πŸ’Œ β€” this cutie is dated August 15, 2016, and it's the TIMINGSAFE_BCMP(3) manual page. slay and stay timing-safe πŸ’…βœ¨

πŸ“¦ where this page comes from
  • freebsd 15.1: base 15.1
  • πŸ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms