CRYPTO_MEMCMP(3ossl)
π CRYPTO_MEMCMP π
okay so bestie, welcome to CRYPTO_memcmp β it's the constant time memory comparison girlie from the OpenSSL 3ossl manual, and she is lowkey iconic. no cap, this is the function you want when you're comparing secrets and you do NOT want the timing of your comparison to snitch on you. π΅οΈββοΈβ¨
β¨ NAME β¨
CRYPTO_memcmp β Constant time memory comparison π
πΈ SYNOPSIS πΈ
#include <openssl/crypto.h>
int CRYPTO_memcmp(const void *a, const void *b, size_t len);
literally the whole vibe right there, bestie π«Ά
π¦ DESCRIPTION π¦
so the CRYPTO_memcmp function compares the len bytes pointed to by a and b β like, are they equal or not, that's the whole question π
and here's the main character energy part: 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 it's not gonna leak anything by being all "hmm let me think about this byte for a sec" π timing-attack-proof queen, we stan π
π RETURN VALUES π
CRYPTO_memcmp()returns0if the memory regions are equal- and nonzero otherwise
that's it, that's the whole return contract, periodt π
π NOTES π
okay so important: unlike memcmp(2), this function cannot be used to order the two memory regions π«
why? because the return value when they differ is undefined, other than being nonzero. so likeβ¦ it tells you that they're different, but it will NOT tell you which one is "bigger" or whatever. do not try to sort with this, bestie, it's giving undefined behaviour and it's not cute π
fr fr β if you need ordering, go get memcmp(2). if you need constant time equality, you're in the right place. iykyk π
π 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>.
and that's the page, bestie!! ππ this lil cutie is from OpenSSL 3.5.0, dated 2026-09-25 β go forth and compare your secrets in constant time, slay π§ββοΈβπ
π¦ where this page comes from
- opensuse-leap 16.0: openssl-3-doc 3.5.0-160000.11.1 Β· Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms