ctr_drbg.h

Go to the documentation of this file.
00001 
00023 #ifndef MBEDTLS_CTR_DRBG_H
00024 #define MBEDTLS_CTR_DRBG_H
00025 
00026 #include "aes.h"
00027 
00028 #if defined(MBEDTLS_THREADING_C)
00029 #include "mbedtls/threading.h"
00030 #endif
00031 
00032 #define MBEDTLS_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED        -0x0034  
00033 #define MBEDTLS_ERR_CTR_DRBG_REQUEST_TOO_BIG              -0x0036  
00034 #define MBEDTLS_ERR_CTR_DRBG_INPUT_TOO_BIG                -0x0038  
00035 #define MBEDTLS_ERR_CTR_DRBG_FILE_IO_ERROR                -0x003A  
00037 #define MBEDTLS_CTR_DRBG_BLOCKSIZE          16      
00038 #define MBEDTLS_CTR_DRBG_KEYSIZE            32      
00039 #define MBEDTLS_CTR_DRBG_KEYBITS            ( MBEDTLS_CTR_DRBG_KEYSIZE * 8 )
00040 #define MBEDTLS_CTR_DRBG_SEEDLEN            ( MBEDTLS_CTR_DRBG_KEYSIZE + MBEDTLS_CTR_DRBG_BLOCKSIZE )
00041 
00051 #if !defined(MBEDTLS_CTR_DRBG_ENTROPY_LEN)
00052 #if defined(MBEDTLS_SHA512_C) && !defined(MBEDTLS_ENTROPY_FORCE_SHA256)
00053 #define MBEDTLS_CTR_DRBG_ENTROPY_LEN        48      
00054 #else
00055 #define MBEDTLS_CTR_DRBG_ENTROPY_LEN        32      
00056 #endif
00057 #endif
00058 
00059 #if !defined(MBEDTLS_CTR_DRBG_RESEED_INTERVAL)
00060 #define MBEDTLS_CTR_DRBG_RESEED_INTERVAL    10000   
00061 #endif
00062 
00063 #if !defined(MBEDTLS_CTR_DRBG_MAX_INPUT)
00064 #define MBEDTLS_CTR_DRBG_MAX_INPUT          256     
00065 #endif
00066 
00067 #if !defined(MBEDTLS_CTR_DRBG_MAX_REQUEST)
00068 #define MBEDTLS_CTR_DRBG_MAX_REQUEST        1024    
00069 #endif
00070 
00071 #if !defined(MBEDTLS_CTR_DRBG_MAX_SEED_INPUT)
00072 #define MBEDTLS_CTR_DRBG_MAX_SEED_INPUT     384     
00073 #endif
00074 
00075 /* \} name SECTION: Module settings */
00076 
00077 #define MBEDTLS_CTR_DRBG_PR_OFF             0       
00078 #define MBEDTLS_CTR_DRBG_PR_ON              1       
00080 #ifdef __cplusplus
00081 extern "C" {
00082 #endif
00083 
00087 typedef struct
00088 {
00089     unsigned char counter[16];  
00090     int reseed_counter;         
00091     int prediction_resistance;  
00093     size_t entropy_len;         
00095     int reseed_interval;        
00097     mbedtls_aes_context aes_ctx;        
00099     /*
00100      * Callbacks (Entropy)
00101      */
00102     int (*f_entropy)(void *, unsigned char *, size_t);
00103 
00104     void *p_entropy;            
00106 #if defined(MBEDTLS_THREADING_C)
00107     mbedtls_threading_mutex_t mutex;
00108 #endif
00109 }
00110 mbedtls_ctr_drbg_context;
00111 
00119 void mbedtls_ctr_drbg_init( mbedtls_ctr_drbg_context *ctx );
00120 
00139 int mbedtls_ctr_drbg_seed( mbedtls_ctr_drbg_context *ctx,
00140                    int (*f_entropy)(void *, unsigned char *, size_t),
00141                    void *p_entropy,
00142                    const unsigned char *custom,
00143                    size_t len );
00144 
00150 void mbedtls_ctr_drbg_free( mbedtls_ctr_drbg_context *ctx );
00151 
00161 void mbedtls_ctr_drbg_set_prediction_resistance( mbedtls_ctr_drbg_context *ctx,
00162                                          int resistance );
00163 
00171 void mbedtls_ctr_drbg_set_entropy_len( mbedtls_ctr_drbg_context *ctx,
00172                                size_t len );
00173 
00181 void mbedtls_ctr_drbg_set_reseed_interval( mbedtls_ctr_drbg_context *ctx,
00182                                    int interval );
00183 
00194 int mbedtls_ctr_drbg_reseed( mbedtls_ctr_drbg_context *ctx,
00195                      const unsigned char *additional, size_t len );
00196 
00208 void mbedtls_ctr_drbg_update( mbedtls_ctr_drbg_context *ctx,
00209                       const unsigned char *additional, size_t add_len );
00210 
00226 int mbedtls_ctr_drbg_random_with_add( void *p_rng,
00227                               unsigned char *output, size_t output_len,
00228                               const unsigned char *additional, size_t add_len );
00229 
00243 int mbedtls_ctr_drbg_random( void *p_rng,
00244                      unsigned char *output, size_t output_len );
00245 
00246 #if defined(MBEDTLS_FS_IO)
00247 
00257 int mbedtls_ctr_drbg_write_seed_file( mbedtls_ctr_drbg_context *ctx, const char *path );
00258 
00271 int mbedtls_ctr_drbg_update_seed_file( mbedtls_ctr_drbg_context *ctx, const char *path );
00272 #endif /* MBEDTLS_FS_IO */
00273 
00279 int mbedtls_ctr_drbg_self_test( int verbose );
00280 
00281 /* Internal functions (do not call directly) */
00282 int mbedtls_ctr_drbg_seed_entropy_len( mbedtls_ctr_drbg_context *,
00283                                int (*)(void *, unsigned char *, size_t), void *,
00284                                const unsigned char *, size_t, size_t );
00285 
00286 #ifdef __cplusplus
00287 }
00288 #endif
00289 
00290 #endif /* ctr_drbg.h */

Generated on 11 Mar 2017 for mbed TLS v2.4.2 by  doxygen 1.4.7