safec  3.0
Safe C Library - ISO TR24731 Bounds Checking Interface
timingsafe_memcmp.c File Reference
#include "safe_mem_lib.h"
+ Include dependency graph for timingsafe_memcmp.c:

Functions

EXPORT int timingsafe_memcmp (const void *b1, const void *b2, size_t len)
 Compare all memory bytes. More...
 

Function Documentation

◆ timingsafe_memcmp()

EXPORT int timingsafe_memcmp ( const void *  b1,
const void *  b2,
size_t  len 
)

Compare all memory bytes.

Return their difference sign (-1,0,1).

The running time is independent of the byte sequences compared, making them safe to use for comparing secret values such as cryptographic MACs. In contrast, bcmp(3) and memcmp(3) may short-circuit after finding the first differing byte.

Remarks
from OpenBSD
Parameters
b1pointer to memory to compare against
b2pointer to the source memory to compare with b1
lennumber of bytes to compare in both buffers
Precondition
Neither b1 nor b2 shall be a null pointer.
Return values
-1,0,or1
See also
memcmp_s(), timingsafe_bcmp()