cmac.h
Go to the documentation of this file.
1 /**
2  * @file cmac.h
3  * @brief CMAC (Cipher-based 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 _CMAC_H
32 #define _CMAC_H
33 
34 //Dependencies
35 #include "core/crypto.h"
37 
38 //Application specific context
39 #ifndef CMAC_PRIVATE_CONTEXT
40  #define CMAC_PRIVATE_CONTEXT
41 #endif
42 
43 //C++ guard
44 #ifdef __cplusplus
45 extern "C" {
46 #endif
47 
48 
49 /**
50  * @brief CMAC algorithm context
51  **/
52 
53 typedef struct
54 {
57  uint8_t k1[MAX_CIPHER_BLOCK_SIZE];
58  uint8_t k2[MAX_CIPHER_BLOCK_SIZE];
59  uint8_t buffer[MAX_CIPHER_BLOCK_SIZE];
60  size_t bufferLength;
61  uint8_t mac[MAX_CIPHER_BLOCK_SIZE];
63 } CmacContext;
64 
65 
66 //CMAC related functions
67 error_t cmacCompute(const CipherAlgo *cipher, const void *key, size_t keyLen,
68  const void *data, size_t dataLen, uint8_t *mac, size_t macLen);
69 
70 error_t cmacInit(CmacContext *context, const CipherAlgo *cipher,
71  const void *key, size_t keyLen);
72 
73 void cmacReset(CmacContext *context);
74 void cmacUpdate(CmacContext *context, const void *data, size_t dataLen);
75 error_t cmacFinal(CmacContext *context, uint8_t *mac, size_t macLen);
76 void cmacDeinit(CmacContext *context);
77 
78 void cmacMul(uint8_t *x, const uint8_t *a, size_t n, uint8_t rb);
79 void cmacXorBlock(uint8_t *x, const uint8_t *a, const uint8_t *b, size_t n);
80 
81 //C++ guard
82 #ifdef __cplusplus
83 }
84 #endif
85 
86 #endif
Collection of AEAD algorithms.
#define MAX_CIPHER_BLOCK_SIZE
void cmacMul(uint8_t *x, const uint8_t *a, size_t n, uint8_t rb)
Multiplication by x in GF(2^128)
Definition: cmac.c:318
#define CMAC_PRIVATE_CONTEXT
Definition: cmac.h:40
void cmacDeinit(CmacContext *context)
Release CMAC context.
Definition: cmac.c:296
error_t cmacCompute(const CipherAlgo *cipher, const void *key, size_t keyLen, const void *data, size_t dataLen, uint8_t *mac, size_t macLen)
Compute CMAC using the specified cipher algorithm.
Definition: cmac.c:58
error_t cmacFinal(CmacContext *context, uint8_t *mac, size_t macLen)
Finish the CMAC calculation.
Definition: cmac.c:237
void cmacUpdate(CmacContext *context, const void *data, size_t dataLen)
Update the CMAC context with a portion of the message being hashed.
Definition: cmac.c:191
void cmacReset(CmacContext *context)
Reset CMAC context.
Definition: cmac.c:172
void cmacXorBlock(uint8_t *x, const uint8_t *a, const uint8_t *b, size_t n)
XOR operation.
Definition: cmac.c:349
error_t cmacInit(CmacContext *context, const CipherAlgo *cipher, const void *key, size_t keyLen)
Initialize CMAC calculation.
Definition: cmac.c:107
General definitions for cryptographic algorithms.
uint8_t n
error_t
Error codes.
Definition: error.h:43
uint8_t data[]
Definition: ethernet.h:222
uint8_t x
Definition: lldp_ext_med.h:211
uint8_t b
Definition: nbns_common.h:104
uint8_t a
Definition: ndp.h:411
uint32_t dataLen
Definition: sftp_common.h:229
Common interface for encryption algorithms.
Definition: crypto.h:1036
CMAC algorithm context.
Definition: cmac.h:54
CipherContext cipherContext
Definition: cmac.h:56
const CipherAlgo * cipher
Definition: cmac.h:55
size_t bufferLength
Definition: cmac.h:60
Generic cipher algorithm context.