mirror of
https://github.com/yuzu-mirror/mbedtls.git
synced 2026-04-20 22:05:15 +00:00
Allow compile-time configuration of I/O function pointers
Introduce the compile-time options - MBEDTLS_SSL_CONF_RECV - MBEDTLS_SSL_CONF_SEND - MBEDTLS_SSL_CONF_RECV_TIMEOUT which can be used to configure the callbacks for the underlying transport at compile-time. Code-size impact: | | GCC 8.2.1 | ARMC5 5.06 | ARMC6 6.12 | | --- | --- | --- | --- | | `libmbedtls.a` before | 23471 | 24077 | 27045 | | `libmbedtls.a` before | 23379 | 23981 | 26941 | | gain in Bytes | 92 | 96 | 104 |
This commit is contained in:
parent
ece325c8dd
commit
a58a896172
11 changed files with 218 additions and 21 deletions
|
|
@ -205,8 +205,13 @@ int main( int argc, char *argv[] )
|
|||
goto exit;
|
||||
}
|
||||
|
||||
mbedtls_ssl_set_bio( &ssl, &server_fd,
|
||||
mbedtls_net_send, mbedtls_net_recv, mbedtls_net_recv_timeout );
|
||||
#if !defined(MBEDTLS_SSL_CONF_RECV) && \
|
||||
!defined(MBEDTLS_SSL_CONF_SEND) && \
|
||||
!defined(MBEDTLS_SSL_CONF_RECV_TIMEOUT)
|
||||
mbedtls_ssl_set_bio( &ssl, &server_fd, mbedtls_net_send, mbedtls_net_recv, NULL );
|
||||
#else
|
||||
mbedtls_ssl_set_bio_ctx( &ssl, &server_fd );
|
||||
#endif
|
||||
|
||||
mbedtls_ssl_set_timer_cb( &ssl, &timer, mbedtls_timing_set_delay,
|
||||
mbedtls_timing_get_delay );
|
||||
|
|
|
|||
|
|
@ -269,7 +269,13 @@ int main( void )
|
|||
goto exit;
|
||||
}
|
||||
|
||||
#if !defined(MBEDTLS_SSL_CONF_RECV) && \
|
||||
!defined(MBEDTLS_SSL_CONF_SEND) && \
|
||||
!defined(MBEDTLS_SSL_CONF_RECV_TIMEOUT)
|
||||
mbedtls_ssl_set_bio( &ssl, &server_fd, mbedtls_net_send, mbedtls_net_recv, NULL );
|
||||
#else
|
||||
mbedtls_ssl_set_bio_ctx( &ssl, &server_fd );
|
||||
#endif
|
||||
|
||||
if( mbedtls_ssl_handshake( &ssl ) != 0 )
|
||||
{
|
||||
|
|
|
|||
|
|
@ -2706,6 +2706,30 @@ int query_config( const char *config )
|
|||
}
|
||||
#endif /* MBEDTLS_SSL_CONF_IGNORE_UNEXPECTED_CID */
|
||||
|
||||
#if defined(MBEDTLS_SSL_CONF_RECV)
|
||||
if( strcmp( "MBEDTLS_SSL_CONF_RECV", config ) == 0 )
|
||||
{
|
||||
MACRO_EXPANSION_TO_STR( MBEDTLS_SSL_CONF_RECV );
|
||||
return( 0 );
|
||||
}
|
||||
#endif /* MBEDTLS_SSL_CONF_RECV */
|
||||
|
||||
#if defined(MBEDTLS_SSL_CONF_SEND)
|
||||
if( strcmp( "MBEDTLS_SSL_CONF_SEND", config ) == 0 )
|
||||
{
|
||||
MACRO_EXPANSION_TO_STR( MBEDTLS_SSL_CONF_SEND );
|
||||
return( 0 );
|
||||
}
|
||||
#endif /* MBEDTLS_SSL_CONF_SEND */
|
||||
|
||||
#if defined(MBEDTLS_SSL_CONF_RECV_TIMEOUT)
|
||||
if( strcmp( "MBEDTLS_SSL_CONF_RECV_TIMEOUT", config ) == 0 )
|
||||
{
|
||||
MACRO_EXPANSION_TO_STR( MBEDTLS_SSL_CONF_RECV_TIMEOUT );
|
||||
return( 0 );
|
||||
}
|
||||
#endif /* MBEDTLS_SSL_CONF_RECV_TIMEOUT */
|
||||
|
||||
#if defined(MBEDTLS_SSL_CONF_RNG)
|
||||
if( strcmp( "MBEDTLS_SSL_CONF_RNG", config ) == 0 )
|
||||
{
|
||||
|
|
|
|||
|
|
@ -466,6 +466,10 @@ static void my_debug( void *ctx, int level,
|
|||
fflush( (FILE *) ctx );
|
||||
}
|
||||
|
||||
|
||||
#if !defined(MBEDTLS_SSL_CONF_RECV) && \
|
||||
!defined(MBEDTLS_SSL_CONF_SEND) && \
|
||||
!defined(MBEDTLS_SSL_CONF_RECV_TIMEOUT)
|
||||
/*
|
||||
* Test recv/send functions that make sure each try returns
|
||||
* WANT_READ/WANT_WRITE at least once before sucesseding
|
||||
|
|
@ -503,6 +507,9 @@ static int my_send( void *ctx, const unsigned char *buf, size_t len )
|
|||
first_try = 1; /* Next call will be a new operation */
|
||||
return( ret );
|
||||
}
|
||||
#endif /* MBEDTLS_SSL_CONF_RECV &&
|
||||
MBEDTLS_SSL_CONF_SEND &&
|
||||
MBEDTLS_SSL_CONF_RECV_TIMEOUT */
|
||||
|
||||
#if defined(MBEDTLS_X509_CRT_PARSE_C)
|
||||
static unsigned char peer_crt_info[1024];
|
||||
|
|
@ -1876,12 +1883,18 @@ int main( int argc, char *argv[] )
|
|||
}
|
||||
#endif
|
||||
|
||||
#if !defined(MBEDTLS_SSL_CONF_RECV) && \
|
||||
!defined(MBEDTLS_SSL_CONF_SEND) && \
|
||||
!defined(MBEDTLS_SSL_CONF_RECV_TIMEOUT)
|
||||
if( opt.nbio == 2 )
|
||||
mbedtls_ssl_set_bio( &ssl, &server_fd, my_send, my_recv, NULL );
|
||||
else
|
||||
mbedtls_ssl_set_bio( &ssl, &server_fd,
|
||||
mbedtls_net_send, mbedtls_net_recv,
|
||||
opt.nbio == 0 ? mbedtls_net_recv_timeout : NULL );
|
||||
#else
|
||||
mbedtls_ssl_set_bio_ctx( &ssl, &server_fd );
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_SSL_DTLS_CONNECTION_ID)
|
||||
if( opt.transport == MBEDTLS_SSL_TRANSPORT_DATAGRAM )
|
||||
|
|
|
|||
|
|
@ -597,6 +597,10 @@ static void my_debug( void *ctx, int level,
|
|||
fflush( (FILE *) ctx );
|
||||
}
|
||||
|
||||
|
||||
#if !defined(MBEDTLS_SSL_CONF_RECV) && \
|
||||
!defined(MBEDTLS_SSL_CONF_SEND) && \
|
||||
!defined(MBEDTLS_SSL_CONF_RECV_TIMEOUT)
|
||||
/*
|
||||
* Test recv/send functions that make sure each try returns
|
||||
* WANT_READ/WANT_WRITE at least once before sucesseding
|
||||
|
|
@ -634,6 +638,9 @@ static int my_send( void *ctx, const unsigned char *buf, size_t len )
|
|||
first_try = 1; /* Next call will be a new operation */
|
||||
return( ret );
|
||||
}
|
||||
#endif /* MBEDTLS_SSL_CONF_RECV &&
|
||||
MBEDTLS_SSL_CONF_SEND &&
|
||||
MBEDTLS_SSL_CONF_RECV_TIMEOUT */
|
||||
|
||||
#if !defined(MBEDTLS_SSL_CONF_AUTHMODE)
|
||||
/*
|
||||
|
|
@ -2859,11 +2866,18 @@ int main( int argc, char *argv[] )
|
|||
goto exit;
|
||||
}
|
||||
|
||||
#if !defined(MBEDTLS_SSL_CONF_RECV) && \
|
||||
!defined(MBEDTLS_SSL_CONF_SEND) && \
|
||||
!defined(MBEDTLS_SSL_CONF_RECV_TIMEOUT)
|
||||
if( opt.nbio == 2 )
|
||||
mbedtls_ssl_set_bio( &ssl, &client_fd, my_send, my_recv, NULL );
|
||||
else
|
||||
mbedtls_ssl_set_bio( &ssl, &client_fd, mbedtls_net_send, mbedtls_net_recv,
|
||||
mbedtls_ssl_set_bio( &ssl, &client_fd,
|
||||
mbedtls_net_send, mbedtls_net_recv,
|
||||
opt.nbio == 0 ? mbedtls_net_recv_timeout : NULL );
|
||||
#else
|
||||
mbedtls_ssl_set_bio_ctx( &ssl, &client_fd );
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_SSL_DTLS_CONNECTION_ID)
|
||||
if( opt.transport == MBEDTLS_SSL_TRANSPORT_DATAGRAM )
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue