Go to main content

man pages section 3: Basic Library Functions

Exit Print View

Updated: Thursday, June 13, 2019
 
 

timingsafe_memcmp (3C)

Name

timingsafe_bcmp, timingsafe_memcmp - timing safe memory operations

Synopsis

#include <string.h>

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

Description

The timingsafe_bcmp() and timingsafe_memcmp() functions operate on memory areas that are arrays of bytes bounded by a count, and not terminated by a null character. These functions have an execution time that 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_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.

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, similarly as 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.

Attributes

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

ATTRIBUTE TYPE
ATTRIBUTE VALUE
Interface Stability
Committed
MT-Level
MT-Safe

See Also

attributes(7)

HISTORY

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