CRYPTO_VERIFY16(3MONOCYPHER)
π CRYPTO_VERIFY16 π
okay bestie, welcome to Monocypher β the crypto_verify16, crypto_verify32, and crypto_verify64 girlies are here and they are literally the timing-safe data comparison trio you didn't know you needed. π
β¨ SYNOPSIS β¨
#include <monocypher.h>
int
crypto_verify16(const uint8_t a[16], const uint8_t b[16]);
int
crypto_verify32(const uint8_t a[32], const uint8_t b[32]);
int
crypto_verify64(const uint8_t a[64], const uint8_t b[64]);
π¦ DESCRIPTION π¦
so like. crypto stuff constantly needs to compare secrets, or compare values that came from secrets, right? and the standard comparison functions β you know the one, memcmp() β they are NOT it. they dip out the second they spot a difference, and that little early exit leaks info through timing differences. leaking timing = leaking secrets, periodt. π
here's the vibe. imagine a message authentication code (MAC) gets sent over the network with a message, but the correct MAC is secret. an attacker tries a forgery. you do not want to be out here revealing "your MAC is wrong, and it took 384 microseconds to tell you that". because if their next attempt takes 462 microseconds instead? that just told them they guessed one byte correctly. and then they can just keep going, deriving the correct MAC byte by byte, until they successfully forge a message. π this has lead to practical attacks in the past β like, real ones, in the wild.
to avoid such catastrophic failure, crypto_verify16(), crypto_verify32() and crypto_verify64() show up like the main characters they are π«Ά and they give you comparison functions whose timing is independent from the content of their input. iconic. they compare the first 16, 32, or 64 bytes of the two byte arrays a and b. that's it. that's the whole job. π
when in doubt, prefer these functions over memcmp(). no cap.
π RETURN VALUES π
- these functions return
0if the two memory chunks are the same π - and
-1otherwise π
πΈ SEE ALSO πΈ
β HISTORY β
the crypto_verify16(), crypto_verify32(), crypto_verify64() functions first appeared in Monocypher 1.1.0. they replaced the crypto_memcmp() and crypto_zerocmp() functions that were present until Monocypher 1.0.1. glow-up fr fr β¨
okay that's the whole page bestie, ty for coming to my ted talk π§π this one's from Debian, dated March 31, 2020, and it lives in the 3MONOCYPHER manual section β mwah, go compare some secrets safely π
π¦ where this page comes from
- fedora 43: monocypher-devel 3.1.2-12.fc43 Β· LicenseRef-Callaway-BSD OR CC0-1.0
- fedora 43: monocypher-devel 3.1.2-12.fc43 Β· LicenseRef-Callaway-BSD OR CC0-1.0
- fedora 44: monocypher-devel 3.1.2-13.fc44 Β· LicenseRef-Callaway-BSD OR CC0-1.0
- fedora 44: monocypher-devel 3.1.2-13.fc44 Β· LicenseRef-Callaway-BSD OR CC0-1.0
- π the page's license: BSD-2-Clause OR CC0-1.0
- Copyright (c) 2017-2019 Loup Vaillant
- Copyright (c) 2017-2018 Michael Savage
- Copyright (c) 2017, 2019-2020 Fabio Scotoni
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms