CRYPTO_MEMCMP(3ossl)

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

πŸ’– CRYPTO_MEMCMP πŸ’–

ok so bestie, welcome to the tea on CRYPTO_memcmp β€” it's a manual page from the OpenSSL fam (that's the <pink>3ossl</pink> section suffix you'll see floating around, iykyk), and honestly? she's a baddie with one very specific job. Let's get into it ✨


🌸 NAME 🌸

CRYPTO_memcmp β€” constant time memory comparison. literally that's her whole thing πŸ’…


πŸŽ€ SYNOPSIS πŸŽ€

#include <openssl/crypto.h>

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

like yes, that's the whole vibe. three args, no drama πŸ¦‹


✨ DESCRIPTION ✨

ok so picture this: the CRYPTO_memcmp function compares the len bytes pointed to by a and b for equality. that's it, that's the mission 🫢

but here's the iconic part β€” the way she does it: it takes an amount of time dependent on len, but independent of the contents of the memory regions pointed to by a and b. no cap. she does not peek at what's inside and go "ooh early exit 😏". she just vibes for the same amount of time regardless, and that's the whole point πŸ’€πŸ”₯


🌈 RETURN VALUES 🌈

  • CRYPTO_memcmp() returns 0 if the memory regions are equal
  • and nonzero otherwise πŸ‘‘

periodt.


πŸ’œ NOTES πŸ’œ

so here's the lowkey important thing: unlike memcmp(2), this function cannot be used to order the two memory regions. like, do not try to sort with her, she will not help you 😭

why? because the return value when they differ is undefined, other than being nonzero. so you get "yep, they're different" energy and absolutely nothing else. don't read into it, don't build a comparator on it, don't make it a thing πŸ™ˆ

fr fr β€” the only guarantee you're getting on inequality is "nonzero". that's the contract. respect it πŸ’…

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


ok that's the whole page bestie β€” she's short, she's sweet, she's constant time, and she ate πŸ’–βœ¨

this has been CRYPTO_memcmp, from OpenSSL, version 3.5.6, dated 2026-04-07 πŸ§šβ€β™€οΈπŸ“ β€” go forth and compare responsibly, mwah πŸ’œ
πŸ“¦ where this page comes from