2018-03-03 23:28:26 +01:00
|
|
|
/**
|
2016-12-11 21:03:00 +01:00
|
|
|
* \file md.h
|
|
|
|
*
|
2018-03-03 23:28:26 +01:00
|
|
|
* \brief The generic message-digest wrapper.
|
2016-12-11 21:03:00 +01:00
|
|
|
*
|
|
|
|
* \author Adriaan de Jong <dejong@fox-it.com>
|
2018-03-03 23:28:26 +01:00
|
|
|
*/
|
|
|
|
/*
|
|
|
|
* Copyright (C) 2006-2018, Arm Limited (or its affiliates), All Rights Reserved
|
2016-12-11 21:03:00 +01:00
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); you may
|
|
|
|
* not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*
|
2018-03-03 23:28:26 +01:00
|
|
|
* This file is part of Mbed TLS (https://tls.mbed.org)
|
2016-12-11 21:03:00 +01:00
|
|
|
*/
|
2018-03-03 23:28:26 +01:00
|
|
|
|
2016-12-11 21:03:00 +01:00
|
|
|
#ifndef MBEDTLS_MD_H
|
|
|
|
#define MBEDTLS_MD_H
|
|
|
|
|
|
|
|
#include <stddef.h>
|
|
|
|
|
2018-03-03 23:28:26 +01:00
|
|
|
#if !defined(MBEDTLS_CONFIG_FILE)
|
|
|
|
#include "config.h"
|
|
|
|
#else
|
|
|
|
#include MBEDTLS_CONFIG_FILE
|
|
|
|
#endif
|
|
|
|
|
2016-12-11 21:03:00 +01:00
|
|
|
#define MBEDTLS_ERR_MD_FEATURE_UNAVAILABLE -0x5080 /**< The selected feature is not available. */
|
|
|
|
#define MBEDTLS_ERR_MD_BAD_INPUT_DATA -0x5100 /**< Bad input parameters to function. */
|
|
|
|
#define MBEDTLS_ERR_MD_ALLOC_FAILED -0x5180 /**< Failed to allocate memory. */
|
|
|
|
#define MBEDTLS_ERR_MD_FILE_IO_ERROR -0x5200 /**< Opening or reading of file failed. */
|
2018-03-03 23:28:26 +01:00
|
|
|
#define MBEDTLS_ERR_MD_HW_ACCEL_FAILED -0x5280 /**< MD hardware accelerator failed. */
|
2016-12-11 21:03:00 +01:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2018-03-03 23:28:26 +01:00
|
|
|
/**
|
|
|
|
* \brief Enumeration of supported message digests
|
|
|
|
*
|
|
|
|
* \warning MD2, MD4, MD5 and SHA-1 are considered weak message digests and
|
|
|
|
* their use constitutes a security risk. We recommend considering
|
|
|
|
* stronger message digests instead.
|
|
|
|
*
|
|
|
|
*/
|
2016-12-11 21:03:00 +01:00
|
|
|
typedef enum {
|
|
|
|
MBEDTLS_MD_NONE=0,
|
|
|
|
MBEDTLS_MD_MD2,
|
|
|
|
MBEDTLS_MD_MD4,
|
|
|
|
MBEDTLS_MD_MD5,
|
|
|
|
MBEDTLS_MD_SHA1,
|
|
|
|
MBEDTLS_MD_SHA224,
|
|
|
|
MBEDTLS_MD_SHA256,
|
|
|
|
MBEDTLS_MD_SHA384,
|
|
|
|
MBEDTLS_MD_SHA512,
|
|
|
|
MBEDTLS_MD_RIPEMD160,
|
|
|
|
} mbedtls_md_type_t;
|
|
|
|
|
|
|
|
#if defined(MBEDTLS_SHA512_C)
|
|
|
|
#define MBEDTLS_MD_MAX_SIZE 64 /* longest known is SHA512 */
|
|
|
|
#else
|
|
|
|
#define MBEDTLS_MD_MAX_SIZE 32 /* longest known is SHA256 or less */
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/**
|
2018-03-03 23:28:26 +01:00
|
|
|
* Opaque struct defined in md_internal.h.
|
2016-12-11 21:03:00 +01:00
|
|
|
*/
|
|
|
|
typedef struct mbedtls_md_info_t mbedtls_md_info_t;
|
|
|
|
|
|
|
|
/**
|
2018-03-03 23:28:26 +01:00
|
|
|
* The generic message-digest context.
|
2016-12-11 21:03:00 +01:00
|
|
|
*/
|
|
|
|
typedef struct {
|
2018-03-03 23:28:26 +01:00
|
|
|
/** Information about the associated message digest. */
|
2016-12-11 21:03:00 +01:00
|
|
|
const mbedtls_md_info_t *md_info;
|
|
|
|
|
2018-03-03 23:28:26 +01:00
|
|
|
/** The digest-specific context. */
|
2016-12-11 21:03:00 +01:00
|
|
|
void *md_ctx;
|
|
|
|
|
2018-03-03 23:28:26 +01:00
|
|
|
/** The HMAC part of the context. */
|
2016-12-11 21:03:00 +01:00
|
|
|
void *hmac_ctx;
|
|
|
|
} mbedtls_md_context_t;
|
|
|
|
|
|
|
|
/**
|
2018-03-03 23:28:26 +01:00
|
|
|
* \brief This function returns the list of digests supported by the
|
|
|
|
* generic digest module.
|
2016-12-11 21:03:00 +01:00
|
|
|
*
|
2018-03-03 23:28:26 +01:00
|
|
|
* \return 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.
|
2016-12-11 21:03:00 +01:00
|
|
|
*/
|
|
|
|
const int *mbedtls_md_list( void );
|
|
|
|
|
|
|
|
/**
|
2018-03-03 23:28:26 +01:00
|
|
|
* \brief This function returns the message-digest information
|
|
|
|
* associated with the given digest name.
|
2016-12-11 21:03:00 +01:00
|
|
|
*
|
2018-03-03 23:28:26 +01:00
|
|
|
* \param md_name The name of the digest to search for.
|
2016-12-11 21:03:00 +01:00
|
|
|
*
|
2018-03-03 23:28:26 +01:00
|
|
|
* \return The message-digest information associated with \p md_name,
|
|
|
|
* or NULL if not found.
|
2016-12-11 21:03:00 +01:00
|
|
|
*/
|
|
|
|
const mbedtls_md_info_t *mbedtls_md_info_from_string( const char *md_name );
|
|
|
|
|
|
|
|
/**
|
2018-03-03 23:28:26 +01:00
|
|
|
* \brief This function returns the message-digest information
|
|
|
|
* associated with the given digest type.
|
2016-12-11 21:03:00 +01:00
|
|
|
*
|
2018-03-03 23:28:26 +01:00
|
|
|
* \param md_type The type of digest to search for.
|
2016-12-11 21:03:00 +01:00
|
|
|
*
|
2018-03-03 23:28:26 +01:00
|
|
|
* \return The message-digest information associated with \p md_type,
|
|
|
|
* or NULL if not found.
|
2016-12-11 21:03:00 +01:00
|
|
|
*/
|
|
|
|
const mbedtls_md_info_t *mbedtls_md_info_from_type( mbedtls_md_type_t md_type );
|
|
|
|
|
|
|
|
/**
|
2018-03-03 23:28:26 +01:00
|
|
|
* \brief 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.
|
2016-12-11 21:03:00 +01:00
|
|
|
*/
|
|
|
|
void mbedtls_md_init( mbedtls_md_context_t *ctx );
|
|
|
|
|
|
|
|
/**
|
2018-03-03 23:28:26 +01:00
|
|
|
* \brief This function clears the internal structure of \p ctx and
|
|
|
|
* frees any embedded internal structure, but does not free
|
|
|
|
* \p ctx itself.
|
|
|
|
*
|
|
|
|
* If you have called mbedtls_md_setup() on \p 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().
|
2016-12-11 21:03:00 +01:00
|
|
|
*/
|
|
|
|
void mbedtls_md_free( mbedtls_md_context_t *ctx );
|
|
|
|
|
|
|
|
#if ! defined(MBEDTLS_DEPRECATED_REMOVED)
|
|
|
|
#if defined(MBEDTLS_DEPRECATED_WARNING)
|
|
|
|
#define MBEDTLS_DEPRECATED __attribute__((deprecated))
|
|
|
|
#else
|
|
|
|
#define MBEDTLS_DEPRECATED
|
|
|
|
#endif
|
|
|
|
/**
|
2018-03-03 23:28:26 +01:00
|
|
|
* \brief 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().
|
2016-12-11 21:03:00 +01:00
|
|
|
* Makes it necessary to call mbedtls_md_free() later.
|
|
|
|
*
|
|
|
|
* \deprecated Superseded by mbedtls_md_setup() in 2.0.0
|
|
|
|
*
|
2018-03-03 23:28:26 +01:00
|
|
|
* \param ctx The context to set up.
|
|
|
|
* \param md_info The information structure of the message-digest algorithm
|
|
|
|
* to use.
|
2016-12-11 21:03:00 +01:00
|
|
|
*
|
|
|
|
* \returns \c 0 on success,
|
2018-03-03 23:28:26 +01:00
|
|
|
* #MBEDTLS_ERR_MD_BAD_INPUT_DATA on parameter failure,
|
|
|
|
* #MBEDTLS_ERR_MD_ALLOC_FAILED memory allocation failure.
|
2016-12-11 21:03:00 +01:00
|
|
|
*/
|
|
|
|
int mbedtls_md_init_ctx( mbedtls_md_context_t *ctx, const mbedtls_md_info_t *md_info ) MBEDTLS_DEPRECATED;
|
|
|
|
#undef MBEDTLS_DEPRECATED
|
|
|
|
#endif /* MBEDTLS_DEPRECATED_REMOVED */
|
|
|
|
|
|
|
|
/**
|
2018-03-03 23:28:26 +01:00
|
|
|
* \brief This function selects the message digest algorithm to use,
|
|
|
|
* and allocates internal structures.
|
2016-12-11 21:03:00 +01:00
|
|
|
*
|
2018-03-03 23:28:26 +01:00
|
|
|
* It should be called after mbedtls_md_init() or
|
|
|
|
* mbedtls_md_free(). Makes it necessary to call
|
|
|
|
* mbedtls_md_free() later.
|
|
|
|
*
|
|
|
|
* \param ctx The context to set up.
|
|
|
|
* \param md_info The information structure of the message-digest algorithm
|
|
|
|
* to use.
|
|
|
|
* \param hmac <ul><li>0: HMAC is not used. Saves some memory.</li>
|
|
|
|
* <li>non-zero: HMAC is used with this context.</li></ul>
|
2016-12-11 21:03:00 +01:00
|
|
|
*
|
|
|
|
* \returns \c 0 on success,
|
2018-03-03 23:28:26 +01:00
|
|
|
* #MBEDTLS_ERR_MD_BAD_INPUT_DATA on parameter failure, or
|
|
|
|
* #MBEDTLS_ERR_MD_ALLOC_FAILED on memory allocation failure.
|
2016-12-11 21:03:00 +01:00
|
|
|
*/
|
|
|
|
int mbedtls_md_setup( mbedtls_md_context_t *ctx, const mbedtls_md_info_t *md_info, int hmac );
|
|
|
|
|
|
|
|
/**
|
2018-03-03 23:28:26 +01:00
|
|
|
* \brief This function clones the state of an message-digest
|
|
|
|
* context.
|
|
|
|
*
|
|
|
|
* \note You must call mbedtls_md_setup() on \c dst before calling
|
|
|
|
* this function.
|
2016-12-11 21:03:00 +01:00
|
|
|
*
|
2018-03-03 23:28:26 +01:00
|
|
|
* \note The two contexts must have the same type,
|
|
|
|
* for example, both are SHA-256.
|
2016-12-11 21:03:00 +01:00
|
|
|
*
|
2018-03-03 23:28:26 +01:00
|
|
|
* \warning This function clones the message-digest state, not the
|
|
|
|
* HMAC state.
|
2016-12-11 21:03:00 +01:00
|
|
|
*
|
2018-03-03 23:28:26 +01:00
|
|
|
* \param dst The destination context.
|
|
|
|
* \param src The context to be cloned.
|
2016-12-11 21:03:00 +01:00
|
|
|
*
|
|
|
|
* \return \c 0 on success,
|
2018-03-03 23:28:26 +01:00
|
|
|
* #MBEDTLS_ERR_MD_BAD_INPUT_DATA on parameter failure.
|
2016-12-11 21:03:00 +01:00
|
|
|
*/
|
|
|
|
int mbedtls_md_clone( mbedtls_md_context_t *dst,
|
|
|
|
const mbedtls_md_context_t *src );
|
|
|
|
|
|
|
|
/**
|
2018-03-03 23:28:26 +01:00
|
|
|
* \brief This function extracts the message-digest size from the
|
|
|
|
* message-digest information structure.
|
2016-12-11 21:03:00 +01:00
|
|
|
*
|
2018-03-03 23:28:26 +01:00
|
|
|
* \param md_info The information structure of the message-digest algorithm
|
|
|
|
* to use.
|
2016-12-11 21:03:00 +01:00
|
|
|
*
|
2018-03-03 23:28:26 +01:00
|
|
|
* \return The size of the message-digest output in Bytes.
|
2016-12-11 21:03:00 +01:00
|
|
|
*/
|
2018-01-10 21:48:36 +01:00
|
|
|
unsigned char mbedtls_md_get_size( const mbedtls_md_info_t *md_info );
|
2016-12-11 21:03:00 +01:00
|
|
|
|
|
|
|
/**
|
2018-03-03 23:28:26 +01:00
|
|
|
* \brief This function extracts the message-digest type from the
|
|
|
|
* message-digest information structure.
|
2016-12-11 21:03:00 +01:00
|
|
|
*
|
2018-03-03 23:28:26 +01:00
|
|
|
* \param md_info The information structure of the message-digest algorithm
|
|
|
|
* to use.
|
2016-12-11 21:03:00 +01:00
|
|
|
*
|
2018-03-03 23:28:26 +01:00
|
|
|
* \return The type of the message digest.
|
2016-12-11 21:03:00 +01:00
|
|
|
*/
|
|
|
|
mbedtls_md_type_t mbedtls_md_get_type( const mbedtls_md_info_t *md_info );
|
|
|
|
|
|
|
|
/**
|
2018-03-03 23:28:26 +01:00
|
|
|
* \brief This function extracts the message-digest name from the
|
|
|
|
* message-digest information structure.
|
2016-12-11 21:03:00 +01:00
|
|
|
*
|
2018-03-03 23:28:26 +01:00
|
|
|
* \param md_info The information structure of the message-digest algorithm
|
|
|
|
* to use.
|
2016-12-11 21:03:00 +01:00
|
|
|
*
|
2018-03-03 23:28:26 +01:00
|
|
|
* \return The name of the message digest.
|
2016-12-11 21:03:00 +01:00
|
|
|
*/
|
|
|
|
const char *mbedtls_md_get_name( const mbedtls_md_info_t *md_info );
|
|
|
|
|
|
|
|
/**
|
2018-03-03 23:28:26 +01:00
|
|
|
* \brief This function starts a message-digest computation.
|
2016-12-11 21:03:00 +01:00
|
|
|
*
|
2018-03-03 23:28:26 +01:00
|
|
|
* You must call this function after setting up the context
|
|
|
|
* with mbedtls_md_setup(), and before passing data with
|
|
|
|
* mbedtls_md_update().
|
2016-12-11 21:03:00 +01:00
|
|
|
*
|
2018-03-03 23:28:26 +01:00
|
|
|
* \param ctx The generic message-digest context.
|
|
|
|
*
|
|
|
|
* \returns \c 0 on success, #MBEDTLS_ERR_MD_BAD_INPUT_DATA if
|
|
|
|
* parameter verification fails.
|
2016-12-11 21:03:00 +01:00
|
|
|
*/
|
|
|
|
int mbedtls_md_starts( mbedtls_md_context_t *ctx );
|
|
|
|
|
|
|
|
/**
|
2018-03-03 23:28:26 +01:00
|
|
|
* \brief 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().
|
2016-12-11 21:03:00 +01:00
|
|
|
*
|
2018-03-03 23:28:26 +01:00
|
|
|
* \param ctx The generic message-digest context.
|
|
|
|
* \param input The buffer holding the input data.
|
|
|
|
* \param ilen The length of the input data.
|
2016-12-11 21:03:00 +01:00
|
|
|
*
|
2018-03-03 23:28:26 +01:00
|
|
|
* \returns \c 0 on success, #MBEDTLS_ERR_MD_BAD_INPUT_DATA if
|
|
|
|
* parameter verification fails.
|
2016-12-11 21:03:00 +01:00
|
|
|
*/
|
|
|
|
int mbedtls_md_update( mbedtls_md_context_t *ctx, const unsigned char *input, size_t ilen );
|
|
|
|
|
|
|
|
/**
|
2018-03-03 23:28:26 +01:00
|
|
|
* \brief This function finishes the digest operation,
|
|
|
|
* and writes the result to the output buffer.
|
2016-12-11 21:03:00 +01:00
|
|
|
*
|
2018-03-03 23:28:26 +01:00
|
|
|
* 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.
|
2016-12-11 21:03:00 +01:00
|
|
|
*
|
2018-03-03 23:28:26 +01:00
|
|
|
* \param ctx The generic message-digest context.
|
|
|
|
* \param output The buffer for the generic message-digest checksum result.
|
|
|
|
*
|
|
|
|
* \returns \c 0 on success, or #MBEDTLS_ERR_MD_BAD_INPUT_DATA if
|
|
|
|
* parameter verification fails.
|
2016-12-11 21:03:00 +01:00
|
|
|
*/
|
|
|
|
int mbedtls_md_finish( mbedtls_md_context_t *ctx, unsigned char *output );
|
|
|
|
|
|
|
|
/**
|
2018-03-03 23:28:26 +01:00
|
|
|
* \brief 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).
|
2016-12-11 21:03:00 +01:00
|
|
|
*
|
2018-03-03 23:28:26 +01:00
|
|
|
* \param md_info The information structure of the message-digest algorithm
|
|
|
|
* to use.
|
|
|
|
* \param input The buffer holding the data.
|
|
|
|
* \param ilen The length of the input data.
|
|
|
|
* \param output The generic message-digest checksum result.
|
2016-12-11 21:03:00 +01:00
|
|
|
*
|
2018-03-03 23:28:26 +01:00
|
|
|
* \returns \c 0 on success, or #MBEDTLS_ERR_MD_BAD_INPUT_DATA if
|
|
|
|
* parameter verification fails.
|
2016-12-11 21:03:00 +01:00
|
|
|
*/
|
|
|
|
int mbedtls_md( const mbedtls_md_info_t *md_info, const unsigned char *input, size_t ilen,
|
|
|
|
unsigned char *output );
|
|
|
|
|
|
|
|
#if defined(MBEDTLS_FS_IO)
|
|
|
|
/**
|
2018-03-03 23:28:26 +01:00
|
|
|
* \brief 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).
|
2016-12-11 21:03:00 +01:00
|
|
|
*
|
2018-03-03 23:28:26 +01:00
|
|
|
* \param md_info The information structure of the message-digest algorithm
|
|
|
|
* to use.
|
|
|
|
* \param path The input file name.
|
|
|
|
* \param output The generic message-digest checksum result.
|
2016-12-11 21:03:00 +01:00
|
|
|
*
|
2018-03-03 23:28:26 +01:00
|
|
|
* \return \c 0 on success,
|
|
|
|
* #MBEDTLS_ERR_MD_FILE_IO_ERROR if file input failed, or
|
|
|
|
* #MBEDTLS_ERR_MD_BAD_INPUT_DATA if \p md_info was NULL.
|
2016-12-11 21:03:00 +01:00
|
|
|
*/
|
|
|
|
int mbedtls_md_file( const mbedtls_md_info_t *md_info, const char *path,
|
|
|
|
unsigned char *output );
|
|
|
|
#endif /* MBEDTLS_FS_IO */
|
|
|
|
|
|
|
|
/**
|
2018-03-03 23:28:26 +01:00
|
|
|
* \brief This function sets the HMAC key and prepares to
|
|
|
|
* authenticate a new message.
|
2016-12-11 21:03:00 +01:00
|
|
|
*
|
2018-03-03 23:28:26 +01:00
|
|
|
* 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.
|
2016-12-11 21:03:00 +01:00
|
|
|
*
|
2018-03-03 23:28:26 +01:00
|
|
|
* \param ctx The message digest context containing an embedded HMAC
|
|
|
|
* context.
|
|
|
|
* \param key The HMAC secret key.
|
|
|
|
* \param keylen The length of the HMAC key in Bytes.
|
|
|
|
*
|
|
|
|
* \returns \c 0 on success, or #MBEDTLS_ERR_MD_BAD_INPUT_DATA if
|
|
|
|
* parameter verification fails.
|
2016-12-11 21:03:00 +01:00
|
|
|
*/
|
|
|
|
int mbedtls_md_hmac_starts( mbedtls_md_context_t *ctx, const unsigned char *key,
|
|
|
|
size_t keylen );
|
|
|
|
|
|
|
|
/**
|
2018-03-03 23:28:26 +01:00
|
|
|
* \brief 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().
|
|
|
|
*
|
|
|
|
* \param ctx The message digest context containing an embedded HMAC
|
|
|
|
* context.
|
|
|
|
* \param input The buffer holding the input data.
|
|
|
|
* \param ilen The length of the input data.
|
|
|
|
*
|
|
|
|
* \returns \c 0 on success, or #MBEDTLS_ERR_MD_BAD_INPUT_DATA if
|
|
|
|
* parameter verification fails.
|
2016-12-11 21:03:00 +01:00
|
|
|
*/
|
|
|
|
int mbedtls_md_hmac_update( mbedtls_md_context_t *ctx, const unsigned char *input,
|
|
|
|
size_t ilen );
|
|
|
|
|
|
|
|
/**
|
2018-03-03 23:28:26 +01:00
|
|
|
* \brief 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.
|
2016-12-11 21:03:00 +01:00
|
|
|
*
|
2018-03-03 23:28:26 +01:00
|
|
|
* \param ctx The message digest context containing an embedded HMAC
|
|
|
|
* context.
|
|
|
|
* \param output The generic HMAC checksum result.
|
2016-12-11 21:03:00 +01:00
|
|
|
*
|
2018-03-03 23:28:26 +01:00
|
|
|
* \returns \c 0 on success, or #MBEDTLS_ERR_MD_BAD_INPUT_DATA if
|
|
|
|
* parameter verification fails.
|
2016-12-11 21:03:00 +01:00
|
|
|
*/
|
|
|
|
int mbedtls_md_hmac_finish( mbedtls_md_context_t *ctx, unsigned char *output);
|
|
|
|
|
|
|
|
/**
|
2018-03-03 23:28:26 +01:00
|
|
|
* \brief This function prepares to authenticate a new message with
|
|
|
|
* the same key as the previous HMAC operation.
|
2016-12-11 21:03:00 +01:00
|
|
|
*
|
2018-03-03 23:28:26 +01:00
|
|
|
* You may call this function after mbedtls_md_hmac_finish().
|
|
|
|
* Afterwards call mbedtls_md_hmac_update() to pass the new
|
|
|
|
* input.
|
2016-12-11 21:03:00 +01:00
|
|
|
*
|
2018-03-03 23:28:26 +01:00
|
|
|
* \param ctx The message digest context containing an embedded HMAC
|
|
|
|
* context.
|
|
|
|
*
|
|
|
|
* \returns \c 0 on success, or #MBEDTLS_ERR_MD_BAD_INPUT_DATA if
|
|
|
|
* parameter verification fails.
|
2016-12-11 21:03:00 +01:00
|
|
|
*/
|
|
|
|
int mbedtls_md_hmac_reset( mbedtls_md_context_t *ctx );
|
|
|
|
|
|
|
|
/**
|
2018-03-03 23:28:26 +01:00
|
|
|
* \brief 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).
|
2016-12-11 21:03:00 +01:00
|
|
|
*
|
2018-03-03 23:28:26 +01:00
|
|
|
* \param md_info The information structure of the message-digest algorithm
|
|
|
|
* to use.
|
|
|
|
* \param key The HMAC secret key.
|
|
|
|
* \param keylen The length of the HMAC secret key in Bytes.
|
|
|
|
* \param input The buffer holding the input data.
|
|
|
|
* \param ilen The length of the input data.
|
|
|
|
* \param output The generic HMAC result.
|
2016-12-11 21:03:00 +01:00
|
|
|
*
|
2018-03-03 23:28:26 +01:00
|
|
|
* \returns \c 0 on success, or #MBEDTLS_ERR_MD_BAD_INPUT_DATA if
|
|
|
|
* parameter verification fails.
|
2016-12-11 21:03:00 +01:00
|
|
|
*/
|
|
|
|
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 );
|
|
|
|
|
|
|
|
/* Internal use */
|
|
|
|
int mbedtls_md_process( mbedtls_md_context_t *ctx, const unsigned char *data );
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif /* MBEDTLS_MD_H */
|