mirror of https://github.com/ARMmbed/mbed-os.git
Add documentation + reformat the code
parent
4c50ec2734
commit
824fff5d63
|
|
@ -30,21 +30,27 @@
|
|||
/* RNG handler declaration */
|
||||
RNG_HandleTypeDef RngHandle;
|
||||
|
||||
/*
|
||||
* Get one byte of entropy from the RNG, assuming it is up and running.
|
||||
|
||||
/** rng_get_byte
|
||||
* @brief Get one byte of entropy from the RNG, assuming it is up and running.
|
||||
* @param pointer to the hardware generated random byte.
|
||||
*/
|
||||
static void rng_get_byte( unsigned char *byte )
|
||||
{
|
||||
*byte = (unsigned char)HAL_RNG_GetRandomNumber(&RngHandle);
|
||||
}
|
||||
|
||||
/*
|
||||
* Get len bytes of entropy from the hardware RNG.
|
||||
|
||||
/** mbedtls_hardware_poll
|
||||
* @brief Get len bytes of entropy from the hardware RNG.
|
||||
* @param data pointer will be NULL
|
||||
* @param output pointer to the random generated bytes buffer
|
||||
* @param len input is the requested length of bytes to be generated
|
||||
* @param olen is the pointer to the length of bytes effectively generated
|
||||
* @returns 0 if the generation went well. -1 in case of error
|
||||
*/
|
||||
int mbedtls_hardware_poll( void *data,
|
||||
unsigned char *output, size_t len, size_t *olen )
|
||||
int mbedtls_hardware_poll( void *data, unsigned char *output, size_t len, size_t *olen )
|
||||
{
|
||||
size_t i;
|
||||
int ret;
|
||||
((void) data);
|
||||
|
||||
|
|
@ -56,22 +62,17 @@ int mbedtls_hardware_poll( void *data,
|
|||
HAL_RNG_Init(&RngHandle);
|
||||
|
||||
/* Get Random byte */
|
||||
for( i = 0; i < len; i++ ){
|
||||
for( uint32_t i = 0; i < len; i++ ){
|
||||
rng_get_byte( output + i );
|
||||
printf("output %i: %i\n",i,(int)*(output+i));
|
||||
|
||||
}
|
||||
/* Just be extra sure that we didn't do it wrong */
|
||||
if( ( __HAL_RNG_GET_FLAG(&RngHandle, (RNG_FLAG_CECS|RNG_FLAG_SECS)) ) != 0 )
|
||||
{
|
||||
ret = -1;
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
*olen = len;
|
||||
ret = 0;
|
||||
|
||||
cleanup:
|
||||
/* Just be extra sure that we didn't do it wrong */
|
||||
if( ( __HAL_RNG_GET_FLAG(&RngHandle, (RNG_FLAG_CECS|RNG_FLAG_SECS)) ) != 0 ) {
|
||||
ret = -1;
|
||||
} else {
|
||||
ret = 0;
|
||||
}
|
||||
/*Disable the RNG peripheral */
|
||||
HAL_RNG_DeInit(&RngHandle);
|
||||
/* RNG Peripheral clock disable - assume we're the only users of RNG */
|
||||
|
|
|
|||
|
|
@ -25,21 +25,27 @@
|
|||
/* RNG handler declaration */
|
||||
RNG_HandleTypeDef RngHandle;
|
||||
|
||||
/*
|
||||
* Get one byte of entropy from the RNG, assuming it is up and running.
|
||||
|
||||
/** rng_get_byte
|
||||
* @brief Get one byte of entropy from the RNG, assuming it is up and running.
|
||||
* @param pointer to the hardware generated random byte.
|
||||
*/
|
||||
static void rng_get_byte( unsigned char *byte )
|
||||
{
|
||||
*byte = (unsigned char)HAL_RNG_GetRandomNumber(&RngHandle);
|
||||
}
|
||||
|
||||
/*
|
||||
* Get len bytes of entropy from the hardware RNG.
|
||||
|
||||
/** mbedtls_hardware_poll
|
||||
* @brief Get len bytes of entropy from the hardware RNG.
|
||||
* @param data pointer will be NULL
|
||||
* @param output pointer to the random generated bytes buffer
|
||||
* @param len input is the requested length of bytes to be generated
|
||||
* @param olen is the pointer to the length of bytes effectively generated
|
||||
* @returns 0 if the generation went well. -1 in case of error
|
||||
*/
|
||||
int mbedtls_hardware_poll( void *data,
|
||||
unsigned char *output, size_t len, size_t *olen )
|
||||
int mbedtls_hardware_poll( void *data, unsigned char *output, size_t len, size_t *olen )
|
||||
{
|
||||
size_t i;
|
||||
int ret;
|
||||
((void) data);
|
||||
|
||||
|
|
@ -50,22 +56,18 @@ int mbedtls_hardware_poll( void *data,
|
|||
RngHandle.Instance = RNG;
|
||||
HAL_RNG_Init(&RngHandle);
|
||||
|
||||
|
||||
/* Get Random byte */
|
||||
for( i = 0; i < len; i++ )
|
||||
for( uint32_t i = 0; i < len; i++ ){
|
||||
rng_get_byte( output + i );
|
||||
|
||||
/* Just be extra sure that we didn't do it wrong */
|
||||
if( ( __HAL_RNG_GET_FLAG(&RngHandle, (RNG_FLAG_CECS|RNG_FLAG_SECS)) ) != 0 )
|
||||
{
|
||||
ret = -1;
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
*olen = len;
|
||||
ret = 0;
|
||||
|
||||
cleanup:
|
||||
/* Just be extra sure that we didn't do it wrong */
|
||||
if( ( __HAL_RNG_GET_FLAG(&RngHandle, (RNG_FLAG_CECS|RNG_FLAG_SECS)) ) != 0 ) {
|
||||
ret = -1;
|
||||
} else {
|
||||
ret = 0;
|
||||
}
|
||||
/*Disable the RNG peripheral */
|
||||
HAL_RNG_DeInit(&RngHandle);
|
||||
/* RNG Peripheral clock disable - assume we're the only users of RNG */
|
||||
|
|
|
|||
Loading…
Reference in New Issue