From ef982d57bfe90968911a5ed08cda4bdcbc9d6b03 Mon Sep 17 00:00:00 2001 From: Hanno Becker Date: Tue, 23 Jul 2019 15:56:18 +0100 Subject: [PATCH] tinyCrypt: Bind RNG wrapper to tinyCrypt in mbedtls_ssl_setup() --- include/mbedtls/ssl_internal.h | 4 ---- library/ssl_cli.c | 2 -- library/ssl_srv.c | 2 -- library/ssl_tls.c | 18 +++++++++++------- 4 files changed, 11 insertions(+), 15 deletions(-) diff --git a/include/mbedtls/ssl_internal.h b/include/mbedtls/ssl_internal.h index 0e9575626..8b4417024 100644 --- a/include/mbedtls/ssl_internal.h +++ b/include/mbedtls/ssl_internal.h @@ -902,10 +902,6 @@ int mbedtls_ssl_handle_message_type( mbedtls_ssl_context *ssl ); int mbedtls_ssl_prepare_handshake_record( mbedtls_ssl_context *ssl ); void mbedtls_ssl_update_handshake_status( mbedtls_ssl_context *ssl ); -#if defined(MBEDTLS_USE_TINYCRYPT) -int mbetls_uecc_rng_wrapper( uint8_t *dest, unsigned int size ); -#endif - /** * \brief Update record layer * diff --git a/library/ssl_cli.c b/library/ssl_cli.c index 582c9fdd4..c3c99c114 100644 --- a/library/ssl_cli.c +++ b/library/ssl_cli.c @@ -3533,8 +3533,6 @@ static int ssl_out_client_key_exchange_write( mbedtls_ssl_context *ssl, { const struct uECC_Curve_t * uecc_curve = uECC_secp256r1(); - uECC_set_rng( &mbetls_uecc_rng_wrapper ); - if( !uECC_make_key( ssl->handshake->ecdh_ownpubkey, ssl->handshake->ecdh_privkey, uecc_curve ) ) diff --git a/library/ssl_srv.c b/library/ssl_srv.c index 8f75f6af7..2562a5712 100644 --- a/library/ssl_srv.c +++ b/library/ssl_srv.c @@ -3384,8 +3384,6 @@ static int ssl_prepare_server_key_exchange( mbedtls_ssl_context *ssl, */ #if defined(MBEDTLS_USE_TINYCRYPT) - uECC_set_rng( &mbetls_uecc_rng_wrapper ); - if( ssl->handshake->curve_tls_id != 23 ) return( MBEDTLS_ERR_SSL_NO_CIPHER_CHOSEN ); diff --git a/library/ssl_tls.c b/library/ssl_tls.c index a1c26d075..752c1724f 100644 --- a/library/ssl_tls.c +++ b/library/ssl_tls.c @@ -55,6 +55,13 @@ #include "mbedtls/oid.h" #endif +#if defined(MBEDTLS_USE_TINYCRYPT) +static int uecc_rng_wrapper( uint8_t *dest, unsigned int size ) +{ + return( mbedtls_ssl_conf_rng_func( NULL, dest, size ) ); +} +#endif /* MBEDTLS_USE_TINYCRYPT */ + static void ssl_reset_in_out_pointers( mbedtls_ssl_context *ssl ); static uint32_t ssl_get_hs_total_len( mbedtls_ssl_context const *ssl ); @@ -8234,6 +8241,10 @@ int mbedtls_ssl_setup( mbedtls_ssl_context *ssl, ssl->conf = conf; +#if defined(MBEDTLS_USE_TINYCRYPT) + uECC_set_rng( &uecc_rng_wrapper ); +#endif + /* * Prepare base structures */ @@ -12165,13 +12176,6 @@ unsigned char mbedtls_ssl_hash_from_md_alg( int md ) } } -#if defined(MBEDTLS_USE_TINYCRYPT) -int mbetls_uecc_rng_wrapper( uint8_t *dest, unsigned int size ) -{ - return( mbedtls_ssl_conf_rng_func( NULL, dest, size ) ); -} -#endif /* MBEDTLS_USE_TINYCRYPT */ - #if defined(MBEDTLS_ECP_C) /* * Check if a curve proposed by the peer is in our list.