00001
00027 #ifndef POLARSSL_CTR_DRBG_H
00028 #define POLARSSL_CTR_DRBG_H
00029
00030 #include <string.h>
00031
00032 #include "aes.h"
00033
00034 #define POLARSSL_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED -0x0034
00035 #define POLARSSL_ERR_CTR_DRBG_REQUEST_TOO_BIG -0x0036
00036 #define POLARSSL_ERR_CTR_DRBG_INPUT_TOO_BIG -0x0038
00037 #define POLARSSL_ERR_CTR_DRBG_FILE_IO_ERROR -0x003A
00039 #define CTR_DRBG_BLOCKSIZE 16
00040 #define CTR_DRBG_KEYSIZE 32
00041 #define CTR_DRBG_KEYBITS ( CTR_DRBG_KEYSIZE * 8 )
00042 #define CTR_DRBG_SEEDLEN ( CTR_DRBG_KEYSIZE + CTR_DRBG_BLOCKSIZE )
00043
00045 #if !defined(POLARSSL_CONFIG_OPTIONS)
00046 #if defined(POLARSSL_SHA512_C)
00047 #define CTR_DRBG_ENTROPY_LEN 48
00048 #else
00049 #define CTR_DRBG_ENTROPY_LEN 32
00050 #endif
00051 #define CTR_DRBG_RESEED_INTERVAL 10000
00052 #define CTR_DRBG_MAX_INPUT 256
00053 #define CTR_DRBG_MAX_REQUEST 1024
00054 #define CTR_DRBG_MAX_SEED_INPUT 384
00055 #endif
00056
00057 #define CTR_DRBG_PR_OFF 0
00058 #define CTR_DRBG_PR_ON 1
00060 #ifdef __cplusplus
00061 extern "C" {
00062 #endif
00063
00067 typedef struct
00068 {
00069 unsigned char counter[16];
00070 int reseed_counter;
00071 int prediction_resistance;
00073 size_t entropy_len;
00074 int reseed_interval;
00076 aes_context aes_ctx;
00078
00079
00080
00081 int (*f_entropy)(void *, unsigned char *, size_t);
00082
00083 void *p_entropy;
00084 }
00085 ctr_drbg_context;
00086
00104 int ctr_drbg_init( ctr_drbg_context *ctx,
00105 int (*f_entropy)(void *, unsigned char *, size_t),
00106 void *p_entropy,
00107 const unsigned char *custom,
00108 size_t len );
00109
00119 void ctr_drbg_set_prediction_resistance( ctr_drbg_context *ctx,
00120 int resistance );
00121
00129 void ctr_drbg_set_entropy_len( ctr_drbg_context *ctx,
00130 size_t len );
00131
00139 void ctr_drbg_set_reseed_interval( ctr_drbg_context *ctx,
00140 int interval );
00141
00152 int ctr_drbg_reseed( ctr_drbg_context *ctx,
00153 const unsigned char *additional, size_t len );
00154
00162 void ctr_drbg_update( ctr_drbg_context *ctx,
00163 const unsigned char *additional, size_t add_len );
00164
00180 int ctr_drbg_random_with_add( void *p_rng,
00181 unsigned char *output, size_t output_len,
00182 const unsigned char *additional, size_t add_len );
00183
00197 int ctr_drbg_random( void *p_rng,
00198 unsigned char *output, size_t output_len );
00199
00200 #if defined(POLARSSL_FS_IO)
00201
00210 int ctr_drbg_write_seed_file( ctr_drbg_context *ctx, const char *path );
00211
00223 int ctr_drbg_update_seed_file( ctr_drbg_context *ctx, const char *path );
00224 #endif
00225
00231 int ctr_drbg_self_test( int verbose );
00232
00233
00234 int ctr_drbg_init_entropy_len( ctr_drbg_context *, int (*)(void *, unsigned char *, size_t), void *, const unsigned char *, size_t, size_t );
00235
00236 #ifdef __cplusplus
00237 }
00238 #endif
00239
00240 #endif