debug_internal.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. /**
  2. * \file debug_internal.h
  3. *
  4. * \brief Internal part of the public "debug.h".
  5. */
  6. /*
  7. * Copyright The Mbed TLS Contributors
  8. * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
  9. */
  10. #ifndef MBEDTLS_DEBUG_INTERNAL_H
  11. #define MBEDTLS_DEBUG_INTERNAL_H
  12. #include "mbedtls/debug.h"
  13. /**
  14. * \brief Print a message to the debug output. This function is always used
  15. * through the MBEDTLS_SSL_DEBUG_MSG() macro, which supplies the ssl
  16. * context, file and line number parameters.
  17. *
  18. * \param ssl SSL context
  19. * \param level error level of the debug message
  20. * \param file file the message has occurred in
  21. * \param line line number the message has occurred at
  22. * \param format format specifier, in printf format
  23. * \param ... variables used by the format specifier
  24. *
  25. * \attention This function is intended for INTERNAL usage within the
  26. * library only.
  27. */
  28. void mbedtls_debug_print_msg(const mbedtls_ssl_context *ssl, int level,
  29. const char *file, int line,
  30. const char *format, ...) MBEDTLS_PRINTF_ATTRIBUTE(5, 6);
  31. /**
  32. * \brief Print the return value of a function to the debug output. This
  33. * function is always used through the MBEDTLS_SSL_DEBUG_RET() macro,
  34. * which supplies the ssl context, file and line number parameters.
  35. *
  36. * \param ssl SSL context
  37. * \param level error level of the debug message
  38. * \param file file the error has occurred in
  39. * \param line line number the error has occurred in
  40. * \param text the name of the function that returned the error
  41. * \param ret the return code value
  42. *
  43. * \attention This function is intended for INTERNAL usage within the
  44. * library only.
  45. */
  46. void mbedtls_debug_print_ret(const mbedtls_ssl_context *ssl, int level,
  47. const char *file, int line,
  48. const char *text, int ret);
  49. /**
  50. * \brief Output a buffer of size len bytes to the debug output. This function
  51. * is always used through the MBEDTLS_SSL_DEBUG_BUF() macro,
  52. * which supplies the ssl context, file and line number parameters.
  53. *
  54. * \param ssl SSL context
  55. * \param level error level of the debug message
  56. * \param file file the error has occurred in
  57. * \param line line number the error has occurred in
  58. * \param text a name or label for the buffer being dumped. Normally the
  59. * variable or buffer name
  60. * \param buf the buffer to be outputted
  61. * \param len length of the buffer
  62. *
  63. * \attention This function is intended for INTERNAL usage within the
  64. * library only.
  65. */
  66. void mbedtls_debug_print_buf(const mbedtls_ssl_context *ssl, int level,
  67. const char *file, int line, const char *text,
  68. const unsigned char *buf, size_t len);
  69. #if defined(MBEDTLS_BIGNUM_C)
  70. /**
  71. * \brief Print a MPI variable to the debug output. This function is always
  72. * used through the MBEDTLS_SSL_DEBUG_MPI() macro, which supplies the
  73. * ssl context, file and line number parameters.
  74. *
  75. * \param ssl SSL context
  76. * \param level error level of the debug message
  77. * \param file file the error has occurred in
  78. * \param line line number the error has occurred in
  79. * \param text a name or label for the MPI being output. Normally the
  80. * variable name
  81. * \param X the MPI variable
  82. *
  83. * \attention This function is intended for INTERNAL usage within the
  84. * library only.
  85. */
  86. void mbedtls_debug_print_mpi(const mbedtls_ssl_context *ssl, int level,
  87. const char *file, int line,
  88. const char *text, const mbedtls_mpi *X);
  89. #endif
  90. #if defined(MBEDTLS_ECP_LIGHT)
  91. /**
  92. * \brief Print an ECP point to the debug output. This function is always
  93. * used through the MBEDTLS_SSL_DEBUG_ECP() macro, which supplies the
  94. * ssl context, file and line number parameters.
  95. *
  96. * \param ssl SSL context
  97. * \param level error level of the debug message
  98. * \param file file the error has occurred in
  99. * \param line line number the error has occurred in
  100. * \param text a name or label for the ECP point being output. Normally the
  101. * variable name
  102. * \param X the ECP point
  103. *
  104. * \attention This function is intended for INTERNAL usage within the
  105. * library only.
  106. */
  107. void mbedtls_debug_print_ecp(const mbedtls_ssl_context *ssl, int level,
  108. const char *file, int line,
  109. const char *text, const mbedtls_ecp_point *X);
  110. #endif
  111. #if defined(MBEDTLS_X509_CRT_PARSE_C) && !defined(MBEDTLS_X509_REMOVE_INFO)
  112. /**
  113. * \brief Print a X.509 certificate structure to the debug output. This
  114. * function is always used through the MBEDTLS_SSL_DEBUG_CRT() macro,
  115. * which supplies the ssl context, file and line number parameters.
  116. *
  117. * \param ssl SSL context
  118. * \param level error level of the debug message
  119. * \param file file the error has occurred in
  120. * \param line line number the error has occurred in
  121. * \param text a name or label for the certificate being output
  122. * \param crt X.509 certificate structure
  123. *
  124. * \attention This function is intended for INTERNAL usage within the
  125. * library only.
  126. */
  127. void mbedtls_debug_print_crt(const mbedtls_ssl_context *ssl, int level,
  128. const char *file, int line,
  129. const char *text, const mbedtls_x509_crt *crt);
  130. #endif
  131. /* Note: the MBEDTLS_ECDH_C guard here is mandatory because this debug function
  132. only works for the built-in implementation. */
  133. #if defined(MBEDTLS_KEY_EXCHANGE_SOME_ECDH_OR_ECDHE_ANY_ENABLED) && \
  134. defined(MBEDTLS_ECDH_C)
  135. typedef enum {
  136. MBEDTLS_DEBUG_ECDH_Q,
  137. MBEDTLS_DEBUG_ECDH_QP,
  138. MBEDTLS_DEBUG_ECDH_Z,
  139. } mbedtls_debug_ecdh_attr;
  140. /**
  141. * \brief Print a field of the ECDH structure in the SSL context to the debug
  142. * output. This function is always used through the
  143. * MBEDTLS_SSL_DEBUG_ECDH() macro, which supplies the ssl context, file
  144. * and line number parameters.
  145. *
  146. * \param ssl SSL context
  147. * \param level error level of the debug message
  148. * \param file file the error has occurred in
  149. * \param line line number the error has occurred in
  150. * \param ecdh the ECDH context
  151. * \param attr the identifier of the attribute being output
  152. *
  153. * \attention This function is intended for INTERNAL usage within the
  154. * library only.
  155. */
  156. void mbedtls_debug_printf_ecdh(const mbedtls_ssl_context *ssl, int level,
  157. const char *file, int line,
  158. const mbedtls_ecdh_context *ecdh,
  159. mbedtls_debug_ecdh_attr attr);
  160. #endif /* MBEDTLS_KEY_EXCHANGE_SOME_ECDH_OR_ECDHE_ANY_ENABLED &&
  161. MBEDTLS_ECDH_C */
  162. #endif /* MBEDTLS_DEBUG_INTERNAL_H */