CRYPTO_MEMCMP(3)

πŸ“¦ version 4.4.0, in alpine 3.24, arch rolling

πŸ’– NAME πŸ’–

okay so welcome to the CRYPTO_memcmp(3) page from the Library Functions Manual, aka the libcrypto girlie πŸ’… this one is all about constant time memory comparison β€” no cap, it's giving secure little helper energy 🫢


✨ SYNOPSIS ✨

library β€œlibcrypto” #include <openssl/crypto.h>

int
CRYPTO_memcmp(const void *a, const void *b, size_t len);

🌸 DESCRIPTION 🌸

CRYPTO_memcmp() compares the len bytes pointed to by a and b for equality πŸ’–

the way it works timing-wise: it takes an amount of time dependent on len, but independent of the contents of the memory regions pointed to by a and b ✨ so the clock is basically like β€œhow many bytes, bestie?” and not β€œwhat’s inside them?” πŸŽ€


πŸ¦‹ RETURN VALUES πŸ¦‹

  • CRYPTO_memcmp() returns 0 if the content of the memory regions is equal πŸ’š
  • or non-zero otherwise πŸ’€

🌈 HISTORY 🌈

  • CRYPTO_memcmp() first appeared in OpenSSL 1.0.1d πŸ”₯
  • and has been available since OpenBSD 5.6 πŸ‘‘

πŸ’€ BUGS πŸ’€

  • unlike memcmp(3) and timingsafe_memcmp(3), this function cannot be used to order the two memory regions πŸ™ˆ like, it is not a sorting vibe, periodt
  • in the current implementation, the return value is always greater than or equal to 0 🧚

xoxo, this page is from Debian and dated June 8, 2025 πŸŽ€ stay constant-time, bestie πŸ’œ

πŸ“¦ where this page comes from