PolarSSL v1.3.9
entropy.h
Go to the documentation of this file.
1
27#ifndef POLARSSL_ENTROPY_H
28#define POLARSSL_ENTROPY_H
29
30#include <string.h>
31
32#if !defined(POLARSSL_CONFIG_FILE)
33#include "config.h"
34#else
35#include POLARSSL_CONFIG_FILE
36#endif
37
38#if defined(POLARSSL_SHA512_C) && !defined(POLARSSL_ENTROPY_FORCE_SHA256)
39#include "sha512.h"
40#define POLARSSL_ENTROPY_SHA512_ACCUMULATOR
41#else
42#if defined(POLARSSL_SHA256_C)
43#define POLARSSL_ENTROPY_SHA256_ACCUMULATOR
44#include "sha256.h"
45#endif
46#endif
47
48#if defined(POLARSSL_THREADING_C)
49#include "threading.h"
50#endif
51
52#if defined(POLARSSL_HAVEGE_C)
53#include "havege.h"
54#endif
55
56#define POLARSSL_ERR_ENTROPY_SOURCE_FAILED -0x003C
57#define POLARSSL_ERR_ENTROPY_MAX_SOURCES -0x003E
58#define POLARSSL_ERR_ENTROPY_NO_SOURCES_DEFINED -0x0040
59#define POLARSSL_ERR_ENTROPY_FILE_IO_ERROR -0x0058
69#if !defined(ENTROPY_MAX_SOURCES)
70#define ENTROPY_MAX_SOURCES 20
71#endif
72
73#if !defined(ENTROPY_MAX_GATHER)
74#define ENTROPY_MAX_GATHER 128
75#endif
76
77/* \} name SECTION: Module settings */
78
79#if defined(POLARSSL_ENTROPY_SHA512_ACCUMULATOR)
80#define ENTROPY_BLOCK_SIZE 64
81#else
82#define ENTROPY_BLOCK_SIZE 32
83#endif
84
85#define ENTROPY_MAX_SEED_SIZE 1024
86#define ENTROPY_SOURCE_MANUAL ENTROPY_MAX_SOURCES
87
88#ifdef __cplusplus
89extern "C" {
90#endif
91
103typedef int (*f_source_ptr)(void *data, unsigned char *output, size_t len,
104 size_t *olen);
105
109typedef struct
110{
112 void * p_source;
113 size_t size;
114 size_t threshold;
115}
117
121typedef struct
122{
123#if defined(POLARSSL_ENTROPY_SHA512_ACCUMULATOR)
125#else
126 sha256_context accumulator;
127#endif
130#if defined(POLARSSL_HAVEGE_C)
132#endif
133#if defined(POLARSSL_THREADING_C)
134 threading_mutex_t mutex;
135#endif
136}
138
145
152
166 f_source_ptr f_source, void *p_source,
167 size_t threshold );
168
178
190int entropy_func( void *data, unsigned char *output, size_t len );
191
203 const unsigned char *data, size_t len );
204
205#if defined(POLARSSL_FS_IO)
216int entropy_write_seed_file( entropy_context *ctx, const char *path );
217
230int entropy_update_seed_file( entropy_context *ctx, const char *path );
231#endif /* POLARSSL_FS_IO */
232
233#if defined(POLARSSL_SELF_TEST)
239int entropy_self_test( int verbose );
240#endif /* POLARSSL_SELF_TEST */
241
242#ifdef __cplusplus
243}
244#endif
245
246#endif /* entropy.h */
Configuration options (set of defines)
void entropy_init(entropy_context *ctx)
Initialize the context.
int entropy_func(void *data, unsigned char *output, size_t len)
Retrieve entropy from the accumulator (Maximum length: ENTROPY_BLOCK_SIZE) (Thread-safe if POLARSSL_T...
int(* f_source_ptr)(void *data, unsigned char *output, size_t len, size_t *olen)
Entropy poll callback pointer.
Definition: entropy.h:103
int entropy_update_manual(entropy_context *ctx, const unsigned char *data, size_t len)
Add data to the accumulator manually (Thread-safe if POLARSSL_THREADING_C is enabled)
int entropy_add_source(entropy_context *ctx, f_source_ptr f_source, void *p_source, size_t threshold)
Adds an entropy source to poll (Thread-safe if POLARSSL_THREADING_C is enabled)
int entropy_update_seed_file(entropy_context *ctx, const char *path)
Read and update a seed file.
#define ENTROPY_MAX_SOURCES
Maximum number of sources supported.
Definition: entropy.h:70
int entropy_gather(entropy_context *ctx)
Trigger an extra gather poll for the accumulator (Thread-safe if POLARSSL_THREADING_C is enabled)
void entropy_free(entropy_context *ctx)
Free the data in the context.
int entropy_self_test(int verbose)
Checkup routine.
int entropy_write_seed_file(entropy_context *ctx, const char *path)
Write a seed file.
HAVEGE: HArdware Volatile Entropy Gathering and Expansion.
SHA-224 and SHA-256 cryptographic hash function.
SHA-384 and SHA-512 cryptographic hash function.
Entropy context structure.
Definition: entropy.h:122
int source_count
Definition: entropy.h:128
sha512_context accumulator
Definition: entropy.h:124
havege_state havege_data
Definition: entropy.h:131
HAVEGE state structure.
Definition: havege.h:42
SHA-256 context structure.
Definition: sha256.h:59
SHA-512 context structure.
Definition: sha512.h:60
Entropy source state.
Definition: entropy.h:110
f_source_ptr f_source
The entropy source callback.
Definition: entropy.h:111
void * p_source
The callback data pointer.
Definition: entropy.h:112
size_t threshold
Minimum level required before release.
Definition: entropy.h:114
size_t size
Amount received.
Definition: entropy.h:113
Threading abstraction layer.