From e8dd7097c33f2420ea408e6f6106f615d7deb45d Mon Sep 17 00:00:00 2001 From: TRodziewicz Date: Wed, 12 May 2021 14:19:11 +0200 Subject: [PATCH 1/5] Combine MBEDTLS_SSL__PADDING_GRANULARITY options Signed-off-by: TRodziewicz --- ChangeLog.d/issue4335.txt | 4 ++++ include/mbedtls/config.h | 23 +++-------------------- include/mbedtls/ssl.h | 8 ++------ library/ssl_misc.h | 2 +- library/ssl_msg.c | 4 ++-- 5 files changed, 12 insertions(+), 29 deletions(-) create mode 100644 ChangeLog.d/issue4335.txt diff --git a/ChangeLog.d/issue4335.txt b/ChangeLog.d/issue4335.txt new file mode 100644 index 000000000..66480264c --- /dev/null +++ b/ChangeLog.d/issue4335.txt @@ -0,0 +1,4 @@ +Changes + * Replace MBEDTLS_SSL_CID_PADDING_GRANULARITY and + MBEDTLS_SSL_TLS1_3_PADDING_GRANULARITY with a single unified option + MBEDTLS_SSL_CID_TLS1_3_PADDING_GRANULARITY. Fixes #4335. diff --git a/include/mbedtls/config.h b/include/mbedtls/config.h index 715c73ada..2670a2f1b 100644 --- a/include/mbedtls/config.h +++ b/include/mbedtls/config.h @@ -3497,27 +3497,10 @@ */ //#define MBEDTLS_SSL_CID_OUT_LEN_MAX 32 -/** \def MBEDTLS_SSL_CID_PADDING_GRANULARITY +/** \def MBEDTLS_SSL_CID_TLS1_3_PADDING_GRANULARITY * * This option controls the use of record plaintext padding - * when using the Connection ID extension in DTLS 1.2. - * - * The padding will always be chosen so that the length of the - * padded plaintext is a multiple of the value of this option. - * - * Note: A value of \c 1 means that no padding will be used - * for outgoing records. - * - * Note: On systems lacking division instructions, - * a power of two should be preferred. - * - */ -//#define MBEDTLS_SSL_CID_PADDING_GRANULARITY 16 - -/** \def MBEDTLS_SSL_TLS1_3_PADDING_GRANULARITY - * - * This option controls the use of record plaintext padding - * in TLS 1.3. + * when using the Connection ID extension in DTLS 1.2 and TLS 1.3. * * The padding will always be chosen so that the length of the * padded plaintext is a multiple of the value of this option. @@ -3528,7 +3511,7 @@ * Note: On systems lacking division instructions, * a power of two should be preferred. */ -//#define MBEDTLS_SSL_TLS1_3_PADDING_GRANULARITY 1 +//#define MBEDTLS_SSL_CID_TLS1_3_PADDING_GRANULARITY 16 /** \def MBEDTLS_SSL_OUT_CONTENT_LEN * diff --git a/include/mbedtls/ssl.h b/include/mbedtls/ssl.h index bdc2b4797..78f1a8c9a 100644 --- a/include/mbedtls/ssl.h +++ b/include/mbedtls/ssl.h @@ -257,12 +257,8 @@ #define MBEDTLS_SSL_CID_OUT_LEN_MAX 32 #endif -#if !defined(MBEDTLS_SSL_CID_PADDING_GRANULARITY) -#define MBEDTLS_SSL_CID_PADDING_GRANULARITY 16 -#endif - -#if !defined(MBEDTLS_SSL_TLS1_3_PADDING_GRANULARITY) -#define MBEDTLS_SSL_TLS1_3_PADDING_GRANULARITY 1 +#if !defined(MBEDTLS_SSL_CID_TLS1_3_PADDING_GRANULARITY) +#define MBEDTLS_SSL_CID_TLS1_3_PADDING_GRANULARITY 16 #endif /* \} name SECTION: Module settings */ diff --git a/library/ssl_misc.h b/library/ssl_misc.h index 1f1de2bfd..73ffdef92 100644 --- a/library/ssl_misc.h +++ b/library/ssl_misc.h @@ -164,7 +164,7 @@ #endif #if defined(MBEDTLS_SSL_DTLS_CONNECTION_ID) -#define MBEDTLS_SSL_MAX_CID_EXPANSION MBEDTLS_SSL_CID_PADDING_GRANULARITY +#define MBEDTLS_SSL_MAX_CID_EXPANSION MBEDTLS_SSL_CID_TLS1_3_PADDING_GRANULARITY #else #define MBEDTLS_SSL_MAX_CID_EXPANSION 0 #endif diff --git a/library/ssl_msg.c b/library/ssl_msg.c index a75b9190b..d62df20d0 100644 --- a/library/ssl_msg.c +++ b/library/ssl_msg.c @@ -579,7 +579,7 @@ int mbedtls_ssl_encrypt_buf( mbedtls_ssl_context *ssl, { size_t padding = ssl_compute_padding_length( rec->data_len, - MBEDTLS_SSL_TLS1_3_PADDING_GRANULARITY ); + MBEDTLS_SSL_CID_TLS1_3_PADDING_GRANULARITY ); if( ssl_build_inner_plaintext( data, &rec->data_len, post_avail, @@ -605,7 +605,7 @@ int mbedtls_ssl_encrypt_buf( mbedtls_ssl_context *ssl, { size_t padding = ssl_compute_padding_length( rec->data_len, - MBEDTLS_SSL_CID_PADDING_GRANULARITY ); + MBEDTLS_SSL_CID_TLS1_3_PADDING_GRANULARITY ); /* * Wrap plaintext into DTLSInnerPlaintext structure. * See ssl_build_inner_plaintext() for more information. From 5e3c398de20837ef99b7c5beb500b35689159ab6 Mon Sep 17 00:00:00 2001 From: TRodziewicz Date: Wed, 12 May 2021 17:58:51 +0200 Subject: [PATCH 2/5] A small change in ChangeLog just to restart Travis build Signed-off-by: TRodziewicz --- ChangeLog.d/issue4335.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ChangeLog.d/issue4335.txt b/ChangeLog.d/issue4335.txt index 66480264c..fe9b7affa 100644 --- a/ChangeLog.d/issue4335.txt +++ b/ChangeLog.d/issue4335.txt @@ -1,4 +1,4 @@ Changes * Replace MBEDTLS_SSL_CID_PADDING_GRANULARITY and - MBEDTLS_SSL_TLS1_3_PADDING_GRANULARITY with a single unified option + MBEDTLS_SSL_TLS1_3_PADDING_GRANULARITY with a new single unified option MBEDTLS_SSL_CID_TLS1_3_PADDING_GRANULARITY. Fixes #4335. From 0a02fbb783bbb24bcc8fca56d830331a13822dea Mon Sep 17 00:00:00 2001 From: TRodziewicz Date: Wed, 26 May 2021 15:57:50 +0200 Subject: [PATCH 3/5] Addition of the migration guide entry. Signed-off-by: TRodziewicz --- ...e_SSL_CID-TLS1_3_PADDING_GRANULARITY_options.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 docs/3.0-migration-guide.d/combine_SSL_CID-TLS1_3_PADDING_GRANULARITY_options.md diff --git a/docs/3.0-migration-guide.d/combine_SSL_CID-TLS1_3_PADDING_GRANULARITY_options.md b/docs/3.0-migration-guide.d/combine_SSL_CID-TLS1_3_PADDING_GRANULARITY_options.md new file mode 100644 index 000000000..405d572a8 --- /dev/null +++ b/docs/3.0-migration-guide.d/combine_SSL_CID-TLS1_3_PADDING_GRANULARITY_options.md @@ -0,0 +1,14 @@ +Combine the `MBEDTLS_SSL_CID_PADDING_GRANULARITY` and `MBEDTLS_SSL_TLS1_3_PADDING_GRANULARITY` options +-- + +This change affects users who modified the default `config.h` padding granularity +settings, i.e. enabled at least one of the options. + +`config.h` options `MBEDTLS_SSL_CID_PADDING_GRANULARITY` and +`MBEDTLS_SSL_TLS1_3_PADDING_GRANULARITY` were combined into one option because +they used exactly the same padding mechanism and hence their respective padding +granularities can be used in exactly the same way. This change simplifies the +code maintenance. + +The new single option `MBEDTLS_SSL_CID_TLS1_3_PADDING_GRANULARITY` can be used +for both DTLS-CID and TLS 1.3. From 1e660edd82a66aec41b3b13609c15087aa3c559c Mon Sep 17 00:00:00 2001 From: TRodziewicz Date: Wed, 26 May 2021 17:08:54 +0200 Subject: [PATCH 4/5] Change the comment wording in config.h Signed-off-by: TRodziewicz --- include/mbedtls/config.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/mbedtls/config.h b/include/mbedtls/config.h index 2670a2f1b..044bbd722 100644 --- a/include/mbedtls/config.h +++ b/include/mbedtls/config.h @@ -3500,7 +3500,7 @@ /** \def MBEDTLS_SSL_CID_TLS1_3_PADDING_GRANULARITY * * This option controls the use of record plaintext padding - * when using the Connection ID extension in DTLS 1.2 and TLS 1.3. + * in TLS 1.3 and when using the Connection ID extension in DTLS 1.2. * * The padding will always be chosen so that the length of the * padded plaintext is a multiple of the value of this option. From 4e57f4cdfdfddffde50641a9bd9d4c1b62a5fd05 Mon Sep 17 00:00:00 2001 From: TRodziewicz Date: Mon, 31 May 2021 12:58:25 +0200 Subject: [PATCH 5/5] Adding removed defines to check_config.h and fixing the migration guide entry. Signed-off-by: TRodziewicz --- .../combine_SSL_CID-TLS1_3_PADDING_GRANULARITY_options.md | 2 +- include/mbedtls/check_config.h | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/docs/3.0-migration-guide.d/combine_SSL_CID-TLS1_3_PADDING_GRANULARITY_options.md b/docs/3.0-migration-guide.d/combine_SSL_CID-TLS1_3_PADDING_GRANULARITY_options.md index 405d572a8..bc3fa6806 100644 --- a/docs/3.0-migration-guide.d/combine_SSL_CID-TLS1_3_PADDING_GRANULARITY_options.md +++ b/docs/3.0-migration-guide.d/combine_SSL_CID-TLS1_3_PADDING_GRANULARITY_options.md @@ -4,7 +4,7 @@ Combine the `MBEDTLS_SSL_CID_PADDING_GRANULARITY` and `MBEDTLS_SSL_TLS1_3_PADDIN This change affects users who modified the default `config.h` padding granularity settings, i.e. enabled at least one of the options. -`config.h` options `MBEDTLS_SSL_CID_PADDING_GRANULARITY` and +The `config.h` options `MBEDTLS_SSL_CID_PADDING_GRANULARITY` and `MBEDTLS_SSL_TLS1_3_PADDING_GRANULARITY` were combined into one option because they used exactly the same padding mechanism and hence their respective padding granularities can be used in exactly the same way. This change simplifies the diff --git a/include/mbedtls/check_config.h b/include/mbedtls/check_config.h index 389ae2a71..92f6bfea2 100644 --- a/include/mbedtls/check_config.h +++ b/include/mbedtls/check_config.h @@ -841,6 +841,14 @@ #error "MBEDTLS_SSL_PROTO_TLS1_1 (TLS v1.1 support) was removed in Mbed TLS 3.0. See https://github.com/ARMmbed/mbedtls/issues/4286" #endif +#if defined(MBEDTLS_SSL_CID_PADDING_GRANULARITY) //no-check-names +#error "MBEDTLS_SSL_CID_PADDING_GRANULARITY was removed in Mbed TLS 3.0. See https://github.com/ARMmbed/mbedtls/issues/4335" +#endif + +#if defined(MBEDTLS_SSL_TLS1_3_PADDING_GRANULARITY) //no-check-names +#error "MBEDTLS_SSL_TLS1_3_PADDING_GRANULARITY was removed in Mbed TLS 3.0. See https://github.com/ARMmbed/mbedtls/issues/4335" +#endif + /* * Avoid warning from -pedantic. This is a convenient place for this * workaround since this is included by every single file before the