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