blob: f23bad40aae836e0b8b4525314b86c07d27b3eed [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>
Darryl Greena40a1012018-01-05 15:33:17 +00007 */
8/*
Manuel Pégourié-Gonnardca878db2015-03-24 12:13:30 +01009 * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
Manuel Pégourié-Gonnard37ff1402015-09-04 14:21:07 +020010 * SPDX-License-Identifier: Apache-2.0
11 *
12 * Licensed under the Apache License, Version 2.0 (the "License"); you may
13 * not use this file except in compliance with the License.
14 * You may obtain a copy of the License at
15 *
16 * http://www.apache.org/licenses/LICENSE-2.0
17 *
18 * Unless required by applicable law or agreed to in writing, software
19 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
20 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21 * See the License for the specific language governing permissions and
22 * limitations under the License.
Paul Bakker17373852011-01-06 14:20:01 +000023 *
Manuel Pégourié-Gonnardfe446432015-03-06 13:17:10 +000024 * This file is part of mbed TLS (https://tls.mbed.org)
Paul Bakker17373852011-01-06 14:20:01 +000025 */
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
Ron Eldorf231eaa2017-08-22 14:50:14 +030031#if !defined(MBEDTLS_CONFIG_FILE)
32#include "config.h"
33#else
34#include MBEDTLS_CONFIG_FILE
35#endif
36
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020037#define MBEDTLS_ERR_MD_FEATURE_UNAVAILABLE -0x5080 /**< The selected feature is not available. */
38#define MBEDTLS_ERR_MD_BAD_INPUT_DATA -0x5100 /**< Bad input parameters to function. */
39#define MBEDTLS_ERR_MD_ALLOC_FAILED -0x5180 /**< Failed to allocate memory. */
40#define MBEDTLS_ERR_MD_FILE_IO_ERROR -0x5200 /**< Opening or reading of file failed. */
Paul Bakker335db3f2011-04-25 15:28:35 +000041
Paul Bakker407a0da2013-06-27 14:29:21 +020042#ifdef __cplusplus
43extern "C" {
44#endif
45
Paul Bakker17373852011-01-06 14:20:01 +000046typedef enum {
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020047 MBEDTLS_MD_NONE=0,
48 MBEDTLS_MD_MD2,
49 MBEDTLS_MD_MD4,
50 MBEDTLS_MD_MD5,
51 MBEDTLS_MD_SHA1,
52 MBEDTLS_MD_SHA224,
53 MBEDTLS_MD_SHA256,
54 MBEDTLS_MD_SHA384,
55 MBEDTLS_MD_SHA512,
56 MBEDTLS_MD_RIPEMD160,
57} mbedtls_md_type_t;
Paul Bakker17373852011-01-06 14:20:01 +000058
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020059#if defined(MBEDTLS_SHA512_C)
60#define MBEDTLS_MD_MAX_SIZE 64 /* longest known is SHA512 */
Paul Bakker7db01092013-09-10 11:10:57 +020061#else
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020062#define MBEDTLS_MD_MAX_SIZE 32 /* longest known is SHA256 or less */
Paul Bakker7db01092013-09-10 11:10:57 +020063#endif
Paul Bakker1b57b062011-01-06 15:48:19 +000064
Paul Bakker17373852011-01-06 14:20:01 +000065/**
Manuel Pégourié-Gonnard50518f42015-05-26 11:04:15 +020066 * Opaque struct defined in md_internal.h
Paul Bakker17373852011-01-06 14:20:01 +000067 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020068typedef struct mbedtls_md_info_t mbedtls_md_info_t;
Paul Bakker17373852011-01-06 14:20:01 +000069
70/**
71 * Generic message digest context.
72 */
73typedef struct {
74 /** Information about the associated message digest */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020075 const mbedtls_md_info_t *md_info;
Paul Bakker17373852011-01-06 14:20:01 +000076
77 /** Digest-specific context */
78 void *md_ctx;
Manuel Pégourié-Gonnard8379a822015-03-24 16:48:22 +010079
Manuel Pégourié-Gonnarddfb3dc82015-03-25 11:49:07 +010080 /** HMAC part of the context */
81 void *hmac_ctx;
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020082} mbedtls_md_context_t;
Paul Bakker17373852011-01-06 14:20:01 +000083
Paul Bakker17373852011-01-06 14:20:01 +000084/**
Paul Bakker72f62662011-01-16 21:27:44 +000085 * \brief Returns the list of digests supported by the generic digest module.
86 *
87 * \return a statically allocated array of digests, the last entry
88 * is 0.
89 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020090const int *mbedtls_md_list( void );
Paul Bakker72f62662011-01-16 21:27:44 +000091
92/**
Paul Bakker17373852011-01-06 14:20:01 +000093 * \brief Returns the message digest information associated with the
94 * given digest name.
95 *
Paul Bakker23986e52011-04-24 08:57:21 +000096 * \param md_name Name of the digest to search for.
Paul Bakker17373852011-01-06 14:20:01 +000097 *
98 * \return The message digest information associated with md_name or
99 * NULL if not found.
100 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200101const mbedtls_md_info_t *mbedtls_md_info_from_string( const char *md_name );
Paul Bakker17373852011-01-06 14:20:01 +0000102
103/**
104 * \brief Returns the message digest information associated with the
105 * given digest type.
106 *
107 * \param md_type type of digest to search for.
108 *
109 * \return The message digest information associated with md_type or
110 * NULL if not found.
111 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200112const mbedtls_md_info_t *mbedtls_md_info_from_type( mbedtls_md_type_t md_type );
Paul Bakker17373852011-01-06 14:20:01 +0000113
114/**
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100115 * \brief Initialize a md_context (as NONE)
116 * This should always be called first.
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200117 * Prepares the context for mbedtls_md_setup() or mbedtls_md_free().
Paul Bakker84bbeb52014-07-01 14:53:22 +0200118 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200119void mbedtls_md_init( mbedtls_md_context_t *ctx );
Paul Bakker84bbeb52014-07-01 14:53:22 +0200120
121/**
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100122 * \brief Free and clear the internal structures of ctx.
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200123 * Can be called at any time after mbedtls_md_init().
124 * Mandatory once mbedtls_md_setup() has been called.
Paul Bakker84bbeb52014-07-01 14:53:22 +0200125 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200126void mbedtls_md_free( mbedtls_md_context_t *ctx );
Paul Bakker84bbeb52014-07-01 14:53:22 +0200127
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200128#if ! defined(MBEDTLS_DEPRECATED_REMOVED)
129#if defined(MBEDTLS_DEPRECATED_WARNING)
130#define MBEDTLS_DEPRECATED __attribute__((deprecated))
Manuel Pégourié-Gonnard147fa092015-03-25 16:43:14 +0100131#else
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200132#define MBEDTLS_DEPRECATED
Manuel Pégourié-Gonnard147fa092015-03-25 16:43:14 +0100133#endif
134/**
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100135 * \brief Select MD to use and allocate internal structures.
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200136 * Should be called after mbedtls_md_init() or mbedtls_md_free().
137 * Makes it necessary to call mbedtls_md_free() later.
Manuel Pégourié-Gonnard147fa092015-03-25 16:43:14 +0100138 *
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200139 * \deprecated Superseded by mbedtls_md_setup() in 2.0.0
Manuel Pégourié-Gonnard147fa092015-03-25 16:43:14 +0100140 *
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100141 * \param ctx Context to set up.
142 * \param md_info Message digest to use.
Manuel Pégourié-Gonnard147fa092015-03-25 16:43:14 +0100143 *
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100144 * \returns \c 0 on success,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200145 * \c MBEDTLS_ERR_MD_BAD_INPUT_DATA on parameter failure,
146 * \c MBEDTLS_ERR_MD_ALLOC_FAILED memory allocation failure.
Manuel Pégourié-Gonnard147fa092015-03-25 16:43:14 +0100147 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200148int mbedtls_md_init_ctx( mbedtls_md_context_t *ctx, const mbedtls_md_info_t *md_info ) MBEDTLS_DEPRECATED;
149#undef MBEDTLS_DEPRECATED
150#endif /* MBEDTLS_DEPRECATED_REMOVED */
Manuel Pégourié-Gonnard147fa092015-03-25 16:43:14 +0100151
Paul Bakker84bbeb52014-07-01 14:53:22 +0200152/**
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100153 * \brief Select MD to use and allocate internal structures.
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200154 * Should be called after mbedtls_md_init() or mbedtls_md_free().
155 * Makes it necessary to call mbedtls_md_free() later.
Paul Bakker562535d2011-01-20 16:42:01 +0000156 *
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100157 * \param ctx Context to set up.
158 * \param md_info Message digest to use.
Manuel Pégourié-Gonnardac50fc52015-08-10 13:07:09 +0200159 * \param hmac 0 to save some memory if HMAC will not be used,
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100160 * non-zero is HMAC is going to be used with this context.
Paul Bakker562535d2011-01-20 16:42:01 +0000161 *
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100162 * \returns \c 0 on success,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200163 * \c MBEDTLS_ERR_MD_BAD_INPUT_DATA on parameter failure,
164 * \c MBEDTLS_ERR_MD_ALLOC_FAILED memory allocation failure.
Paul Bakker562535d2011-01-20 16:42:01 +0000165 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200166int mbedtls_md_setup( mbedtls_md_context_t *ctx, const mbedtls_md_info_t *md_info, int hmac );
Paul Bakker562535d2011-01-20 16:42:01 +0000167
168/**
Manuel Pégourié-Gonnard052a6c92015-07-06 16:06:02 +0200169 * \brief Clone the state of an MD context
170 *
171 * \note The two contexts must have been setup to the same type
172 * (cloning from SHA-256 to SHA-512 make no sense).
173 *
174 * \warning Only clones the MD state, not the HMAC state! (for now)
175 *
176 * \param dst The destination context
177 * \param src The context to be cloned
178 *
179 * \return \c 0 on success,
180 * \c MBEDTLS_ERR_MD_BAD_INPUT_DATA on parameter failure.
181 */
182int mbedtls_md_clone( mbedtls_md_context_t *dst,
183 const mbedtls_md_context_t *src );
184
185/**
Paul Bakker17373852011-01-06 14:20:01 +0000186 * \brief Returns the size of the message digest output.
187 *
188 * \param md_info message digest info
189 *
Manuel Pégourié-Gonnardb8186a52015-06-18 14:58:58 +0200190 * \return size of the message digest output in bytes.
Paul Bakker17373852011-01-06 14:20:01 +0000191 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200192unsigned char mbedtls_md_get_size( const mbedtls_md_info_t *md_info );
Paul Bakker17373852011-01-06 14:20:01 +0000193
194/**
195 * \brief Returns the type of the message digest output.
196 *
197 * \param md_info message digest info
198 *
199 * \return type of the message digest output.
200 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200201mbedtls_md_type_t mbedtls_md_get_type( const mbedtls_md_info_t *md_info );
Paul Bakker17373852011-01-06 14:20:01 +0000202
203/**
204 * \brief Returns the name of the message digest output.
205 *
206 * \param md_info message digest info
207 *
208 * \return name of the message digest output.
209 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200210const char *mbedtls_md_get_name( const mbedtls_md_info_t *md_info );
Paul Bakker17373852011-01-06 14:20:01 +0000211
212/**
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100213 * \brief Prepare the context to digest a new message.
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200214 * Generally called after mbedtls_md_setup() or mbedtls_md_finish().
215 * Followed by mbedtls_md_update().
Paul Bakker17373852011-01-06 14:20:01 +0000216 *
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100217 * \param ctx generic message digest context.
Paul Bakker17373852011-01-06 14:20:01 +0000218 *
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200219 * \returns 0 on success, MBEDTLS_ERR_MD_BAD_INPUT_DATA if parameter
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100220 * verification fails.
Paul Bakker17373852011-01-06 14:20:01 +0000221 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200222int mbedtls_md_starts( mbedtls_md_context_t *ctx );
Paul Bakker17373852011-01-06 14:20:01 +0000223
224/**
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100225 * \brief Generic message digest process buffer
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200226 * Called between mbedtls_md_starts() and mbedtls_md_finish().
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100227 * May be called repeatedly.
Paul Bakker17373852011-01-06 14:20:01 +0000228 *
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100229 * \param ctx Generic message digest context
230 * \param input buffer holding the datal
231 * \param ilen length of the input data
Paul Bakker17373852011-01-06 14:20:01 +0000232 *
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200233 * \returns 0 on success, MBEDTLS_ERR_MD_BAD_INPUT_DATA if parameter
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100234 * verification fails.
Paul Bakker17373852011-01-06 14:20:01 +0000235 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200236int mbedtls_md_update( mbedtls_md_context_t *ctx, const unsigned char *input, size_t ilen );
Paul Bakker17373852011-01-06 14:20:01 +0000237
238/**
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100239 * \brief Generic message digest final digest
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200240 * Called after mbedtls_md_update().
241 * Usually followed by mbedtls_md_free() or mbedtls_md_starts().
Paul Bakker17373852011-01-06 14:20:01 +0000242 *
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100243 * \param ctx Generic message digest context
244 * \param output Generic message digest checksum result
Paul Bakker17373852011-01-06 14:20:01 +0000245 *
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200246 * \returns 0 on success, MBEDTLS_ERR_MD_BAD_INPUT_DATA if parameter
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100247 * verification fails.
Paul Bakker17373852011-01-06 14:20:01 +0000248 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200249int mbedtls_md_finish( mbedtls_md_context_t *ctx, unsigned char *output );
Paul Bakker17373852011-01-06 14:20:01 +0000250
251/**
Paul Bakker17373852011-01-06 14:20:01 +0000252 * \brief Output = message_digest( input buffer )
253 *
254 * \param md_info message digest info
255 * \param input buffer holding the data
256 * \param ilen length of the input data
257 * \param output Generic message digest checksum result
258 *
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200259 * \returns 0 on success, MBEDTLS_ERR_MD_BAD_INPUT_DATA if parameter
Paul Bakker9c021ad2011-06-09 15:55:11 +0000260 * verification fails.
Paul Bakker17373852011-01-06 14:20:01 +0000261 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200262int mbedtls_md( const mbedtls_md_info_t *md_info, const unsigned char *input, size_t ilen,
Paul Bakker17373852011-01-06 14:20:01 +0000263 unsigned char *output );
264
Manuel Pégourié-Gonnardbfffa902015-05-28 14:44:00 +0200265#if defined(MBEDTLS_FS_IO)
Paul Bakker17373852011-01-06 14:20:01 +0000266/**
267 * \brief Output = message_digest( file contents )
268 *
269 * \param md_info message digest info
270 * \param path input file name
271 * \param output generic message digest checksum result
272 *
Manuel Pégourié-Gonnard932e3932015-04-03 16:37:14 +0200273 * \return 0 if successful,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200274 * MBEDTLS_ERR_MD_FILE_IO_ERROR if file input failed,
275 * MBEDTLS_ERR_MD_BAD_INPUT_DATA if md_info was NULL.
Paul Bakker17373852011-01-06 14:20:01 +0000276 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200277int mbedtls_md_file( const mbedtls_md_info_t *md_info, const char *path,
Manuel Pégourié-Gonnardbfffa902015-05-28 14:44:00 +0200278 unsigned char *output );
279#endif /* MBEDTLS_FS_IO */
Paul Bakker17373852011-01-06 14:20:01 +0000280
281/**
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100282 * \brief Set HMAC key and prepare to authenticate a new message.
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200283 * Usually called after mbedtls_md_setup() or mbedtls_md_hmac_finish().
Paul Bakker17373852011-01-06 14:20:01 +0000284 *
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100285 * \param ctx HMAC context
286 * \param key HMAC secret key
Manuel Pégourié-Gonnardb8186a52015-06-18 14:58:58 +0200287 * \param keylen length of the HMAC key in bytes
Paul Bakker17373852011-01-06 14:20:01 +0000288 *
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200289 * \returns 0 on success, MBEDTLS_ERR_MD_BAD_INPUT_DATA if parameter
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100290 * verification fails.
Paul Bakker17373852011-01-06 14:20:01 +0000291 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200292int mbedtls_md_hmac_starts( mbedtls_md_context_t *ctx, const unsigned char *key,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200293 size_t keylen );
Paul Bakker17373852011-01-06 14:20:01 +0000294
295/**
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100296 * \brief Generic HMAC process buffer.
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200297 * Called between mbedtls_md_hmac_starts() or mbedtls_md_hmac_reset()
298 * and mbedtls_md_hmac_finish().
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100299 * May be called repeatedly.
Paul Bakker17373852011-01-06 14:20:01 +0000300 *
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100301 * \param ctx HMAC context
302 * \param input buffer holding the data
303 * \param ilen length of the input data
Paul Bakker17373852011-01-06 14:20:01 +0000304 *
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200305 * \returns 0 on success, MBEDTLS_ERR_MD_BAD_INPUT_DATA if parameter
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100306 * verification fails.
Paul Bakker17373852011-01-06 14:20:01 +0000307 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200308int mbedtls_md_hmac_update( mbedtls_md_context_t *ctx, const unsigned char *input,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200309 size_t ilen );
Paul Bakker17373852011-01-06 14:20:01 +0000310
311/**
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100312 * \brief Output HMAC.
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200313 * Called after mbedtls_md_hmac_update().
Simon Butcher01ba45b2016-10-05 14:17:01 +0100314 * Usually followed by mbedtls_md_hmac_reset(),
315 * mbedtls_md_hmac_starts(), or mbedtls_md_free().
Paul Bakker17373852011-01-06 14:20:01 +0000316 *
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100317 * \param ctx HMAC context
318 * \param output Generic HMAC checksum result
Paul Bakker17373852011-01-06 14:20:01 +0000319 *
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200320 * \returns 0 on success, MBEDTLS_ERR_MD_BAD_INPUT_DATA if parameter
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100321 * verification fails.
Paul Bakker17373852011-01-06 14:20:01 +0000322 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200323int mbedtls_md_hmac_finish( mbedtls_md_context_t *ctx, unsigned char *output);
Paul Bakker17373852011-01-06 14:20:01 +0000324
325/**
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100326 * \brief Prepare to authenticate a new message with the same key.
Simon Butcher01ba45b2016-10-05 14:17:01 +0100327 * Called after mbedtls_md_hmac_finish() and before
328 * mbedtls_md_hmac_update().
Paul Bakker17373852011-01-06 14:20:01 +0000329 *
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100330 * \param ctx HMAC context to be reset
Paul Bakker17373852011-01-06 14:20:01 +0000331 *
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200332 * \returns 0 on success, MBEDTLS_ERR_MD_BAD_INPUT_DATA if parameter
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100333 * verification fails.
Paul Bakker17373852011-01-06 14:20:01 +0000334 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200335int mbedtls_md_hmac_reset( mbedtls_md_context_t *ctx );
Paul Bakker17373852011-01-06 14:20:01 +0000336
337/**
338 * \brief Output = Generic_HMAC( hmac key, input buffer )
339 *
340 * \param md_info message digest info
341 * \param key HMAC secret key
Manuel Pégourié-Gonnardb8186a52015-06-18 14:58:58 +0200342 * \param keylen length of the HMAC key in bytes
Paul Bakker17373852011-01-06 14:20:01 +0000343 * \param input buffer holding the data
344 * \param ilen length of the input data
345 * \param output Generic HMAC-result
346 *
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200347 * \returns 0 on success, MBEDTLS_ERR_MD_BAD_INPUT_DATA if parameter
Paul Bakker9c021ad2011-06-09 15:55:11 +0000348 * verification fails.
Paul Bakker17373852011-01-06 14:20:01 +0000349 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200350int mbedtls_md_hmac( const mbedtls_md_info_t *md_info, const unsigned char *key, size_t keylen,
Paul Bakker23986e52011-04-24 08:57:21 +0000351 const unsigned char *input, size_t ilen,
Paul Bakker17373852011-01-06 14:20:01 +0000352 unsigned char *output );
353
Paul Bakker1bd3ae82013-03-13 10:26:44 +0100354/* Internal use */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200355int mbedtls_md_process( mbedtls_md_context_t *ctx, const unsigned char *data );
Paul Bakker1bd3ae82013-03-13 10:26:44 +0100356
Paul Bakker17373852011-01-06 14:20:01 +0000357#ifdef __cplusplus
358}
359#endif
360
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200361#endif /* MBEDTLS_MD_H */