mbed TLS v1.3.11
md.h
Go to the documentation of this file.
1 
26 #ifndef POLARSSL_MD_H
27 #define POLARSSL_MD_H
28 
29 #include <stddef.h>
30 
31 #if defined(_MSC_VER) && !defined(inline)
32 #define inline _inline
33 #else
34 #if defined(__ARMCC_VERSION) && !defined(inline)
35 #define inline __inline
36 #endif /* __ARMCC_VERSION */
37 #endif /*_MSC_VER */
38 
39 #define POLARSSL_ERR_MD_FEATURE_UNAVAILABLE -0x5080
40 #define POLARSSL_ERR_MD_BAD_INPUT_DATA -0x5100
41 #define POLARSSL_ERR_MD_ALLOC_FAILED -0x5180
42 #define POLARSSL_ERR_MD_FILE_IO_ERROR -0x5200
44 #ifdef __cplusplus
45 extern "C" {
46 #endif
47 
48 typedef enum {
59 } md_type_t;
60 
61 #if defined(POLARSSL_SHA512_C)
62 #define POLARSSL_MD_MAX_SIZE 64 /* longest known is SHA512 */
63 #else
64 #define POLARSSL_MD_MAX_SIZE 32 /* longest known is SHA256 or less */
65 #endif
66 
71 typedef struct {
74 
76  const char * name;
77 
79  int size;
80 
82  void (*starts_func)( void *ctx );
83 
85  void (*update_func)( void *ctx, const unsigned char *input, size_t ilen );
86 
88  void (*finish_func)( void *ctx, unsigned char *output );
89 
91  void (*digest_func)( const unsigned char *input, size_t ilen,
92  unsigned char *output );
93 
95  int (*file_func)( const char *path, unsigned char *output );
96 
98  void (*hmac_starts_func)( void *ctx, const unsigned char *key,
99  size_t keylen );
100 
102  void (*hmac_update_func)( void *ctx, const unsigned char *input,
103  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 
175 void md_init( md_context_t *ctx );
176 
182 void md_free( md_context_t *ctx );
183 
201 int md_init_ctx( md_context_t *ctx, const md_info_t *md_info );
202 
203 #if ! defined(POLARSSL_DEPRECATED_REMOVED)
204 #if defined(POLARSSL_DEPRECATED_WARNING)
205 #define DEPRECATED __attribute__((deprecated))
206 #else
207 #define DEPRECATED
208 #endif
209 
220 #undef DEPRECATED
221 #endif /* POLARSSL_DEPRECATED_REMOVED */
222 
230 static inline unsigned char md_get_size( const md_info_t *md_info )
231 {
232  if( md_info == NULL )
233  return( 0 );
234 
235  return md_info->size;
236 }
237 
245 static inline md_type_t md_get_type( const md_info_t *md_info )
246 {
247  if( md_info == NULL )
248  return( POLARSSL_MD_NONE );
249 
250  return md_info->type;
251 }
252 
260 static inline const char *md_get_name( const md_info_t *md_info )
261 {
262  if( md_info == NULL )
263  return( NULL );
264 
265  return md_info->name;
266 }
267 
276 int md_starts( md_context_t *ctx );
277 
288 int md_update( md_context_t *ctx, const unsigned char *input, size_t ilen );
289 
299 int md_finish( md_context_t *ctx, unsigned char *output );
300 
312 int md( const md_info_t *md_info, const unsigned char *input, size_t ilen,
313  unsigned char *output );
314 
326 int md_file( const md_info_t *md_info, const char *path,
327  unsigned char *output );
328 
339 int md_hmac_starts( md_context_t *ctx, const unsigned char *key,
340  size_t keylen );
341 
352 int md_hmac_update( md_context_t *ctx, const unsigned char *input,
353  size_t ilen );
354 
364 int md_hmac_finish( md_context_t *ctx, unsigned char *output);
365 
374 int md_hmac_reset( md_context_t *ctx );
375 
389 int md_hmac( const md_info_t *md_info, const unsigned char *key, size_t keylen,
390  const unsigned char *input, size_t ilen,
391  unsigned char *output );
392 
393 /* Internal use */
394 int md_process( md_context_t *ctx, const unsigned char *data );
395 
396 #ifdef __cplusplus
397 }
398 #endif
399 
400 #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.
void md_init(md_context_t *ctx)
Initialize a md_context (as NONE)
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:230
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:245
const md_info_t * md_info
Information about the associated message digest.
Definition: md.h:131
md_type_t
Definition: md.h:48
const md_info_t * md_info_from_type(md_type_t md_type)
Returns the message digest information associated with the given digest type.
void md_free(md_context_t *ctx)
Free and clear the message-specific context of ctx.
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_free_ctx(md_context_t *ctx) DEPRECATED
Free the message-specific context of ctx.
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:76
int size
Output length of the digest function.
Definition: md.h:79
static const char * md_get_name(const md_info_t *md_info)
Returns the name of the message digest output.
Definition: md.h:260
md_type_t type
Digest identifier.
Definition: md.h:73
int md_finish(md_context_t *ctx, unsigned char *output)
Generic message digest final digest.
Message digest information.
Definition: md.h:71
int md_update(md_context_t *ctx, const unsigned char *input, size_t ilen)
Generic message digest process buffer.
#define DEPRECATED
Definition: md.h:207
int md_hmac_finish(md_context_t *ctx, unsigned char *output)
Generic HMAC final digest.
Generic message digest context.
Definition: md.h:129