4 * Copyright 2007 Develer S.r.l. (http://www.develer.com/)
5 * This file is part of DevLib - See README.devlib for information.
8 * \brief API function for to manage entropy pool.
11 * \author Daniele Basile <asterix@develer.com>
16 *#* Revision 1.3 2007/02/08 14:25:29 asterix
17 *#* Write static funcion push_byte.
24 #include <string.h> //memset(), memcpy();
25 #include <cfg/compiler.h>
26 #include <cfg/debug.h> //ASSERT()
28 static void stir(EntrPool *pool)
34 * Insert bytes in entropy pool, making a XOR of bytes present
37 static void push_byte(EntrPool *pool, void *_byte)
39 size_t i = pool->pool_pos_add; // Current number of byte insert in entropy pool.
44 byte = (uint8_t *)_byte;
45 len_byte = strlen(byte);
48 * Insert a bytes in entropy pool.
50 for(int j = 0; j < len_byte; j++)
52 pool->pool_entropy[i] = pool->pool_entropy[i] ^ byte[j];
53 i = (i++) % CONFIG_SIZE_ENTROPY_POOL;
56 pool->pool_pos_add = i; // Update a insert bytes.
59 void init_pool(EntrPool *pool)
62 memset(pool, 0, sizeof(EntrPool));
66 void add_data(EntrPool *pool, void *data, size_t n_bit)
71 size_t pool_size(EntrPool *pool)
75 void get_bit(EntrPool *pool, void *data, size_t n_bit)
79 void get_bit_n(EntrPool *pool, void *data, size_t n_bit)
83 bool save_pool(void *data)
87 uint8_t *load_pool(void)