1
0
mirror of https://github.com/Mbed-TLS/mbedtls.git synced 2025-08-01 10:06:53 +03:00

- Changed the used random function pointer to more flexible format. Renamed havege_rand() to havege_random() to prevent mistakes. Lots of changes as a consequence in library code and programs

This commit is contained in:
Paul Bakker
2011-11-27 21:07:34 +00:00
parent 880ac7eb95
commit a3d195c41f
31 changed files with 232 additions and 119 deletions

View File

@ -200,18 +200,32 @@ void havege_init( havege_state *hs )
/*
* HAVEGE rand function
*/
int havege_rand( void *p_rng )
int havege_random( void *p_rng, unsigned char *buf, size_t len )
{
int ret;
int val;
size_t use_len;
havege_state *hs = (havege_state *) p_rng;
unsigned char *p = buf;
if( hs->offset[1] >= COLLECT_SIZE )
havege_fill( hs );
while( len > 0 )
{
use_len = len;
if( use_len > sizeof(int) )
use_len = sizeof(int);
ret = hs->pool[hs->offset[0]++];
ret ^= hs->pool[hs->offset[1]++];
if( hs->offset[1] >= COLLECT_SIZE )
havege_fill( hs );
return( ret );
val = hs->pool[hs->offset[0]++];
val ^= hs->pool[hs->offset[1]++];
memcpy( p, &val, use_len );
len -= use_len;
p += use_len;
}
return( 0 );
}
#endif