SE RT Services Utilities library

| SE RT Services Utilities library

Functions
Random generation
IFX SE PSA crypto API

## 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] | output | Output buffer for the generated data.
  [in] | output_size | Number of bytes to generate and output.
  [in] | ctx | The 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];
  ifx_se_status_t status;
  uint32_t crc32;
  /* Generate True Random number in a specified range */
  status = ifx_se_generate_random(ifx_se_fih_ptr_encode(random_data),
  ifx_se_fih_uint_encode(RANDOM_DATA_SIZE),
  IFX_SE_NULL_CTX);
  /* ... 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... */
  return IFX_SE_SYSCALL_DATA_INVALID;
  }
  /* ... continue ... */
  IFX_CRC32_CALC
  #define IFX_CRC32_CALC(Q, n)
  Calculates CRC32 value of the data block.
  Definition: ifx_se_crc32.h:71
  IFX_CRC32_CRC_SIZE
  #define IFX_CRC32_CRC_SIZE
  Size of CRC32 data value in bytes.
  Definition: ifx_se_crc32.h:58
  ifx_se_fih_ptr_encode
  __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
  ifx_se_fih_uint_encode
  __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
  ifx_se_fih_uint
  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_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.
  Definition: ifx_se_psacrypto.c:794
  IFX_SE_SUCCESS
  #define IFX_SE_SUCCESS
  Success operation.
  Definition: ifx_se_syscall.h:201
  IFX_SE_SYSCALL_DATA_INVALID
  #define IFX_SE_SYSCALL_DATA_INVALID
  Returned on output data preparation error.
  Definition: ifx_se_syscall.h:242
  IFX_SE_NULL_CTX
  #define IFX_SE_NULL_CTX
  SE RT Services user defined syscall context.
  Definition: ifx_se_syscall.h:303