blob: 12559afe345a3716195e2c9f6b369011e94f329e [file] [log] [blame]
Jens Wiklander817466c2018-05-22 13:49:31 +02001/*
2 * Debugging routines
3 *
Jerome Forissier79013242021-07-28 10:24:04 +02004 * Copyright The Mbed TLS Contributors
5 * SPDX-License-Identifier: Apache-2.0
Jens Wiklander817466c2018-05-22 13:49:31 +02006 *
7 * Licensed under the Apache License, Version 2.0 (the "License"); you may
8 * not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
15 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
Jens Wiklander817466c2018-05-22 13:49:31 +020018 */
19
Jerome Forissier79013242021-07-28 10:24:04 +020020#include "common.h"
Jens Wiklander817466c2018-05-22 13:49:31 +020021
22#if defined(MBEDTLS_DEBUG_C)
23
Jens Wiklander817466c2018-05-22 13:49:31 +020024#include "mbedtls/platform.h"
Jens Wiklander817466c2018-05-22 13:49:31 +020025
26#include "mbedtls/debug.h"
Jerome Forissier11fa71b2020-04-20 17:17:56 +020027#include "mbedtls/error.h"
Jens Wiklander817466c2018-05-22 13:49:31 +020028
29#include <stdarg.h>
30#include <stdio.h>
31#include <string.h>
32
Jens Wiklander817466c2018-05-22 13:49:31 +020033#define DEBUG_BUF_SIZE 512
34
35static int debug_threshold = 0;
36
Jens Wiklander32b31802023-10-06 16:59:46 +020037void mbedtls_debug_set_threshold(int threshold)
Jens Wiklander817466c2018-05-22 13:49:31 +020038{
39 debug_threshold = threshold;
40}
41
42/*
43 * All calls to f_dbg must be made via this function
44 */
Jens Wiklander32b31802023-10-06 16:59:46 +020045static inline void debug_send_line(const mbedtls_ssl_context *ssl, int level,
46 const char *file, int line,
47 const char *str)
Jens Wiklander817466c2018-05-22 13:49:31 +020048{
49 /*
50 * If in a threaded environment, we need a thread identifier.
51 * Since there is no portable way to get one, use the address of the ssl
52 * context instead, as it shouldn't be shared between threads.
53 */
54#if defined(MBEDTLS_THREADING_C)
55 char idstr[20 + DEBUG_BUF_SIZE]; /* 0x + 16 nibbles + ': ' */
Jens Wiklander32b31802023-10-06 16:59:46 +020056 mbedtls_snprintf(idstr, sizeof(idstr), "%p: %s", (void *) ssl, str);
57 ssl->conf->f_dbg(ssl->conf->p_dbg, level, file, line, idstr);
Jens Wiklander817466c2018-05-22 13:49:31 +020058#else
Jens Wiklander32b31802023-10-06 16:59:46 +020059 ssl->conf->f_dbg(ssl->conf->p_dbg, level, file, line, str);
Jens Wiklander817466c2018-05-22 13:49:31 +020060#endif
61}
62
Jerome Forissier79013242021-07-28 10:24:04 +020063MBEDTLS_PRINTF_ATTRIBUTE(5, 6)
Jens Wiklander32b31802023-10-06 16:59:46 +020064void mbedtls_debug_print_msg(const mbedtls_ssl_context *ssl, int level,
65 const char *file, int line,
66 const char *format, ...)
Jens Wiklander817466c2018-05-22 13:49:31 +020067{
68 va_list argp;
69 char str[DEBUG_BUF_SIZE];
Jerome Forissier11fa71b2020-04-20 17:17:56 +020070 int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
Jens Wiklander817466c2018-05-22 13:49:31 +020071
Jens Wiklander32b31802023-10-06 16:59:46 +020072 if (NULL == ssl ||
Jerome Forissier5b25c762020-04-07 11:18:49 +020073 NULL == ssl->conf ||
74 NULL == ssl->conf->f_dbg ||
Jens Wiklander32b31802023-10-06 16:59:46 +020075 level > debug_threshold) {
Jens Wiklander817466c2018-05-22 13:49:31 +020076 return;
Jerome Forissier5b25c762020-04-07 11:18:49 +020077 }
Jens Wiklander817466c2018-05-22 13:49:31 +020078
Jens Wiklander32b31802023-10-06 16:59:46 +020079 va_start(argp, format);
80 ret = mbedtls_vsnprintf(str, DEBUG_BUF_SIZE, format, argp);
81 va_end(argp);
Jens Wiklander817466c2018-05-22 13:49:31 +020082
Jens Wiklander32b31802023-10-06 16:59:46 +020083 if (ret >= 0 && ret < DEBUG_BUF_SIZE - 1) {
Jens Wiklander817466c2018-05-22 13:49:31 +020084 str[ret] = '\n';
85 str[ret + 1] = '\0';
86 }
87
Jens Wiklander32b31802023-10-06 16:59:46 +020088 debug_send_line(ssl, level, file, line, str);
Jens Wiklander817466c2018-05-22 13:49:31 +020089}
90
Jens Wiklander32b31802023-10-06 16:59:46 +020091void mbedtls_debug_print_ret(const mbedtls_ssl_context *ssl, int level,
92 const char *file, int line,
93 const char *text, int ret)
Jens Wiklander817466c2018-05-22 13:49:31 +020094{
95 char str[DEBUG_BUF_SIZE];
96
Jens Wiklander32b31802023-10-06 16:59:46 +020097 if (NULL == ssl ||
Jerome Forissier5b25c762020-04-07 11:18:49 +020098 NULL == ssl->conf ||
99 NULL == ssl->conf->f_dbg ||
Jens Wiklander32b31802023-10-06 16:59:46 +0200100 level > debug_threshold) {
Jens Wiklander817466c2018-05-22 13:49:31 +0200101 return;
Jerome Forissier5b25c762020-04-07 11:18:49 +0200102 }
Jens Wiklander817466c2018-05-22 13:49:31 +0200103
104 /*
105 * With non-blocking I/O and examples that just retry immediately,
106 * the logs would be quickly flooded with WANT_READ, so ignore that.
Jens Wiklander32b31802023-10-06 16:59:46 +0200107 * Don't ignore WANT_WRITE however, since it is usually rare.
Jens Wiklander817466c2018-05-22 13:49:31 +0200108 */
Jens Wiklander32b31802023-10-06 16:59:46 +0200109 if (ret == MBEDTLS_ERR_SSL_WANT_READ) {
Jens Wiklander817466c2018-05-22 13:49:31 +0200110 return;
Jens Wiklander32b31802023-10-06 16:59:46 +0200111 }
Jens Wiklander817466c2018-05-22 13:49:31 +0200112
Jens Wiklander32b31802023-10-06 16:59:46 +0200113 mbedtls_snprintf(str, sizeof(str), "%s() returned %d (-0x%04x)\n",
114 text, ret, (unsigned int) -ret);
Jens Wiklander817466c2018-05-22 13:49:31 +0200115
Jens Wiklander32b31802023-10-06 16:59:46 +0200116 debug_send_line(ssl, level, file, line, str);
Jens Wiklander817466c2018-05-22 13:49:31 +0200117}
118
Jens Wiklander32b31802023-10-06 16:59:46 +0200119void mbedtls_debug_print_buf(const mbedtls_ssl_context *ssl, int level,
120 const char *file, int line, const char *text,
121 const unsigned char *buf, size_t len)
Jens Wiklander817466c2018-05-22 13:49:31 +0200122{
123 char str[DEBUG_BUF_SIZE];
124 char txt[17];
125 size_t i, idx = 0;
126
Jens Wiklander32b31802023-10-06 16:59:46 +0200127 if (NULL == ssl ||
Jerome Forissier5b25c762020-04-07 11:18:49 +0200128 NULL == ssl->conf ||
129 NULL == ssl->conf->f_dbg ||
Jens Wiklander32b31802023-10-06 16:59:46 +0200130 level > debug_threshold) {
Jens Wiklander817466c2018-05-22 13:49:31 +0200131 return;
Jerome Forissier5b25c762020-04-07 11:18:49 +0200132 }
Jens Wiklander817466c2018-05-22 13:49:31 +0200133
Jens Wiklander32b31802023-10-06 16:59:46 +0200134 mbedtls_snprintf(str + idx, sizeof(str) - idx, "dumping '%s' (%u bytes)\n",
135 text, (unsigned int) len);
Jens Wiklander817466c2018-05-22 13:49:31 +0200136
Jens Wiklander32b31802023-10-06 16:59:46 +0200137 debug_send_line(ssl, level, file, line, str);
Jens Wiklander817466c2018-05-22 13:49:31 +0200138
139 idx = 0;
Jens Wiklander32b31802023-10-06 16:59:46 +0200140 memset(txt, 0, sizeof(txt));
141 for (i = 0; i < len; i++) {
142 if (i >= 4096) {
Jens Wiklander817466c2018-05-22 13:49:31 +0200143 break;
Jens Wiklander32b31802023-10-06 16:59:46 +0200144 }
Jens Wiklander817466c2018-05-22 13:49:31 +0200145
Jens Wiklander32b31802023-10-06 16:59:46 +0200146 if (i % 16 == 0) {
147 if (i > 0) {
148 mbedtls_snprintf(str + idx, sizeof(str) - idx, " %s\n", txt);
149 debug_send_line(ssl, level, file, line, str);
Jens Wiklander817466c2018-05-22 13:49:31 +0200150
151 idx = 0;
Jens Wiklander32b31802023-10-06 16:59:46 +0200152 memset(txt, 0, sizeof(txt));
Jens Wiklander817466c2018-05-22 13:49:31 +0200153 }
154
Jens Wiklander32b31802023-10-06 16:59:46 +0200155 idx += mbedtls_snprintf(str + idx, sizeof(str) - idx, "%04x: ",
156 (unsigned int) i);
Jens Wiklander817466c2018-05-22 13:49:31 +0200157
158 }
159
Jens Wiklander32b31802023-10-06 16:59:46 +0200160 idx += mbedtls_snprintf(str + idx, sizeof(str) - idx, " %02x",
161 (unsigned int) buf[i]);
162 txt[i % 16] = (buf[i] > 31 && buf[i] < 127) ? buf[i] : '.';
Jens Wiklander817466c2018-05-22 13:49:31 +0200163 }
164
Jens Wiklander32b31802023-10-06 16:59:46 +0200165 if (len > 0) {
166 for (/* i = i */; i % 16 != 0; i++) {
167 idx += mbedtls_snprintf(str + idx, sizeof(str) - idx, " ");
168 }
Jens Wiklander817466c2018-05-22 13:49:31 +0200169
Jens Wiklander32b31802023-10-06 16:59:46 +0200170 mbedtls_snprintf(str + idx, sizeof(str) - idx, " %s\n", txt);
171 debug_send_line(ssl, level, file, line, str);
Jens Wiklander817466c2018-05-22 13:49:31 +0200172 }
173}
174
175#if defined(MBEDTLS_ECP_C)
Jens Wiklander32b31802023-10-06 16:59:46 +0200176void mbedtls_debug_print_ecp(const mbedtls_ssl_context *ssl, int level,
177 const char *file, int line,
178 const char *text, const mbedtls_ecp_point *X)
Jens Wiklander817466c2018-05-22 13:49:31 +0200179{
180 char str[DEBUG_BUF_SIZE];
181
Jens Wiklander32b31802023-10-06 16:59:46 +0200182 if (NULL == ssl ||
Jerome Forissier5b25c762020-04-07 11:18:49 +0200183 NULL == ssl->conf ||
184 NULL == ssl->conf->f_dbg ||
Jens Wiklander32b31802023-10-06 16:59:46 +0200185 level > debug_threshold) {
Jens Wiklander817466c2018-05-22 13:49:31 +0200186 return;
Jerome Forissier5b25c762020-04-07 11:18:49 +0200187 }
Jens Wiklander817466c2018-05-22 13:49:31 +0200188
Jens Wiklander32b31802023-10-06 16:59:46 +0200189 mbedtls_snprintf(str, sizeof(str), "%s(X)", text);
190 mbedtls_debug_print_mpi(ssl, level, file, line, str, &X->X);
Jens Wiklander817466c2018-05-22 13:49:31 +0200191
Jens Wiklander32b31802023-10-06 16:59:46 +0200192 mbedtls_snprintf(str, sizeof(str), "%s(Y)", text);
193 mbedtls_debug_print_mpi(ssl, level, file, line, str, &X->Y);
Jens Wiklander817466c2018-05-22 13:49:31 +0200194}
195#endif /* MBEDTLS_ECP_C */
196
197#if defined(MBEDTLS_BIGNUM_C)
Jens Wiklander32b31802023-10-06 16:59:46 +0200198void mbedtls_debug_print_mpi(const mbedtls_ssl_context *ssl, int level,
199 const char *file, int line,
200 const char *text, const mbedtls_mpi *X)
Jens Wiklander817466c2018-05-22 13:49:31 +0200201{
202 char str[DEBUG_BUF_SIZE];
Jerome Forissier79013242021-07-28 10:24:04 +0200203 size_t bitlen;
204 size_t idx = 0;
Jens Wiklander817466c2018-05-22 13:49:31 +0200205
Jens Wiklander32b31802023-10-06 16:59:46 +0200206 if (NULL == ssl ||
Jerome Forissier5b25c762020-04-07 11:18:49 +0200207 NULL == ssl->conf ||
208 NULL == ssl->conf->f_dbg ||
209 NULL == X ||
Jens Wiklander32b31802023-10-06 16:59:46 +0200210 level > debug_threshold) {
Jens Wiklander817466c2018-05-22 13:49:31 +0200211 return;
Jerome Forissier5b25c762020-04-07 11:18:49 +0200212 }
Jens Wiklander817466c2018-05-22 13:49:31 +0200213
Jens Wiklander32b31802023-10-06 16:59:46 +0200214 bitlen = mbedtls_mpi_bitlen(X);
Jens Wiklander817466c2018-05-22 13:49:31 +0200215
Jens Wiklander32b31802023-10-06 16:59:46 +0200216 mbedtls_snprintf(str, sizeof(str), "value of '%s' (%u bits) is:\n",
217 text, (unsigned) bitlen);
218 debug_send_line(ssl, level, file, line, str);
Jens Wiklander817466c2018-05-22 13:49:31 +0200219
Jens Wiklander32b31802023-10-06 16:59:46 +0200220 if (bitlen == 0) {
Jerome Forissier79013242021-07-28 10:24:04 +0200221 str[0] = ' '; str[1] = '0'; str[2] = '0';
222 idx = 3;
Jens Wiklander32b31802023-10-06 16:59:46 +0200223 } else {
Jerome Forissier79013242021-07-28 10:24:04 +0200224 int n;
Jens Wiklander32b31802023-10-06 16:59:46 +0200225 for (n = (int) ((bitlen - 1) / 8); n >= 0; n--) {
226 size_t limb_offset = n / sizeof(mbedtls_mpi_uint);
227 size_t offset_in_limb = n % sizeof(mbedtls_mpi_uint);
Jerome Forissier79013242021-07-28 10:24:04 +0200228 unsigned char octet =
Jens Wiklander32b31802023-10-06 16:59:46 +0200229 (X->p[limb_offset] >> (offset_in_limb * 8)) & 0xff;
230 mbedtls_snprintf(str + idx, sizeof(str) - idx, " %02x", octet);
Jerome Forissier79013242021-07-28 10:24:04 +0200231 idx += 3;
232 /* Wrap lines after 16 octets that each take 3 columns */
Jens Wiklander32b31802023-10-06 16:59:46 +0200233 if (idx >= 3 * 16) {
234 mbedtls_snprintf(str + idx, sizeof(str) - idx, "\n");
235 debug_send_line(ssl, level, file, line, str);
Jerome Forissier79013242021-07-28 10:24:04 +0200236 idx = 0;
Jens Wiklander817466c2018-05-22 13:49:31 +0200237 }
Jens Wiklander817466c2018-05-22 13:49:31 +0200238 }
Jens Wiklander817466c2018-05-22 13:49:31 +0200239 }
240
Jens Wiklander32b31802023-10-06 16:59:46 +0200241 if (idx != 0) {
242 mbedtls_snprintf(str + idx, sizeof(str) - idx, "\n");
243 debug_send_line(ssl, level, file, line, str);
Jerome Forissier79013242021-07-28 10:24:04 +0200244 }
Jens Wiklander817466c2018-05-22 13:49:31 +0200245}
246#endif /* MBEDTLS_BIGNUM_C */
247
Jens Wiklander32b31802023-10-06 16:59:46 +0200248#if defined(MBEDTLS_X509_CRT_PARSE_C) && !defined(MBEDTLS_X509_REMOVE_INFO)
249static void debug_print_pk(const mbedtls_ssl_context *ssl, int level,
250 const char *file, int line,
251 const char *text, const mbedtls_pk_context *pk)
Jens Wiklander817466c2018-05-22 13:49:31 +0200252{
253 size_t i;
254 mbedtls_pk_debug_item items[MBEDTLS_PK_DEBUG_MAX_ITEMS];
255 char name[16];
256
Jens Wiklander32b31802023-10-06 16:59:46 +0200257 memset(items, 0, sizeof(items));
Jens Wiklander817466c2018-05-22 13:49:31 +0200258
Jens Wiklander32b31802023-10-06 16:59:46 +0200259 if (mbedtls_pk_debug(pk, items) != 0) {
260 debug_send_line(ssl, level, file, line,
261 "invalid PK context\n");
Jens Wiklander817466c2018-05-22 13:49:31 +0200262 return;
263 }
264
Jens Wiklander32b31802023-10-06 16:59:46 +0200265 for (i = 0; i < MBEDTLS_PK_DEBUG_MAX_ITEMS; i++) {
266 if (items[i].type == MBEDTLS_PK_DEBUG_NONE) {
Jens Wiklander817466c2018-05-22 13:49:31 +0200267 return;
Jens Wiklander32b31802023-10-06 16:59:46 +0200268 }
Jens Wiklander817466c2018-05-22 13:49:31 +0200269
Jens Wiklander32b31802023-10-06 16:59:46 +0200270 mbedtls_snprintf(name, sizeof(name), "%s%s", text, items[i].name);
271 name[sizeof(name) - 1] = '\0';
Jens Wiklander817466c2018-05-22 13:49:31 +0200272
Jens Wiklander32b31802023-10-06 16:59:46 +0200273 if (items[i].type == MBEDTLS_PK_DEBUG_MPI) {
274 mbedtls_debug_print_mpi(ssl, level, file, line, name, items[i].value);
275 } else
Jens Wiklander817466c2018-05-22 13:49:31 +0200276#if defined(MBEDTLS_ECP_C)
Jens Wiklander32b31802023-10-06 16:59:46 +0200277 if (items[i].type == MBEDTLS_PK_DEBUG_ECP) {
278 mbedtls_debug_print_ecp(ssl, level, file, line, name, items[i].value);
279 } else
Jens Wiklander817466c2018-05-22 13:49:31 +0200280#endif
Jens Wiklander32b31802023-10-06 16:59:46 +0200281 { debug_send_line(ssl, level, file, line,
282 "should not happen\n"); }
Jens Wiklander817466c2018-05-22 13:49:31 +0200283 }
284}
285
Jens Wiklander32b31802023-10-06 16:59:46 +0200286static void debug_print_line_by_line(const mbedtls_ssl_context *ssl, int level,
287 const char *file, int line, const char *text)
Jens Wiklander817466c2018-05-22 13:49:31 +0200288{
289 char str[DEBUG_BUF_SIZE];
290 const char *start, *cur;
291
292 start = text;
Jens Wiklander32b31802023-10-06 16:59:46 +0200293 for (cur = text; *cur != '\0'; cur++) {
294 if (*cur == '\n') {
Jens Wiklander817466c2018-05-22 13:49:31 +0200295 size_t len = cur - start + 1;
Jens Wiklander32b31802023-10-06 16:59:46 +0200296 if (len > DEBUG_BUF_SIZE - 1) {
Jens Wiklander817466c2018-05-22 13:49:31 +0200297 len = DEBUG_BUF_SIZE - 1;
Jens Wiklander32b31802023-10-06 16:59:46 +0200298 }
Jens Wiklander817466c2018-05-22 13:49:31 +0200299
Jens Wiklander32b31802023-10-06 16:59:46 +0200300 memcpy(str, start, len);
Jens Wiklander817466c2018-05-22 13:49:31 +0200301 str[len] = '\0';
302
Jens Wiklander32b31802023-10-06 16:59:46 +0200303 debug_send_line(ssl, level, file, line, str);
Jens Wiklander817466c2018-05-22 13:49:31 +0200304
305 start = cur + 1;
306 }
307 }
308}
309
Jens Wiklander32b31802023-10-06 16:59:46 +0200310void mbedtls_debug_print_crt(const mbedtls_ssl_context *ssl, int level,
311 const char *file, int line,
312 const char *text, const mbedtls_x509_crt *crt)
Jens Wiklander817466c2018-05-22 13:49:31 +0200313{
314 char str[DEBUG_BUF_SIZE];
315 int i = 0;
316
Jens Wiklander32b31802023-10-06 16:59:46 +0200317 if (NULL == ssl ||
Jerome Forissier5b25c762020-04-07 11:18:49 +0200318 NULL == ssl->conf ||
319 NULL == ssl->conf->f_dbg ||
320 NULL == crt ||
Jens Wiklander32b31802023-10-06 16:59:46 +0200321 level > debug_threshold) {
Jens Wiklander817466c2018-05-22 13:49:31 +0200322 return;
Jerome Forissier5b25c762020-04-07 11:18:49 +0200323 }
Jens Wiklander817466c2018-05-22 13:49:31 +0200324
Jens Wiklander32b31802023-10-06 16:59:46 +0200325 while (crt != NULL) {
Jens Wiklander817466c2018-05-22 13:49:31 +0200326 char buf[1024];
327
Jens Wiklander32b31802023-10-06 16:59:46 +0200328 mbedtls_snprintf(str, sizeof(str), "%s #%d:\n", text, ++i);
329 debug_send_line(ssl, level, file, line, str);
Jens Wiklander817466c2018-05-22 13:49:31 +0200330
Jens Wiklander32b31802023-10-06 16:59:46 +0200331 mbedtls_x509_crt_info(buf, sizeof(buf) - 1, "", crt);
332 debug_print_line_by_line(ssl, level, file, line, buf);
Jens Wiklander817466c2018-05-22 13:49:31 +0200333
Jens Wiklander32b31802023-10-06 16:59:46 +0200334 debug_print_pk(ssl, level, file, line, "crt->", &crt->pk);
Jens Wiklander817466c2018-05-22 13:49:31 +0200335
336 crt = crt->next;
337 }
338}
Jens Wiklander32b31802023-10-06 16:59:46 +0200339#endif /* MBEDTLS_X509_CRT_PARSE_C && MBEDTLS_X509_REMOVE_INFO */
Jens Wiklander817466c2018-05-22 13:49:31 +0200340
Jens Wiklander3d3b0592019-03-20 15:30:29 +0100341#if defined(MBEDTLS_ECDH_C)
Jens Wiklander32b31802023-10-06 16:59:46 +0200342static void mbedtls_debug_printf_ecdh_internal(const mbedtls_ssl_context *ssl,
343 int level, const char *file,
344 int line,
345 const mbedtls_ecdh_context *ecdh,
346 mbedtls_debug_ecdh_attr attr)
Jens Wiklander3d3b0592019-03-20 15:30:29 +0100347{
348#if defined(MBEDTLS_ECDH_LEGACY_CONTEXT)
Jens Wiklander32b31802023-10-06 16:59:46 +0200349 const mbedtls_ecdh_context *ctx = ecdh;
Jens Wiklander3d3b0592019-03-20 15:30:29 +0100350#else
Jens Wiklander32b31802023-10-06 16:59:46 +0200351 const mbedtls_ecdh_context_mbed *ctx = &ecdh->ctx.mbed_ecdh;
Jens Wiklander3d3b0592019-03-20 15:30:29 +0100352#endif
353
Jens Wiklander32b31802023-10-06 16:59:46 +0200354 switch (attr) {
Jens Wiklander3d3b0592019-03-20 15:30:29 +0100355 case MBEDTLS_DEBUG_ECDH_Q:
Jens Wiklander32b31802023-10-06 16:59:46 +0200356 mbedtls_debug_print_ecp(ssl, level, file, line, "ECDH: Q",
357 &ctx->Q);
Jens Wiklander3d3b0592019-03-20 15:30:29 +0100358 break;
359 case MBEDTLS_DEBUG_ECDH_QP:
Jens Wiklander32b31802023-10-06 16:59:46 +0200360 mbedtls_debug_print_ecp(ssl, level, file, line, "ECDH: Qp",
361 &ctx->Qp);
Jens Wiklander3d3b0592019-03-20 15:30:29 +0100362 break;
363 case MBEDTLS_DEBUG_ECDH_Z:
Jens Wiklander32b31802023-10-06 16:59:46 +0200364 mbedtls_debug_print_mpi(ssl, level, file, line, "ECDH: z",
365 &ctx->z);
Jens Wiklander3d3b0592019-03-20 15:30:29 +0100366 break;
367 default:
368 break;
369 }
370}
371
Jens Wiklander32b31802023-10-06 16:59:46 +0200372void mbedtls_debug_printf_ecdh(const mbedtls_ssl_context *ssl, int level,
373 const char *file, int line,
374 const mbedtls_ecdh_context *ecdh,
375 mbedtls_debug_ecdh_attr attr)
Jens Wiklander3d3b0592019-03-20 15:30:29 +0100376{
377#if defined(MBEDTLS_ECDH_LEGACY_CONTEXT)
Jens Wiklander32b31802023-10-06 16:59:46 +0200378 mbedtls_debug_printf_ecdh_internal(ssl, level, file, line, ecdh, attr);
Jens Wiklander3d3b0592019-03-20 15:30:29 +0100379#else
Jens Wiklander32b31802023-10-06 16:59:46 +0200380 switch (ecdh->var) {
Jens Wiklander3d3b0592019-03-20 15:30:29 +0100381 default:
Jens Wiklander32b31802023-10-06 16:59:46 +0200382 mbedtls_debug_printf_ecdh_internal(ssl, level, file, line, ecdh,
383 attr);
Jens Wiklander3d3b0592019-03-20 15:30:29 +0100384 }
385#endif
386}
387#endif /* MBEDTLS_ECDH_C */
388
Jens Wiklander817466c2018-05-22 13:49:31 +0200389#endif /* MBEDTLS_DEBUG_C */