kmac.h File Reference

KMAC (Keccak Message Authentication Code) More...

#include "core/crypto.h"
#include "xof/cshake.h"

Go to the source code of this file.

Data Structures

struct  KmacContext
 KMAC algorithm context. More...
 

Macros

#define KMAC_PRIVATE_CONTEXT
 

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]
 
const uint8_t kmac256Oid [9]
 

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.

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

Definition in file kmac.h.

Macro Definition Documentation

◆ KMAC_PRIVATE_CONTEXT

#define KMAC_PRIVATE_CONTEXT

Definition at line 40 of file kmac.h.

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]
extern

Definition at line 48 of file kmac.c.

◆ kmac256Oid

const uint8_t kmac256Oid[9]
extern

Definition at line 50 of file kmac.c.