blob: 57c27a6f024a1b7b93ae84f13ecf26eb75c64ebf [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. */
Gilles Peskine7ecab3d2018-01-26 17:56:38 +010041#define MBEDTLS_ERR_MD_HW_ACCEL_FAILED -0x5280 /**< MD hardware accelerator failed. */
Paul Bakker335db3f2011-04-25 15:28:35 +000042
Paul Bakker407a0da2013-06-27 14:29:21 +020043#ifdef __cplusplus
44extern "C" {
45#endif
46
Paul Bakker17373852011-01-06 14:20:01 +000047typedef enum {
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020048 MBEDTLS_MD_NONE=0,
49 MBEDTLS_MD_MD2,
50 MBEDTLS_MD_MD4,
51 MBEDTLS_MD_MD5,
52 MBEDTLS_MD_SHA1,
53 MBEDTLS_MD_SHA224,
54 MBEDTLS_MD_SHA256,
55 MBEDTLS_MD_SHA384,
56 MBEDTLS_MD_SHA512,
57 MBEDTLS_MD_RIPEMD160,
58} mbedtls_md_type_t;
Paul Bakker17373852011-01-06 14:20:01 +000059
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020060#if defined(MBEDTLS_SHA512_C)
61#define MBEDTLS_MD_MAX_SIZE 64 /* longest known is SHA512 */
Paul Bakker7db01092013-09-10 11:10:57 +020062#else
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020063#define MBEDTLS_MD_MAX_SIZE 32 /* longest known is SHA256 or less */
Paul Bakker7db01092013-09-10 11:10:57 +020064#endif
Paul Bakker1b57b062011-01-06 15:48:19 +000065
Paul Bakker17373852011-01-06 14:20:01 +000066/**
Manuel Pégourié-Gonnard50518f42015-05-26 11:04:15 +020067 * Opaque struct defined in md_internal.h
Paul Bakker17373852011-01-06 14:20:01 +000068 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020069typedef struct mbedtls_md_info_t mbedtls_md_info_t;
Paul Bakker17373852011-01-06 14:20:01 +000070
71/**
72 * Generic message digest context.
73 */
74typedef struct {
75 /** Information about the associated message digest */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020076 const mbedtls_md_info_t *md_info;
Paul Bakker17373852011-01-06 14:20:01 +000077
78 /** Digest-specific context */
79 void *md_ctx;
Manuel Pégourié-Gonnard8379a822015-03-24 16:48:22 +010080
Manuel Pégourié-Gonnarddfb3dc82015-03-25 11:49:07 +010081 /** HMAC part of the context */
82 void *hmac_ctx;
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020083} mbedtls_md_context_t;
Paul Bakker17373852011-01-06 14:20:01 +000084
Paul Bakker17373852011-01-06 14:20:01 +000085/**
Paul Bakker72f62662011-01-16 21:27:44 +000086 * \brief Returns the list of digests supported by the generic digest module.
87 *
88 * \return a statically allocated array of digests, the last entry
89 * is 0.
90 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020091const int *mbedtls_md_list( void );
Paul Bakker72f62662011-01-16 21:27:44 +000092
93/**
Paul Bakker17373852011-01-06 14:20:01 +000094 * \brief Returns the message digest information associated with the
95 * given digest name.
96 *
Paul Bakker23986e52011-04-24 08:57:21 +000097 * \param md_name Name of the digest to search for.
Paul Bakker17373852011-01-06 14:20:01 +000098 *
99 * \return The message digest information associated with md_name or
100 * NULL if not found.
101 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200102const mbedtls_md_info_t *mbedtls_md_info_from_string( const char *md_name );
Paul Bakker17373852011-01-06 14:20:01 +0000103
104/**
105 * \brief Returns the message digest information associated with the
106 * given digest type.
107 *
108 * \param md_type type of digest to search for.
109 *
110 * \return The message digest information associated with md_type or
111 * NULL if not found.
112 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200113const mbedtls_md_info_t *mbedtls_md_info_from_type( mbedtls_md_type_t md_type );
Paul Bakker17373852011-01-06 14:20:01 +0000114
115/**
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100116 * \brief Initialize a md_context (as NONE)
117 * This should always be called first.
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200118 * Prepares the context for mbedtls_md_setup() or mbedtls_md_free().
Paul Bakker84bbeb52014-07-01 14:53:22 +0200119 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200120void mbedtls_md_init( mbedtls_md_context_t *ctx );
Paul Bakker84bbeb52014-07-01 14:53:22 +0200121
122/**
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100123 * \brief Free and clear the internal structures of ctx.
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200124 * Can be called at any time after mbedtls_md_init().
125 * Mandatory once mbedtls_md_setup() has been called.
Paul Bakker84bbeb52014-07-01 14:53:22 +0200126 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200127void mbedtls_md_free( mbedtls_md_context_t *ctx );
Paul Bakker84bbeb52014-07-01 14:53:22 +0200128
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200129#if ! defined(MBEDTLS_DEPRECATED_REMOVED)
130#if defined(MBEDTLS_DEPRECATED_WARNING)
131#define MBEDTLS_DEPRECATED __attribute__((deprecated))
Manuel Pégourié-Gonnard147fa092015-03-25 16:43:14 +0100132#else
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200133#define MBEDTLS_DEPRECATED
Manuel Pégourié-Gonnard147fa092015-03-25 16:43:14 +0100134#endif
135/**
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100136 * \brief Select MD to use and allocate internal structures.
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200137 * Should be called after mbedtls_md_init() or mbedtls_md_free().
138 * Makes it necessary to call mbedtls_md_free() later.
Manuel Pégourié-Gonnard147fa092015-03-25 16:43:14 +0100139 *
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200140 * \deprecated Superseded by mbedtls_md_setup() in 2.0.0
Manuel Pégourié-Gonnard147fa092015-03-25 16:43:14 +0100141 *
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100142 * \param ctx Context to set up.
143 * \param md_info Message digest to use.
Manuel Pégourié-Gonnard147fa092015-03-25 16:43:14 +0100144 *
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100145 * \returns \c 0 on success,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200146 * \c MBEDTLS_ERR_MD_BAD_INPUT_DATA on parameter failure,
147 * \c MBEDTLS_ERR_MD_ALLOC_FAILED memory allocation failure.
Manuel Pégourié-Gonnard147fa092015-03-25 16:43:14 +0100148 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200149int mbedtls_md_init_ctx( mbedtls_md_context_t *ctx, const mbedtls_md_info_t *md_info ) MBEDTLS_DEPRECATED;
150#undef MBEDTLS_DEPRECATED
151#endif /* MBEDTLS_DEPRECATED_REMOVED */
Manuel Pégourié-Gonnard147fa092015-03-25 16:43:14 +0100152
Paul Bakker84bbeb52014-07-01 14:53:22 +0200153/**
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100154 * \brief Select MD to use and allocate internal structures.
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200155 * Should be called after mbedtls_md_init() or mbedtls_md_free().
156 * Makes it necessary to call mbedtls_md_free() later.
Paul Bakker562535d2011-01-20 16:42:01 +0000157 *
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100158 * \param ctx Context to set up.
159 * \param md_info Message digest to use.
Manuel Pégourié-Gonnardac50fc52015-08-10 13:07:09 +0200160 * \param hmac 0 to save some memory if HMAC will not be used,
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100161 * non-zero is HMAC is going to be used with this context.
Paul Bakker562535d2011-01-20 16:42:01 +0000162 *
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100163 * \returns \c 0 on success,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200164 * \c MBEDTLS_ERR_MD_BAD_INPUT_DATA on parameter failure,
165 * \c MBEDTLS_ERR_MD_ALLOC_FAILED memory allocation failure.
Paul Bakker562535d2011-01-20 16:42:01 +0000166 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200167int mbedtls_md_setup( mbedtls_md_context_t *ctx, const mbedtls_md_info_t *md_info, int hmac );
Paul Bakker562535d2011-01-20 16:42:01 +0000168
169/**
Manuel Pégourié-Gonnard052a6c92015-07-06 16:06:02 +0200170 * \brief Clone the state of an MD context
171 *
172 * \note The two contexts must have been setup to the same type
173 * (cloning from SHA-256 to SHA-512 make no sense).
174 *
175 * \warning Only clones the MD state, not the HMAC state! (for now)
176 *
177 * \param dst The destination context
178 * \param src The context to be cloned
179 *
180 * \return \c 0 on success,
181 * \c MBEDTLS_ERR_MD_BAD_INPUT_DATA on parameter failure.
182 */
183int mbedtls_md_clone( mbedtls_md_context_t *dst,
184 const mbedtls_md_context_t *src );
185
186/**
Paul Bakker17373852011-01-06 14:20:01 +0000187 * \brief Returns the size of the message digest output.
188 *
189 * \param md_info message digest info
190 *
Manuel Pégourié-Gonnardb8186a52015-06-18 14:58:58 +0200191 * \return size of the message digest output in bytes.
Paul Bakker17373852011-01-06 14:20:01 +0000192 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200193unsigned char mbedtls_md_get_size( const mbedtls_md_info_t *md_info );
Paul Bakker17373852011-01-06 14:20:01 +0000194
195/**
196 * \brief Returns the type of the message digest output.
197 *
198 * \param md_info message digest info
199 *
200 * \return type of the message digest output.
201 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200202mbedtls_md_type_t mbedtls_md_get_type( const mbedtls_md_info_t *md_info );
Paul Bakker17373852011-01-06 14:20:01 +0000203
204/**
205 * \brief Returns the name of the message digest output.
206 *
207 * \param md_info message digest info
208 *
209 * \return name of the message digest output.
210 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200211const char *mbedtls_md_get_name( const mbedtls_md_info_t *md_info );
Paul Bakker17373852011-01-06 14:20:01 +0000212
213/**
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100214 * \brief Prepare the context to digest a new message.
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200215 * Generally called after mbedtls_md_setup() or mbedtls_md_finish().
216 * Followed by mbedtls_md_update().
Paul Bakker17373852011-01-06 14:20:01 +0000217 *
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100218 * \param ctx generic message digest context.
Paul Bakker17373852011-01-06 14:20:01 +0000219 *
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200220 * \returns 0 on success, MBEDTLS_ERR_MD_BAD_INPUT_DATA if parameter
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100221 * verification fails.
Paul Bakker17373852011-01-06 14:20:01 +0000222 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200223int mbedtls_md_starts( mbedtls_md_context_t *ctx );
Paul Bakker17373852011-01-06 14:20:01 +0000224
225/**
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100226 * \brief Generic message digest process buffer
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200227 * Called between mbedtls_md_starts() and mbedtls_md_finish().
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100228 * May be called repeatedly.
Paul Bakker17373852011-01-06 14:20:01 +0000229 *
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100230 * \param ctx Generic message digest context
231 * \param input buffer holding the datal
232 * \param ilen length of the input data
Paul Bakker17373852011-01-06 14:20:01 +0000233 *
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200234 * \returns 0 on success, MBEDTLS_ERR_MD_BAD_INPUT_DATA if parameter
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100235 * verification fails.
Paul Bakker17373852011-01-06 14:20:01 +0000236 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200237int mbedtls_md_update( mbedtls_md_context_t *ctx, const unsigned char *input, size_t ilen );
Paul Bakker17373852011-01-06 14:20:01 +0000238
239/**
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100240 * \brief Generic message digest final digest
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200241 * Called after mbedtls_md_update().
242 * Usually followed by mbedtls_md_free() or mbedtls_md_starts().
Paul Bakker17373852011-01-06 14:20:01 +0000243 *
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100244 * \param ctx Generic message digest context
245 * \param output Generic message digest checksum result
Paul Bakker17373852011-01-06 14:20:01 +0000246 *
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200247 * \returns 0 on success, MBEDTLS_ERR_MD_BAD_INPUT_DATA if parameter
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100248 * verification fails.
Paul Bakker17373852011-01-06 14:20:01 +0000249 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200250int mbedtls_md_finish( mbedtls_md_context_t *ctx, unsigned char *output );
Paul Bakker17373852011-01-06 14:20:01 +0000251
252/**
Paul Bakker17373852011-01-06 14:20:01 +0000253 * \brief Output = message_digest( input buffer )
254 *
255 * \param md_info message digest info
256 * \param input buffer holding the data
257 * \param ilen length of the input data
258 * \param output Generic message digest checksum result
259 *
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200260 * \returns 0 on success, MBEDTLS_ERR_MD_BAD_INPUT_DATA if parameter
Paul Bakker9c021ad2011-06-09 15:55:11 +0000261 * verification fails.
Paul Bakker17373852011-01-06 14:20:01 +0000262 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200263int mbedtls_md( const mbedtls_md_info_t *md_info, const unsigned char *input, size_t ilen,
Paul Bakker17373852011-01-06 14:20:01 +0000264 unsigned char *output );
265
Manuel Pégourié-Gonnardbfffa902015-05-28 14:44:00 +0200266#if defined(MBEDTLS_FS_IO)
Paul Bakker17373852011-01-06 14:20:01 +0000267/**
268 * \brief Output = message_digest( file contents )
269 *
270 * \param md_info message digest info
271 * \param path input file name
272 * \param output generic message digest checksum result
273 *
Manuel Pégourié-Gonnard932e3932015-04-03 16:37:14 +0200274 * \return 0 if successful,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200275 * MBEDTLS_ERR_MD_FILE_IO_ERROR if file input failed,
276 * MBEDTLS_ERR_MD_BAD_INPUT_DATA if md_info was NULL.
Paul Bakker17373852011-01-06 14:20:01 +0000277 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200278int mbedtls_md_file( const mbedtls_md_info_t *md_info, const char *path,
Manuel Pégourié-Gonnardbfffa902015-05-28 14:44:00 +0200279 unsigned char *output );
280#endif /* MBEDTLS_FS_IO */
Paul Bakker17373852011-01-06 14:20:01 +0000281
282/**
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100283 * \brief Set HMAC key and prepare to authenticate a new message.
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200284 * Usually called after mbedtls_md_setup() or mbedtls_md_hmac_finish().
Paul Bakker17373852011-01-06 14:20:01 +0000285 *
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100286 * \param ctx HMAC context
287 * \param key HMAC secret key
Manuel Pégourié-Gonnardb8186a52015-06-18 14:58:58 +0200288 * \param keylen length of the HMAC key in bytes
Paul Bakker17373852011-01-06 14:20:01 +0000289 *
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200290 * \returns 0 on success, MBEDTLS_ERR_MD_BAD_INPUT_DATA if parameter
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100291 * verification fails.
Paul Bakker17373852011-01-06 14:20:01 +0000292 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200293int mbedtls_md_hmac_starts( mbedtls_md_context_t *ctx, const unsigned char *key,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200294 size_t keylen );
Paul Bakker17373852011-01-06 14:20:01 +0000295
296/**
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100297 * \brief Generic HMAC process buffer.
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200298 * Called between mbedtls_md_hmac_starts() or mbedtls_md_hmac_reset()
299 * and mbedtls_md_hmac_finish().
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100300 * May be called repeatedly.
Paul Bakker17373852011-01-06 14:20:01 +0000301 *
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100302 * \param ctx HMAC context
303 * \param input buffer holding the data
304 * \param ilen length of the input data
Paul Bakker17373852011-01-06 14:20:01 +0000305 *
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200306 * \returns 0 on success, MBEDTLS_ERR_MD_BAD_INPUT_DATA if parameter
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100307 * verification fails.
Paul Bakker17373852011-01-06 14:20:01 +0000308 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200309int mbedtls_md_hmac_update( mbedtls_md_context_t *ctx, const unsigned char *input,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200310 size_t ilen );
Paul Bakker17373852011-01-06 14:20:01 +0000311
312/**
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100313 * \brief Output HMAC.
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200314 * Called after mbedtls_md_hmac_update().
Simon Butcher01ba45b2016-10-05 14:17:01 +0100315 * Usually followed by mbedtls_md_hmac_reset(),
316 * mbedtls_md_hmac_starts(), or mbedtls_md_free().
Paul Bakker17373852011-01-06 14:20:01 +0000317 *
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100318 * \param ctx HMAC context
319 * \param output Generic HMAC checksum result
Paul Bakker17373852011-01-06 14:20:01 +0000320 *
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200321 * \returns 0 on success, MBEDTLS_ERR_MD_BAD_INPUT_DATA if parameter
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100322 * verification fails.
Paul Bakker17373852011-01-06 14:20:01 +0000323 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200324int mbedtls_md_hmac_finish( mbedtls_md_context_t *ctx, unsigned char *output);
Paul Bakker17373852011-01-06 14:20:01 +0000325
326/**
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100327 * \brief Prepare to authenticate a new message with the same key.
Simon Butcher01ba45b2016-10-05 14:17:01 +0100328 * Called after mbedtls_md_hmac_finish() and before
329 * mbedtls_md_hmac_update().
Paul Bakker17373852011-01-06 14:20:01 +0000330 *
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100331 * \param ctx HMAC context to be reset
Paul Bakker17373852011-01-06 14:20:01 +0000332 *
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200333 * \returns 0 on success, MBEDTLS_ERR_MD_BAD_INPUT_DATA if parameter
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100334 * verification fails.
Paul Bakker17373852011-01-06 14:20:01 +0000335 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200336int mbedtls_md_hmac_reset( mbedtls_md_context_t *ctx );
Paul Bakker17373852011-01-06 14:20:01 +0000337
338/**
339 * \brief Output = Generic_HMAC( hmac key, input buffer )
340 *
341 * \param md_info message digest info
342 * \param key HMAC secret key
Manuel Pégourié-Gonnardb8186a52015-06-18 14:58:58 +0200343 * \param keylen length of the HMAC key in bytes
Paul Bakker17373852011-01-06 14:20:01 +0000344 * \param input buffer holding the data
345 * \param ilen length of the input data
346 * \param output Generic HMAC-result
347 *
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200348 * \returns 0 on success, MBEDTLS_ERR_MD_BAD_INPUT_DATA if parameter
Paul Bakker9c021ad2011-06-09 15:55:11 +0000349 * verification fails.
Paul Bakker17373852011-01-06 14:20:01 +0000350 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200351int mbedtls_md_hmac( const mbedtls_md_info_t *md_info, const unsigned char *key, size_t keylen,
Paul Bakker23986e52011-04-24 08:57:21 +0000352 const unsigned char *input, size_t ilen,
Paul Bakker17373852011-01-06 14:20:01 +0000353 unsigned char *output );
354
Paul Bakker1bd3ae82013-03-13 10:26:44 +0100355/* Internal use */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200356int mbedtls_md_process( mbedtls_md_context_t *ctx, const unsigned char *data );
Paul Bakker1bd3ae82013-03-13 10:26:44 +0100357
Paul Bakker17373852011-01-06 14:20:01 +0000358#ifdef __cplusplus
359}
360#endif
361
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200362#endif /* MBEDTLS_MD_H */