Entropy

Overview

The entropy API provides functions to retrieve entropy values from entropy hardware present on the platform. The entropy APIs are provided for use by the random subsystem and cryptographic services. They are not suitable to be used as random number generation functions.

API Reference

group entropy_interface

Entropy Interface.

Defines

ENTROPY_BUSYWAIT

Driver is allowed to busy-wait for random data to be ready.

Typedefs

typedef int (*entropy_get_entropy_t)(const struct device *dev, uint8_t *buffer, uint16_t length)

Callback API to get entropy.

See entropy_get_entropy() for argument description

Note

This call has to be thread safe to satisfy requirements of the random subsystem.

typedef int (*entropy_get_entropy_isr_t)(const struct device *dev, uint8_t *buffer, uint16_t length, uint32_t flags)

Callback API to get entropy from an ISR.

See entropy_get_entropy_isr() for argument description

Functions

int entropy_get_entropy(const struct device *dev, uint8_t *buffer, uint16_t length)

Fills a buffer with entropy.

Blocks if required in order to generate the necessary random data.

Parameters:
  • dev – Pointer to the entropy device.

  • buffer – Buffer to fill with entropy.

  • length – Buffer length.

Return values:
  • 0 – on success.

  • -ERRNO – errno code on error.

static inline int entropy_get_entropy_isr(const struct device *dev, uint8_t *buffer, uint16_t length, uint32_t flags)

Fills a buffer with entropy in a non-blocking or busy-wait manner.

Callable from ISRs.

Parameters:
  • dev – Pointer to the device structure.

  • buffer – Buffer to fill with entropy.

  • length – Buffer length.

  • flags – Flags to modify the behavior of the call.

Return values:

number – of bytes filled with entropy or -error.

struct entropy_driver_api
#include <entropy.h>

Entropy driver API structure.

This is the mandatory API any Entropy driver needs to expose.