From a61d123e0eb38509de08e2b32b696860f02fd4c0 Mon Sep 17 00:00:00 2001 From: Brian J Murray Date: Fri, 6 Jul 2018 10:02:39 -0700 Subject: [PATCH 1/3] Minor changes to comments in hkdf.c --- library/hkdf.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/library/hkdf.c b/library/hkdf.c index d2e55e869..41d7d8764 100644 --- a/library/hkdf.c +++ b/library/hkdf.c @@ -114,6 +114,10 @@ int mbedtls_hkdf_expand( const mbedtls_md_info_t *md, const unsigned char *prk, n++; } + /* + * Per RFC 5869 Section 2.3, okm_len must not exceed + * 255 times the hash length + */ if( n > 255 ) { return( MBEDTLS_ERR_HKDF_BAD_INPUT_DATA ); @@ -126,7 +130,10 @@ int mbedtls_hkdf_expand( const mbedtls_md_info_t *md, const unsigned char *prk, goto exit; } - /* RFC 5869 Section 2.3. */ + /* + * Compute T = T(1) | T(2) | T(3) | ... | T(N) + * Where T(N) is defined in RFC 5869 Section 2.3 + */ for( i = 1; i <= n; i++ ) { size_t num_to_copy; @@ -150,7 +157,7 @@ int mbedtls_hkdf_expand( const mbedtls_md_info_t *md, const unsigned char *prk, goto exit; } - /* The constant concatenated to the end of each t(n) is a single octet. + /* The constant concatenated to the end of each T(n) is a single octet. * */ ret = mbedtls_md_hmac_update( &ctx, &c, 1 ); if( ret != 0 ) From ca2ea4e217bab5fac250a256d4011899982332ba Mon Sep 17 00:00:00 2001 From: Brian J Murray Date: Fri, 6 Jul 2018 10:03:58 -0700 Subject: [PATCH 2/3] Fix issue if salt = NULL and salt_len !=0 in mbedtls_hkdf_extract() --- library/hkdf.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/library/hkdf.c b/library/hkdf.c index 41d7d8764..82d8a429f 100644 --- a/library/hkdf.c +++ b/library/hkdf.c @@ -62,6 +62,11 @@ int mbedtls_hkdf_extract( const mbedtls_md_info_t *md, { size_t hash_len; + if( salt_len != 0 ) + { + return MBEDTLS_ERR_HKDF_BAD_INPUT_DATA; + } + hash_len = mbedtls_md_get_size( md ); if( hash_len == 0 ) From 4736e96568b2991e5ff0b38af1d3a27773eec258 Mon Sep 17 00:00:00 2001 From: Brian J Murray Date: Fri, 6 Jul 2018 10:05:22 -0700 Subject: [PATCH 3/3] add myself to changelog --- ChangeLog | 3 +++ 1 file changed, 3 insertions(+) diff --git a/ChangeLog b/ChangeLog index 44533d2ae..f56859ec5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -18,6 +18,9 @@ Bugfix return value. Found by @davidwu2000. #839 * Fix a memory leak in mbedtls_x509_csr_parse(), found by catenacyber, Philippe Antoine. Fixes #1623. + * Change the default behaviour of mbedtls_hkdf_extract() to return an error + when calling with a NULL salt and non-zero salt_len. Contributed by + Brian J Murray Changes * Change the shebang line in Perl scripts to look up perl in the PATH.