RetroArch
ctr_drbg.h
Go to the documentation of this file.
1 
23 #ifndef MBEDTLS_CTR_DRBG_H
24 #define MBEDTLS_CTR_DRBG_H
25 
26 #include "aes.h"
27 
28 #if defined(MBEDTLS_THREADING_C)
29 #include "mbedtls/threading.h"
30 #endif
31 
32 #define MBEDTLS_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED -0x0034
33 #define MBEDTLS_ERR_CTR_DRBG_REQUEST_TOO_BIG -0x0036
34 #define MBEDTLS_ERR_CTR_DRBG_INPUT_TOO_BIG -0x0038
35 #define MBEDTLS_ERR_CTR_DRBG_FILE_IO_ERROR -0x003A
37 #define MBEDTLS_CTR_DRBG_BLOCKSIZE 16
38 #define MBEDTLS_CTR_DRBG_KEYSIZE 32
39 #define MBEDTLS_CTR_DRBG_KEYBITS ( MBEDTLS_CTR_DRBG_KEYSIZE * 8 )
40 #define MBEDTLS_CTR_DRBG_SEEDLEN ( MBEDTLS_CTR_DRBG_KEYSIZE + MBEDTLS_CTR_DRBG_BLOCKSIZE )
41 
51 #if !defined(MBEDTLS_CTR_DRBG_ENTROPY_LEN)
52 #if defined(MBEDTLS_SHA512_C) && !defined(MBEDTLS_ENTROPY_FORCE_SHA256)
53 #define MBEDTLS_CTR_DRBG_ENTROPY_LEN 48
54 #else
55 #define MBEDTLS_CTR_DRBG_ENTROPY_LEN 32
56 #endif
57 #endif
58 
59 #if !defined(MBEDTLS_CTR_DRBG_RESEED_INTERVAL)
60 #define MBEDTLS_CTR_DRBG_RESEED_INTERVAL 10000
61 #endif
62 
63 #if !defined(MBEDTLS_CTR_DRBG_MAX_INPUT)
64 #define MBEDTLS_CTR_DRBG_MAX_INPUT 256
65 #endif
66 
67 #if !defined(MBEDTLS_CTR_DRBG_MAX_REQUEST)
68 #define MBEDTLS_CTR_DRBG_MAX_REQUEST 1024
69 #endif
70 
71 #if !defined(MBEDTLS_CTR_DRBG_MAX_SEED_INPUT)
72 #define MBEDTLS_CTR_DRBG_MAX_SEED_INPUT 384
73 #endif
74 
75 /* \} name SECTION: Module settings */
76 
77 #define MBEDTLS_CTR_DRBG_PR_OFF 0
78 #define MBEDTLS_CTR_DRBG_PR_ON 1
80 #ifdef __cplusplus
81 extern "C" {
82 #endif
83 
87 typedef struct
88 {
89  unsigned char counter[16];
93  size_t entropy_len;
99  /*
100  * Callbacks (Entropy)
101  */
102  int (*f_entropy)(void *, unsigned char *, size_t);
103 
104  void *p_entropy;
106 #if defined(MBEDTLS_THREADING_C)
107  mbedtls_threading_mutex_t mutex;
108 #endif
109 }
111 
120 
140  int (*f_entropy)(void *, unsigned char *, size_t),
141  void *p_entropy,
142  const unsigned char *custom,
143  size_t len );
144 
151 
162  int resistance );
163 
172  size_t len );
173 
182  int interval );
183 
195  const unsigned char *additional, size_t len );
196 
209  const unsigned char *additional, size_t add_len );
210 
226 int mbedtls_ctr_drbg_random_with_add( void *p_rng,
227  unsigned char *output, size_t output_len,
228  const unsigned char *additional, size_t add_len );
229 
243 int mbedtls_ctr_drbg_random( void *p_rng,
244  unsigned char *output, size_t output_len );
245 
246 #if defined(MBEDTLS_FS_IO)
247 
258 
272 #endif /* MBEDTLS_FS_IO */
273 
279 int mbedtls_ctr_drbg_self_test( int verbose );
280 
281 /* Internal functions (do not call directly) */
283  int (*)(void *, unsigned char *, size_t), void *,
284  const unsigned char *, size_t, size_t );
285 
286 #ifdef __cplusplus
287 }
288 #endif
289 
290 #endif /* ctr_drbg.h */
CTR_DRBG context structure.
Definition: ctr_drbg.h:87
int mbedtls_ctr_drbg_update_seed_file(mbedtls_ctr_drbg_context *ctx, const char *path)
Read and update a seed file. Seed is added to this instance.
Definition: ctr_drbg.c:442
void mbedtls_ctr_drbg_set_reseed_interval(mbedtls_ctr_drbg_context *ctx, int interval)
Set the reseed interval (Default: MBEDTLS_CTR_DRBG_RESEED_INTERVAL)
Definition: ctr_drbg.c:134
Threading abstraction layer.
void mbedtls_ctr_drbg_free(mbedtls_ctr_drbg_context *ctx)
Clear CTR_CRBG context data.
Definition: ctr_drbg.c:112
void * p_entropy
Definition: ctr_drbg.h:104
int mbedtls_ctr_drbg_write_seed_file(mbedtls_ctr_drbg_context *ctx, const char *path)
Write a seed file.
Definition: ctr_drbg.c:417
GLsizei const GLchar ** path
Definition: glext.h:7901
AES block cipher.
static const size_t add_len[NB_TESTS]
Definition: ccm.c:382
void mbedtls_ctr_drbg_set_prediction_resistance(mbedtls_ctr_drbg_context *ctx, int resistance)
Enable / disable prediction resistance (Default: Off)
Definition: ctr_drbg.c:124
GLenum GLsizei len
Definition: glext.h:7389
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.
Definition: ctr_drbg.c:330
size_t entropy_len
Definition: ctr_drbg.h:93
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)
Definition: ctr_drbg.c:129
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)
Definition: ctr_drbg.c:284
static sys_sem mutex
Definition: memp.c:120
int reseed_counter
Definition: ctr_drbg.h:90
GLuint counter
Definition: glext.h:12023
AVFormatContext * ctx
Definition: record_ffmpeg.c:247
int mbedtls_ctr_drbg_self_test(int verbose)
Checkup routine.
Definition: ctr_drbg.c:537
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)
Definition: ctr_drbg.c:70
int prediction_resistance
Definition: ctr_drbg.h:91
int reseed_interval
Definition: ctr_drbg.h:95
std::string output
Definition: Config.FromFile.cpp:44
AES context structure.
Definition: aes.h:62
void mbedtls_ctr_drbg_update(mbedtls_ctr_drbg_context *ctx, const unsigned char *additional, size_t add_len)
CTR_DRBG update state.
Definition: ctr_drbg.c:267
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...
Definition: ctr_drbg.c:57
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.
Definition: ctr_drbg.c:102
mbedtls_aes_context aes_ctx
Definition: ctr_drbg.h:97
int mbedtls_ctr_drbg_random(void *p_rng, unsigned char *output, size_t output_len)
CTR_DRBG generate random.
Definition: ctr_drbg.c:396
static const unsigned char additional[MAX_TESTS][64]
Definition: gcm.c:559