Mbed TLS v3.5.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 \
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#if !defined(MBEDTLS_PRINTF_MS_TIME)
135#define MBEDTLS_PRINTF_MS_TIME PRId64
136#endif /* MBEDTLS_PRINTF_MS_TIME */
137
138#ifdef __cplusplus
139extern "C" {
140#endif
141
157void mbedtls_debug_set_threshold(int threshold);
158
175 const char *file, int line,
176 const char *format, ...) MBEDTLS_PRINTF_ATTRIBUTE(5, 6);
177
194 const char *file, int line,
195 const char *text, int ret);
196
215 const char *file, int line, const char *text,
216 const unsigned char *buf, size_t len);
217
218#if defined(MBEDTLS_BIGNUM_C)
236 const char *file, int line,
237 const char *text, const mbedtls_mpi *X);
238#endif
239
240#if defined(MBEDTLS_ECP_C)
258 const char *file, int line,
259 const char *text, const mbedtls_ecp_point *X);
260#endif
261
262#if defined(MBEDTLS_X509_CRT_PARSE_C) && !defined(MBEDTLS_X509_REMOVE_INFO)
279 const char *file, int line,
280 const char *text, const mbedtls_x509_crt *crt);
281#endif
282
283/* Note: the MBEDTLS_ECDH_C guard here is mandatory because this debug function
284 only works for the built-in implementation. */
285#if defined(MBEDTLS_KEY_EXCHANGE_SOME_ECDH_OR_ECDHE_ANY_ENABLED) && \
286 defined(MBEDTLS_ECDH_C)
287typedef enum {
292
310 const char *file, int line,
311 const mbedtls_ecdh_context *ecdh,
313#endif /* MBEDTLS_KEY_EXCHANGE_SOME_ECDH_OR_ECDHE_ANY_ENABLED &&
314 MBEDTLS_ECDH_C */
315
316#ifdef __cplusplus
317}
318#endif
319
320#endif /* debug.h */
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...
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_...
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_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...
#define MBEDTLS_PRINTF_ATTRIBUTE(string_index, first_to_check)
Definition: debug.h:108
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...
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_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_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()...
mbedtls_debug_ecdh_attr
Definition: debug.h:287
@ MBEDTLS_DEBUG_ECDH_QP
Definition: debug.h:289
@ MBEDTLS_DEBUG_ECDH_Q
Definition: debug.h:288
@ MBEDTLS_DEBUG_ECDH_Z
Definition: debug.h:290
This file provides an API for Elliptic Curves over GF(P) (ECP).
Build-time configuration info.
SSL/TLS functions.
The ECDH context structure.
Definition: ecdh.h:117
The ECP point structure, in Jacobian coordinates.
Definition: ecp.h:169
MPI structure.
Definition: bignum.h:219