Fix documentation comments.

This commit is contained in:
Aiden Fox Ivey 2025-06-21 00:12:09 -04:00 committed by Jonathan Bennett
parent 98d010761e
commit 1378657206

View File

@ -16,22 +16,23 @@
* @param a First byte array to compare
* @param b Second byte array to compare
* @param len Number of bytes to compare
* @return 0 if arrays are equal, 1 if different or if inputs are invalid
* @return 0 if arrays are equal, -1 if different or if inputs are invalid
*/
static int constant_time_compare(const void *a_, const void *b_, size_t len)
{
// Cast to volatile to prevent the compiler from optimizing out their comparison.
/* Cast to volatile to prevent the compiler from optimizing out their comparison. */
const volatile uint8_t *volatile a = (const volatile uint8_t *volatile) a_;
const volatile uint8_t *volatile b = (const volatile uint8_t *volatile) b_;
if (len == 0)
return 0;
if (a == NULL || b == NULL)
return 1;
return -1;
size_t i;
volatile uint8_t d = 0U;
for (i = 0U; i < len; i++) {
d |= (a[i] ^ b[i]);
}
/* Constant time bit arithmetic to convert d > 0 to -1 and d = 0 to 0. */
return (1 & ((d - 1) >> 8)) - 1;
}