Macros | Enumerations | Functions
HMAC: Hash-based Message Authentication Code

This module provides optional support for Keyed-Hash Message Authentication Codes. It is intended to comply with RFC 2104. More...

Macros

#define MAIN_ERR_PREFIX   "HMAC: "
 Message prefix for HMAC module.
 

Enumerations

enum  hmac_alg { HMAC_ALG_SHA1_160, HMAC_ALG_SHA2_256 }
 

Functions

int hmac_sha1_160 (const char *text, size_t text_len, const char *key, size_t key_len, unsigned char *mac)
 Message Authentication Code based on SHA1-160 hash algorithm. More...
 
int hmac_sha2_256 (const char *text, size_t text_len, const char *key, size_t key_len, unsigned char *mac)
 Message Authentication Code based on SHA2-256 hash algorithm. More...
 
void hmac_init (void)
 Initialize HMAC module.
 
void hmac_exit (void)
 Shutdown HMAC module.
 

Lenght of message authentication codes

#define HMAC_SHA1_160_LEN   (size_t) 20
 160 bit
 
#define HMAC_SHA2_256_LEN   (size_t) 32
 256 bit
 

Detailed Description

This module provides optional support for Keyed-Hash Message Authentication Codes. It is intended to comply with RFC 2104.

Attention
This module currently works only if TLS support is available (because both share the cryptographic functions provided by OpenSSL).

Function Documentation

◆ hmac_sha1_160()

int hmac_sha1_160 ( const char *  text,
size_t  text_len,
const char *  key,
size_t  key_len,
unsigned char *  mac 
)

Message Authentication Code based on SHA1-160 hash algorithm.

Parameters
[in]textMessage
[in]text_lenMessage length
[in]keyKey
[in]key_lenKey length
[out]macResult

The values of paramaters text_len and key_len must represent bytes.

On success, the result is written to mac and has a length of HMAC_SHA1_160_LEN bytes.

Returns
  • 0 on success
  • -1 on error

Definition at line 224 of file hmac.c.

Referenced by core_get_cancel_key().

◆ hmac_sha2_256()

int hmac_sha2_256 ( const char *  text,
size_t  text_len,
const char *  key,
size_t  key_len,
unsigned char *  mac 
)

Message Authentication Code based on SHA2-256 hash algorithm.

Parameters
[in]textMessage
[in]text_lenMessage length
[in]keyKey
[in]key_lenKey length
[out]macResult

The values of paramaters text_len and key_len must represent bytes.

On success, the result is written to mac and has a length of HMAC_SHA2_256_LEN bytes.

Returns
  • 0 on success
  • -1 on error

Definition at line 250 of file hmac.c.

Referenced by core_get_cancel_key().


Generated at 2024-04-27 using  doxygen