mbed TLS v2.2.0
entropy.h
Go to the documentation of this file.
1 
23 #ifndef MBEDTLS_ENTROPY_H
24 #define MBEDTLS_ENTROPY_H
25 
26 #if !defined(MBEDTLS_CONFIG_FILE)
27 #include "config.h"
28 #else
29 #include MBEDTLS_CONFIG_FILE
30 #endif
31 
32 #if defined(MBEDTLS_ENTROPY_ALT)
33 
34 #include "entropy_alt.h"
35 
36 #else
37 
38 #include <stddef.h>
39 
40 #if defined(MBEDTLS_SHA512_C) && !defined(MBEDTLS_ENTROPY_FORCE_SHA256)
41 #include "sha512.h"
42 #define MBEDTLS_ENTROPY_SHA512_ACCUMULATOR
43 #else
44 #if defined(MBEDTLS_SHA256_C)
45 #define MBEDTLS_ENTROPY_SHA256_ACCUMULATOR
46 #include "sha256.h"
47 #endif
48 #endif
49 
50 #if defined(MBEDTLS_THREADING_C)
51 #include "threading.h"
52 #endif
53 
54 #if defined(MBEDTLS_HAVEGE_C)
55 #include "havege.h"
56 #endif
57 
58 #define MBEDTLS_ERR_ENTROPY_SOURCE_FAILED -0x003C
59 #define MBEDTLS_ERR_ENTROPY_MAX_SOURCES -0x003E
60 #define MBEDTLS_ERR_ENTROPY_NO_SOURCES_DEFINED -0x0040
61 #define MBEDTLS_ERR_ENTROPY_NO_STRONG_SOURCE -0x003D
62 #define MBEDTLS_ERR_ENTROPY_FILE_IO_ERROR -0x003F
72 #if !defined(MBEDTLS_ENTROPY_MAX_SOURCES)
73 #define MBEDTLS_ENTROPY_MAX_SOURCES 20
74 #endif
75 
76 #if !defined(MBEDTLS_ENTROPY_MAX_GATHER)
77 #define MBEDTLS_ENTROPY_MAX_GATHER 128
78 #endif
79 
80 /* \} name SECTION: Module settings */
81 
82 #if defined(MBEDTLS_ENTROPY_SHA512_ACCUMULATOR)
83 #define MBEDTLS_ENTROPY_BLOCK_SIZE 64
84 #else
85 #define MBEDTLS_ENTROPY_BLOCK_SIZE 32
86 #endif
87 
88 #define MBEDTLS_ENTROPY_MAX_SEED_SIZE 1024
89 #define MBEDTLS_ENTROPY_SOURCE_MANUAL MBEDTLS_ENTROPY_MAX_SOURCES
90 
91 #define MBEDTLS_ENTROPY_SOURCE_STRONG 1
92 #define MBEDTLS_ENTROPY_SOURCE_WEAK 0
94 #ifdef __cplusplus
95 extern "C" {
96 #endif
97 
109 typedef int (*mbedtls_entropy_f_source_ptr)(void *data, unsigned char *output, size_t len,
110  size_t *olen);
111 
115 typedef struct
116 {
118  void * p_source;
119  size_t size;
120  size_t threshold;
121  int strong;
122 }
124 
128 typedef struct
129 {
130 #if defined(MBEDTLS_ENTROPY_SHA512_ACCUMULATOR)
131  mbedtls_sha512_context accumulator;
132 #else
133  mbedtls_sha256_context accumulator;
134 #endif
135  int source_count;
137 #if defined(MBEDTLS_HAVEGE_C)
138  mbedtls_havege_state havege_data;
139 #endif
140 #if defined(MBEDTLS_THREADING_C)
141  mbedtls_threading_mutex_t mutex;
142 #endif
143 }
145 
152 
159 
178  mbedtls_entropy_f_source_ptr f_source, void *p_source,
179  size_t threshold, int strong );
180 
190 
202 int mbedtls_entropy_func( void *data, unsigned char *output, size_t len );
203 
215  const unsigned char *data, size_t len );
216 
217 #if defined(MBEDTLS_FS_IO)
218 
228 int mbedtls_entropy_write_seed_file( mbedtls_entropy_context *ctx, const char *path );
229 
242 int mbedtls_entropy_update_seed_file( mbedtls_entropy_context *ctx, const char *path );
243 #endif /* MBEDTLS_FS_IO */
244 
245 #if defined(MBEDTLS_SELF_TEST)
246 
251 int mbedtls_entropy_self_test( int verbose );
252 #endif /* MBEDTLS_SELF_TEST */
253 
254 #ifdef __cplusplus
255 }
256 #endif
257 
258 #endif /* !MBEDTLS_ENTROPY_ALT */
259 
260 #endif /* entropy.h */
int(* mbedtls_entropy_f_source_ptr)(void *data, unsigned char *output, size_t len, size_t *olen)
Entropy poll callback pointer.
Definition: entropy_alt.h:107
HAVEGE state structure.
Definition: havege.h:37
Compatibility names (set of defines)
int mbedtls_entropy_gather(mbedtls_entropy_context *ctx)
Trigger an extra gather poll for the accumulator (Thread-safe if MBEDTLS_THREADING_C is enabled) ...
Entropy context structure.
Definition: entropy_alt.h:126
Threading abstraction layer.
SHA-512 context structure.
Definition: sha512.h:46
void mbedtls_entropy_init(mbedtls_entropy_context *ctx)
Initialize the context.
int mbedtls_entropy_add_source(mbedtls_entropy_context *ctx, mbedtls_entropy_f_source_ptr f_source, void *p_source, size_t threshold, int strong)
Adds an entropy source to poll (Thread-safe if MBEDTLS_THREADING_C is enabled)
#define MBEDTLS_ENTROPY_MAX_SOURCES
Maximum number of sources supported.
Definition: entropy_alt.h:71
HAVEGE: HArdware Volatile Entropy Gathering and Expansion.
SHA-256 context structure.
Definition: sha256_alt.h:58
int mbedtls_entropy_update_manual(mbedtls_entropy_context *ctx, const unsigned char *data, size_t len)
Add data to the accumulator manually (Thread-safe if MBEDTLS_THREADING_C is enabled) ...
void mbedtls_entropy_free(mbedtls_entropy_context *ctx)
Free the data in the context.
SHA-384 and SHA-512 cryptographic hash function.
int mbedtls_entropy_func(void *data, unsigned char *output, size_t len)
Retrieve entropy from the accumulator (Maximum length: MBEDTLS_ENTROPY_BLOCK_SIZE) (Thread-safe if MB...
SHA-224 and SHA-256 cryptographic hash function.
Entropy source state.
Definition: entropy_alt.h:113