API参考
载入中...
搜索中...
未找到
hs_kx.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 HS_KX_H
17#define HS_KX_H
18
19#include <stdint.h>
20#include "hs_ctx.h"
21#include "hs_msg.h"
22
23#ifdef __cplusplus
24extern "C" {
25#endif
26
27#define MASTER_SECRET_LABEL "CLIENT_RANDOM"
28#define CLIENT_EARLY_LABEL "CLIENT_EARLY_TRAFFIC_SECRET"
29#define CLIENT_HANDSHAKE_LABEL "CLIENT_HANDSHAKE_TRAFFIC_SECRET"
30#define SERVER_HANDSHAKE_LABEL "SERVER_HANDSHAKE_TRAFFIC_SECRET"
31#define CLIENT_APPLICATION_LABEL "CLIENT_TRAFFIC_SECRET_0"
32#define SERVER_APPLICATION_LABEL "SERVER_TRAFFIC_SECRET_0"
33#define EARLY_EXPORTER_SECRET_LABEL "EARLY_EXPORTER_SECRET"
34#define EXPORTER_SECRET_LABEL "EXPORTER_SECRET"
35
36/* The maximum premaster secret calculated by using the PSK may be:
37 * |uint16_t|HITLS_MAX_OTHER_SECRET_SIZE|uint16_t|HS_PSK_MAX_LEN| */
38#ifndef HITLS_MAX_OTHER_SECRET_SIZE
39#define HITLS_MAX_OTHER_SECRET_SIZE 1536
40#endif
41#define MAX_PRE_MASTER_SECRET_SIZE (sizeof(uint16_t) + HITLS_MAX_OTHER_SECRET_SIZE + sizeof(uint16_t) + \
42 HS_PSK_MAX_LEN)
43#define MAX_SHA1_SIZE 20
44#define MAX_MD5_SIZE 16
45
51KeyExchCtx *HS_KeyExchCtxNew(void);
52
58void HS_KeyExchCtxFree(KeyExchCtx *keyExchCtx);
59
72int32_t HS_ProcessServerKxMsgEcdhe(TLS_Ctx *ctx, const ServerKeyExchangeMsg *serverKxMsg);
73
85int32_t HS_ProcessClientKxMsgEcdhe(TLS_Ctx *ctx, const ClientKeyExchangeMsg *clientKxMsg);
86
97int32_t HS_ProcessServerKxMsgDhe(TLS_Ctx *ctx, const ServerKeyExchangeMsg *serverKxMsg);
98
108int32_t HS_ProcessClientKxMsgDhe(TLS_Ctx *ctx, const ClientKeyExchangeMsg *clientKxMsg);
109
110int32_t HS_ProcessClientKxMsgRsa(TLS_Ctx *ctx, const ClientKeyExchangeMsg *clientKxMsg);
111
112int32_t HS_ProcessClientKxMsgSm2(TLS_Ctx *ctx, const ClientKeyExchangeMsg *clientKxMsg);
113
123int32_t HS_GenerateMasterSecret(TLS_Ctx *ctx);
124
136int32_t HS_ProcessServerKxMsgIdentityHint(TLS_Ctx *ctx, const ServerKeyExchangeMsg *serverKxMsg);
137
152int32_t HS_TLS13DeriveSecret(CRYPT_KeyDeriveParameters *deriveInfo, bool isHashed, uint8_t *outSecret, uint32_t outLen);
153
154int32_t HS_TLS13DeriveBinderKey(HITLS_Lib_Ctx *libCtx, const char *attrName,
155 HITLS_HashAlgo hashAlgo, bool isExternalPsk, uint8_t *earlySecret, uint32_t secretLen,
156 uint8_t *binderKey, uint32_t keyLen);
157
171int32_t HS_TLS13DeriveEarlySecret(HITLS_Lib_Ctx *libCtx, const char *attrName,
172 HITLS_HashAlgo hashAlgo, uint8_t *psk, uint32_t pskLen, uint8_t *earlySecret, uint32_t *outLen);
173
191int32_t HS_TLS13DeriveNextStageSecret(HITLS_Lib_Ctx *libCtx, const char *attrName,
192 HITLS_HashAlgo hashAlgo, uint8_t *inSecret, uint32_t inLen, uint8_t *givenSecret,
193 uint32_t givenLen, uint8_t *outSecret, uint32_t *outLen);
194
209int32_t HS_TLS13DeriveFinishedKey(HITLS_Lib_Ctx *libCtx, const char *attrName,
210 HITLS_HashAlgo hashAlgo, uint8_t *baseKey, uint32_t baseKeyLen, uint8_t *finishedkey, uint32_t finishedkeyLen);
211
226int32_t HS_SwitchTrafficKey(TLS_Ctx *ctx, uint8_t *secret, uint32_t secretLen, bool isOut);
227
237int32_t HS_SetInitPendingStateParam(const TLS_Ctx *ctx, bool isClient, REC_SecParameters *keyPara);
238
252int32_t HS_TLS13CalcServerHelloProcessSecret(TLS_Ctx *ctx);
253
266int32_t HS_TLS13CalcServerFinishProcessSecret(TLS_Ctx *ctx);
267
281int32_t HS_TLS13UpdateTrafficSecret(TLS_Ctx *ctx, bool isOut);
282
296int32_t HS_TLS13DeriveResumptionMasterSecret(TLS_Ctx *ctx);
297
313int32_t HS_TLS13DeriveResumePsk(
314 TLS_Ctx *ctx, const uint8_t *ticketNonce, uint32_t ticketNonceSize, uint8_t *resumePsk, uint32_t resumePskLen);
315
316int32_t HS_TLS13DeriveHandshakeTrafficSecret(TLS_Ctx *ctx);
317
318#ifdef __cplusplus
319}
320#endif
321
322#endif
定义 crypt.h:32
定义 hs_msg.h:274
PskInfo is used for PSK negotiation and stores identity and psk during negotiation
定义 hs_ctx.h:112
定义 rec.h:55
定义 hs_msg.h:263