blob: 281d1f55a9b5db54a7767580457e9a17b9155236 [file] [log] [blame]
Yanray Wang47907a42022-10-24 14:42:01 +08001/** \file ssl_helpers.h
2 *
3 * \brief This file contains helper functions to set up a TLS connection.
4 */
5
6/*
7 * Copyright The Mbed TLS Contributors
8 * 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.
21 */
22
23#ifndef SSL_HELPERS_H
24#define SSL_HELPERS_H
25
Yanray Wang4d07d1c2022-10-27 15:28:16 +080026#include "mbedtls/build_info.h"
27
28#include <string.h>
29
Yanray Wang47907a42022-10-24 14:42:01 +080030#include <test/helpers.h>
Yanray Wang4d07d1c2022-10-27 15:28:16 +080031#include <test/macros.h>
32#include <test/random.h>
33#include <test/psa_crypto_helpers.h>
34
35#if defined(MBEDTLS_SSL_TLS_C)
36#include <ssl_misc.h>
37#include <mbedtls/timing.h>
38#include <mbedtls/debug.h>
39#include "hash_info.h"
40
41#include "test/certs.h"
Yanray Wang55a66192022-10-26 09:57:53 +080042
43#if defined(MBEDTLS_SSL_CACHE_C)
44#include "mbedtls/ssl_cache.h"
45#endif
46
Yanray Wang5ba709c2023-02-03 11:07:56 +080047#if defined(MBEDTLS_USE_PSA_CRYPTO)
48#define PSA_TO_MBEDTLS_ERR(status) PSA_TO_MBEDTLS_ERR_LIST(status, \
49 psa_to_ssl_errors, \
50 psa_generic_status_to_mbedtls)
51#endif
52
53#if defined(MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED) || \
54 defined(MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED) || \
55 defined(MBEDTLS_KEY_EXCHANGE_RSA_ENABLED)
56#define MBEDTLS_CAN_HANDLE_RSA_TEST_KEY
57#endif
58enum {
59#define MBEDTLS_SSL_TLS1_3_LABEL(name, string) \
60 tls13_label_ ## name,
61 MBEDTLS_SSL_TLS1_3_LABEL_LIST
62#undef MBEDTLS_SSL_TLS1_3_LABEL
63};
64
Yanray Wang55a66192022-10-26 09:57:53 +080065typedef struct mbedtls_test_ssl_log_pattern {
66 const char *pattern;
67 size_t counter;
68} mbedtls_test_ssl_log_pattern;
69
70typedef struct mbedtls_test_handshake_test_options {
71 const char *cipher;
72 mbedtls_ssl_protocol_version client_min_version;
73 mbedtls_ssl_protocol_version client_max_version;
74 mbedtls_ssl_protocol_version server_min_version;
75 mbedtls_ssl_protocol_version server_max_version;
76 mbedtls_ssl_protocol_version expected_negotiated_version;
77 int expected_handshake_result;
78 int expected_ciphersuite;
79 int pk_alg;
80 int opaque_alg;
81 int opaque_alg2;
82 int opaque_usage;
83 data_t *psk_str;
84 int dtls;
85 int srv_auth_mode;
86 int serialize;
87 int mfl;
88 int cli_msg_len;
89 int srv_msg_len;
90 int expected_cli_fragments;
91 int expected_srv_fragments;
92 int renegotiate;
93 int legacy_renegotiation;
94 void *srv_log_obj;
95 void *cli_log_obj;
96 void (*srv_log_fun)(void *, int, const char *, int, const char *);
97 void (*cli_log_fun)(void *, int, const char *, int, const char *);
98 int resize_buffers;
99#if defined(MBEDTLS_SSL_CACHE_C)
100 mbedtls_ssl_cache_context *cache;
101#endif
102} mbedtls_test_handshake_test_options;
103
104typedef struct mbedtls_test_ssl_buffer {
105 size_t start;
106 size_t content_length;
107 size_t capacity;
108 unsigned char *buffer;
109} mbedtls_test_ssl_buffer;
110
111/*
112 * Context for a message metadata queue (fifo) that is on top of the ring buffer.
113 */
114typedef struct mbedtls_test_ssl_message_queue {
115 size_t *messages;
116 int pos;
117 int num;
118 int capacity;
119} mbedtls_test_ssl_message_queue;
120
121/*
122 * Context for the I/O callbacks simulating network connection.
123 */
124
125#define MBEDTLS_MOCK_SOCKET_CONNECTED 1
126
127typedef struct mbedtls_test_mock_socket {
128 int status;
129 mbedtls_test_ssl_buffer *input;
130 mbedtls_test_ssl_buffer *output;
131 struct mbedtls_test_mock_socket *peer;
132} mbedtls_test_mock_socket;
133
134/* Errors used in the message socket mocks */
135
136#define MBEDTLS_TEST_ERROR_CONTEXT_ERROR -55
137#define MBEDTLS_TEST_ERROR_SEND_FAILED -66
138#define MBEDTLS_TEST_ERROR_RECV_FAILED -77
139
140/*
141 * Structure used as an addon, or a wrapper, around the mocked sockets.
142 * Contains an input queue, to which the other socket pushes metadata,
143 * and an output queue, to which this one pushes metadata. This context is
144 * considered as an owner of the input queue only, which is initialized and
145 * freed in the respective setup and free calls.
146 */
147typedef struct mbedtls_test_message_socket_context {
148 mbedtls_test_ssl_message_queue *queue_input;
149 mbedtls_test_ssl_message_queue *queue_output;
150 mbedtls_test_mock_socket *socket;
151} mbedtls_test_message_socket_context;
152
153#if defined(MBEDTLS_SSL_HANDSHAKE_WITH_CERT_ENABLED)
154
155/*
156 * Structure with endpoint's certificates for SSL communication tests.
157 */
158typedef struct mbedtls_test_ssl_endpoint_certificate {
159 mbedtls_x509_crt *ca_cert;
160 mbedtls_x509_crt *cert;
161 mbedtls_pk_context *pkey;
162} mbedtls_test_ssl_endpoint_certificate;
163
164/*
165 * Endpoint structure for SSL communication tests.
166 */
167typedef struct mbedtls_test_ssl_endpoint {
168 const char *name;
169 mbedtls_ssl_context ssl;
170 mbedtls_ssl_config conf;
171 mbedtls_test_mock_socket socket;
172 mbedtls_test_ssl_endpoint_certificate cert;
173} mbedtls_test_ssl_endpoint;
174
175#endif /* MBEDTLS_SSL_HANDSHAKE_WITH_CERT_ENABLED */
Yanray Wang47907a42022-10-24 14:42:01 +0800176
Yanray Wang4d07d1c2022-10-27 15:28:16 +0800177/*
178 * This function can be passed to mbedtls to receive output logs from it. In
179 * this case, it will count the instances of a mbedtls_test_ssl_log_pattern
180 * in the received logged messages.
181 */
182void mbedtls_test_ssl_log_analyzer(void *ctx, int level,
183 const char *file, int line,
184 const char *str);
185
186void mbedtls_test_init_handshake_options(
187 mbedtls_test_handshake_test_options *opts);
188
189void mbedtls_test_free_handshake_options(
190 mbedtls_test_handshake_test_options *opts);
191
192/*
193 * Initialises \p buf. After calling this function it is safe to call
194 * `mbedtls_test_ssl_buffer_free()` on \p buf.
195 */
196void mbedtls_test_ssl_buffer_init(mbedtls_test_ssl_buffer *buf);
197
198/*
199 * Sets up \p buf. After calling this function it is safe to call
200 * `mbedtls_test_ssl_buffer_put()` and `mbedtls_test_ssl_buffer_get()`
201 * on \p buf.
202 */
203int mbedtls_test_ssl_buffer_setup(mbedtls_test_ssl_buffer *buf,
204 size_t capacity);
205
206void mbedtls_test_ssl_buffer_free(mbedtls_test_ssl_buffer *buf);
207
208/*
Yanray Wang4d07d1c2022-10-27 15:28:16 +0800209 * Puts \p input_len bytes from the \p input buffer into the ring buffer \p buf.
210 *
211 * \p buf must have been initialized and set up by calling
212 * `mbedtls_test_ssl_buffer_init()` and `mbedtls_test_ssl_buffer_setup()`.
213 *
214 * \retval \p input_len, if the data fits.
215 * \retval 0 <= value < \p input_len, if the data does not fit.
216 * \retval -1, if \p buf is NULL, it hasn't been set up or \p input_len is not
217 * zero and \p input is NULL.
218 */
219int mbedtls_test_ssl_buffer_put(mbedtls_test_ssl_buffer *buf,
220 const unsigned char *input, size_t input_len);
221
222/*
223 * Gets \p output_len bytes from the ring buffer \p buf into the
224 * \p output buffer. The output buffer can be NULL, in this case a part of the
225 * ring buffer will be dropped, if the requested length is available.
226 *
227 * \p buf must have been initialized and set up by calling
228 * `mbedtls_test_ssl_buffer_init()` and `mbedtls_test_ssl_buffer_setup()`.
229 *
230 * \retval \p output_len, if the data is available.
231 * \retval 0 <= value < \p output_len, if the data is not available.
232 * \retval -1, if \buf is NULL or it hasn't been set up.
233 */
234int mbedtls_test_ssl_buffer_get(mbedtls_test_ssl_buffer *buf,
235 unsigned char *output, size_t output_len);
236
237/*
238 * Errors used in the message transport mock tests
239 */
240 #define MBEDTLS_TEST_ERROR_ARG_NULL -11
241 #define MBEDTLS_TEST_ERROR_MESSAGE_TRUNCATED -44
242
243/*
244 * Setup and free functions for the message metadata queue.
245 *
246 * \p capacity describes the number of message metadata chunks that can be held
247 * within the queue.
248 *
249 * \retval 0, if a metadata queue of a given length can be allocated.
250 * \retval MBEDTLS_ERR_SSL_ALLOC_FAILED, if allocation failed.
251 */
252int mbedtls_test_ssl_message_queue_setup(
253 mbedtls_test_ssl_message_queue *queue, size_t capacity);
254
255void mbedtls_test_ssl_message_queue_free(
256 mbedtls_test_ssl_message_queue *queue);
257
258/*
259 * Push message length information onto the message metadata queue.
260 * This will become the last element to leave it (fifo).
261 *
262 * \retval MBEDTLS_TEST_ERROR_ARG_NULL, if the queue is null.
263 * \retval MBEDTLS_ERR_SSL_WANT_WRITE, if the queue is full.
264 * \retval \p len, if the push was successful.
265 */
266int mbedtls_test_ssl_message_queue_push_info(
267 mbedtls_test_ssl_message_queue *queue, size_t len);
268
269/*
270 * Pop information about the next message length from the queue. This will be
271 * the oldest inserted message length(fifo). \p msg_len can be null, in which
272 * case the data will be popped from the queue but not copied anywhere.
273 *
274 * \retval MBEDTLS_TEST_ERROR_ARG_NULL, if the queue is null.
275 * \retval MBEDTLS_ERR_SSL_WANT_READ, if the queue is empty.
276 * \retval message length, if the pop was successful, up to the given
277 \p buf_len.
278 */
279int mbedtls_test_ssl_message_queue_pop_info(
280 mbedtls_test_ssl_message_queue *queue, size_t buf_len);
281
282/*
283 * Setup and teardown functions for mock sockets.
284 */
285void mbedtls_mock_socket_init(mbedtls_test_mock_socket *socket);
286
287/*
288 * Closes the socket \p socket.
289 *
290 * \p socket must have been previously initialized by calling
291 * mbedtls_mock_socket_init().
292 *
293 * This function frees all allocated resources and both sockets are aware of the
294 * new connection state.
295 *
296 * That is, this function does not simulate half-open TCP connections and the
297 * phenomenon that when closing a UDP connection the peer is not aware of the
298 * connection having been closed.
299 */
300void mbedtls_test_mock_socket_close(mbedtls_test_mock_socket *socket);
301
302/*
303 * Establishes a connection between \p peer1 and \p peer2.
304 *
305 * \p peer1 and \p peer2 must have been previously initialized by calling
306 * mbedtls_mock_socket_init().
307 *
308 * The capacities of the internal buffers are set to \p bufsize. Setting this to
309 * the correct value allows for simulation of MTU, sanity testing the mock
310 * implementation and mocking TCP connections with lower memory cost.
311 */
312int mbedtls_test_mock_socket_connect(mbedtls_test_mock_socket *peer1,
313 mbedtls_test_mock_socket *peer2,
314 size_t bufsize);
315
316
317/*
318 * Callbacks for simulating blocking I/O over connection-oriented transport.
319 */
Yanray Wangaf727a22023-03-13 19:22:36 +0800320int mbedtls_test_mock_tcp_send_b(void *ctx,
321 const unsigned char *buf, size_t len);
Yanray Wang4d07d1c2022-10-27 15:28:16 +0800322
323int mbedtls_test_mock_tcp_recv_b(void *ctx, unsigned char *buf, size_t len);
324
325/*
326 * Callbacks for simulating non-blocking I/O over connection-oriented transport.
327 */
Yanray Wangaf727a22023-03-13 19:22:36 +0800328int mbedtls_test_mock_tcp_send_nb(void *ctx,
329 const unsigned char *buf, size_t len);
Yanray Wang4d07d1c2022-10-27 15:28:16 +0800330
331int mbedtls_test_mock_tcp_recv_nb(void *ctx, unsigned char *buf, size_t len);
332
333void mbedtls_test_message_socket_init(
334 mbedtls_test_message_socket_context *ctx);
335
336/*
337 * Setup a given message socket context including initialization of
338 * input/output queues to a chosen capacity of messages. Also set the
339 * corresponding mock socket.
340 *
341 * \retval 0, if everything succeeds.
342 * \retval MBEDTLS_ERR_SSL_ALLOC_FAILED, if allocation of a message
343 * queue failed.
344 */
345int mbedtls_test_message_socket_setup(
346 mbedtls_test_ssl_message_queue *queue_input,
347 mbedtls_test_ssl_message_queue *queue_output,
Yanray Wangd19894f2023-03-16 11:47:39 +0800348 size_t queue_capacity,
349 mbedtls_test_mock_socket *socket,
Yanray Wang4d07d1c2022-10-27 15:28:16 +0800350 mbedtls_test_message_socket_context *ctx);
351
352/*
353 * Close a given message socket context, along with the socket itself. Free the
354 * memory allocated by the input queue.
355 */
356void mbedtls_test_message_socket_close(
357 mbedtls_test_message_socket_context *ctx);
358
359/*
360 * Send one message through a given message socket context.
361 *
362 * \retval \p len, if everything succeeds.
363 * \retval MBEDTLS_TEST_ERROR_CONTEXT_ERROR, if any of the needed context
364 * elements or the context itself is null.
365 * \retval MBEDTLS_TEST_ERROR_SEND_FAILED if
366 * mbedtls_test_mock_tcp_send_b failed.
367 * \retval MBEDTLS_ERR_SSL_WANT_WRITE, if the output queue is full.
368 *
369 * This function will also return any error from
370 * mbedtls_test_ssl_message_queue_push_info.
371 */
Yanray Wangaf727a22023-03-13 19:22:36 +0800372int mbedtls_test_mock_tcp_send_msg(void *ctx,
373 const unsigned char *buf, size_t len);
Yanray Wang4d07d1c2022-10-27 15:28:16 +0800374
375/*
376 * Receive one message from a given message socket context and return message
377 * length or an error.
378 *
379 * \retval message length, if everything succeeds.
380 * \retval MBEDTLS_TEST_ERROR_CONTEXT_ERROR, if any of the needed context
381 * elements or the context itself is null.
382 * \retval MBEDTLS_TEST_ERROR_RECV_FAILED if
383 * mbedtls_test_mock_tcp_recv_b failed.
384 *
385 * This function will also return any error other than
386 * MBEDTLS_TEST_ERROR_MESSAGE_TRUNCATED from
387 * mbedtls_test_message_queue_peek_info.
388 */
Yanray Wangaf727a22023-03-13 19:22:36 +0800389int mbedtls_test_mock_tcp_recv_msg(void *ctx,
390 unsigned char *buf, size_t buf_len);
Yanray Wang4d07d1c2022-10-27 15:28:16 +0800391
392#if defined(MBEDTLS_SSL_HANDSHAKE_WITH_CERT_ENABLED)
393
394/*
395 * Initializes \p ep_cert structure and assigns it to endpoint
396 * represented by \p ep.
397 *
398 * \retval 0 on success, otherwise error code.
399 */
400int mbedtls_test_ssl_endpoint_certificate_init(mbedtls_test_ssl_endpoint *ep,
401 int pk_alg,
402 int opaque_alg, int opaque_alg2,
403 int opaque_usage);
404
405/*
406 * Initializes \p ep structure. It is important to call
407 * `mbedtls_test_ssl_endpoint_free()` after calling this function
408 * even if it fails.
409 *
410 * \p endpoint_type must be set as MBEDTLS_SSL_IS_SERVER or
411 * MBEDTLS_SSL_IS_CLIENT.
412 * \p pk_alg the algorithm to use, currently only MBEDTLS_PK_RSA and
413 * MBEDTLS_PK_ECDSA are supported.
414 * \p dtls_context - in case of DTLS - this is the context handling metadata.
415 * \p input_queue - used only in case of DTLS.
416 * \p output_queue - used only in case of DTLS.
417 *
418 * \retval 0 on success, otherwise error code.
419 */
420int mbedtls_test_ssl_endpoint_init(
421 mbedtls_test_ssl_endpoint *ep, int endpoint_type,
422 mbedtls_test_handshake_test_options *options,
423 mbedtls_test_message_socket_context *dtls_context,
424 mbedtls_test_ssl_message_queue *input_queue,
425 mbedtls_test_ssl_message_queue *output_queue,
426 uint16_t *group_list);
427
428/*
429 * Deinitializes endpoint represented by \p ep.
430 */
431void mbedtls_test_ssl_endpoint_free(
432 mbedtls_test_ssl_endpoint *ep,
433 mbedtls_test_message_socket_context *context);
434
435/*
436 * This function moves ssl handshake from \p ssl to prescribed \p state.
437 * /p second_ssl is used as second endpoint and their sockets have to be
438 * connected before calling this function.
439 *
440 * \retval 0 on success, otherwise error code.
441 */
442int mbedtls_test_move_handshake_to_state(mbedtls_ssl_context *ssl,
443 mbedtls_ssl_context *second_ssl,
444 int state);
445
446#endif /* MBEDTLS_SSL_HANDSHAKE_WITH_CERT_ENABLED */
447
Yanray Wang1fca4de2023-02-06 12:10:48 +0800448/*
449 * Helper function setting up inverse record transformations
450 * using given cipher, hash, EtM mode, authentication tag length,
451 * and version.
452 */
453#define CHK(x) \
454 do \
455 { \
456 if (!(x)) \
457 { \
458 ret = -1; \
459 goto cleanup; \
460 } \
461 } while (0)
462
Yanray Wang4d07d1c2022-10-27 15:28:16 +0800463#if defined(MBEDTLS_SSL_PROTO_TLS1_2) && \
464 defined(MBEDTLS_CIPHER_MODE_CBC) && defined(MBEDTLS_AES_C)
465int mbedtls_test_psa_cipher_encrypt_helper(mbedtls_ssl_transform *transform,
466 const unsigned char *iv,
467 size_t iv_len,
468 const unsigned char *input,
469 size_t ilen,
470 unsigned char *output,
471 size_t *olen);
472#endif /* MBEDTLS_SSL_PROTO_TLS1_2 && MBEDTLS_CIPHER_MODE_CBC &&
473 MBEDTLS_AES_C */
474
475int mbedtls_test_ssl_build_transforms(mbedtls_ssl_transform *t_in,
476 mbedtls_ssl_transform *t_out,
477 int cipher_type, int hash_id,
478 int etm, int tag_mode,
479 mbedtls_ssl_protocol_version tls_version,
480 size_t cid0_len,
481 size_t cid1_len);
482
483/*
484 * Populate a session structure for serialization tests.
485 * Choose dummy values, mostly non-0 to distinguish from the init default.
486 */
487int mbedtls_test_ssl_tls12_populate_session(mbedtls_ssl_session *session,
488 int ticket_len,
489 const char *crt_file);
490
491#if defined(MBEDTLS_SSL_PROTO_TLS1_3)
492int mbedtls_test_ssl_tls13_populate_session(mbedtls_ssl_session *session,
493 int ticket_len,
494 int endpoint_type);
495#endif /* MBEDTLS_SSL_PROTO_TLS1_3 */
496
497/*
498 * Perform data exchanging between \p ssl_1 and \p ssl_2 and check if the
499 * message was sent in the correct number of fragments.
500 *
501 * /p ssl_1 and /p ssl_2 Endpoints represented by mbedtls_ssl_context. Both
502 * of them must be initialized and connected
503 * beforehand.
504 * /p msg_len_1 and /p msg_len_2 specify the size of the message to send.
505 * /p expected_fragments_1 and /p expected_fragments_2 determine in how many
506 * fragments the message should be sent.
507 * expected_fragments is 0: can be used for DTLS testing while the message
508 * size is larger than MFL. In that case the message
509 * cannot be fragmented and sent to the second
510 * endpoint.
511 * This value can be used for negative tests.
512 * expected_fragments is 1: can be used for TLS/DTLS testing while the
513 * message size is below MFL
514 * expected_fragments > 1: can be used for TLS testing while the message
515 * size is larger than MFL
516 *
517 * \retval 0 on success, otherwise error code.
518 */
519int mbedtls_exchange_data(mbedtls_ssl_context *ssl_1,
520 int msg_len_1, const int expected_fragments_1,
521 mbedtls_ssl_context *ssl_2,
522 int msg_len_2, const int expected_fragments_2);
523
524#if defined(MBEDTLS_SSL_HANDSHAKE_WITH_CERT_ENABLED)
525void mbedtls_test_ssl_perform_handshake(
526 mbedtls_test_handshake_test_options *options);
527#endif /* MBEDTLS_SSL_HANDSHAKE_WITH_CERT_ENABLED */
528
529#if defined(MBEDTLS_TEST_HOOKS)
530/*
531 * Tweak vector lengths in a TLS 1.3 Certificate message
532 *
533 * \param[in] buf Buffer containing the Certificate message to tweak
534 * \param[in]]out] end End of the buffer to parse
535 * \param tweak Tweak identifier (from 1 to the number of tweaks).
536 * \param[out] expected_result Error code expected from the parsing function
537 * \param[out] args Arguments of the MBEDTLS_SSL_CHK_BUF_READ_PTR call that
538 * is expected to fail. All zeroes if no
539 * MBEDTLS_SSL_CHK_BUF_READ_PTR failure is expected.
540 */
541int tweak_tls13_certificate_msg_vector_len(
542 unsigned char *buf, unsigned char **end, int tweak,
543 int *expected_result, mbedtls_ssl_chk_buf_ptr_args *args);
544#endif /* MBEDTLS_TEST_HOOKS */
Yanray Wang1db628f2023-02-03 11:01:29 +0800545
546#define ECJPAKE_TEST_PWD "bla"
547
548#if defined(MBEDTLS_USE_PSA_CRYPTO)
549#define ECJPAKE_TEST_SET_PASSWORD(exp_ret_val) \
550 ret = (use_opaque_arg) ? \
551 mbedtls_ssl_set_hs_ecjpake_password_opaque(&ssl, pwd_slot) : \
552 mbedtls_ssl_set_hs_ecjpake_password(&ssl, pwd_string, pwd_len); \
553 TEST_EQUAL(ret, exp_ret_val)
554#else
555#define ECJPAKE_TEST_SET_PASSWORD(exp_ret_val) \
556 ret = mbedtls_ssl_set_hs_ecjpake_password(&ssl, \
557 pwd_string, pwd_len); \
558 TEST_EQUAL(ret, exp_ret_val)
559#endif /* MBEDTLS_USE_PSA_CRYPTO */
560
Yanray Wang09a6f7e2023-02-03 11:04:38 +0800561#define TEST_AVAILABLE_ECC(tls_id_, group_id_, psa_family_, psa_bits_) \
562 TEST_EQUAL(mbedtls_ssl_get_ecp_group_id_from_tls_id(tls_id_), \
563 group_id_); \
564 TEST_EQUAL(mbedtls_ssl_get_tls_id_from_ecp_group_id(group_id_), \
565 tls_id_); \
566 TEST_EQUAL(mbedtls_ssl_get_psa_curve_info_from_tls_id(tls_id_, \
567 &psa_family, &psa_bits), PSA_SUCCESS); \
568 TEST_EQUAL(psa_family_, psa_family); \
569 TEST_EQUAL(psa_bits_, psa_bits);
570
571#define TEST_UNAVAILABLE_ECC(tls_id_, group_id_, psa_family_, psa_bits_) \
572 TEST_EQUAL(mbedtls_ssl_get_ecp_group_id_from_tls_id(tls_id_), \
573 MBEDTLS_ECP_DP_NONE); \
574 TEST_EQUAL(mbedtls_ssl_get_tls_id_from_ecp_group_id(group_id_), \
575 0); \
576 TEST_EQUAL(mbedtls_ssl_get_psa_curve_info_from_tls_id(tls_id_, \
577 &psa_family, &psa_bits), \
578 PSA_ERROR_NOT_SUPPORTED);
579
Yanray Wang4d07d1c2022-10-27 15:28:16 +0800580#endif /* MBEDTLS_SSL_TLS_C */
581
Yanray Wang47907a42022-10-24 14:42:01 +0800582#endif /* SSL_HELPERS_H */