1
0
mirror of https://github.com/Mbed-TLS/mbedtls.git synced 2025-07-07 12:21:11 +03:00

ssl_helpers.c: remove duplicate comments for some functions

Signed-off-by: Yanray Wang <yanray.wang@arm.com>
This commit is contained in:
Yanray Wang
2023-03-14 16:59:00 +08:00
parent 4323e459e9
commit 1ef77c01c4
2 changed files with 24 additions and 221 deletions

View File

@ -424,10 +424,25 @@ int mbedtls_test_move_handshake_to_state(mbedtls_ssl_context *ssl,
mbedtls_ssl_context *second_ssl, mbedtls_ssl_context *second_ssl,
int state); int state);
#endif \ #endif /* MBEDTLS_KEY_EXCHANGE_WITH_CERT_ENABLED && MBEDTLS_CERTS_C &&
/* MBEDTLS_KEY_EXCHANGE_WITH_CERT_ENABLED && MBEDTLS_CERTS_C &&
MBEDTLS_ENTROPY_C && MBEDTLS_CTR_DRBG_C */ MBEDTLS_ENTROPY_C && MBEDTLS_CTR_DRBG_C */
/*
* Helper function setting up inverse record transformations
* using given cipher, hash, EtM mode, authentication tag length,
* and version.
*/
#define CHK(x) \
do \
{ \
if (!(x)) \
{ \
ret = -1; \
goto cleanup; \
} \
} while (0)
int mbedtls_test_ssl_build_transforms(mbedtls_ssl_transform *t_in, int mbedtls_test_ssl_build_transforms(mbedtls_ssl_transform *t_in,
mbedtls_ssl_transform *t_out, mbedtls_ssl_transform *t_out,
int cipher_type, int hash_id, int cipher_type, int hash_id,
@ -476,8 +491,8 @@ int mbedtls_exchange_data(mbedtls_ssl_context *ssl_1,
defined(MBEDTLS_CTR_DRBG_C) defined(MBEDTLS_CTR_DRBG_C)
void mbedtls_test_ssl_perform_handshake( void mbedtls_test_ssl_perform_handshake(
mbedtls_test_handshake_test_options *options); mbedtls_test_handshake_test_options *options);
#endif \ #endif /* MBEDTLS_KEY_EXCHANGE_WITH_CERT_ENABLED && MBEDTLS_CERTS_C &&
/* MBEDTLS_KEY_EXCHANGE_WITH_CERT_ENABLED && MBEDTLS_CERTS_C && MBEDTLS_ENTROPY_C && MBEDTLS_CTR_DRBG_C */ MBEDTLS_ENTROPY_C && MBEDTLS_CTR_DRBG_C */
#endif /* MBEDTLS_SSL_TLS_C */ #endif /* MBEDTLS_SSL_TLS_C */
#endif /* SSL_HELPERS_H */ #endif /* SSL_HELPERS_H */

View File

@ -24,11 +24,6 @@
#if defined(MBEDTLS_SSL_TLS_C) #if defined(MBEDTLS_SSL_TLS_C)
/*
* This function can be passed to mbedtls to receive output logs from it. In
* this case, it will count the instances of a mbedtls_test_ssl_log_pattern
* in the received logged messages.
*/
void mbedtls_test_ssl_log_analyzer(void *ctx, int level, void mbedtls_test_ssl_log_analyzer(void *ctx, int level,
const char *file, int line, const char *file, int line,
const char *str) const char *str)
@ -74,20 +69,11 @@ void mbedtls_test_init_handshake_options(
opts->resize_buffers = 1; opts->resize_buffers = 1;
} }
/*
* Initialises \p buf. After calling this function it is safe to call
* `mbedtls_test_ssl_buffer_free()` on \p buf.
*/
void mbedtls_test_ssl_buffer_init(mbedtls_test_ssl_buffer *buf) void mbedtls_test_ssl_buffer_init(mbedtls_test_ssl_buffer *buf)
{ {
memset(buf, 0, sizeof(*buf)); memset(buf, 0, sizeof(*buf));
} }
/*
* Sets up \p buf. After calling this function it is safe to call
* `mbedtls_test_ssl_buffer_put()` and `mbedtls_test_ssl_buffer_get()`
* on \p buf.
*/
int mbedtls_test_ssl_buffer_setup(mbedtls_test_ssl_buffer *buf, int mbedtls_test_ssl_buffer_setup(mbedtls_test_ssl_buffer *buf,
size_t capacity) size_t capacity)
{ {
@ -110,17 +96,6 @@ void mbedtls_test_ssl_buffer_free(mbedtls_test_ssl_buffer *buf)
memset(buf, 0, sizeof(*buf)); memset(buf, 0, sizeof(*buf));
} }
/*
* Puts \p input_len bytes from the \p input buffer into the ring buffer \p buf.
*
* \p buf must have been initialized and set up by calling
* `mbedtls_test_ssl_buffer_init()` and `mbedtls_test_ssl_buffer_setup()`.
*
* \retval \p input_len, if the data fits.
* \retval 0 <= value < \p input_len, if the data does not fit.
* \retval -1, if \p buf is NULL, it hasn't been set up or \p input_len is not
* zero and \p input is NULL.
*/
int mbedtls_test_ssl_buffer_put(mbedtls_test_ssl_buffer *buf, int mbedtls_test_ssl_buffer_put(mbedtls_test_ssl_buffer *buf,
const unsigned char *input, size_t input_len) const unsigned char *input, size_t input_len)
{ {
@ -165,18 +140,6 @@ int mbedtls_test_ssl_buffer_put(mbedtls_test_ssl_buffer *buf,
return input_len; return input_len;
} }
/*
* Gets \p output_len bytes from the ring buffer \p buf into the
* \p output buffer. The output buffer can be NULL, in this case a part of the
* ring buffer will be dropped, if the requested length is available.
*
* \p buf must have been initialized and set up by calling
* `mbedtls_test_ssl_buffer_init()` and `mbedtls_test_ssl_buffer_setup()`.
*
* \retval \p output_len, if the data is available.
* \retval 0 <= value < \p output_len, if the data is not available.
* \retval -1, if \buf is NULL or it hasn't been set up.
*/
int mbedtls_test_ssl_buffer_get(mbedtls_test_ssl_buffer *buf, int mbedtls_test_ssl_buffer_get(mbedtls_test_ssl_buffer *buf,
unsigned char *output, size_t output_len) unsigned char *output, size_t output_len)
{ {
@ -211,15 +174,6 @@ int mbedtls_test_ssl_buffer_get(mbedtls_test_ssl_buffer *buf,
return output_len; return output_len;
} }
/*
* Setup and free functions for the message metadata queue.
*
* \p capacity describes the number of message metadata chunks that can be held
* within the queue.
*
* \retval 0, if a metadata queue of a given length can be allocated.
* \retval MBEDTLS_ERR_SSL_ALLOC_FAILED, if allocation failed.
*/
int mbedtls_test_ssl_message_queue_setup( int mbedtls_test_ssl_message_queue_setup(
mbedtls_test_ssl_message_queue *queue, size_t capacity) mbedtls_test_ssl_message_queue *queue, size_t capacity)
{ {
@ -249,14 +203,6 @@ void mbedtls_test_ssl_message_queue_free(
memset(queue, 0, sizeof(*queue)); memset(queue, 0, sizeof(*queue));
} }
/*
* Push message length information onto the message metadata queue.
* This will become the last element to leave it (fifo).
*
* \retval MBEDTLS_TEST_ERROR_ARG_NULL, if the queue is null.
* \retval MBEDTLS_ERR_SSL_WANT_WRITE, if the queue is full.
* \retval \p len, if the push was successful.
*/
int mbedtls_test_ssl_message_queue_push_info( int mbedtls_test_ssl_message_queue_push_info(
mbedtls_test_ssl_message_queue *queue, size_t len) mbedtls_test_ssl_message_queue *queue, size_t len)
{ {
@ -275,16 +221,6 @@ int mbedtls_test_ssl_message_queue_push_info(
return len; return len;
} }
/*
* Pop information about the next message length from the queue. This will be
* the oldest inserted message length(fifo). \p msg_len can be null, in which
* case the data will be popped from the queue but not copied anywhere.
*
* \retval MBEDTLS_TEST_ERROR_ARG_NULL, if the queue is null.
* \retval MBEDTLS_ERR_SSL_WANT_READ, if the queue is empty.
* \retval message length, if the pop was successful, up to the given
\p buf_len.
*/
int mbedtls_test_ssl_message_queue_pop_info( int mbedtls_test_ssl_message_queue_pop_info(
mbedtls_test_ssl_message_queue *queue, size_t buf_len) mbedtls_test_ssl_message_queue *queue, size_t buf_len)
{ {
@ -334,27 +270,11 @@ int mbedtls_test_message_queue_peek_info(mbedtls_test_ssl_message_queue *queue,
return (*msg_len > buf_len) ? MBEDTLS_TEST_ERROR_MESSAGE_TRUNCATED : 0; return (*msg_len > buf_len) ? MBEDTLS_TEST_ERROR_MESSAGE_TRUNCATED : 0;
} }
/*
* Setup and teardown functions for mock sockets.
*/
void mbedtls_mock_socket_init(mbedtls_test_mock_socket *socket) void mbedtls_mock_socket_init(mbedtls_test_mock_socket *socket)
{ {
memset(socket, 0, sizeof(*socket)); memset(socket, 0, sizeof(*socket));
} }
/*
* Closes the socket \p socket.
*
* \p socket must have been previously initialized by calling
* mbedtls_mock_socket_init().
*
* This function frees all allocated resources and both sockets are aware of the
* new connection state.
*
* That is, this function does not simulate half-open TCP connections and the
* phenomenon that when closing a UDP connection the peer is not aware of the
* connection having been closed.
*/
void mbedtls_test_mock_socket_close(mbedtls_test_mock_socket *socket) void mbedtls_test_mock_socket_close(mbedtls_test_mock_socket *socket)
{ {
if (socket == NULL) { if (socket == NULL) {
@ -378,16 +298,6 @@ void mbedtls_test_mock_socket_close(mbedtls_test_mock_socket *socket)
memset(socket, 0, sizeof(*socket)); memset(socket, 0, sizeof(*socket));
} }
/*
* Establishes a connection between \p peer1 and \p peer2.
*
* \p peer1 and \p peer2 must have been previously initialized by calling
* mbedtls_mock_socket_init().
*
* The capacities of the internal buffers are set to \p bufsize. Setting this to
* the correct value allows for simulation of MTU, sanity testing the mock
* implementation and mocking TCP connections with lower memory cost.
*/
int mbedtls_test_mock_socket_connect(mbedtls_test_mock_socket *peer1, int mbedtls_test_mock_socket_connect(mbedtls_test_mock_socket *peer1,
mbedtls_test_mock_socket *peer2, mbedtls_test_mock_socket *peer2,
size_t bufsize) size_t bufsize)
@ -436,10 +346,6 @@ exit:
return ret; return ret;
} }
/*
* Callbacks for simulating blocking I/O over connection-oriented transport.
*/
int mbedtls_test_mock_tcp_send_b(void *ctx, int mbedtls_test_mock_tcp_send_b(void *ctx,
const unsigned char *buf, size_t len) const unsigned char *buf, size_t len)
{ {
@ -463,10 +369,6 @@ int mbedtls_test_mock_tcp_recv_b(void *ctx, unsigned char *buf, size_t len)
return mbedtls_test_ssl_buffer_get(socket->input, buf, len); return mbedtls_test_ssl_buffer_get(socket->input, buf, len);
} }
/*
* Callbacks for simulating non-blocking I/O over connection-oriented transport.
*/
int mbedtls_test_mock_tcp_send_nb(void *ctx, int mbedtls_test_mock_tcp_send_nb(void *ctx,
const unsigned char *buf, size_t len) const unsigned char *buf, size_t len)
{ {
@ -506,15 +408,6 @@ void mbedtls_test_message_socket_init(
ctx->socket = NULL; ctx->socket = NULL;
} }
/*
* Setup a given message socket context including initialization of
* input/output queues to a chosen capacity of messages. Also set the
* corresponding mock socket.
*
* \retval 0, if everything succeeds.
* \retval MBEDTLS_ERR_SSL_ALLOC_FAILED, if allocation of a message
* queue failed.
*/
int mbedtls_test_message_socket_setup( int mbedtls_test_message_socket_setup(
mbedtls_test_ssl_message_queue *queue_input, mbedtls_test_ssl_message_queue *queue_input,
mbedtls_test_ssl_message_queue *queue_output, mbedtls_test_ssl_message_queue *queue_output,
@ -534,10 +427,6 @@ int mbedtls_test_message_socket_setup(
return 0; return 0;
} }
/*
* Close a given message socket context, along with the socket itself. Free the
* memory allocated by the input queue.
*/
void mbedtls_test_message_socket_close( void mbedtls_test_message_socket_close(
mbedtls_test_message_socket_context *ctx) mbedtls_test_message_socket_context *ctx)
{ {
@ -550,19 +439,6 @@ void mbedtls_test_message_socket_close(
memset(ctx, 0, sizeof(*ctx)); memset(ctx, 0, sizeof(*ctx));
} }
/*
* Send one message through a given message socket context.
*
* \retval \p len, if everything succeeds.
* \retval MBEDTLS_TEST_ERROR_CONTEXT_ERROR, if any of the needed context
* elements or the context itself is null.
* \retval MBEDTLS_TEST_ERROR_SEND_FAILED if
* mbedtls_test_mock_tcp_send_b failed.
* \retval MBEDTLS_ERR_SSL_WANT_WRITE, if the output queue is full.
*
* This function will also return any error from
* mbedtls_test_ssl_message_queue_push_info.
*/
int mbedtls_test_mock_tcp_send_msg(void *ctx, int mbedtls_test_mock_tcp_send_msg(void *ctx,
const unsigned char *buf, size_t len) const unsigned char *buf, size_t len)
{ {
@ -590,20 +466,6 @@ int mbedtls_test_mock_tcp_send_msg(void *ctx,
return mbedtls_test_ssl_message_queue_push_info(queue, len); return mbedtls_test_ssl_message_queue_push_info(queue, len);
} }
/*
* Receive one message from a given message socket context and return message
* length or an error.
*
* \retval message length, if everything succeeds.
* \retval MBEDTLS_TEST_ERROR_CONTEXT_ERROR, if any of the needed context
* elements or the context itself is null.
* \retval MBEDTLS_TEST_ERROR_RECV_FAILED if
* mbedtls_test_mock_tcp_recv_b failed.
*
* This function will also return any error other than
* MBEDTLS_TEST_ERROR_MESSAGE_TRUNCATED from
* mbedtls_test_message_queue_peek_info.
*/
int mbedtls_test_mock_tcp_recv_msg(void *ctx, int mbedtls_test_mock_tcp_recv_msg(void *ctx,
unsigned char *buf, size_t buf_len) unsigned char *buf, size_t buf_len)
{ {
@ -690,12 +552,6 @@ void mbedtls_endpoint_certificate_free(mbedtls_test_ssl_endpoint *ep)
} }
} }
/*
* Initializes \p ep_cert structure and assigns it to endpoint
* represented by \p ep.
*
* \retval 0 on success, otherwise error code.
*/
int mbedtls_test_ssl_endpoint_certificate_init(mbedtls_test_ssl_endpoint *ep, int mbedtls_test_ssl_endpoint_certificate_init(mbedtls_test_ssl_endpoint *ep,
int pk_alg) int pk_alg)
{ {
@ -796,21 +652,6 @@ exit:
return ret; return ret;
} }
/*
* Initializes \p ep structure. It is important to call
* `mbedtls_test_ssl_endpoint_free()` after calling this function
* even if it fails.
*
* \p endpoint_type must be set as MBEDTLS_SSL_IS_SERVER or
* MBEDTLS_SSL_IS_CLIENT.
* \p pk_alg the algorithm to use, currently only MBEDTLS_PK_RSA and
* MBEDTLS_PK_ECDSA are supported.
* \p dtls_context - in case of DTLS - this is the context handling metadata.
* \p input_queue - used only in case of DTLS.
* \p output_queue - used only in case of DTLS.
*
* \retval 0 on success, otherwise error code.
*/
int mbedtls_test_ssl_endpoint_init( int mbedtls_test_ssl_endpoint_init(
mbedtls_test_ssl_endpoint *ep, int endpoint_type, int pk_alg, mbedtls_test_ssl_endpoint *ep, int endpoint_type, int pk_alg,
mbedtls_test_message_socket_context *dtls_context, mbedtls_test_message_socket_context *dtls_context,
@ -898,9 +739,6 @@ exit:
return ret; return ret;
} }
/*
* Deinitializes endpoint represented by \p ep.
*/
void mbedtls_test_ssl_endpoint_free( void mbedtls_test_ssl_endpoint_free(
mbedtls_test_ssl_endpoint *ep, mbedtls_test_ssl_endpoint *ep,
mbedtls_test_message_socket_context *context) mbedtls_test_message_socket_context *context)
@ -919,13 +757,6 @@ void mbedtls_test_ssl_endpoint_free(
} }
} }
/*
* This function moves ssl handshake from \p ssl to prescribed \p state.
* /p second_ssl is used as second endpoint and their sockets have to be
* connected before calling this function.
*
* \retval 0 on success, otherwise error code.
*/
int mbedtls_test_move_handshake_to_state(mbedtls_ssl_context *ssl, int mbedtls_test_move_handshake_to_state(mbedtls_ssl_context *ssl,
mbedtls_ssl_context *second_ssl, mbedtls_ssl_context *second_ssl,
int state) int state)
@ -962,8 +793,7 @@ int mbedtls_test_move_handshake_to_state(mbedtls_ssl_context *ssl,
return (max_steps >= 0) ? ret : -1; return (max_steps >= 0) ? ret : -1;
} }
#endif \ #endif /* MBEDTLS_KEY_EXCHANGE_WITH_CERT_ENABLED && MBEDTLS_CERTS_C &&
/* MBEDTLS_KEY_EXCHANGE_WITH_CERT_ENABLED && MBEDTLS_CERTS_C &&
MBEDTLS_ENTROPY_C && MBEDTLS_CTR_DRBG_C */ MBEDTLS_ENTROPY_C && MBEDTLS_CTR_DRBG_C */
/* /*
@ -1052,22 +882,6 @@ exit:
return -1; return -1;
} }
/*
* Helper function setting up inverse record transformations
* using given cipher, hash, EtM mode, authentication tag length,
* and version.
*/
#define CHK(x) \
do \
{ \
if (!(x)) \
{ \
ret = -1; \
goto cleanup; \
} \
} while (0)
void set_ciphersuite(mbedtls_ssl_config *conf, const char *cipher, void set_ciphersuite(mbedtls_ssl_config *conf, const char *cipher,
int *forced_ciphersuite) int *forced_ciphersuite)
{ {
@ -1359,10 +1173,6 @@ cleanup:
return ret; return ret;
} }
/*
* Populate a session structure for serialization tests.
* Choose dummy values, mostly non-0 to distinguish from the init default.
*/
int mbedtls_test_ssl_populate_session(mbedtls_ssl_session *session, int mbedtls_test_ssl_populate_session(mbedtls_ssl_session *session,
int ticket_len, int ticket_len,
const char *crt_file) const char *crt_file)
@ -1451,28 +1261,6 @@ int mbedtls_test_ssl_populate_session(mbedtls_ssl_session *session,
return 0; return 0;
} }
/*
* Perform data exchanging between \p ssl_1 and \p ssl_2 and check if the
* message was sent in the correct number of fragments.
*
* /p ssl_1 and /p ssl_2 Endpoints represented by mbedtls_ssl_context. Both
* of them must be initialized and connected
* beforehand.
* /p msg_len_1 and /p msg_len_2 specify the size of the message to send.
* /p expected_fragments_1 and /p expected_fragments_2 determine in how many
* fragments the message should be sent.
* expected_fragments is 0: can be used for DTLS testing while the message
* size is larger than MFL. In that case the message
* cannot be fragmented and sent to the second
* endpoint.
* This value can be used for negative tests.
* expected_fragments is 1: can be used for TLS/DTLS testing while the
* message size is below MFL
* expected_fragments > 1: can be used for TLS testing while the message
* size is larger than MFL
*
* \retval 0 on success, otherwise error code.
*/
int mbedtls_exchange_data(mbedtls_ssl_context *ssl_1, int mbedtls_exchange_data(mbedtls_ssl_context *ssl_1,
int msg_len_1, const int expected_fragments_1, int msg_len_1, const int expected_fragments_1,
mbedtls_ssl_context *ssl_2, mbedtls_ssl_context *ssl_2,
@ -1957,7 +1745,7 @@ exit:
} }
#endif #endif
} }
#endif \ #endif /* MBEDTLS_KEY_EXCHANGE_WITH_CERT_ENABLED && MBEDTLS_CERTS_C &&
/* MBEDTLS_KEY_EXCHANGE_WITH_CERT_ENABLED && MBEDTLS_CERTS_C && MBEDTLS_ENTROPY_C && MBEDTLS_CTR_DRBG_C */ MBEDTLS_ENTROPY_C && MBEDTLS_CTR_DRBG_C */
#endif /* MBEDTLS_SSL_TLS_C */ #endif /* MBEDTLS_SSL_TLS_C */