NCBI C++ ToolKit
Macros | Functions | Variables
alignment.h File Reference

Utility code for dealing with unaligned memory accesses. More...

#include <stdint.h>
#include <string.h>
#include <stdlib.h>
+ Include dependency graph for alignment.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Go to the SVN repository for this file.

Macros

#define MBEDTLS_BYTE_0(x)   ((uint8_t) ((x) & 0xff))
 Byte Reading Macros. More...
 
#define MBEDTLS_BYTE_1(x)   ((uint8_t) (((x) >> 8) & 0xff))
 
#define MBEDTLS_BYTE_2(x)   ((uint8_t) (((x) >> 16) & 0xff))
 
#define MBEDTLS_BYTE_3(x)   ((uint8_t) (((x) >> 24) & 0xff))
 
#define MBEDTLS_BYTE_4(x)   ((uint8_t) (((x) >> 32) & 0xff))
 
#define MBEDTLS_BYTE_5(x)   ((uint8_t) (((x) >> 40) & 0xff))
 
#define MBEDTLS_BYTE_6(x)   ((uint8_t) (((x) >> 48) & 0xff))
 
#define MBEDTLS_BYTE_7(x)   ((uint8_t) (((x) >> 56) & 0xff))
 
#define MBEDTLS_BSWAP16   mbedtls_bswap16
 
#define MBEDTLS_BSWAP32   mbedtls_bswap32
 
#define MBEDTLS_BSWAP64   mbedtls_bswap64
 
#define MBEDTLS_IS_BIG_ENDIAN   (*((unsigned char *) (&mbedtls_byte_order_detector)) == 0x01)
 
#define MBEDTLS_GET_UINT32_BE(data, offset)
 Get the unsigned 32 bits integer corresponding to four bytes in big-endian order (MSB first). More...
 
#define MBEDTLS_PUT_UINT32_BE(n, data, offset)
 Put in memory a 32 bits unsigned integer in big-endian order. More...
 
#define MBEDTLS_GET_UINT32_LE(data, offset)
 Get the unsigned 32 bits integer corresponding to four bytes in little-endian order (LSB first). More...
 
#define MBEDTLS_PUT_UINT32_LE(n, data, offset)
 Put in memory a 32 bits unsigned integer in little-endian order. More...
 
#define MBEDTLS_GET_UINT16_LE(data, offset)
 Get the unsigned 16 bits integer corresponding to two bytes in little-endian order (LSB first). More...
 
#define MBEDTLS_PUT_UINT16_LE(n, data, offset)
 Put in memory a 16 bits unsigned integer in little-endian order. More...
 
#define MBEDTLS_GET_UINT16_BE(data, offset)
 Get the unsigned 16 bits integer corresponding to two bytes in big-endian order (MSB first). More...
 
#define MBEDTLS_PUT_UINT16_BE(n, data, offset)
 Put in memory a 16 bits unsigned integer in big-endian order. More...
 
#define MBEDTLS_GET_UINT24_BE(data, offset)
 Get the unsigned 24 bits integer corresponding to three bytes in big-endian order (MSB first). More...
 
#define MBEDTLS_PUT_UINT24_BE(n, data, offset)
 Put in memory a 24 bits unsigned integer in big-endian order. More...
 
#define MBEDTLS_GET_UINT24_LE(data, offset)
 Get the unsigned 24 bits integer corresponding to three bytes in little-endian order (LSB first). More...
 
#define MBEDTLS_PUT_UINT24_LE(n, data, offset)
 Put in memory a 24 bits unsigned integer in little-endian order. More...
 
#define MBEDTLS_GET_UINT64_BE(data, offset)
 Get the unsigned 64 bits integer corresponding to eight bytes in big-endian order (MSB first). More...
 
#define MBEDTLS_PUT_UINT64_BE(n, data, offset)
 Put in memory a 64 bits unsigned integer in big-endian order. More...
 
#define MBEDTLS_GET_UINT64_LE(data, offset)
 Get the unsigned 64 bits integer corresponding to eight bytes in little-endian order (LSB first). More...
 
#define MBEDTLS_PUT_UINT64_LE(n, data, offset)
 Put in memory a 64 bits unsigned integer in little-endian order. More...
 

Functions

static uint16_t mbedtls_get_unaligned_uint16 (const void *p)
 Read the unsigned 16 bits integer from the given address, which need not be aligned. More...
 
static void mbedtls_put_unaligned_uint16 (void *p, uint16_t x)
 Write the unsigned 16 bits integer to the given address, which need not be aligned. More...
 
