• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * This file is part of the openHiTLS project.
3  *
4  * openHiTLS is licensed under the Mulan PSL v2.
5  * You can use this software according to the terms and conditions of the Mulan PSL v2.
6  * You may obtain a copy of Mulan PSL v2 at:
7  *
8  *     http://license.coscl.org.cn/MulanPSL2
9  *
10  * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
11  * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
12  * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
13  * See the Mulan PSL v2 for more details.
14  */
15 
16 #ifndef CIPHER_MAC_COMMON_H
17 #define CIPHER_MAC_COMMON_H
18 
19 #include "hitls_build.h"
20 #if defined(HITLS_CRYPTO_CBC_MAC) || defined(HITLS_CRYPTO_CMAC)
21 #include <stdint.h>
22 #include "crypt_local_types.h"
23 #include "crypt_cmac.h"
24 
25 #ifdef __cplusplus
26 extern "C" {
27 #endif /* __cpluscplus */
28 
29 #define CIPHER_MAC_MAXBLOCKSIZE 16
30 
31 struct Cipher_MAC_Ctx {
32     const EAL_SymMethod *method;
33     void *key;
34     /* Stores the intermediate process data of CBC_MAC. The length is the block size. */
35     uint8_t data[CIPHER_MAC_MAXBLOCKSIZE];
36     uint8_t left[CIPHER_MAC_MAXBLOCKSIZE];
37     uint32_t len; /* Length of a non-integral data block */
38 };
39 
40 typedef struct Cipher_MAC_Ctx Cipher_MAC_Common_Ctx;
41 
42 #ifdef HITLS_CRYPTO_CBC_MAC
43 struct CBC_MAC_Ctx {
44     Cipher_MAC_Common_Ctx common;
45     CRYPT_PaddingType paddingType;
46 };
47 #endif
48 
49 int32_t CipherMacInitCtx(Cipher_MAC_Common_Ctx *ctx, const EAL_SymMethod *method);
50 
51 void CipherMacDeinitCtx(Cipher_MAC_Common_Ctx *ctx);
52 
53 int32_t CipherMacInit(Cipher_MAC_Common_Ctx *ctx, const uint8_t *key, uint32_t len);
54 
55 int32_t CipherMacUpdate(Cipher_MAC_Common_Ctx *ctx, const uint8_t *in, uint32_t len);
56 
57 void CipherMacReinit(Cipher_MAC_Common_Ctx *ctx);
58 
59 void CipherMacDeinit(Cipher_MAC_Common_Ctx *ctx);
60 
61 int32_t CipherMacGetMacLen(const Cipher_MAC_Common_Ctx *ctx, void *val, uint32_t len);
62 
63 #ifdef __cplusplus
64 }
65 #endif /* __cpluscplus */
66 
67 #endif // #if defined(HITLS_CRYPTO_CBC_MAC) || defined(HITLS_CRYPTO_CMAC)
68 
69 #endif // CIPHER_MAC_COMMON_H
70