51#if !defined(MBEDTLS_CONFIG_FILE)
54#include MBEDTLS_CONFIG_FILE
57#if defined(MBEDTLS_MD_C)
63#if defined(MBEDTLS_PLATFORM_C)
67#define mbedtls_calloc calloc
68#define mbedtls_free free
73#if defined(MBEDTLS_FS_IO)
80static const int supported_digests[] = {
82#if defined(MBEDTLS_SHA512_C)
87#if defined(MBEDTLS_SHA256_C)
92#if defined(MBEDTLS_SHA1_C)
96#if defined(MBEDTLS_RIPEMD160_C)
100#if defined(MBEDTLS_MD5_C)
104#if defined(MBEDTLS_MD4_C)
108#if defined(MBEDTLS_MD2_C)
117 return( supported_digests );
122 if(
NULL == md_name )
126#if defined(MBEDTLS_MD2_C)
127 if( !
strcmp(
"MD2", md_name ) )
130#if defined(MBEDTLS_MD4_C)
131 if( !
strcmp(
"MD4", md_name ) )
134#if defined(MBEDTLS_MD5_C)
135 if( !
strcmp(
"MD5", md_name ) )
138#if defined(MBEDTLS_RIPEMD160_C)
139 if( !
strcmp(
"RIPEMD160", md_name ) )
142#if defined(MBEDTLS_SHA1_C)
143 if( !
strcmp(
"SHA1", md_name ) || !
strcmp(
"SHA", md_name ) )
146#if defined(MBEDTLS_SHA256_C)
147 if( !
strcmp(
"SHA224", md_name ) )
149 if( !
strcmp(
"SHA256", md_name ) )
152#if defined(MBEDTLS_SHA512_C)
153 if( !
strcmp(
"SHA384", md_name ) )
155 if( !
strcmp(
"SHA512", md_name ) )
165#if defined(MBEDTLS_MD2_C)
167 return( &mbedtls_md2_info );
169#if defined(MBEDTLS_MD4_C)
171 return( &mbedtls_md4_info );
173#if defined(MBEDTLS_MD5_C)
177#if defined(MBEDTLS_RIPEMD160_C)
181#if defined(MBEDTLS_SHA1_C)
185#if defined(MBEDTLS_SHA256_C)
191#if defined(MBEDTLS_SHA512_C)
213 ctx->md_info->ctx_free_func(
ctx->md_ctx );
218 2 *
ctx->md_info->block_size );
230 dst->md_info !=
src->md_info )
235 dst->md_info->clone_func(
dst->md_ctx,
src->md_ctx );
240#if ! defined(MBEDTLS_DEPRECATED_REMOVED)
265 ctx->md_info = md_info;
275 return(
ctx->md_info->starts_func(
ctx->md_ctx ) );
283 return(
ctx->md_info->update_func(
ctx->md_ctx,
input, ilen ) );
291 return(
ctx->md_info->finish_func(
ctx->md_ctx, output ) );
295 unsigned char *output )
297 if( md_info ==
NULL )
303#if defined(MBEDTLS_FS_IO)
310 unsigned char buf[1024];
312 if( md_info ==
NULL )
348 unsigned char *ipad, *opad;
354 if( keylen > (
size_t)
ctx->md_info->block_size )
356 if( (
ret =
ctx->md_info->starts_func(
ctx->md_ctx ) ) != 0 )
358 if( (
ret =
ctx->md_info->update_func(
ctx->md_ctx,
key, keylen ) ) != 0 )
360 if( (
ret =
ctx->md_info->finish_func(
ctx->md_ctx,
sum ) ) != 0 )
363 keylen =
ctx->md_info->size;
367 ipad = (
unsigned char *)
ctx->hmac_ctx;
368 opad = (
unsigned char *)
ctx->hmac_ctx +
ctx->md_info->block_size;
370 memset( ipad, 0x36,
ctx->md_info->block_size );
371 memset( opad, 0x5C,
ctx->md_info->block_size );
373 for(
i = 0;
i < keylen;
i++ )
375 ipad[
i] = (
unsigned char)( ipad[
i] ^
key[
i] );
376 opad[
i] = (
unsigned char)( opad[
i] ^
key[
i] );
379 if( (
ret =
ctx->md_info->starts_func(
ctx->md_ctx ) ) != 0 )
381 if( (
ret =
ctx->md_info->update_func(
ctx->md_ctx, ipad,
382 ctx->md_info->block_size ) ) != 0 )
396 return(
ctx->md_info->update_func(
ctx->md_ctx,
input, ilen ) );
408 opad = (
unsigned char *)
ctx->hmac_ctx +
ctx->md_info->block_size;
410 if( (
ret =
ctx->md_info->finish_func(
ctx->md_ctx, tmp ) ) != 0 )
412 if( (
ret =
ctx->md_info->starts_func(
ctx->md_ctx ) ) != 0 )
414 if( (
ret =
ctx->md_info->update_func(
ctx->md_ctx, opad,
415 ctx->md_info->block_size ) ) != 0 )
417 if( (
ret =
ctx->md_info->update_func(
ctx->md_ctx, tmp,
418 ctx->md_info->size ) ) != 0 )
420 return(
ctx->md_info->finish_func(
ctx->md_ctx, output ) );
431 ipad = (
unsigned char *)
ctx->hmac_ctx;
433 if( (
ret =
ctx->md_info->starts_func(
ctx->md_ctx ) ) != 0 )
435 return(
ctx->md_info->update_func(
ctx->md_ctx, ipad,
436 ctx->md_info->block_size ) );
440 const unsigned char *
key,
size_t keylen,
441 const unsigned char *
input,
size_t ilen,
442 unsigned char *output )
447 if( md_info ==
NULL )
473 return(
ctx->md_info->process_func(
ctx->md_ctx,
data ) );
478 if( md_info ==
NULL )
481 return md_info->
size;
486 if( md_info ==
NULL )
489 return md_info->
type;
494 if( md_info ==
NULL )
497 return md_info->
name;
int strcmp(const char *String1, const char *String2)
static void cleanup(void)
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
GLenum GLuint GLenum GLsizei const GLchar * buf
GLenum GLenum GLenum input
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
_Check_return_ _CRTIMP int __cdecl ferror(_In_ FILE *_File)
_Check_return_opt_ _CRTIMP size_t __cdecl fread(_Out_writes_bytes_(_ElementSize *_Count) void *_DstBuf, _In_ size_t _ElementSize, _In_ size_t _Count, _Inout_ FILE *_File)
_Check_return_ _CRTIMP FILE *__cdecl fopen(_In_z_ const char *_Filename, _In_z_ const char *_Mode)
_Check_return_opt_ _CRTIMP int __cdecl fclose(_Inout_ FILE *_File)
This file contains the generic message-digest wrapper.
const int * mbedtls_md_list(void)
This function returns the list of digests supported by the generic digest module.
int mbedtls_md_setup(mbedtls_md_context_t *ctx, const mbedtls_md_info_t *md_info, int hmac)
This function selects the message digest algorithm to use, and allocates internal structures.
mbedtls_md_type_t
Supported message digests.
int mbedtls_md_starts(mbedtls_md_context_t *ctx)
This function starts a message-digest computation.
int mbedtls_md_hmac(const mbedtls_md_info_t *md_info, const unsigned char *key, size_t keylen, const unsigned char *input, size_t ilen, unsigned char *output)
This function calculates the full generic HMAC on the input buffer with the provided key.
int mbedtls_md(const mbedtls_md_info_t *md_info, const unsigned char *input, size_t ilen, unsigned char *output)
This function calculates the message-digest of a buffer, with respect to a configurable message-diges...
int mbedtls_md_hmac_reset(mbedtls_md_context_t *ctx)
This function prepares to authenticate a new message with the same key as the previous HMAC operation...
const char * mbedtls_md_get_name(const mbedtls_md_info_t *md_info)
This function extracts the message-digest name from the message-digest information structure.
int mbedtls_md_init_ctx(mbedtls_md_context_t *ctx, const mbedtls_md_info_t *md_info) MBEDTLS_DEPRECATED
This function selects the message digest algorithm to use, and allocates internal structures.
int mbedtls_md_clone(mbedtls_md_context_t *dst, const mbedtls_md_context_t *src)
This function clones the state of an message-digest context.
mbedtls_md_type_t mbedtls_md_get_type(const mbedtls_md_info_t *md_info)
This function extracts the message-digest type from the message-digest information structure.
int mbedtls_md_hmac_finish(mbedtls_md_context_t *ctx, unsigned char *output)
This function finishes the HMAC operation, and writes the result to the output buffer.
int mbedtls_md_update(mbedtls_md_context_t *ctx, const unsigned char *input, size_t ilen)
This function feeds an input buffer into an ongoing message-digest computation.
#define MBEDTLS_ERR_MD_ALLOC_FAILED
int mbedtls_md_hmac_update(mbedtls_md_context_t *ctx, const unsigned char *input, size_t ilen)
This function feeds an input buffer into an ongoing HMAC computation.
int mbedtls_md_hmac_starts(mbedtls_md_context_t *ctx, const unsigned char *key, size_t keylen)
This function sets the HMAC key and prepares to authenticate a new message.
#define MBEDTLS_ERR_MD_FILE_IO_ERROR
int mbedtls_md_process(mbedtls_md_context_t *ctx, const unsigned char *data)
#define MBEDTLS_MD_MAX_SIZE
void mbedtls_md_init(mbedtls_md_context_t *ctx)
This function initializes a message-digest context without binding it to a particular message-digest ...
int mbedtls_md_finish(mbedtls_md_context_t *ctx, unsigned char *output)
This function finishes the digest operation, and writes the result to the output buffer.
const mbedtls_md_info_t * mbedtls_md_info_from_string(const char *md_name)
This function returns the message-digest information associated with the given digest name.
unsigned char mbedtls_md_get_size(const mbedtls_md_info_t *md_info)
This function extracts the message-digest size from the message-digest information structure.
#define MBEDTLS_ERR_MD_BAD_INPUT_DATA
void mbedtls_md_free(mbedtls_md_context_t *ctx)
This function clears the internal structure of ctx and frees any embedded internal structure,...
const mbedtls_md_info_t mbedtls_sha384_info
const mbedtls_md_info_t mbedtls_sha1_info
const mbedtls_md_info_t mbedtls_ripemd160_info
const mbedtls_md_info_t mbedtls_sha256_info
const mbedtls_md_info_t mbedtls_sha224_info
const mbedtls_md_info_t mbedtls_md5_info
const mbedtls_md_info_t mbedtls_sha512_info
static int sum(int x_, int y_)
#define mbedtls_md_info_from_type
Configuration options (set of defines)
int(* digest_func)(const unsigned char *input, size_t ilen, unsigned char *output)
int(* update_func)(void *ctx, const unsigned char *input, size_t ilen)
void(* ctx_free_func)(void *ctx)
void *(* ctx_alloc_func)(void)
int(* finish_func)(void *ctx, unsigned char *output)
int(* starts_func)(void *ctx)