1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
53
/* ... */
#include "mbedtls_config.h"
#ifdef MBEDTLS_ENTROPY_HARDWARE_ALT
#include "main.h"
#include <string.h>
#include "mbedtls/entropy_poll.h"
extern RNG_HandleTypeDef RngHandle;
int mbedtls_hardware_poll( void *Data, unsigned char *Output, size_t Len, size_t *oLen )
{
uint32_t index;
uint32_t randomValue;
for (index = 0; index < Len/4; index++)
{
if (HAL_RNG_GenerateRandomNumber(&RngHandle, &randomValue) == HAL_OK)
{
*oLen += 4;
memset(&(Output[index * 4]), (int)randomValue, 4);
}if (HAL_RNG_GenerateRandomNumber(&RngHandle, &randomValue) == HAL_OK) { ... }
else
{
Error_Handler();
}else { ... }
}for (index = 0; index < Len/4; index++) { ... }
return 0;
}{ ... }
#endif/* ... */