+ size_t i = pool->pos_add; // Current number of byte insert in entropy pool.
+ uint8_t *byte;
+
+ byte = (uint8_t *)_byte;
+
+ /*
+ * Insert a bytes in entropy pool.
+ */
+ 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->pos_add = i; // Update a insert bytes.
+}
+
+
+/*
+ * This function stir entropy pool with MD2 function hash.
+ *
+ */
+static void randpool_stir(EntropyPool *pool)
+{
+ size_t entropy = pool->entropy; //Save current calue of entropy.
+ Md2Context context;
+ uint8_t tmp_buf[((sizeof(size_t) * 2) + sizeof(int)) * 2]; //Temporary buffer.
+
+ md2_init(&context); //Init MD2 algorithm.
+
+ randpool_add(pool, "", 0, 0);
+
+ for (int i = 0; i < NUM_STIR_LOOP; i++)
+ {
+ sprintf(tmp_buf, "%0x%0x%0x",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, strlen(tmp_buf));
+
+ /*Insert a message digest in entropy pool.*/
+ randpool_push(pool, md2_end(&context), CONFIG_MD2_BLOCK_LEN);
+
+ pool->counter = (pool->counter + 1) & 0xFFFFFFFF; //Clamp a counter to 4 byte.
+
+ }
+
+ /*Insert in pool the difference between a two call of this function (see above).*/
+ randpool_add(pool, "", 0, 0);
+
+ pool->entropy = entropy; //Restore old value of entropy. We haven't add entropy.
+}
+
+/**
+ * Add n_bit of entropy in entropy pool.
+ */
+void randpool_add(EntropyPool *pool, void *data, size_t data_len, size_t entropy)
+{
+ uint8_t sep[] = "\xaa\xaa\xaa\xaa"; // ??
+
+ randpool_push(pool, data, data_len); //Insert data to entropy pool.
+
+ randpool_push(pool, sep, strlen(sep)); // ??
+
+#if CONFIG_RANDPOOL_TIMER
+
+ ticks_t event = timer_clock();
+ uint32_t delta;
+
+ /*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++;
+ }
+
+#else
+ size_t event = 0;
+
+ /*Difference of time between a two accese to entropy pool.*/
+ event = pool->last_counter++;
+
+#endif
+
+ pool->entropy += entropy; //Update a entropy of the pool.
+ pool->last_counter = event;