+ Md2Context context;
+ size_t i = pool->pos_get;
+ int n = n_byte;
+ size_t len = MIN((size_t)CONFIG_MD2_BLOCK_LEN, n_byte);
+
+ /* Test if i + CONFIG_MD2_BLOCK_LEN is inside of entropy pool.*/
+ ASSERT((CONFIG_MD2_BLOCK_LEN + i) < CONFIG_SIZE_ENTROPY_POOL);
+
+ md2_init(&context);
+
+ while(n < 0)
+ {
+ /*Hash previous state of pool*/
+ md2_update(&context, &pool->pool_entropy[i], CONFIG_MD2_BLOCK_LEN);
+
+ memcpy(data, md2_end(&context), len);
+
+ n -= len; //Number of byte copied in data.
+
+ len = MIN(n, CONFIG_MD2_BLOCK_LEN);
+
+ i = (i + CONFIG_MD2_BLOCK_LEN) % CONFIG_SIZE_ENTROPY_POOL;
+
+ /* If we haven't more entropy pool to hash, we stir it.*/
+ if(i < CONFIG_MD2_BLOCK_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*/
+ if(pool->entropy < 0)
+ pool->entropy = 0;