Go to main content

man pages section 3: Basic Library Functions

Exit Print View

Updated: Wednesday, July 27, 2022
 
 

timingsafe_bcmp(3C)

Name

timingsafe_memcmp, timingsafe_bcmp - timing safe memory operations

Synopsis

#include <string.h>

int timingsafe_memcmp(const void *s1, const void *s2, size_t n);
int timingsafe_bcmp(const void *s1, const void *s2, size_t n);

Description

The timingsafe_memcmp() and timingsafe_bcmp() functions operate on memory areas that are arrays of bytes bounded by a count. The execution times of these functions are not affected by the memory contents of their arguments. They are designed to be used in timing sensitive use cases, for example, cryptography.

The timingsafe_memcmp() function compares its arguments looking at the first n bytes where each is interpreted as an unsigned character. It returns an integer less than, equal to, or greater than 0, corresponding to whether s1 is lexicographically less than, equal to, or greater than s2 when taken to be unsigned characters. The timingsafe_memcmp() function always returns 0 when n is 0.

The timingsafe_bcmp() function compares the first n bytes of its arguments, returning 0 if they are identical and 1 otherwise. The timingsafe_bcmp() function always returns 0 when n is 0.

Attributes

See attributes(7) for descriptions of the following attributes:

ATTRIBUTE TYPE
ATTRIBUTE VALUE
Interface Stability
Committed
MT-Level
Async-Signal-Safe
Standard
None

See Also

bcmp(3C), memcmp(3C), attributes(7)

History

The timingsafe_memcmp() and timingsafe_bcmp() functions were added to Oracle Solaris in the 11.4.0 release.