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