BeRTOS
random_p.h
Go to the documentation of this file.
00001 
00038 #ifndef SEC_RANDOM_P_H
00039 #define SEC_RANDOM_P_H
00040 
00041 #include <cfg/compiler.h>
00042 #include <sec/random.h>
00043 
00044 /********************************************************************************/
00045 /* Configuration of the random module                                           */
00046 /********************************************************************************/
00047 
00048 #define POOL_NONE       0
00049 #define POOL_YARROW     1
00050 #define POOL_NAMEU1     YarrowPool
00051 #define POOL_NAMEL1     yarrowpool
00052 
00053 #define PRNG_ISAAC      1
00054 #define PRNG_X917       2
00055 #define PRNG_YARROW     3
00056 #define PRNG_NAMEU1     Isaac
00057 #define PRNG_NAMEL1     isaac
00058 #define PRNG_NAMEU2     X917
00059 #define PRNG_NAMEL2     x917
00060 #define PRNG_NAMEU3     Yarrow
00061 #define PRNG_NAMEL3     yarrow
00062 
00063 #define EXTRACTOR_NONE  0
00064 #define EXTRACTOR_SHA1  1
00065 #define EXTRACTOR_NAME1 SHA1
00066 
00067 #if RANDOM_SECURITY_LEVEL == RANDOM_SECURITY_STRONG
00068     #define CONFIG_RANDOM_POOL          POOL_YARROW
00069     #define CONFIG_RANDOM_EXTRACTOR     EXTRACTOR_NONE   // not required with a pool
00070     #define CONFIG_RANDOM_PRNG          PRNG_YARROW
00071 #elif RANDOM_SECURITY_LEVEL == RANDOM_SECURITY_MEDIUM
00072     #define CONFIG_RANDOM_POOL          POOL_NONE
00073     #define CONFIG_RANDOM_EXTRACTOR     EXTRACTOR_SHA1
00074     #define CONFIG_RANDOM_PRNG          PRNG_X917
00075 #elif RANDOM_SECURITY_LEVEL == RANDOM_SECURITY_MINIMUM
00076     #define CONFIG_RANDOM_POOL          POOL_NONE
00077     #define CONFIG_RANDOM_EXTRACTOR     EXTRACTOR_NONE
00078     #define CONFIG_RANDOM_PRNG          PRNG_ISAAC
00079 #else
00080     #error Unsupported random security level value
00081 #endif
00082 
00083 /***************************************************************************/
00084 /* Internal functions used by BeRTOS drivers to push data into             */
00085 /* the entropy pool                                                        */
00086 /***************************************************************************/
00087 
00088 #if CONFIG_RANDOM_POOL != POOL_NONE
00089 
00090 enum EntropySource
00091 {
00092     ENTROPY_SOURCE_IRQ,
00093     ENTROPY_SOURCE_ADC,
00094 };
00095 
00096 /*
00097  * Add entropy to the global entropy pool.
00098  */
00099 void random_add_entropy(enum EntropySource source_idx,
00100                         const uint8_t *data, size_t len,
00101                         int entropy);
00102 
00103 
00104 /*
00105  * Add entropy to the global interrupt pool based on the IRQ
00106  * call time.
00107  *
00108  * This function can be called from interrupt handlers that are
00109  * triggered at unpredictable intervals (so it should not be
00110  * called from clock-driven interrupts like ADC, PWM, etc.).
00111  *
00112  */
00113 void random_add_entropy_irq(int irq);
00114 
00115 #endif
00116 
00117 /*
00118  * This hardware-dependent function can be used to pull raw
00119  * entropy from a hardware source at startup only. It is used
00120  * for initial seeding of the random generator and should not
00121  * be used in different situations.
00122  */
00123 void random_pull_entropy(uint8_t *entropy, size_t len);
00124 
00125 #endif /* SEC_RANDOM_P_H */