tinydtls  0.8.1
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups
Data Structures | Macros | Enumerations | Functions
Keyed-Hash Message Authentication Code (HMAC)

Data Structures

struct  dtls_hmac_context_t
 

Macros

#define DTLS_HMAC_BLOCKSIZE   64
 
#define DTLS_HMAC_DIGEST_SIZE   32
 
#define DTLS_HMAC_MAX   64
 

Enumerations

enum  dtls_hashfunc_t {
  HASH_NONE =0, HASH_MD5 =1, HASH_SHA1 =2, HASH_SHA224 =3,
  HASH_SHA256 =4, HASH_SHA384 =5, HASH_SHA512 =6
}
 

Functions

void dtls_hmac_init (dtls_hmac_context_t *ctx, const unsigned char *key, size_t klen)
 
dtls_hmac_context_tdtls_hmac_new (const unsigned char *key, size_t klen)
 
void dtls_hmac_free (dtls_hmac_context_t *ctx)
 
void dtls_hmac_update (dtls_hmac_context_t *ctx, const unsigned char *input, size_t ilen)
 
int dtls_hmac_finalize (dtls_hmac_context_t *ctx, unsigned char *result)
 

Detailed Description

NIST Standard FIPS 198 describes the Keyed-Hash Message Authentication Code (HMAC) which is used as hash function for the DTLS PRF.

Macro Definition Documentation

#define DTLS_HMAC_BLOCKSIZE   64

size of hmac blocks

Definition at line 73 of file hmac.h.

#define DTLS_HMAC_DIGEST_SIZE   32

digest size (for SHA-256)

Definition at line 74 of file hmac.h.

#define DTLS_HMAC_MAX   64

max number of bytes in digest

Definition at line 75 of file hmac.h.

Enumeration Type Documentation

List of known hash functions for use in dtls_hmac_init(). The identifiers are the same as the HashAlgorithm defined in Section 7.4.1.4.1 of RFC 5246.

Enumerator
HASH_NONE 
HASH_MD5 
HASH_SHA1 
HASH_SHA224 
HASH_SHA256 
HASH_SHA384 
HASH_SHA512 

Definition at line 83 of file hmac.h.

Function Documentation

int dtls_hmac_finalize ( dtls_hmac_context_t ctx,
unsigned char *  result 
)

Completes the HMAC generation and writes the result to the given output parameter result. The buffer must be large enough to hold the message digest created by the actual hash function. If in doubt, use DTLS_HMAC_MAX. The function returns the number of bytes written to result.

Parameters
ctxThe HMAC context.
resultOutput parameter where the MAC is written to.
Returns
Length of the MAC written to result.

Definition at line 127 of file hmac.c.

void dtls_hmac_free ( dtls_hmac_context_t ctx)

Releases the storage for ctx that has been allocated by dtls_hmac_new().

Parameters
ctxThe dtls_hmac_context_t to free.

Definition at line 121 of file hmac.c.

void dtls_hmac_init ( dtls_hmac_context_t ctx,
const unsigned char *  key,
size_t  klen 
)

Initializes an existing HMAC context.

Parameters
ctxThe HMAC context to initialize.
keyThe secret key.
klenThe length of key.

Definition at line 94 of file hmac.c.

dtls_hmac_context_t* dtls_hmac_new ( const unsigned char *  key,
size_t  klen 
)

Allocates a new HMAC context ctx with the given secret key. This function returns 1 if ctx has been set correctly, or 0 or -1 otherwise. Note that this function allocates new storage that must be released by dtls_hmac_free().

Parameters
keyThe secret key.
klenThe length of key.
Returns
A new dtls_hmac_context_t object or NULL on error

Definition at line 83 of file hmac.c.

void dtls_hmac_update ( dtls_hmac_context_t ctx,
const unsigned char *  input,
size_t  ilen 
)

Updates the HMAC context with data from input.

Parameters
ctxThe HMAC context.
inputThe input data.
ilenSize of input.

Definition at line 76 of file hmac.c.