PolarSSL v1.2.12
Data Structures | Macros | Typedefs | Functions
entropy.h File Reference

Entropy accumulator implementation. More...

#include <string.h>
#include "config.h"
#include "sha4.h"
Include dependency graph for entropy.h:

Go to the source code of this file.

Data Structures

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

Macros

#define POLARSSL_ERR_ENTROPY_SOURCE_FAILED   -0x003C
 Critical entropy source failure. More...
 
#define POLARSSL_ERR_ENTROPY_MAX_SOURCES   -0x003E
 No more sources can be added. More...
 
#define POLARSSL_ERR_ENTROPY_NO_SOURCES_DEFINED   -0x0040
 No sources have been added to poll. More...
 
#define POLARSSL_ERR_ENTROPY_FILE_IO_ERROR   -0x0058
 Read/write error in file. More...
 
#define ENTROPY_MAX_SOURCES   20
 Maximum number of sources supported. More...
 
#define ENTROPY_MAX_GATHER   128
 Maximum amount requested from entropy sources. More...
 
#define ENTROPY_BLOCK_SIZE   64
 Block size of entropy accumulator (SHA-512) More...
 
#define ENTROPY_MAX_SEED_SIZE   1024
 Maximum size of seed we read from seed file. More...
 
#define ENTROPY_SOURCE_MANUAL   ENTROPY_MAX_SOURCES
 

Typedefs

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

Functions

void entropy_init (entropy_context *ctx)
 Initialize the context. More...
 
int entropy_add_source (entropy_context *ctx, f_source_ptr f_source, void *p_source, size_t threshold)
 Adds an entropy source to poll. More...
 
int entropy_gather (entropy_context *ctx)
 Trigger an extra gather poll for the accumulator. More...
 
int entropy_func (void *data, unsigned char *output, size_t len)
 Retrieve entropy from the accumulator (Max ENTROPY_BLOCK_SIZE) More...
 
int entropy_update_manual (entropy_context *ctx, const unsigned char *data, size_t len)
 Add data to the accumulator manually. More...
 
int entropy_write_seed_file (entropy_context *ctx, const char *path)
 Write a seed file. More...
 
int entropy_update_seed_file (entropy_context *ctx, const char *path)
 Read and update a seed file. More...
 

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.

Macro Definition Documentation

#define ENTROPY_BLOCK_SIZE   64

Block size of entropy accumulator (SHA-512)

Definition at line 49 of file entropy.h.

#define ENTROPY_MAX_GATHER   128

Maximum amount requested from entropy sources.

Definition at line 46 of file entropy.h.

#define ENTROPY_MAX_SEED_SIZE   1024

Maximum size of seed we read from seed file.

Definition at line 51 of file entropy.h.

#define ENTROPY_MAX_SOURCES   20

Maximum number of sources supported.

Definition at line 45 of file entropy.h.

#define ENTROPY_SOURCE_MANUAL   ENTROPY_MAX_SOURCES

Definition at line 52 of file entropy.h.

#define POLARSSL_ERR_ENTROPY_FILE_IO_ERROR   -0x0058

Read/write error in file.

Definition at line 42 of file entropy.h.

#define POLARSSL_ERR_ENTROPY_MAX_SOURCES   -0x003E

No more sources can be added.

Definition at line 40 of file entropy.h.

#define POLARSSL_ERR_ENTROPY_NO_SOURCES_DEFINED   -0x0040

No sources have been added to poll.

Definition at line 41 of file entropy.h.

#define POLARSSL_ERR_ENTROPY_SOURCE_FAILED   -0x003C

Critical entropy source failure.

Definition at line 39 of file entropy.h.

Typedef Documentation

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

Entropy poll callback pointer.

Parameters
dataCallback-specific data pointer
outputData to fill
lenMaximum size to provide
olenThe 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 69 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
ctxEntropy context
f_sourceEntropy function
p_sourceFunction data
thresholdMinimum required from source before entropy is released ( with entropy_func() )
Returns
0 if successful or POLARSSL_ERR_ENTROPY_MAX_SOURCES
int entropy_func ( void *  data,
unsigned char *  output,
size_t  len 
)

Retrieve entropy from the accumulator (Max ENTROPY_BLOCK_SIZE)

Parameters
dataEntropy context
outputBuffer to fill
lenLength of buffer
Returns
0 if successful, or POLARSSL_ERR_ENTROPY_SOURCE_FAILED
int entropy_gather ( entropy_context ctx)

Trigger an extra gather poll for the accumulator.

Parameters
ctxEntropy context
Returns
0 if successful, or POLARSSL_ERR_ENTROPY_SOURCE_FAILED
void entropy_init ( entropy_context ctx)

Initialize the context.

Parameters
ctxEntropy context to initialize
int entropy_update_manual ( entropy_context ctx,
const unsigned char *  data,
size_t  len 
)

Add data to the accumulator manually.

Parameters
ctxEntropy context
dataData to add
lenLength of data
Returns
0 if successful
int entropy_update_seed_file ( entropy_context ctx,
const char *  path 
)

Read and update a seed file.

Seed is added to this instance. No more than ENTROPY_MAX_SEED_SIZE bytes are read from the seed file. The rest is ignored.

Parameters
ctxEntropy context
pathName of the file
Returns
0 if successful, POLARSSL_ERR_ENTROPY_FILE_IO_ERROR on file error, POLARSSL_ERR_ENTROPY_SOURCE_FAILED
int entropy_write_seed_file ( entropy_context ctx,
const char *  path 
)

Write a seed file.

Parameters
ctxEntropy context
pathName of the file
Returns
0 if successful, POLARSSL_ERR_ENTROPY_FILE_IO_ERROR on file error, or POLARSSL_ERR_ENTROPY_SOURCE_FAILED