mbed TLS v2.0.0
md.h
Go to the documentation of this file.
1 
26 #ifndef MBEDTLS_MD_H
27 #define MBEDTLS_MD_H
28 
29 #include <stddef.h>
30 
31 #if ( defined(__ARMCC_VERSION) || defined(_MSC_VER) ) && !defined(inline)
32 #define inline __inline
33 #endif
34 
35 #define MBEDTLS_ERR_MD_FEATURE_UNAVAILABLE -0x5080
36 #define MBEDTLS_ERR_MD_BAD_INPUT_DATA -0x5100
37 #define MBEDTLS_ERR_MD_ALLOC_FAILED -0x5180
38 #define MBEDTLS_ERR_MD_FILE_IO_ERROR -0x5200
40 #ifdef __cplusplus
41 extern "C" {
42 #endif
43 
44 typedef enum {
56 
57 #if defined(MBEDTLS_SHA512_C)
58 #define MBEDTLS_MD_MAX_SIZE 64 /* longest known is SHA512 */
59 #else
60 #define MBEDTLS_MD_MAX_SIZE 32 /* longest known is SHA256 or less */
61 #endif
62 
67 
71 typedef struct {
74 
76  void *md_ctx;
77 
79  void *hmac_ctx;
81 
88 const int *mbedtls_md_list( void );
89 
99 const mbedtls_md_info_t *mbedtls_md_info_from_string( const char *md_name );
100 
111 
118 
125 
126 #if ! defined(MBEDTLS_DEPRECATED_REMOVED)
127 #if defined(MBEDTLS_DEPRECATED_WARNING)
128 #define MBEDTLS_DEPRECATED __attribute__((deprecated))
129 #else
130 #define MBEDTLS_DEPRECATED
131 #endif
132 
147 #undef MBEDTLS_DEPRECATED
148 #endif /* MBEDTLS_DEPRECATED_REMOVED */
149 
164 int mbedtls_md_setup( mbedtls_md_context_t *ctx, const mbedtls_md_info_t *md_info, int hmac );
165 
181  const mbedtls_md_context_t *src );
182 
190 unsigned char mbedtls_md_get_size( const mbedtls_md_info_t *md_info );
191 
200 
208 const char *mbedtls_md_get_name( const mbedtls_md_info_t *md_info );
209 
221 
234 int mbedtls_md_update( mbedtls_md_context_t *ctx, const unsigned char *input, size_t ilen );
235 
247 int mbedtls_md_finish( mbedtls_md_context_t *ctx, unsigned char *output );
248 
260 int mbedtls_md( const mbedtls_md_info_t *md_info, const unsigned char *input, size_t ilen,
261  unsigned char *output );
262 
263 #if defined(MBEDTLS_FS_IO)
264 
275 int mbedtls_md_file( const mbedtls_md_info_t *md_info, const char *path,
276  unsigned char *output );
277 #endif /* MBEDTLS_FS_IO */
278 
290 int mbedtls_md_hmac_starts( mbedtls_md_context_t *ctx, const unsigned char *key,
291  size_t keylen );
292 
306 int mbedtls_md_hmac_update( mbedtls_md_context_t *ctx, const unsigned char *input,
307  size_t ilen );
308 
321 int mbedtls_md_hmac_finish( mbedtls_md_context_t *ctx, unsigned char *output);
322 
333 
347 int mbedtls_md_hmac( const mbedtls_md_info_t *md_info, const unsigned char *key, size_t keylen,
348  const unsigned char *input, size_t ilen,
349  unsigned char *output );
350 
351 /* Internal use */
352 int mbedtls_md_process( mbedtls_md_context_t *ctx, const unsigned char *data );
353 
354 #ifdef __cplusplus
355 }
356 #endif
357 
358 #endif /* MBEDTLS_MD_H */
int mbedtls_md_init_ctx(mbedtls_md_context_t *ctx, const mbedtls_md_info_t *md_info) MBEDTLS_DEPRECATED
Select MD to use and allocate internal structures.
int mbedtls_md_hmac_reset(mbedtls_md_context_t *ctx)
Prepare to authenticate a new message with the same key.
mbedtls_md_type_t mbedtls_md_get_type(const mbedtls_md_info_t *md_info)
Returns the type of the message digest output.
int mbedtls_md_starts(mbedtls_md_context_t *ctx)
Prepare the context to digest a new message.
void * hmac_ctx
HMAC part of the context.
Definition: md.h:79
int mbedtls_md_hmac_update(mbedtls_md_context_t *ctx, const unsigned char *input, size_t ilen)
Generic HMAC process buffer.
void mbedtls_md_free(mbedtls_md_context_t *ctx)
Free and clear the internal structures of ctx.
void mbedtls_md_init(mbedtls_md_context_t *ctx)
Initialize a md_context (as NONE) This should always be called first.
int mbedtls_md_clone(mbedtls_md_context_t *dst, const mbedtls_md_context_t *src)
Clone the state of an MD context.
void * md_ctx
Digest-specific context.
Definition: md.h:76
Generic message digest context.
Definition: md.h:71
int mbedtls_md_process(mbedtls_md_context_t *ctx, const unsigned char *data)
unsigned char mbedtls_md_get_size(const mbedtls_md_info_t *md_info)
Returns the size of the message digest output.
int mbedtls_md_hmac_finish(mbedtls_md_context_t *ctx, unsigned char *output)
Output HMAC.
int mbedtls_md_setup(mbedtls_md_context_t *ctx, const mbedtls_md_info_t *md_info, int hmac)
Select MD to use and allocate internal structures.
int mbedtls_md_hmac(const mbedtls_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 mbedtls_md(const mbedtls_md_info_t *md_info, const unsigned char *input, size_t ilen, unsigned char *output)
Output = message_digest( input buffer )
int mbedtls_md_finish(mbedtls_md_context_t *ctx, unsigned char *output)
Generic message digest final digest Called after mbedtls_md_update().
#define MBEDTLS_DEPRECATED
Definition: md.h:130
const char * mbedtls_md_get_name(const mbedtls_md_info_t *md_info)
Returns the name of the message digest output.
const int * mbedtls_md_list(void)
Returns the list of digests supported by the generic digest module.
const mbedtls_md_info_t * mbedtls_md_info_from_type(mbedtls_md_type_t md_type)
Returns the message digest information associated with the given digest type.
Message digest information.
Definition: md_internal.h:47
int mbedtls_md_hmac_starts(mbedtls_md_context_t *ctx, const unsigned char *key, size_t keylen)
Set HMAC key and prepare to authenticate a new message.
mbedtls_md_type_t
Definition: md.h:44
const mbedtls_md_info_t * mbedtls_md_info_from_string(const char *md_name)
Returns the message digest information associated with the given digest name.
const mbedtls_md_info_t * md_info
Information about the associated message digest.
Definition: md.h:73
int mbedtls_md_update(mbedtls_md_context_t *ctx, const unsigned char *input, size_t ilen)
Generic message digest process buffer Called between mbedtls_md_starts() and mbedtls_md_finish().