32 #if defined(POLARSSL_MD_C)
39 #if defined _MSC_VER && !defined strcasecmp
40 #define strcasecmp _stricmp
43 static const int supported_digests[] = {
45 #if defined(POLARSSL_MD2_C)
49 #if defined(POLARSSL_MD4_C)
53 #if defined(POLARSSL_MD5_C)
57 #if defined(POLARSSL_SHA1_C)
61 #if defined(POLARSSL_SHA2_C)
66 #if defined(POLARSSL_SHA4_C)
76 return supported_digests;
85 #if defined(POLARSSL_MD2_C)
86 if( !strcasecmp(
"MD2", md_name ) )
89 #if defined(POLARSSL_MD4_C)
90 if( !strcasecmp(
"MD4", md_name ) )
93 #if defined(POLARSSL_MD5_C)
94 if( !strcasecmp(
"MD5", md_name ) )
97 #if defined(POLARSSL_SHA1_C)
98 if( !strcasecmp(
"SHA1", md_name ) || !strcasecmp(
"SHA", md_name ) )
101 #if defined(POLARSSL_SHA2_C)
102 if( !strcasecmp(
"SHA224", md_name ) )
104 if( !strcasecmp(
"SHA256", md_name ) )
107 #if defined(POLARSSL_SHA4_C)
108 if( !strcasecmp(
"SHA384", md_name ) )
110 if( !strcasecmp(
"SHA512", md_name ) )
120 #if defined(POLARSSL_MD2_C)
124 #if defined(POLARSSL_MD4_C)
128 #if defined(POLARSSL_MD5_C)
132 #if defined(POLARSSL_SHA1_C)
136 #if defined(POLARSSL_SHA2_C)
142 #if defined(POLARSSL_SHA4_C)
155 if( md_info == NULL || ctx == NULL )
172 if( ctx == NULL || ctx->
md_info == NULL )
183 if( ctx == NULL || ctx->
md_info == NULL )
193 if( ctx == NULL || ctx->
md_info == NULL )
203 if( ctx == NULL || ctx->
md_info == NULL )
211 int md(
const md_info_t *md_info,
const unsigned char *input,
size_t ilen,
212 unsigned char *output )
214 if ( md_info == NULL )
222 int md_file(
const md_info_t *md_info,
const char *path,
unsigned char *output )
224 #if defined(POLARSSL_FS_IO)
228 if( md_info == NULL )
231 #if defined(POLARSSL_FS_IO)
232 ret = md_info->
file_func( path, output );
247 if( ctx == NULL || ctx->
md_info == NULL )
257 if( ctx == NULL || ctx->
md_info == NULL )
267 if( ctx == NULL || ctx->
md_info == NULL )
277 if( ctx == NULL || ctx->
md_info == NULL )
285 int md_hmac(
const md_info_t *md_info,
const unsigned char *key,
size_t keylen,
286 const unsigned char *input,
size_t ilen,
287 unsigned char *output )
289 if( md_info == NULL )
292 md_info->
hmac_func( key, keylen, input, ilen, output );
int md(const md_info_t *md_info, const unsigned char *input, size_t ilen, unsigned char *output)
Output = message_digest( input buffer )
#define POLARSSL_ERR_MD_ALLOC_FAILED
Failed to allocate memory.
int md_starts(md_context_t *ctx)
Set-up the given context for a new message digest.
#define POLARSSL_ERR_MD_FEATURE_UNAVAILABLE
The selected feature is not available.
int md_file(const md_info_t *md_info, const char *path, unsigned char *output)
Output = message_digest( file contents )
int md_init_ctx(md_context_t *ctx, const md_info_t *md_info)
Initialises and fills the message digest context structure with the appropriate values.
void(* hmac_reset_func)(void *ctx)
HMAC context reset function.
Configuration options (set of defines)
#define POLARSSL_ERR_MD_FILE_IO_ERROR
Opening or reading of file failed.
const md_info_t * md_info_from_string(const char *md_name)
Returns the message digest information associated with the given digest name.
void(* hmac_starts_func)(void *ctx, const unsigned char *key, size_t keylen)
HMAC Initialisation function.
const md_info_t * md_info
Information about the associated message digest.
const md_info_t * md_info_from_type(md_type_t md_type)
Returns the message digest information associated with the given digest type.
#define POLARSSL_ERR_MD_BAD_INPUT_DATA
Bad input parameters to function.
void(* digest_func)(const unsigned char *input, size_t ilen, unsigned char *output)
Generic digest function.
void(* starts_func)(void *ctx)
Digest initialisation function.
void(* finish_func)(void *ctx, unsigned char *output)
Digest finalisation function.
int(* file_func)(const char *path, unsigned char *output)
Generic file digest function.
const md_info_t sha224_info
void(* update_func)(void *ctx, const unsigned char *input, size_t ilen)
Digest update function.
const int * md_list(void)
Returns the list of digests supported by the generic digest module.
int md_hmac_starts(md_context_t *ctx, const unsigned char *key, size_t keylen)
Generic HMAC context setup.
void * md_ctx
Digest-specific context.
Generic message digest wrapper.
int md_hmac(const md_info_t *md_info, const unsigned char *key, size_t keylen, const unsigned char *input, size_t ilen, unsigned char *output)
Output = Generic_HMAC( hmac key, input buffer )
const md_info_t sha1_info
int md_hmac_reset(md_context_t *ctx)
Generic HMAC context reset.
void(* hmac_func)(const unsigned char *key, size_t keylen, const unsigned char *input, size_t ilen, unsigned char *output)
Generic HMAC function.
int md_hmac_update(md_context_t *ctx, const unsigned char *input, size_t ilen)
Generic HMAC process buffer.
const md_info_t sha512_info
void(* hmac_finish_func)(void *ctx, unsigned char *output)
HMAC finalisation function.
const md_info_t sha256_info
int md_finish(md_context_t *ctx, unsigned char *output)
Generic message digest final digest.
int md_free_ctx(md_context_t *ctx)
Free the message-specific context of ctx.
void(* hmac_update_func)(void *ctx, const unsigned char *input, size_t ilen)
HMAC update function.
Message digest information.
int md_update(md_context_t *ctx, const unsigned char *input, size_t ilen)
Generic message digest process buffer.
const md_info_t sha384_info
int md_hmac_finish(md_context_t *ctx, unsigned char *output)
Generic HMAC final digest.
void *(* ctx_alloc_func)(void)
Allocate a new context.
Generic message digest context.
void(* ctx_free_func)(void *ctx)
Free the given context.