PolarSSL v1.1.4
|
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 00044 #define CTR_DRBG_ENTROPY_LEN 48 00045 #define CTR_DRBG_RESEED_INTERVAL 10000 00046 #define CTR_DRBG_MAX_INPUT 256 00047 #define CTR_DRBG_MAX_REQUEST 1024 00048 #define CTR_DRBG_MAX_SEED_INPUT 384 00050 #define CTR_DRBG_PR_OFF 0 00051 #define CTR_DRBG_PR_ON 1 00053 #ifdef __cplusplus 00054 extern "C" { 00055 #endif 00056 00060 typedef struct 00061 { 00062 unsigned char counter[16]; 00063 int reseed_counter; 00064 int prediction_resistance; 00066 size_t entropy_len; 00067 int reseed_interval; 00069 aes_context aes_ctx; 00071 /* 00072 * Callbacks (Entropy) 00073 */ 00074 int (*f_entropy)(void *, unsigned char *, size_t); 00075 00076 void *p_entropy; 00077 } 00078 ctr_drbg_context; 00079 00097 int ctr_drbg_init( ctr_drbg_context *ctx, 00098 int (*f_entropy)(void *, unsigned char *, size_t), 00099 void *p_entropy, 00100 const unsigned char *custom, 00101 size_t len ); 00102 00112 void ctr_drbg_set_prediction_resistance( ctr_drbg_context *ctx, 00113 int resistance ); 00114 00122 void ctr_drbg_set_entropy_len( ctr_drbg_context *ctx, 00123 size_t len ); 00124 00132 void ctr_drbg_set_reseed_interval( ctr_drbg_context *ctx, 00133 int interval ); 00134 00145 int ctr_drbg_reseed( ctr_drbg_context *ctx, 00146 const unsigned char *additional, size_t len ); 00147 00155 void ctr_drbg_update( ctr_drbg_context *ctx, 00156 const unsigned char *additional, size_t add_len ); 00157 00173 int ctr_drbg_random_with_add( void *p_rng, 00174 unsigned char *output, size_t output_len, 00175 const unsigned char *additional, size_t add_len ); 00176 00190 int ctr_drbg_random( void *p_rng, 00191 unsigned char *output, size_t output_len ); 00192 00193 #if defined(POLARSSL_FS_IO) 00194 00202 int ctr_drbg_write_seed_file( ctr_drbg_context *ctx, const char *path ); 00203 00214 int ctr_drbg_update_seed_file( ctr_drbg_context *ctx, const char *path ); 00215 #endif 00216 00222 int ctr_drbg_self_test( int verbose ); 00223 00224 #ifdef __cplusplus 00225 } 00226 #endif 00227 00228 #endif /* ctr_drbg.h */