API参考
载入中...
搜索中...
未找到
hs_common.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_COMMON_H
17#define HS_COMMON_H
18
19#include <stdint.h>
20#include "tls.h"
21#include "hs_ctx.h"
22#include "hs_msg.h"
23
24#ifdef __cplusplus
25extern "C" {
26#endif
27
28#define MAX_CERT_TYPE_LISTS_SIZE 256 /* Maximum length of the certificate type list */
29#define HS_DOWNGRADE_RANDOM_SIZE 8u /* downgrade protection random number field */
30
31#define HITLS_CLIENT_HELLO_MAX_SIZE 131396
32#define HITLS_SERVER_HELLO_MAX_SIZE 65607
33#define HITLS_HELLO_VERIFY_REQUEST_MAX_SIZE 258
34#define HITLS_END_OF_EARLY_DATA_MAX_SIZE 0
35#define HITLS_HELLO_RETRY_REQUEST_MAX_SIZE 20000
36#define HITLS_ENCRYPTED_EXTENSIONS_MAX_SIZE 20000
37#define HITLS_SESSION_TICKET_MAX_SIZE_TLS13 131338
38#define HITLS_SESSION_TICKET_MAX_SIZE_TLS12 65541
39#define HITLS_SERVER_KEY_EXCH_MAX_SIZE 102400
40#define HITLS_SERVER_HELLO_DONE_MAX_SIZE 0
41#define HITLS_KEY_UPDATE_MAX_SIZE 1
42#define HITLS_CLIENT_KEY_EXCH_MAX_SIZE 2048
43#define HITLS_NEXT_PROTO_MAX_SIZE 514
44#define HITLS_FINISHED_MAX_SIZE 64
45#define HITLS_HELLO_REQUEST_MAX_SIZE 0
46
47enum HITLS_CryptInfoCmd {
48 HITLS_CRYPT_INFO_CMD_GET_PUBLIC_KEY_LEN = 0, /* Get the length of the public key, param is HITLS_NamedGroup */
49 HITLS_CRYPT_INFO_CMD_GET_SHARED_KEY_LEN, /* Get the length of the shared key, param is HITLS_NamedGroup */
50 HITLS_CRYPT_INFO_CMD_GET_CIPHERTEXT_LEN, /* Get the length of the ciphertext, param is HITLS_NamedGroup */
51 HITLS_CRYPT_INFO_CMD_GET_HASH_LEN, /* Get the length of the hash, param is HITLS_HashAlgo */
52};
53
61const uint8_t *HS_GetHrrRandom(uint32_t *len);
62
63const uint8_t *HS_GetTls12DowngradeRandom(uint32_t *len);
64
72const char *HS_GetMsgTypeStr(HS_MsgType type);
73
81int32_t HS_ChangeState(TLS_Ctx *ctx, uint32_t nextState);
82
96int32_t HS_CombineRandom(const uint8_t *random1, const uint8_t *random2, uint32_t randomSize,
97 uint8_t *dest, uint32_t destSize);
98
109uint8_t *HS_PrepareSignData(const TLS_Ctx *ctx, const uint8_t *partSignData,
110 uint32_t partSignDataLen, uint32_t *signDataLen);
111
121uint8_t *HS_PrepareSignDataTlcp(
122 const TLS_Ctx *ctx, const uint8_t *partSignData, uint32_t partSignDataLen, uint32_t *signDataLen);
123
124#if defined(HITLS_TLS_PROTO_DTLS12) && defined(HITLS_BSL_UIO_SCTP)
136int32_t HS_SetSctpAuthKey(TLS_Ctx *ctx);
137
146int32_t HS_ActiveSctpAuthKey(TLS_Ctx *ctx);
147
157int32_t HS_DeletePreviousSctpAuthKey(TLS_Ctx *ctx);
158#endif /* #if defined(HITLS_TLS_PROTO_DTLS12) && defined(HITLS_BSL_UIO_SCTP) */
159
160bool IsNeedServerKeyExchange(const TLS_Ctx *ctx);
161
162bool IsPskNegotiation(const TLS_Ctx *ctx);
163
164bool IsNeedCertPrepare(const CipherSuiteInfo *cipherSuiteInfo);
165
166bool IsTicketSupport(const TLS_Ctx *ctx);
167
168int32_t CheckClientPsk(TLS_Ctx *ctx);
169
179int32_t HS_ReSizeMsgBuf(TLS_Ctx *ctx, uint32_t msgSize);
180
192int32_t HS_GrowMsgBuf(TLS_Ctx *ctx, uint32_t msgSize, bool keepOldData);
193
202uint32_t HS_MaxMessageSize(TLS_Ctx *ctx, HS_MsgType type);
203
212uint32_t HS_GetBinderLen(HITLS_Session *session, HITLS_HashAlgo* hashAlg);
213
222bool GroupConformToVersion(const TLS_Ctx *ctx, uint16_t version, uint16_t group);
223
233bool IsCipherSuiteAllowed(const HITLS_Ctx *ctx, uint16_t cipherSuite, bool checkNegoVersion);
234
235uint16_t *CheckSupportSignAlgorithms(const TLS_Ctx *ctx, const uint16_t *signAlgorithms,
236 uint32_t signAlgorithmsSize, uint32_t *newSignAlgorithmsSize);
237
238uint32_t HS_GetExtensionTypeId(uint32_t hsExtensionsType);
239
240int32_t HS_CheckReceivedExtension(HITLS_Ctx *ctx, HS_MsgType hsType, uint64_t hsMsgExtensionsMask,
241 uint64_t hsMsgAllowedExtensionsMask);
242
243
253uint32_t HS_GetCryptLength(const TLS_Ctx *ctx, int32_t cmd, int32_t param);
254
262HITLS_CERT_KeyType HS_SignScheme2CertKeyType(const HITLS_Ctx *ctx, HITLS_SignHashAlgo signScheme);
263
264#ifdef __cplusplus
265}
266#endif
267
268#endif
HITLS_SignHashAlgo
Certificate Signature Algorithm Enumeration
定义 hitls_cert_type.h:177
HITLS_CERT_KeyType
Certificate Public Key Type
定义 hitls_cert_type.h:162
struct TlsCtx HITLS_Ctx
HITLS context
定义 hitls_type.h:35