X-Git-Url: https://codewiz.org/gitweb?a=blobdiff_plain;f=algos%2Frandpool.c;h=63a2716a6fa8a9b89145e1aef5b34eed1f1c0984;hb=bd5a6de1603564daa55869e9dc524bb20be79556;hp=029f5ba10406832051e13ccaf3fec5a9050fe53c;hpb=53e4380b1f39577698180697ec9caa4d646468c1;p=bertos.git diff --git a/algos/randpool.c b/algos/randpool.c index 029f5ba1..63a2716a 100755 --- a/algos/randpool.c +++ b/algos/randpool.c @@ -13,6 +13,12 @@ /*#* *#* $Log$ + *#* Revision 1.11 2007/02/12 09:40:43 asterix + *#* Remove randpool_load function. Add *data in randpool_init prototype. + *#* + *#* Revision 1.10 2007/02/12 09:03:32 asterix + *#* Add CONFIG_RANDPOOL_TIMER macro to swich on or off timer support + *#* *#* Revision 1.9 2007/02/09 17:58:09 asterix *#* Add macro CONFIG_RANDPOOL_TIMER. *#* @@ -27,21 +33,19 @@ #include "randpool.h" #include "md2.h" +#include //sprintf(); #include //memset(), memcpy(); + #include #include //ASSERT() #include //MIN() -#include //timer_clock(); -#include //sprintf(); - -//TODO: -#if CONFIG_RANDPOOL_TIMER - #define TIMER() timer_clock() -#else - #define TIMER() 0 //TODO: +#if CONFIG_RANDPOOL_TIMER + #include //timer_clock(); #endif + + /* * Insert bytes in entropy pool, making a XOR of bytes present * in entropy pool. @@ -109,17 +113,21 @@ static void randpool_stir(EntropyPool *pool) */ void randpool_add(EntropyPool *pool, void *data, size_t data_len, size_t entropy) { - ticks_t event = TIMER(); - uint32_t delta; uint8_t sep[] = "\xaa\xaa\xaa\xaa"; // ?? randpool_push(pool, data, data_len); //Insert data to entropy pool. randpool_push(pool, sep, strlen(sep)); // ?? +#if CONFIG_RANDPOOL_TIMER + + ticks_t event = timer_clock(); + uint32_t delta; + /*Difference of time between a two accese to entropy pool.*/ delta = event - pool->last_counter; + randpool_push(pool, &delta, sizeof(delta)); delta = delta & 0xff; @@ -135,19 +143,48 @@ void randpool_add(EntropyPool *pool, void *data, size_t data_len, size_t entropy entropy++; } +#else + size_t event = 0; + + /*Difference of time between a two accese to entropy pool.*/ + event = pool->last_counter++; + +#endif + pool->entropy += entropy; //Update a entropy of the pool. pool->last_counter = event; } - -void randpool_init(EntropyPool *pool) +/** + * Randpool function initialization. + * The entropy pool can be initialize also with + * a previous entropy pool. + */ +void randpool_init(EntropyPool *pool, void *_data, size_t len) { + uint8_t *data; + + data = (uint8_t *)_data; memset(pool, 0, sizeof(EntropyPool)); pool->pos_get = CONFIG_MD2_BLOCK_LEN; - pool->last_counter = TIMER(); - //TODO: inizializzazione del timer di sistema. +#if CONFIG_RANDPOOL_TIMER + pool->last_counter = timer_clock(); +#endif + + ASSERT(len < CONFIG_SIZE_ENTROPY_POOL); + + if(len > 0) + { + /* + * Initialize a entropy pool with a + * previous pool, and assume all pool as + * entropy. + */ + memcpy(pool->pool_entropy, data, len); + pool->entropy = len; + } } @@ -216,7 +253,3 @@ bool randpool_save(void *data) { } -uint8_t *randpool_load(void) -{ -} -