blob: 89be847ceea5b488af9dbeedfefd7a44330cfa1e [file] [log] [blame]
Paul Bakker17373852011-01-06 14:20:01 +00001/**
Simon Butcher5b331b92016-01-03 16:14:14 +00002 * \file md.h
Paul Bakker9af723c2014-05-01 13:03:14 +02003 *
Paul Bakker17373852011-01-06 14:20:01 +00004 * \brief Generic message digest wrapper
5 *
6 * \author Adriaan de Jong <dejong@fox-it.com>
7 *
Manuel Pégourié-Gonnardca878db2015-03-24 12:13:30 +01008 * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
Manuel Pégourié-Gonnard37ff1402015-09-04 14:21:07 +02009 * SPDX-License-Identifier: Apache-2.0
10 *
11 * Licensed under the Apache License, Version 2.0 (the "License"); you may
12 * not use this file except in compliance with the License.
13 * You may obtain a copy of the License at
14 *
15 * http://www.apache.org/licenses/LICENSE-2.0
16 *
17 * Unless required by applicable law or agreed to in writing, software
18 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
19 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20 * See the License for the specific language governing permissions and
21 * limitations under the License.
Paul Bakker17373852011-01-06 14:20:01 +000022 *
Manuel Pégourié-Gonnardfe446432015-03-06 13:17:10 +000023 * This file is part of mbed TLS (https://tls.mbed.org)
Paul Bakker17373852011-01-06 14:20:01 +000024 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020025#ifndef MBEDTLS_MD_H
26#define MBEDTLS_MD_H
Paul Bakker17373852011-01-06 14:20:01 +000027
Rich Evans00ab4702015-02-06 13:43:58 +000028#include <stddef.h>
Paul Bakker23986e52011-04-24 08:57:21 +000029
Ron Eldorf231eaa2017-08-22 14:50:14 +030030#if !defined(MBEDTLS_CONFIG_FILE)
31#include "config.h"
32#else
33#include MBEDTLS_CONFIG_FILE
34#endif
35
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020036#define MBEDTLS_ERR_MD_FEATURE_UNAVAILABLE -0x5080 /**< The selected feature is not available. */
37#define MBEDTLS_ERR_MD_BAD_INPUT_DATA -0x5100 /**< Bad input parameters to function. */
38#define MBEDTLS_ERR_MD_ALLOC_FAILED -0x5180 /**< Failed to allocate memory. */
39#define MBEDTLS_ERR_MD_FILE_IO_ERROR -0x5200 /**< Opening or reading of file failed. */
Paul Bakker335db3f2011-04-25 15:28:35 +000040
Paul Bakker407a0da2013-06-27 14:29:21 +020041#ifdef __cplusplus
42extern "C" {
43#endif
44
Paul Bakker17373852011-01-06 14:20:01 +000045typedef enum {
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020046 MBEDTLS_MD_NONE=0,
47 MBEDTLS_MD_MD2,
48 MBEDTLS_MD_MD4,
49 MBEDTLS_MD_MD5,
50 MBEDTLS_MD_SHA1,
51 MBEDTLS_MD_SHA224,
52 MBEDTLS_MD_SHA256,
53 MBEDTLS_MD_SHA384,
54 MBEDTLS_MD_SHA512,
55 MBEDTLS_MD_RIPEMD160,
56} mbedtls_md_type_t;
Paul Bakker17373852011-01-06 14:20:01 +000057
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020058#if defined(MBEDTLS_SHA512_C)
59#define MBEDTLS_MD_MAX_SIZE 64 /* longest known is SHA512 */
Paul Bakker7db01092013-09-10 11:10:57 +020060#else
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020061#define MBEDTLS_MD_MAX_SIZE 32 /* longest known is SHA256 or less */
Paul Bakker7db01092013-09-10 11:10:57 +020062#endif
Paul Bakker1b57b062011-01-06 15:48:19 +000063
Paul Bakker17373852011-01-06 14:20:01 +000064/**
Manuel Pégourié-Gonnard50518f42015-05-26 11:04:15 +020065 * Opaque struct defined in md_internal.h
Paul Bakker17373852011-01-06 14:20:01 +000066 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020067typedef struct mbedtls_md_info_t mbedtls_md_info_t;
Paul Bakker17373852011-01-06 14:20:01 +000068
69/**
70 * Generic message digest context.
71 */
72typedef struct {
73 /** Information about the associated message digest */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020074 const mbedtls_md_info_t *md_info;
Paul Bakker17373852011-01-06 14:20:01 +000075
76 /** Digest-specific context */
77 void *md_ctx;
Manuel Pégourié-Gonnard8379a822015-03-24 16:48:22 +010078
Manuel Pégourié-Gonnarddfb3dc82015-03-25 11:49:07 +010079 /** HMAC part of the context */
80 void *hmac_ctx;
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020081} mbedtls_md_context_t;
Paul Bakker17373852011-01-06 14:20:01 +000082
Paul Bakker17373852011-01-06 14:20:01 +000083/**
Paul Bakker72f62662011-01-16 21:27:44 +000084 * \brief Returns the list of digests supported by the generic digest module.
85 *
86 * \return a statically allocated array of digests, the last entry
87 * is 0.
88 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020089const int *mbedtls_md_list( void );
Paul Bakker72f62662011-01-16 21:27:44 +000090
91/**
Paul Bakker17373852011-01-06 14:20:01 +000092 * \brief Returns the message digest information associated with the
93 * given digest name.
94 *
Paul Bakker23986e52011-04-24 08:57:21 +000095 * \param md_name Name of the digest to search for.
Paul Bakker17373852011-01-06 14:20:01 +000096 *
97 * \return The message digest information associated with md_name or
98 * NULL if not found.
99 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200100const mbedtls_md_info_t *mbedtls_md_info_from_string( const char *md_name );
Paul Bakker17373852011-01-06 14:20:01 +0000101
102/**
103 * \brief Returns the message digest information associated with the
104 * given digest type.
105 *
106 * \param md_type type of digest to search for.
107 *
108 * \return The message digest information associated with md_type or
109 * NULL if not found.
110 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200111const mbedtls_md_info_t *mbedtls_md_info_from_type( mbedtls_md_type_t md_type );
Paul Bakker17373852011-01-06 14:20:01 +0000112
113/**
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100114 * \brief Initialize a md_context (as NONE)
115 * This should always be called first.
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200116 * Prepares the context for mbedtls_md_setup() or mbedtls_md_free().
Paul Bakker84bbeb52014-07-01 14:53:22 +0200117 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200118void mbedtls_md_init( mbedtls_md_context_t *ctx );
Paul Bakker84bbeb52014-07-01 14:53:22 +0200119
120/**
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100121 * \brief Free and clear the internal structures of ctx.
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200122 * Can be called at any time after mbedtls_md_init().
123 * Mandatory once mbedtls_md_setup() has been called.
Paul Bakker84bbeb52014-07-01 14:53:22 +0200124 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200125void mbedtls_md_free( mbedtls_md_context_t *ctx );
Paul Bakker84bbeb52014-07-01 14:53:22 +0200126
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200127#if ! defined(MBEDTLS_DEPRECATED_REMOVED)
128#if defined(MBEDTLS_DEPRECATED_WARNING)
129#define MBEDTLS_DEPRECATED __attribute__((deprecated))
Manuel Pégourié-Gonnard147fa092015-03-25 16:43:14 +0100130#else
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200131#define MBEDTLS_DEPRECATED
Manuel Pégourié-Gonnard147fa092015-03-25 16:43:14 +0100132#endif
133/**
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100134 * \brief Select MD to use and allocate internal structures.
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200135 * Should be called after mbedtls_md_init() or mbedtls_md_free().
136 * Makes it necessary to call mbedtls_md_free() later.
Manuel Pégourié-Gonnard147fa092015-03-25 16:43:14 +0100137 *
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200138 * \deprecated Superseded by mbedtls_md_setup() in 2.0.0
Manuel Pégourié-Gonnard147fa092015-03-25 16:43:14 +0100139 *
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100140 * \param ctx Context to set up.
141 * \param md_info Message digest to use.
Manuel Pégourié-Gonnard147fa092015-03-25 16:43:14 +0100142 *
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100143 * \returns \c 0 on success,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200144 * \c MBEDTLS_ERR_MD_BAD_INPUT_DATA on parameter failure,
145 * \c MBEDTLS_ERR_MD_ALLOC_FAILED memory allocation failure.
Manuel Pégourié-Gonnard147fa092015-03-25 16:43:14 +0100146 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200147int mbedtls_md_init_ctx( mbedtls_md_context_t *ctx, const mbedtls_md_info_t *md_info ) MBEDTLS_DEPRECATED;
148#undef MBEDTLS_DEPRECATED
149#endif /* MBEDTLS_DEPRECATED_REMOVED */
Manuel Pégourié-Gonnard147fa092015-03-25 16:43:14 +0100150
Paul Bakker84bbeb52014-07-01 14:53:22 +0200151/**
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100152 * \brief Select MD to use and allocate internal structures.
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200153 * Should be called after mbedtls_md_init() or mbedtls_md_free().
154 * Makes it necessary to call mbedtls_md_free() later.
Paul Bakker562535d2011-01-20 16:42:01 +0000155 *
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100156 * \param ctx Context to set up.
157 * \param md_info Message digest to use.
Manuel Pégourié-Gonnardac50fc52015-08-10 13:07:09 +0200158 * \param hmac 0 to save some memory if HMAC will not be used,
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100159 * non-zero is HMAC is going to be used with this context.
Paul Bakker562535d2011-01-20 16:42:01 +0000160 *
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100161 * \returns \c 0 on success,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200162 * \c MBEDTLS_ERR_MD_BAD_INPUT_DATA on parameter failure,
163 * \c MBEDTLS_ERR_MD_ALLOC_FAILED memory allocation failure.
Paul Bakker562535d2011-01-20 16:42:01 +0000164 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200165int mbedtls_md_setup( mbedtls_md_context_t *ctx, const mbedtls_md_info_t *md_info, int hmac );
Paul Bakker562535d2011-01-20 16:42:01 +0000166
167/**
Manuel Pégourié-Gonnard052a6c92015-07-06 16:06:02 +0200168 * \brief Clone the state of an MD context
169 *
170 * \note The two contexts must have been setup to the same type
171 * (cloning from SHA-256 to SHA-512 make no sense).
172 *
173 * \warning Only clones the MD state, not the HMAC state! (for now)
174 *
175 * \param dst The destination context
176 * \param src The context to be cloned
177 *
178 * \return \c 0 on success,
179 * \c MBEDTLS_ERR_MD_BAD_INPUT_DATA on parameter failure.
180 */
181int mbedtls_md_clone( mbedtls_md_context_t *dst,
182 const mbedtls_md_context_t *src );
183
184/**
Paul Bakker17373852011-01-06 14:20:01 +0000185 * \brief Returns the size of the message digest output.
186 *
187 * \param md_info message digest info
188 *
Manuel Pégourié-Gonnardb8186a52015-06-18 14:58:58 +0200189 * \return size of the message digest output in bytes.
Paul Bakker17373852011-01-06 14:20:01 +0000190 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200191unsigned char mbedtls_md_get_size( const mbedtls_md_info_t *md_info );
Paul Bakker17373852011-01-06 14:20:01 +0000192
193/**
194 * \brief Returns the type of the message digest output.
195 *
196 * \param md_info message digest info
197 *
198 * \return type of the message digest output.
199 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200200mbedtls_md_type_t mbedtls_md_get_type( const mbedtls_md_info_t *md_info );
Paul Bakker17373852011-01-06 14:20:01 +0000201
202/**
203 * \brief Returns the name of the message digest output.
204 *
205 * \param md_info message digest info
206 *
207 * \return name of the message digest output.
208 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200209const char *mbedtls_md_get_name( const mbedtls_md_info_t *md_info );
Paul Bakker17373852011-01-06 14:20:01 +0000210
211/**
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100212 * \brief Prepare the context to digest a new message.
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200213 * Generally called after mbedtls_md_setup() or mbedtls_md_finish().
214 * Followed by mbedtls_md_update().
Paul Bakker17373852011-01-06 14:20:01 +0000215 *
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100216 * \param ctx generic message digest context.
Paul Bakker17373852011-01-06 14:20:01 +0000217 *
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200218 * \returns 0 on success, MBEDTLS_ERR_MD_BAD_INPUT_DATA if parameter
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100219 * verification fails.
Paul Bakker17373852011-01-06 14:20:01 +0000220 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200221int mbedtls_md_starts( mbedtls_md_context_t *ctx );
Paul Bakker17373852011-01-06 14:20:01 +0000222
223/**
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100224 * \brief Generic message digest process buffer
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200225 * Called between mbedtls_md_starts() and mbedtls_md_finish().
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100226 * May be called repeatedly.
Paul Bakker17373852011-01-06 14:20:01 +0000227 *
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100228 * \param ctx Generic message digest context
229 * \param input buffer holding the datal
230 * \param ilen length of the input data
Paul Bakker17373852011-01-06 14:20:01 +0000231 *
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200232 * \returns 0 on success, MBEDTLS_ERR_MD_BAD_INPUT_DATA if parameter
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100233 * verification fails.
Paul Bakker17373852011-01-06 14:20:01 +0000234 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200235int mbedtls_md_update( mbedtls_md_context_t *ctx, const unsigned char *input, size_t ilen );
Paul Bakker17373852011-01-06 14:20:01 +0000236
237/**
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100238 * \brief Generic message digest final digest
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200239 * Called after mbedtls_md_update().
240 * Usually followed by mbedtls_md_free() or mbedtls_md_starts().
Paul Bakker17373852011-01-06 14:20:01 +0000241 *
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100242 * \param ctx Generic message digest context
243 * \param output Generic message digest checksum result
Paul Bakker17373852011-01-06 14:20:01 +0000244 *
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200245 * \returns 0 on success, MBEDTLS_ERR_MD_BAD_INPUT_DATA if parameter
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100246 * verification fails.
Paul Bakker17373852011-01-06 14:20:01 +0000247 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200248int mbedtls_md_finish( mbedtls_md_context_t *ctx, unsigned char *output );
Paul Bakker17373852011-01-06 14:20:01 +0000249
250/**
Paul Bakker17373852011-01-06 14:20:01 +0000251 * \brief Output = message_digest( input buffer )
252 *
253 * \param md_info message digest info
254 * \param input buffer holding the data
255 * \param ilen length of the input data
256 * \param output Generic message digest checksum result
257 *
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200258 * \returns 0 on success, MBEDTLS_ERR_MD_BAD_INPUT_DATA if parameter
Paul Bakker9c021ad2011-06-09 15:55:11 +0000259 * verification fails.
Paul Bakker17373852011-01-06 14:20:01 +0000260 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200261int mbedtls_md( const mbedtls_md_info_t *md_info, const unsigned char *input, size_t ilen,
Paul Bakker17373852011-01-06 14:20:01 +0000262 unsigned char *output );
263
Manuel Pégourié-Gonnardbfffa902015-05-28 14:44:00 +0200264#if defined(MBEDTLS_FS_IO)
Paul Bakker17373852011-01-06 14:20:01 +0000265/**
266 * \brief Output = message_digest( file contents )
267 *
268 * \param md_info message digest info
269 * \param path input file name
270 * \param output generic message digest checksum result
271 *
Manuel Pégourié-Gonnard932e3932015-04-03 16:37:14 +0200272 * \return 0 if successful,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200273 * MBEDTLS_ERR_MD_FILE_IO_ERROR if file input failed,
274 * MBEDTLS_ERR_MD_BAD_INPUT_DATA if md_info was NULL.
Paul Bakker17373852011-01-06 14:20:01 +0000275 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200276int mbedtls_md_file( const mbedtls_md_info_t *md_info, const char *path,
Manuel Pégourié-Gonnardbfffa902015-05-28 14:44:00 +0200277 unsigned char *output );
278#endif /* MBEDTLS_FS_IO */
Paul Bakker17373852011-01-06 14:20:01 +0000279
280/**
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100281 * \brief Set HMAC key and prepare to authenticate a new message.
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200282 * Usually called after mbedtls_md_setup() or mbedtls_md_hmac_finish().
Paul Bakker17373852011-01-06 14:20:01 +0000283 *
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100284 * \param ctx HMAC context
285 * \param key HMAC secret key
Manuel Pégourié-Gonnardb8186a52015-06-18 14:58:58 +0200286 * \param keylen length of the HMAC key in bytes
Paul Bakker17373852011-01-06 14:20:01 +0000287 *
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200288 * \returns 0 on success, MBEDTLS_ERR_MD_BAD_INPUT_DATA if parameter
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100289 * verification fails.
Paul Bakker17373852011-01-06 14:20:01 +0000290 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200291int mbedtls_md_hmac_starts( mbedtls_md_context_t *ctx, const unsigned char *key,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200292 size_t keylen );
Paul Bakker17373852011-01-06 14:20:01 +0000293
294/**
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100295 * \brief Generic HMAC process buffer.
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200296 * Called between mbedtls_md_hmac_starts() or mbedtls_md_hmac_reset()
297 * and mbedtls_md_hmac_finish().
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100298 * May be called repeatedly.
Paul Bakker17373852011-01-06 14:20:01 +0000299 *
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100300 * \param ctx HMAC context
301 * \param input buffer holding the data
302 * \param ilen length of the input data
Paul Bakker17373852011-01-06 14:20:01 +0000303 *
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200304 * \returns 0 on success, MBEDTLS_ERR_MD_BAD_INPUT_DATA if parameter
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100305 * verification fails.
Paul Bakker17373852011-01-06 14:20:01 +0000306 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200307int mbedtls_md_hmac_update( mbedtls_md_context_t *ctx, const unsigned char *input,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200308 size_t ilen );
Paul Bakker17373852011-01-06 14:20:01 +0000309
310/**
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100311 * \brief Output HMAC.
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200312 * Called after mbedtls_md_hmac_update().
Simon Butcher01ba45b2016-10-05 14:17:01 +0100313 * Usually followed by mbedtls_md_hmac_reset(),
314 * mbedtls_md_hmac_starts(), or mbedtls_md_free().
Paul Bakker17373852011-01-06 14:20:01 +0000315 *
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100316 * \param ctx HMAC context
317 * \param output Generic HMAC checksum result
Paul Bakker17373852011-01-06 14:20:01 +0000318 *
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200319 * \returns 0 on success, MBEDTLS_ERR_MD_BAD_INPUT_DATA if parameter
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100320 * verification fails.
Paul Bakker17373852011-01-06 14:20:01 +0000321 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200322int mbedtls_md_hmac_finish( mbedtls_md_context_t *ctx, unsigned char *output);
Paul Bakker17373852011-01-06 14:20:01 +0000323
324/**
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100325 * \brief Prepare to authenticate a new message with the same key.
Simon Butcher01ba45b2016-10-05 14:17:01 +0100326 * Called after mbedtls_md_hmac_finish() and before
327 * mbedtls_md_hmac_update().
Paul Bakker17373852011-01-06 14:20:01 +0000328 *
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100329 * \param ctx HMAC context to be reset
Paul Bakker17373852011-01-06 14:20:01 +0000330 *
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200331 * \returns 0 on success, MBEDTLS_ERR_MD_BAD_INPUT_DATA if parameter
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100332 * verification fails.
Paul Bakker17373852011-01-06 14:20:01 +0000333 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200334int mbedtls_md_hmac_reset( mbedtls_md_context_t *ctx );
Paul Bakker17373852011-01-06 14:20:01 +0000335
336/**
337 * \brief Output = Generic_HMAC( hmac key, input buffer )
338 *
339 * \param md_info message digest info
340 * \param key HMAC secret key
Manuel Pégourié-Gonnardb8186a52015-06-18 14:58:58 +0200341 * \param keylen length of the HMAC key in bytes
Paul Bakker17373852011-01-06 14:20:01 +0000342 * \param input buffer holding the data
343 * \param ilen length of the input data
344 * \param output Generic HMAC-result
345 *
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200346 * \returns 0 on success, MBEDTLS_ERR_MD_BAD_INPUT_DATA if parameter
Paul Bakker9c021ad2011-06-09 15:55:11 +0000347 * verification fails.
Paul Bakker17373852011-01-06 14:20:01 +0000348 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200349int mbedtls_md_hmac( const mbedtls_md_info_t *md_info, const unsigned char *key, size_t keylen,
Paul Bakker23986e52011-04-24 08:57:21 +0000350 const unsigned char *input, size_t ilen,
Paul Bakker17373852011-01-06 14:20:01 +0000351 unsigned char *output );
352
Paul Bakker1bd3ae82013-03-13 10:26:44 +0100353/* Internal use */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200354int mbedtls_md_process( mbedtls_md_context_t *ctx, const unsigned char *data );
Paul Bakker1bd3ae82013-03-13 10:26:44 +0100355
Paul Bakker17373852011-01-06 14:20:01 +0000356#ifdef __cplusplus
357}
358#endif
359
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200360#endif /* MBEDTLS_MD_H */