Example program to test AES-GCM functionality. Used for a workshop

Dependencies:   mbed

Committer:
HannesTschofenig
Date:
Thu Sep 27 06:34:22 2018 +0000
Revision:
0:796d0f61a05b
Example AES-GCM test program

Who changed what in which revision?

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