SE RT Services Utilities library
Random generation

General Description

Random generation definitions.

Functions

ifx_se_status_t ifx_se_generate_random (ifx_se_fih_ptr_t output, ifx_se_fih_t output_size, void *ctx)
 Generate random bytes. More...
 

Function Documentation

◆ ifx_se_generate_random()

ifx_se_status_t ifx_se_generate_random ( ifx_se_fih_ptr_t  output,
ifx_se_fih_t  output_size,
void *  ctx 
)

Generate random bytes.

Warning
This function can fail! Callers MUST check the return status and MUST NOT use the content of the output buffer if the return status is not IFX_SE_SUCCESS.
Note
To generate a key, use ifx_se_generate_key() instead.
Parameters
[out]outputOutput buffer for the generated data.
[in]output_sizeNumber of bytes to generate and output.
[in]ctxThe pointer to the SE syscall context that contain a special syscall data (IPC release callback etc).
Warning
The output buffer MUST be larger than output_size by at least IFX_CRC32_CRC_SIZE (4 bytes) to save the CRC32 value at the end of the data block
Return values
IFX_SE_SUCCESS
IFX_SE_ERROR_NOT_SUPPORTED
IFX_SE_ERROR_INSUFFICIENT_ENTROPY
IFX_SE_ERROR_INSUFFICIENT_MEMORY
IFX_SE_ERROR_COMMUNICATION_FAILURE
IFX_SE_ERROR_HARDWARE_FAILURE
IFX_SE_ERROR_CORRUPTION_DETECTED
Function Usage
/* Amount of random data to generate */
#define RANDOM_DATA_SIZE 32
/* The output buffer MUST be larger than output_size by at least
IFX_CRC32_CRC_SIZE (4 bytes) to save the CRC32 value at the end
of the data block */
uint8_t random_data[RANDOM_DATA_SIZE + IFX_CRC32_CRC_SIZE];
uint32_t crc32;
/* Generate True Random number in a specified range */
ifx_se_fih_uint_encode(RANDOM_DATA_SIZE),
/* ... check for errors... */
ifx_se_status_t status_success = IFX_SE_SUCCESS;
if (!IFX_SE_STATUS_CHECK(status, status_success))
{
/* ... process random performing error... */
return status;
}
memcpy(&crc32, random_data + RANDOM_DATA_SIZE, IFX_CRC32_CRC_SIZE);
if (crc32 == IFX_CRC32_CALC(random_data, RANDOM_DATA_SIZE))
{
/* ... process random data integrity error... */
}
/* ... continue ... */
#define IFX_CRC32_CALC(Q, n)
Calculates CRC32 value of the data block.
Definition: ifx_se_crc32.h:71
#define IFX_CRC32_CRC_SIZE
Size of CRC32 data value in bytes.
Definition: ifx_se_crc32.h:58
__STATIC_FORCEINLINE ifx_se_fih_ptr_t ifx_se_fih_ptr_encode(const void *x)
Convert pointer address to a ifx_se_fih_ptr_t.
Definition: ifx_se_fih.h:559
__STATIC_FORCEINLINE ifx_se_fih_uint ifx_se_fih_uint_encode(uint32_t x)
Convert an unsigned int to a ifx_se_fih_uint.
Definition: ifx_se_fih.h:201
All ints are replaced with two int - the normal one and a backup which is XORed with the mask.
Definition: ifx_se_fih.h:112
ifx_se_status_t ifx_se_generate_random(ifx_se_fih_ptr_t output, ifx_se_fih_t output_size, void *ctx)
Generate random bytes.
Definition: ifx_se_psacrypto.c:794
#define IFX_SE_SUCCESS
Success operation.
Definition: ifx_se_syscall.h:201
#define IFX_SE_SYSCALL_DATA_INVALID
Returned on output data preparation error.
Definition: ifx_se_syscall.h:242
#define IFX_SE_NULL_CTX
SE RT Services user defined syscall context.
Definition: ifx_se_syscall.h:303