// todo - would like to make this a callback
int dtls_rng(void* handle, uint8_t* data, const size_t len_)
{
	size_t len = len_;
	while (len>=4)
	{
		*((uint32_t*)data) = HAL_RNG_GetRandomNumber();
		data += 4;
		len -= 4;
	}
	while (len-->0)
	{
		*data++ = HAL_RNG_GetRandomNumber();
	}

	return 0;
}
コード例 #2
0
ファイル: audio_recorder_win.c プロジェクト: z80/stm32f429
/**
  * @brief  Paints exit button
  * @param  hObj: button handle
  * @retval None
  */
static void _BuildFileName(void) {

  hRNG.Instance = RNG;
  __HAL_RCC_RNG_CLK_ENABLE();
  HAL_RNG_Init(&hRNG);
  sprintf(FileName, "record-%04lu.wav", HAL_RNG_GetRandomNumber(&hRNG) % 10000);
}
コード例 #3
0
ファイル: main.c プロジェクト: shjere/common
/**
  * @brief  Main program
  * @param  None
  * @retval None
  */
int main(void)
{
  uint32_t counter = 0;
 
  /* STM32L0xx HAL library initialization:
       - Configure the Flash prefetch, Flash preread and Buffer caches
       - 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.
       - Low Level Initialization
     */
  HAL_Init();

  /* Configure LED2 and Key Button */
  BSP_LED_Init(LED2);
  BSP_PB_Init(BUTTON_KEY, BUTTON_MODE_GPIO);   
  
  /* Configure the system clock to 2 Mhz (Up to 32MHZ possible) */
  SystemClock_Config();
  
  /*##-1- Configure the RNG peripheral #######################################*/
  RngHandle.Instance = RNG;
  
  if(HAL_RNG_Init(&RngHandle) != HAL_OK)
  {
    /* Initialization Error */
    Error_Handler();
  }
  
  while (1)
  {
    /*##-2- Wait until Key button is pressed #################################*/
    while(BSP_PB_GetState(BUTTON_KEY) != RESET)
    {
    }
    
    /*##-3- Loop while Key button is maintained pressed ######################*/
    while(BSP_PB_GetState(BUTTON_KEY) == RESET)
    {
    }
    
    /*##-4- Generate 8 Random 32bit Numbers ##################################*/
    for(counter = 0; counter < 8; counter++)
    {
      aRandom32bit[counter] = HAL_RNG_GetRandomNumber(&RngHandle);
    }
  }
}
コード例 #4
0
ファイル: main.c プロジェクト: PaxInstruments/STM32CubeF2
/**
  * @brief  Main program
  * @param  None
  * @retval None
  */
int main(void)
{
  uint32_t counter = 0;
 
  /* STM32F2xx HAL library initialization:
       - Configure the Flash prefetch, instruction and Data caches
       - Configure the Systick to generate an interrupt each 1 msec
       - Set NVIC Group Priority to 4
       - Global MSP (MCU Support Package) initialization
     */
  HAL_Init();
   
  /* Configure the system clock to 168 MHz */
  SystemClock_Config();
  
  /* Configure LED3 */
  BSP_LED_Init(LED3);
  
  /* Configure Key Button */
  BSP_PB_Init(BUTTON_KEY, BUTTON_MODE_GPIO);
  
  /*##-1- Configure the RNG peripheral #######################################*/
  RngHandle.Instance = RNG;
  
  if(HAL_RNG_Init(&RngHandle) != HAL_OK)
  {
    /* Initialization Error */
    Error_Handler();
  }

  /* Infinite loop */  
  while (1)
  {
    /*##-2- Wait until Key button is pressed #################################*/
    while(BSP_PB_GetState(BUTTON_KEY) != RESET)
    {
    }
    
    /*##-3- Loop while Key button is maintained pressed ######################*/
    while(BSP_PB_GetState(BUTTON_KEY) == RESET)
    {
    }
    
    /*##-4- Generate 8 Random 32bit Numbers ##################################*/
    for(counter = 0; counter < 8; counter++)
    {
      aRandom32bit[counter] = HAL_RNG_GetRandomNumber(&RngHandle);
    }
  }
}
コード例 #5
0
ファイル: main.c プロジェクト: EarnestHein89/STM32Cube_FW_F4
/**
  * @brief  Returns a random number.
  * @param  arg not used
  * @param  output random number
  * @param  output_len random number length
  * @retval 0
  */
int RandVal(void* arg, unsigned char *output, size_t output_len)
{
  uint32_t nbrng = 0;
  uint8_t offset = 0;
  
  nbrng = output_len;
  
  while(nbrng > 0)
  {
    /* Wait until random number is ready */  
    while(__HAL_RNG_GET_FLAG(&RngHandle, RNG_FLAG_DRDY)== RESET);
  
    /* Get the random number */
    *(output + offset) = HAL_RNG_GetRandomNumber(&RngHandle) && 0xFFFFFF00;
    
    offset++;
    nbrng --;
  }
 
  /* Return the random number */ 
  return(0);
}
コード例 #6
0
/** 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);
}
コード例 #7
0
ファイル: rng.c プロジェクト: AriZuu/micropython
uint32_t rng_get(void) {
    if (RNGHandle.State == HAL_RNG_STATE_RESET) {
        rng_init();
    }
    return HAL_RNG_GetRandomNumber(&RNGHandle);
}