Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
md.h File Reference
The generic message-digest wrapper. More...
Go to the source code of this file.
Data Structures | |
struct | mbedtls_md_context_t |
The generic message-digest context. More... | |
Typedefs | |
typedef struct mbedtls_md_info_t | mbedtls_md_info_t |
Opaque struct defined in md_internal.h. | |
Enumerations | |
enum | mbedtls_md_type_t |
Enumeration of supported message digests. More... | |
Functions | |
const int * | mbedtls_md_list (void) |
This function returns the list of digests supported by the generic digest module. | |
const mbedtls_md_info_t * | mbedtls_md_info_from_string (const char *md_name) |
This function returns the message-digest information associated with the given digest name. | |
const mbedtls_md_info_t * | mbedtls_md_info_from_type (mbedtls_md_type_t md_type) |
This function returns the message-digest information associated with the given digest type. | |
void | mbedtls_md_init (mbedtls_md_context_t *ctx) |
This function initializes a message-digest context without binding it to a particular message-digest algorithm. | |
void | mbedtls_md_free (mbedtls_md_context_t *ctx) |
This function clears the internal structure of ctx and frees any embedded internal structure, but does not free ctx itself. | |
int | mbedtls_md_init_ctx (mbedtls_md_context_t *ctx, const mbedtls_md_info_t *md_info) MBEDTLS_DEPRECATED |
This function selects the message digest algorithm to use, and allocates internal structures. | |
int | mbedtls_md_setup (mbedtls_md_context_t *ctx, const mbedtls_md_info_t *md_info, int hmac) |
This function selects the message digest algorithm to use, and allocates internal structures. | |
int | mbedtls_md_clone (mbedtls_md_context_t *dst, const mbedtls_md_context_t *src) |
This function clones the state of an message-digest context. | |
unsigned char | mbedtls_md_get_size (const mbedtls_md_info_t *md_info) |
This function extracts the message-digest size from the message-digest information structure. | |
mbedtls_md_type_t | mbedtls_md_get_type (const mbedtls_md_info_t *md_info) |
This function extracts the message-digest type from the message-digest information structure. | |
const char * | mbedtls_md_get_name (const mbedtls_md_info_t *md_info) |
This function extracts the message-digest name from the message-digest information structure. | |
int | mbedtls_md_starts (mbedtls_md_context_t *ctx) |
This function starts a message-digest computation. | |
int | mbedtls_md_update (mbedtls_md_context_t *ctx, const unsigned char *input, size_t ilen) |
This function feeds an input buffer into an ongoing message-digest computation. | |
int | mbedtls_md_finish (mbedtls_md_context_t *ctx, unsigned char *output) |
This function finishes the digest operation, and writes the result to the output buffer. | |
int | mbedtls_md (const mbedtls_md_info_t *md_info, const unsigned char *input, size_t ilen, unsigned char *output) |
This function calculates the message-digest of a buffer, with respect to a configurable message-digest algorithm in a single call. | |
int | mbedtls_md_file (const mbedtls_md_info_t *md_info, const char *path, unsigned char *output) |
This function calculates the message-digest checksum result of the contents of the provided file. | |
int | mbedtls_md_hmac_starts (mbedtls_md_context_t *ctx, const unsigned char *key, size_t keylen) |
This function sets the HMAC key and prepares to authenticate a new message. | |
int | mbedtls_md_hmac_update (mbedtls_md_context_t *ctx, const unsigned char *input, size_t ilen) |
This function feeds an input buffer into an ongoing HMAC computation. | |
int | mbedtls_md_hmac_finish (mbedtls_md_context_t *ctx, unsigned char *output) |
This function finishes the HMAC operation, and writes the result to the output buffer. | |
int | mbedtls_md_hmac_reset (mbedtls_md_context_t *ctx) |
This function prepares to authenticate a new message with the same key as the previous HMAC operation. | |
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) |
This function calculates the full generic HMAC on the input buffer with the provided key. |
Detailed Description
The generic message-digest wrapper.
Definition in file md.h.
Typedef Documentation
typedef struct mbedtls_md_info_t mbedtls_md_info_t |
Opaque struct defined in md_internal.h.
Enumeration Type Documentation
enum mbedtls_md_type_t |
Function Documentation
int mbedtls_md | ( | const mbedtls_md_info_t * | md_info, |
const unsigned char * | input, | ||
size_t | ilen, | ||
unsigned char * | output | ||
) |
This function calculates the message-digest of a buffer, with respect to a configurable message-digest algorithm in a single call.
The result is calculated as Output = message_digest(input buffer).
- Parameters:
-
md_info The information structure of the message-digest algorithm to use. input The buffer holding the data. ilen The length of the input data. output The generic message-digest checksum result.
- Returns:
0
on success, or MBEDTLS_ERR_MD_BAD_INPUT_DATA if parameter verification fails.
int mbedtls_md_clone | ( | mbedtls_md_context_t * | dst, |
const mbedtls_md_context_t * | src | ||
) |
This function clones the state of an message-digest context.
- Note:
- You must call mbedtls_md_setup() on
dst
before calling this function. - The two contexts must have the same type, for example, both are SHA-256.
- Warning:
- This function clones the message-digest state, not the HMAC state.
- Parameters:
-
dst The destination context. src The context to be cloned.
- Returns:
0
on success, MBEDTLS_ERR_MD_BAD_INPUT_DATA on parameter failure.
int mbedtls_md_file | ( | const mbedtls_md_info_t * | md_info, |
const char * | path, | ||
unsigned char * | output | ||
) |
This function calculates the message-digest checksum result of the contents of the provided file.
The result is calculated as Output = message_digest(file contents).
- Parameters:
-
md_info The information structure of the message-digest algorithm to use. path The input file name. output The generic message-digest checksum result.
- Returns:
0
on success, MBEDTLS_ERR_MD_FILE_IO_ERROR if file input failed, or MBEDTLS_ERR_MD_BAD_INPUT_DATA ifmd_info
was NULL.
int mbedtls_md_finish | ( | mbedtls_md_context_t * | ctx, |
unsigned char * | output | ||
) |
This function finishes the digest operation, and writes the result to the output buffer.
Call this function after a call to mbedtls_md_starts(), followed by any number of calls to mbedtls_md_update(). Afterwards, you may either clear the context with mbedtls_md_free(), or call mbedtls_md_starts() to reuse the context for another digest operation with the same algorithm.
- Parameters:
-
ctx The generic message-digest context. output The buffer for the generic message-digest checksum result.
- Returns:
0
on success, or MBEDTLS_ERR_MD_BAD_INPUT_DATA if parameter verification fails.
void mbedtls_md_free | ( | mbedtls_md_context_t * | ctx ) |
This function clears the internal structure of ctx
and frees any embedded internal structure, but does not free ctx
itself.
If you have called mbedtls_md_setup() on ctx
, you must call mbedtls_md_free() when you are no longer using the context. Calling this function if you have previously called mbedtls_md_init() and nothing else is optional. You must not call this function if you have not called mbedtls_md_init().
const char* mbedtls_md_get_name | ( | const mbedtls_md_info_t * | md_info ) |
unsigned char mbedtls_md_get_size | ( | const mbedtls_md_info_t * | md_info ) |
mbedtls_md_type_t mbedtls_md_get_type | ( | const mbedtls_md_info_t * | md_info ) |
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 | ||
) |
This function calculates the full generic HMAC on the input buffer with the provided key.
The function allocates the context, performs the calculation, and frees the context.
The HMAC result is calculated as output = generic HMAC(hmac key, input buffer).
- Parameters:
-
md_info The information structure of the message-digest algorithm to use. key The HMAC secret key. keylen The length of the HMAC secret key in Bytes. input The buffer holding the input data. ilen The length of the input data. output The generic HMAC result.
- Returns:
0
on success, or MBEDTLS_ERR_MD_BAD_INPUT_DATA if parameter verification fails.
int mbedtls_md_hmac_finish | ( | mbedtls_md_context_t * | ctx, |
unsigned char * | output | ||
) |
This function finishes the HMAC operation, and writes the result to the output buffer.
Call this function after mbedtls_md_hmac_starts() and mbedtls_md_hmac_update() to get the HMAC value. Afterwards you may either call mbedtls_md_free() to clear the context, or call mbedtls_md_hmac_reset() to reuse the context with the same HMAC key.
- Parameters:
-
ctx The message digest context containing an embedded HMAC context. output The generic HMAC checksum result.
- Returns:
0
on success, or MBEDTLS_ERR_MD_BAD_INPUT_DATA if parameter verification fails.
int mbedtls_md_hmac_reset | ( | mbedtls_md_context_t * | ctx ) |
This function prepares to authenticate a new message with the same key as the previous HMAC operation.
You may call this function after mbedtls_md_hmac_finish(). Afterwards call mbedtls_md_hmac_update() to pass the new input.
- Parameters:
-
ctx The message digest context containing an embedded HMAC context.
- Returns:
0
on success, or MBEDTLS_ERR_MD_BAD_INPUT_DATA if parameter verification fails.
int mbedtls_md_hmac_starts | ( | mbedtls_md_context_t * | ctx, |
const unsigned char * | key, | ||
size_t | keylen | ||
) |
This function sets the HMAC key and prepares to authenticate a new message.
Call this function after mbedtls_md_setup(), to use the MD context for an HMAC calculation, then call mbedtls_md_hmac_update() to provide the input data, and mbedtls_md_hmac_finish() to get the HMAC value.
- Parameters:
-
ctx The message digest context containing an embedded HMAC context. key The HMAC secret key. keylen The length of the HMAC key in Bytes.
- Returns:
0
on success, or MBEDTLS_ERR_MD_BAD_INPUT_DATA if parameter verification fails.
int mbedtls_md_hmac_update | ( | mbedtls_md_context_t * | ctx, |
const unsigned char * | input, | ||
size_t | ilen | ||
) |
This function feeds an input buffer into an ongoing HMAC computation.
Call mbedtls_md_hmac_starts() or mbedtls_md_hmac_reset() before calling this function. You may call this function multiple times to pass the input piecewise. Afterwards, call mbedtls_md_hmac_finish().
- Parameters:
-
ctx The message digest context containing an embedded HMAC context. input The buffer holding the input data. ilen The length of the input data.
- Returns:
0
on success, or MBEDTLS_ERR_MD_BAD_INPUT_DATA if parameter verification fails.
const mbedtls_md_info_t* mbedtls_md_info_from_string | ( | const char * | md_name ) |
const mbedtls_md_info_t* mbedtls_md_info_from_type | ( | mbedtls_md_type_t | md_type ) |
void mbedtls_md_init | ( | mbedtls_md_context_t * | ctx ) |
This function initializes a message-digest context without binding it to a particular message-digest algorithm.
This function should always be called first. It prepares the context for mbedtls_md_setup() for binding it to a message-digest algorithm.
int mbedtls_md_init_ctx | ( | mbedtls_md_context_t * | ctx, |
const mbedtls_md_info_t * | md_info | ||
) |
This function selects the message digest algorithm to use, and allocates internal structures.
It should be called after mbedtls_md_init() or mbedtls_md_free(). Makes it necessary to call mbedtls_md_free() later.
- Parameters:
-
ctx The context to set up. md_info The information structure of the message-digest algorithm to use.
- Returns:
0
on success, MBEDTLS_ERR_MD_BAD_INPUT_DATA on parameter failure, MBEDTLS_ERR_MD_ALLOC_FAILED memory allocation failure.
const int* mbedtls_md_list | ( | void | ) |
This function returns the list of digests supported by the generic digest module.
- Returns:
- A statically allocated array of digests. Each element in the returned list is an integer belonging to the message-digest enumeration mbedtls_md_type_t. The last entry is 0.
int mbedtls_md_setup | ( | mbedtls_md_context_t * | ctx, |
const mbedtls_md_info_t * | md_info, | ||
int | hmac | ||
) |
This function selects the message digest algorithm to use, and allocates internal structures.
It should be called after mbedtls_md_init() or mbedtls_md_free(). Makes it necessary to call mbedtls_md_free() later.
- Parameters:
-
ctx The context to set up. md_info The information structure of the message-digest algorithm to use. hmac - 0: HMAC is not used. Saves some memory.
- non-zero: HMAC is used with this context.
- Returns:
0
on success, MBEDTLS_ERR_MD_BAD_INPUT_DATA on parameter failure, or MBEDTLS_ERR_MD_ALLOC_FAILED on memory allocation failure.
int mbedtls_md_starts | ( | mbedtls_md_context_t * | ctx ) |
This function starts a message-digest computation.
You must call this function after setting up the context with mbedtls_md_setup(), and before passing data with mbedtls_md_update().
- Parameters:
-
ctx The generic message-digest context.
- Returns:
0
on success, MBEDTLS_ERR_MD_BAD_INPUT_DATA if parameter verification fails.
int mbedtls_md_update | ( | mbedtls_md_context_t * | ctx, |
const unsigned char * | input, | ||
size_t | ilen | ||
) |
This function feeds an input buffer into an ongoing message-digest computation.
You must call mbedtls_md_starts() before calling this function. You may call this function multiple times. Afterwards, call mbedtls_md_finish().
- Parameters:
-
ctx The generic message-digest context. input The buffer holding the input data. ilen The length of the input data.
- Returns:
0
on success, MBEDTLS_ERR_MD_BAD_INPUT_DATA if parameter verification fails.
Generated on Tue Jul 12 2022 12:22:32 by
