mbed TLS v3.1.0
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 #include "mbedtls/build_info.h"
26 
27 #include "mbedtls/ssl.h"
28 
29 #if defined(MBEDTLS_ECP_C)
30 #include "mbedtls/ecp.h"
31 #endif
32 
33 #if defined(MBEDTLS_DEBUG_C)
34 
35 #define MBEDTLS_DEBUG_STRIP_PARENS( ... ) __VA_ARGS__
36 
37 #define MBEDTLS_SSL_DEBUG_MSG( level, args ) \
38  mbedtls_debug_print_msg( ssl, level, __FILE__, __LINE__, \
39  MBEDTLS_DEBUG_STRIP_PARENS args )
40 
41 #define MBEDTLS_SSL_DEBUG_RET( level, text, ret ) \
42  mbedtls_debug_print_ret( ssl, level, __FILE__, __LINE__, text, ret )
43 
44 #define MBEDTLS_SSL_DEBUG_BUF( level, text, buf, len ) \
45  mbedtls_debug_print_buf( ssl, level, __FILE__, __LINE__, text, buf, len )
46 
47 #if defined(MBEDTLS_BIGNUM_C)
48 #define MBEDTLS_SSL_DEBUG_MPI( level, text, X ) \
49  mbedtls_debug_print_mpi( ssl, level, __FILE__, __LINE__, text, X )
50 #endif
51 
52 #if defined(MBEDTLS_ECP_C)
53 #define MBEDTLS_SSL_DEBUG_ECP( level, text, X ) \
54  mbedtls_debug_print_ecp( ssl, level, __FILE__, __LINE__, text, X )
55 #endif
56 
57 #if defined(MBEDTLS_X509_CRT_PARSE_C)
58 #if !defined(MBEDTLS_X509_REMOVE_INFO)
59 #define MBEDTLS_SSL_DEBUG_CRT( level, text, crt ) \
60  mbedtls_debug_print_crt( ssl, level, __FILE__, __LINE__, text, crt )
61 #else
62 #define MBEDTLS_SSL_DEBUG_CRT( level, text, crt ) do { } while( 0 )
63 #endif /* MBEDTLS_X509_REMOVE_INFO */
64 #endif /* MBEDTLS_X509_CRT_PARSE_C */
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 /* (defined(__MINGW32__) && __USE_MINGW_ANSI_STDIO == 0) || (defined(_MSC_VER) && _MSC_VER < 1800) */
128  #define MBEDTLS_PRINTF_SIZET "zu"
129  #define MBEDTLS_PRINTF_LONGLONG "lld"
130 #endif /* (defined(__MINGW32__) && __USE_MINGW_ANSI_STDIO == 0) || (defined(_MSC_VER) && _MSC_VER < 1800) */
131 
132 #ifdef __cplusplus
133 extern "C" {
134 #endif
135 
151 void mbedtls_debug_set_threshold( int threshold );
152 
168 void mbedtls_debug_print_msg( const mbedtls_ssl_context *ssl, int level,
169  const char *file, int line,
170  const char *format, ... ) MBEDTLS_PRINTF_ATTRIBUTE(5, 6);
171 
187 void mbedtls_debug_print_ret( const mbedtls_ssl_context *ssl, int level,
188  const char *file, int line,
189  const char *text, int ret );
190 
208 void mbedtls_debug_print_buf( const mbedtls_ssl_context *ssl, int level,
209  const char *file, int line, const char *text,
210  const unsigned char *buf, size_t len );
211 
212 #if defined(MBEDTLS_BIGNUM_C)
213 
229 void mbedtls_debug_print_mpi( const mbedtls_ssl_context *ssl, int level,
230  const char *file, int line,
231  const char *text, const mbedtls_mpi *X );
232 #endif
233 
234 #if defined(MBEDTLS_ECP_C)
235 
251 void mbedtls_debug_print_ecp( const mbedtls_ssl_context *ssl, int level,
252  const char *file, int line,
253  const char *text, const mbedtls_ecp_point *X );
254 #endif
255 
256 #if defined(MBEDTLS_X509_CRT_PARSE_C) && !defined(MBEDTLS_X509_REMOVE_INFO)
257 
272 void mbedtls_debug_print_crt( const mbedtls_ssl_context *ssl, int level,
273  const char *file, int line,
274  const char *text, const mbedtls_x509_crt *crt );
275 #endif
276 
277 #if defined(MBEDTLS_ECDH_C)
278 typedef enum
279 {
284 
301 void mbedtls_debug_printf_ecdh( const mbedtls_ssl_context *ssl, int level,
302  const char *file, int line,
303  const mbedtls_ecdh_context *ecdh,
305 #endif
306 
307 #ifdef __cplusplus
308 }
309 #endif
310 
311 #endif /* debug.h */
#define MBEDTLS_PRINTF_ATTRIBUTE(string_index, first_to_check)
Definition: debug.h:108
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:278
void 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_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_msg(const mbedtls_ssl_context *ssl, int level, const char *file, int line, const char *format,...) MBEDTLS_PRINTF_ATTRIBUTE(5
Print a message to the debug output. This function is always used through the MBEDTLS_SSL_DEBUG_MSG()...
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:120
Build-time configuration info.
MPI structure.
Definition: bignum.h:189
SSL/TLS functions.
The ECP point structure, in Jacobian coordinates.
Definition: ecp.h:172
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...