doxygen, make constant time for real.

This commit is contained in:
Love Hornquist Astrand
2009-08-18 13:10:23 +02:00
parent b9018774d1
commit 9c95cd27f9

View File

@@ -35,6 +35,23 @@
#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
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;
for (i = 0; i < len; i++)
if (s1[i] != s2[i] && r == 0)
r = s1[i] - s2[i];
return r;
r |= (s1[i] ^ s2[i]);
return !!r;
}