PolarSSL v1.3.1
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 {
61 } md_type_t;
62 
63 #if defined(POLARSSL_SHA512_C)
64 #define POLARSSL_MD_MAX_SIZE 64 /* longest known is SHA512 */
65 #else
66 #define POLARSSL_MD_MAX_SIZE 32 /* longest known is SHA256 or less */
67 #endif
68 
73 typedef struct {
76 
78  const char * name;
79 
81  int size;
82 
84  void (*starts_func)( void *ctx );
85 
87  void (*update_func)( void *ctx, const unsigned char *input, size_t ilen );
88 
90  void (*finish_func)( void *ctx, unsigned char *output );
91 
93  void (*digest_func)( const unsigned char *input, size_t ilen,
94  unsigned char *output );
95 
97  int (*file_func)( const char *path, unsigned char *output );
98 
100  void (*hmac_starts_func)( void *ctx, const unsigned char *key, size_t keylen );
101 
103  void (*hmac_update_func)( void *ctx, const unsigned char *input, size_t ilen );
104 
106  void (*hmac_finish_func)( void *ctx, unsigned char *output);
107 
109  void (*hmac_reset_func)( void *ctx );
110 
112  void (*hmac_func)( const unsigned char *key, size_t keylen,
113  const unsigned char *input, size_t ilen,
114  unsigned char *output );
115 
117  void * (*ctx_alloc_func)( void );
118 
120  void (*ctx_free_func)( void *ctx );
121 
123  void (*process_func)( void *ctx, const unsigned char *input );
124 } md_info_t;
125 
129 typedef struct {
132 
134  void *md_ctx;
135 } md_context_t;
136 
137 #define MD_CONTEXT_T_INIT { \
138  NULL, /* md_info */ \
139  NULL, /* md_ctx */ \
140 }
141 
148 const int *md_list( void );
149 
159 const md_info_t *md_info_from_string( const char *md_name );
160 
170 const md_info_t *md_info_from_type( md_type_t md_type );
171 
185 int md_init_ctx( md_context_t *ctx, const md_info_t *md_info );
186 
196 int md_free_ctx( md_context_t *ctx );
197 
205 static inline unsigned char md_get_size( const md_info_t *md_info )
206 {
207  if( md_info == NULL )
208  return( 0 );
209 
210  return md_info->size;
211 }
212 
220 static inline md_type_t md_get_type( const md_info_t *md_info )
221 {
222  if( md_info == NULL )
223  return( POLARSSL_MD_NONE );
224 
225  return md_info->type;
226 }
227 
235 static inline const char *md_get_name( const md_info_t *md_info )
236 {
237  if( md_info == NULL )
238  return( NULL );
239 
240  return md_info->name;
241 }
242 
251 int md_starts( md_context_t *ctx );
252 
263 int md_update( md_context_t *ctx, const unsigned char *input, size_t ilen );
264 
274 int md_finish( md_context_t *ctx, unsigned char *output );
275 
287 int md( const md_info_t *md_info, const unsigned char *input, size_t ilen,
288  unsigned char *output );
289 
301 int md_file( const md_info_t *md_info, const char *path, unsigned char *output );
302 
313 int md_hmac_starts( md_context_t *ctx, const unsigned char *key, size_t keylen );
314 
325 int md_hmac_update( md_context_t *ctx, const unsigned char *input, size_t ilen );
326 
336 int md_hmac_finish( md_context_t *ctx, unsigned char *output);
337 
346 int md_hmac_reset( md_context_t *ctx );
347 
361 int md_hmac( const md_info_t *md_info, const unsigned char *key, size_t keylen,
362  const unsigned char *input, size_t ilen,
363  unsigned char *output );
364 
365 /* Internal use */
366 int md_process( md_context_t *ctx, const unsigned char *data );
367 
368 #ifdef __cplusplus
369 }
370 #endif
371 
372 #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:205
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:220
const md_info_t * md_info
Information about the associated message digest.
Definition: md.h:131
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:134
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:78
int size
Output length of the digest function.
Definition: md.h:81
static const char * md_get_name(const md_info_t *md_info)
Returns the name of the message digest output.
Definition: md.h:235
md_type_t type
Digest identifier.
Definition: md.h:75
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:73
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:129