blob: 9b996a951bb4c7aa377fe83128fe017cc56dc243 [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
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020030#define MBEDTLS_ERR_MD_FEATURE_UNAVAILABLE -0x5080 /**< The selected feature is not available. */
31#define MBEDTLS_ERR_MD_BAD_INPUT_DATA -0x5100 /**< Bad input parameters to function. */
32#define MBEDTLS_ERR_MD_ALLOC_FAILED -0x5180 /**< Failed to allocate memory. */
33#define MBEDTLS_ERR_MD_FILE_IO_ERROR -0x5200 /**< Opening or reading of file failed. */
Paul Bakker335db3f2011-04-25 15:28:35 +000034
Paul Bakker407a0da2013-06-27 14:29:21 +020035#ifdef __cplusplus
36extern "C" {
37#endif
38
Paul Bakker17373852011-01-06 14:20:01 +000039typedef enum {
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020040 MBEDTLS_MD_NONE=0,
41 MBEDTLS_MD_MD2,
42 MBEDTLS_MD_MD4,
43 MBEDTLS_MD_MD5,
44 MBEDTLS_MD_SHA1,
45 MBEDTLS_MD_SHA224,
46 MBEDTLS_MD_SHA256,
47 MBEDTLS_MD_SHA384,
48 MBEDTLS_MD_SHA512,
49 MBEDTLS_MD_RIPEMD160,
50} mbedtls_md_type_t;
Paul Bakker17373852011-01-06 14:20:01 +000051
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020052#if defined(MBEDTLS_SHA512_C)
53#define MBEDTLS_MD_MAX_SIZE 64 /* longest known is SHA512 */
Paul Bakker7db01092013-09-10 11:10:57 +020054#else
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020055#define MBEDTLS_MD_MAX_SIZE 32 /* longest known is SHA256 or less */
Paul Bakker7db01092013-09-10 11:10:57 +020056#endif
Paul Bakker1b57b062011-01-06 15:48:19 +000057
Paul Bakker17373852011-01-06 14:20:01 +000058/**
Manuel Pégourié-Gonnard50518f42015-05-26 11:04:15 +020059 * Opaque struct defined in md_internal.h
Paul Bakker17373852011-01-06 14:20:01 +000060 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020061typedef struct mbedtls_md_info_t mbedtls_md_info_t;
Paul Bakker17373852011-01-06 14:20:01 +000062
63/**
64 * Generic message digest context.
65 */
66typedef struct {
67 /** Information about the associated message digest */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020068 const mbedtls_md_info_t *md_info;
Paul Bakker17373852011-01-06 14:20:01 +000069
70 /** Digest-specific context */
71 void *md_ctx;
Manuel Pégourié-Gonnard8379a822015-03-24 16:48:22 +010072
Manuel Pégourié-Gonnarddfb3dc82015-03-25 11:49:07 +010073 /** HMAC part of the context */
74 void *hmac_ctx;
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020075} mbedtls_md_context_t;
Paul Bakker17373852011-01-06 14:20:01 +000076
Paul Bakker17373852011-01-06 14:20:01 +000077/**
Paul Bakker72f62662011-01-16 21:27:44 +000078 * \brief Returns the list of digests supported by the generic digest module.
79 *
80 * \return a statically allocated array of digests, the last entry
81 * is 0.
82 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020083const int *mbedtls_md_list( void );
Paul Bakker72f62662011-01-16 21:27:44 +000084
85/**
Paul Bakker17373852011-01-06 14:20:01 +000086 * \brief Returns the message digest information associated with the
87 * given digest name.
88 *
Paul Bakker23986e52011-04-24 08:57:21 +000089 * \param md_name Name of the digest to search for.
Paul Bakker17373852011-01-06 14:20:01 +000090 *
91 * \return The message digest information associated with md_name or
92 * NULL if not found.
93 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020094const mbedtls_md_info_t *mbedtls_md_info_from_string( const char *md_name );
Paul Bakker17373852011-01-06 14:20:01 +000095
96/**
97 * \brief Returns the message digest information associated with the
98 * given digest type.
99 *
100 * \param md_type type of digest to search for.
101 *
102 * \return The message digest information associated with md_type or
103 * NULL if not found.
104 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200105const mbedtls_md_info_t *mbedtls_md_info_from_type( mbedtls_md_type_t md_type );
Paul Bakker17373852011-01-06 14:20:01 +0000106
107/**
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100108 * \brief Initialize a md_context (as NONE)
109 * This should always be called first.
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200110 * Prepares the context for mbedtls_md_setup() or mbedtls_md_free().
Paul Bakker84bbeb52014-07-01 14:53:22 +0200111 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200112void mbedtls_md_init( mbedtls_md_context_t *ctx );
Paul Bakker84bbeb52014-07-01 14:53:22 +0200113
114/**
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100115 * \brief Free and clear the internal structures of ctx.
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200116 * Can be called at any time after mbedtls_md_init().
117 * Mandatory once mbedtls_md_setup() has been called.
Paul Bakker84bbeb52014-07-01 14:53:22 +0200118 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200119void mbedtls_md_free( mbedtls_md_context_t *ctx );
Paul Bakker84bbeb52014-07-01 14:53:22 +0200120
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200121#if ! defined(MBEDTLS_DEPRECATED_REMOVED)
122#if defined(MBEDTLS_DEPRECATED_WARNING)
123#define MBEDTLS_DEPRECATED __attribute__((deprecated))
Manuel Pégourié-Gonnard147fa092015-03-25 16:43:14 +0100124#else
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200125#define MBEDTLS_DEPRECATED
Manuel Pégourié-Gonnard147fa092015-03-25 16:43:14 +0100126#endif
127/**
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100128 * \brief Select MD to use and allocate internal structures.
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200129 * Should be called after mbedtls_md_init() or mbedtls_md_free().
130 * Makes it necessary to call mbedtls_md_free() later.
Manuel Pégourié-Gonnard147fa092015-03-25 16:43:14 +0100131 *
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200132 * \deprecated Superseded by mbedtls_md_setup() in 2.0.0
Manuel Pégourié-Gonnard147fa092015-03-25 16:43:14 +0100133 *
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100134 * \param ctx Context to set up.
135 * \param md_info Message digest to use.
Manuel Pégourié-Gonnard147fa092015-03-25 16:43:14 +0100136 *
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100137 * \returns \c 0 on success,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200138 * \c MBEDTLS_ERR_MD_BAD_INPUT_DATA on parameter failure,
139 * \c MBEDTLS_ERR_MD_ALLOC_FAILED memory allocation failure.
Manuel Pégourié-Gonnard147fa092015-03-25 16:43:14 +0100140 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200141int mbedtls_md_init_ctx( mbedtls_md_context_t *ctx, const mbedtls_md_info_t *md_info ) MBEDTLS_DEPRECATED;
142#undef MBEDTLS_DEPRECATED
143#endif /* MBEDTLS_DEPRECATED_REMOVED */
Manuel Pégourié-Gonnard147fa092015-03-25 16:43:14 +0100144
Paul Bakker84bbeb52014-07-01 14:53:22 +0200145/**
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100146 * \brief Select MD to use and allocate internal structures.
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200147 * Should be called after mbedtls_md_init() or mbedtls_md_free().
148 * Makes it necessary to call mbedtls_md_free() later.
Paul Bakker562535d2011-01-20 16:42:01 +0000149 *
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100150 * \param ctx Context to set up.
151 * \param md_info Message digest to use.
Manuel Pégourié-Gonnardac50fc52015-08-10 13:07:09 +0200152 * \param hmac 0 to save some memory if HMAC will not be used,
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100153 * non-zero is HMAC is going to be used with this context.
Paul Bakker562535d2011-01-20 16:42:01 +0000154 *
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100155 * \returns \c 0 on success,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200156 * \c MBEDTLS_ERR_MD_BAD_INPUT_DATA on parameter failure,
157 * \c MBEDTLS_ERR_MD_ALLOC_FAILED memory allocation failure.
Paul Bakker562535d2011-01-20 16:42:01 +0000158 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200159int mbedtls_md_setup( mbedtls_md_context_t *ctx, const mbedtls_md_info_t *md_info, int hmac );
Paul Bakker562535d2011-01-20 16:42:01 +0000160
161/**
Manuel Pégourié-Gonnard052a6c92015-07-06 16:06:02 +0200162 * \brief Clone the state of an MD context
163 *
164 * \note The two contexts must have been setup to the same type
165 * (cloning from SHA-256 to SHA-512 make no sense).
166 *
167 * \warning Only clones the MD state, not the HMAC state! (for now)
168 *
169 * \param dst The destination context
170 * \param src The context to be cloned
171 *
172 * \return \c 0 on success,
173 * \c MBEDTLS_ERR_MD_BAD_INPUT_DATA on parameter failure.
174 */
175int mbedtls_md_clone( mbedtls_md_context_t *dst,
176 const mbedtls_md_context_t *src );
177
178/**
Paul Bakker17373852011-01-06 14:20:01 +0000179 * \brief Returns the size of the message digest output.
180 *
181 * \param md_info message digest info
182 *
Manuel Pégourié-Gonnardb8186a52015-06-18 14:58:58 +0200183 * \return size of the message digest output in bytes.
Paul Bakker17373852011-01-06 14:20:01 +0000184 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200185unsigned char mbedtls_md_get_size( const mbedtls_md_info_t *md_info );
Paul Bakker17373852011-01-06 14:20:01 +0000186
187/**
188 * \brief Returns the type of the message digest output.
189 *
190 * \param md_info message digest info
191 *
192 * \return type of the message digest output.
193 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200194mbedtls_md_type_t mbedtls_md_get_type( const mbedtls_md_info_t *md_info );
Paul Bakker17373852011-01-06 14:20:01 +0000195
196/**
197 * \brief Returns the name of the message digest output.
198 *
199 * \param md_info message digest info
200 *
201 * \return name of the message digest output.
202 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200203const char *mbedtls_md_get_name( const mbedtls_md_info_t *md_info );
Paul Bakker17373852011-01-06 14:20:01 +0000204
205/**
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100206 * \brief Prepare the context to digest a new message.
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200207 * Generally called after mbedtls_md_setup() or mbedtls_md_finish().
208 * Followed by mbedtls_md_update().
Paul Bakker17373852011-01-06 14:20:01 +0000209 *
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100210 * \param ctx generic message digest context.
Paul Bakker17373852011-01-06 14:20:01 +0000211 *
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200212 * \returns 0 on success, MBEDTLS_ERR_MD_BAD_INPUT_DATA if parameter
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100213 * verification fails.
Paul Bakker17373852011-01-06 14:20:01 +0000214 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200215int mbedtls_md_starts( mbedtls_md_context_t *ctx );
Paul Bakker17373852011-01-06 14:20:01 +0000216
217/**
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100218 * \brief Generic message digest process buffer
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200219 * Called between mbedtls_md_starts() and mbedtls_md_finish().
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100220 * May be called repeatedly.
Paul Bakker17373852011-01-06 14:20:01 +0000221 *
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100222 * \param ctx Generic message digest context
223 * \param input buffer holding the datal
224 * \param ilen length of the input data
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_update( mbedtls_md_context_t *ctx, const unsigned char *input, size_t ilen );
Paul Bakker17373852011-01-06 14:20:01 +0000230
231/**
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100232 * \brief Generic message digest final digest
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200233 * Called after mbedtls_md_update().
234 * Usually followed by mbedtls_md_free() or mbedtls_md_starts().
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 output Generic message digest checksum result
Paul Bakker17373852011-01-06 14:20:01 +0000238 *
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200239 * \returns 0 on success, MBEDTLS_ERR_MD_BAD_INPUT_DATA if parameter
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100240 * verification fails.
Paul Bakker17373852011-01-06 14:20:01 +0000241 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200242int mbedtls_md_finish( mbedtls_md_context_t *ctx, unsigned char *output );
Paul Bakker17373852011-01-06 14:20:01 +0000243
244/**
Paul Bakker17373852011-01-06 14:20:01 +0000245 * \brief Output = message_digest( input buffer )
246 *
247 * \param md_info message digest info
248 * \param input buffer holding the data
249 * \param ilen length of the input data
250 * \param output Generic message digest checksum result
251 *
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200252 * \returns 0 on success, MBEDTLS_ERR_MD_BAD_INPUT_DATA if parameter
Paul Bakker9c021ad2011-06-09 15:55:11 +0000253 * verification fails.
Paul Bakker17373852011-01-06 14:20:01 +0000254 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200255int mbedtls_md( const mbedtls_md_info_t *md_info, const unsigned char *input, size_t ilen,
Paul Bakker17373852011-01-06 14:20:01 +0000256 unsigned char *output );
257
Manuel Pégourié-Gonnardbfffa902015-05-28 14:44:00 +0200258#if defined(MBEDTLS_FS_IO)
Paul Bakker17373852011-01-06 14:20:01 +0000259/**
260 * \brief Output = message_digest( file contents )
261 *
262 * \param md_info message digest info
263 * \param path input file name
264 * \param output generic message digest checksum result
265 *
Manuel Pégourié-Gonnard932e3932015-04-03 16:37:14 +0200266 * \return 0 if successful,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200267 * MBEDTLS_ERR_MD_FILE_IO_ERROR if file input failed,
268 * MBEDTLS_ERR_MD_BAD_INPUT_DATA if md_info was NULL.
Paul Bakker17373852011-01-06 14:20:01 +0000269 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200270int mbedtls_md_file( const mbedtls_md_info_t *md_info, const char *path,
Manuel Pégourié-Gonnardbfffa902015-05-28 14:44:00 +0200271 unsigned char *output );
272#endif /* MBEDTLS_FS_IO */
Paul Bakker17373852011-01-06 14:20:01 +0000273
274/**
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100275 * \brief Set HMAC key and prepare to authenticate a new message.
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200276 * Usually called after mbedtls_md_setup() or mbedtls_md_hmac_finish().
Paul Bakker17373852011-01-06 14:20:01 +0000277 *
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100278 * \param ctx HMAC context
279 * \param key HMAC secret key
Manuel Pégourié-Gonnardb8186a52015-06-18 14:58:58 +0200280 * \param keylen length of the HMAC key in bytes
Paul Bakker17373852011-01-06 14:20:01 +0000281 *
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200282 * \returns 0 on success, MBEDTLS_ERR_MD_BAD_INPUT_DATA if parameter
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100283 * verification fails.
Paul Bakker17373852011-01-06 14:20:01 +0000284 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200285int mbedtls_md_hmac_starts( mbedtls_md_context_t *ctx, const unsigned char *key,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200286 size_t keylen );
Paul Bakker17373852011-01-06 14:20:01 +0000287
288/**
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100289 * \brief Generic HMAC process buffer.
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200290 * Called between mbedtls_md_hmac_starts() or mbedtls_md_hmac_reset()
291 * and mbedtls_md_hmac_finish().
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100292 * May be called repeatedly.
Paul Bakker17373852011-01-06 14:20:01 +0000293 *
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100294 * \param ctx HMAC context
295 * \param input buffer holding the data
296 * \param ilen length of the input data
Paul Bakker17373852011-01-06 14:20:01 +0000297 *
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200298 * \returns 0 on success, MBEDTLS_ERR_MD_BAD_INPUT_DATA if parameter
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100299 * verification fails.
Paul Bakker17373852011-01-06 14:20:01 +0000300 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200301int mbedtls_md_hmac_update( mbedtls_md_context_t *ctx, const unsigned char *input,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200302 size_t ilen );
Paul Bakker17373852011-01-06 14:20:01 +0000303
304/**
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100305 * \brief Output HMAC.
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200306 * Called after mbedtls_md_hmac_update().
Simon Butcher01ba45b2016-10-05 14:17:01 +0100307 * Usually followed by mbedtls_md_hmac_reset(),
308 * mbedtls_md_hmac_starts(), or mbedtls_md_free().
Paul Bakker17373852011-01-06 14:20:01 +0000309 *
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100310 * \param ctx HMAC context
311 * \param output Generic HMAC checksum result
Paul Bakker17373852011-01-06 14:20:01 +0000312 *
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200313 * \returns 0 on success, MBEDTLS_ERR_MD_BAD_INPUT_DATA if parameter
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100314 * verification fails.
Paul Bakker17373852011-01-06 14:20:01 +0000315 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200316int mbedtls_md_hmac_finish( mbedtls_md_context_t *ctx, unsigned char *output);
Paul Bakker17373852011-01-06 14:20:01 +0000317
318/**
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100319 * \brief Prepare to authenticate a new message with the same key.
Simon Butcher01ba45b2016-10-05 14:17:01 +0100320 * Called after mbedtls_md_hmac_finish() and before
321 * mbedtls_md_hmac_update().
Paul Bakker17373852011-01-06 14:20:01 +0000322 *
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100323 * \param ctx HMAC context to be reset
Paul Bakker17373852011-01-06 14:20:01 +0000324 *
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200325 * \returns 0 on success, MBEDTLS_ERR_MD_BAD_INPUT_DATA if parameter
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100326 * verification fails.
Paul Bakker17373852011-01-06 14:20:01 +0000327 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200328int mbedtls_md_hmac_reset( mbedtls_md_context_t *ctx );
Paul Bakker17373852011-01-06 14:20:01 +0000329
330/**
331 * \brief Output = Generic_HMAC( hmac key, input buffer )
332 *
333 * \param md_info message digest info
334 * \param key HMAC secret key
Manuel Pégourié-Gonnardb8186a52015-06-18 14:58:58 +0200335 * \param keylen length of the HMAC key in bytes
Paul Bakker17373852011-01-06 14:20:01 +0000336 * \param input buffer holding the data
337 * \param ilen length of the input data
338 * \param output Generic HMAC-result
339 *
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200340 * \returns 0 on success, MBEDTLS_ERR_MD_BAD_INPUT_DATA if parameter
Paul Bakker9c021ad2011-06-09 15:55:11 +0000341 * verification fails.
Paul Bakker17373852011-01-06 14:20:01 +0000342 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200343int mbedtls_md_hmac( const mbedtls_md_info_t *md_info, const unsigned char *key, size_t keylen,
Paul Bakker23986e52011-04-24 08:57:21 +0000344 const unsigned char *input, size_t ilen,
Paul Bakker17373852011-01-06 14:20:01 +0000345 unsigned char *output );
346
Paul Bakker1bd3ae82013-03-13 10:26:44 +0100347/* Internal use */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200348int mbedtls_md_process( mbedtls_md_context_t *ctx, const unsigned char *data );
Paul Bakker1bd3ae82013-03-13 10:26:44 +0100349
Paul Bakker17373852011-01-06 14:20:01 +0000350#ifdef __cplusplus
351}
352#endif
353
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200354#endif /* MBEDTLS_MD_H */