mbed TLS v2.3.0
ctr_drbg.h
Go to the documentation of this file.
1 
25 #ifndef MBEDTLS_CTR_DRBG_H
26 #define MBEDTLS_CTR_DRBG_H
27 
28 #include "aes.h"
29 
30 #if defined(MBEDTLS_THREADING_C)
31 #include "mbedtls/threading.h"
32 #endif
33 
34 #define MBEDTLS_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED -0x0034
35 #define MBEDTLS_ERR_CTR_DRBG_REQUEST_TOO_BIG -0x0036
36 #define MBEDTLS_ERR_CTR_DRBG_INPUT_TOO_BIG -0x0038
37 #define MBEDTLS_ERR_CTR_DRBG_FILE_IO_ERROR -0x003A
39 #define MBEDTLS_CTR_DRBG_BLOCKSIZE 16
40 #define MBEDTLS_CTR_DRBG_KEYSIZE 32
41 #define MBEDTLS_CTR_DRBG_KEYBITS ( MBEDTLS_CTR_DRBG_KEYSIZE * 8 )
42 #define MBEDTLS_CTR_DRBG_SEEDLEN ( MBEDTLS_CTR_DRBG_KEYSIZE + MBEDTLS_CTR_DRBG_BLOCKSIZE )
43 
53 #if !defined(MBEDTLS_CTR_DRBG_ENTROPY_LEN)
54 #if defined(MBEDTLS_SHA512_C) && !defined(MBEDTLS_ENTROPY_FORCE_SHA256)
55 #define MBEDTLS_CTR_DRBG_ENTROPY_LEN 48
56 #else
57 #define MBEDTLS_CTR_DRBG_ENTROPY_LEN 32
58 #endif
59 #endif
60 
61 #if !defined(MBEDTLS_CTR_DRBG_RESEED_INTERVAL)
62 #define MBEDTLS_CTR_DRBG_RESEED_INTERVAL 10000
63 #endif
64 
65 #if !defined(MBEDTLS_CTR_DRBG_MAX_INPUT)
66 #define MBEDTLS_CTR_DRBG_MAX_INPUT 256
67 #endif
68 
69 #if !defined(MBEDTLS_CTR_DRBG_MAX_REQUEST)
70 #define MBEDTLS_CTR_DRBG_MAX_REQUEST 1024
71 #endif
72 
73 #if !defined(MBEDTLS_CTR_DRBG_MAX_SEED_INPUT)
74 #define MBEDTLS_CTR_DRBG_MAX_SEED_INPUT 384
75 #endif
76 
77 /* \} name SECTION: Module settings */
78 
79 #define MBEDTLS_CTR_DRBG_PR_OFF 0
80 #define MBEDTLS_CTR_DRBG_PR_ON 1
82 #ifdef __cplusplus
83 extern "C" {
84 #endif
85 
89 typedef struct
90 {
91  unsigned char counter[16];
95  size_t entropy_len;
101  /*
102  * Callbacks (Entropy)
103  */
104  int (*f_entropy)(void *, unsigned char *, size_t);
105 
106  void *p_entropy;
108 #if defined(MBEDTLS_THREADING_C)
109  mbedtls_threading_mutex_t mutex;
110 #endif
111 }
113 
122 
142  int (*f_entropy)(void *, unsigned char *, size_t),
143  void *p_entropy,
144  const unsigned char *custom,
145  size_t len );
146 
153 
164  int resistance );
165 
174  size_t len );
175 
184  int interval );
185 
197  const unsigned char *additional, size_t len );
198 
211  const unsigned char *additional, size_t add_len );
212 
228 int mbedtls_ctr_drbg_random_with_add( void *p_rng,
229  unsigned char *output, size_t output_len,
230  const unsigned char *additional, size_t add_len );
231 
245 int mbedtls_ctr_drbg_random( void *p_rng,
246  unsigned char *output, size_t output_len );
247 
248 #if defined(MBEDTLS_FS_IO)
249 
259 int mbedtls_ctr_drbg_write_seed_file( mbedtls_ctr_drbg_context *ctx, const char *path );
260 
273 int mbedtls_ctr_drbg_update_seed_file( mbedtls_ctr_drbg_context *ctx, const char *path );
274 #endif /* MBEDTLS_FS_IO */
275 
281 int mbedtls_ctr_drbg_self_test( int verbose );
282 
283 /* Internal functions (do not call directly) */
285  int (*)(void *, unsigned char *, size_t), void *,
286  const unsigned char *, size_t, size_t );
287 
288 #ifdef __cplusplus
289 }
290 #endif
291 
292 #endif /* ctr_drbg.h */
CTR_DRBG context structure.
Definition: ctr_drbg.h:89
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 mbedtls_ctr_drbg_seed() or mbedtls_ctr_dr...
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:99
AES context structure.
Definition: aes.h:60