CRYPTO_MEMCMP(3ossl)
π 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()returns0if 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 β
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 beenCRYPTO_memcmp, from OpenSSL, version3.5.6, dated2026-04-07π§ββοΈπ β go forth and compare responsibly, mwah π
π¦ where this page comes from
- freebsd 15.1: base 15.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms