Merge pull request #2735 from jareckib/master
[RRG-proxmark3.git] / common / mbedtls / debug.h
blobd48057fef0eb5e1e0207178c493b5ac773937c55
1 /**
2 * \file debug.h
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
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
14 * http://www.apache.org/licenses/LICENSE-2.0
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.
22 #ifndef MBEDTLS_DEBUG_H
23 #define MBEDTLS_DEBUG_H
25 #if !defined(MBEDTLS_CONFIG_FILE)
26 #include "mbedtls/config.h"
27 #else
28 #include MBEDTLS_CONFIG_FILE
29 #endif
31 #include "mbedtls/ssl.h"
33 #if defined(MBEDTLS_ECP_C)
34 #include "mbedtls/ecp.h"
35 #endif
37 #if defined(MBEDTLS_DEBUG_C)
39 #define MBEDTLS_DEBUG_STRIP_PARENS( ... ) __VA_ARGS__
41 #define MBEDTLS_SSL_DEBUG_MSG( level, args ) \
42 mbedtls_debug_print_msg( ssl, level, __FILE__, __LINE__, \
43 MBEDTLS_DEBUG_STRIP_PARENS args )
45 #define MBEDTLS_SSL_DEBUG_RET( level, text, ret ) \
46 mbedtls_debug_print_ret( ssl, level, __FILE__, __LINE__, text, ret )
48 #define MBEDTLS_SSL_DEBUG_BUF( level, text, buf, len ) \
49 mbedtls_debug_print_buf( ssl, level, __FILE__, __LINE__, text, buf, len )
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
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
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
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
71 #else /* MBEDTLS_DEBUG_C */
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 )
81 #endif /* MBEDTLS_DEBUG_C */
83 /**
84 * \def MBEDTLS_PRINTF_ATTRIBUTE
86 * Mark a function as having printf attributes, and thus enable checking
87 * via -wFormat and other flags. This does nothing on builds with compilers
88 * that do not support the format attribute
90 * Module: library/debug.c
91 * Caller:
93 * This module provides debugging functions.
95 #if defined(__has_attribute)
96 #if __has_attribute(format)
97 #define MBEDTLS_PRINTF_ATTRIBUTE(string_index, first_to_check) \
98 __attribute__((format (printf, string_index, first_to_check)))
99 #else /* __has_attribute(format) */
100 #define MBEDTLS_PRINTF_ATTRIBUTE(string_index, first_to_check)
101 #endif /* __has_attribute(format) */
102 #else /* defined(__has_attribute) */
103 #define MBEDTLS_PRINTF_ATTRIBUTE(string_index, first_to_check)
104 #endif
107 * \def MBEDTLS_PRINTF_SIZET
109 * MBEDTLS_PRINTF_xxx: Due to issues with older window compilers
110 * and MinGW we need to define the printf specifier for size_t
111 * and long long per platform.
113 * Module: library/debug.c
114 * Caller:
116 * This module provides debugging functions.
118 #if defined(__MINGW32__) || (defined(_MSC_VER) && _MSC_VER < 1800)
119 #include <inttypes.h>
120 #define MBEDTLS_PRINTF_SIZET PRIuPTR
121 #define MBEDTLS_PRINTF_LONGLONG "I64d"
122 #else /* defined(__MINGW32__) || (defined(_MSC_VER) && _MSC_VER < 1800) */
123 #define MBEDTLS_PRINTF_SIZET "zu"
124 #define MBEDTLS_PRINTF_LONGLONG "lld"
125 #endif /* defined(__MINGW32__) || (defined(_MSC_VER) && _MSC_VER < 1800) */
127 #ifdef __cplusplus
128 extern "C" {
129 #endif
132 * \brief Set the threshold error level to handle globally all debug output.
133 * Debug messages that have a level over the threshold value are
134 * discarded.
135 * (Default value: 0 = No debug )
137 * \param threshold theshold level of messages to filter on. Messages at a
138 * higher level will be discarded.
139 * - Debug levels
140 * - 0 No debug
141 * - 1 Error
142 * - 2 State change
143 * - 3 Informational
144 * - 4 Verbose
146 void mbedtls_debug_set_threshold(int threshold);
149 * \brief Print a message to the debug output. This function is always used
150 * through the MBEDTLS_SSL_DEBUG_MSG() macro, which supplies the ssl
151 * context, file and line number parameters.
153 * \param ssl SSL context
154 * \param level error level of the debug message
155 * \param file file the message has occurred in
156 * \param line line number the message has occurred at
157 * \param format format specifier, in printf format
158 * \param ... variables used by the format specifier
160 * \attention This function is intended for INTERNAL usage within the
161 * library only.
163 void mbedtls_debug_print_msg(const mbedtls_ssl_context *ssl, int level,
164 const char *file, int line,
165 const char *format, ...) MBEDTLS_PRINTF_ATTRIBUTE(5, 6);
168 * \brief Print the return value of a function to the debug output. This
169 * function is always used through the MBEDTLS_SSL_DEBUG_RET() macro,
170 * which supplies the ssl context, file and line number parameters.
172 * \param ssl SSL context
173 * \param level error level of the debug message
174 * \param file file the error has occurred in
175 * \param line line number the error has occurred in
176 * \param text the name of the function that returned the error
177 * \param ret the return code value
179 * \attention This function is intended for INTERNAL usage within the
180 * library only.
182 void mbedtls_debug_print_ret(const mbedtls_ssl_context *ssl, int level,
183 const char *file, int line,
184 const char *text, int ret);
187 * \brief Output a buffer of size len bytes to the debug output. This function
188 * is always used through the MBEDTLS_SSL_DEBUG_BUF() macro,
189 * which supplies the ssl context, file and line number parameters.
191 * \param ssl SSL context
192 * \param level error level of the debug message
193 * \param file file the error has occurred in
194 * \param line line number the error has occurred in
195 * \param text a name or label for the buffer being dumped. Normally the
196 * variable or buffer name
197 * \param buf the buffer to be outputted
198 * \param len length of the buffer
200 * \attention This function is intended for INTERNAL usage within the
201 * library only.
203 void mbedtls_debug_print_buf(const mbedtls_ssl_context *ssl, int level,
204 const char *file, int line, const char *text,
205 const unsigned char *buf, size_t len);
207 #if defined(MBEDTLS_BIGNUM_C)
209 * \brief Print a MPI variable to the debug output. This function is always
210 * used through the MBEDTLS_SSL_DEBUG_MPI() macro, which supplies the
211 * ssl context, file and line number parameters.
213 * \param ssl SSL context
214 * \param level error level of the debug message
215 * \param file file the error has occurred in
216 * \param line line number the error has occurred in
217 * \param text a name or label for the MPI being output. Normally the
218 * variable name
219 * \param X the MPI variable
221 * \attention This function is intended for INTERNAL usage within the
222 * library only.
224 void mbedtls_debug_print_mpi(const mbedtls_ssl_context *ssl, int level,
225 const char *file, int line,
226 const char *text, const mbedtls_mpi *X);
227 #endif
229 #if defined(MBEDTLS_ECP_C)
231 * \brief Print an ECP point to the debug output. This function is always
232 * used through the MBEDTLS_SSL_DEBUG_ECP() macro, which supplies the
233 * ssl context, file and line number parameters.
235 * \param ssl SSL context
236 * \param level error level of the debug message
237 * \param file file the error has occurred in
238 * \param line line number the error has occurred in
239 * \param text a name or label for the ECP point being output. Normally the
240 * variable name
241 * \param X the ECP point
243 * \attention This function is intended for INTERNAL usage within the
244 * library only.
246 void mbedtls_debug_print_ecp(const mbedtls_ssl_context *ssl, int level,
247 const char *file, int line,
248 const char *text, const mbedtls_ecp_point *X);
249 #endif
251 #if defined(MBEDTLS_X509_CRT_PARSE_C)
253 * \brief Print a X.509 certificate structure to the debug output. This
254 * function is always used through the MBEDTLS_SSL_DEBUG_CRT() macro,
255 * which supplies the ssl context, file and line number parameters.
257 * \param ssl SSL context
258 * \param level error level of the debug message
259 * \param file file the error has occurred in
260 * \param line line number the error has occurred in
261 * \param text a name or label for the certificate being output
262 * \param crt X.509 certificate structure
264 * \attention This function is intended for INTERNAL usage within the
265 * library only.
267 void mbedtls_debug_print_crt(const mbedtls_ssl_context *ssl, int level,
268 const char *file, int line,
269 const char *text, const mbedtls_x509_crt *crt);
270 #endif
272 #if defined(MBEDTLS_ECDH_C)
273 typedef enum {
274 MBEDTLS_DEBUG_ECDH_Q,
275 MBEDTLS_DEBUG_ECDH_QP,
276 MBEDTLS_DEBUG_ECDH_Z,
277 } mbedtls_debug_ecdh_attr;
280 * \brief Print a field of the ECDH structure in the SSL context to the debug
281 * output. This function is always used through the
282 * MBEDTLS_SSL_DEBUG_ECDH() macro, which supplies the ssl context, file
283 * and line number parameters.
285 * \param ssl SSL context
286 * \param level error level of the debug message
287 * \param file file the error has occurred in
288 * \param line line number the error has occurred in
289 * \param ecdh the ECDH context
290 * \param attr the identifier of the attribute being output
292 * \attention This function is intended for INTERNAL usage within the
293 * library only.
295 void mbedtls_debug_printf_ecdh(const mbedtls_ssl_context *ssl, int level,
296 const char *file, int line,
297 const mbedtls_ecdh_context *ecdh,
298 mbedtls_debug_ecdh_attr attr);
299 #endif
301 #ifdef __cplusplus
303 #endif
305 #endif /* debug.h */