blob: ef8db67ff1126d8b8a247e487e258c54fd5fab54 [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)
64#define MBEDTLS_SSL_DEBUG_CRT( level, text, crt ) \
Manuel Pégourié-Gonnard2ff873c2015-05-19 14:38:09 +020065 mbedtls_debug_print_crt( ssl, level, __FILE__, __LINE__, text, crt )
Paul Bakkered27a042013-04-18 22:46:23 +020066#endif
Paul Bakker5121ce52009-01-03 21:22:43 +000067
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020068#else /* MBEDTLS_DEBUG_C */
Paul Bakker5121ce52009-01-03 21:22:43 +000069
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020070#define MBEDTLS_SSL_DEBUG_MSG( level, args ) do { } while( 0 )
71#define MBEDTLS_SSL_DEBUG_RET( level, text, ret ) do { } while( 0 )
72#define MBEDTLS_SSL_DEBUG_BUF( level, text, buf, len ) do { } while( 0 )
73#define MBEDTLS_SSL_DEBUG_MPI( level, text, X ) do { } while( 0 )
74#define MBEDTLS_SSL_DEBUG_ECP( level, text, X ) do { } while( 0 )
75#define MBEDTLS_SSL_DEBUG_CRT( level, text, crt ) do { } while( 0 )
Paul Bakker5121ce52009-01-03 21:22:43 +000076
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020077#endif /* MBEDTLS_DEBUG_C */
Paul Bakker5121ce52009-01-03 21:22:43 +000078
79#ifdef __cplusplus
80extern "C" {
81#endif
82
Paul Bakkerc73079a2014-04-25 16:34:30 +020083/**
Simon Butcher7ef5cf32016-02-13 22:20:04 +000084 * \brief Set the threshold error level to handle globally all debug output.
85 * Debug messages that have a level over the threshold value are
86 * discarded.
87 * (Default value: 0 = No debug )
Paul Bakkerc73079a2014-04-25 16:34:30 +020088 *
Simon Butcher7ef5cf32016-02-13 22:20:04 +000089 * \param threshold theshold level of messages to filter on. Messages at a
90 * higher level will be discarded.
91 * - Debug levels
92 * - 0 No debug
93 * - 1 Error
94 * - 2 State change
95 * - 3 Informational
96 * - 4 Verbose
Paul Bakkerc73079a2014-04-25 16:34:30 +020097 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020098void mbedtls_debug_set_threshold( int threshold );
Paul Bakkerc73079a2014-04-25 16:34:30 +020099
Simon Butcher7ef5cf32016-02-13 22:20:04 +0000100/**
Janos Follathd75b7822016-03-18 16:28:20 +0000101 * \brief Print a message to the debug output. This function is always used
Simon Butcher7ef5cf32016-02-13 22:20:04 +0000102 * through the MBEDTLS_SSL_DEBUG_MSG() macro, which supplies the ssl
103 * context, file and line number parameters.
104 *
105 * \param ssl SSL context
106 * \param level error level of the debug message
107 * \param file file the message has occurred in
108 * \param line line number the message has occurred at
109 * \param format format specifier, in printf format
110 * \param ... variables used by the format specifier
111 *
112 * \attention This function is intended for INTERNAL usage within the
113 * library only.
114 */
Manuel Pégourié-Gonnarda16e7c42015-06-29 20:14:19 +0200115void mbedtls_debug_print_msg( const mbedtls_ssl_context *ssl, int level,
Manuel Pégourié-Gonnardb74c2452015-06-29 20:08:23 +0200116 const char *file, int line,
117 const char *format, ... );
Manuel Pégourié-Gonnardd23f5932015-06-23 12:04:52 +0200118
Simon Butcher7ef5cf32016-02-13 22:20:04 +0000119/**
120 * \brief Print the return value of a function to the debug output. This
121 * function is always used through the MBEDTLS_SSL_DEBUG_RET() 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 the name of the function that returned the error
129 * \param ret the return code value
130 *
131 * \attention This function is intended for INTERNAL usage within the
132 * library only.
133 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200134void mbedtls_debug_print_ret( const mbedtls_ssl_context *ssl, int level,
Paul Bakkerff60ee62010-03-16 21:09:09 +0000135 const char *file, int line,
136 const char *text, int ret );
Paul Bakker5121ce52009-01-03 21:22:43 +0000137
Simon Butcher7ef5cf32016-02-13 22:20:04 +0000138/**
139 * \brief Output a buffer of size len bytes to the debug output. This function
140 * is always used through the MBEDTLS_SSL_DEBUG_BUF() macro,
141 * which supplies the ssl context, file and line number parameters.
142 *
143 * \param ssl SSL context
144 * \param level error level of the debug message
145 * \param file file the error has occurred in
146 * \param line line number the error has occurred in
147 * \param text a name or label for the buffer being dumped. Normally the
148 * variable or buffer name
149 * \param buf the buffer to be outputted
150 * \param len length of the buffer
151 *
152 * \attention This function is intended for INTERNAL usage within the
153 * library only.
154 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200155void mbedtls_debug_print_buf( const mbedtls_ssl_context *ssl, int level,
Paul Bakkerff60ee62010-03-16 21:09:09 +0000156 const char *file, int line, const char *text,
Manuel Pégourié-Gonnarda78b2182015-03-19 17:16:11 +0000157 const unsigned char *buf, size_t len );
Paul Bakker5121ce52009-01-03 21:22:43 +0000158
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200159#if defined(MBEDTLS_BIGNUM_C)
Simon Butcher7ef5cf32016-02-13 22:20:04 +0000160/**
161 * \brief Print a MPI variable to the debug output. This function is always
162 * used through the MBEDTLS_SSL_DEBUG_MPI() macro, which supplies the
163 * ssl context, file and line number parameters.
164 *
165 * \param ssl SSL context
166 * \param level error level of the debug message
167 * \param file file the error has occurred in
168 * \param line line number the error has occurred in
169 * \param text a name or label for the MPI being output. Normally the
170 * variable name
171 * \param X the MPI variable
172 *
173 * \attention This function is intended for INTERNAL usage within the
174 * library only.
175 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200176void mbedtls_debug_print_mpi( const mbedtls_ssl_context *ssl, int level,
Paul Bakkerff60ee62010-03-16 21:09:09 +0000177 const char *file, int line,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200178 const char *text, const mbedtls_mpi *X );
Paul Bakkered27a042013-04-18 22:46:23 +0200179#endif
Paul Bakker5121ce52009-01-03 21:22:43 +0000180
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200181#if defined(MBEDTLS_ECP_C)
Simon Butcher7ef5cf32016-02-13 22:20:04 +0000182/**
183 * \brief Print an ECP point to the debug output. This function is always
184 * used through the MBEDTLS_SSL_DEBUG_ECP() macro, which supplies the
185 * ssl context, file and line number parameters.
186 *
187 * \param ssl SSL context
188 * \param level error level of the debug message
189 * \param file file the error has occurred in
190 * \param line line number the error has occurred in
191 * \param text a name or label for the ECP point being output. Normally the
192 * variable name
193 * \param X the ECP point
194 *
195 * \attention This function is intended for INTERNAL usage within the
196 * library only.
197 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200198void mbedtls_debug_print_ecp( const mbedtls_ssl_context *ssl, int level,
Paul Bakker41c83d32013-03-20 14:39:14 +0100199 const char *file, int line,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200200 const char *text, const mbedtls_ecp_point *X );
Paul Bakker41c83d32013-03-20 14:39:14 +0100201#endif
202
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200203#if defined(MBEDTLS_X509_CRT_PARSE_C)
Simon Butcher7ef5cf32016-02-13 22:20:04 +0000204/**
205 * \brief Print a X.509 certificate structure to the debug output. This
206 * function is always used through the MBEDTLS_SSL_DEBUG_CRT() macro,
207 * which supplies the ssl context, file and line number parameters.
208 *
209 * \param ssl SSL context
210 * \param level error level of the debug message
211 * \param file file the error has occurred in
212 * \param line line number the error has occurred in
213 * \param text a name or label for the certificate being output
214 * \param crt X.509 certificate structure
215 *
216 * \attention This function is intended for INTERNAL usage within the
217 * library only.
218 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200219void mbedtls_debug_print_crt( const mbedtls_ssl_context *ssl, int level,
Paul Bakkerff60ee62010-03-16 21:09:09 +0000220 const char *file, int line,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200221 const char *text, const mbedtls_x509_crt *crt );
Paul Bakkered27a042013-04-18 22:46:23 +0200222#endif
Paul Bakker5121ce52009-01-03 21:22:43 +0000223
224#ifdef __cplusplus
225}
226#endif
227
228#endif /* debug.h */
Simon Butcher7ef5cf32016-02-13 22:20:04 +0000229