ssl_client2, ssl_server2: code optimization + guards adaptation
Signed-off-by: Przemek Stekiel <przemyslaw.stekiel@mobica.com>
diff --git a/programs/ssl/ssl_server2.c b/programs/ssl/ssl_server2.c
index 1986b35..715fe0c 100644
--- a/programs/ssl/ssl_server2.c
+++ b/programs/ssl/ssl_server2.c
@@ -446,7 +446,9 @@
#define USAGE_EARLY_DATA ""
#endif /* MBEDTLS_SSL_EARLY_DATA */
-#if defined(MBEDTLS_ECP_LIGHT)
+#if defined(MBEDTLS_ECP_LIGHT) || \
+ (defined(MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_SOME_EPHEMERAL_ENABLED) && \
+ defined(PSA_WANT_ALG_FFDH))
#define USAGE_CURVES \
" curves=a,b,c,d default: \"default\" (library default)\n" \
" example: \"secp521r1,brainpoolP512r1\"\n" \
@@ -1522,7 +1524,6 @@
#endif
#if defined(MBEDTLS_ECP_LIGHT)
uint16_t group_list[CURVE_LIST_SIZE];
- const mbedtls_ecp_curve_info *curve_cur;
#endif
#if defined(MBEDTLS_SSL_ALPN)
const char *alpn_list[ALPN_LIST_SIZE];
@@ -2387,62 +2388,16 @@
}
#endif /* MBEDTLS_SSL_HANDSHAKE_WITH_PSK_ENABLED */
-#if defined(MBEDTLS_ECP_LIGHT)
+#if defined(MBEDTLS_ECP_LIGHT) || \
+ (defined(MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_SOME_EPHEMERAL_ENABLED) && \
+ defined(PSA_WANT_ALG_FFDH))
if (opt.curves != NULL) {
- p = (char *) opt.curves;
- i = 0;
-
- if (strcmp(p, "none") == 0) {
- group_list[0] = 0;
- } else if (strcmp(p, "default") != 0) {
- /* Leave room for a final NULL in curve list */
- while (i < CURVE_LIST_SIZE - 1 && *p != '\0') {
- q = p;
- uint16_t ffdh_group = 0;
-
- /* Terminate the current string */
- while (*p != ',' && *p != '\0') {
- p++;
- }
- if (*p == ',') {
- *p++ = '\0';
- }
-
- if ((curve_cur = mbedtls_ecp_curve_info_from_name(q)) != NULL) {
- group_list[i++] = curve_cur->tls_id;
- } else if ((ffdh_group = mbedtls_ssl_ffdh_group_from_name(q)) != 0) {
- group_list[i++] = ffdh_group;
- } else {
- mbedtls_printf("unknown curve %s\n", q);
- mbedtls_printf("supported curves: ");
- for (curve_cur = mbedtls_ecp_curve_list();
- curve_cur->grp_id != MBEDTLS_ECP_DP_NONE;
- curve_cur++) {
- mbedtls_printf("%s ", curve_cur->name);
- const uint16_t *supported_ffdh_group = mbedtls_ssl_ffdh_supported_groups();
- while (*supported_ffdh_group != 0) {
- mbedtls_printf("%s ",
- mbedtls_ssl_ffdh_name_from_group(*supported_ffdh_group));
- supported_ffdh_group++;
- }
- }
- mbedtls_printf("\n");
- goto exit;
- }
- }
-
- mbedtls_printf("Number of curves: %d\n", i);
-
- if (i == CURVE_LIST_SIZE - 1 && *p != '\0') {
- mbedtls_printf("curves list too long, maximum %d",
- CURVE_LIST_SIZE - 1);
- goto exit;
- }
-
- group_list[i] = 0;
+ if (parse_curves(opt.curves, group_list, CURVE_LIST_SIZE) != 0) {
+ goto exit;
}
}
-#endif /* MBEDTLS_ECP_LIGHT */
+#endif /* MBEDTLS_ECP_LIGHT ||
+ (MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_SOME_EPHEMERAL_ENABLED && PSA_WANT_ALG_FFDH) */
#if defined(MBEDTLS_SSL_HANDSHAKE_WITH_CERT_ENABLED)
if (opt.sig_algs != NULL) {
@@ -3144,7 +3099,9 @@
}
#endif
-#if defined(MBEDTLS_ECP_LIGHT)
+#if defined(MBEDTLS_ECP_LIGHT) || \
+ (defined(MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_SOME_EPHEMERAL_ENABLED) && \
+ defined(PSA_WANT_ALG_FFDH))
if (opt.curves != NULL &&
strcmp(opt.curves, "default") != 0) {
mbedtls_ssl_conf_groups(&conf, group_list);