blob: 19df9e89524e956b1e1a05ea9f9aa58ede1819a6 [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
Manuel Pégourié-Gonnard20af64d2015-07-07 18:33:39 +020031#if ( defined(__ARMCC_VERSION) || defined(_MSC_VER) ) && !defined(inline)
Paul Bakker569df2c2011-06-21 07:48:07 +000032#define inline __inline
Manuel Pégourié-Gonnard20af64d2015-07-07 18:33:39 +020033#endif
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.
Manuel Pégourié-Gonnardac50fc52015-08-10 13:07:09 +0200157 * \param hmac 0 to save some memory if HMAC will not be used,
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100158 * 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/**
Manuel Pégourié-Gonnard052a6c92015-07-06 16:06:02 +0200167 * \brief Clone the state of an MD context
168 *
169 * \note The two contexts must have been setup to the same type
170 * (cloning from SHA-256 to SHA-512 make no sense).
171 *
172 * \warning Only clones the MD state, not the HMAC state! (for now)
173 *
174 * \param dst The destination context
175 * \param src The context to be cloned
176 *
177 * \return \c 0 on success,
178 * \c MBEDTLS_ERR_MD_BAD_INPUT_DATA on parameter failure.
179 */
180int mbedtls_md_clone( mbedtls_md_context_t *dst,
181 const mbedtls_md_context_t *src );
182
183/**
Paul Bakker17373852011-01-06 14:20:01 +0000184 * \brief Returns the size of the message digest output.
185 *
186 * \param md_info message digest info
187 *
Manuel Pégourié-Gonnardb8186a52015-06-18 14:58:58 +0200188 * \return size of the message digest output in bytes.
Paul Bakker17373852011-01-06 14:20:01 +0000189 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200190unsigned char mbedtls_md_get_size( const mbedtls_md_info_t *md_info );
Paul Bakker17373852011-01-06 14:20:01 +0000191
192/**
193 * \brief Returns the type of the message digest output.
194 *
195 * \param md_info message digest info
196 *
197 * \return type of the message digest output.
198 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200199mbedtls_md_type_t mbedtls_md_get_type( const mbedtls_md_info_t *md_info );
Paul Bakker17373852011-01-06 14:20:01 +0000200
201/**
202 * \brief Returns the name of the message digest output.
203 *
204 * \param md_info message digest info
205 *
206 * \return name of the message digest output.
207 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200208const char *mbedtls_md_get_name( const mbedtls_md_info_t *md_info );
Paul Bakker17373852011-01-06 14:20:01 +0000209
210/**
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100211 * \brief Prepare the context to digest a new message.
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200212 * Generally called after mbedtls_md_setup() or mbedtls_md_finish().
213 * Followed by mbedtls_md_update().
Paul Bakker17373852011-01-06 14:20:01 +0000214 *
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100215 * \param ctx generic message digest context.
Paul Bakker17373852011-01-06 14:20:01 +0000216 *
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200217 * \returns 0 on success, MBEDTLS_ERR_MD_BAD_INPUT_DATA if parameter
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100218 * verification fails.
Paul Bakker17373852011-01-06 14:20:01 +0000219 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200220int mbedtls_md_starts( mbedtls_md_context_t *ctx );
Paul Bakker17373852011-01-06 14:20:01 +0000221
222/**
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100223 * \brief Generic message digest process buffer
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200224 * Called between mbedtls_md_starts() and mbedtls_md_finish().
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100225 * May be called repeatedly.
Paul Bakker17373852011-01-06 14:20:01 +0000226 *
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100227 * \param ctx Generic message digest context
228 * \param input buffer holding the datal
229 * \param ilen length of the input data
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_update( mbedtls_md_context_t *ctx, const unsigned char *input, size_t ilen );
Paul Bakker17373852011-01-06 14:20:01 +0000235
236/**
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100237 * \brief Generic message digest final digest
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200238 * Called after mbedtls_md_update().
239 * Usually followed by mbedtls_md_free() or mbedtls_md_starts().
Paul Bakker17373852011-01-06 14:20:01 +0000240 *
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100241 * \param ctx Generic message digest context
242 * \param output Generic message digest checksum result
Paul Bakker17373852011-01-06 14:20:01 +0000243 *
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200244 * \returns 0 on success, MBEDTLS_ERR_MD_BAD_INPUT_DATA if parameter
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100245 * verification fails.
Paul Bakker17373852011-01-06 14:20:01 +0000246 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200247int mbedtls_md_finish( mbedtls_md_context_t *ctx, unsigned char *output );
Paul Bakker17373852011-01-06 14:20:01 +0000248
249/**
Paul Bakker17373852011-01-06 14:20:01 +0000250 * \brief Output = message_digest( input buffer )
251 *
252 * \param md_info message digest info
253 * \param input buffer holding the data
254 * \param ilen length of the input data
255 * \param output Generic message digest checksum result
256 *
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200257 * \returns 0 on success, MBEDTLS_ERR_MD_BAD_INPUT_DATA if parameter
Paul Bakker9c021ad2011-06-09 15:55:11 +0000258 * verification fails.
Paul Bakker17373852011-01-06 14:20:01 +0000259 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200260int mbedtls_md( const mbedtls_md_info_t *md_info, const unsigned char *input, size_t ilen,
Paul Bakker17373852011-01-06 14:20:01 +0000261 unsigned char *output );
262
Manuel Pégourié-Gonnardbfffa902015-05-28 14:44:00 +0200263#if defined(MBEDTLS_FS_IO)
Paul Bakker17373852011-01-06 14:20:01 +0000264/**
265 * \brief Output = message_digest( file contents )
266 *
267 * \param md_info message digest info
268 * \param path input file name
269 * \param output generic message digest checksum result
270 *
Manuel Pégourié-Gonnard932e3932015-04-03 16:37:14 +0200271 * \return 0 if successful,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200272 * MBEDTLS_ERR_MD_FILE_IO_ERROR if file input failed,
273 * MBEDTLS_ERR_MD_BAD_INPUT_DATA if md_info was NULL.
Paul Bakker17373852011-01-06 14:20:01 +0000274 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200275int mbedtls_md_file( const mbedtls_md_info_t *md_info, const char *path,
Manuel Pégourié-Gonnardbfffa902015-05-28 14:44:00 +0200276 unsigned char *output );
277#endif /* MBEDTLS_FS_IO */
Paul Bakker17373852011-01-06 14:20:01 +0000278
279/**
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100280 * \brief Set HMAC key and prepare to authenticate a new message.
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200281 * Usually called after mbedtls_md_setup() or mbedtls_md_hmac_finish().
Paul Bakker17373852011-01-06 14:20:01 +0000282 *
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100283 * \param ctx HMAC context
284 * \param key HMAC secret key
Manuel Pégourié-Gonnardb8186a52015-06-18 14:58:58 +0200285 * \param keylen length of the HMAC key in bytes
Paul Bakker17373852011-01-06 14:20:01 +0000286 *
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200287 * \returns 0 on success, MBEDTLS_ERR_MD_BAD_INPUT_DATA if parameter
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100288 * verification fails.
Paul Bakker17373852011-01-06 14:20:01 +0000289 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200290int mbedtls_md_hmac_starts( mbedtls_md_context_t *ctx, const unsigned char *key,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200291 size_t keylen );
Paul Bakker17373852011-01-06 14:20:01 +0000292
293/**
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100294 * \brief Generic HMAC process buffer.
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200295 * Called between mbedtls_md_hmac_starts() or mbedtls_md_hmac_reset()
296 * and mbedtls_md_hmac_finish().
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100297 * May be called repeatedly.
Paul Bakker17373852011-01-06 14:20:01 +0000298 *
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100299 * \param ctx HMAC context
300 * \param input buffer holding the data
301 * \param ilen length of the input data
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_update( mbedtls_md_context_t *ctx, const unsigned char *input,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200307 size_t ilen );
Paul Bakker17373852011-01-06 14:20:01 +0000308
309/**
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100310 * \brief Output HMAC.
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200311 * Called after mbedtls_md_hmac_update().
312 * Usually followed my mbedtls_md_hmac_reset(), mbedtls_md_hmac_starts(),
313 * or mbedtls_md_free().
Paul Bakker17373852011-01-06 14:20:01 +0000314 *
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100315 * \param ctx HMAC context
316 * \param output Generic HMAC checksum result
Paul Bakker17373852011-01-06 14:20:01 +0000317 *
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200318 * \returns 0 on success, MBEDTLS_ERR_MD_BAD_INPUT_DATA if parameter
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100319 * verification fails.
Paul Bakker17373852011-01-06 14:20:01 +0000320 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200321int mbedtls_md_hmac_finish( mbedtls_md_context_t *ctx, unsigned char *output);
Paul Bakker17373852011-01-06 14:20:01 +0000322
323/**
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100324 * \brief Prepare to authenticate a new message with the same key.
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200325 * Called after mbedtls_md_hmac_finish() and before mbedtls_md_hmac_update().
Paul Bakker17373852011-01-06 14:20:01 +0000326 *
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100327 * \param ctx HMAC context to be reset
Paul Bakker17373852011-01-06 14:20:01 +0000328 *
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200329 * \returns 0 on success, MBEDTLS_ERR_MD_BAD_INPUT_DATA if parameter
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100330 * verification fails.
Paul Bakker17373852011-01-06 14:20:01 +0000331 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200332int mbedtls_md_hmac_reset( mbedtls_md_context_t *ctx );
Paul Bakker17373852011-01-06 14:20:01 +0000333
334/**
335 * \brief Output = Generic_HMAC( hmac key, input buffer )
336 *
337 * \param md_info message digest info
338 * \param key HMAC secret key
Manuel Pégourié-Gonnardb8186a52015-06-18 14:58:58 +0200339 * \param keylen length of the HMAC key in bytes
Paul Bakker17373852011-01-06 14:20:01 +0000340 * \param input buffer holding the data
341 * \param ilen length of the input data
342 * \param output Generic HMAC-result
343 *
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200344 * \returns 0 on success, MBEDTLS_ERR_MD_BAD_INPUT_DATA if parameter
Paul Bakker9c021ad2011-06-09 15:55:11 +0000345 * verification fails.
Paul Bakker17373852011-01-06 14:20:01 +0000346 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200347int mbedtls_md_hmac( const mbedtls_md_info_t *md_info, const unsigned char *key, size_t keylen,
Paul Bakker23986e52011-04-24 08:57:21 +0000348 const unsigned char *input, size_t ilen,
Paul Bakker17373852011-01-06 14:20:01 +0000349 unsigned char *output );
350
Paul Bakker1bd3ae82013-03-13 10:26:44 +0100351/* Internal use */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200352int mbedtls_md_process( mbedtls_md_context_t *ctx, const unsigned char *data );
Paul Bakker1bd3ae82013-03-13 10:26:44 +0100353
Paul Bakker17373852011-01-06 14:20:01 +0000354#ifdef __cplusplus
355}
356#endif
357
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200358#endif /* MBEDTLS_MD_H */