blob: 41cdd34a1f9da9c43590c3b9e94f957a79312c51 [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
Manuel Pégourié-Gonnard37ff1402015-09-04 14:21:07 +02008 * 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.
Paul Bakkerb96f1542010-07-18 20:36:00 +000021 *
Manuel Pégourié-Gonnardfe446432015-03-06 13:17:10 +000022 * This file is part of mbed TLS (https://tls.mbed.org)
Paul Bakker5121ce52009-01-03 21:22:43 +000023 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020024#ifndef MBEDTLS_DEBUG_H
25#define MBEDTLS_DEBUG_H
Paul Bakker5121ce52009-01-03 21:22:43 +000026
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020027#if !defined(MBEDTLS_CONFIG_FILE)
Paul Bakker314052f2011-08-15 09:07:52 +000028#include "config.h"
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020029#else
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020030#include MBEDTLS_CONFIG_FILE
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020031#endif
Rich Evans00ab4702015-02-06 13:43:58 +000032
Paul Bakker314052f2011-08-15 09:07:52 +000033#include "ssl.h"
Rich Evans00ab4702015-02-06 13:43:58 +000034
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020035#if defined(MBEDTLS_ECP_C)
Paul Bakker41c83d32013-03-20 14:39:14 +010036#include "ecp.h"
37#endif
Paul Bakker5121ce52009-01-03 21:22:43 +000038
Hanno Becker1b826852019-09-03 08:46:06 +010039#if defined(MBEDTLS_ECDH_C)
40#include "ecdh.h"
41#endif
42
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020043#if defined(MBEDTLS_DEBUG_C)
Paul Bakker5121ce52009-01-03 21:22:43 +000044
Manuel Pégourié-Gonnardb74c2452015-06-29 20:08:23 +020045#define MBEDTLS_DEBUG_STRIP_PARENS( ... ) __VA_ARGS__
46
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020047#define MBEDTLS_SSL_DEBUG_MSG( level, args ) \
Manuel Pégourié-Gonnarda16e7c42015-06-29 20:14:19 +020048 mbedtls_debug_print_msg( ssl, level, __FILE__, __LINE__, \
Manuel Pégourié-Gonnardb74c2452015-06-29 20:08:23 +020049 MBEDTLS_DEBUG_STRIP_PARENS args )
Paul Bakker5121ce52009-01-03 21:22:43 +000050
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020051#define MBEDTLS_SSL_DEBUG_RET( level, text, ret ) \
Manuel Pégourié-Gonnard2ff873c2015-05-19 14:38:09 +020052 mbedtls_debug_print_ret( ssl, level, __FILE__, __LINE__, text, ret )
Paul Bakker5121ce52009-01-03 21:22:43 +000053
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020054#define MBEDTLS_SSL_DEBUG_BUF( level, text, buf, len ) \
Manuel Pégourié-Gonnard2ff873c2015-05-19 14:38:09 +020055 mbedtls_debug_print_buf( ssl, level, __FILE__, __LINE__, text, buf, len )
Paul Bakker5121ce52009-01-03 21:22:43 +000056
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020057#if defined(MBEDTLS_BIGNUM_C)
58#define MBEDTLS_SSL_DEBUG_MPI( level, text, X ) \
Manuel Pégourié-Gonnard2ff873c2015-05-19 14:38:09 +020059 mbedtls_debug_print_mpi( ssl, level, __FILE__, __LINE__, text, X )
Paul Bakkered27a042013-04-18 22:46:23 +020060#endif
Paul Bakker5121ce52009-01-03 21:22:43 +000061
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020062#if defined(MBEDTLS_ECP_C)
63#define MBEDTLS_SSL_DEBUG_ECP( level, text, X ) \
Manuel Pégourié-Gonnard2ff873c2015-05-19 14:38:09 +020064 mbedtls_debug_print_ecp( ssl, level, __FILE__, __LINE__, text, X )
Paul Bakkered27a042013-04-18 22:46:23 +020065#endif
Paul Bakker41c83d32013-03-20 14:39:14 +010066
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020067#if defined(MBEDTLS_X509_CRT_PARSE_C)
Hanno Becker02a21932019-06-10 15:08:43 +010068#if !defined(MBEDTLS_X509_REMOVE_INFO)
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020069#define MBEDTLS_SSL_DEBUG_CRT( level, text, crt ) \
Manuel Pégourié-Gonnard2ff873c2015-05-19 14:38:09 +020070 mbedtls_debug_print_crt( ssl, level, __FILE__, __LINE__, text, crt )
Peter Kolbusdc470ae2018-12-11 13:55:56 -060071#else
72#define MBEDTLS_SSL_DEBUG_CRT( level, text, crt ) do { } while( 0 )
Hanno Becker02a21932019-06-10 15:08:43 +010073#endif /* !MBEDTLS_X509_REMOVE_INFO */
Peter Kolbusdc470ae2018-12-11 13:55:56 -060074#endif /* MBEDTLS_X509_CRT_PARSE_C */
Paul Bakker5121ce52009-01-03 21:22:43 +000075
Janos Follath948f4be2018-08-22 01:37:55 +010076#if defined(MBEDTLS_ECDH_C)
77#define MBEDTLS_SSL_DEBUG_ECDH( level, ecdh, attr ) \
78 mbedtls_debug_printf_ecdh( ssl, level, __FILE__, __LINE__, ecdh, attr )
79#endif
80
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020081#else /* MBEDTLS_DEBUG_C */
Paul Bakker5121ce52009-01-03 21:22:43 +000082
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020083#define MBEDTLS_SSL_DEBUG_MSG( level, args ) do { } while( 0 )
84#define MBEDTLS_SSL_DEBUG_RET( level, text, ret ) do { } while( 0 )
85#define MBEDTLS_SSL_DEBUG_BUF( level, text, buf, len ) do { } while( 0 )
86#define MBEDTLS_SSL_DEBUG_MPI( level, text, X ) do { } while( 0 )
87#define MBEDTLS_SSL_DEBUG_ECP( level, text, X ) do { } while( 0 )
88#define MBEDTLS_SSL_DEBUG_CRT( level, text, crt ) do { } while( 0 )
Janos Follath948f4be2018-08-22 01:37:55 +010089#define MBEDTLS_SSL_DEBUG_ECDH( level, ecdh, attr ) do { } while( 0 )
Paul Bakker5121ce52009-01-03 21:22:43 +000090
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020091#endif /* MBEDTLS_DEBUG_C */
Paul Bakker5121ce52009-01-03 21:22:43 +000092
93#ifdef __cplusplus
94extern "C" {
95#endif
96
Paul Bakkerc73079a2014-04-25 16:34:30 +020097/**
Simon Butcher7ef5cf32016-02-13 22:20:04 +000098 * \brief Set the threshold error level to handle globally all debug output.
99 * Debug messages that have a level over the threshold value are
100 * discarded.
101 * (Default value: 0 = No debug )
Paul Bakkerc73079a2014-04-25 16:34:30 +0200102 *
Simon Butcher7ef5cf32016-02-13 22:20:04 +0000103 * \param threshold theshold level of messages to filter on. Messages at a
104 * higher level will be discarded.
105 * - Debug levels
106 * - 0 No debug
107 * - 1 Error
108 * - 2 State change
109 * - 3 Informational
110 * - 4 Verbose
Paul Bakkerc73079a2014-04-25 16:34:30 +0200111 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200112void mbedtls_debug_set_threshold( int threshold );
Paul Bakkerc73079a2014-04-25 16:34:30 +0200113
Simon Butcher7ef5cf32016-02-13 22:20:04 +0000114/**
Janos Follathd75b7822016-03-18 16:28:20 +0000115 * \brief Print a message to the debug output. This function is always used
Simon Butcher7ef5cf32016-02-13 22:20:04 +0000116 * through the MBEDTLS_SSL_DEBUG_MSG() macro, which supplies the ssl
117 * context, file and line number parameters.
118 *
119 * \param ssl SSL context
120 * \param level error level of the debug message
121 * \param file file the message has occurred in
122 * \param line line number the message has occurred at
123 * \param format format specifier, in printf format
124 * \param ... variables used by the format specifier
125 *
126 * \attention This function is intended for INTERNAL usage within the
127 * library only.
128 */
Manuel Pégourié-Gonnarda16e7c42015-06-29 20:14:19 +0200129void mbedtls_debug_print_msg( const mbedtls_ssl_context *ssl, int level,
Manuel Pégourié-Gonnardb74c2452015-06-29 20:08:23 +0200130 const char *file, int line,
131 const char *format, ... );
Manuel Pégourié-Gonnardd23f5932015-06-23 12:04:52 +0200132
Simon Butcher7ef5cf32016-02-13 22:20:04 +0000133/**
134 * \brief Print the return value of a function to the debug output. This
135 * function is always used through the MBEDTLS_SSL_DEBUG_RET() macro,
136 * which supplies the ssl 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 error has occurred in
141 * \param line line number the error has occurred in
142 * \param text the name of the function that returned the error
143 * \param ret the return code value
144 *
145 * \attention This function is intended for INTERNAL usage within the
146 * library only.
147 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200148void mbedtls_debug_print_ret( const mbedtls_ssl_context *ssl, int level,
Paul Bakkerff60ee62010-03-16 21:09:09 +0000149 const char *file, int line,
150 const char *text, int ret );
Paul Bakker5121ce52009-01-03 21:22:43 +0000151
Simon Butcher7ef5cf32016-02-13 22:20:04 +0000152/**
153 * \brief Output a buffer of size len bytes to the debug output. This function
154 * is always used through the MBEDTLS_SSL_DEBUG_BUF() 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 a name or label for the buffer being dumped. Normally the
162 * variable or buffer name
163 * \param buf the buffer to be outputted
164 * \param len length of the buffer
165 *
166 * \attention This function is intended for INTERNAL usage within the
167 * library only.
168 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200169void mbedtls_debug_print_buf( const mbedtls_ssl_context *ssl, int level,
Paul Bakkerff60ee62010-03-16 21:09:09 +0000170 const char *file, int line, const char *text,
Manuel Pégourié-Gonnarda78b2182015-03-19 17:16:11 +0000171 const unsigned char *buf, size_t len );
Paul Bakker5121ce52009-01-03 21:22:43 +0000172
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200173#if defined(MBEDTLS_BIGNUM_C)
Simon Butcher7ef5cf32016-02-13 22:20:04 +0000174/**
175 * \brief Print a MPI variable to the debug output. This function is always
176 * used through the MBEDTLS_SSL_DEBUG_MPI() macro, which supplies the
177 * ssl context, file and line number parameters.
178 *
179 * \param ssl SSL context
180 * \param level error level of the debug message
181 * \param file file the error has occurred in
182 * \param line line number the error has occurred in
183 * \param text a name or label for the MPI being output. Normally the
184 * variable name
185 * \param X the MPI variable
186 *
187 * \attention This function is intended for INTERNAL usage within the
188 * library only.
189 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200190void mbedtls_debug_print_mpi( const mbedtls_ssl_context *ssl, int level,
Paul Bakkerff60ee62010-03-16 21:09:09 +0000191 const char *file, int line,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200192 const char *text, const mbedtls_mpi *X );
Paul Bakkered27a042013-04-18 22:46:23 +0200193#endif
Paul Bakker5121ce52009-01-03 21:22:43 +0000194
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200195#if defined(MBEDTLS_ECP_C)
Simon Butcher7ef5cf32016-02-13 22:20:04 +0000196/**
197 * \brief Print an ECP point to the debug output. This function is always
198 * used through the MBEDTLS_SSL_DEBUG_ECP() macro, which supplies the
199 * ssl context, file and line number parameters.
200 *
201 * \param ssl SSL context
202 * \param level error level of the debug message
203 * \param file file the error has occurred in
204 * \param line line number the error has occurred in
205 * \param text a name or label for the ECP point being output. Normally the
206 * variable name
207 * \param X the ECP point
208 *
209 * \attention This function is intended for INTERNAL usage within the
210 * library only.
211 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200212void mbedtls_debug_print_ecp( const mbedtls_ssl_context *ssl, int level,
Paul Bakker41c83d32013-03-20 14:39:14 +0100213 const char *file, int line,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200214 const char *text, const mbedtls_ecp_point *X );
Paul Bakker41c83d32013-03-20 14:39:14 +0100215#endif
216
Hanno Becker02a21932019-06-10 15:08:43 +0100217#if defined(MBEDTLS_X509_CRT_PARSE_C) && !defined(MBEDTLS_X509_REMOVE_INFO)
Simon Butcher7ef5cf32016-02-13 22:20:04 +0000218/**
219 * \brief Print a X.509 certificate structure to the debug output. This
220 * function is always used through the MBEDTLS_SSL_DEBUG_CRT() macro,
221 * which supplies the ssl context, file and line number parameters.
222 *
223 * \param ssl SSL context
224 * \param level error level of the debug message
225 * \param file file the error has occurred in
226 * \param line line number the error has occurred in
227 * \param text a name or label for the certificate being output
228 * \param crt X.509 certificate structure
229 *
230 * \attention This function is intended for INTERNAL usage within the
231 * library only.
232 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200233void mbedtls_debug_print_crt( const mbedtls_ssl_context *ssl, int level,
Paul Bakkerff60ee62010-03-16 21:09:09 +0000234 const char *file, int line,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200235 const char *text, const mbedtls_x509_crt *crt );
Paul Bakkered27a042013-04-18 22:46:23 +0200236#endif
Paul Bakker5121ce52009-01-03 21:22:43 +0000237
Janos Follath948f4be2018-08-22 01:37:55 +0100238#if defined(MBEDTLS_ECDH_C)
239typedef enum
240{
241 MBEDTLS_DEBUG_ECDH_Q,
242 MBEDTLS_DEBUG_ECDH_QP,
243 MBEDTLS_DEBUG_ECDH_Z,
244} mbedtls_debug_ecdh_attr;
245
246/**
247 * \brief Print a field of the ECDH structure in the SSL context to the debug
248 * output. This function is always used through the
249 * MBEDTLS_SSL_DEBUG_ECDH() macro, which supplies the ssl context, file
250 * and line number parameters.
251 *
252 * \param ssl SSL context
253 * \param level error level of the debug message
254 * \param file file the error has occurred in
255 * \param line line number the error has occurred in
256 * \param ecdh the ECDH context
257 * \param attr the identifier of the attribute being output
258 *
259 * \attention This function is intended for INTERNAL usage within the
260 * library only.
261 */
262void mbedtls_debug_printf_ecdh( const mbedtls_ssl_context *ssl, int level,
263 const char *file, int line,
264 const mbedtls_ecdh_context *ecdh,
265 mbedtls_debug_ecdh_attr attr );
266#endif
267
Paul Bakker5121ce52009-01-03 21:22:43 +0000268#ifdef __cplusplus
269}
270#endif
271
272#endif /* debug.h */