From acf1d07eea45831e0a686204497f21434c6d0740 Mon Sep 17 00:00:00 2001 From: Chris Conlon Date: Wed, 26 Dec 2012 15:08:33 -0700 Subject: [PATCH] add STM32F2 RNG support --- ctaocrypt/src/random.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/ctaocrypt/src/random.c b/ctaocrypt/src/random.c index a7376063a..3b0b90d14 100644 --- a/ctaocrypt/src/random.c +++ b/ctaocrypt/src/random.c @@ -462,6 +462,35 @@ int GenerateSeed(OS_Seed* os, byte* output, word32 sz) } #endif /* FREESCALE_K70_RNGA */ +#elif defined(STM32F2_RNG) + + #include "stm32f2xx_rng.h" + /* + * Generate a RNG seed using the hardware random number generator + * on the STM32F2. Documentation located in STM32F2xx Standard Peripheral + * Library document (See note in README). + */ + int GenerateSeed(OS_Seed* os, byte* output, word32 sz) + { + int i; + + /* enable RNG clock source */ + RCC_AHB2PeriphClockCmd(RCC_AHB2Periph_RNG, ENABLE); + + /* enable RNG peripheral */ + RNG_Cmd(ENABLE); + + for (i = 0; i < sz; i++) { + /* wait until RNG number is ready */ + while(RNG_GetFlagStatus(RNG_FLAG_DRDY)== RESET) { } + + /* get value */ + output[i] = RNG_GetRandomNumber(); + } + + return 0; + } + #elif defined(NO_DEV_RANDOM) #error "you need to write an os specific GenerateSeed() here"