hsw-nbt 1.2.0
OPTIGA Authenticate NBT Host Library for C
Data Structures | Macros | Functions
ifx-utils.h File Reference

Provides utility functions and macros. More...

#include <stdint.h>
#include "ifx-utils-lib.h"
#include <string.h>

Go to the source code of this file.

Data Structures

struct  ifx_blob_t
 Data storage for data and data length where both are required as parameters. More...
 

Macros

#define IFX_MEMCPY(dest, src, size)    memcpy(dest, src, size) /* flawfinder: ignore*/
 Allows custom definition of memory copy API. By default, memcpy() from string.h is used.
 
#define IFX_MEMCMP(first_memory, second_memory, size)    memcmp(first_memory, second_memory, size)
 Allows custom definition of memory compare API. By default, memcmp() from string.h is used.
 
#define IFX_MEMSET(buffer, value, size)   memset(buffer, value, size)
 Allows custom definition of memory set API. By default, memset() from string.h is used.
 
#define IFX_FREE(buffer)   free(buffer)
 Allows custom definition of free(free pointer) API. By default, free() from string.h is used.
 
#define IFX_UNUSED_VARIABLE(var)   (void) var
 Macro to suppress unused variable warnings.
 
#define IFX_UTILS_CONCAT   UINT8_C(0x01)
 Function identifier of utils concat for ifx_blob_t type data.
 
#define IFX_ENABLE   UINT8_C(0x01)
 Defines 0x01.
 
#define IFX_DISABLE   UINT8_C(0x00)
 Defines 0x00.
 
#define IFX_LITTLE_ENDIAN   IFX_ENABLE
 Indicates Endianness of architecture.
 
#define IFX_VALIDATE_NULL_PTR   IFX_ENABLE
 Validation of NULL pointer.
 
#define IFX_VALIDATE_NULL_PTR_BLOB(blob)   (blob == NULL || blob->buffer == NULL)
 Macro to check if the blob or its buffer is NULL.
 
#define IFX_VALIDATE_NULL_PTR_MEMORY(data)   (data == NULL)
 Macro to check if the memory address is pointing to NULL.
 
#define IFX_GET_LOWER_BYTE(p1_value, p2_value)    (p1_value) = (((p2_value) & 0xff00) >> 8);
 Stores lower(big endian) byte from p2 to p1.
 
#define IFX_GET_UPPER_BYTE(p1_value, p2_value)    (p1_value) = ((p2_value) & 0x00FF);
 Stores upper(big endian) byte from p2 to p1.
 
#define IFX_READ_U32(buffer, u32value)
 Macro for little endian/big endian read operation To read array data to a word variable.
 
#define IFX_UPDATE_U32(buffer, u32value)
 Macro for little endian/big endian update operation To update array data with value of word variable.
 

Functions

ifx_status_t ifx_utils_concat (const ifx_blob_t *append_data, ifx_blob_t *result)
 Concatenates the buffers of two ifx_blob_t type data structures. Buffer field of append_data will be appended at end of the buffer field of result.
 

Detailed Description

Provides utility functions and macros.

Definition in file ifx-utils.h.

Macro Definition Documentation

◆ IFX_DISABLE

#define IFX_DISABLE   UINT8_C(0x00)

Defines 0x00.

Definition at line 79 of file ifx-utils.h.

◆ IFX_ENABLE

#define IFX_ENABLE   UINT8_C(0x01)

Defines 0x01.

Definition at line 74 of file ifx-utils.h.

◆ IFX_FREE

#define IFX_FREE ( buffer)    free(buffer)

Allows custom definition of free(free pointer) API. By default, free() from string.h is used.

Definition at line 52 of file ifx-utils.h.

◆ IFX_GET_LOWER_BYTE

#define IFX_GET_LOWER_BYTE ( p1_value,
p2_value )    (p1_value) = (((p2_value) & 0xff00) >> 8);

Stores lower(big endian) byte from p2 to p1.

Definition at line 141 of file ifx-utils.h.

141#define IFX_GET_LOWER_BYTE(p1_value, p2_value) \
142 (p1_value) = (((p2_value) & 0xff00) >> 8);

◆ IFX_GET_UPPER_BYTE

#define IFX_GET_UPPER_BYTE ( p1_value,
p2_value )    (p1_value) = ((p2_value) & 0x00FF);

Stores upper(big endian) byte from p2 to p1.

Definition at line 147 of file ifx-utils.h.

147#define IFX_GET_UPPER_BYTE(p1_value, p2_value) \
148 (p1_value) = ((p2_value) & 0x00FF);

◆ IFX_LITTLE_ENDIAN

#define IFX_LITTLE_ENDIAN   IFX_ENABLE

Indicates Endianness of architecture.

Definition at line 84 of file ifx-utils.h.

◆ IFX_MEMCMP

#define IFX_MEMCMP ( first_memory,
second_memory,
size )    memcmp(first_memory, second_memory, size)

Allows custom definition of memory compare API. By default, memcmp() from string.h is used.

Definition at line 35 of file ifx-utils.h.

