Mbed OS Reference
Loading...
Searching...
No Matches
debug.h
Go to the documentation of this file.
1/**
2 * \file debug.h
3 *
4 * \brief Functions for controlling and providing debug output from the library.
5 */
6/*
7 * Copyright The Mbed TLS Contributors
8 * SPDX-License-Identifier: Apache-2.0
9 *
10 * Licensed under the Apache License, Version 2.0 (the "License"); you may
11 * not use this file except in compliance with the License.
12 * You may obtain a copy of the License at
13 *
14 * http://www.apache.org/licenses/LICENSE-2.0
15 *
16 * Unless required by applicable law or agreed to in writing, software
17 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
18 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 * See the License for the specific language governing permissions and
20 * limitations under the License.
21 */
22#ifndef MBEDTLS_DEBUG_H
23#define MBEDTLS_DEBUG_H
24
25#if !defined(MBEDTLS_CONFIG_FILE)
26#include "mbedtls/config.h"
27#else
28#include MBEDTLS_CONFIG_FILE
29#endif
30
31#include "mbedtls/ssl.h"
32
33#if defined(MBEDTLS_ECP_C)
34#include "mbedtls/ecp.h"
35#endif
36
37/**
38 * \addtogroup mbedtls
39 * \{
40 * \defgroup mbedtls_debug_module Debug
41 * \{
42 */
43
44
45#if defined(MBEDTLS_DEBUG_C)
46
47#define MBEDTLS_DEBUG_STRIP_PARENS( ... ) __VA_ARGS__
48
49#define MBEDTLS_SSL_DEBUG_MSG( level, args ) \
50 mbedtls_debug_print_msg( ssl, level, __FILE__, __LINE__, \
51 MBEDTLS_DEBUG_STRIP_PARENS args )
52
53#define MBEDTLS_SSL_DEBUG_RET( level, text, ret ) \
54 mbedtls_debug_print_ret( ssl, level, __FILE__, __LINE__, text, ret )
55
56#define MBEDTLS_SSL_DEBUG_BUF( level, text, buf, len ) \
57 mbedtls_debug_print_buf( ssl, level, __FILE__, __LINE__, text, buf, len )
58
59#if defined(MBEDTLS_BIGNUM_C)
60#define MBEDTLS_SSL_DEBUG_MPI( level, text, X ) \
61 mbedtls_debug_print_mpi( ssl, level, __FILE__, __LINE__, text, X )
62#endif
63
64#if defined(MBEDTLS_ECP_C)
65#define MBEDTLS_SSL_DEBUG_ECP( level, text, X ) \
66 mbedtls_debug_print_ecp( ssl, level, __FILE__, __LINE__, text, X )
67#endif
68
69#if defined(MBEDTLS_X509_CRT_PARSE_C)
70#define MBEDTLS_SSL_DEBUG_CRT( level, text, crt ) \
71 mbedtls_debug_print_crt( ssl, level, __FILE__, __LINE__, text, crt )
72#endif
73
74#if defined(MBEDTLS_ECDH_C)
75#define MBEDTLS_SSL_DEBUG_ECDH( level, ecdh, attr ) \
76 mbedtls_debug_printf_ecdh( ssl, level, __FILE__, __LINE__, ecdh, attr )
77#endif
78
79#else /* MBEDTLS_DEBUG_C */
80
81#define MBEDTLS_SSL_DEBUG_MSG( level, args ) do { } while( 0 )
82#define MBEDTLS_SSL_DEBUG_RET( level, text, ret ) do { } while( 0 )
83#define MBEDTLS_SSL_DEBUG_BUF( level, text, buf, len ) do { } while( 0 )
84#define MBEDTLS_SSL_DEBUG_MPI( level, text, X ) do { } while( 0 )
85#define MBEDTLS_SSL_DEBUG_ECP( level, text, X ) do { } while( 0 )
86#define MBEDTLS_SSL_DEBUG_CRT( level, text, crt ) do { } while( 0 )
87#define MBEDTLS_SSL_DEBUG_ECDH( level, ecdh, attr ) do { } while( 0 )
88
89#endif /* MBEDTLS_DEBUG_C */
90
91#ifdef __cplusplus
92extern "C" {
93#endif
94
95/**
96 * \brief Set the threshold error level to handle globally all debug output.
97 * Debug messages that have a level over the threshold value are
98 * discarded.
99 * (Default value: 0 = No debug )
100 *
101 * \param threshold theshold level of messages to filter on. Messages at a
102 * higher level will be discarded.
103 * - Debug levels
104 * - 0 No debug
105 * - 1 Error
106 * - 2 State change
107 * - 3 Informational
108 * - 4 Verbose
109 */
110void mbedtls_debug_set_threshold( int threshold );
111
112/**
113 * \brief Print a message to the debug output. This function is always used
114 * through the MBEDTLS_SSL_DEBUG_MSG() macro, which supplies the ssl
115 * context, file and line number parameters.
116 *
117 * \param ssl SSL context
118 * \param level error level of the debug message
119 * \param file file the message has occurred in
120 * \param line line number the message has occurred at
121 * \param format format specifier, in printf format
122 * \param ... variables used by the format specifier
123 *
124 * \attention This function is intended for INTERNAL usage within the
125 * library only.
126 */
128 const char *file, int line,
129 const char *format, ... );
130
131/**
132 * \brief Print the return value of a function to the debug output. This
133 * function is always used through the MBEDTLS_SSL_DEBUG_RET() macro,
134 * which supplies the ssl context, file and line number parameters.
135 *
136 * \param ssl SSL context
137 * \param level error level of the debug message
138 * \param file file the error has occurred in
139 * \param line line number the error has occurred in
140 * \param text the name of the function that returned the error
141 * \param ret the return code value
142 *
143 * \attention This function is intended for INTERNAL usage within the
144 * library only.
145 */
147 const char *file, int line,
148 const char *text, int ret );
149
150/**
151 * \brief Output a buffer of size len bytes to the debug output. This function
152 * is always used through the MBEDTLS_SSL_DEBUG_BUF() macro,
153 * which supplies the ssl context, file and line number parameters.
154 *
155 * \param ssl SSL context
156 * \param level error level of the debug message
157 * \param file file the error has occurred in
158 * \param line line number the error has occurred in
159 * \param text a name or label for the buffer being dumped. Normally the
160 * variable or buffer name
161 * \param buf the buffer to be outputted
162 * \param len length of the buffer
163 *
164 * \attention This function is intended for INTERNAL usage within the
165 * library only.
166 */
168 const char *file, int line, const char *text,
169 const unsigned char *buf, size_t len );
170
171#if defined(MBEDTLS_BIGNUM_C)
172/**
173 * \brief Print a MPI variable to the debug output. This function is always
174 * used through the MBEDTLS_SSL_DEBUG_MPI() macro, which supplies the
175 * ssl context, file and line number parameters.
176 *
177 * \param ssl SSL context
178 * \param level error level of the debug message
179 * \param file file the error has occurred in
180 * \param line line number the error has occurred in
181 * \param text a name or label for the MPI being output. Normally the
182 * variable name
183 * \param X the MPI variable
184 *
185 * \attention This function is intended for INTERNAL usage within the
186 * library only.
187 */
188void mbedtls_debug_print_mpi( const mbedtls_ssl_context *ssl, int level,
189 const char *file, int line,
190 const char *text, const mbedtls_mpi *X );
191#endif
192
193#if defined(MBEDTLS_ECP_C)
194/**
195 * \brief Print an ECP point to the debug output. This function is always
196 * used through the MBEDTLS_SSL_DEBUG_ECP() macro, which supplies the
197 * ssl context, file and line number parameters.
198 *
199 * \param ssl SSL context
200 * \param level error level of the debug message
201 * \param file file the error has occurred in
202 * \param line line number the error has occurred in
203 * \param text a name or label for the ECP point being output. Normally the
204 * variable name
205 * \param X the ECP point
206 *
207 * \attention This function is intended for INTERNAL usage within the
208 * library only.
209 */
210void mbedtls_debug_print_ecp( const mbedtls_ssl_context *ssl, int level,
211 const char *file, int line,
212 const char *text, const mbedtls_ecp_point *X );
213#endif
214
215#if defined(MBEDTLS_X509_CRT_PARSE_C)
216/**
217 * \brief Print a X.509 certificate structure to the debug output. This
218 * function is always used through the MBEDTLS_SSL_DEBUG_CRT() macro,
219 * which supplies the ssl context, file and line number parameters.
220 *
221 * \param ssl SSL context
222 * \param level error level of the debug message
223 * \param file file the error has occurred in
224 * \param line line number the error has occurred in
225 * \param text a name or label for the certificate being output
226 * \param crt X.509 certificate structure
227 *
228 * \attention This function is intended for INTERNAL usage within the
229 * library only.
230 */
231void mbedtls_debug_print_crt( const mbedtls_ssl_context *ssl, int level,
232 const char *file, int line,
233 const char *text, const mbedtls_x509_crt *crt );
234#endif
235
236#if defined(MBEDTLS_ECDH_C)
237typedef enum
238{
239 MBEDTLS_DEBUG_ECDH_Q,
240 MBEDTLS_DEBUG_ECDH_QP,
241 MBEDTLS_DEBUG_ECDH_Z,
242} mbedtls_debug_ecdh_attr;
243
244/**
245 * \brief Print a field of the ECDH structure in the SSL context to the debug
246 * output. This function is always used through the
247 * MBEDTLS_SSL_DEBUG_ECDH() macro, which supplies the ssl context, file
248 * and line number parameters.
249 *
250 * \param ssl SSL context
251 * \param level error level of the debug message
252 * \param file file the error has occurred in
253 * \param line line number the error has occurred in
254 * \param ecdh the ECDH context
255 * \param attr the identifier of the attribute being output
256 *
257 * \attention This function is intended for INTERNAL usage within the
258 * library only.
259 */
260void mbedtls_debug_printf_ecdh( const mbedtls_ssl_context *ssl, int level,
261 const char *file, int line,
262 const mbedtls_ecdh_context *ecdh,
263 mbedtls_debug_ecdh_attr attr );
264#endif
265
266/// \}
267/// \}
268
269#ifdef __cplusplus
270}
271#endif
272
273#endif /* debug.h */
Configuration options (set of defines)
void mbedtls_debug_set_threshold(int threshold)
Set the threshold error level to handle globally all debug output.
void mbedtls_debug_print_buf(const mbedtls_ssl_context *ssl, int level, const char *file, int line, const char *text, const unsigned char *buf, size_t len)
Output a buffer of size len bytes to the debug output.
void mbedtls_debug_print_ret(const mbedtls_ssl_context *ssl, int level, const char *file, int line, const char *text, int ret)
Print the return value of a function to the debug output.
void mbedtls_debug_print_msg(const mbedtls_ssl_context *ssl, int level, const char *file, int line, const char *format,...)
Print a message to the debug output.
This file provides an API for Elliptic Curves over GF(P) (ECP).
SSL/TLS functions.
The ECDH context structure.
Definition: ecdh.h:113
The ECP point structure, in Jacobian coordinates.
MPI structure.
Definition: bignum.h:185
Container for an X.509 certificate.
Definition: x509_crt.h:53