projects
/
bertos.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Set to const col_address; add static assert check on array dimension.
[bertos.git]
/
algos
/
randpool.c
diff --git
a/algos/randpool.c
b/algos/randpool.c
index d975ba5655b0eca9fcb0ccaaa029676049b5f778..735bd06e9447007a110a795eaf5a386713705b6e 100755
(executable)
--- a/
algos/randpool.c
+++ b/
algos/randpool.c
@@
-13,6
+13,12
@@
/*#*
*#* $Log$
/*#*
*#* $Log$
+ *#* 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.
*#*
*#* Revision 1.17 2007/02/15 13:40:42 asterix
*#* Fix bug in randpool_add and randpool_strir.
*#*
@@
-121,7
+127,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)
{
*/
void randpool_add(EntropyPool *pool, void *data, size_t entropy)
{
@@
-171,21
+177,20
@@
void randpool_init(EntropyPool *pool, void *_data, size_t len)
data = (uint8_t *)_data;
memset(pool, 0, sizeof(EntropyPool));
data = (uint8_t *)_data;
memset(pool, 0, sizeof(EntropyPool));
- pool->pos_get =
CONFIG_MD2_BLOCK
_LEN;
+ pool->pos_get =
MD2_DIGEST
_LEN;
#if CONFIG_RANDPOOL_TIMER
pool->last_counter = timer_clock();
#endif
#if CONFIG_RANDPOOL_TIMER
pool->last_counter = timer_clock();
#endif
- ASSERT(len < CONFIG_SIZE_ENTROPY_POOL);
-
- if(len > 0)
+ if(data)
{
/*
* Initialize a entropy pool with a
* previous pool, and assume all pool as
* entropy.
*/
{
/*
* Initialize a entropy pool with a
* previous pool, and assume all pool as
* entropy.
*/
+ len = MIN(len,(size_t)CONFIG_SIZE_ENTROPY_POOL);
memcpy(pool->pool_entropy, data, len);
pool->entropy = len;
}
memcpy(pool->pool_entropy, data, len);
pool->entropy = len;
}
@@
-200,60
+205,56
@@
size_t randpool_size(EntropyPool *pool)
return pool->entropy;
}
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, rand
pool_get
continue
* to generate pseudocasual value from previous state of
* pool.
* 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_get
N
(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.
{
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.*/
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*/
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.
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 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;
}
}
{
randpool_stir(pool);
i = pool->pos_get;
}
}
-
pool->pos_get = i; //Current number of byte we get from pool.
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*/
pool->entropy -= n_byte; //Update a entropy.
/*If we get all entropy entropy is 0*/