TIMINGSAFE_BCMP(3)
π¦ 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()β returns0if the byte sequence pointed to byb1compares equal to the byte sequence pointed to byb2, or not zero if it compares not equal. respectively, no cap β¨timingsafe_memcmp()β returns a negative value if the byte sequence pointed to byb1compares less than the byte sequence pointed to byb2,0if 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
- Copyright (c) 2014 Google Inc
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms