PolarSSL v1.3.9
md.h File Reference

Generic message digest wrapper. More...

#include <string.h>
Include dependency graph for md.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  md_info_t
 Message digest information. More...
 
struct  md_context_t
 Generic message digest context. More...
 

Macros

#define POLARSSL_ERR_MD_FEATURE_UNAVAILABLE   -0x5080
 The selected feature is not available.
 
#define POLARSSL_ERR_MD_BAD_INPUT_DATA   -0x5100
 Bad input parameters to function.
 
#define POLARSSL_ERR_MD_ALLOC_FAILED   -0x5180
 Failed to allocate memory.
 
#define POLARSSL_ERR_MD_FILE_IO_ERROR   -0x5200
 Opening or reading of file failed.
 
#define POLARSSL_MD_MAX_SIZE   32 /* longest known is SHA256 or less */
 
#define MD_CONTEXT_T_INIT
 

Enumerations

enum  md_type_t {
  POLARSSL_MD_NONE =0 , POLARSSL_MD_MD2 , POLARSSL_MD_MD4 , POLARSSL_MD_MD5 ,
  POLARSSL_MD_SHA1 , POLARSSL_MD_SHA224 , POLARSSL_MD_SHA256 , POLARSSL_MD_SHA384 ,
  POLARSSL_MD_SHA512 , POLARSSL_MD_RIPEMD160
}
 

Functions

const int * md_list (void)
 Returns the list of digests supported by the generic digest module.
 
const md_info_tmd_info_from_string (const char *md_name)
 Returns the message digest information associated with the given digest name.
 
const md_info_tmd_info_from_type (md_type_t md_type)
 Returns the message digest information associated with the given digest type.
 
void md_init (md_context_t *ctx)
 Initialize a md_context (as NONE)
 
void md_free (md_context_t *ctx)
 Free and clear the message-specific context of ctx.
 
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_free_ctx (md_context_t *ctx)
 Free the message-specific context of ctx.
 
static unsigned char md_get_size (const md_info_t *md_info)
 Returns the size of the message digest output.
 
static md_type_t md_get_type (const md_info_t *md_info)
 Returns the type of the message digest output.
 
static const char * md_get_name (const md_info_t *md_info)
 Returns the name of the message digest output.
 
int md_starts (md_context_t *ctx)
 Set-up the given context for a new message digest.
 
int md_update (md_context_t *ctx, const unsigned char *input, size_t ilen)
 Generic message digest process buffer.
 
int md_finish (md_context_t *ctx, unsigned char *output)
 Generic message digest final digest.
 
int md (const md_info_t *md_info, const unsigned char *input, size_t ilen, unsigned char *output)
 Output = message_digest( input buffer )
 
int md_file (const md_info_t *md_info, const char *path, unsigned char *output)
 Output = message_digest( file contents )
 
int md_hmac_starts (md_context_t *ctx, const unsigned char *key, size_t keylen)
 Generic HMAC context setup.
 
int md_hmac_update (md_context_t *ctx, const unsigned char *input, size_t ilen)
 Generic HMAC process buffer.
 
int md_hmac_finish (md_context_t *ctx, unsigned char *output)
 Generic HMAC final digest.
 
int md_hmac_reset (md_context_t *ctx)
 Generic HMAC context reset.
 
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 )
 
int md_process (md_context_t *ctx, const unsigned char *data)
 

Detailed Description

Generic message digest wrapper.

Author
Adriaan de Jong dejon.nosp@m.g@fo.nosp@m.x-it..nosp@m.com

Copyright (C) 2006-2014, Brainspark B.V.

This file is part of PolarSSL (http://www.polarssl.org) Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>

All rights reserved.

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

Definition in file md.h.

Macro Definition Documentation

◆ MD_CONTEXT_T_INIT

#define MD_CONTEXT_T_INIT
Value:
{ \
NULL, /* md_info */ \
NULL, /* md_ctx */ \
}

Definition at line 140 of file md.h.

◆ POLARSSL_ERR_MD_ALLOC_FAILED

#define POLARSSL_ERR_MD_ALLOC_FAILED   -0x5180

Failed to allocate memory.

Definition at line 44 of file md.h.

◆ POLARSSL_ERR_MD_BAD_INPUT_DATA

#define POLARSSL_ERR_MD_BAD_INPUT_DATA   -0x5100

Bad input parameters to function.

Definition at line 43 of file md.h.

◆ POLARSSL_ERR_MD_FEATURE_UNAVAILABLE

#define POLARSSL_ERR_MD_FEATURE_UNAVAILABLE   -0x5080

The selected feature is not available.

Definition at line 42 of file md.h.

◆ POLARSSL_ERR_MD_FILE_IO_ERROR

#define POLARSSL_ERR_MD_FILE_IO_ERROR   -0x5200

Opening or reading of file failed.

Definition at line 45 of file md.h.

◆ POLARSSL_MD_MAX_SIZE

#define POLARSSL_MD_MAX_SIZE   32 /* longest known is SHA256 or less */

Definition at line 67 of file md.h.

Enumeration Type Documentation

◆ md_type_t

enum md_type_t
Enumerator
POLARSSL_MD_NONE 
POLARSSL_MD_MD2 
POLARSSL_MD_MD4 
POLARSSL_MD_MD5 
POLARSSL_MD_SHA1 
POLARSSL_MD_SHA224 
POLARSSL_MD_SHA256 
POLARSSL_MD_SHA384 
POLARSSL_MD_SHA512 
POLARSSL_MD_RIPEMD160 

Definition at line 51 of file md.h.

Function Documentation

◆ md()

int md ( const md_info_t * md_info,
const unsigned char * input,
size_t ilen,
unsigned char * output )

Output = message_digest( input buffer )

Parameters
md_infomessage digest info
inputbuffer holding the data
ilenlength of the input data
outputGeneric message digest checksum result
Returns
0 on success, POLARSSL_ERR_MD_BAD_INPUT_DATA if parameter verification fails.

◆ md_file()

int md_file ( const md_info_t * md_info,
const char * path,
unsigned char * output )

Output = message_digest( file contents )

Parameters
md_infomessage digest info
pathinput file name
outputgeneric message digest checksum result
Returns
0 if successful, POLARSSL_ERR_MD_FILE_OPEN_FAILED if fopen failed, POLARSSL_ERR_MD_FILE_READ_FAILED if fread failed, POLARSSL_ERR_MD_BAD_INPUT_DATA if md_info was NULL.

◆ md_finish()

int md_finish ( md_context_t * ctx,
unsigned char * output )

Generic message digest final digest.

Parameters
ctxGeneric message digest context
outputGeneric message digest checksum result
Returns
0 on success, POLARSSL_ERR_MD_BAD_INPUT_DATA if parameter verification fails.

◆ md_free()

void md_free ( md_context_t * ctx)

Free and clear the message-specific context of ctx.

Freeing ctx itself remains the responsibility of the caller.

◆ md_free_ctx()

int md_free_ctx ( md_context_t * ctx)

Free the message-specific context of ctx.

Freeing ctx itself remains the responsibility of the caller.

Note
Deprecated: Redirects to md_free()
Parameters
ctxFree the message-specific context
Returns
0

◆ md_get_name()

static const char * md_get_name ( const md_info_t * md_info)
inlinestatic

Returns the name of the message digest output.

Parameters
md_infomessage digest info
Returns
name of the message digest output.

Definition at line 255 of file md.h.

References md_info_t::name.

◆ md_get_size()

static unsigned char md_get_size ( const md_info_t * md_info)
inlinestatic

Returns the size of the message digest output.

Parameters
md_infomessage digest info
Returns
size of the message digest output.

Definition at line 225 of file md.h.

References md_info_t::size.

◆ md_get_type()

static md_type_t md_get_type ( const md_info_t * md_info)
inlinestatic

Returns the type of the message digest output.

Parameters
md_infomessage digest info
Returns
type of the message digest output.

Definition at line 240 of file md.h.

References POLARSSL_MD_NONE, and md_info_t::type.

◆ md_hmac()

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 )

Parameters
md_infomessage digest info
keyHMAC secret key
keylenlength of the HMAC key
inputbuffer holding the data
ilenlength of the input data
outputGeneric HMAC-result
Returns
0 on success, POLARSSL_ERR_MD_BAD_INPUT_DATA if parameter verification fails.

◆ md_hmac_finish()

int md_hmac_finish ( md_context_t * ctx,
unsigned char * output )

Generic HMAC final digest.

Parameters
ctxHMAC context
outputGeneric HMAC checksum result
Returns
0 on success, POLARSSL_ERR_MD_BAD_INPUT_DATA if parameter verification fails.

◆ md_hmac_reset()

int md_hmac_reset ( md_context_t * ctx)

Generic HMAC context reset.

Parameters
ctxHMAC context to be reset
Returns
0 on success, POLARSSL_ERR_MD_BAD_INPUT_DATA if parameter verification fails.

◆ md_hmac_starts()

int md_hmac_starts ( md_context_t * ctx,
const unsigned char * key,
size_t keylen )

Generic HMAC context setup.

Parameters
ctxHMAC context to be initialized
keyHMAC secret key
keylenlength of the HMAC key
Returns
0 on success, POLARSSL_ERR_MD_BAD_INPUT_DATA if parameter verification fails.

◆ md_hmac_update()

int md_hmac_update ( md_context_t * ctx,
const unsigned char * input,
size_t ilen )

Generic HMAC process buffer.

Parameters
ctxHMAC context
inputbuffer holding the data
ilenlength of the input data
Returns
0 on success, POLARSSL_ERR_MD_BAD_INPUT_DATA if parameter verification fails.

◆ md_info_from_string()

const md_info_t * md_info_from_string ( const char * md_name)

Returns the message digest information associated with the given digest name.

Parameters
md_nameName of the digest to search for.
Returns
The message digest information associated with md_name or NULL if not found.

◆ md_info_from_type()

const md_info_t * md_info_from_type ( md_type_t md_type)

Returns the message digest information associated with the given digest type.

Parameters
md_typetype of digest to search for.
Returns
The message digest information associated with md_type or NULL if not found.

◆ md_init()

void md_init ( md_context_t * ctx)

Initialize a md_context (as NONE)

◆ md_init_ctx()

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.

Note
Currently also clears structure. In future versions you will be required to call md_init() on the structure first.
Parameters
ctxcontext to initialise. May not be NULL. The digest-specific context (ctx->md_ctx) must be NULL. It will be allocated, and must be freed using md_free_ctx() later.
md_infomessage digest to use.
Returns
0 on success, POLARSSL_ERR_MD_BAD_INPUT_DATA on parameter failure, POLARSSL_ERR_MD_ALLOC_FAILED if allocation of the digest-specific context failed.

◆ md_list()

const int * md_list ( void )

Returns the list of digests supported by the generic digest module.

Returns
a statically allocated array of digests, the last entry is 0.

◆ md_process()

int md_process ( md_context_t * ctx,
const unsigned char * data )

◆ md_starts()

int md_starts ( md_context_t * ctx)

Set-up the given context for a new message digest.

Parameters
ctxgeneric message digest context.
Returns
0 on success, POLARSSL_ERR_MD_BAD_INPUT_DATA if parameter verification fails.

◆ md_update()

int md_update ( md_context_t * ctx,
const unsigned char * input,
size_t ilen )

Generic message digest process buffer.

Parameters
ctxGeneric message digest context
inputbuffer holding the datal
ilenlength of the input data
Returns
0 on success, POLARSSL_ERR_MD_BAD_INPUT_DATA if parameter verification fails.