This is a fork due to permission issues

Dependencies:   mbed Socket lwip-eth lwip-sys lwip

Fork of 6_songs-from-the-cloud by MakingMusicWorkshop

Committer:
maclobdell
Date:
Wed May 18 19:06:32 2016 +0000
Revision:
0:f7c60d3e7b8a
clean version

Who changed what in which revision?

UserRevisionLine numberNew contents of line
maclobdell 0:f7c60d3e7b8a 1 /**
maclobdell 0:f7c60d3e7b8a 2 * \file mbedtls_md.h
maclobdell 0:f7c60d3e7b8a 3 *
maclobdell 0:f7c60d3e7b8a 4 * \brief Generic message digest wrapper
maclobdell 0:f7c60d3e7b8a 5 *
maclobdell 0:f7c60d3e7b8a 6 * \author Adriaan de Jong <dejong@fox-it.com>
maclobdell 0:f7c60d3e7b8a 7 *
maclobdell 0:f7c60d3e7b8a 8 * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
maclobdell 0:f7c60d3e7b8a 9 * SPDX-License-Identifier: Apache-2.0
maclobdell 0:f7c60d3e7b8a 10 *
maclobdell 0:f7c60d3e7b8a 11 * Licensed under the Apache License, Version 2.0 (the "License"); you may
maclobdell 0:f7c60d3e7b8a 12 * not use this file except in compliance with the License.
maclobdell 0:f7c60d3e7b8a 13 * You may obtain a copy of the License at
maclobdell 0:f7c60d3e7b8a 14 *
maclobdell 0:f7c60d3e7b8a 15 * http://www.apache.org/licenses/LICENSE-2.0
maclobdell 0:f7c60d3e7b8a 16 *
maclobdell 0:f7c60d3e7b8a 17 * Unless required by applicable law or agreed to in writing, software
maclobdell 0:f7c60d3e7b8a 18 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
maclobdell 0:f7c60d3e7b8a 19 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
maclobdell 0:f7c60d3e7b8a 20 * See the License for the specific language governing permissions and
maclobdell 0:f7c60d3e7b8a 21 * limitations under the License.
maclobdell 0:f7c60d3e7b8a 22 *
maclobdell 0:f7c60d3e7b8a 23 * This file is part of mbed TLS (https://tls.mbed.org)
maclobdell 0:f7c60d3e7b8a 24 */
maclobdell 0:f7c60d3e7b8a 25 #ifndef MBEDTLS_MD_H
maclobdell 0:f7c60d3e7b8a 26 #define MBEDTLS_MD_H
maclobdell 0:f7c60d3e7b8a 27
maclobdell 0:f7c60d3e7b8a 28 #include <stddef.h>
maclobdell 0:f7c60d3e7b8a 29
maclobdell 0:f7c60d3e7b8a 30 #define MBEDTLS_ERR_MD_FEATURE_UNAVAILABLE -0x5080 /**< The selected feature is not available. */
maclobdell 0:f7c60d3e7b8a 31 #define MBEDTLS_ERR_MD_BAD_INPUT_DATA -0x5100 /**< Bad input parameters to function. */
maclobdell 0:f7c60d3e7b8a 32 #define MBEDTLS_ERR_MD_ALLOC_FAILED -0x5180 /**< Failed to allocate memory. */
maclobdell 0:f7c60d3e7b8a 33 #define MBEDTLS_ERR_MD_FILE_IO_ERROR -0x5200 /**< Opening or reading of file failed. */
maclobdell 0:f7c60d3e7b8a 34
maclobdell 0:f7c60d3e7b8a 35 #ifdef __cplusplus
maclobdell 0:f7c60d3e7b8a 36 extern "C" {
maclobdell 0:f7c60d3e7b8a 37 #endif
maclobdell 0:f7c60d3e7b8a 38
maclobdell 0:f7c60d3e7b8a 39 typedef enum {
maclobdell 0:f7c60d3e7b8a 40 MBEDTLS_MD_NONE=0,
maclobdell 0:f7c60d3e7b8a 41 MBEDTLS_MD_MD2,
maclobdell 0:f7c60d3e7b8a 42 MBEDTLS_MD_MD4,
maclobdell 0:f7c60d3e7b8a 43 MBEDTLS_MD_MD5,
maclobdell 0:f7c60d3e7b8a 44 MBEDTLS_MD_SHA1,
maclobdell 0:f7c60d3e7b8a 45 MBEDTLS_MD_SHA224,
maclobdell 0:f7c60d3e7b8a 46 MBEDTLS_MD_SHA256,
maclobdell 0:f7c60d3e7b8a 47 MBEDTLS_MD_SHA384,
maclobdell 0:f7c60d3e7b8a 48 MBEDTLS_MD_SHA512,
maclobdell 0:f7c60d3e7b8a 49 MBEDTLS_MD_RIPEMD160,
maclobdell 0:f7c60d3e7b8a 50 } mbedtls_md_type_t;
maclobdell 0:f7c60d3e7b8a 51
maclobdell 0:f7c60d3e7b8a 52 #if defined(MBEDTLS_SHA512_C)
maclobdell 0:f7c60d3e7b8a 53 #define MBEDTLS_MD_MAX_SIZE 64 /* longest known is SHA512 */
maclobdell 0:f7c60d3e7b8a 54 #else
maclobdell 0:f7c60d3e7b8a 55 #define MBEDTLS_MD_MAX_SIZE 32 /* longest known is SHA256 or less */
maclobdell 0:f7c60d3e7b8a 56 #endif
maclobdell 0:f7c60d3e7b8a 57
maclobdell 0:f7c60d3e7b8a 58 /**
maclobdell 0:f7c60d3e7b8a 59 * Opaque struct defined in md_internal.h
maclobdell 0:f7c60d3e7b8a 60 */
maclobdell 0:f7c60d3e7b8a 61 typedef struct mbedtls_md_info_t mbedtls_md_info_t;
maclobdell 0:f7c60d3e7b8a 62
maclobdell 0:f7c60d3e7b8a 63 /**
maclobdell 0:f7c60d3e7b8a 64 * Generic message digest context.
maclobdell 0:f7c60d3e7b8a 65 */
maclobdell 0:f7c60d3e7b8a 66 typedef struct {
maclobdell 0:f7c60d3e7b8a 67 /** Information about the associated message digest */
maclobdell 0:f7c60d3e7b8a 68 const mbedtls_md_info_t *md_info;
maclobdell 0:f7c60d3e7b8a 69
maclobdell 0:f7c60d3e7b8a 70 /** Digest-specific context */
maclobdell 0:f7c60d3e7b8a 71 void *md_ctx;
maclobdell 0:f7c60d3e7b8a 72
maclobdell 0:f7c60d3e7b8a 73 /** HMAC part of the context */
maclobdell 0:f7c60d3e7b8a 74 void *hmac_ctx;
maclobdell 0:f7c60d3e7b8a 75 } mbedtls_md_context_t;
maclobdell 0:f7c60d3e7b8a 76
maclobdell 0:f7c60d3e7b8a 77 /**
maclobdell 0:f7c60d3e7b8a 78 * \brief Returns the list of digests supported by the generic digest module.
maclobdell 0:f7c60d3e7b8a 79 *
maclobdell 0:f7c60d3e7b8a 80 * \return a statically allocated array of digests, the last entry
maclobdell 0:f7c60d3e7b8a 81 * is 0.
maclobdell 0:f7c60d3e7b8a 82 */
maclobdell 0:f7c60d3e7b8a 83 const int *mbedtls_md_list( void );
maclobdell 0:f7c60d3e7b8a 84
maclobdell 0:f7c60d3e7b8a 85 /**
maclobdell 0:f7c60d3e7b8a 86 * \brief Returns the message digest information associated with the
maclobdell 0:f7c60d3e7b8a 87 * given digest name.
maclobdell 0:f7c60d3e7b8a 88 *
maclobdell 0:f7c60d3e7b8a 89 * \param md_name Name of the digest to search for.
maclobdell 0:f7c60d3e7b8a 90 *
maclobdell 0:f7c60d3e7b8a 91 * \return The message digest information associated with md_name or
maclobdell 0:f7c60d3e7b8a 92 * NULL if not found.
maclobdell 0:f7c60d3e7b8a 93 */
maclobdell 0:f7c60d3e7b8a 94 const mbedtls_md_info_t *mbedtls_md_info_from_string( const char *md_name );
maclobdell 0:f7c60d3e7b8a 95
maclobdell 0:f7c60d3e7b8a 96 /**
maclobdell 0:f7c60d3e7b8a 97 * \brief Returns the message digest information associated with the
maclobdell 0:f7c60d3e7b8a 98 * given digest type.
maclobdell 0:f7c60d3e7b8a 99 *
maclobdell 0:f7c60d3e7b8a 100 * \param md_type type of digest to search for.
maclobdell 0:f7c60d3e7b8a 101 *
maclobdell 0:f7c60d3e7b8a 102 * \return The message digest information associated with md_type or
maclobdell 0:f7c60d3e7b8a 103 * NULL if not found.
maclobdell 0:f7c60d3e7b8a 104 */
maclobdell 0:f7c60d3e7b8a 105 const mbedtls_md_info_t *mbedtls_md_info_from_type( mbedtls_md_type_t md_type );
maclobdell 0:f7c60d3e7b8a 106
maclobdell 0:f7c60d3e7b8a 107 /**
maclobdell 0:f7c60d3e7b8a 108 * \brief Initialize a md_context (as NONE)
maclobdell 0:f7c60d3e7b8a 109 * This should always be called first.
maclobdell 0:f7c60d3e7b8a 110 * Prepares the context for mbedtls_md_setup() or mbedtls_md_free().
maclobdell 0:f7c60d3e7b8a 111 */
maclobdell 0:f7c60d3e7b8a 112 void mbedtls_md_init( mbedtls_md_context_t *ctx );
maclobdell 0:f7c60d3e7b8a 113
maclobdell 0:f7c60d3e7b8a 114 /**
maclobdell 0:f7c60d3e7b8a 115 * \brief Free and clear the internal structures of ctx.
maclobdell 0:f7c60d3e7b8a 116 * Can be called at any time after mbedtls_md_init().
maclobdell 0:f7c60d3e7b8a 117 * Mandatory once mbedtls_md_setup() has been called.
maclobdell 0:f7c60d3e7b8a 118 */
maclobdell 0:f7c60d3e7b8a 119 void mbedtls_md_free( mbedtls_md_context_t *ctx );
maclobdell 0:f7c60d3e7b8a 120
maclobdell 0:f7c60d3e7b8a 121 #if ! defined(MBEDTLS_DEPRECATED_REMOVED)
maclobdell 0:f7c60d3e7b8a 122 #if defined(MBEDTLS_DEPRECATED_WARNING)
maclobdell 0:f7c60d3e7b8a 123 #define MBEDTLS_DEPRECATED __attribute__((deprecated))
maclobdell 0:f7c60d3e7b8a 124 #else
maclobdell 0:f7c60d3e7b8a 125 #define MBEDTLS_DEPRECATED
maclobdell 0:f7c60d3e7b8a 126 #endif
maclobdell 0:f7c60d3e7b8a 127 /**
maclobdell 0:f7c60d3e7b8a 128 * \brief Select MD to use and allocate internal structures.
maclobdell 0:f7c60d3e7b8a 129 * Should be called after mbedtls_md_init() or mbedtls_md_free().
maclobdell 0:f7c60d3e7b8a 130 * Makes it necessary to call mbedtls_md_free() later.
maclobdell 0:f7c60d3e7b8a 131 *
maclobdell 0:f7c60d3e7b8a 132 * \deprecated Superseded by mbedtls_md_setup() in 2.0.0
maclobdell 0:f7c60d3e7b8a 133 *
maclobdell 0:f7c60d3e7b8a 134 * \param ctx Context to set up.
maclobdell 0:f7c60d3e7b8a 135 * \param md_info Message digest to use.
maclobdell 0:f7c60d3e7b8a 136 *
maclobdell 0:f7c60d3e7b8a 137 * \returns \c 0 on success,
maclobdell 0:f7c60d3e7b8a 138 * \c MBEDTLS_ERR_MD_BAD_INPUT_DATA on parameter failure,
maclobdell 0:f7c60d3e7b8a 139 * \c MBEDTLS_ERR_MD_ALLOC_FAILED memory allocation failure.
maclobdell 0:f7c60d3e7b8a 140 */
maclobdell 0:f7c60d3e7b8a 141 int mbedtls_md_init_ctx( mbedtls_md_context_t *ctx, const mbedtls_md_info_t *md_info ) MBEDTLS_DEPRECATED;
maclobdell 0:f7c60d3e7b8a 142 #undef MBEDTLS_DEPRECATED
maclobdell 0:f7c60d3e7b8a 143 #endif /* MBEDTLS_DEPRECATED_REMOVED */
maclobdell 0:f7c60d3e7b8a 144
maclobdell 0:f7c60d3e7b8a 145 /**
maclobdell 0:f7c60d3e7b8a 146 * \brief Select MD to use and allocate internal structures.
maclobdell 0:f7c60d3e7b8a 147 * Should be called after mbedtls_md_init() or mbedtls_md_free().
maclobdell 0:f7c60d3e7b8a 148 * Makes it necessary to call mbedtls_md_free() later.
maclobdell 0:f7c60d3e7b8a 149 *
maclobdell 0:f7c60d3e7b8a 150 * \param ctx Context to set up.
maclobdell 0:f7c60d3e7b8a 151 * \param md_info Message digest to use.
maclobdell 0:f7c60d3e7b8a 152 * \param hmac 0 to save some memory if HMAC will not be used,
maclobdell 0:f7c60d3e7b8a 153 * non-zero is HMAC is going to be used with this context.
maclobdell 0:f7c60d3e7b8a 154 *
maclobdell 0:f7c60d3e7b8a 155 * \returns \c 0 on success,
maclobdell 0:f7c60d3e7b8a 156 * \c MBEDTLS_ERR_MD_BAD_INPUT_DATA on parameter failure,
maclobdell 0:f7c60d3e7b8a 157 * \c MBEDTLS_ERR_MD_ALLOC_FAILED memory allocation failure.
maclobdell 0:f7c60d3e7b8a 158 */
maclobdell 0:f7c60d3e7b8a 159 int mbedtls_md_setup( mbedtls_md_context_t *ctx, const mbedtls_md_info_t *md_info, int hmac );
maclobdell 0:f7c60d3e7b8a 160
maclobdell 0:f7c60d3e7b8a 161 /**
maclobdell 0:f7c60d3e7b8a 162 * \brief Clone the state of an MD context
maclobdell 0:f7c60d3e7b8a 163 *
maclobdell 0:f7c60d3e7b8a 164 * \note The two contexts must have been setup to the same type
maclobdell 0:f7c60d3e7b8a 165 * (cloning from SHA-256 to SHA-512 make no sense).
maclobdell 0:f7c60d3e7b8a 166 *
maclobdell 0:f7c60d3e7b8a 167 * \warning Only clones the MD state, not the HMAC state! (for now)
maclobdell 0:f7c60d3e7b8a 168 *
maclobdell 0:f7c60d3e7b8a 169 * \param dst The destination context
maclobdell 0:f7c60d3e7b8a 170 * \param src The context to be cloned
maclobdell 0:f7c60d3e7b8a 171 *
maclobdell 0:f7c60d3e7b8a 172 * \return \c 0 on success,
maclobdell 0:f7c60d3e7b8a 173 * \c MBEDTLS_ERR_MD_BAD_INPUT_DATA on parameter failure.
maclobdell 0:f7c60d3e7b8a 174 */
maclobdell 0:f7c60d3e7b8a 175 int mbedtls_md_clone( mbedtls_md_context_t *dst,
maclobdell 0:f7c60d3e7b8a 176 const mbedtls_md_context_t *src );
maclobdell 0:f7c60d3e7b8a 177
maclobdell 0:f7c60d3e7b8a 178 /**
maclobdell 0:f7c60d3e7b8a 179 * \brief Returns the size of the message digest output.
maclobdell 0:f7c60d3e7b8a 180 *
maclobdell 0:f7c60d3e7b8a 181 * \param md_info message digest info
maclobdell 0:f7c60d3e7b8a 182 *
maclobdell 0:f7c60d3e7b8a 183 * \return size of the message digest output in bytes.
maclobdell 0:f7c60d3e7b8a 184 */
maclobdell 0:f7c60d3e7b8a 185 unsigned char mbedtls_md_get_size( const mbedtls_md_info_t *md_info );
maclobdell 0:f7c60d3e7b8a 186
maclobdell 0:f7c60d3e7b8a 187 /**
maclobdell 0:f7c60d3e7b8a 188 * \brief Returns the type of the message digest output.
maclobdell 0:f7c60d3e7b8a 189 *
maclobdell 0:f7c60d3e7b8a 190 * \param md_info message digest info
maclobdell 0:f7c60d3e7b8a 191 *
maclobdell 0:f7c60d3e7b8a 192 * \return type of the message digest output.
maclobdell 0:f7c60d3e7b8a 193 */
maclobdell 0:f7c60d3e7b8a 194 mbedtls_md_type_t mbedtls_md_get_type( const mbedtls_md_info_t *md_info );
maclobdell 0:f7c60d3e7b8a 195
maclobdell 0:f7c60d3e7b8a 196 /**
maclobdell 0:f7c60d3e7b8a 197 * \brief Returns the name of the message digest output.
maclobdell 0:f7c60d3e7b8a 198 *
maclobdell 0:f7c60d3e7b8a 199 * \param md_info message digest info
maclobdell 0:f7c60d3e7b8a 200 *
maclobdell 0:f7c60d3e7b8a 201 * \return name of the message digest output.
maclobdell 0:f7c60d3e7b8a 202 */
maclobdell 0:f7c60d3e7b8a 203 const char *mbedtls_md_get_name( const mbedtls_md_info_t *md_info );
maclobdell 0:f7c60d3e7b8a 204
maclobdell 0:f7c60d3e7b8a 205 /**
maclobdell 0:f7c60d3e7b8a 206 * \brief Prepare the context to digest a new message.
maclobdell 0:f7c60d3e7b8a 207 * Generally called after mbedtls_md_setup() or mbedtls_md_finish().
maclobdell 0:f7c60d3e7b8a 208 * Followed by mbedtls_md_update().
maclobdell 0:f7c60d3e7b8a 209 *
maclobdell 0:f7c60d3e7b8a 210 * \param ctx generic message digest context.
maclobdell 0:f7c60d3e7b8a 211 *
maclobdell 0:f7c60d3e7b8a 212 * \returns 0 on success, MBEDTLS_ERR_MD_BAD_INPUT_DATA if parameter
maclobdell 0:f7c60d3e7b8a 213 * verification fails.
maclobdell 0:f7c60d3e7b8a 214 */
maclobdell 0:f7c60d3e7b8a 215 int mbedtls_md_starts( mbedtls_md_context_t *ctx );
maclobdell 0:f7c60d3e7b8a 216
maclobdell 0:f7c60d3e7b8a 217 /**
maclobdell 0:f7c60d3e7b8a 218 * \brief Generic message digest process buffer
maclobdell 0:f7c60d3e7b8a 219 * Called between mbedtls_md_starts() and mbedtls_md_finish().
maclobdell 0:f7c60d3e7b8a 220 * May be called repeatedly.
maclobdell 0:f7c60d3e7b8a 221 *
maclobdell 0:f7c60d3e7b8a 222 * \param ctx Generic message digest context
maclobdell 0:f7c60d3e7b8a 223 * \param input buffer holding the datal
maclobdell 0:f7c60d3e7b8a 224 * \param ilen length of the input data
maclobdell 0:f7c60d3e7b8a 225 *
maclobdell 0:f7c60d3e7b8a 226 * \returns 0 on success, MBEDTLS_ERR_MD_BAD_INPUT_DATA if parameter
maclobdell 0:f7c60d3e7b8a 227 * verification fails.
maclobdell 0:f7c60d3e7b8a 228 */
maclobdell 0:f7c60d3e7b8a 229 int mbedtls_md_update( mbedtls_md_context_t *ctx, const unsigned char *input, size_t ilen );
maclobdell 0:f7c60d3e7b8a 230
maclobdell 0:f7c60d3e7b8a 231 /**
maclobdell 0:f7c60d3e7b8a 232 * \brief Generic message digest final digest
maclobdell 0:f7c60d3e7b8a 233 * Called after mbedtls_md_update().
maclobdell 0:f7c60d3e7b8a 234 * Usually followed by mbedtls_md_free() or mbedtls_md_starts().
maclobdell 0:f7c60d3e7b8a 235 *
maclobdell 0:f7c60d3e7b8a 236 * \param ctx Generic message digest context
maclobdell 0:f7c60d3e7b8a 237 * \param output Generic message digest checksum result
maclobdell 0:f7c60d3e7b8a 238 *
maclobdell 0:f7c60d3e7b8a 239 * \returns 0 on success, MBEDTLS_ERR_MD_BAD_INPUT_DATA if parameter
maclobdell 0:f7c60d3e7b8a 240 * verification fails.
maclobdell 0:f7c60d3e7b8a 241 */
maclobdell 0:f7c60d3e7b8a 242 int mbedtls_md_finish( mbedtls_md_context_t *ctx, unsigned char *output );
maclobdell 0:f7c60d3e7b8a 243
maclobdell 0:f7c60d3e7b8a 244 /**
maclobdell 0:f7c60d3e7b8a 245 * \brief Output = message_digest( input buffer )
maclobdell 0:f7c60d3e7b8a 246 *
maclobdell 0:f7c60d3e7b8a 247 * \param md_info message digest info
maclobdell 0:f7c60d3e7b8a 248 * \param input buffer holding the data
maclobdell 0:f7c60d3e7b8a 249 * \param ilen length of the input data
maclobdell 0:f7c60d3e7b8a 250 * \param output Generic message digest checksum result
maclobdell 0:f7c60d3e7b8a 251 *
maclobdell 0:f7c60d3e7b8a 252 * \returns 0 on success, MBEDTLS_ERR_MD_BAD_INPUT_DATA if parameter
maclobdell 0:f7c60d3e7b8a 253 * verification fails.
maclobdell 0:f7c60d3e7b8a 254 */
maclobdell 0:f7c60d3e7b8a 255 int mbedtls_md( const mbedtls_md_info_t *md_info, const unsigned char *input, size_t ilen,
maclobdell 0:f7c60d3e7b8a 256 unsigned char *output );
maclobdell 0:f7c60d3e7b8a 257
maclobdell 0:f7c60d3e7b8a 258 #if defined(MBEDTLS_FS_IO)
maclobdell 0:f7c60d3e7b8a 259 /**
maclobdell 0:f7c60d3e7b8a 260 * \brief Output = message_digest( file contents )
maclobdell 0:f7c60d3e7b8a 261 *
maclobdell 0:f7c60d3e7b8a 262 * \param md_info message digest info
maclobdell 0:f7c60d3e7b8a 263 * \param path input file name
maclobdell 0:f7c60d3e7b8a 264 * \param output generic message digest checksum result
maclobdell 0:f7c60d3e7b8a 265 *
maclobdell 0:f7c60d3e7b8a 266 * \return 0 if successful,
maclobdell 0:f7c60d3e7b8a 267 * MBEDTLS_ERR_MD_FILE_IO_ERROR if file input failed,
maclobdell 0:f7c60d3e7b8a 268 * MBEDTLS_ERR_MD_BAD_INPUT_DATA if md_info was NULL.
maclobdell 0:f7c60d3e7b8a 269 */
maclobdell 0:f7c60d3e7b8a 270 int mbedtls_md_file( const mbedtls_md_info_t *md_info, const char *path,
maclobdell 0:f7c60d3e7b8a 271 unsigned char *output );
maclobdell 0:f7c60d3e7b8a 272 #endif /* MBEDTLS_FS_IO */
maclobdell 0:f7c60d3e7b8a 273
maclobdell 0:f7c60d3e7b8a 274 /**
maclobdell 0:f7c60d3e7b8a 275 * \brief Set HMAC key and prepare to authenticate a new message.
maclobdell 0:f7c60d3e7b8a 276 * Usually called after mbedtls_md_setup() or mbedtls_md_hmac_finish().
maclobdell 0:f7c60d3e7b8a 277 *
maclobdell 0:f7c60d3e7b8a 278 * \param ctx HMAC context
maclobdell 0:f7c60d3e7b8a 279 * \param key HMAC secret key
maclobdell 0:f7c60d3e7b8a 280 * \param keylen length of the HMAC key in bytes
maclobdell 0:f7c60d3e7b8a 281 *
maclobdell 0:f7c60d3e7b8a 282 * \returns 0 on success, MBEDTLS_ERR_MD_BAD_INPUT_DATA if parameter
maclobdell 0:f7c60d3e7b8a 283 * verification fails.
maclobdell 0:f7c60d3e7b8a 284 */
maclobdell 0:f7c60d3e7b8a 285 int mbedtls_md_hmac_starts( mbedtls_md_context_t *ctx, const unsigned char *key,
maclobdell 0:f7c60d3e7b8a 286 size_t keylen );
maclobdell 0:f7c60d3e7b8a 287
maclobdell 0:f7c60d3e7b8a 288 /**
maclobdell 0:f7c60d3e7b8a 289 * \brief Generic HMAC process buffer.
maclobdell 0:f7c60d3e7b8a 290 * Called between mbedtls_md_hmac_starts() or mbedtls_md_hmac_reset()
maclobdell 0:f7c60d3e7b8a 291 * and mbedtls_md_hmac_finish().
maclobdell 0:f7c60d3e7b8a 292 * May be called repeatedly.
maclobdell 0:f7c60d3e7b8a 293 *
maclobdell 0:f7c60d3e7b8a 294 * \param ctx HMAC context
maclobdell 0:f7c60d3e7b8a 295 * \param input buffer holding the data
maclobdell 0:f7c60d3e7b8a 296 * \param ilen length of the input data
maclobdell 0:f7c60d3e7b8a 297 *
maclobdell 0:f7c60d3e7b8a 298 * \returns 0 on success, MBEDTLS_ERR_MD_BAD_INPUT_DATA if parameter
maclobdell 0:f7c60d3e7b8a 299 * verification fails.
maclobdell 0:f7c60d3e7b8a 300 */
maclobdell 0:f7c60d3e7b8a 301 int mbedtls_md_hmac_update( mbedtls_md_context_t *ctx, const unsigned char *input,
maclobdell 0:f7c60d3e7b8a 302 size_t ilen );
maclobdell 0:f7c60d3e7b8a 303
maclobdell 0:f7c60d3e7b8a 304 /**
maclobdell 0:f7c60d3e7b8a 305 * \brief Output HMAC.
maclobdell 0:f7c60d3e7b8a 306 * Called after mbedtls_md_hmac_update().
maclobdell 0:f7c60d3e7b8a 307 * Usually followed my mbedtls_md_hmac_reset(), mbedtls_md_hmac_starts(),
maclobdell 0:f7c60d3e7b8a 308 * or mbedtls_md_free().
maclobdell 0:f7c60d3e7b8a 309 *
maclobdell 0:f7c60d3e7b8a 310 * \param ctx HMAC context
maclobdell 0:f7c60d3e7b8a 311 * \param output Generic HMAC checksum result
maclobdell 0:f7c60d3e7b8a 312 *
maclobdell 0:f7c60d3e7b8a 313 * \returns 0 on success, MBEDTLS_ERR_MD_BAD_INPUT_DATA if parameter
maclobdell 0:f7c60d3e7b8a 314 * verification fails.
maclobdell 0:f7c60d3e7b8a 315 */
maclobdell 0:f7c60d3e7b8a 316 int mbedtls_md_hmac_finish( mbedtls_md_context_t *ctx, unsigned char *output);
maclobdell 0:f7c60d3e7b8a 317
maclobdell 0:f7c60d3e7b8a 318 /**
maclobdell 0:f7c60d3e7b8a 319 * \brief Prepare to authenticate a new message with the same key.
maclobdell 0:f7c60d3e7b8a 320 * Called after mbedtls_md_hmac_finish() and before mbedtls_md_hmac_update().
maclobdell 0:f7c60d3e7b8a 321 *
maclobdell 0:f7c60d3e7b8a 322 * \param ctx HMAC context to be reset
maclobdell 0:f7c60d3e7b8a 323 *
maclobdell 0:f7c60d3e7b8a 324 * \returns 0 on success, MBEDTLS_ERR_MD_BAD_INPUT_DATA if parameter
maclobdell 0:f7c60d3e7b8a 325 * verification fails.
maclobdell 0:f7c60d3e7b8a 326 */
maclobdell 0:f7c60d3e7b8a 327 int mbedtls_md_hmac_reset( mbedtls_md_context_t *ctx );
maclobdell 0:f7c60d3e7b8a 328
maclobdell 0:f7c60d3e7b8a 329 /**
maclobdell 0:f7c60d3e7b8a 330 * \brief Output = Generic_HMAC( hmac key, input buffer )
maclobdell 0:f7c60d3e7b8a 331 *
maclobdell 0:f7c60d3e7b8a 332 * \param md_info message digest info
maclobdell 0:f7c60d3e7b8a 333 * \param key HMAC secret key
maclobdell 0:f7c60d3e7b8a 334 * \param keylen length of the HMAC key in bytes
maclobdell 0:f7c60d3e7b8a 335 * \param input buffer holding the data
maclobdell 0:f7c60d3e7b8a 336 * \param ilen length of the input data
maclobdell 0:f7c60d3e7b8a 337 * \param output Generic HMAC-result
maclobdell 0:f7c60d3e7b8a 338 *
maclobdell 0:f7c60d3e7b8a 339 * \returns 0 on success, MBEDTLS_ERR_MD_BAD_INPUT_DATA if parameter
maclobdell 0:f7c60d3e7b8a 340 * verification fails.
maclobdell 0:f7c60d3e7b8a 341 */
maclobdell 0:f7c60d3e7b8a 342 int mbedtls_md_hmac( const mbedtls_md_info_t *md_info, const unsigned char *key, size_t keylen,
maclobdell 0:f7c60d3e7b8a 343 const unsigned char *input, size_t ilen,
maclobdell 0:f7c60d3e7b8a 344 unsigned char *output );
maclobdell 0:f7c60d3e7b8a 345
maclobdell 0:f7c60d3e7b8a 346 /* Internal use */
maclobdell 0:f7c60d3e7b8a 347 int mbedtls_md_process( mbedtls_md_context_t *ctx, const unsigned char *data );
maclobdell 0:f7c60d3e7b8a 348
maclobdell 0:f7c60d3e7b8a 349 #ifdef __cplusplus
maclobdell 0:f7c60d3e7b8a 350 }
maclobdell 0:f7c60d3e7b8a 351 #endif
maclobdell 0:f7c60d3e7b8a 352
maclobdell 0:f7c60d3e7b8a 353 #endif /* MBEDTLS_MD_H */