32 #if defined(POLARSSL_MD_C)
39 #if defined _MSC_VER && !defined strcasecmp
40 #define strcasecmp _stricmp
44 static void polarssl_zeroize(
void *v,
size_t n ) {
45 volatile unsigned char *p = v;
while( n-- ) *p++ = 0;
48 static const int supported_digests[] = {
50 #if defined(POLARSSL_MD2_C)
54 #if defined(POLARSSL_MD4_C)
58 #if defined(POLARSSL_MD5_C)
62 #if defined(POLARSSL_SHA1_C)
66 #if defined(POLARSSL_SHA2_C)
71 #if defined(POLARSSL_SHA4_C)
81 return supported_digests;
90 #if defined(POLARSSL_MD2_C)
91 if( !strcasecmp(
"MD2", md_name ) )
94 #if defined(POLARSSL_MD4_C)
95 if( !strcasecmp(
"MD4", md_name ) )
98 #if defined(POLARSSL_MD5_C)
99 if( !strcasecmp(
"MD5", md_name ) )
102 #if defined(POLARSSL_SHA1_C)
103 if( !strcasecmp(
"SHA1", md_name ) || !strcasecmp(
"SHA", md_name ) )
106 #if defined(POLARSSL_SHA2_C)
107 if( !strcasecmp(
"SHA224", md_name ) )
109 if( !strcasecmp(
"SHA256", md_name ) )
112 #if defined(POLARSSL_SHA4_C)
113 if( !strcasecmp(
"SHA384", md_name ) )
115 if( !strcasecmp(
"SHA512", md_name ) )
125 #if defined(POLARSSL_MD2_C)
129 #if defined(POLARSSL_MD4_C)
133 #if defined(POLARSSL_MD5_C)
137 #if defined(POLARSSL_SHA1_C)
141 #if defined(POLARSSL_SHA2_C)
147 #if defined(POLARSSL_SHA4_C)
160 if( md_info == NULL || ctx == NULL )
177 if( ctx == NULL || ctx->
md_info == NULL )
189 if( ctx == NULL || ctx->
md_info == NULL )
199 if( ctx == NULL || ctx->
md_info == NULL )
209 if( ctx == NULL || ctx->
md_info == NULL )
217 int md(
const md_info_t *md_info,
const unsigned char *input,
size_t ilen,
218 unsigned char *output )
220 if ( md_info == NULL )
228 int md_file(
const md_info_t *md_info,
const char *path,
unsigned char *output )
230 #if defined(POLARSSL_FS_IO)
234 if( md_info == NULL )
237 #if defined(POLARSSL_FS_IO)
238 ret = md_info->
file_func( path, output );
253 if( ctx == NULL || ctx->
md_info == NULL )
263 if( ctx == NULL || ctx->
md_info == NULL )
273 if( ctx == NULL || ctx->
md_info == NULL )
283 if( ctx == NULL || ctx->
md_info == NULL )
291 int md_hmac(
const md_info_t *md_info,
const unsigned char *key,
size_t keylen,
292 const unsigned char *input,
size_t ilen,
293 unsigned char *output )
295 if( md_info == NULL )
298 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.