utils: Add a constant time memeq() variant for cryptographic purposes
This commit is contained in:
@@ -109,6 +109,25 @@ void memwipe_noinline(void *ptr, size_t n)
|
||||
memwipe_inline(ptr, n);
|
||||
}
|
||||
|
||||
/**
|
||||
* Described in header.
|
||||
*/
|
||||
bool memeq_const(const void *x, const void *y, size_t len)
|
||||
{
|
||||
const u_char *a, *b;
|
||||
u_int bad = 0;
|
||||
size_t i;
|
||||
|
||||
a = (const u_char*)x;
|
||||
b = (const u_char*)y;
|
||||
|
||||
for (i = 0; i < len; i++)
|
||||
{
|
||||
bad |= a[i] != b[i];
|
||||
}
|
||||
return !bad;
|
||||
}
|
||||
|
||||
/**
|
||||
* Described in header.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user