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