API参考
载入中...
搜索中...
未找到
crypt_modes.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_H
17#define CRYPT_MODES_H
18
19#include "hitls_build.h"
20#ifdef HITLS_CRYPTO_MODES
21
22#include <stdint.h>
23#include "crypt_local_types.h"
24
25#ifdef __cplusplus
26extern "C" {
27#endif // __cplusplus
28
29#define MODES_MAX_IV_LENGTH 24
30#define MODES_MAX_BUF_LENGTH 24
31#define MODES_IV_LENGTH 16
32#define EAL_MAX_BLOCK_LENGTH 32
33typedef struct {
34 void *ciphCtx; /* Context defined by each algorithm */
35 const EAL_SymMethod *ciphMeth; /* Corresponding to the related methods for each symmetric algorithm */
36 uint8_t iv[MODES_MAX_IV_LENGTH]; /* IV information */
37 uint8_t buf[MODES_MAX_BUF_LENGTH]; /* Cache the information of the previous block. */
38 uint8_t blockSize; /* Save the block size. */
39 uint8_t offset;
40 uint8_t flag3Iv; /* Indicates whether three IVs are used. */
41 uint32_t ivIndex; /* Indicates the sequence number of the IV block to be used. TDES may have three IV. */
42} MODES_CipherCommonCtx;
43
44struct ModesCipherCtx {
45 MODES_CipherCommonCtx commonCtx;
46 int32_t algId;
47 uint8_t data[EAL_MAX_BLOCK_LENGTH];
48 uint8_t dataLen;
49 CRYPT_PaddingType pad;
50 bool enc;
51};
52typedef struct ModesCipherCtx MODES_CipherCtx;
53
54typedef struct {
55 const uint8_t *in;
56 uint8_t *out;
57 const uint8_t *ctr;
58 uint8_t *tag;
59} XorCryptData;
60void MODES_Clean(MODES_CipherCommonCtx *ctx);
61int32_t MODES_SetIv(MODES_CipherCommonCtx *ctx, const uint8_t *val, uint32_t len);
62int32_t MODES_GetIv(MODES_CipherCommonCtx *ctx, uint8_t *val, uint32_t len);
63
64MODES_CipherCtx *MODES_CipherNewCtx(int32_t algId);
65MODES_CipherCtx *MODES_CipherNewCtxEx(void *libCtx, int32_t algId);
66MODES_CipherCtx *MODES_CipherDupCtx(const MODES_CipherCtx *modeCtx);
67
68#ifdef __cplusplus
69}
70#endif // __cplusplus
71
72#endif // HITLS_CRYPTO_MODES
73
74#endif // CRYPT_MODES_H
定义 crypt_local_types.h:241