constant_time.h
stddef.h
constant_time.h
stddef.h
int int mbedtls_ct_memcmp (const void *a, const void *b, size_t n) mbedtls_ct_memcmp const void * a const void * b size_t n

Constant-time functions

Copyright The Mbed TLS Contributors SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later Constant-time buffer comparison without branches.

This is equivalent to the standard memcmp function, but is likely to be compiled to code using bitwise operation rather than a branch.

This function can be used to write constant-time code by replacing branches with bit operations using masks.

a

Pointer to the first buffer.

b

Pointer to the second buffer.

n

The number of bytes to compare in the buffer.

Zero if the content of the two buffer is the same, otherwise non-zero.

    #ifndefMBEDTLS_CONSTANT_TIME_H
    #defineMBEDTLS_CONSTANT_TIME_H

    #include<stddef.h>

    intmbedtls_ct_memcmp(constvoid*a,
    constvoid*b,
    size_tn);

    #endif/*MBEDTLS_CONSTANT_TIME_H*/