hmac.c File Reference

HMAC (Keyed-Hashing for Message Authentication) More...

#include "core/crypto.h"
#include "mac/hmac.h"

Go to the source code of this file.

Macros

#define TRACE_LEVEL   CRYPTO_TRACE_LEVEL
 

Functions

__weak_func error_t hmacCompute (const HashAlgo *hash, const void *key, size_t keyLen, const void *data, size_t dataLen, uint8_t *digest)
 Compute HMAC using the specified hash function. More...
 
__weak_func error_t hmacInit (HmacContext *context, const HashAlgo *hash, const void *key, size_t keyLen)
 Initialize HMAC calculation. More...
 
__weak_func void hmacUpdate (HmacContext *context, const void *data, size_t length)
 Update the HMAC context with a portion of the message being hashed. More...
 
__weak_func void hmacFinal (HmacContext *context, uint8_t *digest)
 Finish the HMAC calculation. More...
 
void hmacDeinit (HmacContext *context)
 Release HMAC context. More...
 
void hmacFinalRaw (HmacContext *context, uint8_t *digest)
 Finish the HMAC calculation (no padding added) More...
 

Variables

const uint8_t HMAC_WITH_MD5_OID [8] = {0x2B, 0x06, 0x01, 0x05, 0x05, 0x08, 0x01, 0x01}
 
const uint8_t HMAC_WITH_TIGER_OID [8] = {0x2B, 0x06, 0x01, 0x05, 0x05, 0x08, 0x01, 0x03}
 
const uint8_t HMAC_WITH_RIPEMD160_OID [8] = {0x2B, 0x06, 0x01, 0x05, 0x05, 0x08, 0x01, 0x04}
 
const uint8_t HMAC_WITH_SHA1_OID [8] = {0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x02, 0x07}
 
const uint8_t HMAC_WITH_SHA224_OID [8] = {0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x02, 0x08}
 
const uint8_t HMAC_WITH_SHA256_OID [8] = {0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x02, 0x09}
 
const uint8_t HMAC_WITH_SHA384_OID [8] = {0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x02, 0x0A}
 
const uint8_t HMAC_WITH_SHA512_OID [8] = {0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x02, 0x0B}
 
const uint8_t HMAC_WITH_SHA512_224_OID [8] = {0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x02, 0x0C}
 
const uint8_t HMAC_WITH_SHA512_256_OID [8] = {0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x02, 0x0D}
 
const uint8_t HMAC_WITH_SHA3_224_OID [9] = {0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x0D}
 
const uint8_t HMAC_WITH_SHA3_256_OID [9] = {0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x0E}
 
const uint8_t HMAC_WITH_SHA3_384_OID [9] = {0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x0F}
 
const uint8_t HMAC_WITH_SHA3_512_OID [9] = {0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x10}
 
const uint8_t HMAC_WITH_SM3_OID [10] = {0x2A, 0x81, 0x1C, 0xCF, 0x55, 0x01, 0x82, 0x91, 0x03, 0x01}
 

Detailed Description

HMAC (Keyed-Hashing for Message Authentication)

License

SPDX-License-Identifier: GPL-2.0-or-later

Copyright (C) 2010-2024 Oryx Embedded SARL. All rights reserved.

This file is part of CycloneCRYPTO Open.

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.

Description

HMAC is a mechanism for message authentication using cryptographic hash functions. HMAC can be used with any iterative cryptographic hash function (MD5, SHA-1 or SHA-256) in combination with a secret shared key. Refer to RFC 2104 for more details

Author
Oryx Embedded SARL (www.oryx-embedded.com)
Version
2.4.4

Definition in file hmac.c.

Macro Definition Documentation

◆ TRACE_LEVEL

#define TRACE_LEVEL   CRYPTO_TRACE_LEVEL

Definition at line 39 of file hmac.c.

Function Documentation

◆ hmacCompute()

__weak_func error_t hmacCompute ( const HashAlgo hash,
const void *  key,
size_t  keyLen,
const void *  data,
size_t  dataLen,
uint8_t *  digest 
)

Compute HMAC using the specified hash function.

Parameters
[in]hashHash algorithm used to compute HMAC
[in]keyKey to use in the hash algorithm
[in]keyLenLength of the key
[in]dataThe input data for which to compute the hash code
[in]dataLenLength of the input data
[out]digestThe computed HMAC value
Returns
Error code

Definition at line 91 of file hmac.c.

◆ hmacDeinit()

void hmacDeinit ( HmacContext context)

Release HMAC context.

Parameters
[in]contextPointer to the HMAC context

Definition at line 256 of file hmac.c.

