PolarSSL v1.3.9
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
48extern "C" {
49#endif
50
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
74typedef 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,
102 size_t keylen );
103
105 void (*hmac_update_func)( void *ctx, const unsigned char *input,
106 size_t ilen );
107
109 void (*hmac_finish_func)( void *ctx, unsigned char *output);
110
112 void (*hmac_reset_func)( void *ctx );
113
115 void (*hmac_func)( const unsigned char *key, size_t keylen,
116 const unsigned char *input, size_t ilen,
117 unsigned char *output );
118
120 void * (*ctx_alloc_func)( void );
121
123 void (*ctx_free_func)( void *ctx );
124
126 void (*process_func)( void *ctx, const unsigned char *input );
127} md_info_t;
128
132typedef struct {
135
137 void *md_ctx;
139
140#define MD_CONTEXT_T_INIT { \
141 NULL, /* md_info */ \
142 NULL, /* md_ctx */ \
143}
144
151const int *md_list( void );
152
162const md_info_t *md_info_from_string( const char *md_name );
163
174
179
186
204int md_init_ctx( md_context_t *ctx, const md_info_t *md_info );
205
217
225static inline unsigned char md_get_size( const md_info_t *md_info )
226{
227 if( md_info == NULL )
228 return( 0 );
229
230 return md_info->size;
231}
232
240static inline md_type_t md_get_type( const md_info_t *md_info )
241{
242 if( md_info == NULL )
243 return( POLARSSL_MD_NONE );
244
245 return md_info->type;
246}
247
255static inline const char *md_get_name( const md_info_t *md_info )
256{
257 if( md_info == NULL )
258 return( NULL );
259
260 return md_info->name;
261}
262
272
283int md_update( md_context_t *ctx, const unsigned char *input, size_t ilen );
284
294int md_finish( md_context_t *ctx, unsigned char *output );
295
307int md( const md_info_t *md_info, const unsigned char *input, size_t ilen,
308 unsigned char *output );
309
321int md_file( const md_info_t *md_info, const char *path,
322 unsigned char *output );
323
334int md_hmac_starts( md_context_t *ctx, const unsigned char *key,
335 size_t keylen );
336
347int md_hmac_update( md_context_t *ctx, const unsigned char *input,
348 size_t ilen );
349
359int md_hmac_finish( md_context_t *ctx, unsigned char *output);
360
370
384int md_hmac( const md_info_t *md_info, const unsigned char *key, size_t keylen,
385 const unsigned char *input, size_t ilen,
386 unsigned char *output );
387
388/* Internal use */
389int md_process( md_context_t *ctx, const unsigned char *data );
390
391#ifdef __cplusplus
392}
393#endif
394
395#endif /* POLARSSL_MD_H */
const md_info_t * md_info_from_string(const char *md_name)
Returns the message digest information associated with the given digest name.
int md_hmac_reset(md_context_t *ctx)
Generic HMAC context reset.
int md_free_ctx(md_context_t *ctx)
Free the message-specific context of ctx.
static unsigned char md_get_size(const md_info_t *md_info)
Returns the size of the message digest output.
Definition md.h:225
int md_starts(md_context_t *ctx)
Set-up the given context for a new message digest.
const md_info_t * md_info_from_type(md_type_t md_type)
Returns the message digest information associated with the given digest type.
int md_hmac_update(md_context_t *ctx, const unsigned char *input, size_t ilen)
Generic HMAC process buffer.
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_hmac_starts(md_context_t *ctx, const unsigned char *key, size_t keylen)
Generic HMAC context setup.
const int * md_list(void)
Returns the list of digests supported by the generic digest module.
static md_type_t md_get_type(const md_info_t *md_info)
Returns the type of the message digest output.
Definition md.h:240
int md_file(const md_info_t *md_info, const char *path, unsigned char *output)
Output = message_digest( file contents )
int md(const md_info_t *md_info, const unsigned char *input, size_t ilen, unsigned char *output)
Output = message_digest( input buffer )
void md_free(md_context_t *ctx)
Free and clear the message-specific context of ctx.
int md_process(md_context_t *ctx, const unsigned char *data)
int md_finish(md_context_t *ctx, unsigned char *output)
Generic message digest final digest.
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 )
static const char * md_get_name(const md_info_t *md_info)
Returns the name of the message digest output.
Definition md.h:255
int md_hmac_finish(md_context_t *ctx, unsigned char *output)
Generic HMAC final digest.
void md_init(md_context_t *ctx)
Initialize a md_context (as NONE)
int md_update(md_context_t *ctx, const unsigned char *input, size_t ilen)
Generic message digest process buffer.
md_type_t
Definition md.h:51
@ POLARSSL_MD_MD5
Definition md.h:55
@ POLARSSL_MD_NONE
Definition md.h:52
@ POLARSSL_MD_SHA224
Definition md.h:57
@ POLARSSL_MD_SHA1
Definition md.h:56
@ POLARSSL_MD_SHA384
Definition md.h:59
@ POLARSSL_MD_MD2
Definition md.h:53
@ POLARSSL_MD_MD4
Definition md.h:54
@ POLARSSL_MD_RIPEMD160
Definition md.h:61
@ POLARSSL_MD_SHA512
Definition md.h:60
@ POLARSSL_MD_SHA256
Definition md.h:58
Generic message digest context.
Definition md.h:132
const md_info_t * md_info
Information about the associated message digest.
Definition md.h:134
void * md_ctx
Digest-specific context.
Definition md.h:137
Message digest information.
Definition md.h:74
md_type_t type
Digest identifier.
Definition md.h:76
const char * name
Name of the message digest.
Definition md.h:79
int size
Output length of the digest function.
Definition md.h:82