Leancrypto 0.12.0
Post-Quantum Cryptographic Library
Loading...
Searching...
No Matches
lc_memory_support.h File Reference
#include "ext_headers.h"
+ Include dependency graph for lc_memory_support.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define LC_MEM_COMMON_ALIGNMENT   (8)
 
#define LC_ALIGNED_BUFFER(name, size, alignment)
 Allocate aligned stack memory.
 
#define LC_ALIGNMENT_MASK(alignment)   (alignment - 1)
 
#define LC_ALIGN_APPLY(x, mask)   (((x) + (mask)) & ~(mask))
 
#define LC_ALIGN(x, a)   LC_ALIGN_APPLY((x), (uintptr_t)(a))
 
#define LC_ALIGN_PTR_64(p, a)   ((uint64_t *)LC_ALIGN((uintptr_t)(p), (a)));
 Align pointer interpreted as 64 bit variable.
 
#define LC_ALIGN_PTR_32(p, a)   ((uint32_t *)LC_ALIGN((uintptr_t)(p), (a)))
 Align pointer interpreted as 32 bit variable.
 
#define LC_ALIGN_PTR_16(p, a)   ((uint16_t *)LC_ALIGN((uintptr_t)(p), (a)))
 Align pointer interpreted as 16 bit variable.
 
#define LC_ALIGN_PTR_8(p, a)   ((uint8_t *)LC_ALIGN((uintptr_t)(p), (a)))
 Align pointer interpreted as 8 bit variable.
 
#define LC_XOR_MIN_ALIGNMENT(min, requested)    ((min < requested) ? (requested) : (min))
 
#define LC_DEF_HOST_X86_64
 
#define LC_XOR_AVX2_ALIGNMENT   (sizeof(uint64_t))
 
#define LC_XOR_ALIGNMENT(min)   LC_XOR_MIN_ALIGNMENT(min, LC_XOR_AVX2_ALIGNMENT)
 

Functions

int lc_alloc_aligned (void **memptr, size_t alignment, size_t size)
 allocate aligned memory up to 8 bytes alignment
 
int lc_alloc_aligned_secure (void **memptr, size_t alignment, size_t size)
 allocate aligned memory up to 8 bytes alignment with additional security precautions
 
int lc_alloc_high_aligned (void **memptr, size_t alignment, size_t size)
 allocate aligned memory with arbitrary alignment
 
void lc_free (void *ptr)
 free the memory allocated with lc_alloc_aligned
 
void lc_free_high_aligned (void *ptr, size_t size)
 free the memory allocated with lc_alloc_high_aligned
 
static int lc_mem_aligned (const uint8_t *ptr, uint32_t alignmask)
 Check if memory pointer is aligned to given alignment mask.
 

Macro Definition Documentation

◆ LC_ALIGN

#define LC_ALIGN ( x,
a )   LC_ALIGN_APPLY((x), (uintptr_t)(a))

Definition at line 48 of file lc_memory_support.h.

◆ LC_ALIGN_APPLY

#define LC_ALIGN_APPLY ( x,
mask )   (((x) + (mask)) & ~(mask))

Definition at line 47 of file lc_memory_support.h.

◆ LC_ALIGN_PTR_16

#define LC_ALIGN_PTR_16 ( p,
a )   ((uint16_t *)LC_ALIGN((uintptr_t)(p), (a)))

Align pointer interpreted as 16 bit variable.

Parameters
ppointer
aalignment

Definition at line 72 of file lc_memory_support.h.

◆ LC_ALIGN_PTR_32

#define LC_ALIGN_PTR_32 ( p,
a )   ((uint32_t *)LC_ALIGN((uintptr_t)(p), (a)))

Align pointer interpreted as 32 bit variable.

Parameters
ppointer
aalignment

Definition at line 64 of file lc_memory_support.h.

◆ LC_ALIGN_PTR_64

#define LC_ALIGN_PTR_64 ( p,
a )   ((uint64_t *)LC_ALIGN((uintptr_t)(p), (a)));

Align pointer interpreted as 64 bit variable.

