v / thirdparty / mbedtls / library / debug_internal.h
185 lines · 175 sloc · 7.78 KB · 3d9911f887ecec942f9ae2a5be02d064f233b729
Raw
1/**
2 * \file debug_internal.h
3 *
4 * \brief Internal part of the public "debug.h".
5 */
6/*
7 * Copyright The Mbed TLS Contributors
8 * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
9 */
10#ifndef MBEDTLS_DEBUG_INTERNAL_H
11#define MBEDTLS_DEBUG_INTERNAL_H
12
13#include "mbedtls/debug.h"
14
15/* This should be equivalent to mbedtls_snprintf(). But it might not be due
16 * to platform shenanigans. For example, Mbed TLS and TF-PSA-Crypto could
17 * have inconsistent platform definitions. On Mingw, some code might
18 * be built with a different setting of __USE_MINGW_ANSI_STDIO, resulting
19 * in an old non-C99 printf being used somewhere.
20 *
21 * Our library assumes that mbedtls_snprintf() and other printf functions
22 * are consistent throughout. This function is not an official API and
23 * is not meant to be used inside the library. It is provided to help
24 * debugging printf inconsistencies issues. If you need it, good luck!
25 */
26int mbedtls_debug_snprintf(char *dest, size_t maxlen,
27 const char *format, ...) MBEDTLS_PRINTF_ATTRIBUTE(3, 4);
28/**
29 * \brief Print a message to the debug output. This function is always used
30 * through the MBEDTLS_SSL_DEBUG_MSG() macro, which supplies the ssl
31 * context, file and line number parameters.
32 *
33 * \param ssl SSL context
34 * \param level error level of the debug message
35 * \param file file the message has occurred in
36 * \param line line number the message has occurred at
37 * \param format format specifier, in printf format
38 * \param ... variables used by the format specifier
39 *
40 * \attention This function is intended for INTERNAL usage within the
41 * library only.
42 */
43void mbedtls_debug_print_msg(const mbedtls_ssl_context *ssl, int level,
44 const char *file, int line,
45 const char *format, ...) MBEDTLS_PRINTF_ATTRIBUTE(5, 6);
46
47/**
48 * \brief Print the return value of a function to the debug output. This
49 * function is always used through the MBEDTLS_SSL_DEBUG_RET() macro,
50 * which supplies the ssl context, file and line number parameters.
51 *
52 * \param ssl SSL context
53 * \param level error level of the debug message
54 * \param file file the error has occurred in
55 * \param line line number the error has occurred in
56 * \param text the name of the function that returned the error
57 * \param ret the return code value
58 *
59 * \attention This function is intended for INTERNAL usage within the
60 * library only.
61 */
62void mbedtls_debug_print_ret(const mbedtls_ssl_context *ssl, int level,
63 const char *file, int line,
64 const char *text, int ret);
65
66/**
67 * \brief Output a buffer of size len bytes to the debug output. This function
68 * is always used through the MBEDTLS_SSL_DEBUG_BUF() macro,
69 * which supplies the ssl context, file and line number parameters.
70 *
71 * \param ssl SSL context
72 * \param level error level of the debug message
73 * \param file file the error has occurred in
74 * \param line line number the error has occurred in
75 * \param text a name or label for the buffer being dumped. Normally the
76 * variable or buffer name
77 * \param buf the buffer to be outputted
78 * \param len length of the buffer
79 *
80 * \attention This function is intended for INTERNAL usage within the
81 * library only.
82 */
83void mbedtls_debug_print_buf(const mbedtls_ssl_context *ssl, int level,
84 const char *file, int line, const char *text,
85 const unsigned char *buf, size_t len);
86
87#if defined(MBEDTLS_BIGNUM_C)
88/**
89 * \brief Print a MPI variable to the debug output. This function is always
90 * used through the MBEDTLS_SSL_DEBUG_MPI() macro, which supplies the
91 * ssl context, file and line number parameters.
92 *
93 * \param ssl SSL context
94 * \param level error level of the debug message
95 * \param file file the error has occurred in
96 * \param line line number the error has occurred in
97 * \param text a name or label for the MPI being output. Normally the
98 * variable name
99 * \param X the MPI variable
100 *
101 * \attention This function is intended for INTERNAL usage within the
102 * library only.
103 */
104void mbedtls_debug_print_mpi(const mbedtls_ssl_context *ssl, int level,
105 const char *file, int line,
106 const char *text, const mbedtls_mpi *X);
107#endif
108
109#if defined(MBEDTLS_ECP_LIGHT)
110/**
111 * \brief Print an ECP point to the debug output. This function is always
112 * used through the MBEDTLS_SSL_DEBUG_ECP() macro, which supplies the
113 * ssl context, file and line number parameters.
114 *
115 * \param ssl SSL context
116 * \param level error level of the debug message
117 * \param file file the error has occurred in
118 * \param line line number the error has occurred in
119 * \param text a name or label for the ECP point being output. Normally the
120 * variable name
121 * \param X the ECP point
122 *
123 * \attention This function is intended for INTERNAL usage within the
124 * library only.
125 */
126void mbedtls_debug_print_ecp(const mbedtls_ssl_context *ssl, int level,
127 const char *file, int line,
128 const char *text, const mbedtls_ecp_point *X);
129#endif
130
131#if defined(MBEDTLS_X509_CRT_PARSE_C) && !defined(MBEDTLS_X509_REMOVE_INFO)
132/**
133 * \brief Print a X.509 certificate structure to the debug output. This
134 * function is always used through the MBEDTLS_SSL_DEBUG_CRT() macro,
135 * which supplies the ssl context, file and line number parameters.
136 *
137 * \param ssl SSL context
138 * \param level error level of the debug message
139 * \param file file the error has occurred in
140 * \param line line number the error has occurred in
141 * \param text a name or label for the certificate being output
142 * \param crt X.509 certificate structure
143 *
144 * \attention This function is intended for INTERNAL usage within the
145 * library only.
146 */
147void mbedtls_debug_print_crt(const mbedtls_ssl_context *ssl, int level,
148 const char *file, int line,
149 const char *text, const mbedtls_x509_crt *crt);
150#endif
151
152/* Note: the MBEDTLS_ECDH_C guard here is mandatory because this debug function
153 only works for the built-in implementation. */
154#if defined(MBEDTLS_KEY_EXCHANGE_SOME_ECDH_OR_ECDHE_ANY_ENABLED) && \
155 defined(MBEDTLS_ECDH_C)
156typedef enum {
157 MBEDTLS_DEBUG_ECDH_Q,
158 MBEDTLS_DEBUG_ECDH_QP,
159 MBEDTLS_DEBUG_ECDH_Z,
160} mbedtls_debug_ecdh_attr;
161
162/**
163 * \brief Print a field of the ECDH structure in the SSL context to the debug
164 * output. This function is always used through the
165 * MBEDTLS_SSL_DEBUG_ECDH() macro, which supplies the ssl context, file
166 * and line number parameters.
167 *
168 * \param ssl SSL context
169 * \param level error level of the debug message
170 * \param file file the error has occurred in
171 * \param line line number the error has occurred in
172 * \param ecdh the ECDH context
173 * \param attr the identifier of the attribute being output
174 *
175 * \attention This function is intended for INTERNAL usage within the
176 * library only.
177 */
178void mbedtls_debug_printf_ecdh(const mbedtls_ssl_context *ssl, int level,
179 const char *file, int line,
180 const mbedtls_ecdh_context *ecdh,
181 mbedtls_debug_ecdh_attr attr);
182#endif /* MBEDTLS_KEY_EXCHANGE_SOME_ECDH_OR_ECDHE_ANY_ENABLED &&
183 MBEDTLS_ECDH_C */
184
185#endif /* MBEDTLS_DEBUG_INTERNAL_H */
186