From: asterix Date: Fri, 9 Feb 2007 09:24:38 +0000 (+0000) Subject: Typos. Add data_len in randpool_add and n_byte in randpool_push pototypes. X-Git-Tag: 1.0.0~469 X-Git-Url: https://codewiz.org/gitweb?a=commitdiff_plain;h=96b027ed7b226e3f269b0f01b6bfe8957a8f2741;p=bertos.git Typos. Add data_len in randpool_add and n_byte in randpool_push pototypes. git-svn-id: https://src.develer.com/svnoss/bertos/trunk@772 38d2e660-2303-0410-9eaa-f027e97ec537 --- diff --git a/algos/randpool.c b/algos/randpool.c index e8c74229..b2d91727 100755 --- a/algos/randpool.c +++ b/algos/randpool.c @@ -13,8 +13,8 @@ /*#* *#* $Log$ - *#* Revision 1.5 2007/02/08 17:21:51 asterix - *#* Write pool_size function. + *#* Revision 1.6 2007/02/09 09:24:38 asterix + *#* Typos. Add data_len in randpool_add and n_byte in randpool_push pototypes. *#* *#* Revision 1.3 2007/02/08 14:25:29 asterix *#* Write static funcion push_byte. @@ -29,7 +29,7 @@ #include //ASSERT() #include //timer_clock(); -#include //sprintf(); +#include //sprintf(); @@ -37,130 +37,133 @@ * Insert bytes in entropy pool, making a XOR of bytes present * in entropy pool. */ -static void push_byte(EntrPool *pool, void *_byte) +static void randpool_push(EntrPool *pool, void *_byte, size_t n_byte) { - size_t i = pool->pool_pos_add; // Current number of byte insert in entropy pool. - size_t len_byte; + size_t i = pool->pos_add; // Current number of byte insert in entropy pool. uint8_t *byte; - byte = (uint8_t *)_byte; - len_byte = strlen(byte); /* * Insert a bytes in entropy pool. */ - for(int j = 0; j < len_byte; j++) + for(int j = 0; j < n_byte; j++) { pool->pool_entropy[i] = pool->pool_entropy[i] ^ byte[j]; i = (i++) % CONFIG_SIZE_ENTROPY_POOL; } - pool->pool_pos_add = i; // Update a insert bytes. + pool->pos_add = i; // Update a insert bytes. } -/* + +/** + * Add n_bit of entropy in entropy pool. + */ +void randpool_add(EntrPool *pool, void *data, size_t data_len, size_t entropy) +{ + uint32_t event = timer_clock(); + 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)); // ?? + + /*Difference of time between a two accese to entropy pool.*/ + delta = event - pool->last_counter; + + randpool_push(pool, &delta, sizeof(delta)); + + delta = delta & 0xff; + + randpool_push(pool, &delta, sizeof(delta)); + + /* + * Count of number entropy bit add with delta. + */ + while(delta) + { + delta >>= 1; + entropy++; + } + + pool->entropy = entropy; //Update a entropy of the pool. + pool->last_counter = event; +} + +/* \ * This function stir entropy pool with MD2 function hash. * */ -static void stir(EntrPool *pool) +static void randpool_stir(EntrPool *pool) { size_t entropy = pool->entropy; //Save current calue of entropy. Md2Context context; uint8_t tmp_buf[(sizeof(size_t) * 2) + sizeof(int)]; //Temporary buffer. md2_init(&context); - - add_data(pool, "", 0); - + + randpool_add(pool, "", 0, 0); + for (int i = 0; i < (CONFIG_SIZE_ENTROPY_POOL / CONFIG_MD2_BLOCK_LEN); i++) { - sprintf(tmp_buf, "%x%x%x",pool->counter, i, pool->pool_pos_add); - + sprintf(tmp_buf, "%x%x%x",pool->counter, i, pool->pos_add); + /* * Hash with MD2 algorithm the entropy pool. */ md2_update(&context, pool->pool_entropy, CONFIG_SIZE_ENTROPY_POOL); - + md2_update(&context, tmp_buf, CONFIG_SIZE_ENTROPY_POOL); - push_byte(pool, md2_end(&context)); //Insert a message digest in entropy pool. + /*Insert a message digest in entropy pool.*/ + randpool_push(pool, md2_end(&context), CONFIG_MD2_BLOCK_LEN); pool->counter = (pool->counter + 1) & 0xFFFFFFFF; //Update a counter modulo 4. - + } - + /*Insert in pool the difference between a two call of this function (see above).*/ - add_data(pool, "", 0); - + randpool_add(pool, "", 0, 0); + pool->entropy = entropy; //Restore old value of entropy. We haven't add entropy. } -void init_pool(EntrPool *pool) +void randpool_init(EntrPool *pool) { - + memset(pool, 0, sizeof(EntrPool)); + pool->pos_get = CONFIG_MD2_BLOCK_LEN; + pool->last_counter = timer_clock(); //TODO: inizializzazione del timer di sistema. } -/** - * Add n_bit of entropy in entropy pool. - */ -void add_data(EntrPool *pool, void *data, size_t n_bit) -{ - uint32_t event = timer_clock(); - uint32_t delta; - - push_byte(pool, data); //Insert data to entropy pool. - - push_byte(pool, "\xaa\xaa\xaa\xaa"); // ?? - - /*Difference of time between a two accese to entropy pool.*/ - delta = event - pool->last_counter; - - push_byte(pool, &delta); - - delta = delta & 0xff; - - push_byte(pool, &delta); - - /* - * Count of number entropy bit add with delta. - */ - while(delta) - { - delta >>= 1; - n_bit++; - } - - pool->entropy = n_bit; //Update a entropy of the pool. - pool->last_counter = event; -} - /** * Get the actual value of entropy. */ -size_t pool_size(EntrPool *pool) +size_t randpool_size(EntrPool *pool) { return pool->entropy; } -void get_bit(EntrPool *pool, void *data, size_t n_bit) +void randpool_get(EntrPool *pool, void *data, size_t n_byte) { + } -void get_bit_n(EntrPool *pool, void *data, size_t n_bit) +void randpool_getN(EntrPool *pool, void *data, size_t n_byte) { } -bool save_pool(void *data) +bool randpool_save(void *data) { } -uint8_t *load_pool(void) +uint8_t *randpool_load(void) { } diff --git a/algos/randpool.h b/algos/randpool.h index e996fa3c..75564943 100755 --- a/algos/randpool.h +++ b/algos/randpool.h @@ -1,7 +1,7 @@ /** * \file * * @@ -14,6 +14,9 @@ /*#* *#* $Log$ + *#* Revision 1.5 2007/02/09 09:24:38 asterix + *#* Typos. Add data_len in randpool_add and n_byte in randpool_push pototypes. + *#* *#* Revision 1.4 2007/02/08 17:18:01 asterix *#* Write add_data and stir function. Typos *#* @@ -39,21 +42,22 @@ */ typedef struct EntrPool { - size_t entropy; ///< Actual value of entropy (In bit). - size_t pool_pos_add; ///< Size of byte insert in entropy pool. - size_t pool_pos_get; ///< Size of byte take in entropy pool. + size_t entropy; ///< Actual value of entropy (byte). + size_t pos_add; ///< Size of byte insert in entropy pool. + size_t pos_get; ///< Size of byte take in entropy pool. size_t counter; ///< Counter. size_t last_counter; ///< Last timer value. uint8_t pool_entropy[CONFIG_SIZE_ENTROPY_POOL]; ///< Entropy pool. } EntrPool; -void init_pool(EntrPool *pool); -void add_data(EntrPool *pool, void *data, size_t n_bit); -size_t pool_size(EntrPool *pool); -void get_bit(EntrPool *pool, void *data, size_t n_bit); -void get_bit_n(EntrPool *pool, void *data, size_t n_bit); -bool save_pool(void *data); -uint8_t *load_pool(void); + +void randpool_add(EntrPool *pool, void *data, size_t data_len, size_t entropy); +void randpool_init(EntrPool *pool); +size_t randpool_size(EntrPool *pool); +void randpool_get(EntrPool *pool, void *data, size_t n_byte); +void randpool_getN(EntrPool *pool, void *data, size_t n_byte); +bool randpool_save(void *data); +uint8_t *randpool_load(void); #endif /* RANDPOOL_H */