static uint32_t mbedtls_get_unaligned_uint32 (const void *p)
 Read the unsigned 32 bits integer from the given address, which need not be aligned. More...
 
static void mbedtls_put_unaligned_uint32 (void *p, uint32_t x)
 Write the unsigned 32 bits integer to the given address, which need not be aligned. More...
 
static uint64_t mbedtls_get_unaligned_uint64 (const void *p)
 Read the unsigned 64 bits integer from the given address, which need not be aligned. More...
 
static void mbedtls_put_unaligned_uint64 (void *p, uint64_t x)
 Write the unsigned 64 bits integer to the given address, which need not be aligned. More...
 
static uint16_t mbedtls_bswap16 (uint16_t x)
 
static uint32_t mbedtls_bswap32 (uint32_t x)
 
static uint64_t mbedtls_bswap64 (uint64_t x)
 

Variables

static const uint16_t mbedtls_byte_order_detector = { 0x100 }
 

Detailed Description

Utility code for dealing with unaligned memory accesses.

Definition in file alignment.h.

Macro Definition Documentation

◆ MBEDTLS_BSWAP16

#define MBEDTLS_BSWAP16   mbedtls_bswap16

Definition at line 350 of file alignment.h.

◆ MBEDTLS_BSWAP32

#define MBEDTLS_BSWAP32   mbedtls_bswap32

Definition at line 362 of file alignment.h.

◆ MBEDTLS_BSWAP64

#define MBEDTLS_BSWAP64   mbedtls_bswap64

Definition at line 378 of file alignment.h.

◆ MBEDTLS_BYTE_0

#define MBEDTLS_BYTE_0 (   x)    ((uint8_t) ((x) & 0xff))

Byte Reading Macros.

Given a multi-byte integer x, MBEDTLS_BYTE_n retrieves the n-th byte from x, where byte 0 is the least significant byte.

Definition at line 268 of file alignment.h.

◆ MBEDTLS_BYTE_1

#define MBEDTLS_BYTE_1 (   x)    ((uint8_t) (((x) >> 8) & 0xff))

Definition at line 269 of file alignment.h.

◆ MBEDTLS_BYTE_2

#define MBEDTLS_BYTE_2 (   x)    ((uint8_t) (((x) >> 16) & 0xff))

Definition at line 270 of file alignment.h.

◆ MBEDTLS_BYTE_3

#define MBEDTLS_BYTE_3 (   x)    ((uint8_t) (((x) >> 24) & 0xff))

Definition at line 271 of file alignment.h.

◆ MBEDTLS_BYTE_4

#define MBEDTLS_BYTE_4 (   x)    ((uint8_t) (((x) >> 32) & 0xff))

Definition at line 272 of file alignment.h.

◆ MBEDTLS_BYTE_5

#define MBEDTLS_BYTE_5 (   x)    ((uint8_t) (((x) >> 40) & 0xff))

Definition at line 273 of file alignment.h.

◆ MBEDTLS_BYTE_6

#define MBEDTLS_BYTE_6 (   x)    ((uint8_t) (((x) >> 48) & 0xff))

Definition at line 274 of file alignment.h.

◆ MBEDTLS_BYTE_7

#define MBEDTLS_BYTE_7 (   x)    ((uint8_t) (((x) >> 56) & 0xff))

Definition at line 275 of file alignment.h.

◆ MBEDTLS_GET_UINT16_BE

#define MBEDTLS_GET_UINT16_BE (   data,
  offset 
)
Value:
)
#define MBEDTLS_IS_BIG_ENDIAN
Definition: alignment.h:390
#define MBEDTLS_BSWAP16
Definition: alignment.h:350
static uint16_t mbedtls_get_unaligned_uint16(const void *p)
Read the unsigned 16 bits integer from the given address, which need not be aligned.
Definition: alignment.h:115
int offset
Definition: replacements.h:160
char data[12]
Definition: iconv.c:80

Get the unsigned 16 bits integer corresponding to two bytes in big-endian order (MSB first).

Parameters
dataBase address of the memory to get the two bytes from.
offsetOffset from data of the first and most significant byte of the two bytes to build the 16 bits unsigned integer from.

Definition at line 521 of file alignment.h.

◆ MBEDTLS_GET_UINT16_LE

#define MBEDTLS_GET_UINT16_LE (   data,
  offset 
)
Value:

Get the unsigned 16 bits integer corresponding to two bytes in little-endian order (LSB first).

