XenevaOS
Loading...
Searching...
No Matches
Macros | Functions
common.h File Reference

Utility macros for internal use in the library. More...

#include "mbedtls/build_info.h"
#include "alignment.h"
#include <assert.h>
#include <stddef.h>
#include <stdint.h>
Include dependency graph for common.h:

Go to the source code of this file.

Macros

#define MBEDTLS_STATIC_TESTABLE   static
 
#define MBEDTLS_TEST_HOOK_TEST_ASSERT(TEST)
 
#define ARRAY_LENGTH_UNSAFE(array)    (sizeof(array) / sizeof(*(array)))
 
#define ARRAY_LENGTH(array)   ARRAY_LENGTH_UNSAFE(array)
 
#define MBEDTLS_ALLOW_PRIVATE_ACCESS
 
#define asm   __asm__
 
#define MBEDTLS_STATIC_ASSERT(expr, msg)    struct ISO_C_does_not_allow_extra_semicolon_outside_of_a_function
 
#define MBEDTLS_HAS_BUILTIN(x)   0
 
#define MBEDTLS_LIKELY(x)   x
 
#define MBEDTLS_UNLIKELY(x)   x
 
#define MBEDTLS_ASSUME(x)   do { } while (0)
 
#define MBEDTLS_OPTIMIZE_FOR_PERFORMANCE
 
#define MBEDTLS_MAYBE_UNUSED
 
#define MBEDTLS_ATTRIBUTE_UNTERMINATED_STRING
 

Functions

void mbedtls_zeroize_and_free (void *buf, size_t len)
 Securely zeroize a buffer then free it.
 

Detailed Description

Utility macros for internal use in the library.

Macro Definition Documentation

◆ ARRAY_LENGTH

#define ARRAY_LENGTH (   array)    ARRAY_LENGTH_UNSAFE(array)

Return the number of elements of a static or stack array.

Parameters
arrayA value of array (not pointer) type.
Returns
The number of elements of the array.

◆ ARRAY_LENGTH_UNSAFE

#define ARRAY_LENGTH_UNSAFE (   array)     (sizeof(array) / sizeof(*(array)))

◆ asm

#define asm   __asm__

◆ MBEDTLS_ALLOW_PRIVATE_ACCESS

#define MBEDTLS_ALLOW_PRIVATE_ACCESS

Allow library to access its structs' private members.

Although structs defined in header files are publicly available, their members are private and should not be accessed by the user.

◆ MBEDTLS_ASSUME

#define MBEDTLS_ASSUME (   x)    do { } while (0)

◆ MBEDTLS_ATTRIBUTE_UNTERMINATED_STRING

#define MBEDTLS_ATTRIBUTE_UNTERMINATED_STRING

◆ MBEDTLS_HAS_BUILTIN

#define MBEDTLS_HAS_BUILTIN (   x)    0

◆ MBEDTLS_LIKELY

#define MBEDTLS_LIKELY (   x)    x

◆ MBEDTLS_MAYBE_UNUSED

#define MBEDTLS_MAYBE_UNUSED

◆ MBEDTLS_OPTIMIZE_FOR_PERFORMANCE

#define MBEDTLS_OPTIMIZE_FOR_PERFORMANCE

◆ MBEDTLS_STATIC_ASSERT

#define MBEDTLS_STATIC_ASSERT (   expr,
  msg 
)     struct ISO_C_does_not_allow_extra_semicolon_outside_of_a_function

◆ MBEDTLS_STATIC_TESTABLE

#define MBEDTLS_STATIC_TESTABLE   static

Helper to define a function as static except when building invasive tests.

If a function is only used inside its own source file and should be declared static to allow the compiler to optimize for code size, but that function has unit tests, define it with

MBEDTLS_STATIC_TESTABLE int mbedtls_foo(...) { ... }
#define MBEDTLS_STATIC_TESTABLE
Definition common.h:48

and declare it in a header in the library/ directory with

#if defined(MBEDTLS_TEST_HOOKS)
int mbedtls_foo(...);
#endif

◆ MBEDTLS_TEST_HOOK_TEST_ASSERT

#define MBEDTLS_TEST_HOOK_TEST_ASSERT (   TEST)

◆ MBEDTLS_UNLIKELY

#define MBEDTLS_UNLIKELY (   x)    x

Function Documentation

◆ mbedtls_zeroize_and_free()

void mbedtls_zeroize_and_free ( void *  buf,
size_t  len 
)

Securely zeroize a buffer then free it.

         Similar to making consecutive calls to
         \c mbedtls_platform_zeroize() and \c mbedtls_free(), but has
         code size savings, and potential for optimisation in the future.

         Guaranteed to be a no-op if \p buf is \c NULL and \p len is 0.
Parameters
bufBuffer to be zeroized then freed.
lenLength of the buffer in bytes