xcbc_mac.h
Go to the documentation of this file.
1 /**
2  * @file xcbc_mac.h
3  * @brief XCBC-MAC 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.4
29  **/
30 
31 #ifndef _XCBC_MAC_H
32 #define _XCBC_MAC_H
33 
34 //Dependencies
35 #include "core/crypto.h"
37 
38 //Application specific context
39 #ifndef XCBC_MAC_PRIVATE_CONTEXT
40  #define XCBC_MAC_PRIVATE_CONTEXT
41 #endif
42 
43 //C++ guard
44 #ifdef __cplusplus
45 extern "C" {
46 #endif
47 
48 
49 /**
50  * @brief XCBC-MAC 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 k3[MAX_CIPHER_BLOCK_SIZE];
60  uint8_t buffer[MAX_CIPHER_BLOCK_SIZE];
61  size_t bufferLength;
62  uint8_t mac[MAX_CIPHER_BLOCK_SIZE];
65 
66 
67 //XCBC-MAC related functions
68 error_t xcbcMacCompute(const CipherAlgo *cipher, const void *key, size_t keyLen,
69  const void *data, size_t dataLen, uint8_t *mac, size_t macLen);
70 
71 error_t xcbcMacInit(XcbcMacContext *context, const CipherAlgo *cipher,
72  const void *key, size_t keyLen);
73 
74 void xcbcMacReset(XcbcMacContext *context);
75 void xcbcMacUpdate(XcbcMacContext *context, const void *data, size_t dataLen);
76 error_t xcbcMacFinal(XcbcMacContext *context, uint8_t *mac, size_t macLen);
77 void xcbcMacDeinit(XcbcMacContext *context);
78 
79 void xcbcMacXorBlock(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
void xcbcMacUpdate(XcbcMacContext *context, const void *data, size_t dataLen)
Update the XCBC-MAC context with a portion of the message being hashed.
Definition: xcbc_mac.c:183
XCBC-MAC algorithm context.
Definition: xcbc_mac.h:54
uint8_t b
Definition: nbns_common.h:104
const CipherAlgo * cipher
Definition: xcbc_mac.h:55
uint8_t a
Definition: ndp.h:411
uint8_t x
Definition: lldp_ext_med.h:211
Collection of AEAD algorithms.
uint8_t data[]
Definition: ethernet.h:222
size_t bufferLength
Definition: xcbc_mac.h:61
Generic cipher algorithm context.
#define MAX_CIPHER_BLOCK_SIZE
error_t xcbcMacCompute(const CipherAlgo *cipher, const void *key, size_t keyLen, const void *data, size_t dataLen, uint8_t *mac, size_t macLen)
Compute XCBC-MAC using the specified cipher algorithm.
Definition: xcbc_mac.c:58
error_t
Error codes.
Definition: error.h:43
error_t xcbcMacInit(XcbcMacContext *context, const CipherAlgo *cipher, const void *key, size_t keyLen)
Initialize XCBC-MAC calculation.
Definition: xcbc_mac.c:107
error_t xcbcMacFinal(XcbcMacContext *context, uint8_t *mac, size_t macLen)
Finish the XCBC-MAC calculation.
Definition: xcbc_mac.c:229
CipherContext cipherContext
Definition: xcbc_mac.h:56
General definitions for cryptographic algorithms.
void xcbcMacReset(XcbcMacContext *context)
Reset XCBC-MAC context.
Definition: xcbc_mac.c:164
uint32_t dataLen
Definition: sftp_common.h:229
void xcbcMacDeinit(XcbcMacContext *context)
Release XCBC-MAC context.
Definition: xcbc_mac.c:294
#define XCBC_MAC_PRIVATE_CONTEXT
Definition: xcbc_mac.h:40
uint8_t n
void xcbcMacXorBlock(uint8_t *x, const uint8_t *a, const uint8_t *b, size_t n)
XOR operation.
Definition: xcbc_mac.c:316
Common interface for encryption algorithms.
Definition: crypto.h:1068