blob: 3164788701cc556e462e339fd697a39236522c16 [file] [log] [blame]
Paul Bakker17373852011-01-06 14:20:01 +00001/**
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002 * \file mbedtls_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
Paul Bakker17373852011-01-06 14:20:01 +00009 *
Manuel Pégourié-Gonnardfe446432015-03-06 13:17:10 +000010 * This file is part of mbed TLS (https://tls.mbed.org)
Paul Bakker17373852011-01-06 14:20:01 +000011 *
Paul Bakker17373852011-01-06 14:20:01 +000012 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License along
23 * with this program; if not, write to the Free Software Foundation, Inc.,
24 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020026#ifndef MBEDTLS_MD_H
27#define MBEDTLS_MD_H
Paul Bakker17373852011-01-06 14:20:01 +000028
Rich Evans00ab4702015-02-06 13:43:58 +000029#include <stddef.h>
Paul Bakker23986e52011-04-24 08:57:21 +000030
Paul Bakker09b1ec62011-07-27 16:28:54 +000031#if defined(_MSC_VER) && !defined(inline)
Paul Bakkeraf5c85f2011-04-18 03:47:52 +000032#define inline _inline
Paul Bakker569df2c2011-06-21 07:48:07 +000033#else
Paul Bakker09b1ec62011-07-27 16:28:54 +000034#if defined(__ARMCC_VERSION) && !defined(inline)
Paul Bakker569df2c2011-06-21 07:48:07 +000035#define inline __inline
Paul Bakker74fb74e2011-06-21 13:36:18 +000036#endif /* __ARMCC_VERSION */
Paul Bakker569df2c2011-06-21 07:48:07 +000037#endif /*_MSC_VER */
Paul Bakkeraf5c85f2011-04-18 03:47:52 +000038
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020039#define MBEDTLS_ERR_MD_FEATURE_UNAVAILABLE -0x5080 /**< The selected feature is not available. */
40#define MBEDTLS_ERR_MD_BAD_INPUT_DATA -0x5100 /**< Bad input parameters to function. */
41#define MBEDTLS_ERR_MD_ALLOC_FAILED -0x5180 /**< Failed to allocate memory. */
42#define MBEDTLS_ERR_MD_FILE_IO_ERROR -0x5200 /**< Opening or reading of file failed. */
Paul Bakker335db3f2011-04-25 15:28:35 +000043
Paul Bakker407a0da2013-06-27 14:29:21 +020044#ifdef __cplusplus
45extern "C" {
46#endif
47
Paul Bakker17373852011-01-06 14:20:01 +000048typedef enum {
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020049 MBEDTLS_MD_NONE=0,
50 MBEDTLS_MD_MD2,
51 MBEDTLS_MD_MD4,
52 MBEDTLS_MD_MD5,
53 MBEDTLS_MD_SHA1,
54 MBEDTLS_MD_SHA224,
55 MBEDTLS_MD_SHA256,
56 MBEDTLS_MD_SHA384,
57 MBEDTLS_MD_SHA512,
58 MBEDTLS_MD_RIPEMD160,
59} mbedtls_md_type_t;
Paul Bakker17373852011-01-06 14:20:01 +000060
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020061#if defined(MBEDTLS_SHA512_C)
62#define MBEDTLS_MD_MAX_SIZE 64 /* longest known is SHA512 */
Paul Bakker7db01092013-09-10 11:10:57 +020063#else
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020064#define MBEDTLS_MD_MAX_SIZE 32 /* longest known is SHA256 or less */
Paul Bakker7db01092013-09-10 11:10:57 +020065#endif
Paul Bakker1b57b062011-01-06 15:48:19 +000066
Paul Bakker17373852011-01-06 14:20:01 +000067/**
Manuel Pégourié-Gonnard50518f42015-05-26 11:04:15 +020068 * Opaque struct defined in md_internal.h
Paul Bakker17373852011-01-06 14:20:01 +000069 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020070typedef struct mbedtls_md_info_t mbedtls_md_info_t;
Paul Bakker17373852011-01-06 14:20:01 +000071
72/**
73 * Generic message digest context.
74 */
75typedef struct {
76 /** Information about the associated message digest */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020077 const mbedtls_md_info_t *md_info;
Paul Bakker17373852011-01-06 14:20:01 +000078
79 /** Digest-specific context */
80 void *md_ctx;
Manuel Pégourié-Gonnard8379a822015-03-24 16:48:22 +010081
Manuel Pégourié-Gonnarddfb3dc82015-03-25 11:49:07 +010082 /** HMAC part of the context */
83 void *hmac_ctx;
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020084} mbedtls_md_context_t;
Paul Bakker17373852011-01-06 14:20:01 +000085
Paul Bakker17373852011-01-06 14:20:01 +000086/**
Paul Bakker72f62662011-01-16 21:27:44 +000087 * \brief Returns the list of digests supported by the generic digest module.
88 *
89 * \return a statically allocated array of digests, the last entry
90 * is 0.
91 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020092const int *mbedtls_md_list( void );
Paul Bakker72f62662011-01-16 21:27:44 +000093
94/**
Paul Bakker17373852011-01-06 14:20:01 +000095 * \brief Returns the message digest information associated with the
96 * given digest name.
97 *
Paul Bakker23986e52011-04-24 08:57:21 +000098 * \param md_name Name of the digest to search for.
Paul Bakker17373852011-01-06 14:20:01 +000099 *
100 * \return The message digest information associated with md_name or
101 * NULL if not found.
102 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200103const mbedtls_md_info_t *mbedtls_md_info_from_string( const char *md_name );
Paul Bakker17373852011-01-06 14:20:01 +0000104
105/**
106 * \brief Returns the message digest information associated with the
107 * given digest type.
108 *
109 * \param md_type type of digest to search for.
110 *
111 * \return The message digest information associated with md_type or
112 * NULL if not found.
113 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200114const mbedtls_md_info_t *mbedtls_md_info_from_type( mbedtls_md_type_t md_type );
Paul Bakker17373852011-01-06 14:20:01 +0000115
116/**
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100117 * \brief Initialize a md_context (as NONE)
118 * This should always be called first.
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200119 * Prepares the context for mbedtls_md_setup() or mbedtls_md_free().
Paul Bakker84bbeb52014-07-01 14:53:22 +0200120 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200121void mbedtls_md_init( mbedtls_md_context_t *ctx );
Paul Bakker84bbeb52014-07-01 14:53:22 +0200122
123/**
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100124 * \brief Free and clear the internal structures of ctx.
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200125 * Can be called at any time after mbedtls_md_init().
126 * Mandatory once mbedtls_md_setup() has been called.
Paul Bakker84bbeb52014-07-01 14:53:22 +0200127 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200128void mbedtls_md_free( mbedtls_md_context_t *ctx );
Paul Bakker84bbeb52014-07-01 14:53:22 +0200129
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200130#if ! defined(MBEDTLS_DEPRECATED_REMOVED)
131#if defined(MBEDTLS_DEPRECATED_WARNING)
132#define MBEDTLS_DEPRECATED __attribute__((deprecated))
Manuel Pégourié-Gonnard147fa092015-03-25 16:43:14 +0100133#else
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200134#define MBEDTLS_DEPRECATED
Manuel Pégourié-Gonnard147fa092015-03-25 16:43:14 +0100135#endif
136/**
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100137 * \brief Select MD to use and allocate internal structures.
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200138 * Should be called after mbedtls_md_init() or mbedtls_md_free().
139 * Makes it necessary to call mbedtls_md_free() later.
Manuel Pégourié-Gonnard147fa092015-03-25 16:43:14 +0100140 *
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200141 * \deprecated Superseded by mbedtls_md_setup() in 2.0.0
Manuel Pégourié-Gonnard147fa092015-03-25 16:43:14 +0100142 *
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100143 * \param ctx Context to set up.
144 * \param md_info Message digest to use.
Manuel Pégourié-Gonnard147fa092015-03-25 16:43:14 +0100145 *
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100146 * \returns \c 0 on success,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200147 * \c MBEDTLS_ERR_MD_BAD_INPUT_DATA on parameter failure,
148 * \c MBEDTLS_ERR_MD_ALLOC_FAILED memory allocation failure.
Manuel Pégourié-Gonnard147fa092015-03-25 16:43:14 +0100149 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200150int mbedtls_md_init_ctx( mbedtls_md_context_t *ctx, const mbedtls_md_info_t *md_info ) MBEDTLS_DEPRECATED;
151#undef MBEDTLS_DEPRECATED
152#endif /* MBEDTLS_DEPRECATED_REMOVED */
Manuel Pégourié-Gonnard147fa092015-03-25 16:43:14 +0100153
Paul Bakker84bbeb52014-07-01 14:53:22 +0200154/**
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100155 * \brief Select MD to use and allocate internal structures.
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200156 * Should be called after mbedtls_md_init() or mbedtls_md_free().
157 * Makes it necessary to call mbedtls_md_free() later.
Paul Bakker562535d2011-01-20 16:42:01 +0000158 *
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100159 * \param ctx Context to set up.
160 * \param md_info Message digest to use.
161 * \param hmac 0 to save some meory is HMAC will not be use,
162 * non-zero is HMAC is going to be used with this context.
Paul Bakker562535d2011-01-20 16:42:01 +0000163 *
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100164 * \returns \c 0 on success,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200165 * \c MBEDTLS_ERR_MD_BAD_INPUT_DATA on parameter failure,
166 * \c MBEDTLS_ERR_MD_ALLOC_FAILED memory allocation failure.
Paul Bakker562535d2011-01-20 16:42:01 +0000167 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200168int mbedtls_md_setup( mbedtls_md_context_t *ctx, const mbedtls_md_info_t *md_info, int hmac );
Paul Bakker562535d2011-01-20 16:42:01 +0000169
170/**
Paul Bakker17373852011-01-06 14:20:01 +0000171 * \brief Returns the size of the message digest output.
172 *
173 * \param md_info message digest info
174 *
175 * \return size of the message digest output.
176 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200177unsigned char mbedtls_md_get_size( const mbedtls_md_info_t *md_info );
Paul Bakker17373852011-01-06 14:20:01 +0000178
179/**
180 * \brief Returns the type of the message digest output.
181 *
182 * \param md_info message digest info
183 *
184 * \return type of the message digest output.
185 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200186mbedtls_md_type_t mbedtls_md_get_type( const mbedtls_md_info_t *md_info );
Paul Bakker17373852011-01-06 14:20:01 +0000187
188/**
189 * \brief Returns the name of the message digest output.
190 *
191 * \param md_info message digest info
192 *
193 * \return name of the message digest output.
194 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200195const char *mbedtls_md_get_name( const mbedtls_md_info_t *md_info );
Paul Bakker17373852011-01-06 14:20:01 +0000196
197/**
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100198 * \brief Prepare the context to digest a new message.
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200199 * Generally called after mbedtls_md_setup() or mbedtls_md_finish().
200 * Followed by mbedtls_md_update().
Paul Bakker17373852011-01-06 14:20:01 +0000201 *
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100202 * \param ctx generic message digest context.
Paul Bakker17373852011-01-06 14:20:01 +0000203 *
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200204 * \returns 0 on success, MBEDTLS_ERR_MD_BAD_INPUT_DATA if parameter
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100205 * verification fails.
Paul Bakker17373852011-01-06 14:20:01 +0000206 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200207int mbedtls_md_starts( mbedtls_md_context_t *ctx );
Paul Bakker17373852011-01-06 14:20:01 +0000208
209/**
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100210 * \brief Generic message digest process buffer
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200211 * Called between mbedtls_md_starts() and mbedtls_md_finish().
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100212 * May be called repeatedly.
Paul Bakker17373852011-01-06 14:20:01 +0000213 *
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100214 * \param ctx Generic message digest context
215 * \param input buffer holding the datal
216 * \param ilen length of the input data
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_update( mbedtls_md_context_t *ctx, const unsigned char *input, size_t ilen );
Paul Bakker17373852011-01-06 14:20:01 +0000222
223/**
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100224 * \brief Generic message digest final digest
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200225 * Called after mbedtls_md_update().
226 * Usually followed by mbedtls_md_free() or mbedtls_md_starts().
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 output Generic message digest checksum result
Paul Bakker17373852011-01-06 14:20:01 +0000230 *
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200231 * \returns 0 on success, MBEDTLS_ERR_MD_BAD_INPUT_DATA if parameter
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100232 * verification fails.
Paul Bakker17373852011-01-06 14:20:01 +0000233 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200234int mbedtls_md_finish( mbedtls_md_context_t *ctx, unsigned char *output );
Paul Bakker17373852011-01-06 14:20:01 +0000235
236/**
Paul Bakker17373852011-01-06 14:20:01 +0000237 * \brief Output = message_digest( input buffer )
238 *
239 * \param md_info message digest info
240 * \param input buffer holding the data
241 * \param ilen length of the input data
242 * \param output Generic message digest checksum result
243 *
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200244 * \returns 0 on success, MBEDTLS_ERR_MD_BAD_INPUT_DATA if parameter
Paul Bakker9c021ad2011-06-09 15:55:11 +0000245 * verification fails.
Paul Bakker17373852011-01-06 14:20:01 +0000246 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200247int mbedtls_md( const mbedtls_md_info_t *md_info, const unsigned char *input, size_t ilen,
Paul Bakker17373852011-01-06 14:20:01 +0000248 unsigned char *output );
249
250/**
251 * \brief Output = message_digest( file contents )
252 *
253 * \param md_info message digest info
254 * \param path input file name
255 * \param output generic message digest checksum result
256 *
Manuel Pégourié-Gonnard932e3932015-04-03 16:37:14 +0200257 * \return 0 if successful,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200258 * MBEDTLS_ERR_MD_FILE_IO_ERROR if file input failed,
259 * MBEDTLS_ERR_MD_BAD_INPUT_DATA if md_info was NULL.
Paul Bakker17373852011-01-06 14:20:01 +0000260 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200261int mbedtls_md_file( const mbedtls_md_info_t *md_info, const char *path,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200262 unsigned char *output );
Paul Bakker17373852011-01-06 14:20:01 +0000263
264/**
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100265 * \brief Set HMAC key and prepare to authenticate a new message.
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200266 * Usually called after mbedtls_md_setup() or mbedtls_md_hmac_finish().
Paul Bakker17373852011-01-06 14:20:01 +0000267 *
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100268 * \param ctx HMAC context
269 * \param key HMAC secret key
270 * \param keylen length of the HMAC key
Paul Bakker17373852011-01-06 14:20:01 +0000271 *
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200272 * \returns 0 on success, MBEDTLS_ERR_MD_BAD_INPUT_DATA if parameter
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100273 * verification fails.
Paul Bakker17373852011-01-06 14:20:01 +0000274 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200275int mbedtls_md_hmac_starts( mbedtls_md_context_t *ctx, const unsigned char *key,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200276 size_t keylen );
Paul Bakker17373852011-01-06 14:20:01 +0000277
278/**
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100279 * \brief Generic HMAC process buffer.
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200280 * Called between mbedtls_md_hmac_starts() or mbedtls_md_hmac_reset()
281 * and mbedtls_md_hmac_finish().
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100282 * May be called repeatedly.
Paul Bakker17373852011-01-06 14:20:01 +0000283 *
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100284 * \param ctx HMAC context
285 * \param input buffer holding the data
286 * \param ilen length of the input data
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_update( mbedtls_md_context_t *ctx, const unsigned char *input,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200292 size_t ilen );
Paul Bakker17373852011-01-06 14:20:01 +0000293
294/**
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100295 * \brief Output HMAC.
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200296 * Called after mbedtls_md_hmac_update().
297 * Usually followed my mbedtls_md_hmac_reset(), mbedtls_md_hmac_starts(),
298 * or mbedtls_md_free().
Paul Bakker17373852011-01-06 14:20:01 +0000299 *
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100300 * \param ctx HMAC context
301 * \param output Generic HMAC checksum result
Paul Bakker17373852011-01-06 14:20:01 +0000302 *
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200303 * \returns 0 on success, MBEDTLS_ERR_MD_BAD_INPUT_DATA if parameter
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100304 * verification fails.
Paul Bakker17373852011-01-06 14:20:01 +0000305 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200306int mbedtls_md_hmac_finish( mbedtls_md_context_t *ctx, unsigned char *output);
Paul Bakker17373852011-01-06 14:20:01 +0000307
308/**
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100309 * \brief Prepare to authenticate a new message with the same key.
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200310 * Called after mbedtls_md_hmac_finish() and before mbedtls_md_hmac_update().
Paul Bakker17373852011-01-06 14:20:01 +0000311 *
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100312 * \param ctx HMAC context to be reset
Paul Bakker17373852011-01-06 14:20:01 +0000313 *
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200314 * \returns 0 on success, MBEDTLS_ERR_MD_BAD_INPUT_DATA if parameter
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100315 * verification fails.
Paul Bakker17373852011-01-06 14:20:01 +0000316 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200317int mbedtls_md_hmac_reset( mbedtls_md_context_t *ctx );
Paul Bakker17373852011-01-06 14:20:01 +0000318
319/**
320 * \brief Output = Generic_HMAC( hmac key, input buffer )
321 *
322 * \param md_info message digest info
323 * \param key HMAC secret key
324 * \param keylen length of the HMAC key
325 * \param input buffer holding the data
326 * \param ilen length of the input data
327 * \param output Generic HMAC-result
328 *
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200329 * \returns 0 on success, MBEDTLS_ERR_MD_BAD_INPUT_DATA if parameter
Paul Bakker9c021ad2011-06-09 15:55:11 +0000330 * verification fails.
Paul Bakker17373852011-01-06 14:20:01 +0000331 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200332int mbedtls_md_hmac( const mbedtls_md_info_t *md_info, const unsigned char *key, size_t keylen,
Paul Bakker23986e52011-04-24 08:57:21 +0000333 const unsigned char *input, size_t ilen,
Paul Bakker17373852011-01-06 14:20:01 +0000334 unsigned char *output );
335
Paul Bakker1bd3ae82013-03-13 10:26:44 +0100336/* Internal use */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200337int mbedtls_md_process( mbedtls_md_context_t *ctx, const unsigned char *data );
Paul Bakker1bd3ae82013-03-13 10:26:44 +0100338
Paul Bakker17373852011-01-06 14:20:01 +0000339#ifdef __cplusplus
340}
341#endif
342
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200343#endif /* MBEDTLS_MD_H */