API参考
载入中...
搜索中...
未找到
crypt_modes_chacha20poly1305.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_CHACHA20POLY1305_H
17#define CRYPT_MODES_CHACHA20POLY1305_H
18
19#include "hitls_build.h"
20#if defined(HITLS_CRYPTO_CHACHA20) && defined(HITLS_CRYPTO_CHACHA20POLY1305)
21
22#include "crypt_types.h"
23#include "crypt_modes.h"
24
25#ifdef __cplusplus
26extern "C" {
27#endif // __cplusplus
28
29typedef struct {
30 uint32_t acc[6]; // The intermediate data of the acc, must be greater than 130 bits.
31 uint32_t r[4]; // Key information r, 16 bytes, that is, 4 * sizeof(uint32_t)
32 uint32_t s[4]; // Key information s, 16 bytes, that is, 4 * sizeof(uint32_t)
33 uint32_t table[36]; // Indicates the table used to accelerate the assembly calculation.
34 uint8_t last[16]; // A block 16 bytes are cached for the last unprocessed data.
35 uint32_t lastLen; // Indicates the remaining length of the last data.
36 uint32_t flag; // Used to save the assembly status information.
37} Poly1305Ctx;
38
39typedef struct {
40 void *key; // Handle for the method.
41 const EAL_SymMethod *method; // algorithm method
42 Poly1305Ctx polyCtx;
43 uint64_t aadLen; // Status, indicating whether identification data is set.
44 uint64_t cipherTextLen; // status, indicating whether the identification data is set.
45} MODES_CipherChaChaPolyCtx;
46
47struct ModesChaChaCtx {
48 int32_t algId;
49 MODES_CipherChaChaPolyCtx chachaCtx;
50 bool enc;
51};
52
53typedef struct ModesChaChaCtx MODES_CHACHAPOLY_Ctx;
54
55MODES_CHACHAPOLY_Ctx *MODES_CHACHA20POLY1305_NewCtx(int32_t algId);
56MODES_CHACHAPOLY_Ctx *MODES_CHACHA20POLY1305_NewCtxEx(void *libCtx, int32_t algId);
57int32_t MODES_CHACHA20POLY1305_InitCtx(MODES_CHACHAPOLY_Ctx *modeCtx, const uint8_t *key,
58 uint32_t keyLen, const uint8_t *iv, uint32_t ivLen, void *param, bool enc);
59
60int32_t MODES_CHACHA20POLY1305_Update(MODES_CHACHAPOLY_Ctx *modeCtx, const uint8_t *in, uint32_t inLen,
61 uint8_t *out, uint32_t *outLen);
62int32_t MODES_CHACHA20POLY1305_Final(MODES_CHACHAPOLY_Ctx *modeCtx, uint8_t *out, uint32_t *outLen);
63int32_t MODES_CHACHA20POLY1305_DeInitCtx(MODES_CHACHAPOLY_Ctx *modeCtx);
64int32_t MODES_CHACHA20POLY1305_Ctrl(MODES_CHACHAPOLY_Ctx *modeCtx, int32_t cmd, void *val, uint32_t len);
65void MODES_CHACHA20POLY1305_FreeCtx(MODES_CHACHAPOLY_Ctx *modeCtx);
66MODES_CHACHAPOLY_Ctx *MODES_CHACHA20POLY1305_DupCtx(const MODES_CHACHAPOLY_Ctx *modeCtx);
67
68#ifdef __cplusplus
69}
70#endif // __cplusplus
71
72#endif // HITLS_CRYPTO_CHACHA20POLY1305
73
74#endif // CRYPT_MODES_CHACHA20POLY1305_H
定义 crypt_local_types.h:241