CRYPTO_MEMCMP(3SSL)

πŸ’– CRYPTO_MEMCMP πŸ’–

okay bestie, welcome to CRYPTO_memcmp from the OpenSSL manual, section 3SSL β€” it's the constant time memory comparison girlie and she is lowkey a whole vibe. no cap. πŸŽ€


✨ NAME ✨

CRYPTO_memcmp β€” constant time memory comparison πŸ”₯


✨ SYNOPSIS ✨

#include <openssl/crypto.h>

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

like. that's it. that's the whole thing. she's simple, she's elegant, she's iconic πŸ’…


✨ DESCRIPTION ✨

so CRYPTO_memcmp compares the len bytes pointed to by a and b for equality. bestie, that's the assignment. πŸ’–

and here's the part that makes her main character energy: the amount of time she takes depends on len, but it is independent of the contents of the memory regions pointed to by a and b.

read that again. the time doesn't leak what's inside. she's not gonna tell on you. periodt. πŸ‘‘

that's literally the whole point β€” no timing side-channel, no peeking, just pure equality-checking in constant time. iykyk. πŸ¦‹


✨ RETURN VALUES ✨

  • returns 0 if the memory regions are equal βœ…
  • returns nonzero otherwise ❌

no in-between, no maybe, no situationship. it's giving binary. πŸ’€


✨ NOTES ✨

⚠️ ok so listen β€” unlike memcmp(2), this function cannot be used to order the two memory regions.

why? because when they differ, the return value is undefined, other than just being nonzero.

so don't you dare do if (CRYPTO_memcmp(a, b, len) < 0) and think you're sorting something. you are NOT. the value is undefined fr fr. it's nonzero and that's the only promise you get. πŸ™ˆ


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>.

boring but legally required bestie, we love a compliant queen 🌸


okay bye pookie 🫢 that was CRYPTO_MEMCMP(3SSL) from OpenSSL 4.0.3, dated 2026-09-29. go compare your bytes in constant time and slay πŸ’…βœ¨πŸŒˆ

πŸ“¦ where this page comes from