kmac.h
Go to the documentation of this file.
1 /**
2  * @file kmac.h
3  * @brief KMAC (Keccak Message Authentication Code)
4  *
5  * @section License
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  *
9  * Copyright (C) 2010-2024 Oryx Embedded SARL. All rights reserved.
10  *
11  * This file is part of CycloneCRYPTO Open.
12  *
13  * This program is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU General Public License
15  * as published by the Free Software Foundation; either version 2
16  * of the License, or (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software Foundation,
25  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
26  *
27  * @author Oryx Embedded SARL (www.oryx-embedded.com)
28  * @version 2.4.0
29  **/
30 
31 #ifndef _KMAC_H
32 #define _KMAC_H
33 
34 //Dependencies
35 #include "core/crypto.h"
36 #include "xof/cshake.h"
37 
38 //Application specific context
39 #ifndef KMAC_PRIVATE_CONTEXT
40  #define KMAC_PRIVATE_CONTEXT
41 #endif
42 
43 //C++ guard
44 #ifdef __cplusplus
45 extern "C" {
46 #endif
47 
48 
49 /**
50  * @brief KMAC algorithm context
51  **/
52 
53 typedef struct
54 {
57 } KmacContext;
58 
59 
60 //KMAC related constants
61 extern const uint8_t kmac128Oid[9];
62 extern const uint8_t kmac256Oid[9];
63 
64 //KMAC related functions
65 error_t kmacCompute(uint_t strength, const void *key, size_t keyLen,
66  const void *data, size_t dataLen, const char_t *custom, size_t customLen,
67  uint8_t *mac, size_t macLen);
68 
69 error_t kmacInit(KmacContext *context, uint_t strength, const void *key,
70  size_t keyLen, const char_t *custom, size_t customLen);
71 
72 void kmacUpdate(KmacContext *context, const void *data, size_t dataLen);
73 error_t kmacFinal(KmacContext *context, uint8_t *mac, size_t macLen);
74 void kmacDeinit(KmacContext *context);
75 
76 void kmacRightEncode(size_t value, uint8_t *buffer, size_t *length);
77 
78 //C++ guard
79 #ifdef __cplusplus
80 }
81 #endif
82 
83 #endif
unsigned int uint_t
Definition: compiler_port.h:50
char char_t
Definition: compiler_port.h:48
General definitions for cryptographic algorithms.
cSHAKE128 and cSHAKE256 (customizable SHAKE function)
error_t
Error codes.
Definition: error.h:43
uint8_t data[]
Definition: ethernet.h:222
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.
Definition: kmac.c:68
#define KMAC_PRIVATE_CONTEXT
Definition: kmac.h:40
void kmacRightEncode(size_t value, uint8_t *buffer, size_t *length)
Encode integer as byte string.
Definition: kmac.c:250
error_t kmacInit(KmacContext *context, uint_t strength, const void *key, size_t keyLen, const char_t *custom, size_t customLen)
Initialize KMAC calculation.
Definition: kmac.c:121
void kmacUpdate(KmacContext *context, const void *data, size_t dataLen)
Update the KMAC context with a portion of the message being hashed.
Definition: kmac.c:184
const uint8_t kmac256Oid[9]
Definition: kmac.c:50
void kmacDeinit(KmacContext *context)
Release KMAC context.
Definition: kmac.c:232
const uint8_t kmac128Oid[9]
Definition: kmac.c:48
error_t kmacFinal(KmacContext *context, uint8_t *mac, size_t macLen)
Finish the KMAC calculation.
Definition: kmac.c:199
uint32_t dataLen
Definition: sftp_common.h:229
cSHAKE algorithm context
Definition: cshake.h:49
KMAC algorithm context.
Definition: kmac.h:54
CshakeContext cshakeContext
Definition: kmac.h:55
uint8_t length
Definition: tcp.h:368
uint8_t value[]
Definition: tcp.h:369