Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | Download | RSS feed

  1. /**
  2.  * \file debug.h
  3.  *
  4.  * \brief Functions for controlling and providing debug output from the library.
  5.  */
  6. /*
  7.  *  Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
  8.  *  SPDX-License-Identifier: GPL-2.0
  9.  *
  10.  *  This program is free software; you can redistribute it and/or modify
  11.  *  it under the terms of the GNU General Public License as published by
  12.  *  the Free Software Foundation; either version 2 of the License, or
  13.  *  (at your option) any later version.
  14.  *
  15.  *  This program is distributed in the hope that it will be useful,
  16.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  17.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  18.  *  GNU General Public License for more details.
  19.  *
  20.  *  You should have received a copy of the GNU General Public License along
  21.  *  with this program; if not, write to the Free Software Foundation, Inc.,
  22.  *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  23.  *
  24.  *  This file is part of mbed TLS (https://tls.mbed.org)
  25.  */
  26. #ifndef MBEDTLS_DEBUG_H
  27. #define MBEDTLS_DEBUG_H
  28.  
  29. #if !defined(MBEDTLS_CONFIG_FILE)
  30. #include "config.h"
  31. #else
  32. #include MBEDTLS_CONFIG_FILE
  33. #endif
  34.  
  35. #include "ssl.h"
  36.  
  37. #if defined(MBEDTLS_ECP_C)
  38. #include "ecp.h"
  39. #endif
  40.  
  41. #if defined(MBEDTLS_DEBUG_C)
  42.  
  43. #define MBEDTLS_DEBUG_STRIP_PARENS( ... )   __VA_ARGS__
  44.  
  45. #define MBEDTLS_SSL_DEBUG_MSG( level, args )                    \
  46.     mbedtls_debug_print_msg( ssl, level, __FILE__, __LINE__,    \
  47.                              MBEDTLS_DEBUG_STRIP_PARENS args )
  48.  
  49. #define MBEDTLS_SSL_DEBUG_RET( level, text, ret )                \
  50.     mbedtls_debug_print_ret( ssl, level, __FILE__, __LINE__, text, ret )
  51.  
  52. #define MBEDTLS_SSL_DEBUG_BUF( level, text, buf, len )           \
  53.     mbedtls_debug_print_buf( ssl, level, __FILE__, __LINE__, text, buf, len )
  54.  
  55. #if defined(MBEDTLS_BIGNUM_C)
  56. #define MBEDTLS_SSL_DEBUG_MPI( level, text, X )                  \
  57.     mbedtls_debug_print_mpi( ssl, level, __FILE__, __LINE__, text, X )
  58. #endif
  59.  
  60. #if defined(MBEDTLS_ECP_C)
  61. #define MBEDTLS_SSL_DEBUG_ECP( level, text, X )                  \
  62.     mbedtls_debug_print_ecp( ssl, level, __FILE__, __LINE__, text, X )
  63. #endif
  64.  
  65. #if defined(MBEDTLS_X509_CRT_PARSE_C)
  66. #define MBEDTLS_SSL_DEBUG_CRT( level, text, crt )                \
  67.     mbedtls_debug_print_crt( ssl, level, __FILE__, __LINE__, text, crt )
  68. #endif
  69.  
  70. #if defined(MBEDTLS_ECDH_C)
  71. #define MBEDTLS_SSL_DEBUG_ECDH( level, ecdh, attr )               \
  72.     mbedtls_debug_printf_ecdh( ssl, level, __FILE__, __LINE__, ecdh, attr )
  73. #endif
  74.  
  75. #else /* MBEDTLS_DEBUG_C */
  76.  
  77. #define MBEDTLS_SSL_DEBUG_MSG( level, args )            do { } while( 0 )
  78. #define MBEDTLS_SSL_DEBUG_RET( level, text, ret )       do { } while( 0 )
  79. #define MBEDTLS_SSL_DEBUG_BUF( level, text, buf, len )  do { } while( 0 )
  80. #define MBEDTLS_SSL_DEBUG_MPI( level, text, X )         do { } while( 0 )
  81. #define MBEDTLS_SSL_DEBUG_ECP( level, text, X )         do { } while( 0 )
  82. #define MBEDTLS_SSL_DEBUG_CRT( level, text, crt )       do { } while( 0 )
  83. #define MBEDTLS_SSL_DEBUG_ECDH( level, ecdh, attr )     do { } while( 0 )
  84.  
  85. #endif /* MBEDTLS_DEBUG_C */
  86.  
  87. #ifdef __cplusplus
  88. extern "C" {
  89. #endif
  90.  
  91. /**
  92.  * \brief   Set the threshold error level to handle globally all debug output.
  93.  *          Debug messages that have a level over the threshold value are
  94.  *          discarded.
  95.  *          (Default value: 0 = No debug )
  96.  *
  97.  * \param threshold     theshold level of messages to filter on. Messages at a
  98.  *                      higher level will be discarded.
  99.  *                          - Debug levels
  100.  *                              - 0 No debug
  101.  *                              - 1 Error
  102.  *                              - 2 State change
  103.  *                              - 3 Informational
  104.  *                              - 4 Verbose
  105.  */
  106. void mbedtls_debug_set_threshold( int threshold );
  107.  
  108. /**
  109.  * \brief    Print a message to the debug output. This function is always used
  110.  *          through the MBEDTLS_SSL_DEBUG_MSG() macro, which supplies the ssl
  111.  *          context, file and line number parameters.
  112.  *
  113.  * \param ssl       SSL context
  114.  * \param level     error level of the debug message
  115.  * \param file      file the message has occurred in
  116.  * \param line      line number the message has occurred at
  117.  * \param format    format specifier, in printf format
  118.  * \param ...       variables used by the format specifier
  119.  *
  120.  * \attention       This function is intended for INTERNAL usage within the
  121.  *                  library only.
  122.  */
  123. void mbedtls_debug_print_msg( const mbedtls_ssl_context *ssl, int level,
  124.                               const char *file, int line,
  125.                               const char *format, ... );
  126.  
  127. /**
  128.  * \brief   Print the return value of a function to the debug output. This
  129.  *          function is always used through the MBEDTLS_SSL_DEBUG_RET() macro,
  130.  *          which supplies the ssl context, file and line number parameters.
  131.  *
  132.  * \param ssl       SSL context
  133.  * \param level     error level of the debug message
  134.  * \param file      file the error has occurred in
  135.  * \param line      line number the error has occurred in
  136.  * \param text      the name of the function that returned the error
  137.  * \param ret       the return code value
  138.  *
  139.  * \attention       This function is intended for INTERNAL usage within the
  140.  *                  library only.
  141.  */
  142. void mbedtls_debug_print_ret( const mbedtls_ssl_context *ssl, int level,
  143.                       const char *file, int line,
  144.                       const char *text, int ret );
  145.  
  146. /**
  147.  * \brief   Output a buffer of size len bytes to the debug output. This function
  148.  *          is always used through the MBEDTLS_SSL_DEBUG_BUF() macro,
  149.  *          which supplies the ssl context, file and line number parameters.
  150.  *
  151.  * \param ssl       SSL context
  152.  * \param level     error level of the debug message
  153.  * \param file      file the error has occurred in
  154.  * \param line      line number the error has occurred in
  155.  * \param text      a name or label for the buffer being dumped. Normally the
  156.  *                  variable or buffer name
  157.  * \param buf       the buffer to be outputted
  158.  * \param len       length of the buffer
  159.  *
  160.  * \attention       This function is intended for INTERNAL usage within the
  161.  *                  library only.
  162.  */
  163. void mbedtls_debug_print_buf( const mbedtls_ssl_context *ssl, int level,
  164.                       const char *file, int line, const char *text,
  165.                       const unsigned char *buf, size_t len );
  166.  
  167. #if defined(MBEDTLS_BIGNUM_C)
  168. /**
  169.  * \brief   Print a MPI variable to the debug output. This function is always
  170.  *          used through the MBEDTLS_SSL_DEBUG_MPI() macro, which supplies the
  171.  *          ssl context, file and line number parameters.
  172.  *
  173.  * \param ssl       SSL context
  174.  * \param level     error level of the debug message
  175.  * \param file      file the error has occurred in
  176.  * \param line      line number the error has occurred in
  177.  * \param text      a name or label for the MPI being output. Normally the
  178.  *                  variable name
  179.  * \param X         the MPI variable
  180.  *
  181.  * \attention       This function is intended for INTERNAL usage within the
  182.  *                  library only.
  183.  */
  184. void mbedtls_debug_print_mpi( const mbedtls_ssl_context *ssl, int level,
  185.                       const char *file, int line,
  186.                       const char *text, const mbedtls_mpi *X );
  187. #endif
  188.  
  189. #if defined(MBEDTLS_ECP_C)
  190. /**
  191.  * \brief   Print an ECP point to the debug output. This function is always
  192.  *          used through the MBEDTLS_SSL_DEBUG_ECP() macro, which supplies the
  193.  *          ssl context, file and line number parameters.
  194.  *
  195.  * \param ssl       SSL context
  196.  * \param level     error level of the debug message
  197.  * \param file      file the error has occurred in
  198.  * \param line      line number the error has occurred in
  199.  * \param text      a name or label for the ECP point being output. Normally the
  200.  *                  variable name
  201.  * \param X         the ECP point
  202.  *
  203.  * \attention       This function is intended for INTERNAL usage within the
  204.  *                  library only.
  205.  */
  206. void mbedtls_debug_print_ecp( const mbedtls_ssl_context *ssl, int level,
  207.                       const char *file, int line,
  208.                       const char *text, const mbedtls_ecp_point *X );
  209. #endif
  210.  
  211. #if defined(MBEDTLS_X509_CRT_PARSE_C)
  212. /**
  213.  * \brief   Print a X.509 certificate structure to the debug output. This
  214.  *          function is always used through the MBEDTLS_SSL_DEBUG_CRT() macro,
  215.  *          which supplies the ssl context, file and line number parameters.
  216.  *
  217.  * \param ssl       SSL context
  218.  * \param level     error level of the debug message
  219.  * \param file      file the error has occurred in
  220.  * \param line      line number the error has occurred in
  221.  * \param text      a name or label for the certificate being output
  222.  * \param crt       X.509 certificate structure
  223.  *
  224.  * \attention       This function is intended for INTERNAL usage within the
  225.  *                  library only.
  226.  */
  227. void mbedtls_debug_print_crt( const mbedtls_ssl_context *ssl, int level,
  228.                       const char *file, int line,
  229.                       const char *text, const mbedtls_x509_crt *crt );
  230. #endif
  231.  
  232. #if defined(MBEDTLS_ECDH_C)
  233. typedef enum
  234. {
  235.     MBEDTLS_DEBUG_ECDH_Q,
  236.     MBEDTLS_DEBUG_ECDH_QP,
  237.     MBEDTLS_DEBUG_ECDH_Z,
  238. } mbedtls_debug_ecdh_attr;
  239.  
  240. /**
  241.  * \brief   Print a field of the ECDH structure in the SSL context to the debug
  242.  *          output. This function is always used through the
  243.  *          MBEDTLS_SSL_DEBUG_ECDH() macro, which supplies the ssl context, file
  244.  *          and line number parameters.
  245.  *
  246.  * \param ssl       SSL context
  247.  * \param level     error level of the debug message
  248.  * \param file      file the error has occurred in
  249.  * \param line      line number the error has occurred in
  250.  * \param ecdh      the ECDH context
  251.  * \param attr      the identifier of the attribute being output
  252.  *
  253.  * \attention       This function is intended for INTERNAL usage within the
  254.  *                  library only.
  255.  */
  256. void mbedtls_debug_printf_ecdh( const mbedtls_ssl_context *ssl, int level,
  257.                                 const char *file, int line,
  258.                                 const mbedtls_ecdh_context *ecdh,
  259.                                 mbedtls_debug_ecdh_attr attr );
  260. #endif
  261.  
  262. #ifdef __cplusplus
  263. }
  264. #endif
  265.  
  266. #endif /* debug.h */
  267.  
  268.