diff --git a/ChangeLog b/ChangeLog index 8888f994b9..5545e5d132 100644 --- a/ChangeLog +++ b/ChangeLog @@ -48,6 +48,9 @@ Bugfix * Fix ssl_client2 example to send application data with 0-length content when the request_size argument is set to 0 as stated in the documentation. Fixes #1833. + * 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. diff --git a/library/hkdf.c b/library/hkdf.c index d2e55e869b..82d8a429f4 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 ) @@ -114,6 +119,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 +135,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 +162,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 )