cmac.h
1 /* cmac.h
2  *
3  * Copyright (C) 2006-2020 wolfSSL Inc.
4  *
5  * This file is part of wolfSSL.
6  *
7  * wolfSSL is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * wolfSSL is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
20  */
21 
22 
23 #ifndef WOLF_CRYPT_CMAC_H
24 #define WOLF_CRYPT_CMAC_H
25 
27 #include <wolfssl/wolfcrypt/aes.h>
28 
29 #if !defined(NO_AES) && defined(WOLFSSL_CMAC)
30 
31 #if defined(HAVE_FIPS) && \
32  defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 2)
33  #include <wolfssl/wolfcrypt/fips.h>
34 #endif /* HAVE_FIPS_VERSION >= 2 */
35 
36 #ifdef __cplusplus
37  extern "C" {
38 #endif
39 
40 /* avoid redefinition of structs */
41 #if !defined(HAVE_FIPS) || \
42  (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 2))
43 
44 #ifndef WC_CMAC_TYPE_DEFINED
45  typedef struct Cmac Cmac;
46  #define WC_CMAC_TYPE_DEFINED
47 #endif
48 struct Cmac {
49  Aes aes;
50  byte buffer[AES_BLOCK_SIZE]; /* partially stored block */
51  byte digest[AES_BLOCK_SIZE]; /* running digest */
52  byte k1[AES_BLOCK_SIZE];
53  byte k2[AES_BLOCK_SIZE];
54  word32 bufferSz;
55  word32 totalSz;
56 };
57 
58 
59 
60 typedef enum CmacType {
61  WC_CMAC_AES = 1
62 } CmacType;
63 
64 #define WC_CMAC_TAG_MAX_SZ AES_BLOCK_SIZE
65 #define WC_CMAC_TAG_MIN_SZ (AES_BLOCK_SIZE/4)
66 
67 #endif /* HAVE_FIPS */
68 
69 WOLFSSL_API
70 int wc_InitCmac(Cmac* cmac,
71  const byte* key, word32 keySz,
72  int type, void* unused);
73 WOLFSSL_API
74 int wc_CmacUpdate(Cmac* cmac,
75  const byte* in, word32 inSz);
76 WOLFSSL_API
77 int wc_CmacFinal(Cmac* cmac,
78  byte* out, word32* outSz);
79 
80 WOLFSSL_API
81 int wc_AesCmacGenerate(byte* out, word32* outSz,
82  const byte* in, word32 inSz,
83  const byte* key, word32 keySz);
84 
85 WOLFSSL_API
86 int wc_AesCmacVerify(const byte* check, word32 checkSz,
87  const byte* in, word32 inSz,
88  const byte* key, word32 keySz);
89 
90 #ifdef __cplusplus
91  } /* extern "C" */
92 #endif
93 
94 
95 #endif /* NO_AES && WOLFSSL_CMAC */
96 #endif /* WOLF_CRYPT_CMAC_H */
97 
Definition: aes.h:149
Definition: cmac.h:48