PolarSSL v1.1.4
md.h
Go to the documentation of this file.
00001 
00029 #ifndef POLARSSL_MD_H
00030 #define POLARSSL_MD_H
00031 
00032 #include <string.h>
00033 
00034 #if defined(_MSC_VER) && !defined(inline)
00035 #define inline _inline
00036 #else
00037 #if defined(__ARMCC_VERSION) && !defined(inline)
00038 #define inline __inline
00039 #endif /* __ARMCC_VERSION */
00040 #endif /*_MSC_VER */
00041 
00042 #define POLARSSL_ERR_MD_FEATURE_UNAVAILABLE                -0x5080  
00043 #define POLARSSL_ERR_MD_BAD_INPUT_DATA                     -0x5100  
00044 #define POLARSSL_ERR_MD_ALLOC_FAILED                       -0x5180  
00045 #define POLARSSL_ERR_MD_FILE_IO_ERROR                      -0x5200  
00047 typedef enum {
00048     POLARSSL_MD_NONE=0,
00049     POLARSSL_MD_MD2,
00050     POLARSSL_MD_MD4,
00051     POLARSSL_MD_MD5,
00052     POLARSSL_MD_SHA1,
00053     POLARSSL_MD_SHA224,
00054     POLARSSL_MD_SHA256,
00055     POLARSSL_MD_SHA384,
00056     POLARSSL_MD_SHA512,
00057 } md_type_t;
00058 
00059 #define POLARSSL_MD_MAX_SIZE         64  /* longest known is SHA512 */
00060 
00065 typedef struct {
00067     md_type_t type;
00068 
00070     const char * name;
00071 
00073     int size;
00074 
00076     void (*starts_func)( void *ctx );
00077 
00079     void (*update_func)( void *ctx, const unsigned char *input, size_t ilen );
00080 
00082     void (*finish_func)( void *ctx, unsigned char *output );
00083 
00085     void (*digest_func)( const unsigned char *input, size_t ilen,
00086                             unsigned char *output );
00087 
00089     int (*file_func)( const char *path, unsigned char *output );
00090 
00092     void (*hmac_starts_func)( void *ctx, const unsigned char *key, size_t keylen );
00093 
00095     void (*hmac_update_func)( void *ctx, const unsigned char *input, size_t ilen );
00096 
00098     void (*hmac_finish_func)( void *ctx, unsigned char *output);
00099 
00101     void (*hmac_reset_func)( void *ctx );
00102 
00104     void (*hmac_func)( const unsigned char *key, size_t keylen,
00105                     const unsigned char *input, size_t ilen,
00106                     unsigned char *output );
00107 
00109     void * (*ctx_alloc_func)( void );
00110 
00112     void (*ctx_free_func)( void *ctx );
00113 
00114 } md_info_t;
00115 
00119 typedef struct {
00121     const md_info_t *md_info;
00122 
00124     void *md_ctx;
00125 } md_context_t;
00126 
00127 #define MD_CONTEXT_T_INIT { \
00128     NULL, /* md_info */ \
00129     NULL, /* md_ctx */ \
00130 }
00131 
00132 #ifdef __cplusplus
00133 extern "C" {
00134 #endif
00135 
00142 const int *md_list( void );
00143 
00153 const md_info_t *md_info_from_string( const char *md_name );
00154 
00164 const md_info_t *md_info_from_type( md_type_t md_type );
00165 
00179 int md_init_ctx( md_context_t *ctx, const md_info_t *md_info );
00180 
00190 int md_free_ctx( md_context_t *ctx );
00191 
00199 static inline unsigned char md_get_size( const md_info_t *md_info )
00200 {
00201     return md_info->size;
00202 }
00203 
00211 static inline md_type_t md_get_type( const md_info_t *md_info )
00212 {
00213     return md_info->type;
00214 }
00215 
00223 static inline const char *md_get_name( const md_info_t *md_info )
00224 {
00225     return md_info->name;
00226 }
00227 
00236 int md_starts( md_context_t *ctx );
00237 
00248 int md_update( md_context_t *ctx, const unsigned char *input, size_t ilen );
00249 
00259 int md_finish( md_context_t *ctx, unsigned char *output );
00260 
00272 int md( const md_info_t *md_info, const unsigned char *input, size_t ilen,
00273         unsigned char *output );
00274 
00286 int md_file( const md_info_t *md_info, const char *path, unsigned char *output );
00287 
00298 int md_hmac_starts( md_context_t *ctx, const unsigned char *key, size_t keylen );
00299 
00310 int md_hmac_update( md_context_t *ctx, const unsigned char *input, size_t ilen );
00311 
00321 int md_hmac_finish( md_context_t *ctx, unsigned char *output);
00322 
00331 int md_hmac_reset( md_context_t *ctx );
00332 
00346 int md_hmac( const md_info_t *md_info, const unsigned char *key, size_t keylen,
00347                 const unsigned char *input, size_t ilen,
00348                 unsigned char *output );
00349 
00350 #ifdef __cplusplus
00351 }
00352 #endif
00353 
00354 #endif /* POLARSSL_MD_H */