The FreeRADIUS server  $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
Macros | Functions
const_time.h File Reference
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define NO_UBSAN_UINT_OVERFLOW
 

Functions

static unsigned int const_time_eq (unsigned int a, unsigned int b)
 
static unsigned int const_time_eq_bin (const void *a, const void *b, size_t len)
 const_time_eq_bin - Constant time memory comparison More...
 
static unsigned char const_time_eq_u8 (unsigned int a, unsigned int b)
 
static unsigned int const_time_fill_msb (unsigned int val)
 const_time_fill_msb - Fill all bits with MSB value More...
 
static unsigned int const_time_is_zero (unsigned int val) NO_UBSAN_UINT_OVERFLOW
 
static int const_time_memcmp (const void *a, const void *b, size_t len)
 
static unsigned int const_time_select (unsigned int mask, unsigned int true_val, unsigned int false_val)
 const_time_select - Constant time unsigned int selection More...
 
static void const_time_select_bin (unsigned char mask, const unsigned char *true_val, const unsigned char *false_val, size_t len, unsigned char *dst)
 const_time_select_bin - Constant time binary buffer selection copy More...
 
static int const_time_select_int (unsigned int mask, int true_val, int false_val)
 const_time_select_int - Constant time int selection More...
 
static char const_time_select_s8 (char mask, char true_val, char false_val)
 const_time_select_s8 - Constant time s8 selection More...
 
static unsigned char const_time_select_u8 (unsigned char mask, unsigned char true_val, unsigned char false_val)
 const_time_select_u8 - Constant time u8 selection More...
 

Macro Definition Documentation

◆ NO_UBSAN_UINT_OVERFLOW

#define NO_UBSAN_UINT_OVERFLOW

Definition at line 22 of file const_time.h.

Function Documentation

◆ const_time_eq()

static unsigned int const_time_eq ( unsigned int  a,
unsigned int  b 
)
inlinestatic

Definition at line 47 of file const_time.h.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ const_time_eq_bin()

static unsigned int const_time_eq_bin ( const void *  a,
const void *  b,
size_t  len 
)
inlinestatic

const_time_eq_bin - Constant time memory comparison

Parameters
aFirst buffer to compare
bSecond buffer to compare
lenNumber of octets to compare
Returns
-1 if buffers are equal, 0 if not

This function is meant for comparing passwords or hash values where difference in execution time or memory access pattern could provide external observer information about the location of the difference in the memory buffers. The return value does not behave like memcmp(), i.e., const_time_eq_bin() cannot be used to sort items into a defined order. Unlike memcmp(), the execution time of const_time_eq_bin() does not depend on the contents of the compared memory buffers, but only on the total compared length.

Definition at line 76 of file const_time.h.

+ Here is the call graph for this function:

◆ const_time_eq_u8()

static unsigned char const_time_eq_u8 ( unsigned int  a,
unsigned int  b 
)
inlinestatic

Definition at line 54 of file const_time.h.

+ Here is the call graph for this function:

◆ const_time_fill_msb()

static unsigned int const_time_fill_msb ( unsigned int  val)
inlinestatic

const_time_fill_msb - Fill all bits with MSB value

Parameters
valInput value
Returns
Value with all the bits set to the MSB of the input val

Definition at line 30 of file const_time.h.

+ Here is the caller graph for this function:

◆ const_time_is_zero()

static unsigned int const_time_is_zero ( unsigned int  val)
inlinestatic

Definition at line 38 of file const_time.h.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ const_time_memcmp()

static int const_time_memcmp ( const void *  a,
const void *  b,
size_t  len 
)
inlinestatic

Definition at line 171 of file const_time.h.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ const_time_select()

static unsigned int const_time_select ( unsigned int  mask,
unsigned int  true_val,
unsigned int  false_val 
)
inlinestatic

const_time_select - Constant time unsigned int selection

Parameters
mask0 (false) or -1 (true) to identify which value to select
true_valValue to select for the true case
false_valValue to select for the false case
Returns
true_val if mask == -1, false_val if mask == 0

Definition at line 98 of file const_time.h.

+ Here is the caller graph for this function:

◆ const_time_select_bin()

static void const_time_select_bin ( unsigned char  mask,
const unsigned char *  true_val,
const unsigned char *  false_val,
size_t  len,
unsigned char *  dst 
)
inlinestatic

const_time_select_bin - Constant time binary buffer selection copy

Parameters
mask0 (false) or -1 (true) to identify which value to copy
true_valBuffer to copy for the true case
false_valBuffer to copy for the false case
lenNumber of octets to copy
dstDestination buffer for the copy

This function copies the specified buffer into the destination buffer using operations with identical memory access pattern regardless of which buffer is being copied.

Definition at line 160 of file const_time.h.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ const_time_select_int()

static int const_time_select_int ( unsigned int  mask,
int  true_val,
int  false_val 
)
inlinestatic

const_time_select_int - Constant time int selection

Parameters
mask0 (false) or -1 (true) to identify which value to select
true_valValue to select for the true case
false_valValue to select for the false case
Returns
true_val if mask == -1, false_val if mask == 0

Definition at line 113 of file const_time.h.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ const_time_select_s8()

static char const_time_select_s8 ( char  mask,
char  true_val,
char  false_val 
)
inlinestatic

const_time_select_s8 - Constant time s8 selection

Parameters
mask0 (false) or -1 (true) to identify which value to select
true_valValue to select for the true case
false_valValue to select for the false case
Returns
true_val if mask == -1, false_val if mask == 0

Definition at line 141 of file const_time.h.

+ Here is the call graph for this function:

◆ const_time_select_u8()

static unsigned char const_time_select_u8 ( unsigned char  mask,
unsigned char  true_val,
unsigned char  false_val 
)
inlinestatic

const_time_select_u8 - Constant time u8 selection

Parameters
mask0 (false) or -1 (true) to identify which value to select
true_valValue to select for the true case
false_valValue to select for the false case
Returns
true_val if mask == -1, false_val if mask == 0

Definition at line 128 of file const_time.h.

+ Here is the call graph for this function:
+ Here is the caller graph for this function: