Mbed TLS v2.28.5
debug.h
Go to the documentation of this file.
1 
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 #if defined(MBEDTLS_DEBUG_C)
38 
39 #define MBEDTLS_DEBUG_STRIP_PARENS(...) __VA_ARGS__
40 
41 #define MBEDTLS_SSL_DEBUG_MSG(level, args) \
42  mbedtls_debug_print_msg(ssl, level, __FILE__, __LINE__, \
43  MBEDTLS_DEBUG_STRIP_PARENS args)
44 
45 #define MBEDTLS_SSL_DEBUG_RET(level, text, ret) \
46  mbedtls_debug_print_ret(ssl, level, __FILE__, __LINE__, text, ret)
47 
48 #define MBEDTLS_SSL_DEBUG_BUF(level, text, buf, len) \
49  mbedtls_debug_print_buf(ssl, level, __FILE__, __LINE__, text, buf, len)
50 
51 #if defined(MBEDTLS_BIGNUM_C)
52 #define MBEDTLS_SSL_DEBUG_MPI(level, text, X) \
53  mbedtls_debug_print_mpi(ssl, level, __FILE__, __LINE__, text, X)
54 #endif
55 
56 #if defined(MBEDTLS_ECP_C)
57 #define MBEDTLS_SSL_DEBUG_ECP(level, text, X) \
58  mbedtls_debug_print_ecp(ssl, level, __FILE__, __LINE__, text, X)
59 #endif
60 
61 #if defined(MBEDTLS_X509_CRT_PARSE_C)
62 #define MBEDTLS_SSL_DEBUG_CRT(level, text, crt) \
63  mbedtls_debug_print_crt(ssl, level, __FILE__, __LINE__, text, crt)
64 #endif
65 
66 #if defined(MBEDTLS_ECDH_C)
67 #define MBEDTLS_SSL_DEBUG_ECDH(level, ecdh, attr) \
68  mbedtls_debug_printf_ecdh(ssl, level, __FILE__, __LINE__, ecdh, attr)
69 #endif
70 
71 #else /* MBEDTLS_DEBUG_C */
72 
73 #define MBEDTLS_SSL_DEBUG_MSG(level, args) do { } while (0)
74 #define MBEDTLS_SSL_DEBUG_RET(level, text, ret) do { } while (0)
75 #define MBEDTLS_SSL_DEBUG_BUF(level, text, buf, len) do { } while (0)
76 #define MBEDTLS_SSL_DEBUG_MPI(level, text, X) do { } while (0)
77 #define MBEDTLS_SSL_DEBUG_ECP(level, text, X) do { } while (0)
78 #define MBEDTLS_SSL_DEBUG_CRT(level, text, crt) do { } while (0)
79 #define MBEDTLS_SSL_DEBUG_ECDH(level, ecdh, attr) do { } while (0)
80 
81 #endif /* MBEDTLS_DEBUG_C */
82 
95 #if defined(__has_attribute)
96 #if __has_attribute(format)
97 #if defined(__MINGW32__) && __USE_MINGW_ANSI_STDIO == 1
98 #define MBEDTLS_PRINTF_ATTRIBUTE(string_index, first_to_check) \
99  __attribute__((__format__(gnu_printf, string_index, first_to_check)))
100 #else /* defined(__MINGW32__) && __USE_MINGW_ANSI_STDIO == 1 */
101 #define MBEDTLS_PRINTF_ATTRIBUTE(string_index, first_to_check) \
102  __attribute__((format(printf, string_index, first_to_check)))
103 #endif
104 #else /* __has_attribute(format) */
105 #define MBEDTLS_PRINTF_ATTRIBUTE(string_index, first_to_check)
106 #endif /* __has_attribute(format) */
107 #else /* defined(__has_attribute) */
108 #define MBEDTLS_PRINTF_ATTRIBUTE(string_index, first_to_check)
109 #endif
110 
123 #if (defined(__MINGW32__) && __USE_MINGW_ANSI_STDIO == 0) || (defined(_MSC_VER) && _MSC_VER < 1800)
124  #include <inttypes.h>
125  #define MBEDTLS_PRINTF_SIZET PRIuPTR
126  #define MBEDTLS_PRINTF_LONGLONG "I64d"
127 #else \
128  /* (defined(__MINGW32__) && __USE_MINGW_ANSI_STDIO == 0) || (defined(_MSC_VER) && _MSC_VER < 1800) */
129  #define MBEDTLS_PRINTF_SIZET "zu"
130  #define MBEDTLS_PRINTF_LONGLONG "lld"
131 #endif \
132  /* (defined(__MINGW32__) && __USE_MINGW_ANSI_STDIO == 0) || (defined(_MSC_VER) && _MSC_VER < 1800) */
133 
134 #ifdef __cplusplus
135 extern "C" {
136 #endif
137 
153 void mbedtls_debug_set_threshold(int threshold);
154 
170 void mbedtls_debug_print_msg(const mbedtls_ssl_context *ssl, int level,
171  const char *file, int line,
172  const char *format, ...) MBEDTLS_PRINTF_ATTRIBUTE(5, 6);
173 
189 void mbedtls_debug_print_ret(const mbedtls_ssl_context *ssl, int level,
190  const char *file, int line,
191  const char *text, int ret);
192 
210 void mbedtls_debug_print_buf(const mbedtls_ssl_context *ssl, int level,
211  const char *file, int line, const char *text,
212  const unsigned char *buf, size_t len);
213 
214 #if defined(MBEDTLS_BIGNUM_C)
215 
231 void mbedtls_debug_print_mpi(const mbedtls_ssl_context *ssl, int level,
232  const char *file, int line,
233  const char *text, const mbedtls_mpi *X);
234 #endif
235 
236 #if defined(MBEDTLS_ECP_C)
237 
253 void mbedtls_debug_print_ecp(const mbedtls_ssl_context *ssl, int level,
254  const char *file, int line,
255  const char *text, const mbedtls_ecp_point *X);
256 #endif
257 
258 #if defined(MBEDTLS_X509_CRT_PARSE_C)
259 
274 void mbedtls_debug_print_crt(const mbedtls_ssl_context *ssl, int level,
275  const char *file, int line,
276  const char *text, const mbedtls_x509_crt *crt);
277 #endif
278 
279 #if defined(MBEDTLS_ECDH_C)
280 typedef enum {
285 
302 void mbedtls_debug_printf_ecdh(const mbedtls_ssl_context *ssl, int level,
303  const char *file, int line,
304  const mbedtls_ecdh_context *ecdh,
306 #endif
307 
308 #ifdef __cplusplus
309 }
310 #endif
311 
312 #endif /* debug.h */
#define MBEDTLS_PRINTF_ATTRIBUTE(string_index, first_to_check)
Definition: debug.h:108
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:280
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:101
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:208
SSL/TLS functions.
The ECP point structure, in Jacobian coordinates.
Definition: ecp.h:179
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...