openHiTLS API openHiTLS 0.1.0-Alpha1
hitls_security.h
浏览该文件的文档.
1/*---------------------------------------------------------------------------------------------
2 * This file is part of the openHiTLS project.
3 * Copyright © 2023 Huawei Technologies Co.,Ltd. All rights reserved.
4 * Licensed under the openHiTLS Software license agreement 1.0. See LICENSE in the project root
5 * for license information.
6 *---------------------------------------------------------------------------------------------
7 */
8
15#ifndef HITLS_SECURITY_H
16#define HITLS_SECURITY_H
17
18#include <stdint.h>
19#include "hitls_type.h"
20
21#ifdef __cplusplus
22extern "C" {
23#endif
24
31#ifndef HITLS_DEFAULT_SECURITY_LEVEL
32#define HITLS_DEFAULT_SECURITY_LEVEL 0
33#endif
34
35/* security level */
36#define HITLS_SECURITY_LEVEL_ZERO 0
37#define HITLS_SECURITY_LEVEL_ONE 1
38#define HITLS_SECURITY_LEVEL_TWO 2
39#define HITLS_SECURITY_LEVEL_THREE 3
40#define HITLS_SECURITY_LEVEL_FOUR 4
41#define HITLS_SECURITY_LEVEL_FIVE 5
42#define HITLS_SECURITY_LEVEL_MIN HITLS_SECURITY_LEVEL_ZERO
43#define HITLS_SECURITY_LEVEL_MAX HITLS_SECURITY_LEVEL_FIVE
44
45/* security strength */
46#define HITLS_SECURITY_LEVEL_ONE_SECBITS 80
47#define HITLS_SECURITY_LEVEL_TWO_SECBITS 112
48#define HITLS_SECURITY_LEVEL_THREE_SECBITS 128
49#define HITLS_SECURITY_LEVEL_FOUR_SECBITS 192
50#define HITLS_SECURITY_LEVEL_FIVE_SECBITS 256
51
52/* What the "other" parameter contains in security callback */
53/* Mask for type */
54# define HITLS_SECURITY_SECOP_OTHER_TYPE 0xffff0000
55# define HITLS_SECURITY_SECOP_OTHER_NONE 0
56# define HITLS_SECURITY_SECOP_OTHER_CIPHER (1 << 16)
57# define HITLS_SECURITY_SECOP_OTHER_CURVE (2 << 16)
58# define HITLS_SECURITY_SECOP_OTHER_DH (3 << 16)
59# define HITLS_SECURITY_SECOP_OTHER_PKEY (4 << 16)
60# define HITLS_SECURITY_SECOP_OTHER_SIGALG (5 << 16)
61# define HITLS_SECURITY_SECOP_OTHER_CERT (6 << 16)
62
63/* Indicated operation refers to peer key or certificate */
64# define HITLS_SECURITY_SECOP_PEER 0x1000
65
66/* Called to filter ciphers */
67/* Ciphers client supports */
68# define HITLS_SECURITY_SECOP_CIPHER_SUPPORTED (1 | HITLS_SECURITY_SECOP_OTHER_CIPHER)
69/* Cipher shared by client/server */
70# define HITLS_SECURITY_SECOP_CIPHER_SHARED (2 | HITLS_SECURITY_SECOP_OTHER_CIPHER)
71/* Sanity check of cipher server selects */
72# define HITLS_SECURITY_SECOP_CIPHER_CHECK (3 | HITLS_SECURITY_SECOP_OTHER_CIPHER)
73/* Curves supported by client */
74# define HITLS_SECURITY_SECOP_CURVE_SUPPORTED (4 | HITLS_SECURITY_SECOP_OTHER_CURVE)
75/* Curves shared by client/server */
76# define HITLS_SECURITY_SECOP_CURVE_SHARED (5 | HITLS_SECURITY_SECOP_OTHER_CURVE)
77/* Sanity check of curve server selects */
78# define HITLS_SECURITY_SECOP_CURVE_CHECK (6 | HITLS_SECURITY_SECOP_OTHER_CURVE)
79/* Temporary DH key */
80# define HITLS_SECURITY_SECOP_TMP_DH (7 | HITLS_SECURITY_SECOP_OTHER_PKEY)
81/* SSL/TLS version */
82# define HITLS_SECURITY_SECOP_VERSION (9 | HITLS_SECURITY_SECOP_OTHER_NONE)
83/* Session tickets */
84# define HITLS_SECURITY_SECOP_TICKET (10 | HITLS_SECURITY_SECOP_OTHER_NONE)
85/* Supported signature algorithms sent to peer */
86# define HITLS_SECURITY_SECOP_SIGALG_SUPPORTED (11 | HITLS_SECURITY_SECOP_OTHER_SIGALG)
87/* Shared signature algorithm */
88# define HITLS_SECURITY_SECOP_SIGALG_SHARED (12 | HITLS_SECURITY_SECOP_OTHER_SIGALG)
89/* Sanity check signature algorithm allowed */
90# define HITLS_SECURITY_SECOP_SIGALG_CHECK (13 | HITLS_SECURITY_SECOP_OTHER_SIGALG)
91/* Used to get mask of supported public key signature algorithms */
92# define HITLS_SECURITY_SECOP_SIGALG_MASK (14 | HITLS_SECURITY_SECOP_OTHER_SIGALG)
93/* Use to see if compression is allowed */
94# define HITLS_SECURITY_SECOP_COMPRESSION (15 | HITLS_SECURITY_SECOP_OTHER_NONE)
95/* EE key in certificate */
96# define HITLS_SECURITY_SECOP_EE_KEY (16 | HITLS_SECURITY_SECOP_OTHER_CERT)
97/* CA key in certificate */
98# define HITLS_SECURITY_SECOP_CA_KEY (17 | HITLS_SECURITY_SECOP_OTHER_CERT)
99/* CA digest algorithm in certificate */
100# define HITLS_SECURITY_SECOP_CA_MD (18 | HITLS_SECURITY_SECOP_OTHER_CERT)
101/* Peer EE key in certificate */
102# define HITLS_SECURITY_SECOP_PEER_EE_KEY (HITLS_SECURITY_SECOP_EE_KEY | HITLS_SECURITY_SECOP_PEER)
103/* Peer CA key in certificate */
104# define HITLS_SECURITY_SECOP_PEER_CA_KEY (HITLS_SECURITY_SECOP_CA_KEY | HITLS_SECURITY_SECOP_PEER)
105/* Peer CA digest algorithm in certificate */
106# define HITLS_SECURITY_SECOP_PEER_CA_MD (HITLS_SECURITY_SECOP_CA_MD | HITLS_SECURITY_SECOP_PEER)
107
124typedef int32_t (*HITLS_SecurityCb)(const HITLS_Ctx *ctx, const HITLS_Config *config, int32_t option,
125 int32_t bits, int32_t id, void *other, void *exData);
126
136int32_t HITLS_CFG_SetSecurityLevel(HITLS_Config *config, int32_t securityLevel);
137
147int32_t HITLS_CFG_GetSecurityLevel(const HITLS_Config *config, int32_t *securityLevel);
148
159
168
178int32_t HITLS_CFG_SetSecurityExData(HITLS_Config *config, void *securityExData);
179
188
198int32_t HITLS_SetSecurityLevel(HITLS_Ctx *ctx, int32_t securityLevel);
199
209int32_t HITLS_GetSecurityLevel(const HITLS_Ctx *ctx, int32_t *securityLevel);
210
221
230
240int32_t HITLS_SetSecurityExData(HITLS_Ctx *ctx, void *securityExData);
241
250
251#ifdef __cplusplus
252}
253#endif /* end __cplusplus */
254
255#endif /* end HITLS_SECURITY_H */
int32_t HITLS_CFG_SetSecurityExData(HITLS_Config *config, void *securityExData)
Configuring the Security ExData
int32_t HITLS_SetSecurityCb(HITLS_Ctx *ctx, HITLS_SecurityCb securityCb)
Callback function for setting link security
HITLS_SecurityCb HITLS_CFG_GetSecurityCb(const HITLS_Config *config)
Obtain the configured security callback function
void * HITLS_GetSecurityExData(const HITLS_Ctx *ctx)
Obtains the configured Security ExData.
int32_t HITLS_SetSecurityExData(HITLS_Ctx *ctx, void *securityExData)
Setting Security ExData for the Link
int32_t HITLS_CFG_SetSecurityCb(HITLS_Config *config, HITLS_SecurityCb securityCb)
Configure the security callback function.
HITLS_SecurityCb HITLS_GetSecurityCb(const HITLS_Ctx *ctx)
Obtain the Security callback function of the link
int32_t HITLS_SetSecurityLevel(HITLS_Ctx *ctx, int32_t securityLevel)
Set the link security level
int32_t HITLS_CFG_SetSecurityLevel(HITLS_Config *config, int32_t securityLevel)
Configure the security level
void * HITLS_CFG_GetSecurityExData(const HITLS_Config *config)
Obtain the configured Security ExData
int32_t HITLS_GetSecurityLevel(const HITLS_Ctx *ctx, int32_t *securityLevel)
Obtain the link security level
int32_t(* HITLS_SecurityCb)(const HITLS_Ctx *ctx, const HITLS_Config *config, int32_t option, int32_t bits, int32_t id, void *other, void *exData)
Secure Callback Function Prototype
Definition hitls_security.h:124
int32_t HITLS_CFG_GetSecurityLevel(const HITLS_Config *config, int32_t *securityLevel)
Obtain the configured security level.
struct TlsCtx HITLS_Ctx
HITLS context
Definition hitls_type.h:28
struct TlsConfig HITLS_Config
config context
Definition hitls_type.h:34