• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 PACK_MSG_H
17 #define PACK_MSG_H
18 
19 #include <stdint.h>
20 #include "tls.h"
21 
22 #ifdef __cplusplus
23 extern "C" {
24 #endif
25 
26 /**
27  * @brief   Pack ClientHello message
28  *
29  * @param   ctx  [IN] TLS context
30  * @param   buf [OUT] Returned handshake message
31  * @param   bufLen [IN] Buffer size
32  * @param   usedLen  [OUT] Returned message length
33  *
34  * @retval  HITLS_SUCCESS
35  * @retval  For other error codes, see hitls_error.h
36  */
37 int32_t PackClientHello(const TLS_Ctx *ctx, uint8_t *buf, uint32_t bufLen, uint32_t *usedLen);
38 
39 /**
40  * @brief   Pack HelloVerifyRequest message
41  *
42  * @param   ctx  [IN] TLS context
43  * @param   buf [OUT] Returned handshake message
44  * @param   bufLen [IN] Buffer size
45  * @param   usedLen  [OUT] Returned message length
46  *
47  * @retval  HITLS_SUCCESS
48  * @retval  For other error codes, see hitls_error.h
49  */
50 int32_t PackHelloVerifyRequest(const TLS_Ctx *ctx, uint8_t *buf, uint32_t bufLen, uint32_t *usedLen);
51 
52 /**
53  * @brief   Pack ServertHello message
54  *
55  * @param   ctx  [IN] TLS context
56  * @param   buf [OUT] Returned handshake message
57  * @param   bufLen [IN] Buffer size
58  * @param   usedLen  [OUT] Returned message length
59  *
60  * @retval  HITLS_SUCCESS
61  * @retval  For other error codes, see hitls_error.h
62  */
63 int32_t PackServerHello(const TLS_Ctx *ctx, uint8_t *buf, uint32_t bufLen, uint32_t *usedLen);
64 
65 /**
66  * @brief   Pack Encrypted Extensions message
67  *
68  * @param   ctx  [IN] TLS context
69  * @param   buf [OUT] Returned handshake message
70  * @param   bufLen [IN] Buffer size
71  * @param   usedLen  [OUT] Returned message length
72  *
73  * @retval  HITLS_SUCCESS
74  * @retval  For other error codes, see hitls_error.h
75  */
76 int32_t PackEncryptedExtensions(const TLS_Ctx *ctx, uint8_t *buf, uint32_t bufLen, uint32_t *usedLen);
77 /**
78  * @brief   Pack Tls1.3 Certificate message
79  *
80  * @param   ctx  [IN] TLS context
81  * @param   buf [OUT] Returned handshake message
82  * @param   bufLen [IN] Buffer size
83  * @param   usedLen  [OUT] Returned message length
84  *
85  * @retval  HITLS_SUCCESS
86  * @retval  For other error codes, see hitls_error.h
87  */
88 int32_t Tls13PackCertificate(TLS_Ctx *ctx, uint8_t *buf, uint32_t bufLen, uint32_t *usedLen);
89 /**
90  * @brief   Pack certificate message
91  *
92  * @param   ctx  [IN] TLS context
93  * @param   buf [OUT] Returned handshake message
94  * @param   bufLen [IN] Buffer size
95  * @param   usedLen  [OUT] Returned message length
96  *
97  * @retval  HITLS_SUCCESS
98  * @retval  For other error codes, see hitls_error.h
99  */
100 int32_t PackCertificate(TLS_Ctx *ctx, uint8_t *buf, uint32_t bufLen, uint32_t *usedLen);
101 
102 /**
103  * @brief   Pack CertificateRequest message
104  *
105  * @param   ctx  [IN] TLS context
106  * @param   buf [OUT] Returned handshake message
107  * @param   bufLen [IN] Buffer size
108  * @param   usedLen  [OUT] Returned message length
109  *
110  * @retval  HITLS_SUCCESS
111  * @retval  For other error codes, see hitls_error.h
112  */
113 int32_t PackCertificateRequest(const TLS_Ctx *ctx, uint8_t *buf, uint32_t bufLen, uint32_t *usedLen);
114 
115 /**
116  * @brief   Pack Tls1.3 CertificateRequest message
117  *
118  * @param   ctx  [IN] TLS context
119  * @param   buf [OUT] Returned handshake message
120  * @param   bufLen [IN] Buffer size
121  * @param   usedLen  [OUT] Returned message length
122  *
123  * @retval  HITLS_SUCCESS
124  * @retval  For other error codes, see hitls_error.h
125  */
126 int32_t Tls13PackCertificateRequest(const TLS_Ctx *ctx, uint8_t *buf, uint32_t bufLen, uint32_t *usedLen);
127 /**
128  * @brief   Pack CertificateVerify message
129  *
130  * @param   ctx  [IN] TLS context
131  * @param   buf [OUT] Returned handshake message
132  * @param   bufLen [IN] Buffer size
133  * @param   usedLen  [OUT] Returned message length
134  *
135  * @retval  HITLS_SUCCESS
136  * @retval  For other error codes, see hitls_error.h
137  */
138 int32_t PackCertificateVerify(const TLS_Ctx *ctx, uint8_t *buf, uint32_t bufLen, uint32_t *usedLen);
139 
140 /**
141  * @brief   Pack new session ticket message
142  *
143  * @param   ctx  [IN] TLS context
144  * @param   buf [OUT] Returned handshake message
145  * @param   bufLen [IN] Buffer size
146  * @param   usedLen  [OUT] Returned message length
147  *
148  * @retval  HITLS_SUCCESS
149  * @retval  For other error codes, see hitls_error.h
150  */
151 int32_t PackNewSessionTicket(const TLS_Ctx *ctx, uint8_t *buf, uint32_t bufLen, uint32_t *usedLen);
152 
153 /**
154  * @brief   Pack TLS1.3 new session ticket message
155  *
156  * @param   ctx  [IN] TLS context
157  * @param   buf [OUT] Returned handshake message
158  * @param   bufLen [IN] Buffer size
159  * @param   usedLen  [OUT] Returned message length
160  *
161  * @retval  HITLS_SUCCESS
162  * @retval  For other error codes, see hitls_error.h
163  */
164 int32_t Tls13PackNewSessionTicket(const TLS_Ctx *ctx, uint8_t *buf, uint32_t bufLen, uint32_t *usedLen);
165 /**
166  * @brief   Pack ServerKeyExchange message
167  *
168  * @param   ctx  [IN] TLS context
169  * @param   buf [OUT] Returned handshake message
170  * @param   bufLen [IN] Buffer size
171  * @param   usedLen  [OUT] Returned message length
172  *
173  * @retval  HITLS_SUCCESS
174  * @retval  For other error codes, see hitls_error.h
175  */
176 int32_t PackServerKeyExchange(TLS_Ctx *ctx, uint8_t *buf, uint32_t bufLen, uint32_t *usedLen);
177 
178 /**
179  * @brief   Pack ClientKeyExchange message
180  *
181  * @param   ctx  [IN] TLS context
182  * @param   buf [OUT] Returned handshake message
183  * @param   bufLen [IN] Buffer size
184  * @param   usedLen  [OUT] Returned message length
185  *
186  * @retval  HITLS_SUCCESS
187  * @retval  For other error codes, see hitls_error.h
188  */
189 int32_t PackClientKeyExchange(TLS_Ctx *ctx, uint8_t *buf, uint32_t bufLen, uint32_t *usedLen);
190 
191 /**
192  * @brief   Pack Finished message
193  *
194  * @param   ctx  [IN] TLS context
195  * @param   buf [OUT] Returned handshake message
196  * @param   bufLen [IN] Buffer size
197  * @param   usedLen  [OUT] Returned message length
198  *
199  * @retval  HITLS_SUCCESS
200  * @retval  For other error codes, see hitls_error.h
201  */
202 int32_t PackFinished(const TLS_Ctx *ctx, uint8_t *buf, uint32_t bufLen, uint32_t *usedLen);
203 /**
204  * @brief   Pack KeyUpdate message
205  *
206  * @param   ctx  [IN] TLS context
207  * @param   buf [OUT] Returned handshake message
208  * @param   bufLen [IN] Buffer size
209  * @param   usedLen  [OUT] Returned message length
210  *
211  * @retval  HITLS_SUCCESS
212  * @retval  For other error codes, see hitls_error.h
213  */
214 int32_t PackKeyUpdate(const TLS_Ctx *ctx, uint8_t *buf, uint32_t bufLen, uint32_t *usedLen);
215 #ifdef __cplusplus
216 }
217 #endif /* end __cplusplus */
218 
219 #endif /* end PACK_MSG_H */