2016-11-20 00:46:22 +01:00
|
|
|
/**
|
|
|
|
* @file random.h
|
|
|
|
*
|
|
|
|
* @brief Public APIs for the random driver.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 2016 ARM Ltd.
|
|
|
|
*
|
2017-01-19 02:01:01 +01:00
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
2016-11-20 00:46:22 +01:00
|
|
|
*/
|
|
|
|
#ifndef __RANDOM_H__
|
|
|
|
#define __RANDOM_H__
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Random Interface
|
|
|
|
* @defgroup random_interface Random Interface
|
|
|
|
* @ingroup io_interfaces
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
Introduce new sized integer typedefs
This is a start to move away from the C99 {u}int{8,16,32,64}_t types to
Zephyr defined u{8,16,32,64}_t and s{8,16,32,64}_t. This allows Zephyr
to define the sized types in a consistent manor across all the
architectures we support and not conflict with what various compilers
and libc might do with regards to the C99 types.
We introduce <zephyr/types.h> as part of this and have it include
<stdint.h> for now until we transition all the code away from the C99
types.
We go with u{8,16,32,64}_t and s{8,16,32,64}_t as there are some
existing variables defined u8 & u16 as well as to be consistent with
Zephyr naming conventions.
Jira: ZEP-2051
Change-Id: I451fed0623b029d65866622e478225dfab2c0ca8
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2017-04-19 17:32:08 +02:00
|
|
|
#include <zephyr/types.h>
|
2016-11-20 00:46:22 +01:00
|
|
|
#include <device.h>
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @typedef random_get_entropy_t
|
|
|
|
* @brief Callback API to get entropy.
|
|
|
|
*
|
|
|
|
* See random_get_entropy() for argument description
|
|
|
|
*/
|
|
|
|
typedef int (*random_get_entropy_t)(struct device *dev,
|
2017-04-21 17:55:34 +02:00
|
|
|
u8_t *buffer,
|
|
|
|
u16_t length);
|
2016-11-20 00:46:22 +01:00
|
|
|
|
|
|
|
struct random_driver_api {
|
|
|
|
random_get_entropy_t get_entropy;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Get entropy from the random driver.
|
|
|
|
*
|
|
|
|
* Fill a buffer with entropy from the random driver.
|
|
|
|
*
|
|
|
|
* @param dev Pointer to the random device.
|
|
|
|
* @param buffer Buffer to fill with entropy.
|
|
|
|
* @param length Buffer length.
|
|
|
|
* @retval 0 on success.
|
|
|
|
* @retval -ERRNO errno code on error.
|
|
|
|
*/
|
|
|
|
static inline int random_get_entropy(struct device *dev,
|
2017-04-21 17:55:34 +02:00
|
|
|
u8_t *buffer,
|
|
|
|
u16_t length)
|
2016-11-20 00:46:22 +01:00
|
|
|
{
|
|
|
|
const struct random_driver_api *api = dev->driver_api;
|
|
|
|
|
|
|
|
__ASSERT(api->get_entropy, "Callback pointer should not be NULL");
|
|
|
|
return api->get_entropy(dev, buffer, length);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @}
|
|
|
|
*/
|
|
|
|
|
|
|
|
#endif /* __RANDOM_H__ */
|