nqcteq — compare
two buffers in constant time
libnoqtis, -lnoqtis
#include
<noqtis.h>
int
nqcteq(const
void *a, const void
*b, size_t
len);
nqcteq()
compares the len bytes at a and
b in time that depends only on
len, not on their contents or on where they first
differ. Use it for MAC tags, shared secrets and anything else an attacker
must not learn byte by byte; use
memcmp(3) only for
public data.
It does not order the buffers: it tells only whether they are equal.
1 when the buffers are equal, 0 otherwise. A len of 0 gives 1.
uint8_t tag[32];
if (nqhmac(NQS256, key, keylen, msg, msglen, tag, sizeof tag) == NQOK &&
nqcteq(tag, received, sizeof tag))
accept();