mbed TLS v1.3.18
ctr_drbg.h
Go to the documentation of this file.
1 
24 #ifndef POLARSSL_CTR_DRBG_H
25 #define POLARSSL_CTR_DRBG_H
26 
27 #include "aes.h"
28 
29 #define POLARSSL_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED -0x0034
30 #define POLARSSL_ERR_CTR_DRBG_REQUEST_TOO_BIG -0x0036
31 #define POLARSSL_ERR_CTR_DRBG_INPUT_TOO_BIG -0x0038
32 #define POLARSSL_ERR_CTR_DRBG_FILE_IO_ERROR -0x003A
34 #define CTR_DRBG_BLOCKSIZE 16
35 #define CTR_DRBG_KEYSIZE 32
36 #define CTR_DRBG_KEYBITS ( CTR_DRBG_KEYSIZE * 8 )
37 #define CTR_DRBG_SEEDLEN ( CTR_DRBG_KEYSIZE + CTR_DRBG_BLOCKSIZE )
38 
48 #if !defined(CTR_DRBG_ENTROPY_LEN)
49 #if defined(POLARSSL_SHA512_C) && !defined(POLARSSL_ENTROPY_FORCE_SHA256)
50 #define CTR_DRBG_ENTROPY_LEN 48
51 #else
52 #define CTR_DRBG_ENTROPY_LEN 32
53 #endif
54 #endif
55 
56 #if !defined(CTR_DRBG_RESEED_INTERVAL)
57 #define CTR_DRBG_RESEED_INTERVAL 10000
58 #endif
59 
60 #if !defined(CTR_DRBG_MAX_INPUT)
61 #define CTR_DRBG_MAX_INPUT 256
62 #endif
63 
64 #if !defined(CTR_DRBG_MAX_REQUEST)
65 #define CTR_DRBG_MAX_REQUEST 1024
66 #endif
67 
68 #if !defined(CTR_DRBG_MAX_SEED_INPUT)
69 #define CTR_DRBG_MAX_SEED_INPUT 384
70 #endif
71 
72 /* \} name SECTION: Module settings */
73 
74 #define CTR_DRBG_PR_OFF 0
75 #define CTR_DRBG_PR_ON 1
77 #ifdef __cplusplus
78 extern "C" {
79 #endif
80 
84 typedef struct
85 {
86  unsigned char counter[16];
90  size_t entropy_len;
96  /*
97  * Callbacks (Entropy)
98  */
99  int (*f_entropy)(void *, unsigned char *, size_t);
100 
101  void *p_entropy;
102 }
104 
123  int (*f_entropy)(void *, unsigned char *, size_t),
124  void *p_entropy,
125  const unsigned char *custom,
126  size_t len );
127 
133 void ctr_drbg_free( ctr_drbg_context *ctx );
134 
145  int resistance );
146 
155  size_t len );
156 
165  int interval );
166 
178  const unsigned char *additional, size_t len );
179 
192  const unsigned char *additional, size_t add_len );
193 
209 int ctr_drbg_random_with_add( void *p_rng,
210  unsigned char *output, size_t output_len,
211  const unsigned char *additional, size_t add_len );
212 
226 int ctr_drbg_random( void *p_rng,
227  unsigned char *output, size_t output_len );
228 
229 #if defined(POLARSSL_FS_IO)
230 
240 int ctr_drbg_write_seed_file( ctr_drbg_context *ctx, const char *path );
241 
254 int ctr_drbg_update_seed_file( ctr_drbg_context *ctx, const char *path );
255 #endif /* POLARSSL_FS_IO */
256 
262 int ctr_drbg_self_test( int verbose );
263 
264 /* Internal functions (do not call directly) */
266  int (*)(void *, unsigned char *, size_t), void *,
267  const unsigned char *, size_t, size_t );
268 
269 #ifdef __cplusplus
270 }
271 #endif
272 
273 #endif /* ctr_drbg.h */
int ctr_drbg_random(void *p_rng, unsigned char *output, size_t output_len)
CTR_DRBG generate random.
void ctr_drbg_set_prediction_resistance(ctr_drbg_context *ctx, int resistance)
Enable / disable prediction resistance (Default: Off)
int reseed_counter
Definition: ctr_drbg.h:87
AES context structure.
Definition: aes.h:65
void ctr_drbg_free(ctr_drbg_context *ctx)
Clear CTR_CRBG context data.
int ctr_drbg_init_entropy_len(ctr_drbg_context *, int(*)(void *, unsigned char *, size_t), void *, const unsigned char *, size_t, size_t)
int prediction_resistance
Definition: ctr_drbg.h:88
int 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.
size_t entropy_len
Definition: ctr_drbg.h:90
AES block cipher.
int ctr_drbg_reseed(ctr_drbg_context *ctx, const unsigned char *additional, size_t len)
CTR_DRBG reseeding (extracts data from entropy source)
int reseed_interval
Definition: ctr_drbg.h:92
CTR_DRBG context structure.
Definition: ctr_drbg.h:84
void * p_entropy
Definition: ctr_drbg.h:101
void ctr_drbg_set_reseed_interval(ctr_drbg_context *ctx, int interval)
Set the reseed interval (Default: CTR_DRBG_RESEED_INTERVAL)
int ctr_drbg_update_seed_file(ctr_drbg_context *ctx, const char *path)
Read and update a seed file.
void ctr_drbg_set_entropy_len(ctr_drbg_context *ctx, size_t len)
Set the amount of entropy grabbed on each (re)seed (Default: CTR_DRBG_ENTROPY_LEN) ...
int ctr_drbg_self_test(int verbose)
Checkup routine.
int ctr_drbg_init(ctr_drbg_context *ctx, int(*f_entropy)(void *, unsigned char *, size_t), void *p_entropy, const unsigned char *custom, size_t len)
CTR_DRBG initialization.
aes_context aes_ctx
Definition: ctr_drbg.h:94
int ctr_drbg_write_seed_file(ctr_drbg_context *ctx, const char *path)
Write a seed file.
void ctr_drbg_update(ctr_drbg_context *ctx, const unsigned char *additional, size_t add_len)
CTR_DRBG update state.