Comment on possible data-dependent branch in `!res'.
This commit is contained in:
parent
c462ebccdd
commit
3db7caeeb3
@ -1,4 +1,4 @@
|
|||||||
/* $NetBSD: consttime_memequal.c,v 1.3 2013/08/28 17:47:07 riastradh Exp $ */
|
/* $NetBSD: consttime_memequal.c,v 1.4 2013/08/28 19:31:14 riastradh Exp $ */
|
||||||
|
|
||||||
#if !defined(_KERNEL) && !defined(_STANDALONE)
|
#if !defined(_KERNEL) && !defined(_STANDALONE)
|
||||||
#include "namespace.h"
|
#include "namespace.h"
|
||||||
@ -18,5 +18,15 @@ consttime_memequal(const void *b1, const void *b2, size_t len)
|
|||||||
|
|
||||||
while (len --)
|
while (len --)
|
||||||
res |= *c1++ ^ *c2++;
|
res |= *c1++ ^ *c2++;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* If the compiler for your favourite architecture generates a
|
||||||
|
* conditional branch for `!res', it will be a data-dependent
|
||||||
|
* branch, in which case this should be replaced by
|
||||||
|
*
|
||||||
|
* return (1 - (1 & ((res - 1) >> 8)));
|
||||||
|
*
|
||||||
|
* or rewritten in assembly.
|
||||||
|
*/
|
||||||
return !res;
|
return !res;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user