PolarSSL v1.3.4
md.h
Go to the documentation of this file.
1 
29 #ifndef POLARSSL_MD_H
30 #define POLARSSL_MD_H
31 
32 #include <string.h>
33 
34 #if defined(_MSC_VER) && !defined(inline)
35 #define inline _inline
36 #else
37 #if defined(__ARMCC_VERSION) && !defined(inline)
38 #define inline __inline
39 #endif /* __ARMCC_VERSION */
40 #endif /*_MSC_VER */
41 
42 #define POLARSSL_ERR_MD_FEATURE_UNAVAILABLE -0x5080
43 #define POLARSSL_ERR_MD_BAD_INPUT_DATA -0x5100
44 #define POLARSSL_ERR_MD_ALLOC_FAILED -0x5180
45 #define POLARSSL_ERR_MD_FILE_IO_ERROR -0x5200
47 #ifdef __cplusplus
48 extern "C" {
49 #endif
50 
51 typedef enum {
62 } md_type_t;
63 
64 #if defined(POLARSSL_SHA512_C)
65 #define POLARSSL_MD_MAX_SIZE 64 /* longest known is SHA512 */
66 #else
67 #define POLARSSL_MD_MAX_SIZE 32 /* longest known is SHA256 or less */
68 #endif
69 
74 typedef struct {
77 
79  const char * name;
80 
82  int size;
83 
85  void (*starts_func)( void *ctx );
86 
88  void (*update_func)( void *ctx, const unsigned char *input, size_t ilen );
89 
91  void (*finish_func)( void *ctx, unsigned char *output );
92 
94  void (*digest_func)( const unsigned char *input, size_t ilen,
95  unsigned char *output );
96 
98  int (*file_func)( const char *path, unsigned char *output );
99 
101  void (*hmac_starts_func)( void *ctx, const unsigned char *key, size_t keylen );
102 
104  void (*hmac_update_func)( void *ctx, const unsigned char *input, size_t ilen );
105 
107  void (*hmac_finish_func)( void *ctx, unsigned char *output);
108 
110  void (*hmac_reset_func)( void *ctx );
111 
113  void (*hmac_func)( const unsigned char *key, size_t keylen,
114  const unsigned char *input, size_t ilen,
115  unsigned char *output );
116 
118  void * (*ctx_alloc_func)( void );
119 
121  void (*ctx_free_func)( void *ctx );
122 
124  void (*process_func)( void *ctx, const unsigned char *input );
125 } md_info_t;
126 
130 typedef struct {
133 
135  void *md_ctx;
136 } md_context_t;
137 
138 #define MD_CONTEXT_T_INIT { \
139  NULL, /* md_info */ \
140  NULL, /* md_ctx */ \
141 }
142 
149 const int *md_list( void );
150 
160 const md_info_t *md_info_from_string( const char *md_name );
161 
171 const md_info_t *md_info_from_type( md_type_t md_type );
172 
186 int md_init_ctx( md_context_t *ctx, const md_info_t *md_info );
187 
197 int md_free_ctx( md_context_t *ctx );
198 
206 static inline unsigned char md_get_size( const md_info_t *md_info )
207 {
208  if( md_info == NULL )
209  return( 0 );
210 
211  return md_info->size;
212 }
213 
221 static inline md_type_t md_get_type( const md_info_t *md_info )
222 {
223  if( md_info == NULL )
224  return( POLARSSL_MD_NONE );
225 
226  return md_info->type;
227 }
228 
236 static inline const char *md_get_name( const md_info_t *md_info )
237 {
238  if( md_info == NULL )
239  return( NULL );
240 
241  return md_info->name;
242 }
243 
252 int md_starts( md_context_t *ctx );
253 
264 int md_update( md_context_t *ctx, const unsigned char *input, size_t ilen );
265 
275 int md_finish( md_context_t *ctx, unsigned char *output );
276 
288 int md( const md_info_t *md_info, const unsigned char *input, size_t ilen,
289  unsigned char *output );
290 
302 int md_file( const md_info_t *md_info, const char *path, unsigned char *output );
303 
314 int md_hmac_starts( md_context_t *ctx, const unsigned char *key, size_t keylen );
315 
326 int md_hmac_update( md_context_t *ctx, const unsigned char *input, size_t ilen );
327 
337 int md_hmac_finish( md_context_t *ctx, unsigned char *output);
338 
347 int md_hmac_reset( md_context_t *ctx );
348 
362 int md_hmac( const md_info_t *md_info, const unsigned char *key, size_t keylen,
363  const unsigned char *input, size_t ilen,
364  unsigned char *output );
365 
366 /* Internal use */
367 int md_process( md_context_t *ctx, const unsigned char *data );
368 
369 #ifdef __cplusplus
370 }
371 #endif
372 
373 #endif /* POLARSSL_MD_H */
int md(const md_info_t *md_info, const unsigned char *input, size_t ilen, unsigned char *output)
Output = message_digest( input buffer )
int md_starts(md_context_t *ctx)
Set-up the given context for a new message digest.
int md_file(const md_info_t *md_info, const char *path, unsigned char *output)
Output = message_digest( file contents )
int md_init_ctx(md_context_t *ctx, const md_info_t *md_info)
Initialises and fills the message digest context structure with the appropriate values.
int md_process(md_context_t *ctx, const unsigned char *data)
static unsigned char md_get_size(const md_info_t *md_info)
Returns the size of the message digest output.
Definition: md.h:206
const md_info_t * md_info_from_string(const char *md_name)
Returns the message digest information associated with the given digest name.
static md_type_t md_get_type(const md_info_t *md_info)
Returns the type of the message digest output.
Definition: md.h:221
const md_info_t * md_info
Information about the associated message digest.
Definition: md.h:132
md_type_t
Definition: md.h:51
const md_info_t * md_info_from_type(md_type_t md_type)
Returns the message digest information associated with the given digest type.
const int * md_list(void)
Returns the list of digests supported by the generic digest module.
int md_hmac_starts(md_context_t *ctx, const unsigned char *key, size_t keylen)
Generic HMAC context setup.
void * md_ctx
Digest-specific context.
Definition: md.h:135
int md_hmac(const md_info_t *md_info, const unsigned char *key, size_t keylen, const unsigned char *input, size_t ilen, unsigned char *output)
Output = Generic_HMAC( hmac key, input buffer )
int md_hmac_reset(md_context_t *ctx)
Generic HMAC context reset.
int md_hmac_update(md_context_t *ctx, const unsigned char *input, size_t ilen)
Generic HMAC process buffer.
const char * name
Name of the message digest.
Definition: md.h:79
int size
Output length of the digest function.
Definition: md.h:82
static const char * md_get_name(const md_info_t *md_info)
Returns the name of the message digest output.
Definition: md.h:236
md_type_t type
Digest identifier.
Definition: md.h:76
int md_finish(md_context_t *ctx, unsigned char *output)
Generic message digest final digest.
int md_free_ctx(md_context_t *ctx)
Free the message-specific context of ctx.
Message digest information.
Definition: md.h:74
int md_update(md_context_t *ctx, const unsigned char *input, size_t ilen)
Generic message digest process buffer.
int md_hmac_finish(md_context_t *ctx, unsigned char *output)
Generic HMAC final digest.
Generic message digest context.
Definition: md.h:130