123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287 |
- #ifndef MBEDTLS_ENTROPY_H
- #define MBEDTLS_ENTROPY_H
- #if !defined(MBEDTLS_CONFIG_FILE)
- #include "config.h"
- #else
- #include MBEDTLS_CONFIG_FILE
- #endif
- #include <stddef.h>
- #if defined(MBEDTLS_SHA512_C) && !defined(MBEDTLS_ENTROPY_FORCE_SHA256)
- #include "sha512.h"
- #define MBEDTLS_ENTROPY_SHA512_ACCUMULATOR
- #else
- #if defined(MBEDTLS_SHA256_C)
- #define MBEDTLS_ENTROPY_SHA256_ACCUMULATOR
- #include "sha256.h"
- #endif
- #endif
- #if defined(MBEDTLS_THREADING_C)
- #include "threading.h"
- #endif
- #if defined(MBEDTLS_HAVEGE_C)
- #include "havege.h"
- #endif
- #define MBEDTLS_ERR_ENTROPY_SOURCE_FAILED -0x003C
- #define MBEDTLS_ERR_ENTROPY_MAX_SOURCES -0x003E
- #define MBEDTLS_ERR_ENTROPY_NO_SOURCES_DEFINED -0x0040
- #define MBEDTLS_ERR_ENTROPY_NO_STRONG_SOURCE -0x003D
- #define MBEDTLS_ERR_ENTROPY_FILE_IO_ERROR -0x003F
- #if !defined(MBEDTLS_ENTROPY_MAX_SOURCES)
- #define MBEDTLS_ENTROPY_MAX_SOURCES 20
- #endif
- #if !defined(MBEDTLS_ENTROPY_MAX_GATHER)
- #define MBEDTLS_ENTROPY_MAX_GATHER 128
- #endif
- #if defined(MBEDTLS_ENTROPY_SHA512_ACCUMULATOR)
- #define MBEDTLS_ENTROPY_BLOCK_SIZE 64
- #else
- #define MBEDTLS_ENTROPY_BLOCK_SIZE 32
- #endif
- #define MBEDTLS_ENTROPY_MAX_SEED_SIZE 1024
- #define MBEDTLS_ENTROPY_SOURCE_MANUAL MBEDTLS_ENTROPY_MAX_SOURCES
- #define MBEDTLS_ENTROPY_SOURCE_STRONG 1
- #define MBEDTLS_ENTROPY_SOURCE_WEAK 0
- #ifdef __cplusplus
- extern "C" {
- #endif
- typedef int (*mbedtls_entropy_f_source_ptr)(void *data, unsigned char *output, size_t len,
- size_t *olen);
- typedef struct
- {
- mbedtls_entropy_f_source_ptr f_source;
- void * p_source;
- size_t size;
- size_t threshold;
- int strong;
- }
- mbedtls_entropy_source_state;
- typedef struct
- {
- #if defined(MBEDTLS_ENTROPY_SHA512_ACCUMULATOR)
- mbedtls_sha512_context accumulator;
- #else
- mbedtls_sha256_context accumulator;
- #endif
- int source_count;
- mbedtls_entropy_source_state source[MBEDTLS_ENTROPY_MAX_SOURCES];
- #if defined(MBEDTLS_HAVEGE_C)
- mbedtls_havege_state havege_data;
- #endif
- #if defined(MBEDTLS_THREADING_C)
- mbedtls_threading_mutex_t mutex;
- #endif
- #if defined(MBEDTLS_ENTROPY_NV_SEED)
- int initial_entropy_run;
- #endif
- }
- mbedtls_entropy_context;
- void mbedtls_entropy_init( mbedtls_entropy_context *ctx );
- void mbedtls_entropy_free( mbedtls_entropy_context *ctx );
- int mbedtls_entropy_add_source( mbedtls_entropy_context *ctx,
- mbedtls_entropy_f_source_ptr f_source, void *p_source,
- size_t threshold, int strong );
- int mbedtls_entropy_gather( mbedtls_entropy_context *ctx );
- int mbedtls_entropy_func( void *data, unsigned char *output, size_t len );
- int mbedtls_entropy_update_manual( mbedtls_entropy_context *ctx,
- const unsigned char *data, size_t len );
- #if defined(MBEDTLS_ENTROPY_NV_SEED)
- int mbedtls_entropy_update_nv_seed( mbedtls_entropy_context *ctx );
- #endif
- #if defined(MBEDTLS_FS_IO)
- int mbedtls_entropy_write_seed_file( mbedtls_entropy_context *ctx, const char *path );
- int mbedtls_entropy_update_seed_file( mbedtls_entropy_context *ctx, const char *path );
- #endif
- #if defined(MBEDTLS_SELF_TEST)
- int mbedtls_entropy_self_test( int verbose );
- #if defined(MBEDTLS_ENTROPY_HARDWARE_ALT)
- int mbedtls_entropy_source_self_test( int verbose );
- #endif
- #endif
- #ifdef __cplusplus
- }
- #endif
- #endif
|