Parameters
dataBase address of the memory to get the two bytes from.
offsetOffset from data of the first and least significant byte of the two bytes to build the 16 bits unsigned integer from.

Definition at line 485 of file alignment.h.

◆ MBEDTLS_GET_UINT24_BE

#define MBEDTLS_GET_UINT24_BE (   data,
  offset 
)
Value:
( \
((uint32_t) (data)[(offset)] << 16) \
| ((uint32_t) (data)[(offset) + 1] << 8) \
| ((uint32_t) (data)[(offset) + 2]) \
)
#define uint32_t
Definition: config.h:42

Get the unsigned 24 bits integer corresponding to three bytes in big-endian order (MSB first).

Parameters
dataBase address of the memory to get the three bytes from.
offsetOffset from data of the first and most significant byte of the three bytes to build the 24 bits unsigned integer from.

Definition at line 557 of file alignment.h.

◆ MBEDTLS_GET_UINT24_LE

#define MBEDTLS_GET_UINT24_LE (   data,
  offset 
)
Value:
( \
((uint32_t) (data)[(offset)]) \
| ((uint32_t) (data)[(offset) + 1] << 8) \
| ((uint32_t) (data)[(offset) + 2] << 16) \
)

Get the unsigned 24 bits integer corresponding to three bytes in little-endian order (LSB first).

Parameters
dataBase address of the memory to get the three bytes from.
offsetOffset from data of the first and least significant byte of the three bytes to build the 24 bits unsigned integer from.

Definition at line 589 of file alignment.h.

◆ MBEDTLS_GET_UINT32_BE

#define MBEDTLS_GET_UINT32_BE (   data,
  offset 
)
Value:
)
#define MBEDTLS_BSWAP32
Definition: alignment.h:362
static uint32_t mbedtls_get_unaligned_uint32(const void *p)
Read the unsigned 32 bits integer from the given address, which need not be aligned.
Definition: alignment.h:167

Get the unsigned 32 bits integer corresponding to four bytes in big-endian order (MSB first).

Parameters
dataBase address of the memory to get the four bytes from.
offsetOffset from data of the first and most significant byte of the four bytes to build the 32 bits unsigned integer from.

Definition at line 412 of file alignment.h.

◆ MBEDTLS_GET_UINT32_LE

#define MBEDTLS_GET_UINT32_LE (   data,
  offset 
)
Value:

Get the unsigned 32 bits integer corresponding to four bytes in little-endian order (LSB first).

Parameters
dataBase address of the memory to get the four bytes from.
offsetOffset from data of the first and least significant byte of the four bytes to build the 32 bits unsigned integer from.

Definition at line 448 of file alignment.h.

◆ MBEDTLS_GET_UINT64_BE

#define MBEDTLS_GET_UINT64_BE (   data,
  offset 
)
Value:
)
static uint64_t mbedtls_get_unaligned_uint64(const void *p)
Read the unsigned 64 bits integer from the given address, which need not be aligned.
Definition: alignment.h:219
#define MBEDTLS_BSWAP64
Definition: alignment.h:378

Get the unsigned 64 bits integer corresponding to eight bytes in big-endian order (MSB first).

Parameters
dataBase address of the memory to get the eight bytes from.
offsetOffset from data of the first and most significant byte of the eight bytes to build the 64 bits unsigned integer from.

Definition at line 621 of file alignment.h.

◆ MBEDTLS_GET_UINT64_LE

#define MBEDTLS_GET_UINT64_LE (   data,
  offset 
)
Value:

Get the unsigned 64 bits integer corresponding to eight bytes in little-endian order (LSB first).

Parameters
dataBase address of the memory to get the eight bytes from.
offsetOffset from data of the first and least significant byte of the eight bytes to build the 64 bits unsigned integer from.

Definition at line 657 of file alignment.h.

◆ MBEDTLS_IS_BIG_ENDIAN

#define MBEDTLS_IS_BIG_ENDIAN   (*((unsigned char *) (&mbedtls_byte_order_detector)) == 0x01)

Definition at line 390 of file alignment.h.

◆ MBEDTLS_PUT_UINT16_BE

#define MBEDTLS_PUT_UINT16_BE (   n,
  data,
  offset 
)
Value:
{ \
{ \
mbedtls_put_unaligned_uint16((data) + (offset), (uint16_t) (n)); \
} \
else \
{ \
mbedtls_put_unaligned_uint16((data) + (offset), MBEDTLS_BSWAP16((uint16_t) (n))); \
} \
}
Uint2 uint16_t
yy_size_t n

Put in memory a 16 bits unsigned integer in big-endian order.

