Anjay Lite
Loading...
Searching...
No Matches
rng.h File Reference

Platform hook for providing randomness. More...

#include <anj/init.h>
#include <stddef.h>
#include <stdint.h>

Go to the source code of this file.

Functions

int anj_rng_generate (uint8_t *buffer, size_t size)
 

Detailed Description

Platform hook for providing randomness.

This header declares a minimal API that platform integrators must implement to provide entropy to Anjay Lite. It defines:

The implementation may wrap a TRNG, OS CSRNG service, or any other platform-specific entropy source. Quality of generated data directly impacts security features that depend on randomness.

Function Documentation

◆ anj_rng_generate()

int anj_rng_generate ( uint8_t *  buffer,
size_t  size 
)

Generates random bytes and fills buffer with them.

Implementation has to be provided by the application and is used by the library wherever randomness is needed. It is also an entropy source for crypto libraries when default integrations are used (e.g. ANJ_WITH_MBEDTLS).

When using a library with secure connections, a cryptographically secure random number generator (CSRNG) is required. Recommended RNG sources in this case include:

  • The operating system's CSRNG (e.g. Linux getrandom())
  • For embedded/bare-metal systems:
    • (a) A hardware TRNG, if it provides sufficient throughput, or
    • (b) A DRBG, such as NIST SP 800-90A DRBG: CTR_DRBG, MAC_DRBG, or Hash_DRBG seeded by a TRNG
Warning
The library assumes this function returns cryptographically secure bytes whenever security features are enabled. If an application supplies a weaker generator, overall security is undefined.

For case with non-secure connections, any general-purpose PRNG is acceptable.

Parameters
[out]bufferPointer to the buffer where generated bytes will be stored.
sizeNumber of bytes to generate and write to out.
Returns
0 on success, or non-zero error code on failure.