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  * Copyright (C) 2010-2018 Oryx Embedded SARL. All rights reserved.
8  *
9  * This file is part of CycloneCrypto Open.
10  *
11  * This program is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU General Public License
13  * as published by the Free Software Foundation; either version 2
14  * of the License, or (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software Foundation,
23  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24  *
25  * @author Oryx Embedded SARL (www.oryx-embedded.com)
26  * @version 1.9.0
27  **/
28 
29 #ifndef _GMAC_H
30 #define _GMAC_H
31 
32 //Dependencies
33 #include "core/crypto.h"
34 
35 //RC2 support?
36 #if (RC2_SUPPORT == ENABLED)
37  #include "cipher/rc2.h"
38 #endif
39 
40 //RC6 support?
41 #if (RC6_SUPPORT == ENABLED)
42  #include "cipher/rc6.h"
43 #endif
44 
45 //IDEA support?
46 #if (IDEA_SUPPORT == ENABLED)
47  #include "cipher/idea.h"
48 #endif
49 
50 //DES support?
51 #if (DES_SUPPORT == ENABLED)
52  #include "cipher/des.h"
53 #endif
54 
55 //Triple DES support?
56 #if (DES3_SUPPORT == ENABLED)
57  #include "cipher/des3.h"
58 #endif
59 
60 //AES support?
61 #if (AES_SUPPORT == ENABLED)
62  #include "cipher/aes.h"
63 #endif
64 
65 //Camellia support?
66 #if (CAMELLIA_SUPPORT == ENABLED)
67  #include "cipher/camellia.h"
68 #endif
69 
70 //SEED support?
71 #if (SEED_SUPPORT == ENABLED)
72  #include "cipher/seed.h"
73 #endif
74 
75 //ARIA support?
76 #if (ARIA_SUPPORT == ENABLED)
77  #include "cipher/aria.h"
78 #endif
79 
80 //PRESENT support?
81 #if (PRESENT_SUPPORT == ENABLED)
82  #include "cipher/present.h"
83 #endif
84 
85 //C++ guard
86 #ifdef __cplusplus
87  extern "C" {
88 #endif
89 
90 
91 /**
92  * @brief GMAC algorithm context
93  **/
94 
95 typedef struct
96 {
98  uint8_t cipherContext[MAX_CIPHER_CONTEXT_SIZE];
99  uint32_t m[16][4];
100  uint8_t s[16];
101  uint8_t buffer[16];
102  size_t bufferLength;
103  uint64_t totalLength;
104  uint8_t mac[16];
105 } GmacContext;
106 
107 
108 //GMAC related functions
109 error_t gmacCompute(const CipherAlgo *cipher, const void *key, size_t keyLen,
110  const uint8_t *iv, size_t ivLen, const void *data, size_t dataLen,
111  uint8_t *mac, size_t macLen);
112 
113 error_t gmacInit(GmacContext *context, const CipherAlgo *cipher,
114  const void *key, size_t keyLen);
115 
116 error_t gmacReset(GmacContext *context, const uint8_t *iv, size_t ivLen);
117 void gmacUpdate(GmacContext *context, const void *data, size_t dataLen);
118 error_t gmacFinal(GmacContext *context, uint8_t *mac, size_t macLen);
119 
120 void gmacMul(GmacContext *context, uint8_t *x);
121 void gmacXorBlock(uint8_t *x, const uint8_t *a, const uint8_t *b, size_t n);
122 void gmacIncCounter(uint8_t *x);
123 
124 //C++ guard
125 #ifdef __cplusplus
126  }
127 #endif
128 
129 #endif
error_t gmacReset(GmacContext *context, const uint8_t *iv, size_t ivLen)
Reset GMAC context.
Definition: gmac.c:256
void gmacIncCounter(uint8_t *x)
Increment counter block.
Definition: gmac.c:506
GMAC algorithm context.
Definition: gmac.h:95
General definitions for cryptographic algorithms.
RC2 block cipher.
Common interface for encryption algorithms.
Definition: crypto.h:1073
SEED encryption algorithm.
Camellia encryption algorithm.
void gmacMul(GmacContext *context, uint8_t *x)
Multiplication operation in GF(2^128)
Definition: gmac.c:420
uint8_t m
Definition: ndp.h:299
RC6-32/20 block cipher.
uint8_t a
Definition: ndp.h:407
Triple DES (Triple Data Encryption Algorithm)
PRESENT encryption algorithm.
#define MAX_CIPHER_CONTEXT_SIZE
Definition: crypto.h:802
error_t gmacFinal(GmacContext *context, uint8_t *mac, size_t macLen)
Finish the GMAC calculation.
Definition: gmac.c:376
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:80
AES (Advanced Encryption Standard)
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:333
ARIA encryption algorithm.
uint64_t totalLength
Definition: gmac.h:103
uint8_t s
DES (Data Encryption Standard)
error_t
Error codes.
Definition: error.h:40
void gmacXorBlock(uint8_t *x, const uint8_t *a, const uint8_t *b, size_t n)
XOR operation.
Definition: gmac.c:489
size_t bufferLength
Definition: gmac.h:102
uint8_t data[]
Definition: dtls_misc.h:167
error_t gmacInit(GmacContext *context, const CipherAlgo *cipher, const void *key, size_t keyLen)
Initialize GMAC calculation.
Definition: gmac.c:135
const CipherAlgo * cipher
Definition: gmac.h:97
uint8_t n
uint8_t b[6]
Definition: dtls_misc.h:130
IDEA encryption algorithm.