gmac.h
Go to the documentation of this file.
1 /**
2  * @file gmac.h
3  * @brief GMAC (Galois Message Authentication Code)
4  *
5  * @section License
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  *
9  * Copyright (C) 2010-2020 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 1.9.8
29  **/
30 
31 #ifndef _GMAC_H
32 #define _GMAC_H
33 
34 //Dependencies
35 #include "core/crypto.h"
36 
37 //RC2 support?
38 #if (RC2_SUPPORT == ENABLED)
39  #include "cipher/rc2.h"
40 #endif
41 
42 //RC6 support?
43 #if (RC6_SUPPORT == ENABLED)
44  #include "cipher/rc6.h"
45 #endif
46 
47 //IDEA support?
48 #if (IDEA_SUPPORT == ENABLED)
49  #include "cipher/idea.h"
50 #endif
51 
52 //DES support?
53 #if (DES_SUPPORT == ENABLED)
54  #include "cipher/des.h"
55 #endif
56 
57 //Triple DES support?
58 #if (DES3_SUPPORT == ENABLED)
59  #include "cipher/des3.h"
60 #endif
61 
62 //AES support?
63 #if (AES_SUPPORT == ENABLED)
64  #include "cipher/aes.h"
65 #endif
66 
67 //Blowfish support?
68 #if (BLOWFISH_SUPPORT == ENABLED)
69  #include "cipher/blowfish.h"
70 #endif
71 
72 //Camellia support?
73 #if (CAMELLIA_SUPPORT == ENABLED)
74  #include "cipher/camellia.h"
75 #endif
76 
77 //SEED support?
78 #if (SEED_SUPPORT == ENABLED)
79  #include "cipher/seed.h"
80 #endif
81 
82 //ARIA support?
83 #if (ARIA_SUPPORT == ENABLED)
84  #include "cipher/aria.h"
85 #endif
86 
87 //PRESENT support?
88 #if (PRESENT_SUPPORT == ENABLED)
89  #include "cipher/present.h"
90 #endif
91 
92 //C++ guard
93 #ifdef __cplusplus
94 extern "C" {
95 #endif
96 
97 
98 /**
99  * @brief GMAC algorithm context
100  **/
101 
102 typedef struct
103 {
105  uint8_t cipherContext[MAX_CIPHER_CONTEXT_SIZE];
106  uint32_t m[16][4];
107  uint8_t s[16];
108  uint8_t buffer[16];
109  size_t bufferLength;
110  uint64_t totalLength;
111  uint8_t mac[16];
112 } GmacContext;
113 
114 
115 //GMAC related functions
116 error_t gmacCompute(const CipherAlgo *cipher, const void *key, size_t keyLen,
117  const uint8_t *iv, size_t ivLen, const void *data, size_t dataLen,
118  uint8_t *mac, size_t macLen);
119 
120 error_t gmacInit(GmacContext *context, const CipherAlgo *cipher,
121  const void *key, size_t keyLen);
122 
123 error_t gmacReset(GmacContext *context, const uint8_t *iv, size_t ivLen);
124 void gmacUpdate(GmacContext *context, const void *data, size_t dataLen);
125 error_t gmacFinal(GmacContext *context, uint8_t *mac, size_t macLen);
126 
127 void gmacMul(GmacContext *context, uint8_t *x);
128 void gmacXorBlock(uint8_t *x, const uint8_t *a, const uint8_t *b, size_t n);
129 void gmacIncCounter(uint8_t *x);
130 
131 //C++ guard
132 #ifdef __cplusplus
133 }
134 #endif
135 
136 #endif
error_t gmacInit(GmacContext *context, const CipherAlgo *cipher, const void *key, size_t keyLen)
Initialize GMAC calculation.
Definition: gmac.c:137
PRESENT encryption algorithm.
uint8_t a
Definition: ndp.h:410
uint8_t data[]
Definition: ethernet.h:209
RC6-32/20 block cipher.
void gmacXorBlock(uint8_t *x, const uint8_t *a, const uint8_t *b, size_t n)
XOR operation.
Definition: gmac.c:491
error_t gmacCompute(const CipherAlgo *cipher, const void *key, size_t keyLen, const uint8_t *iv, size_t ivLen, const void *data, size_t dataLen, uint8_t *mac, size_t macLen)
Compute GMAC using the specified cipher algorithm.
Definition: gmac.c:82
error_t gmacFinal(GmacContext *context, uint8_t *mac, size_t macLen)
Finish the GMAC calculation.
Definition: gmac.c:378
void gmacMul(GmacContext *context, uint8_t *x)
Multiplication operation in GF(2^128)
Definition: gmac.c:422
const CipherAlgo * cipher
Definition: gmac.h:104
ARIA encryption algorithm.
error_t gmacReset(GmacContext *context, const uint8_t *iv, size_t ivLen)
Reset GMAC context.
Definition: gmac.c:258
void gmacUpdate(GmacContext *context, const void *data, size_t dataLen)
Update the GMAC context with a portion of the message being hashed.
Definition: gmac.c:335
error_t
Error codes.
Definition: error.h:42
AES (Advanced Encryption Standard)
General definitions for cryptographic algorithms.
IDEA encryption algorithm.
Blowfish encryption algorithm.
SEED encryption algorithm.
DES (Data Encryption Standard)
uint8_t b[6]
Definition: ethernet.h:179
uint8_t m
Definition: ndp.h:302
uint8_t n
uint8_t s
Common interface for encryption algorithms.
Definition: crypto.h:1084
GMAC algorithm context.
Definition: gmac.h:102
#define MAX_CIPHER_CONTEXT_SIZE
Definition: crypto.h:800
uint64_t totalLength
Definition: gmac.h:110
void gmacIncCounter(uint8_t *x)
Increment counter block.
Definition: gmac.c:508
size_t bufferLength
Definition: gmac.h:109
Triple DES (Triple Data Encryption Algorithm)
RC2 block cipher.
Camellia encryption algorithm.