doxygen, make constant time for real.
This commit is contained in:
@@ -35,6 +35,23 @@
|
|||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constant time compare to memory regions. The reason for making it
|
||||||
|
* constant time is to make sure that timeing information leak from
|
||||||
|
* where in the function the diffrence is.
|
||||||
|
*
|
||||||
|
* ct_memcmp() can't be used to order memory regions like memcmp(),
|
||||||
|
* for example, use ct_memcmp() with qsort().
|
||||||
|
*
|
||||||
|
* @param p1 memory region 1 to compare
|
||||||
|
* @param p2 memory region 2 to compare
|
||||||
|
* @param len length of memory
|
||||||
|
*
|
||||||
|
* @return 0 when the memory regions are equal, non zero if not
|
||||||
|
*
|
||||||
|
* @ingroup roken
|
||||||
|
*/
|
||||||
|
|
||||||
int
|
int
|
||||||
ct_memcmp(const void *p1, const void *p2, size_t len)
|
ct_memcmp(const void *p1, const void *p2, size_t len)
|
||||||
{
|
{
|
||||||
@@ -43,7 +60,6 @@ ct_memcmp(const void *p1, const void *p2, size_t len)
|
|||||||
int r = 0;
|
int r = 0;
|
||||||
|
|
||||||
for (i = 0; i < len; i++)
|
for (i = 0; i < len; i++)
|
||||||
if (s1[i] != s2[i] && r == 0)
|
r |= (s1[i] ^ s2[i]);
|
||||||
r = s1[i] - s2[i];
|
return !!r;
|
||||||
return r;
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user