CRYPTO_MEMCMP(3ossl)

πŸ’– CRYPTO_MEMCMP πŸ’–

okay bestie, welcome to the 3ossl corner of the OpenSSL manual, where we're talking about CRYPTO_memcmp β€” the constant time memory comparison girlie. yes, that's the whole name. it's literally just CRYPTO_memcmp, and she does exactly one thing and she does it immaculately. ✨


🌸 SYNOPSIS 🌸

#include <openssl/crypto.h>

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

that's it. that's the whole vibe. three args, one int, no drama. πŸŽ€


πŸ¦‹ DESCRIPTION πŸ¦‹

so here's the tea: CRYPTO_memcmp compares the len bytes pointed to by a and b for equality. equal or not equal, that's the only question she answers. πŸ’…

and the iconic part? the way that it takes an amount of time that depends on len, but is independent of the contents of the memory regions pointed to by a and b. no cap. your secrets stay secret because the clock doesn't snitch. πŸ”₯

like, she's not reading your bytes and going "ooooh interesting" and taking longer. she does not care. she is unbothered. she is constant time. πŸ‘‘

⭐ RETURN VALUES ⭐

  • CRYPTO_memcmp() returns 0 if the memory regions are equal β€” slay, match, we love that πŸ’–
  • and it returns nonzero otherwise β€” nope, not the same, moving on πŸ™ˆ

πŸ’€ NOTES πŸ’€

okay this is the important warning bestie, don't skip it:

unlike memcmp(2), this function cannot be used to order the two memory regions. because when they differ, the return value is undefined, other than being nonzero. so like... it's nonzero, but which nonzero? nobody knows. it's giving mystery. it's giving chaos. 🫠

so if you were about to do if (CRYPTO_memcmp(a, b, len) < 0) β€” no. stop. that's not a thing. it compares for equality, periodt. 🌈


Copyright 2019 The OpenSSL Project Authors. All Rights Reserved.

Licensed under the Apache License 2.0 (the "License"). You may not use this file except in compliance with the License. You can obtain a copy in the file LICENSE in the source distribution or at <https://www.openssl.org/source/license.html>.


and that's the whole page, bestie 🫢 this was CRYPTO_memcmp(3ossl) from the OpenSSL 3.5.9 manual, dated 2026-09-29. stay constant time, stay safe, and go compare some memory the correct way. mwah πŸ’‹βœ¨

πŸ“¦ where this page comes from