Mbed TLS v2.28.9
debug.h
Go to the documentation of this file.
1 
6 /*
7  * Copyright The Mbed TLS Contributors
8  * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
9  */
10 #ifndef MBEDTLS_DEBUG_H
11 #define MBEDTLS_DEBUG_H
12 
13 #if !defined(MBEDTLS_CONFIG_FILE)
14 #include "mbedtls/config.h"
15 #else
16 #include MBEDTLS_CONFIG_FILE
17 #endif
18 
19 #include "mbedtls/ssl.h"
20 
21 #if defined(MBEDTLS_ECP_C)
22 #include "mbedtls/ecp.h"
23 #endif
24 
25 #if defined(MBEDTLS_DEBUG_C)
26 
27 #define MBEDTLS_DEBUG_STRIP_PARENS(...) __VA_ARGS__
28 
29 #define MBEDTLS_SSL_DEBUG_MSG(level, args) \
30  mbedtls_debug_print_msg(ssl, level, __FILE__, __LINE__, \
31  MBEDTLS_DEBUG_STRIP_PARENS args)
32 
33 #define MBEDTLS_SSL_DEBUG_RET(level, text, ret) \
34  mbedtls_debug_print_ret(ssl, level, __FILE__, __LINE__, text, ret)
35 
36 #define MBEDTLS_SSL_DEBUG_BUF(level, text, buf, len) \
37  mbedtls_debug_print_buf(ssl, level, __FILE__, __LINE__, text, buf, len)
38 
39 #if defined(MBEDTLS_BIGNUM_C)
40 #define MBEDTLS_SSL_DEBUG_MPI(level, text, X) \
41  mbedtls_debug_print_mpi(ssl, level, __FILE__, __LINE__, text, X)
42 #endif
43 
44 #if defined(MBEDTLS_ECP_C)
45 #define MBEDTLS_SSL_DEBUG_ECP(level, text, X) \
46  mbedtls_debug_print_ecp(ssl, level, __FILE__, __LINE__, text, X)
47 #endif
48 
49 #if defined(MBEDTLS_X509_CRT_PARSE_C)
50 #define MBEDTLS_SSL_DEBUG_CRT(level, text, crt) \
51  mbedtls_debug_print_crt(ssl, level, __FILE__, __LINE__, text, crt)
52 #endif
53 
54 #if defined(MBEDTLS_ECDH_C)
55 #define MBEDTLS_SSL_DEBUG_ECDH(level, ecdh, attr) \
56  mbedtls_debug_printf_ecdh(ssl, level, __FILE__, __LINE__, ecdh, attr)
57 #endif
58 
59 #else /* MBEDTLS_DEBUG_C */
60 
61 #define MBEDTLS_SSL_DEBUG_MSG(level, args) do { } while (0)
62 #define MBEDTLS_SSL_DEBUG_RET(level, text, ret) do { } while (0)
63 #define MBEDTLS_SSL_DEBUG_BUF(level, text, buf, len) do { } while (0)
64 #define MBEDTLS_SSL_DEBUG_MPI(level, text, X) do { } while (0)
65 #define MBEDTLS_SSL_DEBUG_ECP(level, text, X) do { } while (0)
66 #define MBEDTLS_SSL_DEBUG_CRT(level, text, crt) do { } while (0)
67 #define MBEDTLS_SSL_DEBUG_ECDH(level, ecdh, attr) do { } while (0)
68 
69 #endif /* MBEDTLS_DEBUG_C */
70 
83 #if defined(__has_attribute)
84 #if __has_attribute(format)
85 #if defined(__MINGW32__) && __USE_MINGW_ANSI_STDIO == 1
86 #define MBEDTLS_PRINTF_ATTRIBUTE(string_index, first_to_check) \
87  __attribute__((__format__(gnu_printf, string_index, first_to_check)))
88 #else /* defined(__MINGW32__) && __USE_MINGW_ANSI_STDIO == 1 */
89 #define MBEDTLS_PRINTF_ATTRIBUTE(string_index, first_to_check) \
90  __attribute__((format(printf, string_index, first_to_check)))
91 #endif
92 #else /* __has_attribute(format) */
93 #define MBEDTLS_PRINTF_ATTRIBUTE(string_index, first_to_check)
94 #endif /* __has_attribute(format) */
95 #else /* defined(__has_attribute) */
96 #define MBEDTLS_PRINTF_ATTRIBUTE(string_index, first_to_check)
97 #endif
98 
111 #if (defined(__MINGW32__) && __USE_MINGW_ANSI_STDIO == 0) || (defined(_MSC_VER) && _MSC_VER < 1800)
112  #include <inttypes.h>
113  #define MBEDTLS_PRINTF_SIZET PRIuPTR
114  #define MBEDTLS_PRINTF_LONGLONG "I64d"
115 #else \
116  /* (defined(__MINGW32__) && __USE_MINGW_ANSI_STDIO == 0) || (defined(_MSC_VER) && _MSC_VER < 1800) */
117  #define MBEDTLS_PRINTF_SIZET "zu"
118  #define MBEDTLS_PRINTF_LONGLONG "lld"
119 #endif \
120  /* (defined(__MINGW32__) && __USE_MINGW_ANSI_STDIO == 0) || (defined(_MSC_VER) && _MSC_VER < 1800) */
121 
122 #ifdef __cplusplus
123 extern "C" {
124 #endif
125 
141 void mbedtls_debug_set_threshold(int threshold);
142 
158 void mbedtls_debug_print_msg(const mbedtls_ssl_context *ssl, int level,
159  const char *file, int line,
160  const char *format, ...) MBEDTLS_PRINTF_ATTRIBUTE(5, 6);
161 
177 void mbedtls_debug_print_ret(const mbedtls_ssl_context *ssl, int level,
178  const char *file, int line,
179  const char *text, int ret);
180 
198 void mbedtls_debug_print_buf(const mbedtls_ssl_context *ssl, int level,
199  const char *file, int line, const char *text,
200  const unsigned char *buf, size_t len);
201 
202 #if defined(MBEDTLS_BIGNUM_C)
203 
219 void mbedtls_debug_print_mpi(const mbedtls_ssl_context *ssl, int level,
220  const char *file, int line,
221  const char *text, const mbedtls_mpi *X);
222 #endif
223 
224 #if defined(MBEDTLS_ECP_C)
225 
241 void mbedtls_debug_print_ecp(const mbedtls_ssl_context *ssl, int level,
242  const char *file, int line,
243  const char *text, const mbedtls_ecp_point *X);
244 #endif
245 
246 #if defined(MBEDTLS_X509_CRT_PARSE_C)
247 
262 void mbedtls_debug_print_crt(const mbedtls_ssl_context *ssl, int level,
263  const char *file, int line,
264  const char *text, const mbedtls_x509_crt *crt);
265 #endif
266 
267 #if defined(MBEDTLS_ECDH_C)
268 typedef enum {
273 
290 void mbedtls_debug_printf_ecdh(const mbedtls_ssl_context *ssl, int level,
291  const char *file, int line,
292  const mbedtls_ecdh_context *ecdh,
294 #endif
295 
296 #ifdef __cplusplus
297 }
298 #endif
299 
300 #endif /* debug.h */
#define MBEDTLS_PRINTF_ATTRIBUTE(string_index, first_to_check)
Definition: debug.h:96
void mbedtls_debug_print_crt(const mbedtls_ssl_context *ssl, int level, const char *file, int line, const char *text, const mbedtls_x509_crt *crt)
Print a X.509 certificate structure to the debug output. This function is always used through the MBE...
void mbedtls_debug_print_mpi(const mbedtls_ssl_context *ssl, int level, const char *file, int line, const char *text, const mbedtls_mpi *X)
Print a MPI variable to the debug output. This function is always used through the MBEDTLS_SSL_DEBUG_...
This file provides an API for Elliptic Curves over GF(P) (ECP).
mbedtls_debug_ecdh_attr
Definition: debug.h:268
Configuration options (set of defines)
void mbedtls_debug_set_threshold(int threshold)
Set the threshold error level to handle globally all debug output. Debug messages that have a level o...
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. This function is always used through the MB...
void mbedtls_debug_printf_ecdh(const mbedtls_ssl_context *ssl, int level, const char *file, int line, const mbedtls_ecdh_context *ecdh, mbedtls_debug_ecdh_attr attr)
Print a field of the ECDH structure in the SSL context to the debug output. This function is always u...
The ECDH context structure.
Definition: ecdh.h:89
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 function is always used through the MBEDTLS_SSL_DEBUG_MSG()...
MPI structure.
Definition: bignum.h:196
SSL/TLS functions.
The ECP point structure, in Jacobian coordinates.
Definition: ecp.h:167
void mbedtls_debug_print_ecp(const mbedtls_ssl_context *ssl, int level, const char *file, int line, const char *text, const mbedtls_ecp_point *X)
Print an ECP point to the debug output. This function is always used through the MBEDTLS_SSL_DEBUG_EC...
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. This function is always used through the MBEDT...