28 #if defined(POLARSSL_ENTROPY_C)
33 #if defined(POLARSSL_HAVEGE_C)
37 #define ENTROPY_MAX_LOOP 256
39 void entropy_init( entropy_context *ctx )
43 #if defined(POLARSSL_THREADING_C)
47 #if defined(POLARSSL_ENTROPY_SHA512_ACCUMULATOR)
52 #if defined(POLARSSL_HAVEGE_C)
56 #if !defined(POLARSSL_NO_DEFAULT_ENTROPY_SOURCES)
57 #if !defined(POLARSSL_NO_PLATFORM_ENTROPY)
61 #if defined(POLARSSL_TIMING_C)
64 #if defined(POLARSSL_HAVEGE_C)
74 #if defined(POLARSSL_THREADING_C)
100 static int entropy_update(
entropy_context *ctx,
unsigned char source_id,
101 const unsigned char *data,
size_t len )
103 unsigned char header[2];
105 size_t use_len = len;
106 const unsigned char *p = data;
110 #if defined(POLARSSL_ENTROPY_SHA512_ACCUMULATOR)
111 sha512( data, len, tmp, 0 );
113 sha256( data, len, tmp, 0 );
119 header[0] = source_id;
120 header[1] = use_len & 0xFF;
122 #if defined(POLARSSL_ENTROPY_SHA512_ACCUMULATOR)
134 const unsigned char *data,
size_t len )
168 entropy_update( ctx, (
unsigned char) i, buf, olen );
176 int entropy_func(
void *data,
unsigned char *output,
size_t len )
178 int ret, count = 0, i, reached;
185 #if defined(POLARSSL_THREADING_C)
195 if( count++ > ENTROPY_MAX_LOOP )
214 #if defined(POLARSSL_ENTROPY_SHA512_ACCUMULATOR)
247 memcpy( output, buf, len );
252 #if defined(POLARSSL_THREADING_C)
int(* polarssl_mutex_lock)(threading_mutex_t *mutex)
int entropy_add_source(entropy_context *ctx, f_source_ptr f_source, void *p_source, size_t threshold)
Adds an entropy source to poll.
void sha256_update(sha256_context *ctx, const unsigned char *input, size_t ilen)
SHA-256 process buffer.
void sha256(const unsigned char *input, size_t ilen, unsigned char output[32], int is224)
Output = SHA-256( input buffer )
#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.
sha512_context accumulator
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)
#define ENTROPY_MIN_HAVEGE
Minimum for HAVEGE.
size_t size
Amount received.
f_source_ptr f_source
The entropy source callback.
void sha256_starts(sha256_context *ctx, int is224)
SHA-256 context setup.
SHA-512 context structure.
void sha512_starts(sha512_context *ctx, int is384)
SHA-512 context setup.
void sha512(const unsigned char *input, size_t ilen, unsigned char output[64], int is384)
Output = SHA-512( input buffer )
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.
int(* polarssl_mutex_free)(threading_mutex_t *mutex)
#define ENTROPY_MAX_SOURCES
Maximum number of sources supported.
void sha512_finish(sha512_context *ctx, unsigned char output[64])
SHA-512 final digest.
void havege_init(havege_state *hs)
HAVEGE initialization.
size_t threshold
Minimum level required before release.
int(* polarssl_mutex_unlock)(threading_mutex_t *mutex)
#define POLARSSL_ERR_ENTROPY_NO_SOURCES_DEFINED
No sources have been added to poll.
int(* polarssl_mutex_init)(threading_mutex_t *mutex)
#define POLARSSL_ERR_THREADING_MUTEX_ERROR
Locking / unlocking / free failed with error code.
void sha256_finish(sha256_context *ctx, unsigned char output[32])
SHA-256 final digest.
SHA-256 context structure.
#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
void sha512_update(sha512_context *ctx, const unsigned char *input, size_t ilen)
SHA-512 process buffer.
int entropy_func(void *data, unsigned char *output, size_t len)
Retrieve entropy from the accumulator (Max ENTROPY_BLOCK_SIZE) (Thread-safe if POLARSSL_THREADING_C i...
void entropy_free(entropy_context *ctx)
Free the data in the context.