XenevaOS
Loading...
Searching...
No Matches
Macros | Typedefs | Functions
constant_time_internal.h File Reference
#include <stdint.h>
#include <stddef.h>
#include "common.h"
#include "constant_time_impl.h"
Include dependency graph for constant_time_internal.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define MBEDTLS_CT_TRUE   ((mbedtls_ct_condition_t) mbedtls_ct_compiler_opaque(SIZE_MAX))
 
#define MBEDTLS_CT_FALSE   ((mbedtls_ct_condition_t) mbedtls_ct_compiler_opaque(0))
 

Typedefs

typedef size_t mbedtls_ct_condition_t
 
typedef size_t mbedtls_ct_uint_t
 
typedef ptrdiff_t mbedtls_ct_int_t
 

Functions

void mbedtls_ct_memcpy_if (mbedtls_ct_condition_t condition, unsigned char *dest, const unsigned char *src1, const unsigned char *src2, size_t len)
 
void mbedtls_ct_memcpy_offset (unsigned char *dest, const unsigned char *src, size_t offset, size_t offset_min, size_t offset_max, size_t len)
 

Macro Definition Documentation

◆ MBEDTLS_CT_FALSE

#define MBEDTLS_CT_FALSE   ((mbedtls_ct_condition_t) mbedtls_ct_compiler_opaque(0))

◆ MBEDTLS_CT_TRUE

#define MBEDTLS_CT_TRUE   ((mbedtls_ct_condition_t) mbedtls_ct_compiler_opaque(SIZE_MAX))

Typedef Documentation

◆ mbedtls_ct_condition_t

Constant-time functions

Copyright The Mbed TLS Contributors SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later

◆ mbedtls_ct_int_t

◆ mbedtls_ct_uint_t

Function Documentation

◆ mbedtls_ct_memcpy_if()

void mbedtls_ct_memcpy_if ( mbedtls_ct_condition_t  condition,
unsigned char *  dest,
const unsigned char *  src1,
const unsigned char *  src2,
size_t  len 
)

Conditional memcpy.

Functionally equivalent to:

if (condition) { memcpy(dest, src1, len); } else { if (src2 != NULL) memcpy(dest, src2, len); }

It will always read len bytes from src1. If src2 != NULL, it will always read len bytes from src2. If src2 == NULL, it will instead read len bytes from dest (as if src2 == dest).

Parameters
conditionThe condition
destSecret. Destination pointer.
src1Secret. Pointer to copy from (if condition == MBEDTLS_CT_TRUE). This may be equal to dest, but may not overlap in other ways.
src2Secret (contents only - may branch to determine if this parameter is NULL). Pointer to copy from (if condition == MBEDTLS_CT_FALSE and src2 is not NULL). May be NULL. This may be equal to dest, but may not overlap it in other ways. It may overlap with src1.
lenNumber of bytes to copy.

◆ mbedtls_ct_memcpy_offset()

void mbedtls_ct_memcpy_offset ( unsigned char *  dest,
const unsigned char *  src,
size_t  offset,
size_t  offset_min,
size_t  offset_max,
size_t  len 
)

Copy data from a secret position.

Functionally equivalent to:

memcpy(dst, src + offset, len)

This function copies len bytes from src + offset to dst, with a code flow and memory access pattern that does not depend on offset, but only on offset_min, offset_max and len.

Note
This function reads from dest, but the value that is read does not influence the result and this function's behavior is well-defined regardless of the contents of the buffers. This may result in false positives from static or dynamic analyzers, especially if dest is not initialized.
Parameters
destSecret. The destination buffer. This must point to a writable buffer of at least len bytes.
srcSecret. The base of the source buffer. This must point to a readable buffer of at least offset_max + len bytes. Shouldn't overlap with dest
offsetSecret. The offset in the source buffer from which to copy. This must be no less than offset_min and no greater than offset_max.
offset_minThe minimal value of offset.
offset_maxThe maximal value of offset.
lenThe number of bytes to copy.