mirror of
https://github.com/cuberite/polarssl.git
synced 2025-09-13 09:05:08 -04:00
Create a separate test suite for constant-time functions
This is the first step in arranging that functions from constant_time.c are tested in test_suite_constant_time.function. Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
This commit is contained in:
parent
3daa98ed95
commit
13e7307892
11
tests/suites/test_suite_constant_time.data
Normal file
11
tests/suites/test_suite_constant_time.data
Normal file
@ -0,0 +1,11 @@
|
||||
# these are the numbers we'd get with an empty plaintext and truncated HMAC
|
||||
Constant-flow memcpy from offset: small
|
||||
ssl_cf_memcpy_offset:0:5:10
|
||||
|
||||
# we could get this with 255-bytes plaintext and untruncated SHA-256
|
||||
Constant-flow memcpy from offset: medium
|
||||
ssl_cf_memcpy_offset:0:255:32
|
||||
|
||||
# we could get this with 255-bytes plaintext and untruncated SHA-384
|
||||
Constant-flow memcpy from offset: large
|
||||
ssl_cf_memcpy_offset:100:339:48
|
49
tests/suites/test_suite_constant_time.function
Normal file
49
tests/suites/test_suite_constant_time.function
Normal file
@ -0,0 +1,49 @@
|
||||
/* BEGIN_HEADER */
|
||||
/** \file test_suite_constant_time.function
|
||||
*
|
||||
* Functional testing of functions in the constant_time module.
|
||||
*
|
||||
* The tests are instrumented with #TEST_CF_SECRET and #TEST_CF_PUBLIC
|
||||
* (see tests/include/test/constant_flow.h) so that running the tests
|
||||
* under MSan or Valgrind will detect a non-constant-time implementation.
|
||||
*/
|
||||
|
||||
#include <mbedtls/constant_time.h>
|
||||
#include <constant_time_internal.h>
|
||||
#include <constant_time_invasive.h>
|
||||
|
||||
#include <test/constant_flow.h>
|
||||
/* END_HEADER */
|
||||
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_SSL_SOME_SUITES_USE_TLS_CBC:MBEDTLS_TEST_HOOKS */
|
||||
void ssl_cf_memcpy_offset( int offset_min, int offset_max, int len )
|
||||
{
|
||||
unsigned char *dst = NULL;
|
||||
unsigned char *src = NULL;
|
||||
size_t src_len = offset_max + len;
|
||||
size_t secret;
|
||||
|
||||
ASSERT_ALLOC( dst, len );
|
||||
ASSERT_ALLOC( src, src_len );
|
||||
|
||||
/* Fill src in a way that we can detect if we copied the right bytes */
|
||||
mbedtls_test_rnd_std_rand( NULL, src, src_len );
|
||||
|
||||
for( secret = offset_min; secret <= (size_t) offset_max; secret++ )
|
||||
{
|
||||
mbedtls_test_set_step( (int) secret );
|
||||
|
||||
TEST_CF_SECRET( &secret, sizeof( secret ) );
|
||||
mbedtls_ct_memcpy_offset( dst, src, secret,
|
||||
offset_min, offset_max, len );
|
||||
TEST_CF_PUBLIC( &secret, sizeof( secret ) );
|
||||
TEST_CF_PUBLIC( dst, len );
|
||||
|
||||
ASSERT_COMPARE( dst, len, src + secret, len );
|
||||
}
|
||||
|
||||
exit:
|
||||
mbedtls_free( dst );
|
||||
mbedtls_free( src );
|
||||
}
|
||||
/* END_CASE */
|
@ -10002,18 +10002,6 @@ Session serialization, load buffer size: large ticket, cert
|
||||
depends_on:MBEDTLS_SSL_SESSION_TICKETS:MBEDTLS_SSL_CLI_C:MBEDTLS_X509_USE_C:MBEDTLS_PEM_PARSE_C:MBEDTLS_ECDSA_C:MBEDTLS_ECP_DP_SECP256R1_ENABLED:MBEDTLS_SHA256_C:MBEDTLS_FS_IO
|
||||
ssl_serialize_session_load_buf_size:1023:"data_files/server5.crt"
|
||||
|
||||
# these are the numbers we'd get with an empty plaintext and truncated HMAC
|
||||
Constant-flow memcpy from offset: small
|
||||
ssl_cf_memcpy_offset:0:5:10
|
||||
|
||||
# we could get this with 255-bytes plaintext and untruncated SHA-256
|
||||
Constant-flow memcpy from offset: medium
|
||||
ssl_cf_memcpy_offset:0:255:32
|
||||
|
||||
# we could get this with 255-bytes plaintext and untruncated SHA-384
|
||||
Constant-flow memcpy from offset: large
|
||||
ssl_cf_memcpy_offset:100:339:48
|
||||
|
||||
Raw key agreement: nominal
|
||||
depends_on:MBEDTLS_SHA256_C
|
||||
raw_key_agreement_fail:0
|
||||
|
@ -4467,39 +4467,6 @@ void resize_buffers_renegotiate_mfl( int mfl, int legacy_renegotiation,
|
||||
}
|
||||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_SSL_SOME_SUITES_USE_TLS_CBC:MBEDTLS_TEST_HOOKS */
|
||||
void ssl_cf_memcpy_offset( int offset_min, int offset_max, int len )
|
||||
{
|
||||
unsigned char *dst = NULL;
|
||||
unsigned char *src = NULL;
|
||||
size_t src_len = offset_max + len;
|
||||
size_t secret;
|
||||
|
||||
ASSERT_ALLOC( dst, len );
|
||||
ASSERT_ALLOC( src, src_len );
|
||||
|
||||
/* Fill src in a way that we can detect if we copied the right bytes */
|
||||
mbedtls_test_rnd_std_rand( NULL, src, src_len );
|
||||
|
||||
for( secret = offset_min; secret <= (size_t) offset_max; secret++ )
|
||||
{
|
||||
mbedtls_test_set_step( (int) secret );
|
||||
|
||||
TEST_CF_SECRET( &secret, sizeof( secret ) );
|
||||
mbedtls_ct_memcpy_offset( dst, src, secret,
|
||||
offset_min, offset_max, len );
|
||||
TEST_CF_PUBLIC( &secret, sizeof( secret ) );
|
||||
TEST_CF_PUBLIC( dst, len );
|
||||
|
||||
ASSERT_COMPARE( dst, len, src + secret, len );
|
||||
}
|
||||
|
||||
exit:
|
||||
mbedtls_free( dst );
|
||||
mbedtls_free( src );
|
||||
}
|
||||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_KEY_EXCHANGE_WITH_CERT_ENABLED:MBEDTLS_USE_PSA_CRYPTO:MBEDTLS_PKCS1_V15:MBEDTLS_SSL_PROTO_TLS1_2:MBEDTLS_ECP_DP_SECP256R1_ENABLED:MBEDTLS_ENTROPY_C:MBEDTLS_RSA_C:MBEDTLS_ECP_DP_SECP384R1_ENABLED:MBEDTLS_CTR_DRBG_C:MBEDTLS_ECP_C:MBEDTLS_ECDSA_C */
|
||||
void raw_key_agreement_fail( int bad_server_ecdhe_key )
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user