Parameters
ppointer
aalignment

Definition at line 56 of file lc_memory_support.h.

◆ LC_ALIGN_PTR_8

#define LC_ALIGN_PTR_8 ( p,
a )   ((uint8_t *)LC_ALIGN((uintptr_t)(p), (a)))

Align pointer interpreted as 8 bit variable.

Parameters
ppointer
aalignment

Definition at line 80 of file lc_memory_support.h.

◆ LC_ALIGNED_BUFFER

#define LC_ALIGNED_BUFFER ( name,
size,
alignment )
Value:
uint64_t name[(size + sizeof(uint64_t) - 1) / sizeof(uint64_t)] \
__attribute__((aligned(alignment)))

Allocate aligned stack memory.

The variable can be casted to any structure

Parameters
namevariable name
sizesize of the buffer
alignmentalignment of the buffer

Definition at line 41 of file lc_memory_support.h.

◆ LC_ALIGNMENT_MASK

#define LC_ALIGNMENT_MASK ( alignment)    (alignment - 1)

Definition at line 46 of file lc_memory_support.h.

◆ LC_DEF_HOST_X86_64

#define LC_DEF_HOST_X86_64

Definition at line 89 of file lc_memory_support.h.

◆ LC_MEM_COMMON_ALIGNMENT

#define LC_MEM_COMMON_ALIGNMENT   (8)

Definition at line 30 of file lc_memory_support.h.

◆ LC_XOR_ALIGNMENT

#define LC_XOR_ALIGNMENT ( min)    LC_XOR_MIN_ALIGNMENT(min, LC_XOR_AVX2_ALIGNMENT)

Definition at line 100 of file lc_memory_support.h.

◆ LC_XOR_AVX2_ALIGNMENT

#define LC_XOR_AVX2_ALIGNMENT   (sizeof(uint64_t))

Definition at line 99 of file lc_memory_support.h.

◆ LC_XOR_MIN_ALIGNMENT

#define LC_XOR_MIN_ALIGNMENT ( min,
requested )    ((min < requested) ? (requested) : (min))

Proper memory alignment value when using XOR

Definition at line 85 of file lc_memory_support.h.

Function Documentation

◆ lc_alloc_aligned()

int lc_alloc_aligned ( void ** memptr,
size_t alignment,
size_t size )

allocate aligned memory up to 8 bytes alignment

Parameters
[out]memptrpointer to the newly allocated memory
[in]alignmentalignment of the memory
[in]sizesize of the memory buffer

◆ lc_alloc_aligned_secure()

int lc_alloc_aligned_secure ( void ** memptr,
size_t alignment,
size_t size )

allocate aligned memory up to 8 bytes alignment with additional security precautions

Parameters
[out]memptrpointer to the newly allocated memory
[in]alignmentalignment of the memory
[in]sizesize of the memory buffer

◆ lc_alloc_high_aligned()

int lc_alloc_high_aligned ( void ** memptr,
size_t alignment,
size_t size )

allocate aligned memory with arbitrary alignment

Parameters
[out]memptrpointer to the newly allocated memory
[in]alignmentalignment of the memory
[in]sizesize of the memory buffer

◆ lc_free()

void lc_free ( void * ptr)

free the memory allocated with lc_alloc_aligned

The memory is NOT zeroized.

Parameters
[in]ptrmemory pointer to free

◆ lc_free_high_aligned()

void lc_free_high_aligned ( void * ptr,
size_t size )

free the memory allocated with lc_alloc_high_aligned

The memory is NOT zeroized.

Parameters
[in]ptrmemory pointer to free
[in]sizesize of the memory to free

◆ lc_mem_aligned()

static int lc_mem_aligned ( const uint8_t * ptr,
uint32_t alignmask )
inlinestatic

Check if memory pointer is aligned to given alignment mask.

Parameters
[in]ptrmemory pointer to check
[in]alignmaskalignment mask to check for
Returns
1 if pointer is aligned, 0 if not aligned

Definition at line 173 of file lc_memory_support.h.