blob: 1834b599278ca282b0eed79d59d033c575e3df0b [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
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é-Gonnard20af64d2015-07-07 18:33:39 +020030#if ( defined(__ARMCC_VERSION) || defined(_MSC_VER) ) && !defined(inline)
Paul Bakker569df2c2011-06-21 07:48:07 +000031#define inline __inline
Manuel Pégourié-Gonnard20af64d2015-07-07 18:33:39 +020032#endif
Paul Bakkeraf5c85f2011-04-18 03:47:52 +000033
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020034#define MBEDTLS_ERR_MD_FEATURE_UNAVAILABLE -0x5080 /**< The selected feature is not available. */
35#define MBEDTLS_ERR_MD_BAD_INPUT_DATA -0x5100 /**< Bad input parameters to function. */
36#define MBEDTLS_ERR_MD_ALLOC_FAILED -0x5180 /**< Failed to allocate memory. */
37#define MBEDTLS_ERR_MD_FILE_IO_ERROR -0x5200 /**< Opening or reading of file failed. */
Paul Bakker335db3f2011-04-25 15:28:35 +000038
Paul Bakker407a0da2013-06-27 14:29:21 +020039#ifdef __cplusplus
40extern "C" {
41#endif
42
Paul Bakker17373852011-01-06 14:20:01 +000043typedef enum {
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020044 MBEDTLS_MD_NONE=0,
45 MBEDTLS_MD_MD2,
46 MBEDTLS_MD_MD4,
47 MBEDTLS_MD_MD5,
48 MBEDTLS_MD_SHA1,
49 MBEDTLS_MD_SHA224,
50 MBEDTLS_MD_SHA256,
51 MBEDTLS_MD_SHA384,
52 MBEDTLS_MD_SHA512,
53 MBEDTLS_MD_RIPEMD160,
54} mbedtls_md_type_t;
Paul Bakker17373852011-01-06 14:20:01 +000055
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020056#if defined(MBEDTLS_SHA512_C)
57#define MBEDTLS_MD_MAX_SIZE 64 /* longest known is SHA512 */
Paul Bakker7db01092013-09-10 11:10:57 +020058#else
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020059#define MBEDTLS_MD_MAX_SIZE 32 /* longest known is SHA256 or less */
Paul Bakker7db01092013-09-10 11:10:57 +020060#endif
Paul Bakker1b57b062011-01-06 15:48:19 +000061
Paul Bakker17373852011-01-06 14:20:01 +000062/**
Manuel Pégourié-Gonnard50518f42015-05-26 11:04:15 +020063 * Opaque struct defined in md_internal.h
Paul Bakker17373852011-01-06 14:20:01 +000064 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020065typedef struct mbedtls_md_info_t mbedtls_md_info_t;
Paul Bakker17373852011-01-06 14:20:01 +000066
67/**
68 * Generic message digest context.
69 */
70typedef struct {
71 /** Information about the associated message digest */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020072 const mbedtls_md_info_t *md_info;
Paul Bakker17373852011-01-06 14:20:01 +000073
74 /** Digest-specific context */
75 void *md_ctx;
Manuel Pégourié-Gonnard8379a822015-03-24 16:48:22 +010076
Manuel Pégourié-Gonnarddfb3dc82015-03-25 11:49:07 +010077 /** HMAC part of the context */
78 void *hmac_ctx;
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020079} mbedtls_md_context_t;
Paul Bakker17373852011-01-06 14:20:01 +000080
Paul Bakker17373852011-01-06 14:20:01 +000081/**
Paul Bakker72f62662011-01-16 21:27:44 +000082 * \brief Returns the list of digests supported by the generic digest module.
83 *
84 * \return a statically allocated array of digests, the last entry
85 * is 0.
86 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020087const int *mbedtls_md_list( void );
Paul Bakker72f62662011-01-16 21:27:44 +000088
89/**
Paul Bakker17373852011-01-06 14:20:01 +000090 * \brief Returns the message digest information associated with the
91 * given digest name.
92 *
Paul Bakker23986e52011-04-24 08:57:21 +000093 * \param md_name Name of the digest to search for.
Paul Bakker17373852011-01-06 14:20:01 +000094 *
95 * \return The message digest information associated with md_name or
96 * NULL if not found.
97 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020098const mbedtls_md_info_t *mbedtls_md_info_from_string( const char *md_name );
Paul Bakker17373852011-01-06 14:20:01 +000099
100/**
101 * \brief Returns the message digest information associated with the
102 * given digest type.
103 *
104 * \param md_type type of digest to search for.
105 *
106 * \return The message digest information associated with md_type or
107 * NULL if not found.
108 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200109const mbedtls_md_info_t *mbedtls_md_info_from_type( mbedtls_md_type_t md_type );
Paul Bakker17373852011-01-06 14:20:01 +0000110
111/**
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100112 * \brief Initialize a md_context (as NONE)
113 * This should always be called first.
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200114 * Prepares the context for mbedtls_md_setup() or mbedtls_md_free().
Paul Bakker84bbeb52014-07-01 14:53:22 +0200115 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200116void mbedtls_md_init( mbedtls_md_context_t *ctx );
Paul Bakker84bbeb52014-07-01 14:53:22 +0200117
118/**
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100119 * \brief Free and clear the internal structures of ctx.
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200120 * Can be called at any time after mbedtls_md_init().
121 * Mandatory once mbedtls_md_setup() has been called.
Paul Bakker84bbeb52014-07-01 14:53:22 +0200122 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200123void mbedtls_md_free( mbedtls_md_context_t *ctx );
Paul Bakker84bbeb52014-07-01 14:53:22 +0200124
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200125#if ! defined(MBEDTLS_DEPRECATED_REMOVED)
126#if defined(MBEDTLS_DEPRECATED_WARNING)
127#define MBEDTLS_DEPRECATED __attribute__((deprecated))
Manuel Pégourié-Gonnard147fa092015-03-25 16:43:14 +0100128#else
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200129#define MBEDTLS_DEPRECATED
Manuel Pégourié-Gonnard147fa092015-03-25 16:43:14 +0100130#endif
131/**
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100132 * \brief Select MD to use and allocate internal structures.
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200133 * Should be called after mbedtls_md_init() or mbedtls_md_free().
134 * Makes it necessary to call mbedtls_md_free() later.
Manuel Pégourié-Gonnard147fa092015-03-25 16:43:14 +0100135 *
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200136 * \deprecated Superseded by mbedtls_md_setup() in 2.0.0
Manuel Pégourié-Gonnard147fa092015-03-25 16:43:14 +0100137 *
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100138 * \param ctx Context to set up.
139 * \param md_info Message digest to use.
Manuel Pégourié-Gonnard147fa092015-03-25 16:43:14 +0100140 *
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100141 * \returns \c 0 on success,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200142 * \c MBEDTLS_ERR_MD_BAD_INPUT_DATA on parameter failure,
143 * \c MBEDTLS_ERR_MD_ALLOC_FAILED memory allocation failure.
Manuel Pégourié-Gonnard147fa092015-03-25 16:43:14 +0100144 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200145int mbedtls_md_init_ctx( mbedtls_md_context_t *ctx, const mbedtls_md_info_t *md_info ) MBEDTLS_DEPRECATED;
146#undef MBEDTLS_DEPRECATED
147#endif /* MBEDTLS_DEPRECATED_REMOVED */
Manuel Pégourié-Gonnard147fa092015-03-25 16:43:14 +0100148
Paul Bakker84bbeb52014-07-01 14:53:22 +0200149/**
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100150 * \brief Select MD to use and allocate internal structures.
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200151 * Should be called after mbedtls_md_init() or mbedtls_md_free().
152 * Makes it necessary to call mbedtls_md_free() later.
Paul Bakker562535d2011-01-20 16:42:01 +0000153 *
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100154 * \param ctx Context to set up.
155 * \param md_info Message digest to use.
Manuel Pégourié-Gonnardac50fc52015-08-10 13:07:09 +0200156 * \param hmac 0 to save some memory if HMAC will not be used,
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100157 * non-zero is HMAC is going to be used with this context.
Paul Bakker562535d2011-01-20 16:42:01 +0000158 *
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100159 * \returns \c 0 on success,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200160 * \c MBEDTLS_ERR_MD_BAD_INPUT_DATA on parameter failure,
161 * \c MBEDTLS_ERR_MD_ALLOC_FAILED memory allocation failure.
Paul Bakker562535d2011-01-20 16:42:01 +0000162 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200163int mbedtls_md_setup( mbedtls_md_context_t *ctx, const mbedtls_md_info_t *md_info, int hmac );
Paul Bakker562535d2011-01-20 16:42:01 +0000164
165/**
Manuel Pégourié-Gonnard052a6c92015-07-06 16:06:02 +0200166 * \brief Clone the state of an MD context
167 *
168 * \note The two contexts must have been setup to the same type
169 * (cloning from SHA-256 to SHA-512 make no sense).
170 *
171 * \warning Only clones the MD state, not the HMAC state! (for now)
172 *
173 * \param dst The destination context
174 * \param src The context to be cloned
175 *
176 * \return \c 0 on success,
177 * \c MBEDTLS_ERR_MD_BAD_INPUT_DATA on parameter failure.
178 */
179int mbedtls_md_clone( mbedtls_md_context_t *dst,
180 const mbedtls_md_context_t *src );
181
182/**
Paul Bakker17373852011-01-06 14:20:01 +0000183 * \brief Returns the size of the message digest output.
184 *
185 * \param md_info message digest info
186 *
Manuel Pégourié-Gonnardb8186a52015-06-18 14:58:58 +0200187 * \return size of the message digest output in bytes.
Paul Bakker17373852011-01-06 14:20:01 +0000188 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200189unsigned char mbedtls_md_get_size( const mbedtls_md_info_t *md_info );
Paul Bakker17373852011-01-06 14:20:01 +0000190
191/**
192 * \brief Returns the type of the message digest output.
193 *
194 * \param md_info message digest info
195 *
196 * \return type of the message digest output.
197 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200198mbedtls_md_type_t mbedtls_md_get_type( const mbedtls_md_info_t *md_info );
Paul Bakker17373852011-01-06 14:20:01 +0000199
200/**
201 * \brief Returns the name of the message digest output.
202 *
203 * \param md_info message digest info
204 *
205 * \return name of the message digest output.
206 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200207const char *mbedtls_md_get_name( const mbedtls_md_info_t *md_info );
Paul Bakker17373852011-01-06 14:20:01 +0000208
209/**
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100210 * \brief Prepare the context to digest a new message.
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200211 * Generally called after mbedtls_md_setup() or mbedtls_md_finish().
212 * Followed by mbedtls_md_update().
Paul Bakker17373852011-01-06 14:20:01 +0000213 *
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100214 * \param ctx generic message digest context.
Paul Bakker17373852011-01-06 14:20:01 +0000215 *
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200216 * \returns 0 on success, MBEDTLS_ERR_MD_BAD_INPUT_DATA if parameter
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100217 * verification fails.
Paul Bakker17373852011-01-06 14:20:01 +0000218 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200219int mbedtls_md_starts( mbedtls_md_context_t *ctx );
Paul Bakker17373852011-01-06 14:20:01 +0000220
221/**
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100222 * \brief Generic message digest process buffer
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200223 * Called between mbedtls_md_starts() and mbedtls_md_finish().
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100224 * May be called repeatedly.
Paul Bakker17373852011-01-06 14:20:01 +0000225 *
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100226 * \param ctx Generic message digest context
227 * \param input buffer holding the datal
228 * \param ilen length of the input data
Paul Bakker17373852011-01-06 14:20:01 +0000229 *
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200230 * \returns 0 on success, MBEDTLS_ERR_MD_BAD_INPUT_DATA if parameter
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100231 * verification fails.
Paul Bakker17373852011-01-06 14:20:01 +0000232 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200233int mbedtls_md_update( mbedtls_md_context_t *ctx, const unsigned char *input, size_t ilen );
Paul Bakker17373852011-01-06 14:20:01 +0000234
235/**
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100236 * \brief Generic message digest final digest
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200237 * Called after mbedtls_md_update().
238 * Usually followed by mbedtls_md_free() or mbedtls_md_starts().
Paul Bakker17373852011-01-06 14:20:01 +0000239 *
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100240 * \param ctx Generic message digest context
241 * \param output Generic message digest checksum result
Paul Bakker17373852011-01-06 14:20:01 +0000242 *
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200243 * \returns 0 on success, MBEDTLS_ERR_MD_BAD_INPUT_DATA if parameter
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100244 * verification fails.
Paul Bakker17373852011-01-06 14:20:01 +0000245 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200246int mbedtls_md_finish( mbedtls_md_context_t *ctx, unsigned char *output );
Paul Bakker17373852011-01-06 14:20:01 +0000247
248/**
Paul Bakker17373852011-01-06 14:20:01 +0000249 * \brief Output = message_digest( input buffer )
250 *
251 * \param md_info message digest info
252 * \param input buffer holding the data
253 * \param ilen length of the input data
254 * \param output Generic message digest checksum result
255 *
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200256 * \returns 0 on success, MBEDTLS_ERR_MD_BAD_INPUT_DATA if parameter
Paul Bakker9c021ad2011-06-09 15:55:11 +0000257 * verification fails.
Paul Bakker17373852011-01-06 14:20:01 +0000258 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200259int mbedtls_md( const mbedtls_md_info_t *md_info, const unsigned char *input, size_t ilen,
Paul Bakker17373852011-01-06 14:20:01 +0000260 unsigned char *output );
261
Manuel Pégourié-Gonnardbfffa902015-05-28 14:44:00 +0200262#if defined(MBEDTLS_FS_IO)
Paul Bakker17373852011-01-06 14:20:01 +0000263/**
264 * \brief Output = message_digest( file contents )
265 *
266 * \param md_info message digest info
267 * \param path input file name
268 * \param output generic message digest checksum result
269 *
Manuel Pégourié-Gonnard932e3932015-04-03 16:37:14 +0200270 * \return 0 if successful,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200271 * MBEDTLS_ERR_MD_FILE_IO_ERROR if file input failed,
272 * MBEDTLS_ERR_MD_BAD_INPUT_DATA if md_info was NULL.
Paul Bakker17373852011-01-06 14:20:01 +0000273 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200274int mbedtls_md_file( const mbedtls_md_info_t *md_info, const char *path,
Manuel Pégourié-Gonnardbfffa902015-05-28 14:44:00 +0200275 unsigned char *output );
276#endif /* MBEDTLS_FS_IO */
Paul Bakker17373852011-01-06 14:20:01 +0000277
278/**
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100279 * \brief Set HMAC key and prepare to authenticate a new message.
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200280 * Usually called after mbedtls_md_setup() or mbedtls_md_hmac_finish().
Paul Bakker17373852011-01-06 14:20:01 +0000281 *
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100282 * \param ctx HMAC context
283 * \param key HMAC secret key
Manuel Pégourié-Gonnardb8186a52015-06-18 14:58:58 +0200284 * \param keylen length of the HMAC key in bytes
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_starts( mbedtls_md_context_t *ctx, const unsigned char *key,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200290 size_t keylen );
Paul Bakker17373852011-01-06 14:20:01 +0000291
292/**
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100293 * \brief Generic HMAC process buffer.
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200294 * Called between mbedtls_md_hmac_starts() or mbedtls_md_hmac_reset()
295 * and mbedtls_md_hmac_finish().
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100296 * May be called repeatedly.
Paul Bakker17373852011-01-06 14:20:01 +0000297 *
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100298 * \param ctx HMAC context
299 * \param input buffer holding the data
300 * \param ilen length of the input data
Paul Bakker17373852011-01-06 14:20:01 +0000301 *
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200302 * \returns 0 on success, MBEDTLS_ERR_MD_BAD_INPUT_DATA if parameter
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100303 * verification fails.
Paul Bakker17373852011-01-06 14:20:01 +0000304 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200305int mbedtls_md_hmac_update( mbedtls_md_context_t *ctx, const unsigned char *input,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200306 size_t ilen );
Paul Bakker17373852011-01-06 14:20:01 +0000307
308/**
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100309 * \brief Output HMAC.
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200310 * Called after mbedtls_md_hmac_update().
311 * Usually followed my mbedtls_md_hmac_reset(), mbedtls_md_hmac_starts(),
312 * or mbedtls_md_free().
Paul Bakker17373852011-01-06 14:20:01 +0000313 *
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100314 * \param ctx HMAC context
315 * \param output Generic HMAC checksum result
Paul Bakker17373852011-01-06 14:20:01 +0000316 *
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200317 * \returns 0 on success, MBEDTLS_ERR_MD_BAD_INPUT_DATA if parameter
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100318 * verification fails.
Paul Bakker17373852011-01-06 14:20:01 +0000319 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200320int mbedtls_md_hmac_finish( mbedtls_md_context_t *ctx, unsigned char *output);
Paul Bakker17373852011-01-06 14:20:01 +0000321
322/**
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100323 * \brief Prepare to authenticate a new message with the same key.
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200324 * Called after mbedtls_md_hmac_finish() and before mbedtls_md_hmac_update().
Paul Bakker17373852011-01-06 14:20:01 +0000325 *
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100326 * \param ctx HMAC context to be reset
Paul Bakker17373852011-01-06 14:20:01 +0000327 *
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200328 * \returns 0 on success, MBEDTLS_ERR_MD_BAD_INPUT_DATA if parameter
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100329 * verification fails.
Paul Bakker17373852011-01-06 14:20:01 +0000330 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200331int mbedtls_md_hmac_reset( mbedtls_md_context_t *ctx );
Paul Bakker17373852011-01-06 14:20:01 +0000332
333/**
334 * \brief Output = Generic_HMAC( hmac key, input buffer )
335 *
336 * \param md_info message digest info
337 * \param key HMAC secret key
Manuel Pégourié-Gonnardb8186a52015-06-18 14:58:58 +0200338 * \param keylen length of the HMAC key in bytes
Paul Bakker17373852011-01-06 14:20:01 +0000339 * \param input buffer holding the data
340 * \param ilen length of the input data
341 * \param output Generic HMAC-result
342 *
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200343 * \returns 0 on success, MBEDTLS_ERR_MD_BAD_INPUT_DATA if parameter
Paul Bakker9c021ad2011-06-09 15:55:11 +0000344 * verification fails.
Paul Bakker17373852011-01-06 14:20:01 +0000345 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200346int mbedtls_md_hmac( const mbedtls_md_info_t *md_info, const unsigned char *key, size_t keylen,
Paul Bakker23986e52011-04-24 08:57:21 +0000347 const unsigned char *input, size_t ilen,
Paul Bakker17373852011-01-06 14:20:01 +0000348 unsigned char *output );
349
Paul Bakker1bd3ae82013-03-13 10:26:44 +0100350/* Internal use */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200351int mbedtls_md_process( mbedtls_md_context_t *ctx, const unsigned char *data );
Paul Bakker1bd3ae82013-03-13 10:26:44 +0100352
Paul Bakker17373852011-01-06 14:20:01 +0000353#ifdef __cplusplus
354}
355#endif
356
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200357#endif /* MBEDTLS_MD_H */