Add ssl_conf_dhm_min_bitlen()
diff --git a/include/mbedtls/ssl.h b/include/mbedtls/ssl.h
index fdd3595..1d893bb 100644
--- a/include/mbedtls/ssl.h
+++ b/include/mbedtls/ssl.h
@@ -577,6 +577,10 @@
unsigned int badmac_limit; /*!< limit of records with a bad MAC */
#endif
+#if defined(MBEDTLS_DHM_C) && defined(MBEDTLS_SSL_CLI_C)
+ unsigned int dhm_min_bitlen; /*!< min. bit length of the DHM prime */
+#endif
+
unsigned char max_major_ver; /*!< max. major version used */
unsigned char max_minor_ver; /*!< max. minor version used */
unsigned char min_major_ver; /*!< min. major version used */
@@ -1477,6 +1481,19 @@
int mbedtls_ssl_conf_dh_param_ctx( mbedtls_ssl_config *conf, mbedtls_dhm_context *dhm_ctx );
#endif /* MBEDTLS_DHM_C && defined(MBEDTLS_SSL_SRV_C) */
+#if defined(MBEDTLS_DHM_C) && defined(MBEDTLS_SSL_CLI_C)
+/**
+ * \brief Set the minimum length for Diffie-Hellman parameters.
+ * (Client-side only.)
+ * (Default: 1024 bits.)
+ *
+ * \param conf SSL configuration
+ * \param bitlen Minimum bit length of the DHM prime
+ */
+void mbedtls_ssl_conf_dhm_min_bitlen( mbedtls_ssl_config *conf,
+ unsigned int bitlen );
+#endif /* MBEDTLS_DHM_C && MBEDTLS_SSL_CLI_C */
+
#if defined(MBEDTLS_SSL_SET_CURVES)
/**
* \brief Set the allowed curves in order of preference.
diff --git a/library/ssl_cli.c b/library/ssl_cli.c
index 6eb190c..72ce76f 100644
--- a/library/ssl_cli.c
+++ b/library/ssl_cli.c
@@ -1648,10 +1648,11 @@
return( ret );
}
- if( ssl->handshake->dhm_ctx.len < 64 ||
- ssl->handshake->dhm_ctx.len > 512 )
+ if( ssl->handshake->dhm_ctx.len * 8 < ssl->conf->dhm_min_bitlen )
{
- MBEDTLS_SSL_DEBUG_MSG( 1, ( "bad server key exchange message (DHM length)" ) );
+ MBEDTLS_SSL_DEBUG_MSG( 1, ( "DHM prime too short: %d < %d",
+ ssl->handshake->dhm_ctx.len * 8,
+ ssl->conf->dhm_min_bitlen ) );
return( MBEDTLS_ERR_SSL_BAD_HS_SERVER_KEY_EXCHANGE );
}
diff --git a/library/ssl_tls.c b/library/ssl_tls.c
index ee32502..a0cd3d2 100644
--- a/library/ssl_tls.c
+++ b/library/ssl_tls.c
@@ -5458,6 +5458,17 @@
}
#endif /* MBEDTLS_DHM_C && MBEDTLS_SSL_SRV_C */
+#if defined(MBEDTLS_DHM_C) && defined(MBEDTLS_SSL_CLI_C)
+/*
+ * Set the minimum length for Diffie-Hellman parameters
+ */
+void mbedtls_ssl_conf_dhm_min_bitlen( mbedtls_ssl_config *conf,
+ unsigned int bitlen )
+{
+ conf->dhm_min_bitlen = bitlen;
+}
+#endif /* MBEDTLS_DHM_C && MBEDTLS_SSL_CLI_C */
+
#if defined(MBEDTLS_SSL_SET_CURVES)
/*
* Set the allowed elliptic curves
@@ -6665,6 +6676,10 @@
conf->renego_period[7] = 0x00;
#endif
+#if defined(MBEDTLS_DHM_C) && defined(MBEDTLS_SSL_CLI_C)
+ conf->dhm_min_bitlen = 1024;
+#endif
+
#if defined(MBEDTLS_DHM_C) && defined(MBEDTLS_SSL_SRV_C)
if( endpoint == MBEDTLS_SSL_IS_SERVER )
{