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