API参考
载入中...
搜索中...
未找到
crypt_modes_cfb.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_CFB_H
17#define CRYPT_MODES_CFB_H
18
19#include "hitls_build.h"
20#ifdef HITLS_CRYPTO_CFB
21
22#include "crypt_types.h"
23#include "crypt_modes.h"
24#ifdef __cplusplus
25extern "C" {
26#endif // __cplusplus
27
28#define DES_BLOCK_BYTE_NUM 8
29typedef struct {
30 MODES_CipherCommonCtx modeCtx;
31 uint8_t feedbackBits; /* Save the FeedBack length. */
32 uint8_t cipherCache[3][DES_BLOCK_BYTE_NUM];
33 uint8_t cacheIndex; /* Used by the TDES that has 3IV. Indicate which cache is being used. */
34} MODES_CipherCFBCtx;
35struct ModesCFBCtx {
36 int32_t algId;
37 MODES_CipherCFBCtx cfbCtx;
38 bool enc;
39};
40typedef struct ModesCFBCtx MODES_CFB_Ctx;
41
42// CFB mode universal implementation
43MODES_CFB_Ctx *MODES_CFB_NewCtx(int32_t algId);
44MODES_CFB_Ctx *MODES_CFB_NewCtxEx(void *libCtx, int32_t algId);
45int32_t MODES_CFB_InitCtx(MODES_CFB_Ctx *modeCtx, const uint8_t *key, uint32_t keyLen, const uint8_t *iv,
46 uint32_t ivLen, bool enc);
47
48int32_t MODES_CFB_Update(MODES_CFB_Ctx *modeCtx, const uint8_t *in, uint32_t inLen, uint8_t *out, uint32_t *outLen);
49int32_t MODES_CFB_Final(MODES_CFB_Ctx *modeCtx, uint8_t *out, uint32_t *outLen);
50int32_t MODES_CFB_DeInitCtx(MODES_CFB_Ctx *modeCtx);
51int32_t MODES_CFB_Ctrl(MODES_CFB_Ctx *modeCtx, int32_t opt, void *val, uint32_t len);
52void MODES_CFB_FreeCtx(MODES_CFB_Ctx *modeCtx);
53
54// AES CFB optimization implementation
55int32_t AES_CFB_Update(MODES_CFB_Ctx *modeCtx, const uint8_t *in, uint32_t inLen, uint8_t *out, uint32_t *outLen);
56
57// SM4 CFB optimization implementation
58int32_t SM4_CFB_InitCtx(MODES_CFB_Ctx *modeCtx, const uint8_t *key, uint32_t keyLen, const uint8_t *iv,
59 uint32_t ivLen, bool enc);
60int32_t SM4_CFB_Update(MODES_CFB_Ctx *modeCtx, const uint8_t *in, uint32_t inLen, uint8_t *out, uint32_t *outLen);
61
62
63int32_t MODES_CFB_InitCtxEx(MODES_CFB_Ctx *modeCtx, const uint8_t *key, uint32_t keyLen, const uint8_t *iv,
64 uint32_t ivLen, void *param, bool enc);
65int32_t MODES_CFB_UpdateEx(MODES_CFB_Ctx *modeCtx, const uint8_t *in, uint32_t inLen, uint8_t *out, uint32_t *outLen);
66MODES_CFB_Ctx *MODES_CFB_DupCtx(const MODES_CFB_Ctx *modeCtx);
67
68#ifdef __cplusplus
69}
70#endif // __cplusplus
71
72#endif // HITLS_CRYPTO_CFB
73
74#endif // CRYPT_MODES_CFB_H