entropy.h File Reference

Entropy accumulator implementation. More...

#include <string.h>
#include "config.h"
#include "sha512.h"
Include dependency graph for entropy.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  source_state
 Entropy source state. More...
struct  entropy_context
 Entropy context structure. More...

Defines

#define POLARSSL_ENTROPY_SHA512_ACCUMULATOR
#define POLARSSL_ERR_ENTROPY_SOURCE_FAILED   -0x003C
 Critical entropy source failure.
#define POLARSSL_ERR_ENTROPY_MAX_SOURCES   -0x003E
 No more sources can be added.
#define POLARSSL_ERR_ENTROPY_NO_SOURCES_DEFINED   -0x0040
 No sources have been added to poll.
#define ENTROPY_MAX_SOURCES   20
 Maximum number of sources supported.
#define ENTROPY_MAX_GATHER   128
 Maximum amount requested from entropy sources.
#define ENTROPY_BLOCK_SIZE   64
 Block size of entropy accumulator (SHA-512).
#define ENTROPY_SOURCE_MANUAL   ENTROPY_MAX_SOURCES

Typedefs

typedef int(* f_source_ptr )(void *, unsigned char *, size_t, size_t *)
 Entropy poll callback pointer.

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.
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).
int entropy_update_manual (entropy_context *ctx, const unsigned char *data, size_t len)
 Add data to the accumulator manually.

Detailed Description

Entropy accumulator implementation.

Copyright (C) 2006-2013, Brainspark B.V.

This file is part of PolarSSL (http://www.polarssl.org) Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>

All rights reserved.

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

Definition in file entropy.h.


Define Documentation

#define ENTROPY_BLOCK_SIZE   64

Block size of entropy accumulator (SHA-512).

Definition at line 62 of file entropy.h.

Referenced by entropy_func(), and entropy_update().

#define ENTROPY_MAX_GATHER   128

Maximum amount requested from entropy sources.

Definition at line 58 of file entropy.h.

Referenced by entropy_gather().

#define ENTROPY_MAX_SOURCES   20

Maximum number of sources supported.

Definition at line 57 of file entropy.h.

Referenced by entropy_add_source().

#define ENTROPY_SOURCE_MANUAL   ENTROPY_MAX_SOURCES

Definition at line 67 of file entropy.h.

Referenced by entropy_update_manual().

#define POLARSSL_ENTROPY_SHA512_ACCUMULATOR

Definition at line 36 of file entropy.h.

#define POLARSSL_ERR_ENTROPY_MAX_SOURCES   -0x003E

No more sources can be added.

Definition at line 53 of file entropy.h.

Referenced by entropy_add_source(), and polarssl_strerror().

#define POLARSSL_ERR_ENTROPY_NO_SOURCES_DEFINED   -0x0040

No sources have been added to poll.

Definition at line 54 of file entropy.h.

Referenced by entropy_gather(), and polarssl_strerror().

#define POLARSSL_ERR_ENTROPY_SOURCE_FAILED   -0x003C

Critical entropy source failure.

Definition at line 52 of file entropy.h.

Referenced by entropy_func(), platform_entropy_poll(), and polarssl_strerror().


Typedef Documentation

typedef int(* f_source_ptr)(void *, unsigned char *, size_t, size_t *)

Entropy poll callback pointer.

Parameters:
data Callback-specific data pointer
output Data to fill
len Maximum size to provide
olen The actual amount of bytes put into the buffer (Can be 0)
Returns:
0 if no critical failures occurred, POLARSSL_ERR_ENTROPY_SOURCE_FAILED otherwise

Definition at line 84 of file entropy.h.


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, test_offset, and source_state::threshold.

Referenced by test_suite_ctr_drbg_validate_nopr(), and test_suite_ctr_drbg_validate_pr().

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().

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