2019-11-18 04:40 AM
Hello together
I use the following library to create random numbers:
- Library
The sample project runs on my NUCLEO-144 H743ZI. The problem is that the same byte array (RandomString) is generated at every time.
******************************************************************************
* @file RAND/RandBytesGen/Src/main.c
* @author MCD Application Team
* @version V3.1.1
* @date 20-April-2018
* @brief Main program body
******************************************************************************
/* Entropy String. Uniformly distributed random bit string 1*/
uint8_t entropy_data[32] = {
0x9d, 0x20, 0x1a, 0x18, 0x9b, 0x6d, 0x1a, 0xa7, 0x0e,
0x79, 0x57, 0x6f, 0x36, 0xb6, 0xaa, 0x88, 0x55, 0xfd,
0x4a, 0x7f, 0x97, 0xe9, 0x71, 0x69, 0xb6, 0x60, 0x88,
0x78, 0xe1, 0x9c, 0x8b, 0xa5
};
/* Nonce. Non repeating sequence, such as a timestamp */
uint8_t nonce[] = {0xFE, 0xA9, 0x96, 0xD4, 0x62, 0xC5};
/* Personalization String */
uint8_t personalization_String[] = {0x1E, 0x6C, 0x7B, 0x82, 0xE5, 0xA5, 0x71, 0x8D};
/* Array that will be filled with random bytes */
uint8_t RandomString[32] = {0, };
RNGstate_stt RNGstate;
/* Private function prototypes -----------------------------------------------*/
static void SystemClock_Config(void);
static void CPU_CACHE_Enable(void);
static void Led_Config(void);
static void Led_Toggle( __IO uint32_t toggle_delay);
static void Error_Handler(void);
/* Private functions ---------------------------------------------------------*/
/**
* @brief Main program.
* @param None
* @retval None
*/
int main(void)
{
/* Strucutre used to call the Random engine inizialition */
RNGinitInput_stt RNGinit_st;
int32_t status = RNG_SUCCESS;
/* Enable the CPU Cache */
CPU_CACHE_Enable();
/* STM32F3xx HAL library initialization:
- Configure the Flash prefetch
- Systick timer is configured by default as source of time base, but user
can eventually implement his proper time base source (a general purpose
timer for example or other time source), keeping in mind that Time base
duration should be kept 1ms since PPP_TIMEOUT_VALUEs are defined and
handled in milliseconds basis.
- Set NVIC Group Priority to 4
- Low Level Initialization
*/
HAL_Init();
/* Configure the system clock to 64 MHz */
SystemClock_Config();
/* Configure the green led */
Led_Config();
/* Toggle the green led before starting the algorithm */
Led_Toggle(500);
/* Enable CRC clock */
__CRC_CLK_ENABLE();
/* Set the values of EntropyData, Nonce, Personalization String and their sizes inside the RNGinit_st structure */
RNGinit_st.pmEntropyData = entropy_data;
RNGinit_st.mEntropyDataSize = sizeof(entropy_data);
RNGinit_st.pmNonce = nonce;
RNGinit_st.mNonceSize = sizeof( nonce );
RNGinit_st.pmPersData = personalization_String;
RNGinit_st.mPersDataSize = sizeof( personalization_String );
status = RNGinit(&RNGinit_st, &RNGstate);
if ( status == RNG_SUCCESS )
{
/* The Random engine has been initialized, the status is in RNGstate */
/* Now fill the random string with random bytes */
status = RNGgenBytes(&RNGstate, NULL, RandomString, sizeof(RandomString));
if (status == RNG_SUCCESS)
{
/* Random Generated Succefully, free the state before returning */
status = RNGfree(&RNGstate);
if ( status == RNG_SUCCESS )
{
}
else
{
Error_Handler();
}
}
else
{
/* In case of randomization not success possible values of status:
* RNG_ERR_BAD_PARAMETER, RNG_ERR_UNINIT_STATE
*/
Error_Handler();
}
}
else
{
/* In case of randomization not success possible values of status:
* RNG_ERR_BAD_ENTROPY_SIZE, RNG_ERR_BAD_PERS_STRING_SIZE
*/
Error_Handler();
}
/* Turn on the green led in case of RANDOM operations are successful*/
HAL_GPIO_WritePin(LED1_GPIO_PORT, LED1_PIN, GPIO_PIN_SET);
while (1)
{}
}
Does anyone have an idea?
Regards Jakob
2019-11-18 04:40 AM
... sorry the library is: STM32CryptographicV3.1.1_STM32H7