From b9af2db4cfb6e3ce1a3004c48d991bb91b6f3eec Mon Sep 17 00:00:00 2001 From: Paul Elliott Date: Wed, 9 Mar 2022 15:34:37 +0000 Subject: [PATCH 1/4] Add accessor for timing final delay Signed-off-by: Paul Elliott --- include/mbedtls/timing.h | 11 +++++++++++ library/timing.c | 20 ++++++++++++++++++-- tests/suites/test_suite_ssl.function | 11 +++++++++++ 3 files changed, 40 insertions(+), 2 deletions(-) diff --git a/include/mbedtls/timing.h b/include/mbedtls/timing.h index 25db1c6aa7..652548d971 100644 --- a/include/mbedtls/timing.h +++ b/include/mbedtls/timing.h @@ -90,6 +90,17 @@ void mbedtls_timing_set_delay( void *data, uint32_t int_ms, uint32_t fin_ms ); */ int mbedtls_timing_get_delay( void *data ); +/** + * \brief Get the final timing delay + * + * \param data Pointer to timing data + * Must point to a valid \c mbedtls_timing_delay_context struct. + * + * \return Final timing delay in milliseconds. + */ +uint32_t mbedtls_timing_get_final_delay( + const mbedtls_timing_delay_context *data ); + #ifdef __cplusplus } #endif diff --git a/library/timing.c b/library/timing.c index d66e11e262..a65bc99406 100644 --- a/library/timing.c +++ b/library/timing.c @@ -158,13 +158,28 @@ int mbedtls_timing_get_delay( void *data ) return( 0 ); } -#else -int mbedtls_timing_get_delay( void *data ) + +/* + * Get the final delay. + */ +uint32_t mbedtls_timing_get_final_delay( + const mbedtls_timing_delay_context *data ) +{ + return( data->fin_ms ); +} +#else /* MBEDTLS_HAVE_TIME */ +uint32_t mbedtls_timing_get_final_delay( + const mbedtls_timing_delay_context *data ) { (void) data; return( 0 ); } +int mbedtls_timing_get_delay( void *data ) +{ + (void) data; + return( 0 ); +} void mbedtls_timing_set_delay( void *data, uint32_t int_ms, uint32_t fin_ms ) { (void) data; @@ -178,6 +193,7 @@ unsigned long mbedtls_timing_get_timer( struct mbedtls_timing_hr_time *val, int (void) reset; return( 0 ); } + #endif /* MBEDTLS_HAVE_TIME */ #endif /* !MBEDTLS_TIMING_ALT */ #endif /* MBEDTLS_TIMING_C */ diff --git a/tests/suites/test_suite_ssl.function b/tests/suites/test_suite_ssl.function index 67f4d6ec1f..bda2a96742 100644 --- a/tests/suites/test_suite_ssl.function +++ b/tests/suites/test_suite_ssl.function @@ -5277,3 +5277,14 @@ void conf_group() mbedtls_ssl_config_free( &conf ); } /* END_CASE */ + +/* BEGIN_CASE depends_on:MBEDTLS_TIMING_C:MBEDTLS_HAVE_TIME */ +void timing_accessor( ) +{ + mbedtls_timing_delay_context delay_context; + + mbedtls_timing_set_delay( &delay_context, 50, 100 ); + + TEST_ASSERT( mbedtls_timing_get_final_delay( &delay_context ) == 100 ); +} +/* END_CASE */ From a5bebc297b6e01136329a1d281b8cf0c378d1f13 Mon Sep 17 00:00:00 2001 From: Paul Elliott Date: Wed, 9 Mar 2022 16:24:41 +0000 Subject: [PATCH 2/4] Add changelog entry Signed-off-by: Paul Elliott --- ChangeLog.d/add_final_delay_accessor | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 ChangeLog.d/add_final_delay_accessor diff --git a/ChangeLog.d/add_final_delay_accessor b/ChangeLog.d/add_final_delay_accessor new file mode 100644 index 0000000000..8d341df131 --- /dev/null +++ b/ChangeLog.d/add_final_delay_accessor @@ -0,0 +1,4 @@ +Features + * Add the function mbedtls_timing_get_final_delay() to access the private + final delay field in an mbedtls_timing_delay_context, as requested in + #5183 From 21bbb7a8887a495595ea1e1b83ea853435275a87 Mon Sep 17 00:00:00 2001 From: Paul Elliott Date: Thu, 10 Mar 2022 18:37:22 +0000 Subject: [PATCH 3/4] Add simple test to ensure accessor is working Signed-off-by: Paul Elliott --- tests/suites/test_suite_ssl.data | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/suites/test_suite_ssl.data b/tests/suites/test_suite_ssl.data index eb1b8f44e8..86e84bb413 100644 --- a/tests/suites/test_suite_ssl.data +++ b/tests/suites/test_suite_ssl.data @@ -4779,3 +4779,6 @@ conf_curve: Test configuration of groups for DHE through mbedtls_ssl_conf_groups() conf_group: + +Test accessor into timing_delay_context +timing_accessor From 42d5e51a9879226d24a15dbdbe8146b0e2ff36f1 Mon Sep 17 00:00:00 2001 From: Paul Elliott Date: Thu, 24 Mar 2022 19:41:28 +0000 Subject: [PATCH 4/4] Make test function name more accurate Signed-off-by: Paul Elliott --- tests/suites/test_suite_ssl.data | 2 +- tests/suites/test_suite_ssl.function | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/suites/test_suite_ssl.data b/tests/suites/test_suite_ssl.data index 86e84bb413..06afb2347e 100644 --- a/tests/suites/test_suite_ssl.data +++ b/tests/suites/test_suite_ssl.data @@ -4781,4 +4781,4 @@ Test configuration of groups for DHE through mbedtls_ssl_conf_groups() conf_group: Test accessor into timing_delay_context -timing_accessor +timing_final_delay_accessor diff --git a/tests/suites/test_suite_ssl.function b/tests/suites/test_suite_ssl.function index bda2a96742..be381d54c2 100644 --- a/tests/suites/test_suite_ssl.function +++ b/tests/suites/test_suite_ssl.function @@ -5279,7 +5279,7 @@ void conf_group() /* END_CASE */ /* BEGIN_CASE depends_on:MBEDTLS_TIMING_C:MBEDTLS_HAVE_TIME */ -void timing_accessor( ) +void timing_final_delay_accessor( ) { mbedtls_timing_delay_context delay_context;