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

Functions

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

Function Documentation

◆ timingsafe_bcmp()

EXPORT int timingsafe_bcmp ( const void *  b1,
const void *  b2,
size_t  n 
)

Compare all memory bytes.

Return 0 or not zero.

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
nnumber of bytes to compare in both buffers
Precondition
Neither b1 nor b2 shall be a null pointer.
Return values
0if the buffers are equal, or not zero if they are not equal.
See also
memcmp_s(), timingsafe_memcmp()