- NetBSD Manual Pages
CONSTTIME_MEMEQUAL(3) NetBSD Library Functions Manual CONSTTIME_MEMEQUAL(3)
Powered by man-cgi (2021-06-01).
Maintained for NetBSD
by Kimmo Suominen.
Based on man-cgi by Panagiotis Christias.
consttime_memequal -- compare byte strings for equality without timing
Standard C Library (libc, -lc)
consttime_memequal(void *b1, void *b2, size_t len);
The consttime_memequal() function compares len bytes of memory at b1 and
b2 for equality, returning 0 if they are distinct and 1 if they are iden-
The time taken by consttime_memequal() depends on len, but not on the
data at b1 or b2. Thus, consttime_memequal() is appropriate for compar-
ing cryptographic secrets, hashes, message authentication codes, etc.,
without leaking information about them through a timing side channel. In
crypto literature, consttime_memequal() is said to take `constant time',
meaning time that does not vary depending on the data it processes.
Note that unlike memcmp(3), consttime_memequal() does not return a lexi-
cographic ordering on the data at b1 and b2; it tells only whether they
are equal. NetBSD does not provide a consttime_memcmp() function,
because all known use cases that require `constant time' memory compari-
son also require only comparison for equality, not lexicographic order-
The consttime_memequal() function appeared in NetBSD 7.0.
NetBSD 10.99 March 23, 2015 NetBSD 10.99