ssl_helpers.h 21 KB

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