From: rasky Date: Tue, 28 Sep 2010 18:35:35 +0000 (+0000) Subject: SEC: Add LM3S backend for entropy pulling. X-Git-Tag: 2.6.0~63 X-Git-Url: https://codewiz.org/gitweb?a=commitdiff_plain;h=239b0b70c59b7242e0ff604b7f8b87a37f83de56;p=bertos.git SEC: Add LM3S backend for entropy pulling. git-svn-id: https://src.develer.com/svnoss/bertos/trunk@4338 38d2e660-2303-0410-9eaa-f027e97ec537 --- diff --git a/bertos/sec/random_lm3s.c b/bertos/sec/random_lm3s.c new file mode 100644 index 00000000..0adc96ce --- /dev/null +++ b/bertos/sec/random_lm3s.c @@ -0,0 +1,89 @@ +/** + * \file + * + * + * \brief LM3 backend implementation entropy pulling. + * \author Giovanni Bajo + * + */ + +#include "random_p.h" +#include +#include + +/* + * Return the cpu core temperature in raw format + */ +INLINE uint16_t hw_readRawTemp(void) +{ + /* Trig the temperature sampling */ + HWREG(ADC0_BASE + ADC_O_PSSI) |= ADC_PSSI_SS3; + + while (!(HWREG(ADC0_BASE + ADC_O_SSFSTAT3) & ADC_SSFSTAT3_FULL)); + + return (uint16_t)HWREG(ADC0_BASE + ADC_O_SSFIFO3); +} + +INLINE void hw_initIntTemp(void) +{ + SYSCTL_RCGC0_R |= SYSCTL_RCGC0_ADC0; + + lm3s_busyWait(10); + + /* Disable all sequence */ + HWREG(ADC0_BASE + ADC_O_ACTSS) = 0; + /* Set trigger event to programmed (for all sequence) */ + HWREG(ADC0_BASE + ADC_O_EMUX) = 0; + /* Enalbe read of temperature sensor */ + HWREG(ADC0_BASE + ADC_O_SSCTL3) |= ADC_SSCTL3_TS0; + /* Enable sequence S03 (single sample on select channel) */ + HWREG(ADC0_BASE + ADC_O_ACTSS) |= ADC_ACTSS_ASEN3; +} + + +void random_pull_entropy(uint8_t *entropy, size_t len) +{ + // We use the internal temperature sensor of LM3S as a source of entropy. + // The last bit of the acquisition is very variable and with a decent distribution + // to consider it "entropic". It does not really matter because it will + // go through a randomness extractor anyway. + hw_initIntTemp(); + + for (size_t j=0; j