Remove fixme.
[bertos.git] / algos / randpool.c
old mode 100755 (executable)
new mode 100644 (file)
index 74113d5..a32fdff
@@ -1,8 +1,33 @@
 /**
  * \file
  * <!--
+ * This file is part of BeRTOS.
+ *
+ * Bertos is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ * As a special exception, you may use this file as part of a free software
+ * library without restriction.  Specifically, if other files instantiate
+ * templates or use macros or inline functions from this file, or you compile
+ * this file and link it with other files to produce an executable, this
+ * file does not by itself cause the resulting executable to be covered by
+ * the GNU General Public License.  This exception does not however
+ * invalidate any other reasons why the executable file might be covered by
+ * the GNU General Public License.
+ *
  * Copyright 2007 Develer S.r.l. (http://www.develer.com/)
- * This file is part of DevLib - See README.devlib for information.
+ *
  * -->
  *
  * \brief API function for to manage entropy pool.
 
 /*#*
  *#* $Log$
- *#* Revision 1.18  2007/02/15 13:48:40  asterix
- *#* Fix bug in randpool_init.
+ *#* Revision 1.20  2007/06/07 16:06:39  batt
+ *#* Fix some doxygen errors.
+ *#*
+ *#* Revision 1.19  2007/02/15 13:54:26  asterix
+ *#* Rename randpool_getN in randpool_get. Fix bug in randpool_get.
  *#*
  *#* Revision 1.17  2007/02/15 13:40:42  asterix
  *#* Fix bug in randpool_add and randpool_strir.
@@ -124,7 +152,7 @@ static void randpool_stir(EntropyPool *pool)
 }
 
 /**
- * Add \param entropy bits from \param data buffer to the entropy \param pool.
+ * Add \param entropy bits from \param data buffer to the entropy \param pool
  */
 void randpool_add(EntropyPool *pool, void *data, size_t entropy)
 {
@@ -202,60 +230,56 @@ size_t randpool_size(EntropyPool *pool)
        return pool->entropy;
 }
 
-void randpool_get(EntropyPool *pool, void *data, size_t n_byte)
-{
-
-}
-
 /**
- * Get n_byte from entropy pool. If n_byte is larger than number
- * byte of entropy in entropy pool, rand_pool_getN continue
+ * Get \param n_byte from entropy pool. If n_byte is larger than number
+ * byte of entropy in entropy pool, randpool_get continue
  * to generate pseudocasual value from previous state of
  * pool.
+ * \param n_byte number fo bytes to read.
+ * \param pool is the pool entropy context.
+ * \param _data is the pointer to write the random data to.
  */
-void randpool_getN(EntropyPool *pool, void *_data, size_t n_byte)
+void randpool_get(EntropyPool *pool, void *_data, size_t n_byte)
 {
        Md2Context context;
        size_t i = pool->pos_get;
        size_t n = n_byte;
        size_t pos_write = 0;  //Number of block has been written in data.
-       size_t len = MIN((size_t)CONFIG_MD2_BLOCK_LEN, n_byte);
+       size_t len = MIN((size_t)MD2_DIGEST_LEN, n_byte);
        uint8_t *data;
 
        data = (uint8_t *)_data;
 
        /* Test if i + CONFIG_MD2_BLOCK_LEN  is inside of entropy pool.*/
-       ASSERT((CONFIG_MD2_BLOCK_LEN + i) < CONFIG_SIZE_ENTROPY_POOL);
+       ASSERT((MD2_DIGEST_LEN + i) < CONFIG_SIZE_ENTROPY_POOL);
 
-       md2_init(&context); 
+       md2_init(&context);
 
        while(n > 0)
        {
 
                /*Hash previous state of pool*/
-               md2_update(&context, &pool->pool_entropy[i], CONFIG_MD2_BLOCK_LEN);
+               md2_update(&context, &pool->pool_entropy[i], MD2_DIGEST_LEN);
 
                memcpy(&data[pos_write], md2_end(&context), len);
 
                pos_write += len;   //Update number of block has been written in data.
                n -= len;           //Number of byte copied in data.
 
-               len = MIN(n,(size_t)CONFIG_MD2_BLOCK_LEN);
+               len = MIN(n,(size_t)MD2_DIGEST_LEN);
 
-               i = (i + CONFIG_MD2_BLOCK_LEN) % CONFIG_SIZE_ENTROPY_POOL;
+               i = (i + MD2_DIGEST_LEN) % CONFIG_SIZE_ENTROPY_POOL;
 
                /* If we haven't more entropy pool to hash, we stir it.*/
-               if(i < CONFIG_MD2_BLOCK_LEN)
+               if(i < MD2_DIGEST_LEN)
                {
                        randpool_stir(pool);
                        i = pool->pos_get;
                }
 
        }
-       
 
        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*/