32 #if defined(POLARSSL_MD_C)
39 #if defined(_MSC_VER) && !defined strcasecmp && !defined(EFIX64) && \
41 #define strcasecmp _stricmp
44 static const int supported_digests[] = {
46 #if defined(POLARSSL_MD2_C)
50 #if defined(POLARSSL_MD4_C)
54 #if defined(POLARSSL_MD5_C)
58 #if defined(POLARSSL_RIPEMD160_C)
62 #if defined(POLARSSL_SHA1_C)
66 #if defined(POLARSSL_SHA256_C)
71 #if defined(POLARSSL_SHA512_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_RIPEMD160_C)
103 if( !strcasecmp(
"RIPEMD160", md_name ) )
106 #if defined(POLARSSL_SHA1_C)
107 if( !strcasecmp(
"SHA1", md_name ) || !strcasecmp(
"SHA", md_name ) )
110 #if defined(POLARSSL_SHA256_C)
111 if( !strcasecmp(
"SHA224", md_name ) )
113 if( !strcasecmp(
"SHA256", md_name ) )
116 #if defined(POLARSSL_SHA512_C)
117 if( !strcasecmp(
"SHA384", md_name ) )
119 if( !strcasecmp(
"SHA512", md_name ) )
129 #if defined(POLARSSL_MD2_C)
133 #if defined(POLARSSL_MD4_C)
137 #if defined(POLARSSL_MD5_C)
141 #if defined(POLARSSL_RIPEMD160_C)
145 #if defined(POLARSSL_SHA1_C)
149 #if defined(POLARSSL_SHA256_C)
155 #if defined(POLARSSL_SHA512_C)
168 if( md_info == NULL || ctx == NULL )
185 if( ctx == NULL || ctx->
md_info == NULL )
196 if( ctx == NULL || ctx->
md_info == NULL )
206 if( ctx == NULL || ctx->
md_info == NULL )
216 if( ctx == NULL || ctx->
md_info == NULL )
224 int md(
const md_info_t *md_info,
const unsigned char *input,
size_t ilen,
225 unsigned char *output )
227 if ( md_info == NULL )
235 int md_file(
const md_info_t *md_info,
const char *path,
unsigned char *output )
237 #if defined(POLARSSL_FS_IO)
241 if( md_info == NULL )
244 #if defined(POLARSSL_FS_IO)
245 ret = md_info->
file_func( path, output );
260 if( ctx == NULL || ctx->
md_info == NULL )
270 if( ctx == NULL || ctx->
md_info == NULL )
280 if( ctx == NULL || ctx->
md_info == NULL )
290 if( ctx == NULL || ctx->
md_info == NULL )
298 int md_hmac(
const md_info_t *md_info,
const unsigned char *key,
size_t keylen,
299 const unsigned char *input,
size_t ilen,
300 unsigned char *output )
302 if( md_info == NULL )
305 md_info->
hmac_func( key, keylen, input, ilen, output );
312 if( ctx == NULL || ctx->
md_info == NULL )
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.
int md_process(md_context_t *ctx, const unsigned char *data)
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.
const md_info_t ripemd160_info
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.
void(* process_func)(void *ctx, const unsigned char *input)
Internal use only.
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.