kmac.c File Reference

KMAC (Keccak Message Authentication Code) More...

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

Go to the source code of this file.

Macros

#define TRACE_LEVEL   CRYPTO_TRACE_LEVEL
 

Functions

error_t kmacCompute (uint_t strength, const void *key, size_t keyLen, const void *data, size_t dataLen, const char_t *custom, size_t customLen, uint8_t *mac, size_t macLen)
 Compute KMAC message authentication code. More...
 
error_t kmacInit (KmacContext *context, uint_t strength, const void *key, size_t keyLen, const char_t *custom, size_t customLen)
 Initialize KMAC calculation. More...
 
void kmacUpdate (KmacContext *context, const void *data, size_t dataLen)
 Update the KMAC context with a portion of the message being hashed. More...
 
error_t kmacFinal (KmacContext *context, uint8_t *mac, size_t macLen)
 Finish the KMAC calculation. More...
 
void kmacDeinit (KmacContext *context)
 Release KMAC context. More...
 
void kmacRightEncode (size_t value, uint8_t *buffer, size_t *length)
 Encode integer as byte string. More...
 

Variables

const uint8_t kmac128Oid [9] = {0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x13}
 
const uint8_t kmac256Oid [9] = {0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x14}
 

Detailed Description

KMAC (Keccak Message Authentication Code)

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

The Keccak Message Authentication Code (KMAC) algorithm is a PRF and keyed hash function based on Keccak. KMAC has two variants, KMAC128 and KMAC256, built from cSHAKE128 and cSHAKE256, respectively

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

Definition in file kmac.c.

Macro Definition Documentation

◆ TRACE_LEVEL

#define TRACE_LEVEL   CRYPTO_TRACE_LEVEL

Definition at line 38 of file kmac.c.

Function Documentation

◆ kmacCompute()

error_t kmacCompute ( uint_t  strength,
const void *  key,
size_t  keyLen,
const void *  data,
size_t  dataLen,
const char_t custom,
size_t  customLen,
uint8_t *  mac,
size_t  macLen 
)

Compute KMAC message authentication code.

Parameters
[in]strengthNumber of bits of security (128 for KMAC128 and 256 for KMAC256)
[in]keyPointer to the secret key (K)
[in]keyLenLength of the secret key
[in]dataPointer to the input message (X)
[in]dataLenLength of the input data
[in]customCustomization string (S)
[in]customLenLength of the customization string
[out]macCalculated MAC value
[in]macLenExpected length of the MAC (L)
Returns
Error code

Definition at line 68 of file kmac.c.

◆ kmacDeinit()

void kmacDeinit ( KmacContext context)

Release KMAC context.

Parameters
[in]contextPointer to the KMAC context

Definition at line 232 of file kmac.c.

◆ kmacFinal()

error_t kmacFinal ( KmacContext context,
uint8_t *  mac,
size_t  macLen 
)

Finish the KMAC calculation.

Parameters
[in]contextPointer to the KMAC context
[out]macCalculated MAC value
[in]macLenExpected length of the MAC (L)
Returns
Error code

Definition at line 199 of file kmac.c.

◆ kmacInit()

error_t kmacInit ( KmacContext context,
uint_t  strength,
const void *  key,
size_t  keyLen,
const char_t custom,
size_t  customLen 
)

Initialize KMAC calculation.

Parameters
[in]contextPointer to the KMAC context to initialize
[in]strengthNumber of bits of security (128 for KMAC128 and 256 for KMAC256)
[in]keyPointer to the secret key (K)
[in]keyLenLength of the secret key
[in]customCustomization string (S)
[in]customLenLength of the customization string
Returns
Error code

Definition at line 121 of file kmac.c.

◆ kmacRightEncode()

void kmacRightEncode ( size_t  value,
uint8_t *  buffer,
size_t *  length 
)

Encode integer as byte string.

Parameters
[in]valueValue of the integer to be encoded
[out]bufferBuffer where to store the byte string representation
[out]lengthLength of the resulting byte string

Definition at line 250 of file kmac.c.

◆ kmacUpdate()

void kmacUpdate ( KmacContext context,
const void *  data,
size_t  dataLen 
)

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

Parameters
[in]contextPointer to the KMAC context
[in]dataPointer to the input data
[in]dataLenLength of the buffer

Definition at line 184 of file kmac.c.

Variable Documentation

◆ kmac128Oid

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

Definition at line 48 of file kmac.c.

◆ kmac256Oid

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

Definition at line 50 of file kmac.c.