FreeRTOS-Plus/ThirdParty/WolfSSL-FIPS-Ready/wolfcrypt/src/random.c
/* Generate a RNG seed using the STM32 Standard Peripheral Library */
Generate a RNG seed using the STM32 Standard Peripheral Library
Generate a RNG seed using the STM32 Standard Peripheral Library
int wc_GenerateSeed(OS_Seed* os, byte* output, word32 sz)
    {
        int ret;
        word32 i;
        (void)os;
        ret = wolfSSL_CryptHwMutexLock();
        if (ret != 0) {
            return ret;
        }
        RCC_AHB2PeriphClockCmd(RCC_AHB2Periph_RNG, ENABLE);
        RNG_DeInit();
        RNG_Cmd(ENABLE);
        if (RNG_GetFlagStatus(RNG_FLAG_SECS | RNG_FLAG_CECS) != RESET) {
            wolfSSL_CryptHwMutexUnLock();
            return RNG_FAILURE_E;
        }
        for (i = 0; i < sz; i++) {
            while (RNG_GetFlagStatus(RNG_FLAG_DRDY) == RESET) { }
            output[i] = RNG_GetRandomNumber();
        }
        wolfSSL_CryptHwMutexUnLock();
        return 0;
    }
int wc_GenerateSeed ( OS_Seed * os , byte * output , word32 sz ) { int ret ; word32 i ; ( void ) os ; ret = wolfSSL_CryptHwMutexLock ( ) ; if ( ret != 0 ) { return ret ; } RCC_AHB2PeriphClockCmd ( RCC_AHB2Periph_RNG , ENABLE ) ; RNG_DeInit ( ) ; RNG_Cmd ( ENABLE ) ; if ( RNG_GetFlagStatus ( RNG_FLAG_SECS | RNG_FLAG_CECS ) != RESET ) { wolfSSL_CryptHwMutexUnLock ( ) ; return RNG_FAILURE_E ; } for ( i = 0 ; i < sz ; i ++ ) { while ( RNG_GetFlagStatus ( RNG_FLAG_DRDY ) == RESET ) { } output [ i ] = RNG_GetRandomNumber ( ) ; } wolfSSL_CryptHwMutexUnLock ( ) ; return 0 ; }
Generate a RNG seed using the STM32 Standard Peripheral Library
Generate a RNG seed using the STM32 Standard Peripheral Library
/* enable RNG clock source */ /* reset RNG */ /* enable RNG peripheral */ /* verify no errors with RNG_CLK or Seed */ /* wait until RNG number is ready */ /* get value */