Parameters
n16 bits unsigned integer to put in memory.
dataBase address of the memory where to put the 16 bits unsigned integer in.
offsetOffset from data where to put the most significant byte of the 16 bits unsigned integer n.

Definition at line 536 of file alignment.h.

◆ MBEDTLS_PUT_UINT16_LE

#define MBEDTLS_PUT_UINT16_LE (   n,
  data,
  offset 
)
Value:
{ \
{ \
mbedtls_put_unaligned_uint16((data) + (offset), MBEDTLS_BSWAP16((uint16_t) (n))); \
} \
else \
{ \
mbedtls_put_unaligned_uint16((data) + (offset), (uint16_t) (n)); \
} \
}

Put in memory a 16 bits unsigned integer in little-endian order.

Parameters
n16 bits unsigned integer to put in memory.
dataBase address of the memory where to put the 16 bits unsigned integer in.
offsetOffset from data where to put the least significant byte of the 16 bits unsigned integer n.

Definition at line 500 of file alignment.h.

◆ MBEDTLS_PUT_UINT24_BE

#define MBEDTLS_PUT_UINT24_BE (   n,
  data,
  offset 
)
Value:
{ \
(data)[(offset) + 1] = MBEDTLS_BYTE_1(n); \
(data)[(offset) + 2] = MBEDTLS_BYTE_0(n); \
}
#define MBEDTLS_BYTE_1(x)
Definition: alignment.h:269
#define MBEDTLS_BYTE_2(x)
Definition: alignment.h:270
#define MBEDTLS_BYTE_0(x)
Byte Reading Macros.
Definition: alignment.h:268

Put in memory a 24 bits unsigned integer in big-endian order.

Parameters
n24 bits unsigned integer to put in memory.
dataBase address of the memory where to put the 24 bits unsigned integer in.
offsetOffset from data where to put the most significant byte of the 24 bits unsigned integer n.

Definition at line 573 of file alignment.h.

◆ MBEDTLS_PUT_UINT24_LE

#define MBEDTLS_PUT_UINT24_LE (   n,
  data,
  offset 
)
Value:
{ \
(data)[(offset) + 1] = MBEDTLS_BYTE_1(n); \
(data)[(offset) + 2] = MBEDTLS_BYTE_2(n); \
}

Put in memory a 24 bits unsigned integer in little-endian order.

Parameters
n24 bits unsigned integer to put in memory.
dataBase address of the memory where to put the 24 bits unsigned integer in.
offsetOffset from data where to put the least significant byte of the 24 bits unsigned integer n.

Definition at line 605 of file alignment.h.

◆ MBEDTLS_PUT_UINT32_BE

#define MBEDTLS_PUT_UINT32_BE (   n,
  data,
  offset 
)
Value:
{ \
{ \
mbedtls_put_unaligned_uint32((data) + (offset), (uint32_t) (n)); \
} \
else \
{ \
mbedtls_put_unaligned_uint32((data) + (offset), MBEDTLS_BSWAP32((uint32_t) (n))); \
} \
}
Uint4 uint32_t

Put in memory a 32 bits unsigned integer in big-endian order.

Parameters
n32 bits unsigned integer to put in memory.
dataBase address of the memory where to put the 32 bits unsigned integer in.
offsetOffset from data where to put the most significant byte of the 32 bits unsigned integer n.

Definition at line 427 of file alignment.h.

◆ MBEDTLS_PUT_UINT32_LE

#define MBEDTLS_PUT_UINT32_LE (   n,
  data,
  offset 
)
Value:
{ \
{ \
mbedtls_put_unaligned_uint32((data) + (offset), MBEDTLS_BSWAP32((uint32_t) (n))); \
} \
else \
{ \
mbedtls_put_unaligned_uint32((data) + (offset), ((uint32_t) (n))); \
} \
}

Put in memory a 32 bits unsigned integer in little-endian order.

Parameters
n32 bits unsigned integer to put in memory.
dataBase address of the memory where to put the 32 bits unsigned integer in.
offsetOffset from data where to put the least significant byte of the 32 bits unsigned integer n.

Definition at line 464 of file alignment.h.

◆ MBEDTLS_PUT_UINT64_BE

#define MBEDTLS_PUT_UINT64_BE (   n,
  data,
  offset 
)
Value:
{ \
{ \
mbedtls_put_unaligned_uint64((data) + (offset), (uint64_t) (n)); \
} \
else \
{ \
mbedtls_put_unaligned_uint64((data) + (offset), MBEDTLS_BSWAP64((uint64_t) (n))); \
} \
}
Uint8 uint64_t

