blob: 3a7f3f5cf243423fb4b88d61de49efde00595a94 [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
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020039#if defined(MBEDTLS_DEBUG_C)
Paul Bakker5121ce52009-01-03 21:22:43 +000040
Manuel Pégourié-Gonnardb74c2452015-06-29 20:08:23 +020041#define MBEDTLS_DEBUG_STRIP_PARENS( ... ) __VA_ARGS__
42
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020043#define MBEDTLS_SSL_DEBUG_MSG( level, args ) \
Manuel Pégourié-Gonnarda16e7c42015-06-29 20:14:19 +020044 mbedtls_debug_print_msg( ssl, level, __FILE__, __LINE__, \
Manuel Pégourié-Gonnardb74c2452015-06-29 20:08:23 +020045 MBEDTLS_DEBUG_STRIP_PARENS args )
Paul Bakker5121ce52009-01-03 21:22:43 +000046
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020047#define MBEDTLS_SSL_DEBUG_RET( level, text, ret ) \
Manuel Pégourié-Gonnard2ff873c2015-05-19 14:38:09 +020048 mbedtls_debug_print_ret( ssl, level, __FILE__, __LINE__, text, ret )
Paul Bakker5121ce52009-01-03 21:22:43 +000049
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020050#define MBEDTLS_SSL_DEBUG_BUF( level, text, buf, len ) \
Manuel Pégourié-Gonnard2ff873c2015-05-19 14:38:09 +020051 mbedtls_debug_print_buf( ssl, level, __FILE__, __LINE__, text, buf, len )
Paul Bakker5121ce52009-01-03 21:22:43 +000052
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020053#if defined(MBEDTLS_BIGNUM_C)
54#define MBEDTLS_SSL_DEBUG_MPI( level, text, X ) \
Manuel Pégourié-Gonnard2ff873c2015-05-19 14:38:09 +020055 mbedtls_debug_print_mpi( ssl, level, __FILE__, __LINE__, text, X )
Paul Bakkered27a042013-04-18 22:46:23 +020056#endif
Paul Bakker5121ce52009-01-03 21:22:43 +000057
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020058#if defined(MBEDTLS_ECP_C)
59#define MBEDTLS_SSL_DEBUG_ECP( level, text, X ) \
Manuel Pégourié-Gonnard2ff873c2015-05-19 14:38:09 +020060 mbedtls_debug_print_ecp( ssl, level, __FILE__, __LINE__, text, X )
Paul Bakkered27a042013-04-18 22:46:23 +020061#endif
Paul Bakker41c83d32013-03-20 14:39:14 +010062
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020063#if defined(MBEDTLS_X509_CRT_PARSE_C)
Peter Kolbusdc470ae2018-12-11 13:55:56 -060064#if defined(MBEDTLS_X509_INFO)
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020065#define MBEDTLS_SSL_DEBUG_CRT( level, text, crt ) \
Manuel Pégourié-Gonnard2ff873c2015-05-19 14:38:09 +020066 mbedtls_debug_print_crt( ssl, level, __FILE__, __LINE__, text, crt )
Peter Kolbusdc470ae2018-12-11 13:55:56 -060067#else
68#define MBEDTLS_SSL_DEBUG_CRT( level, text, crt ) do { } while( 0 )
69#endif /* MBEDTLS_X509_INFO */
70#endif /* MBEDTLS_X509_CRT_PARSE_C */
Paul Bakker5121ce52009-01-03 21:22:43 +000071
Janos Follath948f4be2018-08-22 01:37:55 +010072#if defined(MBEDTLS_ECDH_C)
73#define MBEDTLS_SSL_DEBUG_ECDH( level, ecdh, attr ) \
74 mbedtls_debug_printf_ecdh( ssl, level, __FILE__, __LINE__, ecdh, attr )
75#endif
76
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020077#else /* MBEDTLS_DEBUG_C */
Paul Bakker5121ce52009-01-03 21:22:43 +000078
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020079#define MBEDTLS_SSL_DEBUG_MSG( level, args ) do { } while( 0 )
80#define MBEDTLS_SSL_DEBUG_RET( level, text, ret ) do { } while( 0 )
81#define MBEDTLS_SSL_DEBUG_BUF( level, text, buf, len ) do { } while( 0 )
82#define MBEDTLS_SSL_DEBUG_MPI( level, text, X ) do { } while( 0 )
83#define MBEDTLS_SSL_DEBUG_ECP( level, text, X ) do { } while( 0 )
84#define MBEDTLS_SSL_DEBUG_CRT( level, text, crt ) do { } while( 0 )
Janos Follath948f4be2018-08-22 01:37:55 +010085#define MBEDTLS_SSL_DEBUG_ECDH( level, ecdh, attr ) do { } while( 0 )
Paul Bakker5121ce52009-01-03 21:22:43 +000086
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020087#endif /* MBEDTLS_DEBUG_C */
Paul Bakker5121ce52009-01-03 21:22:43 +000088
89#ifdef __cplusplus
90extern "C" {
91#endif
92
Paul Bakkerc73079a2014-04-25 16:34:30 +020093/**
Simon Butcher7ef5cf32016-02-13 22:20:04 +000094 * \brief Set the threshold error level to handle globally all debug output.
95 * Debug messages that have a level over the threshold value are
96 * discarded.
97 * (Default value: 0 = No debug )
Paul Bakkerc73079a2014-04-25 16:34:30 +020098 *
Simon Butcher7ef5cf32016-02-13 22:20:04 +000099 * \param threshold theshold level of messages to filter on. Messages at a
100 * higher level will be discarded.
101 * - Debug levels
102 * - 0 No debug
103 * - 1 Error
104 * - 2 State change
105 * - 3 Informational
106 * - 4 Verbose
Paul Bakkerc73079a2014-04-25 16:34:30 +0200107 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200108void mbedtls_debug_set_threshold( int threshold );
Paul Bakkerc73079a2014-04-25 16:34:30 +0200109
Simon Butcher7ef5cf32016-02-13 22:20:04 +0000110/**
Janos Follathd75b7822016-03-18 16:28:20 +0000111 * \brief Print a message to the debug output. This function is always used
Simon Butcher7ef5cf32016-02-13 22:20:04 +0000112 * through the MBEDTLS_SSL_DEBUG_MSG() macro, which supplies the ssl
113 * 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 message has occurred in
118 * \param line line number the message has occurred at
119 * \param format format specifier, in printf format
120 * \param ... variables used by the format specifier
121 *
122 * \attention This function is intended for INTERNAL usage within the
123 * library only.
124 */
Manuel Pégourié-Gonnarda16e7c42015-06-29 20:14:19 +0200125void mbedtls_debug_print_msg( const mbedtls_ssl_context *ssl, int level,
Manuel Pégourié-Gonnardb74c2452015-06-29 20:08:23 +0200126 const char *file, int line,
127 const char *format, ... );
Manuel Pégourié-Gonnardd23f5932015-06-23 12:04:52 +0200128
Simon Butcher7ef5cf32016-02-13 22:20:04 +0000129/**
130 * \brief Print the return value of a function to the debug output. This
131 * function is always used through the MBEDTLS_SSL_DEBUG_RET() macro,
132 * which supplies the ssl context, file and line number parameters.
133 *
134 * \param ssl SSL context
135 * \param level error level of the debug message
136 * \param file file the error has occurred in
137 * \param line line number the error has occurred in
138 * \param text the name of the function that returned the error
139 * \param ret the return code value
140 *
141 * \attention This function is intended for INTERNAL usage within the
142 * library only.
143 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200144void mbedtls_debug_print_ret( const mbedtls_ssl_context *ssl, int level,
Paul Bakkerff60ee62010-03-16 21:09:09 +0000145 const char *file, int line,
146 const char *text, int ret );
Paul Bakker5121ce52009-01-03 21:22:43 +0000147
Simon Butcher7ef5cf32016-02-13 22:20:04 +0000148/**
149 * \brief Output a buffer of size len bytes to the debug output. This function
150 * is always used through the MBEDTLS_SSL_DEBUG_BUF() macro,
151 * which supplies the ssl context, file and line number parameters.
152 *
153 * \param ssl SSL context
154 * \param level error level of the debug message
155 * \param file file the error has occurred in
156 * \param line line number the error has occurred in
157 * \param text a name or label for the buffer being dumped. Normally the
158 * variable or buffer name
159 * \param buf the buffer to be outputted
160 * \param len length of the buffer
161 *
162 * \attention This function is intended for INTERNAL usage within the
163 * library only.
164 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200165void mbedtls_debug_print_buf( const mbedtls_ssl_context *ssl, int level,
Paul Bakkerff60ee62010-03-16 21:09:09 +0000166 const char *file, int line, const char *text,
Manuel Pégourié-Gonnarda78b2182015-03-19 17:16:11 +0000167 const unsigned char *buf, size_t len );
Paul Bakker5121ce52009-01-03 21:22:43 +0000168
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200169#if defined(MBEDTLS_BIGNUM_C)
Simon Butcher7ef5cf32016-02-13 22:20:04 +0000170/**
171 * \brief Print a MPI variable to the debug output. This function is always
172 * used through the MBEDTLS_SSL_DEBUG_MPI() macro, which supplies the
173 * ssl context, file and line number parameters.
174 *
175 * \param ssl SSL context
176 * \param level error level of the debug message
177 * \param file file the error has occurred in
178 * \param line line number the error has occurred in
179 * \param text a name or label for the MPI being output. Normally the
180 * variable name
181 * \param X the MPI variable
182 *
183 * \attention This function is intended for INTERNAL usage within the
184 * library only.
185 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200186void mbedtls_debug_print_mpi( const mbedtls_ssl_context *ssl, int level,
Paul Bakkerff60ee62010-03-16 21:09:09 +0000187 const char *file, int line,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200188 const char *text, const mbedtls_mpi *X );
Paul Bakkered27a042013-04-18 22:46:23 +0200189#endif
Paul Bakker5121ce52009-01-03 21:22:43 +0000190
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200191#if defined(MBEDTLS_ECP_C)
Simon Butcher7ef5cf32016-02-13 22:20:04 +0000192/**
193 * \brief Print an ECP point to the debug output. This function is always
194 * used through the MBEDTLS_SSL_DEBUG_ECP() macro, which supplies the
195 * ssl context, file and line number parameters.
196 *
197 * \param ssl SSL context
198 * \param level error level of the debug message
199 * \param file file the error has occurred in
200 * \param line line number the error has occurred in
201 * \param text a name or label for the ECP point being output. Normally the
202 * variable name
203 * \param X the ECP point
204 *
205 * \attention This function is intended for INTERNAL usage within the
206 * library only.
207 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200208void mbedtls_debug_print_ecp( const mbedtls_ssl_context *ssl, int level,
Paul Bakker41c83d32013-03-20 14:39:14 +0100209 const char *file, int line,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200210 const char *text, const mbedtls_ecp_point *X );
Paul Bakker41c83d32013-03-20 14:39:14 +0100211#endif
212
Peter Kolbusdc470ae2018-12-11 13:55:56 -0600213#if defined(MBEDTLS_X509_CRT_PARSE_C) && defined(MBEDTLS_X509_INFO)
Simon Butcher7ef5cf32016-02-13 22:20:04 +0000214/**
215 * \brief Print a X.509 certificate structure to the debug output. This
216 * function is always used through the MBEDTLS_SSL_DEBUG_CRT() macro,
217 * which supplies the ssl context, file and line number parameters.
218 *
219 * \param ssl SSL context
220 * \param level error level of the debug message
221 * \param file file the error has occurred in
222 * \param line line number the error has occurred in
223 * \param text a name or label for the certificate being output
224 * \param crt X.509 certificate structure
225 *
226 * \attention This function is intended for INTERNAL usage within the
227 * library only.
228 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200229void mbedtls_debug_print_crt( const mbedtls_ssl_context *ssl, int level,
Paul Bakkerff60ee62010-03-16 21:09:09 +0000230 const char *file, int line,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200231 const char *text, const mbedtls_x509_crt *crt );
Paul Bakkered27a042013-04-18 22:46:23 +0200232#endif
Paul Bakker5121ce52009-01-03 21:22:43 +0000233
Janos Follath948f4be2018-08-22 01:37:55 +0100234#if defined(MBEDTLS_ECDH_C)
235typedef enum
236{
237 MBEDTLS_DEBUG_ECDH_Q,
238 MBEDTLS_DEBUG_ECDH_QP,
239 MBEDTLS_DEBUG_ECDH_Z,
240} mbedtls_debug_ecdh_attr;
241
242/**
243 * \brief Print a field of the ECDH structure in the SSL context to the debug
244 * output. This function is always used through the
245 * MBEDTLS_SSL_DEBUG_ECDH() macro, which supplies the ssl context, file
246 * and line number parameters.
247 *
248 * \param ssl SSL context
249 * \param level error level of the debug message
250 * \param file file the error has occurred in
251 * \param line line number the error has occurred in
252 * \param ecdh the ECDH context
253 * \param attr the identifier of the attribute being output
254 *
255 * \attention This function is intended for INTERNAL usage within the
256 * library only.
257 */
258void mbedtls_debug_printf_ecdh( const mbedtls_ssl_context *ssl, int level,
259 const char *file, int line,
260 const mbedtls_ecdh_context *ecdh,
261 mbedtls_debug_ecdh_attr attr );
262#endif
263
Paul Bakker5121ce52009-01-03 21:22:43 +0000264#ifdef __cplusplus
265}
266#endif
267
268#endif /* debug.h */