blob: b48877acb5cfdff6b1a3fdda9aaca45f236d270e [file] [log] [blame]
Paul Bakker17373852011-01-06 14:20:01 +00001/**
Simon Butchera02fe7c2016-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 Eldor00cb3af2017-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
Hanno Becker15e49512017-09-25 14:53:51 +010045/**
46 * \brief Enumeration of supported message digests
47 *
48 * \warning MD2, MD4, MD5 and SHA-1 are considered weak message digests and
49 * their use constitutes a security risk. We recommend considering
50 * stronger message digests instead.
51 *
52 */
Paul Bakker17373852011-01-06 14:20:01 +000053typedef enum {
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020054 MBEDTLS_MD_NONE=0,
55 MBEDTLS_MD_MD2,
56 MBEDTLS_MD_MD4,
57 MBEDTLS_MD_MD5,
58 MBEDTLS_MD_SHA1,
59 MBEDTLS_MD_SHA224,
60 MBEDTLS_MD_SHA256,
61 MBEDTLS_MD_SHA384,
62 MBEDTLS_MD_SHA512,
63 MBEDTLS_MD_RIPEMD160,
64} mbedtls_md_type_t;
Paul Bakker17373852011-01-06 14:20:01 +000065
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020066#if defined(MBEDTLS_SHA512_C)
67#define MBEDTLS_MD_MAX_SIZE 64 /* longest known is SHA512 */
Paul Bakker7db01092013-09-10 11:10:57 +020068#else
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020069#define MBEDTLS_MD_MAX_SIZE 32 /* longest known is SHA256 or less */
Paul Bakker7db01092013-09-10 11:10:57 +020070#endif
Paul Bakker1b57b062011-01-06 15:48:19 +000071
Paul Bakker17373852011-01-06 14:20:01 +000072/**
Manuel Pégourié-Gonnard50518f42015-05-26 11:04:15 +020073 * Opaque struct defined in md_internal.h
Paul Bakker17373852011-01-06 14:20:01 +000074 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020075typedef struct mbedtls_md_info_t mbedtls_md_info_t;
Paul Bakker17373852011-01-06 14:20:01 +000076
77/**
78 * Generic message digest context.
79 */
80typedef struct {
81 /** Information about the associated message digest */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020082 const mbedtls_md_info_t *md_info;
Paul Bakker17373852011-01-06 14:20:01 +000083
84 /** Digest-specific context */
85 void *md_ctx;
Manuel Pégourié-Gonnard8379a822015-03-24 16:48:22 +010086
Manuel Pégourié-Gonnarddfb3dc82015-03-25 11:49:07 +010087 /** HMAC part of the context */
88 void *hmac_ctx;
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020089} mbedtls_md_context_t;
Paul Bakker17373852011-01-06 14:20:01 +000090
Paul Bakker17373852011-01-06 14:20:01 +000091/**
Paul Bakker72f62662011-01-16 21:27:44 +000092 * \brief Returns the list of digests supported by the generic digest module.
93 *
94 * \return a statically allocated array of digests, the last entry
95 * is 0.
96 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020097const int *mbedtls_md_list( void );
Paul Bakker72f62662011-01-16 21:27:44 +000098
99/**
Paul Bakker17373852011-01-06 14:20:01 +0000100 * \brief Returns the message digest information associated with the
101 * given digest name.
102 *
Paul Bakker23986e52011-04-24 08:57:21 +0000103 * \param md_name Name of the digest to search for.
Paul Bakker17373852011-01-06 14:20:01 +0000104 *
105 * \return The message digest information associated with md_name or
106 * NULL if not found.
107 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200108const mbedtls_md_info_t *mbedtls_md_info_from_string( const char *md_name );
Paul Bakker17373852011-01-06 14:20:01 +0000109
110/**
111 * \brief Returns the message digest information associated with the
112 * given digest type.
113 *
114 * \param md_type type of digest to search for.
115 *
116 * \return The message digest information associated with md_type or
117 * NULL if not found.
118 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200119const mbedtls_md_info_t *mbedtls_md_info_from_type( mbedtls_md_type_t md_type );
Paul Bakker17373852011-01-06 14:20:01 +0000120
121/**
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100122 * \brief Initialize a md_context (as NONE)
123 * This should always be called first.
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200124 * Prepares the context for mbedtls_md_setup() or mbedtls_md_free().
Paul Bakker84bbeb52014-07-01 14:53:22 +0200125 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200126void mbedtls_md_init( mbedtls_md_context_t *ctx );
Paul Bakker84bbeb52014-07-01 14:53:22 +0200127
128/**
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100129 * \brief Free and clear the internal structures of ctx.
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200130 * Can be called at any time after mbedtls_md_init().
131 * Mandatory once mbedtls_md_setup() has been called.
Paul Bakker84bbeb52014-07-01 14:53:22 +0200132 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200133void mbedtls_md_free( mbedtls_md_context_t *ctx );
Paul Bakker84bbeb52014-07-01 14:53:22 +0200134
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200135#if ! defined(MBEDTLS_DEPRECATED_REMOVED)
136#if defined(MBEDTLS_DEPRECATED_WARNING)
137#define MBEDTLS_DEPRECATED __attribute__((deprecated))
Manuel Pégourié-Gonnard147fa092015-03-25 16:43:14 +0100138#else
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200139#define MBEDTLS_DEPRECATED
Manuel Pégourié-Gonnard147fa092015-03-25 16:43:14 +0100140#endif
141/**
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100142 * \brief Select MD to use and allocate internal structures.
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200143 * Should be called after mbedtls_md_init() or mbedtls_md_free().
144 * Makes it necessary to call mbedtls_md_free() later.
Manuel Pégourié-Gonnard147fa092015-03-25 16:43:14 +0100145 *
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200146 * \deprecated Superseded by mbedtls_md_setup() in 2.0.0
Manuel Pégourié-Gonnard147fa092015-03-25 16:43:14 +0100147 *
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100148 * \param ctx Context to set up.
149 * \param md_info Message digest to use.
Manuel Pégourié-Gonnard147fa092015-03-25 16:43:14 +0100150 *
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100151 * \returns \c 0 on success,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200152 * \c MBEDTLS_ERR_MD_BAD_INPUT_DATA on parameter failure,
153 * \c MBEDTLS_ERR_MD_ALLOC_FAILED memory allocation failure.
Manuel Pégourié-Gonnard147fa092015-03-25 16:43:14 +0100154 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200155int mbedtls_md_init_ctx( mbedtls_md_context_t *ctx, const mbedtls_md_info_t *md_info ) MBEDTLS_DEPRECATED;
156#undef MBEDTLS_DEPRECATED
157#endif /* MBEDTLS_DEPRECATED_REMOVED */
Manuel Pégourié-Gonnard147fa092015-03-25 16:43:14 +0100158
Paul Bakker84bbeb52014-07-01 14:53:22 +0200159/**
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100160 * \brief Select MD to use and allocate internal structures.
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200161 * Should be called after mbedtls_md_init() or mbedtls_md_free().
162 * Makes it necessary to call mbedtls_md_free() later.
Paul Bakker562535d2011-01-20 16:42:01 +0000163 *
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100164 * \param ctx Context to set up.
165 * \param md_info Message digest to use.
Manuel Pégourié-Gonnardac50fc52015-08-10 13:07:09 +0200166 * \param hmac 0 to save some memory if HMAC will not be used,
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100167 * non-zero is HMAC is going to be used with this context.
Paul Bakker562535d2011-01-20 16:42:01 +0000168 *
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100169 * \returns \c 0 on success,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200170 * \c MBEDTLS_ERR_MD_BAD_INPUT_DATA on parameter failure,
171 * \c MBEDTLS_ERR_MD_ALLOC_FAILED memory allocation failure.
Paul Bakker562535d2011-01-20 16:42:01 +0000172 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200173int mbedtls_md_setup( mbedtls_md_context_t *ctx, const mbedtls_md_info_t *md_info, int hmac );
Paul Bakker562535d2011-01-20 16:42:01 +0000174
175/**
Manuel Pégourié-Gonnard052a6c92015-07-06 16:06:02 +0200176 * \brief Clone the state of an MD context
177 *
178 * \note The two contexts must have been setup to the same type
179 * (cloning from SHA-256 to SHA-512 make no sense).
180 *
181 * \warning Only clones the MD state, not the HMAC state! (for now)
182 *
183 * \param dst The destination context
184 * \param src The context to be cloned
185 *
186 * \return \c 0 on success,
187 * \c MBEDTLS_ERR_MD_BAD_INPUT_DATA on parameter failure.
188 */
189int mbedtls_md_clone( mbedtls_md_context_t *dst,
190 const mbedtls_md_context_t *src );
191
192/**
Paul Bakker17373852011-01-06 14:20:01 +0000193 * \brief Returns the size of the message digest output.
194 *
195 * \param md_info message digest info
196 *
Manuel Pégourié-Gonnardb8186a52015-06-18 14:58:58 +0200197 * \return size of the message digest output in bytes.
Paul Bakker17373852011-01-06 14:20:01 +0000198 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200199unsigned char mbedtls_md_get_size( const mbedtls_md_info_t *md_info );
Paul Bakker17373852011-01-06 14:20:01 +0000200
201/**
202 * \brief Returns the type of the message digest output.
203 *
204 * \param md_info message digest info
205 *
206 * \return type of the message digest output.
207 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200208mbedtls_md_type_t mbedtls_md_get_type( const mbedtls_md_info_t *md_info );
Paul Bakker17373852011-01-06 14:20:01 +0000209
210/**
211 * \brief Returns the name of the message digest output.
212 *
213 * \param md_info message digest info
214 *
215 * \return name of the message digest output.
216 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200217const char *mbedtls_md_get_name( const mbedtls_md_info_t *md_info );
Paul Bakker17373852011-01-06 14:20:01 +0000218
219/**
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100220 * \brief Prepare the context to digest a new message.
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200221 * Generally called after mbedtls_md_setup() or mbedtls_md_finish().
222 * Followed by mbedtls_md_update().
Paul Bakker17373852011-01-06 14:20:01 +0000223 *
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100224 * \param ctx generic message digest context.
Paul Bakker17373852011-01-06 14:20:01 +0000225 *
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200226 * \returns 0 on success, MBEDTLS_ERR_MD_BAD_INPUT_DATA if parameter
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100227 * verification fails.
Paul Bakker17373852011-01-06 14:20:01 +0000228 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200229int mbedtls_md_starts( mbedtls_md_context_t *ctx );
Paul Bakker17373852011-01-06 14:20:01 +0000230
231/**
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100232 * \brief Generic message digest process buffer
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200233 * Called between mbedtls_md_starts() and mbedtls_md_finish().
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100234 * May be called repeatedly.
Paul Bakker17373852011-01-06 14:20:01 +0000235 *
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100236 * \param ctx Generic message digest context
237 * \param input buffer holding the datal
238 * \param ilen length of the input data
Paul Bakker17373852011-01-06 14:20:01 +0000239 *
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200240 * \returns 0 on success, MBEDTLS_ERR_MD_BAD_INPUT_DATA if parameter
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100241 * verification fails.
Paul Bakker17373852011-01-06 14:20:01 +0000242 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200243int mbedtls_md_update( mbedtls_md_context_t *ctx, const unsigned char *input, size_t ilen );
Paul Bakker17373852011-01-06 14:20:01 +0000244
245/**
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100246 * \brief Generic message digest final digest
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200247 * Called after mbedtls_md_update().
248 * Usually followed by mbedtls_md_free() or mbedtls_md_starts().
Paul Bakker17373852011-01-06 14:20:01 +0000249 *
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100250 * \param ctx Generic message digest context
251 * \param output Generic message digest checksum result
Paul Bakker17373852011-01-06 14:20:01 +0000252 *
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200253 * \returns 0 on success, MBEDTLS_ERR_MD_BAD_INPUT_DATA if parameter
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100254 * verification fails.
Paul Bakker17373852011-01-06 14:20:01 +0000255 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200256int mbedtls_md_finish( mbedtls_md_context_t *ctx, unsigned char *output );
Paul Bakker17373852011-01-06 14:20:01 +0000257
258/**
Paul Bakker17373852011-01-06 14:20:01 +0000259 * \brief Output = message_digest( input buffer )
260 *
261 * \param md_info message digest info
262 * \param input buffer holding the data
263 * \param ilen length of the input data
264 * \param output Generic message digest checksum result
265 *
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200266 * \returns 0 on success, MBEDTLS_ERR_MD_BAD_INPUT_DATA if parameter
Paul Bakker9c021ad2011-06-09 15:55:11 +0000267 * verification fails.
Paul Bakker17373852011-01-06 14:20:01 +0000268 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200269int mbedtls_md( const mbedtls_md_info_t *md_info, const unsigned char *input, size_t ilen,
Paul Bakker17373852011-01-06 14:20:01 +0000270 unsigned char *output );
271
Manuel Pégourié-Gonnardbfffa902015-05-28 14:44:00 +0200272#if defined(MBEDTLS_FS_IO)
Paul Bakker17373852011-01-06 14:20:01 +0000273/**
274 * \brief Output = message_digest( file contents )
275 *
276 * \param md_info message digest info
277 * \param path input file name
278 * \param output generic message digest checksum result
279 *
Manuel Pégourié-Gonnard932e3932015-04-03 16:37:14 +0200280 * \return 0 if successful,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200281 * MBEDTLS_ERR_MD_FILE_IO_ERROR if file input failed,
282 * MBEDTLS_ERR_MD_BAD_INPUT_DATA if md_info was NULL.
Paul Bakker17373852011-01-06 14:20:01 +0000283 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200284int mbedtls_md_file( const mbedtls_md_info_t *md_info, const char *path,
Manuel Pégourié-Gonnardbfffa902015-05-28 14:44:00 +0200285 unsigned char *output );
286#endif /* MBEDTLS_FS_IO */
Paul Bakker17373852011-01-06 14:20:01 +0000287
288/**
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100289 * \brief Set HMAC key and prepare to authenticate a new message.
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200290 * Usually called after mbedtls_md_setup() or mbedtls_md_hmac_finish().
Paul Bakker17373852011-01-06 14:20:01 +0000291 *
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100292 * \param ctx HMAC context
293 * \param key HMAC secret key
Manuel Pégourié-Gonnardb8186a52015-06-18 14:58:58 +0200294 * \param keylen length of the HMAC key in bytes
Paul Bakker17373852011-01-06 14:20:01 +0000295 *
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200296 * \returns 0 on success, MBEDTLS_ERR_MD_BAD_INPUT_DATA if parameter
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100297 * verification fails.
Paul Bakker17373852011-01-06 14:20:01 +0000298 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200299int mbedtls_md_hmac_starts( mbedtls_md_context_t *ctx, const unsigned char *key,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200300 size_t keylen );
Paul Bakker17373852011-01-06 14:20:01 +0000301
302/**
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100303 * \brief Generic HMAC process buffer.
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200304 * Called between mbedtls_md_hmac_starts() or mbedtls_md_hmac_reset()
305 * and mbedtls_md_hmac_finish().
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100306 * May be called repeatedly.
Paul Bakker17373852011-01-06 14:20:01 +0000307 *
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100308 * \param ctx HMAC context
309 * \param input buffer holding the data
310 * \param ilen length of the input data
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_update( mbedtls_md_context_t *ctx, const unsigned char *input,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200316 size_t ilen );
Paul Bakker17373852011-01-06 14:20:01 +0000317
318/**
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100319 * \brief Output HMAC.
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200320 * Called after mbedtls_md_hmac_update().
321 * Usually followed my mbedtls_md_hmac_reset(), mbedtls_md_hmac_starts(),
322 * or mbedtls_md_free().
Paul Bakker17373852011-01-06 14:20:01 +0000323 *
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100324 * \param ctx HMAC context
325 * \param output Generic HMAC checksum result
Paul Bakker17373852011-01-06 14:20:01 +0000326 *
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200327 * \returns 0 on success, MBEDTLS_ERR_MD_BAD_INPUT_DATA if parameter
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100328 * verification fails.
Paul Bakker17373852011-01-06 14:20:01 +0000329 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200330int mbedtls_md_hmac_finish( mbedtls_md_context_t *ctx, unsigned char *output);
Paul Bakker17373852011-01-06 14:20:01 +0000331
332/**
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100333 * \brief Prepare to authenticate a new message with the same key.
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200334 * Called after mbedtls_md_hmac_finish() and before mbedtls_md_hmac_update().
Paul Bakker17373852011-01-06 14:20:01 +0000335 *
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100336 * \param ctx HMAC context to be reset
Paul Bakker17373852011-01-06 14:20:01 +0000337 *
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200338 * \returns 0 on success, MBEDTLS_ERR_MD_BAD_INPUT_DATA if parameter
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100339 * verification fails.
Paul Bakker17373852011-01-06 14:20:01 +0000340 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200341int mbedtls_md_hmac_reset( mbedtls_md_context_t *ctx );
Paul Bakker17373852011-01-06 14:20:01 +0000342
343/**
344 * \brief Output = Generic_HMAC( hmac key, input buffer )
345 *
346 * \param md_info message digest info
347 * \param key HMAC secret key
Manuel Pégourié-Gonnardb8186a52015-06-18 14:58:58 +0200348 * \param keylen length of the HMAC key in bytes
Paul Bakker17373852011-01-06 14:20:01 +0000349 * \param input buffer holding the data
350 * \param ilen length of the input data
351 * \param output Generic HMAC-result
352 *
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200353 * \returns 0 on success, MBEDTLS_ERR_MD_BAD_INPUT_DATA if parameter
Paul Bakker9c021ad2011-06-09 15:55:11 +0000354 * verification fails.
Paul Bakker17373852011-01-06 14:20:01 +0000355 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200356int mbedtls_md_hmac( const mbedtls_md_info_t *md_info, const unsigned char *key, size_t keylen,
Paul Bakker23986e52011-04-24 08:57:21 +0000357 const unsigned char *input, size_t ilen,
Paul Bakker17373852011-01-06 14:20:01 +0000358 unsigned char *output );
359
Paul Bakker1bd3ae82013-03-13 10:26:44 +0100360/* Internal use */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200361int mbedtls_md_process( mbedtls_md_context_t *ctx, const unsigned char *data );
Paul Bakker1bd3ae82013-03-13 10:26:44 +0100362
Paul Bakker17373852011-01-06 14:20:01 +0000363#ifdef __cplusplus
364}
365#endif
366
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200367#endif /* MBEDTLS_MD_H */