mirror of
https://github.com/meshtastic/firmware.git
synced 2025-08-02 11:55:56 +00:00
Fix documentation comments.
This commit is contained in:
parent
98d010761e
commit
1378657206
@ -16,22 +16,23 @@
|
|||||||
* @param a First byte array to compare
|
* @param a First byte array to compare
|
||||||
* @param b Second byte array to compare
|
* @param b Second byte array to compare
|
||||||
* @param len Number of bytes 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)
|
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 a = (const volatile uint8_t *volatile) a_;
|
||||||
const volatile uint8_t *volatile b = (const volatile uint8_t *volatile) b_;
|
const volatile uint8_t *volatile b = (const volatile uint8_t *volatile) b_;
|
||||||
if (len == 0)
|
if (len == 0)
|
||||||
return 0;
|
return 0;
|
||||||
if (a == NULL || b == NULL)
|
if (a == NULL || b == NULL)
|
||||||
return 1;
|
return -1;
|
||||||
size_t i;
|
size_t i;
|
||||||
volatile uint8_t d = 0U;
|
volatile uint8_t d = 0U;
|
||||||
for (i = 0U; i < len; i++) {
|
for (i = 0U; i < len; i++) {
|
||||||
d |= (a[i] ^ b[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;
|
return (1 & ((d - 1) >> 8)) - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user