mbed TLS v2.0.0
ctr_drbg.h
Go to the documentation of this file.
1 
24 #ifndef MBEDTLS_CTR_DRBG_H
25 #define MBEDTLS_CTR_DRBG_H
26 
27 #include "aes.h"
28 
29 #if defined(MBEDTLS_THREADING_C)
30 #include "mbedtls/threading.h"
31 #endif
32 
33 #define MBEDTLS_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED -0x0034
34 #define MBEDTLS_ERR_CTR_DRBG_REQUEST_TOO_BIG -0x0036
35 #define MBEDTLS_ERR_CTR_DRBG_INPUT_TOO_BIG -0x0038
36 #define MBEDTLS_ERR_CTR_DRBG_FILE_IO_ERROR -0x003A
38 #define MBEDTLS_CTR_DRBG_BLOCKSIZE 16
39 #define MBEDTLS_CTR_DRBG_KEYSIZE 32
40 #define MBEDTLS_CTR_DRBG_KEYBITS ( MBEDTLS_CTR_DRBG_KEYSIZE * 8 )
41 #define MBEDTLS_CTR_DRBG_SEEDLEN ( MBEDTLS_CTR_DRBG_KEYSIZE + MBEDTLS_CTR_DRBG_BLOCKSIZE )
42 
52 #if !defined(MBEDTLS_CTR_DRBG_ENTROPY_LEN)
53 #if defined(MBEDTLS_SHA512_C) && !defined(MBEDTLS_ENTROPY_FORCE_SHA256)
54 #define MBEDTLS_CTR_DRBG_ENTROPY_LEN 48
55 #else
56 #define MBEDTLS_CTR_DRBG_ENTROPY_LEN 32
57 #endif
58 #endif
59 
60 #if !defined(MBEDTLS_CTR_DRBG_RESEED_INTERVAL)
61 #define MBEDTLS_CTR_DRBG_RESEED_INTERVAL 10000
62 #endif
63 
64 #if !defined(MBEDTLS_CTR_DRBG_MAX_INPUT)
65 #define MBEDTLS_CTR_DRBG_MAX_INPUT 256
66 #endif
67 
68 #if !defined(MBEDTLS_CTR_DRBG_MAX_REQUEST)
69 #define MBEDTLS_CTR_DRBG_MAX_REQUEST 1024
70 #endif
71 
72 #if !defined(MBEDTLS_CTR_DRBG_MAX_SEED_INPUT)
73 #define MBEDTLS_CTR_DRBG_MAX_SEED_INPUT 384
74 #endif
75 
76 /* \} name SECTION: Module settings */
77 
78 #define MBEDTLS_CTR_DRBG_PR_OFF 0
79 #define MBEDTLS_CTR_DRBG_PR_ON 1
81 #ifdef __cplusplus
82 extern "C" {
83 #endif
84 
88 typedef struct
89 {
90  unsigned char counter[16];
94  size_t entropy_len;
100  /*
101  * Callbacks (Entropy)
102  */
103  int (*f_entropy)(void *, unsigned char *, size_t);
104 
105  void *p_entropy;
107 #if defined(MBEDTLS_THREADING_C)
108  mbedtls_threading_mutex_t mutex;
109 #endif
110 }
112 
121 
141  int (*f_entropy)(void *, unsigned char *, size_t),
142  void *p_entropy,
143  const unsigned char *custom,
144  size_t len );
145 
152 
163  int resistance );
164 
173  size_t len );
174 
183  int interval );
184 
196  const unsigned char *additional, size_t len );
197 
210  const unsigned char *additional, size_t add_len );
211 
227 int mbedtls_ctr_drbg_random_with_add( void *p_rng,
228  unsigned char *output, size_t output_len,
229  const unsigned char *additional, size_t add_len );
230 
244 int mbedtls_ctr_drbg_random( void *p_rng,
245  unsigned char *output, size_t output_len );
246 
247 #if defined(MBEDTLS_FS_IO)
248 
258 int mbedtls_ctr_drbg_write_seed_file( mbedtls_ctr_drbg_context *ctx, const char *path );
259 
272 int mbedtls_ctr_drbg_update_seed_file( mbedtls_ctr_drbg_context *ctx, const char *path );
273 #endif /* MBEDTLS_FS_IO */
274 
280 int mbedtls_ctr_drbg_self_test( int verbose );
281 
282 /* Internal functions (do not call directly) */
284  int (*)(void *, unsigned char *, size_t), void *,
285  const unsigned char *, size_t, size_t );
286 
287 #ifdef __cplusplus
288 }
289 #endif
290 
291 #endif /* ctr_drbg.h */
CTR_DRBG context structure.
Definition: ctr_drbg.h:88
void mbedtls_ctr_drbg_free(mbedtls_ctr_drbg_context *ctx)
Clear CTR_CRBG context data.
void mbedtls_ctr_drbg_update(mbedtls_ctr_drbg_context *ctx, const unsigned char *additional, size_t add_len)
CTR_DRBG update state.
int mbedtls_ctr_drbg_seed_entropy_len(mbedtls_ctr_drbg_context *, int(*)(void *, unsigned char *, size_t), void *, const unsigned char *, size_t, size_t)
void mbedtls_ctr_drbg_init(mbedtls_ctr_drbg_context *ctx)
CTR_DRBG context initialization Makes the context ready for mbetls_ctr_drbg_seed() or mbedtls_ctr_drb...
int mbedtls_ctr_drbg_random(void *p_rng, unsigned char *output, size_t output_len)
CTR_DRBG generate random.
int mbedtls_ctr_drbg_write_seed_file(mbedtls_ctr_drbg_context *ctx, const char *path)
Write a seed file.
void mbedtls_ctr_drbg_set_reseed_interval(mbedtls_ctr_drbg_context *ctx, int interval)
Set the reseed interval (Default: MBEDTLS_CTR_DRBG_RESEED_INTERVAL)
void mbedtls_ctr_drbg_set_prediction_resistance(mbedtls_ctr_drbg_context *ctx, int resistance)
Enable / disable prediction resistance (Default: Off)
int mbedtls_ctr_drbg_reseed(mbedtls_ctr_drbg_context *ctx, const unsigned char *additional, size_t len)
CTR_DRBG reseeding (extracts data from entropy source)
Threading abstraction layer.
int mbedtls_ctr_drbg_update_seed_file(mbedtls_ctr_drbg_context *ctx, const char *path)
Read and update a seed file.
int mbedtls_ctr_drbg_random_with_add(void *p_rng, unsigned char *output, size_t output_len, const unsigned char *additional, size_t add_len)
CTR_DRBG generate random with additional update input.
void mbedtls_ctr_drbg_set_entropy_len(mbedtls_ctr_drbg_context *ctx, size_t len)
Set the amount of entropy grabbed on each (re)seed (Default: MBEDTLS_CTR_DRBG_ENTROPY_LEN) ...
AES block cipher.
int mbedtls_ctr_drbg_seed(mbedtls_ctr_drbg_context *ctx, int(*f_entropy)(void *, unsigned char *, size_t), void *p_entropy, const unsigned char *custom, size_t len)
CTR_DRBG initial seeding Seed and setup entropy source for future reseeds.
int mbedtls_ctr_drbg_self_test(int verbose)
Checkup routine.
mbedtls_aes_context aes_ctx
Definition: ctr_drbg.h:98
AES context structure.
Definition: aes.h:59