Put in memory a 64 bits unsigned integer in big-endian order.

Parameters
n64 bits unsigned integer to put in memory.
dataBase address of the memory where to put the 64 bits unsigned integer in.
offsetOffset from data where to put the most significant byte of the 64 bits unsigned integer n.

Definition at line 636 of file alignment.h.

◆ MBEDTLS_PUT_UINT64_LE

#define MBEDTLS_PUT_UINT64_LE (   n,
  data,
  offset 
)
Value:
{ \
{ \
mbedtls_put_unaligned_uint64((data) + (offset), MBEDTLS_BSWAP64((uint64_t) (n))); \
} \
else \
{ \
mbedtls_put_unaligned_uint64((data) + (offset), (uint64_t) (n)); \
} \
}

Put in memory a 64 bits unsigned integer in little-endian order.

Parameters
n64 bits unsigned integer to put in memory.
dataBase address of the memory where to put the 64 bits unsigned integer in.
offsetOffset from data where to put the least significant byte of the 64 bits unsigned integer n.

Definition at line 672 of file alignment.h.

Function Documentation

◆ mbedtls_bswap16()

static uint16_t mbedtls_bswap16 ( uint16_t  x)
inlinestatic

Definition at line 344 of file alignment.h.

◆ mbedtls_bswap32()

static uint32_t mbedtls_bswap32 ( uint32_t  x)
inlinestatic

Definition at line 354 of file alignment.h.

◆ mbedtls_bswap64()

static uint64_t mbedtls_bswap64 ( uint64_t  x)
inlinestatic

Definition at line 366 of file alignment.h.

◆ mbedtls_get_unaligned_uint16()

static uint16_t mbedtls_get_unaligned_uint16 ( const void *  p)
inlinestatic

Read the unsigned 16 bits integer from the given address, which need not be aligned.

Parameters
ppointer to 2 bytes of data
Returns
Data at the given address

Definition at line 115 of file alignment.h.

References r().

◆ mbedtls_get_unaligned_uint32()

static uint32_t mbedtls_get_unaligned_uint32 ( const void *  p)
inlinestatic

Read the unsigned 32 bits integer from the given address, which need not be aligned.

Parameters
ppointer to 4 bytes of data
Returns
Data at the given address

Definition at line 167 of file alignment.h.

References r().

Referenced by mbedtls_ct_memcpy_if(), mbedtls_xor(), and mbedtls_xor_no_simd().

◆ mbedtls_get_unaligned_uint64()

static uint64_t mbedtls_get_unaligned_uint64 ( const void *  p)
inlinestatic

Read the unsigned 64 bits integer from the given address, which need not be aligned.

Parameters
ppointer to 8 bytes of data
Returns
Data at the given address

Definition at line 219 of file alignment.h.

References r().

Referenced by mbedtls_ct_memcpy_if(), mbedtls_xor(), and mbedtls_xor_no_simd().

◆ mbedtls_put_unaligned_uint16()

static void mbedtls_put_unaligned_uint16 ( void *  p,
uint16_t  x 
)
inlinestatic

Write the unsigned 16 bits integer to the given address, which need not be aligned.

Parameters
ppointer to 2 bytes of data
xdata to write

Definition at line 142 of file alignment.h.

◆ mbedtls_put_unaligned_uint32()

static void mbedtls_put_unaligned_uint32 ( void *  p,
uint32_t  x 
)
inlinestatic

Write the unsigned 32 bits integer to the given address, which need not be aligned.

Parameters
ppointer to 4 bytes of data
xdata to write

Definition at line 194 of file alignment.h.

Referenced by mbedtls_ct_memcpy_if(), mbedtls_xor(), and mbedtls_xor_no_simd().

◆ mbedtls_put_unaligned_uint64()

static void mbedtls_put_unaligned_uint64 ( void *  p,
uint64_t  x 
)
inlinestatic

Write the unsigned 64 bits integer to the given address, which need not be aligned.

Parameters
ppointer to 8 bytes of data
xdata to write

Definition at line 246 of file alignment.h.

Referenced by mbedtls_ct_memcpy_if(), mbedtls_xor(), and mbedtls_xor_no_simd().

Variable Documentation

◆ mbedtls_byte_order_detector

const uint16_t mbedtls_byte_order_detector = { 0x100 }
static

Definition at line 389 of file alignment.h.

Modified on Fri Jun 07 13:35:34 2024 by modify_doxy.py rev. 669887