blob: ce2c274e9b51b7661208914cb3d37c4fe8282868 [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)
Jaeden Amero6609aef2019-07-04 20:01:14 +010028#include "mbedtls/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
Jaeden Amero6609aef2019-07-04 20:01:14 +010033#include "mbedtls/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)
Jaeden Amero6609aef2019-07-04 20:01:14 +010036#include "mbedtls/ecp.h"
Paul Bakker41c83d32013-03-20 14:39:14 +010037#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
Janos Follath948f4be2018-08-22 01:37:55 +010068#if defined(MBEDTLS_ECDH_C)
69#define MBEDTLS_SSL_DEBUG_ECDH( level, ecdh, attr ) \
70 mbedtls_debug_printf_ecdh( ssl, level, __FILE__, __LINE__, ecdh, attr )
71#endif
72
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020073#else /* MBEDTLS_DEBUG_C */
Paul Bakker5121ce52009-01-03 21:22:43 +000074
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020075#define MBEDTLS_SSL_DEBUG_MSG( level, args ) do { } while( 0 )
76#define MBEDTLS_SSL_DEBUG_RET( level, text, ret ) do { } while( 0 )
77#define MBEDTLS_SSL_DEBUG_BUF( level, text, buf, len ) do { } while( 0 )
78#define MBEDTLS_SSL_DEBUG_MPI( level, text, X ) do { } while( 0 )
79#define MBEDTLS_SSL_DEBUG_ECP( level, text, X ) do { } while( 0 )
80#define MBEDTLS_SSL_DEBUG_CRT( level, text, crt ) do { } while( 0 )
Janos Follath948f4be2018-08-22 01:37:55 +010081#define MBEDTLS_SSL_DEBUG_ECDH( level, ecdh, attr ) do { } while( 0 )
Paul Bakker5121ce52009-01-03 21:22:43 +000082
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020083#endif /* MBEDTLS_DEBUG_C */
Paul Bakker5121ce52009-01-03 21:22:43 +000084
85#ifdef __cplusplus
86extern "C" {
87#endif
88
Paul Bakkerc73079a2014-04-25 16:34:30 +020089/**
Simon Butcher7ef5cf32016-02-13 22:20:04 +000090 * \brief Set the threshold error level to handle globally all debug output.
91 * Debug messages that have a level over the threshold value are
92 * discarded.
93 * (Default value: 0 = No debug )
Paul Bakkerc73079a2014-04-25 16:34:30 +020094 *
Simon Butcher7ef5cf32016-02-13 22:20:04 +000095 * \param threshold theshold level of messages to filter on. Messages at a
96 * higher level will be discarded.
97 * - Debug levels
98 * - 0 No debug
99 * - 1 Error
100 * - 2 State change
101 * - 3 Informational
102 * - 4 Verbose
Paul Bakkerc73079a2014-04-25 16:34:30 +0200103 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200104void mbedtls_debug_set_threshold( int threshold );
Paul Bakkerc73079a2014-04-25 16:34:30 +0200105
Simon Butcher7ef5cf32016-02-13 22:20:04 +0000106/**
Janos Follathd75b7822016-03-18 16:28:20 +0000107 * \brief Print a message to the debug output. This function is always used
Simon Butcher7ef5cf32016-02-13 22:20:04 +0000108 * through the MBEDTLS_SSL_DEBUG_MSG() macro, which supplies the ssl
109 * context, file and line number parameters.
110 *
111 * \param ssl SSL context
112 * \param level error level of the debug message
113 * \param file file the message has occurred in
114 * \param line line number the message has occurred at
115 * \param format format specifier, in printf format
116 * \param ... variables used by the format specifier
117 *
118 * \attention This function is intended for INTERNAL usage within the
119 * library only.
120 */
Manuel Pégourié-Gonnarda16e7c42015-06-29 20:14:19 +0200121void mbedtls_debug_print_msg( const mbedtls_ssl_context *ssl, int level,
Manuel Pégourié-Gonnardb74c2452015-06-29 20:08:23 +0200122 const char *file, int line,
123 const char *format, ... );
Manuel Pégourié-Gonnardd23f5932015-06-23 12:04:52 +0200124
Simon Butcher7ef5cf32016-02-13 22:20:04 +0000125/**
126 * \brief Print the return value of a function to the debug output. This
127 * function is always used through the MBEDTLS_SSL_DEBUG_RET() macro,
128 * which supplies the ssl context, file and line number parameters.
129 *
130 * \param ssl SSL context
131 * \param level error level of the debug message
132 * \param file file the error has occurred in
133 * \param line line number the error has occurred in
134 * \param text the name of the function that returned the error
135 * \param ret the return code value
136 *
137 * \attention This function is intended for INTERNAL usage within the
138 * library only.
139 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200140void mbedtls_debug_print_ret( const mbedtls_ssl_context *ssl, int level,
Paul Bakkerff60ee62010-03-16 21:09:09 +0000141 const char *file, int line,
142 const char *text, int ret );
Paul Bakker5121ce52009-01-03 21:22:43 +0000143
Simon Butcher7ef5cf32016-02-13 22:20:04 +0000144/**
145 * \brief Output a buffer of size len bytes to the debug output. This function
146 * is always used through the MBEDTLS_SSL_DEBUG_BUF() macro,
147 * which supplies the ssl context, file and line number parameters.
148 *
149 * \param ssl SSL context
150 * \param level error level of the debug message
151 * \param file file the error has occurred in
152 * \param line line number the error has occurred in
153 * \param text a name or label for the buffer being dumped. Normally the
154 * variable or buffer name
155 * \param buf the buffer to be outputted
156 * \param len length of the buffer
157 *
158 * \attention This function is intended for INTERNAL usage within the
159 * library only.
160 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200161void mbedtls_debug_print_buf( const mbedtls_ssl_context *ssl, int level,
Paul Bakkerff60ee62010-03-16 21:09:09 +0000162 const char *file, int line, const char *text,
Manuel Pégourié-Gonnarda78b2182015-03-19 17:16:11 +0000163 const unsigned char *buf, size_t len );
Paul Bakker5121ce52009-01-03 21:22:43 +0000164
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200165#if defined(MBEDTLS_BIGNUM_C)
Simon Butcher7ef5cf32016-02-13 22:20:04 +0000166/**
167 * \brief Print a MPI variable to the debug output. This function is always
168 * used through the MBEDTLS_SSL_DEBUG_MPI() macro, which supplies the
169 * ssl context, file and line number parameters.
170 *
171 * \param ssl SSL context
172 * \param level error level of the debug message
173 * \param file file the error has occurred in
174 * \param line line number the error has occurred in
175 * \param text a name or label for the MPI being output. Normally the
176 * variable name
177 * \param X the MPI variable
178 *
179 * \attention This function is intended for INTERNAL usage within the
180 * library only.
181 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200182void mbedtls_debug_print_mpi( const mbedtls_ssl_context *ssl, int level,
Paul Bakkerff60ee62010-03-16 21:09:09 +0000183 const char *file, int line,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200184 const char *text, const mbedtls_mpi *X );
Paul Bakkered27a042013-04-18 22:46:23 +0200185#endif
Paul Bakker5121ce52009-01-03 21:22:43 +0000186
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200187#if defined(MBEDTLS_ECP_C)
Simon Butcher7ef5cf32016-02-13 22:20:04 +0000188/**
189 * \brief Print an ECP point to the debug output. This function is always
190 * used through the MBEDTLS_SSL_DEBUG_ECP() macro, which supplies the
191 * ssl context, file and line number parameters.
192 *
193 * \param ssl SSL context
194 * \param level error level of the debug message
195 * \param file file the error has occurred in
196 * \param line line number the error has occurred in
197 * \param text a name or label for the ECP point being output. Normally the
198 * variable name
199 * \param X the ECP point
200 *
201 * \attention This function is intended for INTERNAL usage within the
202 * library only.
203 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200204void mbedtls_debug_print_ecp( const mbedtls_ssl_context *ssl, int level,
Paul Bakker41c83d32013-03-20 14:39:14 +0100205 const char *file, int line,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200206 const char *text, const mbedtls_ecp_point *X );
Paul Bakker41c83d32013-03-20 14:39:14 +0100207#endif
208
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200209#if defined(MBEDTLS_X509_CRT_PARSE_C)
Simon Butcher7ef5cf32016-02-13 22:20:04 +0000210/**
211 * \brief Print a X.509 certificate structure to the debug output. This
212 * function is always used through the MBEDTLS_SSL_DEBUG_CRT() macro,
213 * which supplies the ssl context, file and line number parameters.
214 *
215 * \param ssl SSL context
216 * \param level error level of the debug message
217 * \param file file the error has occurred in
218 * \param line line number the error has occurred in
219 * \param text a name or label for the certificate being output
220 * \param crt X.509 certificate structure
221 *
222 * \attention This function is intended for INTERNAL usage within the
223 * library only.
224 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200225void mbedtls_debug_print_crt( const mbedtls_ssl_context *ssl, int level,
Paul Bakkerff60ee62010-03-16 21:09:09 +0000226 const char *file, int line,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200227 const char *text, const mbedtls_x509_crt *crt );
Paul Bakkered27a042013-04-18 22:46:23 +0200228#endif
Paul Bakker5121ce52009-01-03 21:22:43 +0000229
Janos Follath948f4be2018-08-22 01:37:55 +0100230#if defined(MBEDTLS_ECDH_C)
231typedef enum
232{
233 MBEDTLS_DEBUG_ECDH_Q,
234 MBEDTLS_DEBUG_ECDH_QP,
235 MBEDTLS_DEBUG_ECDH_Z,
236} mbedtls_debug_ecdh_attr;
237
238/**
239 * \brief Print a field of the ECDH structure in the SSL context to the debug
240 * output. This function is always used through the
241 * MBEDTLS_SSL_DEBUG_ECDH() macro, which supplies the ssl context, file
242 * and line number parameters.
243 *
244 * \param ssl SSL context
245 * \param level error level of the debug message
246 * \param file file the error has occurred in
247 * \param line line number the error has occurred in
248 * \param ecdh the ECDH context
249 * \param attr the identifier of the attribute being output
250 *
251 * \attention This function is intended for INTERNAL usage within the
252 * library only.
253 */
254void mbedtls_debug_printf_ecdh( const mbedtls_ssl_context *ssl, int level,
255 const char *file, int line,
256 const mbedtls_ecdh_context *ecdh,
257 mbedtls_debug_ecdh_attr attr );
258#endif
259
Paul Bakker5121ce52009-01-03 21:22:43 +0000260#ifdef __cplusplus
261}
262#endif
263
264#endif /* debug.h */