Reformat.
authorasterix <asterix@38d2e660-2303-0410-9eaa-f027e97ec537>
Fri, 15 Oct 2010 13:30:38 +0000 (13:30 +0000)
committerasterix <asterix@38d2e660-2303-0410-9eaa-f027e97ec537>
Fri, 15 Oct 2010 13:30:38 +0000 (13:30 +0000)
git-svn-id: https://src.develer.com/svnoss/bertos/trunk@4429 38d2e660-2303-0410-9eaa-f027e97ec537

bertos/sec/random.h
bertos/sec/random_lm3s.c
bertos/sec/random_p.h
bertos/sec/util.h
boards/stm32-p103/hw/hw_adc.h

index 6822b950a5a65b61aa581236db9d4a30050f95ac..04f570bb1de93517507ea52b4d289bf096cf4351 100644 (file)
@@ -60,7 +60,7 @@
  *     with enough entropy to generate safe random numbers even
  *     immediately after hw reset.
  *     The overall structure is the same as used by modern
- *        desktop PCs for generating secure random numbers.
+ *        desktop PCs for generating secure random numbers.
  *
  *  * \a RANDOM_SECURITY_MEDIUM: This intermediate settings will
  *     avoid usage of an entropy pool, to reduce memory and code
index b5945f461ea5fa89df8ebb734093068a8538d682..71ce64d54cdb150548c6f99c8aedbb99522c80f4 100644 (file)
  *
  * \brief LM3 backend implementation entropy pulling.
  * \author Giovanni Bajo <rasky@develer.com>
- *
  */
 
 #include "random_p.h"
+
 #include <cpu/power.h>
+
 #include <io/cm3.h>
-#include <drv/clock_lm3s.h>
+
+#include <drv/clock_cm3.h>
 
 /*
  * Return the cpu core temperature in raw format
@@ -78,14 +80,14 @@ void random_pull_entropy(uint8_t *entropy, size_t len)
        // 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<len; j++)
        {
                uint8_t accum = 0;
                for (int b=0; b<8; ++b)
                        if (hw_readRawTemp() & 1)
                                accum |= 1<<b;
-               
+
                *entropy++ = accum;
        }
 }
index bf1b75757a3ca3267128eca296f67f2cd66f805b..990925f8bdc469dab2fae2013da917069067dd81 100644 (file)
@@ -97,7 +97,7 @@ enum EntropySource
  * Add entropy to the global entropy pool.
  */
 void random_add_entropy(enum EntropySource source_idx,
-                                           const uint8_t *data, size_t len,
+                                           const uint8_t *data, size_t len,
                                                int entropy);
 
 
index 36ce22f883a26d5917ce23e573898fe6331a2e2d..189e4ed715858734fcac66a270cbd69bfd3713fb 100644 (file)
@@ -7,7 +7,7 @@
 
 /**
  * Purge local variables, by zeroing them.
- * 
+ *
  * This can be used to clear stack from intermediate results in crypto
  * calculations that might somehow be leaked.
  */
 /**
  * Convert a generic "password" (low-diffused) to a generic "key"
  * (high-diffused).
- * 
+ *
  * In common terminology, a "password" is a key with weak cryptographic
- * characteristics, such as commonly used password input by an user, 
+ * characteristics, such as commonly used password input by an user,
  * which are usually short and use only a few different characters from
  * the 0-255 byte range.
- * 
+ *
  * This function derives a strong key from the password using a one-way
  * process.
- * 
+ *
  * \note Uses PBKDF2 as key-derivation function, with a fixed salt that
  * changes for each Bertos project.
  */
 void password2key(const char *pwd, size_t pwd_len,
                                  uint8_t *key, size_t key_len);
-                                 
+
 /**
  * Perform a bitwise xor between \a in and \a inout, and store
  * the result into \a inout.
@@ -59,7 +59,7 @@ INLINE void xor_block(uint8_t *out, const uint8_t *in1, const uint8_t* in2, size
        const uint32_t *ibuf2 = (const uint32_t *)in2;
        uint32_t *obuf = (uint32_t *)out;
        size_t rem = (len & 3);
-       
+
        len /= 4;
        while (len--)
                *obuf++ = *ibuf1++ ^ *ibuf2++;
@@ -67,7 +67,7 @@ INLINE void xor_block(uint8_t *out, const uint8_t *in1, const uint8_t* in2, size
        in1 = (const uint8_t*)ibuf1;
        in2 = (const uint8_t*)ibuf2;
        out = (uint8_t*)obuf;
-       while (rem--)   
+       while (rem--)
                *out++ = *in1++ ^ *in2++;
 }
 
@@ -80,14 +80,14 @@ INLINE void xor_block_const(uint8_t *out, const uint8_t *in, uint8_t k, size_t l
        const uint32_t *ibuf = (const uint32_t *)in;
        uint32_t *obuf = (uint32_t *)out;
        size_t rem = (len & 3);
-       
+
        len /= 4;
        while (len--)
                *obuf++ = *ibuf++ ^ k32;
 
        in = (const uint8_t*)ibuf;
        out = (uint8_t*)obuf;
-       while (rem--)   
+       while (rem--)
                *out++ = *in++ ^ k;
 }
 
index 0313b2fc47a68939ceea41a1279460e78c26ca9b..8e0f0deecc9b448362207baf047bf2650ae96426 100644 (file)
@@ -61,4 +61,9 @@ INLINE uint16_t hw_readIntTemp(void)
        return (temp / 10);
 }
 
+INLINE uint16_t hw_readRawTemp(void)
+{
+       return (uint16_t)ADC_RANGECONV(adc_read(ADC_TEMP_CH), 0, 3300);
+}
+
 #endif /* HW_ADC_H */