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