Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 1 | /** |
| 2 | * \file md.h |
Paul Bakker | 9af723c | 2014-05-01 13:03:14 +0200 | [diff] [blame] | 3 | * |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 4 | * \brief Generic message digest wrapper |
| 5 | * |
| 6 | * \author Adriaan de Jong <dejong@fox-it.com> |
| 7 | * |
Manuel Pégourié-Gonnard | a658a40 | 2015-01-23 09:45:19 +0000 | [diff] [blame] | 8 | * Copyright (C) 2006-2014, ARM Limited, All Rights Reserved |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 9 | * |
Manuel Pégourié-Gonnard | fe44643 | 2015-03-06 13:17:10 +0000 | [diff] [blame] | 10 | * This file is part of mbed TLS (https://tls.mbed.org) |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 11 | * |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 12 | * This program is free software; you can redistribute it and/or modify |
| 13 | * it under the terms of the GNU General Public License as published by |
| 14 | * the Free Software Foundation; either version 2 of the License, or |
| 15 | * (at your option) any later version. |
| 16 | * |
| 17 | * This program is distributed in the hope that it will be useful, |
| 18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 20 | * GNU General Public License for more details. |
| 21 | * |
| 22 | * You should have received a copy of the GNU General Public License along |
| 23 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 24 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 25 | */ |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 26 | #ifndef POLARSSL_MD_H |
| 27 | #define POLARSSL_MD_H |
| 28 | |
Rich Evans | 00ab470 | 2015-02-06 13:43:58 +0000 | [diff] [blame] | 29 | #include <stddef.h> |
Ron Eldor | bc3fa39 | 2017-09-07 16:58:41 +0300 | [diff] [blame] | 30 | #if !defined(POLARSSL_CONFIG_FILE) |
| 31 | #include "config.h" |
| 32 | #else |
| 33 | #include POLARSSL_CONFIG_FILE |
| 34 | #endif |
| 35 | |
Ron Eldor | 3216c1a | 2017-09-07 17:15:47 +0300 | [diff] [blame^] | 36 | #if ( defined(__ARMCC_VERSION) || defined(_MSC_VER) ) && \ |
| 37 | !defined(inline) && !defined(__cplusplus) |
| 38 | #define inline __inline |
| 39 | #endif |
| 40 | |
Paul Bakker | 9d78140 | 2011-05-09 16:17:09 +0000 | [diff] [blame] | 41 | #define POLARSSL_ERR_MD_FEATURE_UNAVAILABLE -0x5080 /**< The selected feature is not available. */ |
Paul Bakker | 9c021ad | 2011-06-09 15:55:11 +0000 | [diff] [blame] | 42 | #define POLARSSL_ERR_MD_BAD_INPUT_DATA -0x5100 /**< Bad input parameters to function. */ |
| 43 | #define POLARSSL_ERR_MD_ALLOC_FAILED -0x5180 /**< Failed to allocate memory. */ |
Paul Bakker | 8913f82 | 2012-01-14 18:07:41 +0000 | [diff] [blame] | 44 | #define POLARSSL_ERR_MD_FILE_IO_ERROR -0x5200 /**< Opening or reading of file failed. */ |
Paul Bakker | 335db3f | 2011-04-25 15:28:35 +0000 | [diff] [blame] | 45 | |
Paul Bakker | 407a0da | 2013-06-27 14:29:21 +0200 | [diff] [blame] | 46 | #ifdef __cplusplus |
| 47 | extern "C" { |
| 48 | #endif |
| 49 | |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 50 | typedef enum { |
Paul Bakker | 562535d | 2011-01-20 16:42:01 +0000 | [diff] [blame] | 51 | POLARSSL_MD_NONE=0, |
| 52 | POLARSSL_MD_MD2, |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 53 | POLARSSL_MD_MD4, |
| 54 | POLARSSL_MD_MD5, |
| 55 | POLARSSL_MD_SHA1, |
| 56 | POLARSSL_MD_SHA224, |
| 57 | POLARSSL_MD_SHA256, |
| 58 | POLARSSL_MD_SHA384, |
| 59 | POLARSSL_MD_SHA512, |
Paul Bakker | 61b699e | 2014-01-22 13:35:29 +0100 | [diff] [blame] | 60 | POLARSSL_MD_RIPEMD160, |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 61 | } md_type_t; |
| 62 | |
Paul Bakker | 7db0109 | 2013-09-10 11:10:57 +0200 | [diff] [blame] | 63 | #if defined(POLARSSL_SHA512_C) |
Paul Bakker | 1b57b06 | 2011-01-06 15:48:19 +0000 | [diff] [blame] | 64 | #define POLARSSL_MD_MAX_SIZE 64 /* longest known is SHA512 */ |
Paul Bakker | 7db0109 | 2013-09-10 11:10:57 +0200 | [diff] [blame] | 65 | #else |
| 66 | #define POLARSSL_MD_MAX_SIZE 32 /* longest known is SHA256 or less */ |
| 67 | #endif |
Paul Bakker | 1b57b06 | 2011-01-06 15:48:19 +0000 | [diff] [blame] | 68 | |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 69 | /** |
| 70 | * Message digest information. Allows message digest functions to be called |
| 71 | * in a generic way. |
| 72 | */ |
| 73 | typedef struct { |
| 74 | /** Digest identifier */ |
| 75 | md_type_t type; |
| 76 | |
| 77 | /** Name of the message digest */ |
| 78 | const char * name; |
| 79 | |
| 80 | /** Output length of the digest function */ |
| 81 | int size; |
| 82 | |
| 83 | /** Digest initialisation function */ |
| 84 | void (*starts_func)( void *ctx ); |
| 85 | |
| 86 | /** Digest update function */ |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 87 | void (*update_func)( void *ctx, const unsigned char *input, size_t ilen ); |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 88 | |
| 89 | /** Digest finalisation function */ |
| 90 | void (*finish_func)( void *ctx, unsigned char *output ); |
| 91 | |
| 92 | /** Generic digest function */ |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 93 | void (*digest_func)( const unsigned char *input, size_t ilen, |
Paul Bakker | b9e4e2c | 2014-05-01 14:18:25 +0200 | [diff] [blame] | 94 | unsigned char *output ); |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 95 | |
| 96 | /** Generic file digest function */ |
| 97 | int (*file_func)( const char *path, unsigned char *output ); |
| 98 | |
| 99 | /** HMAC Initialisation function */ |
Paul Bakker | b9e4e2c | 2014-05-01 14:18:25 +0200 | [diff] [blame] | 100 | void (*hmac_starts_func)( void *ctx, const unsigned char *key, |
| 101 | size_t keylen ); |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 102 | |
| 103 | /** HMAC update function */ |
Paul Bakker | b9e4e2c | 2014-05-01 14:18:25 +0200 | [diff] [blame] | 104 | void (*hmac_update_func)( void *ctx, const unsigned char *input, |
| 105 | size_t ilen ); |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 106 | |
| 107 | /** HMAC finalisation function */ |
| 108 | void (*hmac_finish_func)( void *ctx, unsigned char *output); |
| 109 | |
| 110 | /** HMAC context reset function */ |
| 111 | void (*hmac_reset_func)( void *ctx ); |
| 112 | |
| 113 | /** Generic HMAC function */ |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 114 | void (*hmac_func)( const unsigned char *key, size_t keylen, |
Paul Bakker | b9e4e2c | 2014-05-01 14:18:25 +0200 | [diff] [blame] | 115 | const unsigned char *input, size_t ilen, |
| 116 | unsigned char *output ); |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 117 | |
| 118 | /** Allocate a new context */ |
| 119 | void * (*ctx_alloc_func)( void ); |
| 120 | |
| 121 | /** Free the given context */ |
| 122 | void (*ctx_free_func)( void *ctx ); |
| 123 | |
Paul Bakker | 1bd3ae8 | 2013-03-13 10:26:44 +0100 | [diff] [blame] | 124 | /** Internal use only */ |
| 125 | void (*process_func)( void *ctx, const unsigned char *input ); |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 126 | } md_info_t; |
| 127 | |
| 128 | /** |
| 129 | * Generic message digest context. |
| 130 | */ |
| 131 | typedef struct { |
| 132 | /** Information about the associated message digest */ |
| 133 | const md_info_t *md_info; |
| 134 | |
| 135 | /** Digest-specific context */ |
| 136 | void *md_ctx; |
| 137 | } md_context_t; |
| 138 | |
| 139 | #define MD_CONTEXT_T_INIT { \ |
| 140 | NULL, /* md_info */ \ |
| 141 | NULL, /* md_ctx */ \ |
| 142 | } |
| 143 | |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 144 | /** |
Paul Bakker | 72f6266 | 2011-01-16 21:27:44 +0000 | [diff] [blame] | 145 | * \brief Returns the list of digests supported by the generic digest module. |
| 146 | * |
| 147 | * \return a statically allocated array of digests, the last entry |
| 148 | * is 0. |
| 149 | */ |
| 150 | const int *md_list( void ); |
| 151 | |
| 152 | /** |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 153 | * \brief Returns the message digest information associated with the |
| 154 | * given digest name. |
| 155 | * |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 156 | * \param md_name Name of the digest to search for. |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 157 | * |
| 158 | * \return The message digest information associated with md_name or |
| 159 | * NULL if not found. |
| 160 | */ |
| 161 | const md_info_t *md_info_from_string( const char *md_name ); |
| 162 | |
| 163 | /** |
| 164 | * \brief Returns the message digest information associated with the |
| 165 | * given digest type. |
| 166 | * |
| 167 | * \param md_type type of digest to search for. |
| 168 | * |
| 169 | * \return The message digest information associated with md_type or |
| 170 | * NULL if not found. |
| 171 | */ |
| 172 | const md_info_t *md_info_from_type( md_type_t md_type ); |
| 173 | |
| 174 | /** |
Paul Bakker | 84bbeb5 | 2014-07-01 14:53:22 +0200 | [diff] [blame] | 175 | * \brief Initialize a md_context (as NONE) |
| 176 | */ |
| 177 | void md_init( md_context_t *ctx ); |
| 178 | |
| 179 | /** |
| 180 | * \brief Free and clear the message-specific context of ctx. |
| 181 | * Freeing ctx itself remains the responsibility of the |
| 182 | * caller. |
| 183 | */ |
| 184 | void md_free( md_context_t *ctx ); |
| 185 | |
| 186 | /** |
Paul Bakker | b9e4e2c | 2014-05-01 14:18:25 +0200 | [diff] [blame] | 187 | * \brief Initialises and fills the message digest context structure |
| 188 | * with the appropriate values. |
Paul Bakker | 562535d | 2011-01-20 16:42:01 +0000 | [diff] [blame] | 189 | * |
Paul Bakker | 84bbeb5 | 2014-07-01 14:53:22 +0200 | [diff] [blame] | 190 | * \note Currently also clears structure. In future versions you |
| 191 | * will be required to call md_init() on the structure |
| 192 | * first. |
| 193 | * |
Paul Bakker | 562535d | 2011-01-20 16:42:01 +0000 | [diff] [blame] | 194 | * \param ctx context to initialise. May not be NULL. The |
| 195 | * digest-specific context (ctx->md_ctx) must be NULL. It will |
| 196 | * be allocated, and must be freed using md_free_ctx() later. |
| 197 | * \param md_info message digest to use. |
| 198 | * |
Paul Bakker | 9c021ad | 2011-06-09 15:55:11 +0000 | [diff] [blame] | 199 | * \returns \c 0 on success, \c POLARSSL_ERR_MD_BAD_INPUT_DATA on |
| 200 | * parameter failure, \c POLARSSL_ERR_MD_ALLOC_FAILED if |
Paul Bakker | 2028156 | 2011-11-11 10:34:04 +0000 | [diff] [blame] | 201 | * allocation of the digest-specific context failed. |
Paul Bakker | 562535d | 2011-01-20 16:42:01 +0000 | [diff] [blame] | 202 | */ |
| 203 | int md_init_ctx( md_context_t *ctx, const md_info_t *md_info ); |
| 204 | |
Manuel Pégourié-Gonnard | c70581c | 2015-03-23 13:58:27 +0100 | [diff] [blame] | 205 | #if ! defined(POLARSSL_DEPRECATED_REMOVED) |
| 206 | #if defined(POLARSSL_DEPRECATED_WARNING) |
| 207 | #define DEPRECATED __attribute__((deprecated)) |
| 208 | #else |
| 209 | #define DEPRECATED |
| 210 | #endif |
Paul Bakker | 562535d | 2011-01-20 16:42:01 +0000 | [diff] [blame] | 211 | /** |
| 212 | * \brief Free the message-specific context of ctx. Freeing ctx itself |
| 213 | * remains the responsibility of the caller. |
| 214 | * |
Manuel Pégourié-Gonnard | 7143284 | 2015-03-20 16:19:35 +0000 | [diff] [blame] | 215 | * \deprecated Use md_free() instead |
Paul Bakker | 84bbeb5 | 2014-07-01 14:53:22 +0200 | [diff] [blame] | 216 | * |
Paul Bakker | f3b86c1 | 2011-01-27 15:24:17 +0000 | [diff] [blame] | 217 | * \param ctx Free the message-specific context |
Paul Bakker | 562535d | 2011-01-20 16:42:01 +0000 | [diff] [blame] | 218 | * |
Paul Bakker | 84bbeb5 | 2014-07-01 14:53:22 +0200 | [diff] [blame] | 219 | * \returns 0 |
Paul Bakker | 562535d | 2011-01-20 16:42:01 +0000 | [diff] [blame] | 220 | */ |
Manuel Pégourié-Gonnard | c70581c | 2015-03-23 13:58:27 +0100 | [diff] [blame] | 221 | int md_free_ctx( md_context_t *ctx ) DEPRECATED; |
| 222 | #undef DEPRECATED |
| 223 | #endif /* POLARSSL_DEPRECATED_REMOVED */ |
Paul Bakker | 562535d | 2011-01-20 16:42:01 +0000 | [diff] [blame] | 224 | |
| 225 | /** |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 226 | * \brief Returns the size of the message digest output. |
| 227 | * |
| 228 | * \param md_info message digest info |
| 229 | * |
| 230 | * \return size of the message digest output. |
| 231 | */ |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 232 | static inline unsigned char md_get_size( const md_info_t *md_info ) |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 233 | { |
Paul Bakker | c295b83 | 2013-04-02 11:13:39 +0200 | [diff] [blame] | 234 | if( md_info == NULL ) |
| 235 | return( 0 ); |
| 236 | |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 237 | return md_info->size; |
| 238 | } |
| 239 | |
| 240 | /** |
| 241 | * \brief Returns the type of the message digest output. |
| 242 | * |
| 243 | * \param md_info message digest info |
| 244 | * |
| 245 | * \return type of the message digest output. |
| 246 | */ |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 247 | static inline md_type_t md_get_type( const md_info_t *md_info ) |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 248 | { |
Paul Bakker | c295b83 | 2013-04-02 11:13:39 +0200 | [diff] [blame] | 249 | if( md_info == NULL ) |
| 250 | return( POLARSSL_MD_NONE ); |
| 251 | |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 252 | return md_info->type; |
| 253 | } |
| 254 | |
| 255 | /** |
| 256 | * \brief Returns the name of the message digest output. |
| 257 | * |
| 258 | * \param md_info message digest info |
| 259 | * |
| 260 | * \return name of the message digest output. |
| 261 | */ |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 262 | static inline const char *md_get_name( const md_info_t *md_info ) |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 263 | { |
Paul Bakker | c295b83 | 2013-04-02 11:13:39 +0200 | [diff] [blame] | 264 | if( md_info == NULL ) |
| 265 | return( NULL ); |
| 266 | |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 267 | return md_info->name; |
| 268 | } |
| 269 | |
| 270 | /** |
Paul Bakker | 562535d | 2011-01-20 16:42:01 +0000 | [diff] [blame] | 271 | * \brief Set-up the given context for a new message digest |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 272 | * |
Paul Bakker | 562535d | 2011-01-20 16:42:01 +0000 | [diff] [blame] | 273 | * \param ctx generic message digest context. |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 274 | * |
Paul Bakker | 9c021ad | 2011-06-09 15:55:11 +0000 | [diff] [blame] | 275 | * \returns 0 on success, POLARSSL_ERR_MD_BAD_INPUT_DATA if parameter |
| 276 | * verification fails. |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 277 | */ |
Paul Bakker | 562535d | 2011-01-20 16:42:01 +0000 | [diff] [blame] | 278 | int md_starts( md_context_t *ctx ); |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 279 | |
| 280 | /** |
| 281 | * \brief Generic message digest process buffer |
| 282 | * |
| 283 | * \param ctx Generic message digest context |
| 284 | * \param input buffer holding the datal |
| 285 | * \param ilen length of the input data |
| 286 | * |
Paul Bakker | 9c021ad | 2011-06-09 15:55:11 +0000 | [diff] [blame] | 287 | * \returns 0 on success, POLARSSL_ERR_MD_BAD_INPUT_DATA if parameter |
| 288 | * verification fails. |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 289 | */ |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 290 | int md_update( md_context_t *ctx, const unsigned char *input, size_t ilen ); |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 291 | |
| 292 | /** |
| 293 | * \brief Generic message digest final digest |
| 294 | * |
| 295 | * \param ctx Generic message digest context |
| 296 | * \param output Generic message digest checksum result |
| 297 | * |
Paul Bakker | 9c021ad | 2011-06-09 15:55:11 +0000 | [diff] [blame] | 298 | * \returns 0 on success, POLARSSL_ERR_MD_BAD_INPUT_DATA if parameter |
| 299 | * verification fails. |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 300 | */ |
| 301 | int md_finish( md_context_t *ctx, unsigned char *output ); |
| 302 | |
| 303 | /** |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 304 | * \brief Output = message_digest( input buffer ) |
| 305 | * |
| 306 | * \param md_info message digest info |
| 307 | * \param input buffer holding the data |
| 308 | * \param ilen length of the input data |
| 309 | * \param output Generic message digest checksum result |
| 310 | * |
Paul Bakker | 9c021ad | 2011-06-09 15:55:11 +0000 | [diff] [blame] | 311 | * \returns 0 on success, POLARSSL_ERR_MD_BAD_INPUT_DATA if parameter |
| 312 | * verification fails. |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 313 | */ |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 314 | int md( const md_info_t *md_info, const unsigned char *input, size_t ilen, |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 315 | unsigned char *output ); |
| 316 | |
| 317 | /** |
| 318 | * \brief Output = message_digest( file contents ) |
| 319 | * |
| 320 | * \param md_info message digest info |
| 321 | * \param path input file name |
| 322 | * \param output generic message digest checksum result |
| 323 | * |
Paul Bakker | 9c021ad | 2011-06-09 15:55:11 +0000 | [diff] [blame] | 324 | * \return 0 if successful, POLARSSL_ERR_MD_FILE_OPEN_FAILED if fopen |
| 325 | * failed, POLARSSL_ERR_MD_FILE_READ_FAILED if fread failed, |
| 326 | * POLARSSL_ERR_MD_BAD_INPUT_DATA if md_info was NULL. |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 327 | */ |
Paul Bakker | b9e4e2c | 2014-05-01 14:18:25 +0200 | [diff] [blame] | 328 | int md_file( const md_info_t *md_info, const char *path, |
| 329 | unsigned char *output ); |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 330 | |
| 331 | /** |
| 332 | * \brief Generic HMAC context setup |
| 333 | * |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 334 | * \param ctx HMAC context to be initialized |
| 335 | * \param key HMAC secret key |
| 336 | * \param keylen length of the HMAC key |
| 337 | * |
Paul Bakker | 9c021ad | 2011-06-09 15:55:11 +0000 | [diff] [blame] | 338 | * \returns 0 on success, POLARSSL_ERR_MD_BAD_INPUT_DATA if parameter |
| 339 | * verification fails. |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 340 | */ |
Paul Bakker | b9e4e2c | 2014-05-01 14:18:25 +0200 | [diff] [blame] | 341 | int md_hmac_starts( md_context_t *ctx, const unsigned char *key, |
| 342 | size_t keylen ); |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 343 | |
| 344 | /** |
| 345 | * \brief Generic HMAC process buffer |
| 346 | * |
| 347 | * \param ctx HMAC context |
| 348 | * \param input buffer holding the data |
| 349 | * \param ilen length of the input data |
| 350 | * |
Paul Bakker | 9c021ad | 2011-06-09 15:55:11 +0000 | [diff] [blame] | 351 | * \returns 0 on success, POLARSSL_ERR_MD_BAD_INPUT_DATA if parameter |
| 352 | * verification fails. |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 353 | */ |
Paul Bakker | b9e4e2c | 2014-05-01 14:18:25 +0200 | [diff] [blame] | 354 | int md_hmac_update( md_context_t *ctx, const unsigned char *input, |
| 355 | size_t ilen ); |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 356 | |
| 357 | /** |
| 358 | * \brief Generic HMAC final digest |
| 359 | * |
| 360 | * \param ctx HMAC context |
| 361 | * \param output Generic HMAC checksum result |
| 362 | * |
Paul Bakker | 9c021ad | 2011-06-09 15:55:11 +0000 | [diff] [blame] | 363 | * \returns 0 on success, POLARSSL_ERR_MD_BAD_INPUT_DATA if parameter |
| 364 | * verification fails. |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 365 | */ |
| 366 | int md_hmac_finish( md_context_t *ctx, unsigned char *output); |
| 367 | |
| 368 | /** |
| 369 | * \brief Generic HMAC context reset |
| 370 | * |
| 371 | * \param ctx HMAC context to be reset |
| 372 | * |
Paul Bakker | 9c021ad | 2011-06-09 15:55:11 +0000 | [diff] [blame] | 373 | * \returns 0 on success, POLARSSL_ERR_MD_BAD_INPUT_DATA if parameter |
| 374 | * verification fails. |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 375 | */ |
| 376 | int md_hmac_reset( md_context_t *ctx ); |
| 377 | |
| 378 | /** |
| 379 | * \brief Output = Generic_HMAC( hmac key, input buffer ) |
| 380 | * |
| 381 | * \param md_info message digest info |
| 382 | * \param key HMAC secret key |
| 383 | * \param keylen length of the HMAC key |
| 384 | * \param input buffer holding the data |
| 385 | * \param ilen length of the input data |
| 386 | * \param output Generic HMAC-result |
| 387 | * |
Paul Bakker | 9c021ad | 2011-06-09 15:55:11 +0000 | [diff] [blame] | 388 | * \returns 0 on success, POLARSSL_ERR_MD_BAD_INPUT_DATA if parameter |
| 389 | * verification fails. |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 390 | */ |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 391 | int md_hmac( const md_info_t *md_info, const unsigned char *key, size_t keylen, |
| 392 | const unsigned char *input, size_t ilen, |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 393 | unsigned char *output ); |
| 394 | |
Paul Bakker | 1bd3ae8 | 2013-03-13 10:26:44 +0100 | [diff] [blame] | 395 | /* Internal use */ |
| 396 | int md_process( md_context_t *ctx, const unsigned char *data ); |
| 397 | |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 398 | #ifdef __cplusplus |
| 399 | } |
| 400 | #endif |
| 401 | |
| 402 | #endif /* POLARSSL_MD_H */ |