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 /**
16  * \brief    Print a message to the debug output. This function is always used
17  *          through the MBEDTLS_SSL_DEBUG_MSG() macro, which supplies the ssl
18  *          context, file and line number parameters.
19  *
20  * \param ssl       SSL context
21  * \param level     error level of the debug message
22  * \param file      file the message has occurred in
23  * \param line      line number the message has occurred at
24  * \param format    format specifier, in printf format
25  * \param ...       variables used by the format specifier
26  *
27  * \attention       This function is intended for INTERNAL usage within the
28  *                  library only.
29  */
30 void mbedtls_debug_print_msg(const mbedtls_ssl_context *ssl, int level,
31                              const char *file, int line,
32                              const char *format, ...) MBEDTLS_PRINTF_ATTRIBUTE(5, 6);
33 
34 /**
35  * \brief   Print the return value of a function to the debug output. This
36  *          function is always used through the MBEDTLS_SSL_DEBUG_RET() macro,
37  *          which supplies the ssl context, file and line number parameters.
38  *
39  * \param ssl       SSL context
40  * \param level     error level of the debug message
41  * \param file      file the error has occurred in
42  * \param line      line number the error has occurred in
43  * \param text      the name of the function that returned the error
44  * \param ret       the return code value
45  *
46  * \attention       This function is intended for INTERNAL usage within the
47  *                  library only.
48  */
49 void mbedtls_debug_print_ret(const mbedtls_ssl_context *ssl, int level,
50                              const char *file, int line,
51                              const char *text, int ret);
52 
53 /**
54  * \brief   Output a buffer of size len bytes to the debug output. This function
55  *          is always used through the MBEDTLS_SSL_DEBUG_BUF() macro,
56  *          which supplies the ssl context, file and line number parameters.
57  *
58  * \param ssl       SSL context
59  * \param level     error level of the debug message
60  * \param file      file the error has occurred in
61  * \param line      line number the error has occurred in
62  * \param text      a name or label for the buffer being dumped. Normally the
63  *                  variable or buffer name
64  * \param buf       the buffer to be outputted
65  * \param len       length of the buffer
66  *
67  * \attention       This function is intended for INTERNAL usage within the
68  *                  library only.
69  */
70 void mbedtls_debug_print_buf(const mbedtls_ssl_context *ssl, int level,
71                              const char *file, int line, const char *text,
72                              const unsigned char *buf, size_t len);
73 
74 #if defined(MBEDTLS_BIGNUM_C)
75 /**
76  * \brief   Print a MPI variable to the debug output. This function is always
77  *          used through the MBEDTLS_SSL_DEBUG_MPI() macro, which supplies the
78  *          ssl context, file and line number parameters.
79  *
80  * \param ssl       SSL context
81  * \param level     error level of the debug message
82  * \param file      file the error has occurred in
83  * \param line      line number the error has occurred in
84  * \param text      a name or label for the MPI being output. Normally the
85  *                  variable name
86  * \param X         the MPI variable
87  *
88  * \attention       This function is intended for INTERNAL usage within the
89  *                  library only.
90  */
91 void mbedtls_debug_print_mpi(const mbedtls_ssl_context *ssl, int level,
92                              const char *file, int line,
93                              const char *text, const mbedtls_mpi *X);
94 #endif
95 
96 #if defined(MBEDTLS_ECP_LIGHT)
97 /**
98  * \brief   Print an ECP point to the debug output. This function is always
99  *          used through the MBEDTLS_SSL_DEBUG_ECP() macro, which supplies the
100  *          ssl context, file and line number parameters.
101  *
102  * \param ssl       SSL context
103  * \param level     error level of the debug message
104  * \param file      file the error has occurred in
105  * \param line      line number the error has occurred in
106  * \param text      a name or label for the ECP point being output. Normally the
107  *                  variable name
108  * \param X         the ECP point
109  *
110  * \attention       This function is intended for INTERNAL usage within the
111  *                  library only.
112  */
113 void mbedtls_debug_print_ecp(const mbedtls_ssl_context *ssl, int level,
114                              const char *file, int line,
115                              const char *text, const mbedtls_ecp_point *X);
116 #endif
117 
118 #if defined(MBEDTLS_X509_CRT_PARSE_C) && !defined(MBEDTLS_X509_REMOVE_INFO)
119 /**
120  * \brief   Print a X.509 certificate structure to the debug output. This
121  *          function is always used through the MBEDTLS_SSL_DEBUG_CRT() macro,
122  *          which supplies the ssl context, file and line number parameters.
123  *
124  * \param ssl       SSL context
125  * \param level     error level of the debug message
126  * \param file      file the error has occurred in
127  * \param line      line number the error has occurred in
128  * \param text      a name or label for the certificate being output
129  * \param crt       X.509 certificate structure
130  *
131  * \attention       This function is intended for INTERNAL usage within the
132  *                  library only.
133  */
134 void mbedtls_debug_print_crt(const mbedtls_ssl_context *ssl, int level,
135                              const char *file, int line,
136                              const char *text, const mbedtls_x509_crt *crt);
137 #endif
138 
139 /* Note: the MBEDTLS_ECDH_C guard here is mandatory because this debug function
140          only works for the built-in implementation. */
141 #if defined(MBEDTLS_KEY_EXCHANGE_SOME_ECDH_OR_ECDHE_ANY_ENABLED) && \
142     defined(MBEDTLS_ECDH_C)
143 typedef enum {
144     MBEDTLS_DEBUG_ECDH_Q,
145     MBEDTLS_DEBUG_ECDH_QP,
146     MBEDTLS_DEBUG_ECDH_Z,
147 } mbedtls_debug_ecdh_attr;
148 
149 /**
150  * \brief   Print a field of the ECDH structure in the SSL context to the debug
151  *          output. This function is always used through the
152  *          MBEDTLS_SSL_DEBUG_ECDH() macro, which supplies the ssl context, file
153  *          and line number parameters.
154  *
155  * \param ssl       SSL context
156  * \param level     error level of the debug message
157  * \param file      file the error has occurred in
158  * \param line      line number the error has occurred in
159  * \param ecdh      the ECDH context
160  * \param attr      the identifier of the attribute being output
161  *
162  * \attention       This function is intended for INTERNAL usage within the
163  *                  library only.
164  */
165 void mbedtls_debug_printf_ecdh(const mbedtls_ssl_context *ssl, int level,
166                                const char *file, int line,
167                                const mbedtls_ecdh_context *ecdh,
168                                mbedtls_debug_ecdh_attr attr);
169 #endif /* MBEDTLS_KEY_EXCHANGE_SOME_ECDH_OR_ECDHE_ANY_ENABLED &&
170           MBEDTLS_ECDH_C */
171 
172 #endif /* MBEDTLS_DEBUG_INTERNAL_H */
173