Skip to content

File syn_random.h

FileList > src > syntropic > util > syn_random.h

Go to the source code of this file

Hardware-agnostic random number generation.

  • #include "../common/syn_compiler.h"
  • #include "../common/syn_defs.h"
  • #include <stddef.h>
  • #include <stdint.h>

Public Functions

Type Name
SYN_WEAK SYN_Status syn_port_random_fill (void * buf, size_t len)
Porting hook: must be implemented by the platform to provide entropy.
SYN_Status syn_random_fallback_fill (void * buf, size_t len)
Internal XOR-shift fallback for random data.
SYN_Status syn_random_fill (void * buf, size_t len)
Fill a buffer with cryptographically secure random bytes.
uint32_t syn_random_range (uint32_t min, uint32_t max)
Generate a random integer within a range [min, max].
uint32_t syn_random_u32 (void)
Generate a random 32-bit integer.

Public Functions Documentation

function syn_port_random_fill

Porting hook: must be implemented by the platform to provide entropy.

SYN_WEAK  SYN_Status syn_port_random_fill (
    void * buf,
    size_t len
) 

Parameters:

  • buf Output buffer.
  • len Number of bytes.

Returns:

SYN_OK on success.


function syn_random_fallback_fill

Internal XOR-shift fallback for random data.

SYN_Status syn_random_fallback_fill (
    void * buf,
    size_t len
) 

Note:

NOT SECURE. Only for testing or desperate fallbacks.

Internal XOR-shift fallback for random data.

Parameters:

  • buf Output buffer.
  • len Length in bytes.

Returns:

SYN_OK.


function syn_random_fill

Fill a buffer with cryptographically secure random bytes.

SYN_Status syn_random_fill (
    void * buf,
    size_t len
) 

This function relies on a platform-specific hardware RNG or secure OS source (via syn_port_random_fill).

Parameters:

  • buf Output buffer.
  • len Number of bytes to generate.

Returns:

SYN_OK on success, SYN_ERROR if the RNG is unavailable.


function syn_random_range

Generate a random integer within a range [min, max].

uint32_t syn_random_range (
    uint32_t min,
    uint32_t max
) 

Parameters:

  • min Minimum value (inclusive).
  • max Maximum value (inclusive).

Returns:

Random value.


function syn_random_u32

Generate a random 32-bit integer.

uint32_t syn_random_u32 (
    void
) 

Returns:

Random value, or 0 on failure (RNG check is recommended for sensitive use).



The documentation for this class was generated from the following file src/syntropic/util/syn_random.h