blob: 11928e98183bc149fccfb39d356827eaccca1689 [file] [log] [blame]
Paul Bakker5121ce52009-01-03 21:22:43 +00001/**
2 * \file debug.h
Paul Bakkere0ccd0a2009-01-04 16:27:10 +00003 *
Simon Butcher7ef5cf32016-02-13 22:20:04 +00004 * \brief Functions for controlling and providing debug output from the library.
Darryl Greena40a1012018-01-05 15:33:17 +00005 */
6/*
Manuel Pégourié-Gonnard6fb81872015-07-27 11:11:48 +02007 * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
Bence Szépkútif744bd72020-06-05 13:02:18 +02008 * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
9 *
10 * This file is provided under the Apache License 2.0, or the
11 * GNU General Public License v2.0 or later.
12 *
13 * **********
14 * Apache License 2.0:
Manuel Pégourié-Gonnard37ff1402015-09-04 14:21:07 +020015 *
16 * Licensed under the Apache License, Version 2.0 (the "License"); you may
17 * not use this file except in compliance with the License.
18 * You may obtain a copy of the License at
19 *
20 * http://www.apache.org/licenses/LICENSE-2.0
21 *
22 * Unless required by applicable law or agreed to in writing, software
23 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
24 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
25 * See the License for the specific language governing permissions and
26 * limitations under the License.
Paul Bakkerb96f1542010-07-18 20:36:00 +000027 *
Bence Szépkútif744bd72020-06-05 13:02:18 +020028 * **********
29 *
30 * **********
31 * GNU General Public License v2.0 or later:
32 *
33 * This program is free software; you can redistribute it and/or modify
34 * it under the terms of the GNU General Public License as published by
35 * the Free Software Foundation; either version 2 of the License, or
36 * (at your option) any later version.
37 *
38 * This program is distributed in the hope that it will be useful,
39 * but WITHOUT ANY WARRANTY; without even the implied warranty of
40 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
41 * GNU General Public License for more details.
42 *
43 * You should have received a copy of the GNU General Public License along
44 * with this program; if not, write to the Free Software Foundation, Inc.,
45 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
46 *
47 * **********
48 *
Manuel Pégourié-Gonnardfe446432015-03-06 13:17:10 +000049 * This file is part of mbed TLS (https://tls.mbed.org)
Paul Bakker5121ce52009-01-03 21:22:43 +000050 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020051#ifndef MBEDTLS_DEBUG_H
52#define MBEDTLS_DEBUG_H
Paul Bakker5121ce52009-01-03 21:22:43 +000053
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020054#if !defined(MBEDTLS_CONFIG_FILE)
Paul Bakker314052f2011-08-15 09:07:52 +000055#include "config.h"
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020056#else
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020057#include MBEDTLS_CONFIG_FILE
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020058#endif
Rich Evans00ab4702015-02-06 13:43:58 +000059
Paul Bakker314052f2011-08-15 09:07:52 +000060#include "ssl.h"
Rich Evans00ab4702015-02-06 13:43:58 +000061
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020062#if defined(MBEDTLS_ECP_C)
Paul Bakker41c83d32013-03-20 14:39:14 +010063#include "ecp.h"
64#endif
Paul Bakker5121ce52009-01-03 21:22:43 +000065
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020066#if defined(MBEDTLS_DEBUG_C)
Paul Bakker5121ce52009-01-03 21:22:43 +000067
Manuel Pégourié-Gonnardb74c2452015-06-29 20:08:23 +020068#define MBEDTLS_DEBUG_STRIP_PARENS( ... ) __VA_ARGS__
69
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020070#define MBEDTLS_SSL_DEBUG_MSG( level, args ) \
Manuel Pégourié-Gonnarda16e7c42015-06-29 20:14:19 +020071 mbedtls_debug_print_msg( ssl, level, __FILE__, __LINE__, \
Manuel Pégourié-Gonnardb74c2452015-06-29 20:08:23 +020072 MBEDTLS_DEBUG_STRIP_PARENS args )
Paul Bakker5121ce52009-01-03 21:22:43 +000073
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020074#define MBEDTLS_SSL_DEBUG_RET( level, text, ret ) \
Manuel Pégourié-Gonnard2ff873c2015-05-19 14:38:09 +020075 mbedtls_debug_print_ret( ssl, level, __FILE__, __LINE__, text, ret )
Paul Bakker5121ce52009-01-03 21:22:43 +000076
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020077#define MBEDTLS_SSL_DEBUG_BUF( level, text, buf, len ) \
Manuel Pégourié-Gonnard2ff873c2015-05-19 14:38:09 +020078 mbedtls_debug_print_buf( ssl, level, __FILE__, __LINE__, text, buf, len )
Paul Bakker5121ce52009-01-03 21:22:43 +000079
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020080#if defined(MBEDTLS_BIGNUM_C)
81#define MBEDTLS_SSL_DEBUG_MPI( level, text, X ) \
Manuel Pégourié-Gonnard2ff873c2015-05-19 14:38:09 +020082 mbedtls_debug_print_mpi( ssl, level, __FILE__, __LINE__, text, X )
Paul Bakkered27a042013-04-18 22:46:23 +020083#endif
Paul Bakker5121ce52009-01-03 21:22:43 +000084
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020085#if defined(MBEDTLS_ECP_C)
86#define MBEDTLS_SSL_DEBUG_ECP( level, text, X ) \
Manuel Pégourié-Gonnard2ff873c2015-05-19 14:38:09 +020087 mbedtls_debug_print_ecp( ssl, level, __FILE__, __LINE__, text, X )
Paul Bakkered27a042013-04-18 22:46:23 +020088#endif
Paul Bakker41c83d32013-03-20 14:39:14 +010089
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020090#if defined(MBEDTLS_X509_CRT_PARSE_C)
91#define MBEDTLS_SSL_DEBUG_CRT( level, text, crt ) \
Manuel Pégourié-Gonnard2ff873c2015-05-19 14:38:09 +020092 mbedtls_debug_print_crt( ssl, level, __FILE__, __LINE__, text, crt )
Paul Bakkered27a042013-04-18 22:46:23 +020093#endif
Paul Bakker5121ce52009-01-03 21:22:43 +000094
Janos Follath948f4be2018-08-22 01:37:55 +010095#if defined(MBEDTLS_ECDH_C)
96#define MBEDTLS_SSL_DEBUG_ECDH( level, ecdh, attr ) \
97 mbedtls_debug_printf_ecdh( ssl, level, __FILE__, __LINE__, ecdh, attr )
98#endif
99
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200100#else /* MBEDTLS_DEBUG_C */
Paul Bakker5121ce52009-01-03 21:22:43 +0000101
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200102#define MBEDTLS_SSL_DEBUG_MSG( level, args ) do { } while( 0 )
103#define MBEDTLS_SSL_DEBUG_RET( level, text, ret ) do { } while( 0 )
104#define MBEDTLS_SSL_DEBUG_BUF( level, text, buf, len ) do { } while( 0 )
105#define MBEDTLS_SSL_DEBUG_MPI( level, text, X ) do { } while( 0 )
106#define MBEDTLS_SSL_DEBUG_ECP( level, text, X ) do { } while( 0 )
107#define MBEDTLS_SSL_DEBUG_CRT( level, text, crt ) do { } while( 0 )
Janos Follath948f4be2018-08-22 01:37:55 +0100108#define MBEDTLS_SSL_DEBUG_ECDH( level, ecdh, attr ) do { } while( 0 )
Paul Bakker5121ce52009-01-03 21:22:43 +0000109
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200110#endif /* MBEDTLS_DEBUG_C */
Paul Bakker5121ce52009-01-03 21:22:43 +0000111
112#ifdef __cplusplus
113extern "C" {
114#endif
115
Paul Bakkerc73079a2014-04-25 16:34:30 +0200116/**
Simon Butcher7ef5cf32016-02-13 22:20:04 +0000117 * \brief Set the threshold error level to handle globally all debug output.
118 * Debug messages that have a level over the threshold value are
119 * discarded.
120 * (Default value: 0 = No debug )
Paul Bakkerc73079a2014-04-25 16:34:30 +0200121 *
Simon Butcher7ef5cf32016-02-13 22:20:04 +0000122 * \param threshold theshold level of messages to filter on. Messages at a
123 * higher level will be discarded.
124 * - Debug levels
125 * - 0 No debug
126 * - 1 Error
127 * - 2 State change
128 * - 3 Informational
129 * - 4 Verbose
Paul Bakkerc73079a2014-04-25 16:34:30 +0200130 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200131void mbedtls_debug_set_threshold( int threshold );
Paul Bakkerc73079a2014-04-25 16:34:30 +0200132
Simon Butcher7ef5cf32016-02-13 22:20:04 +0000133/**
Janos Follathd75b7822016-03-18 16:28:20 +0000134 * \brief Print a message to the debug output. This function is always used
Simon Butcher7ef5cf32016-02-13 22:20:04 +0000135 * through the MBEDTLS_SSL_DEBUG_MSG() macro, which supplies the ssl
136 * context, file and line number parameters.
137 *
138 * \param ssl SSL context
139 * \param level error level of the debug message
140 * \param file file the message has occurred in
141 * \param line line number the message has occurred at
142 * \param format format specifier, in printf format
143 * \param ... variables used by the format specifier
144 *
145 * \attention This function is intended for INTERNAL usage within the
146 * library only.
147 */
Manuel Pégourié-Gonnarda16e7c42015-06-29 20:14:19 +0200148void mbedtls_debug_print_msg( const mbedtls_ssl_context *ssl, int level,
Manuel Pégourié-Gonnardb74c2452015-06-29 20:08:23 +0200149 const char *file, int line,
150 const char *format, ... );
Manuel Pégourié-Gonnardd23f5932015-06-23 12:04:52 +0200151
Simon Butcher7ef5cf32016-02-13 22:20:04 +0000152/**
153 * \brief Print the return value of a function to the debug output. This
154 * function is always used through the MBEDTLS_SSL_DEBUG_RET() macro,
155 * which supplies the ssl context, file and line number parameters.
156 *
157 * \param ssl SSL context
158 * \param level error level of the debug message
159 * \param file file the error has occurred in
160 * \param line line number the error has occurred in
161 * \param text the name of the function that returned the error
162 * \param ret the return code value
163 *
164 * \attention This function is intended for INTERNAL usage within the
165 * library only.
166 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200167void mbedtls_debug_print_ret( const mbedtls_ssl_context *ssl, int level,
Paul Bakkerff60ee62010-03-16 21:09:09 +0000168 const char *file, int line,
169 const char *text, int ret );
Paul Bakker5121ce52009-01-03 21:22:43 +0000170
Simon Butcher7ef5cf32016-02-13 22:20:04 +0000171/**
172 * \brief Output a buffer of size len bytes to the debug output. This function
173 * is always used through the MBEDTLS_SSL_DEBUG_BUF() macro,
174 * which supplies the ssl context, file and line number parameters.
175 *
176 * \param ssl SSL context
177 * \param level error level of the debug message
178 * \param file file the error has occurred in
179 * \param line line number the error has occurred in
180 * \param text a name or label for the buffer being dumped. Normally the
181 * variable or buffer name
182 * \param buf the buffer to be outputted
183 * \param len length of the buffer
184 *
185 * \attention This function is intended for INTERNAL usage within the
186 * library only.
187 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200188void mbedtls_debug_print_buf( const mbedtls_ssl_context *ssl, int level,
Paul Bakkerff60ee62010-03-16 21:09:09 +0000189 const char *file, int line, const char *text,
Manuel Pégourié-Gonnarda78b2182015-03-19 17:16:11 +0000190 const unsigned char *buf, size_t len );
Paul Bakker5121ce52009-01-03 21:22:43 +0000191
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200192#if defined(MBEDTLS_BIGNUM_C)
Simon Butcher7ef5cf32016-02-13 22:20:04 +0000193/**
194 * \brief Print a MPI variable to the debug output. This function is always
195 * used through the MBEDTLS_SSL_DEBUG_MPI() macro, which supplies the
196 * ssl context, file and line number parameters.
197 *
198 * \param ssl SSL context
199 * \param level error level of the debug message
200 * \param file file the error has occurred in
201 * \param line line number the error has occurred in
202 * \param text a name or label for the MPI being output. Normally the
203 * variable name
204 * \param X the MPI variable
205 *
206 * \attention This function is intended for INTERNAL usage within the
207 * library only.
208 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200209void mbedtls_debug_print_mpi( const mbedtls_ssl_context *ssl, int level,
Paul Bakkerff60ee62010-03-16 21:09:09 +0000210 const char *file, int line,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200211 const char *text, const mbedtls_mpi *X );
Paul Bakkered27a042013-04-18 22:46:23 +0200212#endif
Paul Bakker5121ce52009-01-03 21:22:43 +0000213
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200214#if defined(MBEDTLS_ECP_C)
Simon Butcher7ef5cf32016-02-13 22:20:04 +0000215/**
216 * \brief Print an ECP point to the debug output. This function is always
217 * used through the MBEDTLS_SSL_DEBUG_ECP() macro, which supplies the
218 * ssl context, file and line number parameters.
219 *
220 * \param ssl SSL context
221 * \param level error level of the debug message
222 * \param file file the error has occurred in
223 * \param line line number the error has occurred in
224 * \param text a name or label for the ECP point being output. Normally the
225 * variable name
226 * \param X the ECP point
227 *
228 * \attention This function is intended for INTERNAL usage within the
229 * library only.
230 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200231void mbedtls_debug_print_ecp( const mbedtls_ssl_context *ssl, int level,
Paul Bakker41c83d32013-03-20 14:39:14 +0100232 const char *file, int line,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200233 const char *text, const mbedtls_ecp_point *X );
Paul Bakker41c83d32013-03-20 14:39:14 +0100234#endif
235
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200236#if defined(MBEDTLS_X509_CRT_PARSE_C)
Simon Butcher7ef5cf32016-02-13 22:20:04 +0000237/**
238 * \brief Print a X.509 certificate structure to the debug output. This
239 * function is always used through the MBEDTLS_SSL_DEBUG_CRT() macro,
240 * which supplies the ssl context, file and line number parameters.
241 *
242 * \param ssl SSL context
243 * \param level error level of the debug message
244 * \param file file the error has occurred in
245 * \param line line number the error has occurred in
246 * \param text a name or label for the certificate being output
247 * \param crt X.509 certificate structure
248 *
249 * \attention This function is intended for INTERNAL usage within the
250 * library only.
251 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200252void mbedtls_debug_print_crt( const mbedtls_ssl_context *ssl, int level,
Paul Bakkerff60ee62010-03-16 21:09:09 +0000253 const char *file, int line,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200254 const char *text, const mbedtls_x509_crt *crt );
Paul Bakkered27a042013-04-18 22:46:23 +0200255#endif
Paul Bakker5121ce52009-01-03 21:22:43 +0000256
Janos Follath948f4be2018-08-22 01:37:55 +0100257#if defined(MBEDTLS_ECDH_C)
258typedef enum
259{
260 MBEDTLS_DEBUG_ECDH_Q,
261 MBEDTLS_DEBUG_ECDH_QP,
262 MBEDTLS_DEBUG_ECDH_Z,
263} mbedtls_debug_ecdh_attr;
264
265/**
266 * \brief Print a field of the ECDH structure in the SSL context to the debug
267 * output. This function is always used through the
268 * MBEDTLS_SSL_DEBUG_ECDH() macro, which supplies the ssl context, file
269 * and line number parameters.
270 *
271 * \param ssl SSL context
272 * \param level error level of the debug message
273 * \param file file the error has occurred in
274 * \param line line number the error has occurred in
275 * \param ecdh the ECDH context
276 * \param attr the identifier of the attribute being output
277 *
278 * \attention This function is intended for INTERNAL usage within the
279 * library only.
280 */
281void mbedtls_debug_printf_ecdh( const mbedtls_ssl_context *ssl, int level,
282 const char *file, int line,
283 const mbedtls_ecdh_context *ecdh,
284 mbedtls_debug_ecdh_attr attr );
285#endif
286
Paul Bakker5121ce52009-01-03 21:22:43 +0000287#ifdef __cplusplus
288}
289#endif
290
291#endif /* debug.h */
Simon Butcher7ef5cf32016-02-13 22:20:04 +0000292