35#define IFX_MEMCMP(first_memory, second_memory, size) \
36 memcmp(first_memory, second_memory, size)

◆ IFX_MEMCPY

#define IFX_MEMCPY ( dest,
src,
size )    memcpy(dest, src, size) /* flawfinder: ignore*/

Allows custom definition of memory copy API. By default, memcpy() from string.h is used.

Definition at line 25 of file ifx-utils.h.

25#define IFX_MEMCPY(dest, src, size) \
26 memcpy(dest, src, size) /* flawfinder: ignore*/

◆ IFX_MEMSET

#define IFX_MEMSET ( buffer,
value,
size )   memset(buffer, value, size)

Allows custom definition of memory set API. By default, memset() from string.h is used.

Definition at line 44 of file ifx-utils.h.

◆ IFX_READ_U32

#define IFX_READ_U32 ( buffer,
u32value )
Value:
{ \
u32value = ((((*(uint8_t *) (buffer)) << 24) & 0XFF000000) | \
(((*(uint8_t *) (buffer + 1)) << 16) & 0X00FF0000) | \
(((*(uint8_t *) (buffer + 2)) << 8) & 0X0000FF00) | \
(((*(uint8_t *) (buffer + 3)) & 0X000000FF))); \
}

Macro for little endian/big endian read operation To read array data to a word variable.

Read data from 'Buffer' Array and update 'Value' variable, Array is input parameter and value is output parameter

Definition at line 159 of file ifx-utils.h.

159#define IFX_READ_U32(buffer, u32value) \
160 { \
161 u32value = ((((*(uint8_t *) (buffer)) << 24) & 0XFF000000) | \
162 (((*(uint8_t *) (buffer + 1)) << 16) & 0X00FF0000) | \
163 (((*(uint8_t *) (buffer + 2)) << 8) & 0X0000FF00) | \
164 (((*(uint8_t *) (buffer + 3)) & 0X000000FF))); \
165 }

◆ IFX_UNUSED_VARIABLE

#define IFX_UNUSED_VARIABLE ( var)    (void) var

Macro to suppress unused variable warnings.

Definition at line 62 of file ifx-utils.h.

◆ IFX_UPDATE_U32

#define IFX_UPDATE_U32 ( buffer,
u32value )
Value:
{ \
*(uint8_t *) buffer = (uint8_t) ((u32value >> 24) & 0xFF); \
*(uint8_t *) (buffer + 1) = (uint8_t) ((u32value >> 16) & 0xFF); \
*(uint8_t *) (buffer + 2) = (uint8_t) ((u32value >> 8) & 0xFF); \
*(uint8_t *) (buffer + 3) = (uint8_t) (u32value); \
}

Macro for little endian/big endian update operation To update array data with value of word variable.

Read data from 'Value' variable and update 'Buffer' Array, Array is output parameter and value is input parameter

Definition at line 176 of file ifx-utils.h.

176#define IFX_UPDATE_U32(buffer, u32value) \
177 { \
178 *(uint8_t *) buffer = (uint8_t) ((u32value >> 24) & 0xFF); \
179 *(uint8_t *) (buffer + 1) = (uint8_t) ((u32value >> 16) & 0xFF); \
180 *(uint8_t *) (buffer + 2) = (uint8_t) ((u32value >> 8) & 0xFF); \
181 *(uint8_t *) (buffer + 3) = (uint8_t) (u32value); \
182 }

◆ IFX_UTILS_CONCAT

#define IFX_UTILS_CONCAT   UINT8_C(0x01)

Function identifier of utils concat for ifx_blob_t type data.

Definition at line 69 of file ifx-utils.h.

◆ IFX_VALIDATE_NULL_PTR

#define IFX_VALIDATE_NULL_PTR   IFX_ENABLE

Validation of NULL pointer.

Definition at line 89 of file ifx-utils.h.

◆ IFX_VALIDATE_NULL_PTR_BLOB

#define IFX_VALIDATE_NULL_PTR_BLOB ( blob)    (blob == NULL || blob->buffer == NULL)

Macro to check if the blob or its buffer is NULL.

Definition at line 94 of file ifx-utils.h.

◆ IFX_VALIDATE_NULL_PTR_MEMORY

#define IFX_VALIDATE_NULL_PTR_MEMORY ( data)    (data == NULL)

Macro to check if the memory address is pointing to NULL.

Definition at line 99 of file ifx-utils.h.

Function Documentation

◆ ifx_utils_concat()

ifx_status_t ifx_utils_concat ( const ifx_blob_t * append_data,
ifx_blob_t * result )

Concatenates the buffers of two ifx_blob_t type data structures. Buffer field of append_data will be appended at end of the buffer field of result.

Note
In this API, param 'result->buffer' will be reallocated with the memory needed to store the concatenated buffer value. User need to take care to free the memory if required.
Parameters
[in]append_dataData to be appended.
[in,out]resultDestination in which the data will be appended.
Returns
ifx_status_t
Return values
IFX_ILLEGAL_ARGUMENT: If invalid/NULL parameter is passed to function
IFX_OUT_OF_MEMORY: If memory allocation fails