blob: bdea393bc8d41a92c27880b81d8f2d4a248e8812 [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
Hanno Beckerbbca8c52017-09-25 14:53:51 +010047/**
48 * \brief Enumeration of supported message digests
49 *
50 * \warning MD2, MD4, MD5 and SHA-1 are considered weak message digests and
51 * their use constitutes a security risk. We recommend considering
52 * stronger message digests instead.
53 *
54 */
Paul Bakker17373852011-01-06 14:20:01 +000055typedef enum {
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020056 MBEDTLS_MD_NONE=0,
57 MBEDTLS_MD_MD2,
58 MBEDTLS_MD_MD4,
59 MBEDTLS_MD_MD5,
60 MBEDTLS_MD_SHA1,
61 MBEDTLS_MD_SHA224,
62 MBEDTLS_MD_SHA256,
63 MBEDTLS_MD_SHA384,
64 MBEDTLS_MD_SHA512,
65 MBEDTLS_MD_RIPEMD160,
66} mbedtls_md_type_t;
Paul Bakker17373852011-01-06 14:20:01 +000067
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020068#if defined(MBEDTLS_SHA512_C)
69#define MBEDTLS_MD_MAX_SIZE 64 /* longest known is SHA512 */
Paul Bakker7db01092013-09-10 11:10:57 +020070#else
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020071#define MBEDTLS_MD_MAX_SIZE 32 /* longest known is SHA256 or less */
Paul Bakker7db01092013-09-10 11:10:57 +020072#endif
Paul Bakker1b57b062011-01-06 15:48:19 +000073
Paul Bakker17373852011-01-06 14:20:01 +000074/**
Manuel Pégourié-Gonnard50518f42015-05-26 11:04:15 +020075 * Opaque struct defined in md_internal.h
Paul Bakker17373852011-01-06 14:20:01 +000076 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020077typedef struct mbedtls_md_info_t mbedtls_md_info_t;
Paul Bakker17373852011-01-06 14:20:01 +000078
79/**
80 * Generic message digest context.
81 */
82typedef struct {
83 /** Information about the associated message digest */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020084 const mbedtls_md_info_t *md_info;
Paul Bakker17373852011-01-06 14:20:01 +000085
86 /** Digest-specific context */
87 void *md_ctx;
Manuel Pégourié-Gonnard8379a822015-03-24 16:48:22 +010088
Manuel Pégourié-Gonnarddfb3dc82015-03-25 11:49:07 +010089 /** HMAC part of the context */
90 void *hmac_ctx;
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020091} mbedtls_md_context_t;
Paul Bakker17373852011-01-06 14:20:01 +000092
Paul Bakker17373852011-01-06 14:20:01 +000093/**
Paul Bakker72f62662011-01-16 21:27:44 +000094 * \brief Returns the list of digests supported by the generic digest module.
95 *
96 * \return a statically allocated array of digests, the last entry
97 * is 0.
98 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020099const int *mbedtls_md_list( void );
Paul Bakker72f62662011-01-16 21:27:44 +0000100
101/**
Paul Bakker17373852011-01-06 14:20:01 +0000102 * \brief Returns the message digest information associated with the
103 * given digest name.
104 *
Paul Bakker23986e52011-04-24 08:57:21 +0000105 * \param md_name Name of the digest to search for.
Paul Bakker17373852011-01-06 14:20:01 +0000106 *
107 * \return The message digest information associated with md_name or
108 * NULL if not found.
109 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200110const mbedtls_md_info_t *mbedtls_md_info_from_string( const char *md_name );
Paul Bakker17373852011-01-06 14:20:01 +0000111
112/**
113 * \brief Returns the message digest information associated with the
114 * given digest type.
115 *
116 * \param md_type type of digest to search for.
117 *
118 * \return The message digest information associated with md_type or
119 * NULL if not found.
120 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200121const mbedtls_md_info_t *mbedtls_md_info_from_type( mbedtls_md_type_t md_type );
Paul Bakker17373852011-01-06 14:20:01 +0000122
123/**
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100124 * \brief Initialize a md_context (as NONE)
125 * This should always be called first.
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200126 * Prepares the context for mbedtls_md_setup() or mbedtls_md_free().
Paul Bakker84bbeb52014-07-01 14:53:22 +0200127 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200128void mbedtls_md_init( mbedtls_md_context_t *ctx );
Paul Bakker84bbeb52014-07-01 14:53:22 +0200129
130/**
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100131 * \brief Free and clear the internal structures of ctx.
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200132 * Can be called at any time after mbedtls_md_init().
133 * Mandatory once mbedtls_md_setup() has been called.
Paul Bakker84bbeb52014-07-01 14:53:22 +0200134 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200135void mbedtls_md_free( mbedtls_md_context_t *ctx );
Paul Bakker84bbeb52014-07-01 14:53:22 +0200136
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200137#if ! defined(MBEDTLS_DEPRECATED_REMOVED)
138#if defined(MBEDTLS_DEPRECATED_WARNING)
139#define MBEDTLS_DEPRECATED __attribute__((deprecated))
Manuel Pégourié-Gonnard147fa092015-03-25 16:43:14 +0100140#else
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200141#define MBEDTLS_DEPRECATED
Manuel Pégourié-Gonnard147fa092015-03-25 16:43:14 +0100142#endif
143/**
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100144 * \brief Select MD to use and allocate internal structures.
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200145 * Should be called after mbedtls_md_init() or mbedtls_md_free().
146 * Makes it necessary to call mbedtls_md_free() later.
Manuel Pégourié-Gonnard147fa092015-03-25 16:43:14 +0100147 *
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200148 * \deprecated Superseded by mbedtls_md_setup() in 2.0.0
Manuel Pégourié-Gonnard147fa092015-03-25 16:43:14 +0100149 *
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é-Gonnard147fa092015-03-25 16:43:14 +0100152 *
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100153 * \returns \c 0 on success,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200154 * \c MBEDTLS_ERR_MD_BAD_INPUT_DATA on parameter failure,
155 * \c MBEDTLS_ERR_MD_ALLOC_FAILED memory allocation failure.
Manuel Pégourié-Gonnard147fa092015-03-25 16:43:14 +0100156 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200157int mbedtls_md_init_ctx( mbedtls_md_context_t *ctx, const mbedtls_md_info_t *md_info ) MBEDTLS_DEPRECATED;
158#undef MBEDTLS_DEPRECATED
159#endif /* MBEDTLS_DEPRECATED_REMOVED */
Manuel Pégourié-Gonnard147fa092015-03-25 16:43:14 +0100160
Paul Bakker84bbeb52014-07-01 14:53:22 +0200161/**
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100162 * \brief Select MD to use and allocate internal structures.
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200163 * Should be called after mbedtls_md_init() or mbedtls_md_free().
164 * Makes it necessary to call mbedtls_md_free() later.
Paul Bakker562535d2011-01-20 16:42:01 +0000165 *
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100166 * \param ctx Context to set up.
167 * \param md_info Message digest to use.
Manuel Pégourié-Gonnardac50fc52015-08-10 13:07:09 +0200168 * \param hmac 0 to save some memory if HMAC will not be used,
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100169 * non-zero is HMAC is going to be used with this context.
Paul Bakker562535d2011-01-20 16:42:01 +0000170 *
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100171 * \returns \c 0 on success,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200172 * \c MBEDTLS_ERR_MD_BAD_INPUT_DATA on parameter failure,
173 * \c MBEDTLS_ERR_MD_ALLOC_FAILED memory allocation failure.
Paul Bakker562535d2011-01-20 16:42:01 +0000174 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200175int mbedtls_md_setup( mbedtls_md_context_t *ctx, const mbedtls_md_info_t *md_info, int hmac );
Paul Bakker562535d2011-01-20 16:42:01 +0000176
177/**
Manuel Pégourié-Gonnard052a6c92015-07-06 16:06:02 +0200178 * \brief Clone the state of an MD context
179 *
180 * \note The two contexts must have been setup to the same type
181 * (cloning from SHA-256 to SHA-512 make no sense).
182 *
183 * \warning Only clones the MD state, not the HMAC state! (for now)
184 *
185 * \param dst The destination context
186 * \param src The context to be cloned
187 *
188 * \return \c 0 on success,
189 * \c MBEDTLS_ERR_MD_BAD_INPUT_DATA on parameter failure.
190 */
191int mbedtls_md_clone( mbedtls_md_context_t *dst,
192 const mbedtls_md_context_t *src );
193
194/**
Paul Bakker17373852011-01-06 14:20:01 +0000195 * \brief Returns the size of the message digest output.
196 *
197 * \param md_info message digest info
198 *
Manuel Pégourié-Gonnardb8186a52015-06-18 14:58:58 +0200199 * \return size of the message digest output in bytes.
Paul Bakker17373852011-01-06 14:20:01 +0000200 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200201unsigned char mbedtls_md_get_size( const mbedtls_md_info_t *md_info );
Paul Bakker17373852011-01-06 14:20:01 +0000202
203/**
204 * \brief Returns the type of the message digest output.
205 *
206 * \param md_info message digest info
207 *
208 * \return type of the message digest output.
209 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200210mbedtls_md_type_t mbedtls_md_get_type( const mbedtls_md_info_t *md_info );
Paul Bakker17373852011-01-06 14:20:01 +0000211
212/**
213 * \brief Returns the name of the message digest output.
214 *
215 * \param md_info message digest info
216 *
217 * \return name of the message digest output.
218 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200219const char *mbedtls_md_get_name( const mbedtls_md_info_t *md_info );
Paul Bakker17373852011-01-06 14:20:01 +0000220
221/**
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100222 * \brief Prepare the context to digest a new message.
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200223 * Generally called after mbedtls_md_setup() or mbedtls_md_finish().
224 * Followed by mbedtls_md_update().
Paul Bakker17373852011-01-06 14:20:01 +0000225 *
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100226 * \param ctx generic message digest context.
Paul Bakker17373852011-01-06 14:20:01 +0000227 *
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200228 * \returns 0 on success, MBEDTLS_ERR_MD_BAD_INPUT_DATA if parameter
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100229 * verification fails.
Paul Bakker17373852011-01-06 14:20:01 +0000230 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200231int mbedtls_md_starts( mbedtls_md_context_t *ctx );
Paul Bakker17373852011-01-06 14:20:01 +0000232
233/**
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100234 * \brief Generic message digest process buffer
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200235 * Called between mbedtls_md_starts() and mbedtls_md_finish().
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100236 * May be called repeatedly.
Paul Bakker17373852011-01-06 14:20:01 +0000237 *
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100238 * \param ctx Generic message digest context
239 * \param input buffer holding the datal
240 * \param ilen length of the input data
Paul Bakker17373852011-01-06 14:20:01 +0000241 *
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200242 * \returns 0 on success, MBEDTLS_ERR_MD_BAD_INPUT_DATA if parameter
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100243 * verification fails.
Paul Bakker17373852011-01-06 14:20:01 +0000244 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200245int mbedtls_md_update( mbedtls_md_context_t *ctx, const unsigned char *input, size_t ilen );
Paul Bakker17373852011-01-06 14:20:01 +0000246
247/**
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100248 * \brief Generic message digest final digest
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200249 * Called after mbedtls_md_update().
250 * Usually followed by mbedtls_md_free() or mbedtls_md_starts().
Paul Bakker17373852011-01-06 14:20:01 +0000251 *
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100252 * \param ctx Generic message digest context
253 * \param output Generic message digest checksum result
Paul Bakker17373852011-01-06 14:20:01 +0000254 *
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200255 * \returns 0 on success, MBEDTLS_ERR_MD_BAD_INPUT_DATA if parameter
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100256 * verification fails.
Paul Bakker17373852011-01-06 14:20:01 +0000257 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200258int mbedtls_md_finish( mbedtls_md_context_t *ctx, unsigned char *output );
Paul Bakker17373852011-01-06 14:20:01 +0000259
260/**
Paul Bakker17373852011-01-06 14:20:01 +0000261 * \brief Output = message_digest( input buffer )
262 *
263 * \param md_info message digest info
264 * \param input buffer holding the data
265 * \param ilen length of the input data
266 * \param output Generic message digest checksum result
267 *
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200268 * \returns 0 on success, MBEDTLS_ERR_MD_BAD_INPUT_DATA if parameter
Paul Bakker9c021ad2011-06-09 15:55:11 +0000269 * verification fails.
Paul Bakker17373852011-01-06 14:20:01 +0000270 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200271int mbedtls_md( const mbedtls_md_info_t *md_info, const unsigned char *input, size_t ilen,
Paul Bakker17373852011-01-06 14:20:01 +0000272 unsigned char *output );
273
Manuel Pégourié-Gonnardbfffa902015-05-28 14:44:00 +0200274#if defined(MBEDTLS_FS_IO)
Paul Bakker17373852011-01-06 14:20:01 +0000275/**
276 * \brief Output = message_digest( file contents )
277 *
278 * \param md_info message digest info
279 * \param path input file name
280 * \param output generic message digest checksum result
281 *
Manuel Pégourié-Gonnard932e3932015-04-03 16:37:14 +0200282 * \return 0 if successful,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200283 * MBEDTLS_ERR_MD_FILE_IO_ERROR if file input failed,
284 * MBEDTLS_ERR_MD_BAD_INPUT_DATA if md_info was NULL.
Paul Bakker17373852011-01-06 14:20:01 +0000285 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200286int mbedtls_md_file( const mbedtls_md_info_t *md_info, const char *path,
Manuel Pégourié-Gonnardbfffa902015-05-28 14:44:00 +0200287 unsigned char *output );
288#endif /* MBEDTLS_FS_IO */
Paul Bakker17373852011-01-06 14:20:01 +0000289
290/**
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100291 * \brief Set HMAC key and prepare to authenticate a new message.
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200292 * Usually called after mbedtls_md_setup() or mbedtls_md_hmac_finish().
Paul Bakker17373852011-01-06 14:20:01 +0000293 *
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100294 * \param ctx HMAC context
295 * \param key HMAC secret key
Manuel Pégourié-Gonnardb8186a52015-06-18 14:58:58 +0200296 * \param keylen length of the HMAC key in bytes
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_starts( mbedtls_md_context_t *ctx, const unsigned char *key,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200302 size_t keylen );
Paul Bakker17373852011-01-06 14:20:01 +0000303
304/**
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100305 * \brief Generic HMAC process buffer.
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200306 * Called between mbedtls_md_hmac_starts() or mbedtls_md_hmac_reset()
307 * and mbedtls_md_hmac_finish().
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100308 * May be called repeatedly.
Paul Bakker17373852011-01-06 14:20:01 +0000309 *
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100310 * \param ctx HMAC context
311 * \param input buffer holding the data
312 * \param ilen length of the input data
Paul Bakker17373852011-01-06 14:20:01 +0000313 *
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200314 * \returns 0 on success, MBEDTLS_ERR_MD_BAD_INPUT_DATA if parameter
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100315 * verification fails.
Paul Bakker17373852011-01-06 14:20:01 +0000316 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200317int mbedtls_md_hmac_update( mbedtls_md_context_t *ctx, const unsigned char *input,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200318 size_t ilen );
Paul Bakker17373852011-01-06 14:20:01 +0000319
320/**
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100321 * \brief Output HMAC.
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200322 * Called after mbedtls_md_hmac_update().
Simon Butcher01ba45b2016-10-05 14:17:01 +0100323 * Usually followed by mbedtls_md_hmac_reset(),
324 * mbedtls_md_hmac_starts(), or mbedtls_md_free().
Paul Bakker17373852011-01-06 14:20:01 +0000325 *
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100326 * \param ctx HMAC context
327 * \param output Generic HMAC checksum result
Paul Bakker17373852011-01-06 14:20:01 +0000328 *
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200329 * \returns 0 on success, MBEDTLS_ERR_MD_BAD_INPUT_DATA if parameter
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100330 * verification fails.
Paul Bakker17373852011-01-06 14:20:01 +0000331 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200332int mbedtls_md_hmac_finish( mbedtls_md_context_t *ctx, unsigned char *output);
Paul Bakker17373852011-01-06 14:20:01 +0000333
334/**
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100335 * \brief Prepare to authenticate a new message with the same key.
Simon Butcher01ba45b2016-10-05 14:17:01 +0100336 * Called after mbedtls_md_hmac_finish() and before
337 * mbedtls_md_hmac_update().
Paul Bakker17373852011-01-06 14:20:01 +0000338 *
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100339 * \param ctx HMAC context to be reset
Paul Bakker17373852011-01-06 14:20:01 +0000340 *
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200341 * \returns 0 on success, MBEDTLS_ERR_MD_BAD_INPUT_DATA if parameter
Manuel Pégourié-Gonnardeca510f2015-03-26 12:26:34 +0100342 * verification fails.
Paul Bakker17373852011-01-06 14:20:01 +0000343 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200344int mbedtls_md_hmac_reset( mbedtls_md_context_t *ctx );
Paul Bakker17373852011-01-06 14:20:01 +0000345
346/**
347 * \brief Output = Generic_HMAC( hmac key, input buffer )
348 *
349 * \param md_info message digest info
350 * \param key HMAC secret key
Manuel Pégourié-Gonnardb8186a52015-06-18 14:58:58 +0200351 * \param keylen length of the HMAC key in bytes
Paul Bakker17373852011-01-06 14:20:01 +0000352 * \param input buffer holding the data
353 * \param ilen length of the input data
354 * \param output Generic HMAC-result
355 *
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200356 * \returns 0 on success, MBEDTLS_ERR_MD_BAD_INPUT_DATA if parameter
Paul Bakker9c021ad2011-06-09 15:55:11 +0000357 * verification fails.
Paul Bakker17373852011-01-06 14:20:01 +0000358 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200359int mbedtls_md_hmac( const mbedtls_md_info_t *md_info, const unsigned char *key, size_t keylen,
Paul Bakker23986e52011-04-24 08:57:21 +0000360 const unsigned char *input, size_t ilen,
Paul Bakker17373852011-01-06 14:20:01 +0000361 unsigned char *output );
362
Paul Bakker1bd3ae82013-03-13 10:26:44 +0100363/* Internal use */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200364int mbedtls_md_process( mbedtls_md_context_t *ctx, const unsigned char *data );
Paul Bakker1bd3ae82013-03-13 10:26:44 +0100365
Paul Bakker17373852011-01-06 14:20:01 +0000366#ifdef __cplusplus
367}
368#endif
369
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200370#endif /* MBEDTLS_MD_H */