28 #if defined(POLARSSL_ENTROPY_C)
33 #if defined(POLARSSL_FS_IO)
37 #if defined(POLARSSL_HAVEGE_C)
41 #define ENTROPY_MAX_LOOP 256
43 void entropy_init( entropy_context *ctx )
48 #if defined(POLARSSL_HAVEGE_C)
52 #if !defined(POLARSSL_NO_DEFAULT_ENTROPY_SOURCES)
53 #if !defined(POLARSSL_NO_PLATFORM_ENTROPY)
57 #if defined(POLARSSL_TIMING_C)
60 #if defined(POLARSSL_HAVEGE_C)
88 static int entropy_update(
entropy_context *ctx,
unsigned char source_id,
89 const unsigned char *data,
size_t len )
91 unsigned char header[2];
94 const unsigned char *p = data;
98 sha4( data, len, tmp, 0 );
104 header[0] = source_id;
105 header[1] = use_len & 0xFF;
114 const unsigned char *data,
size_t len )
148 entropy_update( ctx, (
unsigned char) i, buf, olen );
156 int entropy_func(
void *data,
unsigned char *output,
size_t len )
158 int ret, count = 0, i, reached;
170 if( count++ > ENTROPY_MAX_LOOP )
203 memcpy( output, buf, len );
208 #if defined(POLARSSL_FS_IO)
215 if( ( f = fopen( path,
"wb" ) ) == NULL )
240 if( ( f = fopen( path,
"rb" ) ) == NULL )
243 fseek( f, 0, SEEK_END );
244 n = (size_t) ftell( f );
245 fseek( f, 0, SEEK_SET );
250 if( fread( buf, 1, n, f ) != n )
int entropy_add_source(entropy_context *ctx, f_source_ptr f_source, void *p_source, size_t threshold)
Adds an entropy source to poll.
#define ENTROPY_MIN_PLATFORM
Minimum for platform source.
int entropy_update_manual(entropy_context *ctx, const unsigned char *data, size_t len)
Add data to the accumulator manually.
#define POLARSSL_ERR_ENTROPY_MAX_SOURCES
No more sources can be added.
Configuration options (set of defines)
int entropy_gather(entropy_context *ctx)
Trigger an extra gather poll for the accumulator.
#define ENTROPY_MIN_HARDCLOCK
Minimum for hardclock()
Entropy context structure.
#define ENTROPY_MAX_GATHER
Maximum amount requested from entropy sources.
void * p_source
The callback data pointer.
Platform-specific and custom entropy polling functions.
Entropy accumulator implementation.
#define ENTROPY_SOURCE_MANUAL
source_state source[ENTROPY_MAX_SOURCES]
#define ENTROPY_BLOCK_SIZE
Block size of entropy accumulator (SHA-512)
void sha4_starts(sha4_context *ctx, int is384)
SHA-512 context setup.
int entropy_write_seed_file(entropy_context *ctx, const char *path)
Write a seed file.
#define ENTROPY_MIN_HAVEGE
Minimum for HAVEGE.
size_t size
Amount received.
f_source_ptr f_source
The entropy source callback.
void sha4_update(sha4_context *ctx, const unsigned char *input, size_t ilen)
SHA-512 process buffer.
#define ENTROPY_MAX_SEED_SIZE
Maximum size of seed we read from seed file.
HAVEGE: HArdware Volatile Entropy Gathering and Expansion.
int platform_entropy_poll(void *data, unsigned char *output, size_t len, size_t *olen)
Platform-specific entropy poll callback.
#define ENTROPY_MAX_SOURCES
Maximum number of sources supported.
void havege_init(havege_state *hs)
HAVEGE initialization.
void sha4(const unsigned char *input, size_t ilen, unsigned char output[64], int is384)
Output = SHA-512( input buffer )
size_t threshold
Minimum level required before release.
#define POLARSSL_ERR_ENTROPY_NO_SOURCES_DEFINED
No sources have been added to poll.
SHA-512 context structure.
int entropy_update_seed_file(entropy_context *ctx, const char *path)
Read and update a seed file.
#define POLARSSL_ERR_ENTROPY_FILE_IO_ERROR
Read/write error in file.
void sha4_finish(sha4_context *ctx, unsigned char output[64])
SHA-512 final digest.
#define POLARSSL_ERR_ENTROPY_SOURCE_FAILED
Critical entropy source failure.
int(* f_source_ptr)(void *, unsigned char *, size_t, size_t *)
Entropy poll callback pointer.
int hardclock_poll(void *data, unsigned char *output, size_t len, size_t *olen)
hardclock-based entropy poll callback
int entropy_func(void *data, unsigned char *output, size_t len)
Retrieve entropy from the accumulator (Max ENTROPY_BLOCK_SIZE)