Function anj_rng_generate

Function Documentation

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 getentropy())

  • 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

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

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.

Parameters:
  • buffer[out] Pointer to the buffer where generated bytes will be stored.

  • size – Number of bytes to generate and write to out.

Returns:

0 on success, or non-zero error code on failure.