◆ hmacFinal()

__weak_func void hmacFinal ( HmacContext context,
uint8_t *  digest 
)

Finish the HMAC calculation.

Parameters
[in]contextPointer to the HMAC context
[out]digestCalculated HMAC value (optional parameter)

Definition at line 218 of file hmac.c.

◆ hmacFinalRaw()

void hmacFinalRaw ( HmacContext context,
uint8_t *  digest 
)

Finish the HMAC calculation (no padding added)

Parameters
[in]contextPointer to the HMAC context
[out]digestCalculated HMAC value (optional parameter)

Definition at line 273 of file hmac.c.

◆ hmacInit()

__weak_func error_t hmacInit ( HmacContext context,
const HashAlgo hash,
const void *  key,
size_t  keyLen 
)

Initialize HMAC calculation.

Parameters
[in]contextPointer to the HMAC context to initialize
[in]hashHash algorithm used to compute HMAC
[in]keyKey to use in the hash algorithm
[in]keyLenLength of the key
Returns
Error code

Definition at line 140 of file hmac.c.

◆ hmacUpdate()

__weak_func void hmacUpdate ( HmacContext context,
const void *  data,
size_t  length 
)

Update the HMAC context with a portion of the message being hashed.

Parameters
[in]contextPointer to the HMAC context
[in]dataPointer to the buffer being hashed
[in]lengthLength of the buffer

Definition at line 201 of file hmac.c.

Variable Documentation

◆ HMAC_WITH_MD5_OID

const uint8_t HMAC_WITH_MD5_OID[8] = {0x2B, 0x06, 0x01, 0x05, 0x05, 0x08, 0x01, 0x01}

Definition at line 49 of file hmac.c.

◆ HMAC_WITH_RIPEMD160_OID

const uint8_t HMAC_WITH_RIPEMD160_OID[8] = {0x2B, 0x06, 0x01, 0x05, 0x05, 0x08, 0x01, 0x04}

Definition at line 53 of file hmac.c.

◆ HMAC_WITH_SHA1_OID

const uint8_t HMAC_WITH_SHA1_OID[8] = {0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x02, 0x07}

Definition at line 55 of file hmac.c.

◆ HMAC_WITH_SHA224_OID

const uint8_t HMAC_WITH_SHA224_OID[8] = {0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x02, 0x08}

Definition at line 57 of file hmac.c.

◆ HMAC_WITH_SHA256_OID

const uint8_t HMAC_WITH_SHA256_OID[8] = {0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x02, 0x09}

Definition at line 59 of file hmac.c.

◆ HMAC_WITH_SHA384_OID

const uint8_t HMAC_WITH_SHA384_OID[8] = {0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x02, 0x0A}

Definition at line 61 of file hmac.c.

◆ HMAC_WITH_SHA3_224_OID

const uint8_t HMAC_WITH_SHA3_224_OID[9] = {0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x0D}

Definition at line 69 of file hmac.c.

◆ HMAC_WITH_SHA3_256_OID

const uint8_t HMAC_WITH_SHA3_256_OID[9] = {0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x0E}

Definition at line 71 of file hmac.c.

◆ HMAC_WITH_SHA3_384_OID

const uint8_t HMAC_WITH_SHA3_384_OID[9] = {0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x0F}

Definition at line 73 of file hmac.c.

◆ HMAC_WITH_SHA3_512_OID

const uint8_t HMAC_WITH_SHA3_512_OID[9] = {0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x10}

Definition at line 75 of file hmac.c.

◆ HMAC_WITH_SHA512_224_OID

const uint8_t HMAC_WITH_SHA512_224_OID[8] = {0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x02, 0x0C}

Definition at line 65 of file hmac.c.

◆ HMAC_WITH_SHA512_256_OID

const uint8_t HMAC_WITH_SHA512_256_OID[8] = {0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x02, 0x0D}

Definition at line 67 of file hmac.c.

◆ HMAC_WITH_SHA512_OID

const uint8_t HMAC_WITH_SHA512_OID[8] = {0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x02, 0x0B}

Definition at line 63 of file hmac.c.

◆ HMAC_WITH_SM3_OID

const uint8_t HMAC_WITH_SM3_OID[10] = {0x2A, 0x81, 0x1C, 0xCF, 0x55, 0x01, 0x82, 0x91, 0x03, 0x01}

Definition at line 77 of file hmac.c.

◆ HMAC_WITH_TIGER_OID

const uint8_t HMAC_WITH_TIGER_OID[8] = {0x2B, 0x06, 0x01, 0x05, 0x05, 0x08, 0x01, 0x03}

Definition at line 51 of file hmac.c.