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
135extern "C" {
136#endif
137
153void mbedtls_debug_set_threshold(int threshold);
154
171 const char *file, int line,
172 const char *format, ...) MBEDTLS_PRINTF_ATTRIBUTE(5, 6);
173
190 const char *file, int line,
191 const char *text, int ret);
192
211 const char *file, int line, const char *text,
212 const unsigned char *buf, size_t len);
213
214#if defined(MBEDTLS_BIGNUM_C)
232 const char *file, int line,
233 const char *text, const mbedtls_mpi *X);
234#endif
235
236#if defined(MBEDTLS_ECP_C)
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)
275 const char *file, int line,
276 const char *text, const mbedtls_x509_crt *crt);
277#endif
278
279#if defined(MBEDTLS_ECDH_C)
280typedef enum {
285
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 */
Configuration options (set of defines)
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:280
@ MBEDTLS_DEBUG_ECDH_QP
Definition: debug.h:282
@ MBEDTLS_DEBUG_ECDH_Q
Definition: debug.h:281
@ MBEDTLS_DEBUG_ECDH_Z
Definition: debug.h:283
This file provides an API for Elliptic Curves over GF(P) (ECP).
SSL/TLS functions.
The ECDH context structure.
Definition: ecdh.h:101
The ECP point structure, in Jacobian coordinates.
Definition: ecp.h:179
MPI structure.
Definition: bignum.h:208