API参考
载入中...
搜索中...
未找到
crypt_modes_ccm.h
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 CRYPT_MODES_CCM_H
17#define CRYPT_MODES_CCM_H
18
19#include "hitls_build.h"
20#ifdef HITLS_CRYPTO_CCM
21
22#include "crypt_types.h"
23#include "crypt_modes.h"
24
25#ifdef __cplusplus
26extern "C" {
27#endif // __cplusplus
28
29#define CCM_BLOCKSIZE 16
30
31typedef struct {
32 void *ciphCtx; /* Context defined by each algorithm */
33 const EAL_SymMethod *ciphMeth; /* Corresponding to the related methods for each symmetric algorithm */
34
35 uint8_t nonce[CCM_BLOCKSIZE]; /* Data nonce, ctr encrypted data */
36 uint8_t tag[CCM_BLOCKSIZE]; /* Data tag, intermediate data encrypted by the CBC */
37 uint8_t last[CCM_BLOCKSIZE]; /* Previous data block in ctr mode */
38 uint64_t msgLen; /* The message length */
39 uint8_t lastLen; /* Unused data length of the previous data block in ctr mode. */
40 uint8_t tagLen; /* The length of the tag is 16 by default. The tag is reset each time the key is set. */
41 uint8_t tagInit; /* Indicate whether the tag is initialized. */
42} MODES_CipherCCMCtx;
43
44struct ModesCcmCtx {
45 int32_t algId;
46 MODES_CipherCCMCtx ccmCtx;
47 bool enc;
48};
49
50typedef struct ModesCcmCtx MODES_CCM_Ctx;
51// CCM mode universal implementation
52MODES_CCM_Ctx *MODES_CCM_NewCtx(int32_t algId);
53MODES_CCM_Ctx *MODES_CCM_NewCtxEx(void *libCtx, int32_t algId);
54
55int32_t MODES_CCM_InitCtx(MODES_CCM_Ctx *modeCtx, const uint8_t *key, uint32_t keyLen, const uint8_t *iv,
56 uint32_t ivLen, void *param, bool enc);
57
58int32_t MODES_CCM_Update(MODES_CCM_Ctx *modeCtx, const uint8_t *in, uint32_t inLen, uint8_t *out, uint32_t *outLen);
59int32_t MODES_CCM_Final(MODES_CCM_Ctx *modeCtx, uint8_t *out, uint32_t *outLen);
60int32_t MODES_CCM_DeInitCtx(MODES_CCM_Ctx *modeCtx);
61int32_t MODES_CCM_Ctrl(MODES_CCM_Ctx *modeCtx, int32_t opt, void *val, uint32_t len);
62void MODES_CCM_FreeCtx(MODES_CCM_Ctx *modeCtx);
63
64// AES CCM optimization implementation
65int32_t AES_CCM_Update(MODES_CCM_Ctx *modeCtx, const uint8_t *in, uint32_t inLen, uint8_t *out, uint32_t *outLen);
66
67int32_t MODES_CCM_UpdateEx(MODES_CCM_Ctx *modeCtx, const uint8_t *in, uint32_t inLen, uint8_t *out, uint32_t *outLen);
68MODES_CCM_Ctx *MODES_CCM_DupCtx(const MODES_CCM_Ctx *modeCtx);
69
70#ifdef __cplusplus
71}
72#endif // __cplusplus
73
74#endif // HITLS_CRYPTO_CCM
75
76#endif // CRYPT_MODES_CCM_H
定义 crypt_local_types.h:241