mbedtls_ct_memcmp() function
Constant-time buffer comparison without branches. This is equivalent to the standard memcmp function, but is likely to be compiled to code using bitwise operations rather than a branch, such that the time taken is constant w.r.t. the data pointed to by \p a and \p b, and w.r.t. whether \p a and \p b are equal or not. It is not constant-time w.r.t. \p n . This function can be used to write constant-time code by replacing branches with bit operations using masks.
Syntax
int mbedtls_ct_memcmp(const void *a,
const void *b,
size_t n);
Arguments
a
Pointer to the first buffer, containing at least \p n bytes. May not be NULL.
b
Pointer to the second buffer, containing at least \p n bytes. May not be NULL.
n
The number of bytes to compare.
Return value
Zero if the contents of the two buffers are the same, otherwise non-zero.
![]()
int mbedtls_ct_memcmp(const void *a,![]()
int mbedtls_ct_memcmp(const void *a,![]()
if (mbedtls_ct_memcmp(tag, check_tag, tag_len) != 0) {![]()
diff = mbedtls_ct_memcmp(tag, check_tag, tag_len);![]()
if (mbedtls_ct_memcmp(hash, actual_hash, actual_hash_length) != 0) {![]()
if (mbedtls_ct_memcmp(hash, actual_hash, actual_hash_length) != 0) {![]()
if (mbedtls_ct_memcmp(mac, actual_mac, actual_mac_length) != 0) {![]()
if (mbedtls_ct_memcmp(verif, sig, ctx->len) != 0) {![]()
if ((ret = mbedtls_ct_memcmp(encoded, encoded_expected,![]()
if (mbedtls_ct_memcmp(cookie + 4, ref_hmac, sizeof(ref_hmac)) != 0) {![]()
if (mbedtls_ct_memcmp(data + rec->data_len, mac_expect,![]()
if (mbedtls_ct_memcmp(mac_peer, mac_expect,![]()
mbedtls_ct_memcmp(buf + 1,![]()
mbedtls_ct_memcmp(ssl->conf->psk_identity, *p, n) != 0) {
mbedtls_ct_memcmp() is called by 18 functions:
![]()
mbedtls_ct_memcmp()
mbedtls_ct_memcmp():
![]()
mbedtls_ct_memcmp()