diff --git a/library/ssl_tls.c b/library/ssl_tls.c index 9a8fe45ec7..b109ffaa0c 100644 --- a/library/ssl_tls.c +++ b/library/ssl_tls.c @@ -6403,6 +6403,16 @@ void mbedtls_ssl_config_init( mbedtls_ssl_config *conf ) } #if defined(MBEDTLS_KEY_EXCHANGE_WITH_CERT_ENABLED) +#if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_RSA_C) +#define MBEDTLS_SSL_SIG_ALG( hash ) (( hash << 8 ) | MBEDTLS_SSL_SIG_ECDSA), \ + (( hash << 8 ) | MBEDTLS_SSL_SIG_RSA), +#elif defined(MBEDTLS_ECDSA_C) +#define MBEDTLS_SSL_SIG_ALG( hash ) (( hash << 8 ) | MBEDTLS_SSL_SIG_ECDSA), +#elif defined(MBEDTLS_RSA_C) +#define MBEDTLS_SSL_SIG_ALG( hash ) (( hash << 8 ) | MBEDTLS_SSL_SIG_RSA), +#else +#define MBEDTLS_SSL_SIG_ALG( hash ) +#endif /* MBEDTLS_ECDSA_C && MBEDTLS_RSA_C */ #if !defined(MBEDTLS_DEPRECATED_REMOVED) /* The selection should be the same as mbedtls_x509_crt_profile_default in * x509_crt.c. Here, the order matters. Currently we favor stronger hashes, @@ -6478,6 +6488,17 @@ static int ssl_preset_suiteb_hashes[] = { #endif /* !MBEDTLS_DEPRECATED_REMOVED */ static uint16_t ssl_preset_default_sig_algs[] = { +#if defined(MBEDTLS_SSL_PROTO_TLS1_2) +#if defined(MBEDTLS_SHA512_C) + MBEDTLS_SSL_SIG_ALG( MBEDTLS_SSL_HASH_SHA512 ) +#endif +#if defined(MBEDTLS_SHA384_C) + MBEDTLS_SSL_SIG_ALG( MBEDTLS_SSL_HASH_SHA384 ) +#endif +#if defined(MBEDTLS_SHA256_C) + MBEDTLS_SSL_SIG_ALG( MBEDTLS_SSL_HASH_SHA256 ) +#endif +#endif /* MBEDTLS_SSL_PROTO_TLS1_2 */ #if defined(MBEDTLS_SSL_PROTO_TLS1_3) /* ECDSA algorithms */ @@ -6504,6 +6525,14 @@ static uint16_t ssl_preset_default_sig_algs[] = { }; static uint16_t ssl_preset_suiteb_sig_algs[] = { +#if defined(MBEDTLS_SSL_PROTO_TLS1_2) +#if defined(MBEDTLS_SHA384_C) + MBEDTLS_SSL_SIG_ALG( MBEDTLS_SSL_HASH_SHA384 ) +#endif +#if defined(MBEDTLS_SHA256_C) + MBEDTLS_SSL_SIG_ALG( MBEDTLS_SSL_HASH_SHA256 ) +#endif +#endif /* MBEDTLS_SSL_PROTO_TLS1_2 */ #if defined(MBEDTLS_SSL_PROTO_TLS1_3) /* ECDSA algorithms */ diff --git a/programs/ssl/ssl_client2.c b/programs/ssl/ssl_client2.c index 762e21b410..1de8ce3d9c 100644 --- a/programs/ssl/ssl_client2.c +++ b/programs/ssl/ssl_client2.c @@ -1729,7 +1729,7 @@ int main( int argc, char *argv[] ) { crt_profile_for_test.allowed_mds |= MBEDTLS_X509_ID_FLAG( MBEDTLS_MD_SHA1 ); mbedtls_ssl_conf_cert_profile( &conf, &crt_profile_for_test ); - mbedtls_ssl_conf_sig_hashes( &conf, ssl_sig_hashes_for_test ); + mbedtls_ssl_conf_sig_algs( &conf, ssl_sig_algs_for_test ); } if( opt.context_crt_cb == 0 ) diff --git a/programs/ssl/ssl_server2.c b/programs/ssl/ssl_server2.c index f627274a49..388ffe047a 100644 --- a/programs/ssl/ssl_server2.c +++ b/programs/ssl/ssl_server2.c @@ -2586,7 +2586,7 @@ int main( int argc, char *argv[] ) { crt_profile_for_test.allowed_mds |= MBEDTLS_X509_ID_FLAG( MBEDTLS_MD_SHA1 ); mbedtls_ssl_conf_cert_profile( &conf, &crt_profile_for_test ); - mbedtls_ssl_conf_sig_hashes( &conf, ssl_sig_hashes_for_test ); + mbedtls_ssl_conf_sig_algs( &conf, ssl_sig_algs_for_test ); } #endif /* MBEDTLS_X509_CRT_PARSE_C */ diff --git a/programs/ssl/ssl_test_common_source.c b/programs/ssl/ssl_test_common_source.c index 62cd35de8f..0e66895dbd 100644 --- a/programs/ssl/ssl_test_common_source.c +++ b/programs/ssl/ssl_test_common_source.c @@ -262,24 +262,34 @@ int send_cb( void *ctx, unsigned char const *buf, size_t len ) } #if defined(MBEDTLS_X509_CRT_PARSE_C) -int ssl_sig_hashes_for_test[] = { +#if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_RSA_C) +#define MBEDTLS_SSL_SIG_ALG( hash ) (( hash << 8 ) | MBEDTLS_SSL_SIG_ECDSA), \ + (( hash << 8 ) | MBEDTLS_SSL_SIG_RSA), +#elif defined(MBEDTLS_ECDSA_C) +#define MBEDTLS_SSL_SIG_ALG( hash ) (( hash << 8 ) | MBEDTLS_SSL_SIG_ECDSA), +#elif defined(MBEDTLS_RSA_C) +#define MBEDTLS_SSL_SIG_ALG( hash ) (( hash << 8 ) | MBEDTLS_SSL_SIG_RSA), +#else +#define MBEDTLS_SSL_SIG_ALG( hash ) +#endif +uint16_t ssl_sig_algs_for_test[] = { #if defined(MBEDTLS_SHA512_C) - MBEDTLS_MD_SHA512, + MBEDTLS_SSL_SIG_ALG( MBEDTLS_SSL_HASH_SHA512 ) #endif #if defined(MBEDTLS_SHA384_C) - MBEDTLS_MD_SHA384, + MBEDTLS_SSL_SIG_ALG( MBEDTLS_SSL_HASH_SHA384 ) #endif #if defined(MBEDTLS_SHA256_C) - MBEDTLS_MD_SHA256, + MBEDTLS_SSL_SIG_ALG( MBEDTLS_SSL_HASH_SHA256 ) #endif #if defined(MBEDTLS_SHA224_C) - MBEDTLS_MD_SHA224, + MBEDTLS_SSL_SIG_ALG( MBEDTLS_SSL_HASH_SHA224 ) #endif #if defined(MBEDTLS_SHA1_C) /* Allow SHA-1 as we use it extensively in tests. */ - MBEDTLS_MD_SHA1, + MBEDTLS_SSL_SIG_ALG( MBEDTLS_SSL_HASH_SHA1 ) #endif - MBEDTLS_MD_NONE + MBEDTLS_TLS1_3_SIG_NONE }; #endif /* MBEDTLS_X509_CRT_PARSE_C */