Remove \version svn tag.
[bertos.git] / bertos / algo / randpool.c
index 0fc2ee9db667da8b35b1635264974a2ad83912e8..4d420f3e8127bfab037e87857ebad885cc8f80bf 100644 (file)
@@ -32,7 +32,6 @@
  *
  * \brief API function for to manage entropy pool.
  *
- * \version $Id$
  * \author Daniele Basile <asterix@develer.com>
  */
 
@@ -66,10 +65,11 @@ static void randpool_push(EntropyPool *pool, void *_byte, size_t n_byte)
        /*
         * Insert a bytes in entropy pool.
         */
-       for(int j = 0; j < n_byte; j++)
+       for(size_t j = 0; j < n_byte; j++)
        {
                pool->pool_entropy[i] = pool->pool_entropy[i] ^ byte[j];
-               i = (++i) % CONFIG_SIZE_ENTROPY_POOL;
+               i++;
+               i = i % CONFIG_SIZE_ENTROPY_POOL;
        }
 
        pool->pos_add  =  i; // Update a insert bytes.
@@ -92,7 +92,7 @@ static void randpool_stir(EntropyPool *pool)
 
        for (int i = 0; i < (CONFIG_SIZE_ENTROPY_POOL / MD2_DIGEST_LEN); i++)
        {
-               sprintf(tmp_buf, "%0x%0x%0x",pool->counter, i, pool->pos_add);
+               sprintf((char *)tmp_buf, "%0x%0x%0x", pool->counter, i, pool->pos_add);
 
                /*
                 * Hash with MD2 algorithm the entropy pool.
@@ -104,7 +104,7 @@ static void randpool_stir(EntropyPool *pool)
                /*Insert a message digest in entropy pool.*/
                randpool_push(pool, md2_end(&context), MD2_DIGEST_LEN);
 
-               pool->counter = pool->counter + 1; 
+               pool->counter = pool->counter + 1;
 
        }
 
@@ -155,8 +155,8 @@ void randpool_add(EntropyPool *pool, void *data, size_t entropy)
 
 /**
  * Randpool function initialization.
- * The entropy pool can be initialize also with 
- * a previous entropy pool. 
+ * The entropy pool can be initialize also with
+ * a previous entropy pool.
  */
 void randpool_init(EntropyPool *pool, void *_data, size_t len)
 {
@@ -174,7 +174,7 @@ void randpool_init(EntropyPool *pool, void *_data, size_t len)
        if(data)
        {
                /*
-                * Initialize a entropy pool with a 
+                * Initialize a entropy pool with a
                 * previous pool, and assume all pool as
                 * entropy.
                 */
@@ -214,7 +214,7 @@ void randpool_get(EntropyPool *pool, void *_data, size_t n_byte)
        data = (uint8_t *)_data;
 
        /* Test if i + CONFIG_MD2_BLOCK_LEN  is inside of entropy pool.*/
-       ASSERT((MD2_DIGEST_LEN + i) < CONFIG_SIZE_ENTROPY_POOL);
+       ASSERT((MD2_DIGEST_LEN + i) <= CONFIG_SIZE_ENTROPY_POOL);
 
        md2_init(&context);
 
@@ -245,10 +245,6 @@ void randpool_get(EntropyPool *pool, void *_data, size_t n_byte)
        pool->pos_get = i; //Current number of byte we get from pool.
        pool->entropy -= n_byte; //Update a entropy.
 
-       /*If we get all entropy entropy is 0*/
-       if(pool->entropy < 0) 
-               pool->entropy = 0;
-
 }
 
 /**