30 #if !defined(POLARSSL_CONFIG_FILE) 33 #include POLARSSL_CONFIG_FILE 36 #if defined(POLARSSL_MD_C) 43 #if defined(_MSC_VER) && !defined strcasecmp && !defined(EFIX64) && \ 45 #define strcasecmp _stricmp 49 static void polarssl_zeroize(
void *v,
size_t n ) {
50 volatile unsigned char *p = v;
while( n-- ) *p++ = 0;
53 static const int supported_digests[] = {
55 #if defined(POLARSSL_SHA512_C) 60 #if defined(POLARSSL_SHA256_C) 65 #if defined(POLARSSL_SHA1_C) 69 #if defined(POLARSSL_RIPEMD160_C) 73 #if defined(POLARSSL_MD5_C) 77 #if defined(POLARSSL_MD4_C) 81 #if defined(POLARSSL_MD2_C) 90 return( supported_digests );
99 #if defined(POLARSSL_MD2_C) 100 if( !strcasecmp(
"MD2", md_name ) )
103 #if defined(POLARSSL_MD4_C) 104 if( !strcasecmp(
"MD4", md_name ) )
107 #if defined(POLARSSL_MD5_C) 108 if( !strcasecmp(
"MD5", md_name ) )
111 #if defined(POLARSSL_RIPEMD160_C) 112 if( !strcasecmp(
"RIPEMD160", md_name ) )
115 #if defined(POLARSSL_SHA1_C) 116 if( !strcasecmp(
"SHA1", md_name ) || !strcasecmp(
"SHA", md_name ) )
119 #if defined(POLARSSL_SHA256_C) 120 if( !strcasecmp(
"SHA224", md_name ) )
122 if( !strcasecmp(
"SHA256", md_name ) )
125 #if defined(POLARSSL_SHA512_C) 126 if( !strcasecmp(
"SHA384", md_name ) )
128 if( !strcasecmp(
"SHA512", md_name ) )
138 #if defined(POLARSSL_MD2_C) 142 #if defined(POLARSSL_MD4_C) 146 #if defined(POLARSSL_MD5_C) 150 #if defined(POLARSSL_RIPEMD160_C) 154 #if defined(POLARSSL_SHA1_C) 158 #if defined(POLARSSL_SHA256_C) 164 #if defined(POLARSSL_SHA512_C) 193 if( md_info == NULL || ctx == NULL )
217 if( ctx == NULL || ctx->
md_info == NULL )
227 if( ctx == NULL || ctx->
md_info == NULL )
237 if( ctx == NULL || ctx->
md_info == NULL )
245 int md(
const md_info_t *md_info,
const unsigned char *input,
size_t ilen,
246 unsigned char *output )
248 if( md_info == NULL )
256 int md_file(
const md_info_t *md_info,
const char *path,
unsigned char *output )
258 #if defined(POLARSSL_FS_IO) 262 if( md_info == NULL )
265 #if defined(POLARSSL_FS_IO) 266 ret = md_info->
file_func( path, output );
281 if( ctx == NULL || ctx->
md_info == NULL )
291 if( ctx == NULL || ctx->
md_info == NULL )
301 if( ctx == NULL || ctx->
md_info == NULL )
311 if( ctx == NULL || ctx->
md_info == NULL )
319 int md_hmac(
const md_info_t *md_info,
const unsigned char *key,
size_t keylen,
320 const unsigned char *input,
size_t ilen,
321 unsigned char *output )
323 if( md_info == NULL )
326 md_info->
hmac_func( key, keylen, input, ilen, output );
333 if( ctx == NULL || ctx->
md_info == NULL )
void *(* ctx_alloc_func)(void)
Allocate a new context.
int md(const md_info_t *md_info, const unsigned char *input, size_t ilen, unsigned char *output)
Output = message_digest( input buffer )
void(* process_func)(void *ctx, const unsigned char *input)
Internal use only.
#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.
void md_init(md_context_t *ctx)
Initialize a md_context (as NONE)
#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)
Configuration options (set of defines)
void(* digest_func)(const unsigned char *input, size_t ilen, unsigned char *output)
Generic digest function.
void(* hmac_update_func)(void *ctx, const unsigned char *input, size_t ilen)
HMAC update function.
#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.
void(* ctx_free_func)(void *ctx)
Free the given context.
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 md_free(md_context_t *ctx)
Free and clear the message-specific context of ctx.
void(* update_func)(void *ctx, const unsigned char *input, size_t ilen)
Digest update function.
void(* hmac_func)(const unsigned char *key, size_t keylen, const unsigned char *input, size_t ilen, unsigned char *output)
Generic HMAC function.
const md_info_t sha224_info
void(* finish_func)(void *ctx, unsigned char *output)
Digest finalisation 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_reset_func)(void *ctx)
HMAC context reset 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
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_finish_func)(void *ctx, unsigned char *output)
HMAC finalisation 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
void(* starts_func)(void *ctx)
Digest initialisation function.
int md_hmac_finish(md_context_t *ctx, unsigned char *output)
Generic HMAC final digest.
Generic message digest context.
int(* file_func)(const char *path, unsigned char *output)
Generic file digest function.