blob: ad62739756f6b3dcbd2b247192a0bcffbfb6327f [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(__ARMCC_VERSION) && !defined(inline)
Paul Bakker569df2c2011-06-21 07:48:07 +000032#define inline __inline
Paul Bakker74fb74e2011-06-21 13:36:18 +000033#endif /* __ARMCC_VERSION */
Paul Bakkeraf5c85f2011-04-18 03:47:52 +000034
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020035#define MBEDTLS_ERR_MD_FEATURE_UNAVAILABLE -0x5080 /**< The selected feature is not available. */
36#define MBEDTLS_ERR_MD_BAD_INPUT_DATA -0x5100 /**< Bad input parameters to function. */
37#define MBEDTLS_ERR_MD_ALLOC_FAILED -0x5180 /**< Failed to allocate memory. */
38#define MBEDTLS_ERR_MD_FILE_IO_ERROR -0x5200 /**< Opening or reading of file failed. */
Paul Bakker335db3f2011-04-25 15:28:35 +000039
Paul Bakker407a0da2013-06-27 14:29:21 +020040#ifdef __cplusplus
41extern "C" {
42#endif
43
Paul Bakker17373852011-01-06 14:20:01 +000044typedef enum {
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020045 MBEDTLS_MD_NONE=0,
46 MBEDTLS_MD_MD2,
47 MBEDTLS_MD_MD4,
48 MBEDTLS_MD_MD5,
49 MBEDTLS_MD_SHA1,
50 MBEDTLS_MD_SHA224,
51 MBEDTLS_MD_SHA256,
52 MBEDTLS_MD_SHA384,
53 MBEDTLS_MD_SHA512,
54 MBEDTLS_MD_RIPEMD160,
55} mbedtls_md_type_t;
Paul Bakker17373852011-01-06 14:20:01 +000056
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020057#if defined(MBEDTLS_SHA512_C)
58#define MBEDTLS_MD_MAX_SIZE 64 /* longest known is SHA512 */
Paul Bakker7db01092013-09-10 11:10:57 +020059#else
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020060#define MBEDTLS_MD_MAX_SIZE 32 /* longest known is SHA256 or less */
Paul Bakker7db01092013-09-10 11:10:57 +020061#endif
Paul Bakker1b57b062011-01-06 15:48:19 +000062
Paul Bakker17373852011-01-06 14:20:01 +000063/**
Manuel Pégourié-Gonnard50518f42015-05-26 11:04:15 +020064 * Opaque struct defined in md_internal.h
Paul Bakker17373852011-01-06 14:20:01 +000065 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020066typedef struct mbedtls_md_info_t mbedtls_md_info_t;
Paul Bakker17373852011-01-06 14:20:01 +000067
68/**
69 * Generic message digest context.
70 */
71typedef struct {
72 /** Information about the associated message digest */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020073 const mbedtls_md_info_t *md_info;
Paul Bakker17373852011-01-06 14:20:01 +000074
75 /** Digest-specific context */
76 void *md_ctx;
Manuel Pégourié-Gonnard8379a822015-03-24 16:48:22 +010077
Manuel Pégourié-Gonnarddfb3dc82015-03-25 11:49:07 +010078 /** HMAC part of the context */
79 void *hmac_ctx;
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020080} mbedtls_md_context_t;
Paul Bakker17373852011-01-06 14:20:01 +000081
Paul Bakker17373852011-01-06 14:20:01 +000082/**
Paul Bakker72f62662011-01-16 21:27:44 +000083 * \brief Returns the list of digests supported by the generic digest module.
84 *
85 * \return a statically allocated array of digests, the last entry
86 * is 0.
87 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020088const int *mbedtls_md_list( void );
Paul Bakker72f62662011-01-16 21:27:44 +000089
90/**
Paul Bakker17373852011-01-06 14:20:01 +000091 * \brief Returns the message digest information associated with the
92 * given digest name.
93 *
Paul Bakker23986e52011-04-24 08:57:21 +000094 * \param md_name Name of the digest to search for.
Paul Bakker17373852011-01-06 14:20:01 +000095 *
96 * \return The message digest information associated with md_name or
97 * NULL if not found.
98 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020099const mbedtls_md_info_t *mbedtls_md_info_from_string( const char *md_name );
Paul Bakker17373852011-01-06 14:20:01 +0000100
101/**
102 * \brief Returns the message digest information associated with the
103 * given digest type.
104 *
105 * \param md_type type of digest to search for.
106 *
107 * \return The message digest information associated with md_type or
108 * NULL if not found.
109 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200110const mbedtls_md_info_t *mbedtls_md_info_from_type( mbedtls_md_type_t md_type );
Paul Bakker17373852011-01-06 14:20:01 +0000111
112/**
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100113 * \brief Initialize a md_context (as NONE)
114 * This should always be called first.
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200115 * Prepares the context for mbedtls_md_setup() or mbedtls_md_free().
Paul Bakker84bbeb52014-07-01 14:53:22 +0200116 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200117void mbedtls_md_init( mbedtls_md_context_t *ctx );
Paul Bakker84bbeb52014-07-01 14:53:22 +0200118
119/**
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100120 * \brief Free and clear the internal structures of ctx.
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200121 * Can be called at any time after mbedtls_md_init().
122 * Mandatory once mbedtls_md_setup() has been called.
Paul Bakker84bbeb52014-07-01 14:53:22 +0200123 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200124void mbedtls_md_free( mbedtls_md_context_t *ctx );
Paul Bakker84bbeb52014-07-01 14:53:22 +0200125
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200126#if ! defined(MBEDTLS_DEPRECATED_REMOVED)
127#if defined(MBEDTLS_DEPRECATED_WARNING)
128#define MBEDTLS_DEPRECATED __attribute__((deprecated))
Manuel Pégourié-Gonnard147fa092015-03-25 16:43:14 +0100129#else
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200130#define MBEDTLS_DEPRECATED
Manuel Pégourié-Gonnard147fa092015-03-25 16:43:14 +0100131#endif
132/**
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100133 * \brief Select MD to use and allocate internal structures.
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200134 * Should be called after mbedtls_md_init() or mbedtls_md_free().
135 * Makes it necessary to call mbedtls_md_free() later.
Manuel Pégourié-Gonnard147fa092015-03-25 16:43:14 +0100136 *
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200137 * \deprecated Superseded by mbedtls_md_setup() in 2.0.0
Manuel Pégourié-Gonnard147fa092015-03-25 16:43:14 +0100138 *
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100139 * \param ctx Context to set up.
140 * \param md_info Message digest to use.
Manuel Pégourié-Gonnard147fa092015-03-25 16:43:14 +0100141 *
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100142 * \returns \c 0 on success,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200143 * \c MBEDTLS_ERR_MD_BAD_INPUT_DATA on parameter failure,
144 * \c MBEDTLS_ERR_MD_ALLOC_FAILED memory allocation failure.
Manuel Pégourié-Gonnard147fa092015-03-25 16:43:14 +0100145 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200146int mbedtls_md_init_ctx( mbedtls_md_context_t *ctx, const mbedtls_md_info_t *md_info ) MBEDTLS_DEPRECATED;
147#undef MBEDTLS_DEPRECATED
148#endif /* MBEDTLS_DEPRECATED_REMOVED */
Manuel Pégourié-Gonnard147fa092015-03-25 16:43:14 +0100149
Paul Bakker84bbeb52014-07-01 14:53:22 +0200150/**
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100151 * \brief Select MD to use and allocate internal structures.
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200152 * Should be called after mbedtls_md_init() or mbedtls_md_free().
153 * Makes it necessary to call mbedtls_md_free() later.
Paul Bakker562535d2011-01-20 16:42:01 +0000154 *
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100155 * \param ctx Context to set up.
156 * \param md_info Message digest to use.
157 * \param hmac 0 to save some meory is HMAC will not be use,
158 * non-zero is HMAC is going to be used with this context.
Paul Bakker562535d2011-01-20 16:42:01 +0000159 *
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100160 * \returns \c 0 on success,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200161 * \c MBEDTLS_ERR_MD_BAD_INPUT_DATA on parameter failure,
162 * \c MBEDTLS_ERR_MD_ALLOC_FAILED memory allocation failure.
Paul Bakker562535d2011-01-20 16:42:01 +0000163 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200164int mbedtls_md_setup( mbedtls_md_context_t *ctx, const mbedtls_md_info_t *md_info, int hmac );
Paul Bakker562535d2011-01-20 16:42:01 +0000165
166/**
Paul Bakker17373852011-01-06 14:20:01 +0000167 * \brief Returns the size of the message digest output.
168 *
169 * \param md_info message digest info
170 *
Manuel Pégourié-Gonnardb8186a52015-06-18 14:58:58 +0200171 * \return size of the message digest output in bytes.
Paul Bakker17373852011-01-06 14:20:01 +0000172 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200173unsigned char mbedtls_md_get_size( const mbedtls_md_info_t *md_info );
Paul Bakker17373852011-01-06 14:20:01 +0000174
175/**
176 * \brief Returns the type of the message digest output.
177 *
178 * \param md_info message digest info
179 *
180 * \return type of the message digest output.
181 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200182mbedtls_md_type_t mbedtls_md_get_type( const mbedtls_md_info_t *md_info );
Paul Bakker17373852011-01-06 14:20:01 +0000183
184/**
185 * \brief Returns the name of the message digest output.
186 *
187 * \param md_info message digest info
188 *
189 * \return name of the message digest output.
190 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200191const char *mbedtls_md_get_name( const mbedtls_md_info_t *md_info );
Paul Bakker17373852011-01-06 14:20:01 +0000192
193/**
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100194 * \brief Prepare the context to digest a new message.
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200195 * Generally called after mbedtls_md_setup() or mbedtls_md_finish().
196 * Followed by mbedtls_md_update().
Paul Bakker17373852011-01-06 14:20:01 +0000197 *
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100198 * \param ctx generic message digest context.
Paul Bakker17373852011-01-06 14:20:01 +0000199 *
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200200 * \returns 0 on success, MBEDTLS_ERR_MD_BAD_INPUT_DATA if parameter
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100201 * verification fails.
Paul Bakker17373852011-01-06 14:20:01 +0000202 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200203int mbedtls_md_starts( mbedtls_md_context_t *ctx );
Paul Bakker17373852011-01-06 14:20:01 +0000204
205/**
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100206 * \brief Generic message digest process buffer
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200207 * Called between mbedtls_md_starts() and mbedtls_md_finish().
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100208 * May be called repeatedly.
Paul Bakker17373852011-01-06 14:20:01 +0000209 *
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100210 * \param ctx Generic message digest context
211 * \param input buffer holding the datal
212 * \param ilen length of the input data
Paul Bakker17373852011-01-06 14:20:01 +0000213 *
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200214 * \returns 0 on success, MBEDTLS_ERR_MD_BAD_INPUT_DATA if parameter
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100215 * verification fails.
Paul Bakker17373852011-01-06 14:20:01 +0000216 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200217int mbedtls_md_update( mbedtls_md_context_t *ctx, const unsigned char *input, size_t ilen );
Paul Bakker17373852011-01-06 14:20:01 +0000218
219/**
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100220 * \brief Generic message digest final digest
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200221 * Called after mbedtls_md_update().
222 * Usually followed by mbedtls_md_free() or mbedtls_md_starts().
Paul Bakker17373852011-01-06 14:20:01 +0000223 *
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100224 * \param ctx Generic message digest context
225 * \param output Generic message digest checksum result
Paul Bakker17373852011-01-06 14:20:01 +0000226 *
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200227 * \returns 0 on success, MBEDTLS_ERR_MD_BAD_INPUT_DATA if parameter
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100228 * verification fails.
Paul Bakker17373852011-01-06 14:20:01 +0000229 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200230int mbedtls_md_finish( mbedtls_md_context_t *ctx, unsigned char *output );
Paul Bakker17373852011-01-06 14:20:01 +0000231
232/**
Paul Bakker17373852011-01-06 14:20:01 +0000233 * \brief Output = message_digest( input buffer )
234 *
235 * \param md_info message digest info
236 * \param input buffer holding the data
237 * \param ilen length of the input data
238 * \param output Generic message digest checksum result
239 *
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200240 * \returns 0 on success, MBEDTLS_ERR_MD_BAD_INPUT_DATA if parameter
Paul Bakker9c021ad2011-06-09 15:55:11 +0000241 * verification fails.
Paul Bakker17373852011-01-06 14:20:01 +0000242 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200243int mbedtls_md( const mbedtls_md_info_t *md_info, const unsigned char *input, size_t ilen,
Paul Bakker17373852011-01-06 14:20:01 +0000244 unsigned char *output );
245
Manuel Pégourié-Gonnardbfffa902015-05-28 14:44:00 +0200246#if defined(MBEDTLS_FS_IO)
Paul Bakker17373852011-01-06 14:20:01 +0000247/**
248 * \brief Output = message_digest( file contents )
249 *
250 * \param md_info message digest info
251 * \param path input file name
252 * \param output generic message digest checksum result
253 *
Manuel Pégourié-Gonnard932e3932015-04-03 16:37:14 +0200254 * \return 0 if successful,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200255 * MBEDTLS_ERR_MD_FILE_IO_ERROR if file input failed,
256 * MBEDTLS_ERR_MD_BAD_INPUT_DATA if md_info was NULL.
Paul Bakker17373852011-01-06 14:20:01 +0000257 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200258int mbedtls_md_file( const mbedtls_md_info_t *md_info, const char *path,
Manuel Pégourié-Gonnardbfffa902015-05-28 14:44:00 +0200259 unsigned char *output );
260#endif /* MBEDTLS_FS_IO */
Paul Bakker17373852011-01-06 14:20:01 +0000261
262/**
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100263 * \brief Set HMAC key and prepare to authenticate a new message.
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200264 * Usually called after mbedtls_md_setup() or mbedtls_md_hmac_finish().
Paul Bakker17373852011-01-06 14:20:01 +0000265 *
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100266 * \param ctx HMAC context
267 * \param key HMAC secret key
Manuel Pégourié-Gonnardb8186a52015-06-18 14:58:58 +0200268 * \param keylen length of the HMAC key in bytes
Paul Bakker17373852011-01-06 14:20:01 +0000269 *
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200270 * \returns 0 on success, MBEDTLS_ERR_MD_BAD_INPUT_DATA if parameter
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100271 * verification fails.
Paul Bakker17373852011-01-06 14:20:01 +0000272 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200273int mbedtls_md_hmac_starts( mbedtls_md_context_t *ctx, const unsigned char *key,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200274 size_t keylen );
Paul Bakker17373852011-01-06 14:20:01 +0000275
276/**
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100277 * \brief Generic HMAC process buffer.
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200278 * Called between mbedtls_md_hmac_starts() or mbedtls_md_hmac_reset()
279 * and mbedtls_md_hmac_finish().
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100280 * May be called repeatedly.
Paul Bakker17373852011-01-06 14:20:01 +0000281 *
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100282 * \param ctx HMAC context
283 * \param input buffer holding the data
284 * \param ilen length of the input data
Paul Bakker17373852011-01-06 14:20:01 +0000285 *
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200286 * \returns 0 on success, MBEDTLS_ERR_MD_BAD_INPUT_DATA if parameter
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100287 * verification fails.
Paul Bakker17373852011-01-06 14:20:01 +0000288 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200289int mbedtls_md_hmac_update( mbedtls_md_context_t *ctx, const unsigned char *input,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200290 size_t ilen );
Paul Bakker17373852011-01-06 14:20:01 +0000291
292/**
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100293 * \brief Output HMAC.
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200294 * Called after mbedtls_md_hmac_update().
295 * Usually followed my mbedtls_md_hmac_reset(), mbedtls_md_hmac_starts(),
296 * or mbedtls_md_free().
Paul Bakker17373852011-01-06 14:20:01 +0000297 *
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100298 * \param ctx HMAC context
299 * \param output Generic HMAC checksum result
Paul Bakker17373852011-01-06 14:20:01 +0000300 *
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200301 * \returns 0 on success, MBEDTLS_ERR_MD_BAD_INPUT_DATA if parameter
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100302 * verification fails.
Paul Bakker17373852011-01-06 14:20:01 +0000303 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200304int mbedtls_md_hmac_finish( mbedtls_md_context_t *ctx, unsigned char *output);
Paul Bakker17373852011-01-06 14:20:01 +0000305
306/**
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100307 * \brief Prepare to authenticate a new message with the same key.
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200308 * Called after mbedtls_md_hmac_finish() and before mbedtls_md_hmac_update().
Paul Bakker17373852011-01-06 14:20:01 +0000309 *
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100310 * \param ctx HMAC context to be reset
Paul Bakker17373852011-01-06 14:20:01 +0000311 *
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200312 * \returns 0 on success, MBEDTLS_ERR_MD_BAD_INPUT_DATA if parameter
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100313 * verification fails.
Paul Bakker17373852011-01-06 14:20:01 +0000314 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200315int mbedtls_md_hmac_reset( mbedtls_md_context_t *ctx );
Paul Bakker17373852011-01-06 14:20:01 +0000316
317/**
318 * \brief Output = Generic_HMAC( hmac key, input buffer )
319 *
320 * \param md_info message digest info
321 * \param key HMAC secret key
Manuel Pégourié-Gonnardb8186a52015-06-18 14:58:58 +0200322 * \param keylen length of the HMAC key in bytes
Paul Bakker17373852011-01-06 14:20:01 +0000323 * \param input buffer holding the data
324 * \param ilen length of the input data
325 * \param output Generic HMAC-result
326 *
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200327 * \returns 0 on success, MBEDTLS_ERR_MD_BAD_INPUT_DATA if parameter
Paul Bakker9c021ad2011-06-09 15:55:11 +0000328 * verification fails.
Paul Bakker17373852011-01-06 14:20:01 +0000329 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200330int mbedtls_md_hmac( const mbedtls_md_info_t *md_info, const unsigned char *key, size_t keylen,
Paul Bakker23986e52011-04-24 08:57:21 +0000331 const unsigned char *input, size_t ilen,
Paul Bakker17373852011-01-06 14:20:01 +0000332 unsigned char *output );
333
Paul Bakker1bd3ae82013-03-13 10:26:44 +0100334/* Internal use */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200335int mbedtls_md_process( mbedtls_md_context_t *ctx, const unsigned char *data );
Paul Bakker1bd3ae82013-03-13 10:26:44 +0100336
Paul Bakker17373852011-01-06 14:20:01 +0000337#ifdef __cplusplus
338}
339#endif
340
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200341#endif /* MBEDTLS_MD_H */