entropy.c File Reference

#include "polarssl/config.h"
#include "polarssl/entropy.h"
#include "polarssl/entropy_poll.h"
Include dependency graph for entropy.c:

Go to the source code of this file.

Defines

#define ENTROPY_MAX_LOOP   256
 Maximum amount to loop before error.

Functions

void entropy_init (entropy_context *ctx)
 Initialize the context.
void entropy_free (entropy_context *ctx)
 Free the data in the context.
int entropy_add_source (entropy_context *ctx, f_source_ptr f_source, void *p_source, size_t threshold)
 Adds an entropy source to poll.
static int entropy_update (entropy_context *ctx, unsigned char source_id, const unsigned char *data, size_t len)
int entropy_update_manual (entropy_context *ctx, const unsigned char *data, size_t len)
 Add data to the accumulator manually.
int entropy_gather (entropy_context *ctx)
 Trigger an extra gather poll for the accumulator.
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 is enabled).

Define Documentation

#define ENTROPY_MAX_LOOP   256

Maximum amount to loop before error.

Definition at line 37 of file entropy.c.

Referenced by entropy_func().


Function Documentation

int entropy_add_source ( entropy_context ctx,
f_source_ptr  f_source,
void *  p_source,
size_t  threshold 
)

Adds an entropy source to poll.

Parameters:
ctx Entropy context
f_source Entropy function
p_source Function data
threshold Minimum required from source before entropy is released ( with entropy_func() )
Returns:
0 if successful or POLARSSL_ERR_ENTROPY_MAX_SOURCES

Definition at line 79 of file entropy.c.

References ENTROPY_MAX_SOURCES, source_state::f_source, source_state::p_source, POLARSSL_ERR_ENTROPY_MAX_SOURCES, entropy_context::source, entropy_context::source_count, and source_state::threshold.

Referenced by entropy_init().

void entropy_free ( entropy_context ctx  ) 

Free the data in the context.

Parameters:
ctx Entropy context to free

Definition at line 71 of file entropy.c.

References polarssl_mutex_free.

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 is enabled).

Parameters:
data Entropy context
output Buffer to fill
len Length of buffer
Returns:
0 if successful, or POLARSSL_ERR_ENTROPY_SOURCE_FAILED

Definition at line 176 of file entropy.c.

References entropy_context::accumulator, ENTROPY_BLOCK_SIZE, entropy_gather(), ENTROPY_MAX_LOOP, POLARSSL_ERR_ENTROPY_SOURCE_FAILED, POLARSSL_ERR_THREADING_MUTEX_ERROR, polarssl_mutex_lock, polarssl_mutex_unlock, sha256(), sha256_finish(), sha256_starts(), sha256_update(), sha512(), sha512_finish(), sha512_starts(), sha512_update(), source_state::size, entropy_context::source, entropy_context::source_count, and source_state::threshold.

int entropy_gather ( entropy_context ctx  ) 

Trigger an extra gather poll for the accumulator.

Parameters:
ctx Entropy context
Returns:
0 if successful, or POLARSSL_ERR_ENTROPY_SOURCE_FAILED

Definition at line 142 of file entropy.c.

References ENTROPY_MAX_GATHER, entropy_update(), source_state::f_source, source_state::p_source, POLARSSL_ERR_ENTROPY_NO_SOURCES_DEFINED, source_state::size, entropy_context::source, and entropy_context::source_count.

Referenced by entropy_func().

void entropy_init ( entropy_context ctx  ) 

Initialize the context.

Parameters:
ctx Entropy context to initialize

Definition at line 39 of file entropy.c.

References entropy_add_source(), ENTROPY_MIN_HARDCLOCK, ENTROPY_MIN_HAVEGE, ENTROPY_MIN_PLATFORM, hardclock_poll(), havege_init(), platform_entropy_poll(), polarssl_mutex_init, sha256_starts(), and sha512_starts().

static int entropy_update ( entropy_context ctx,
unsigned char  source_id,
const unsigned char *  data,
size_t  len 
) [static]
int entropy_update_manual ( entropy_context ctx,
const unsigned char *  data,
size_t  len 
)

Add data to the accumulator manually.

Parameters:
ctx Entropy context
data Data to add
len Length of data
Returns:
0 if successful

Definition at line 133 of file entropy.c.

References ENTROPY_SOURCE_MANUAL, and entropy_update().


Generated on 9 Apr 2014 for PolarSSL v1.3.2 by  doxygen 1.6.1