ARMEBS4  revision-26.06.2015
random.h
Go to the documentation of this file.
1 /**
2  * \file random.h
3  * \brief Random number generation
4  * \author marc dot pignat at hevs dot ch
5  *
6  * STM32F4 cpu have got a hardware based random number generator. Let expose it.
7  * It should be sufficiently random to roll a dice, but care must be taken if
8  * you want cryptographically secure random numbers.
9  * \ingroupg misc
10  * @{
11  ***************************************************************************/
12 #ifndef HEIVS_RANDOM_H
13 #define HEIVS_RANDOM_H
14 
15 #include <stdint.h>
16 #include "heivs/error.h"
17 #include "heivs/time.h"
18 
19 #ifdef __cplusplus
20  extern "C" {
21 #endif
22 
23 /**
24  * \brief Initialize the HW random number generator
25  */
26 status_e random_init(void);
27 
28 /**
29  * \brief Disable the HW random number generator
30  */
32 
33 /*
34  * \brief Get random data
35  * \param data where data should be written
36  * \param timeout_ms, the timeout in ms
37  *
38  * \return #NO_ERROR for no problem
39  *
40  * The returned data is only valid when the return value is NO_ERROR.
41  */
42 status_e random_get(uint32_t *data, uint32_t timeout_ms);
43 
44 /*
45  * \brief Get random data
46  * \param data where data should be written
47  *
48  * \return #NO_ERROR for no problem
49  *
50  * The returned data is only valid when the return value is NO_ERROR.
51  *
52  * When the return value is ERROR_HW_FAILED, re-call random_init()
53  * When the return value is ERROR_AGAIN, retry later (the entropy pool is empty)
54  *
55  * \warning return value may be inaccurate if not initialized
56  * \see random_init
57  */
58 status_e random_get_nowait(uint32_t *data);
59 
60 #ifdef __cplusplus
61  }
62 #endif
63 
64 /**
65  * @}
66  */
67 #endif /* HEIVS_RANDOM_H */
status_e random_init(void)
Initialize the HW random number generator.
Definition: stm32_random.c:11
simple time abstraction
Errors definitions.
status_e random_suspend(void)
Disable the HW random number generator.
Definition: stm32_random.c:22
status_e
Known errors.
Definition: error.h:21