diff --git a/library/md.c b/library/md.c index df010ae27..882942e13 100644 --- a/library/md.c +++ b/library/md.c @@ -529,9 +529,14 @@ int mbedtls_md_hmac_starts( mbedtls_md_context_t *ctx, const unsigned char *key, mbedtls_md_handle_t md_info; - if( ctx == NULL || ctx->hmac_ctx == NULL ) + if( ctx == NULL ) return( MBEDTLS_ERR_MD_BAD_INPUT_DATA ); +#if !defined(MBEDTLS_MD_SINGLE_HASH) + if( ctx->hmac_ctx == NULL ) + return( MBEDTLS_ERR_MD_BAD_INPUT_DATA ); +#endif /* !MBEDTLS_MD_SINGLE_HASH */ + md_info = mbedtls_md_get_handle( ctx ); if( md_info == MBEDTLS_MD_INVALID_HANDLE ) return( MBEDTLS_ERR_MD_BAD_INPUT_DATA ); @@ -587,9 +592,14 @@ int mbedtls_md_hmac_update( mbedtls_md_context_t *ctx, { mbedtls_md_handle_t md_info; - if( ctx == NULL || ctx->hmac_ctx == NULL ) + if( ctx == NULL ) return( MBEDTLS_ERR_MD_BAD_INPUT_DATA ); +#if !defined(MBEDTLS_MD_SINGLE_HASH) + if( ctx->hmac_ctx == NULL ) + return( MBEDTLS_ERR_MD_BAD_INPUT_DATA ); +#endif /* !MBEDTLS_MD_SINGLE_HASH */ + md_info = mbedtls_md_get_handle( ctx ); if( md_info == MBEDTLS_MD_INVALID_HANDLE ) return( MBEDTLS_ERR_MD_BAD_INPUT_DATA ); @@ -607,9 +617,14 @@ int mbedtls_md_hmac_finish( mbedtls_md_context_t *ctx, unsigned char *output ) mbedtls_md_handle_t md_info; - if( ctx == NULL || ctx->hmac_ctx == NULL ) + if( ctx == NULL ) return( MBEDTLS_ERR_MD_BAD_INPUT_DATA ); +#if !defined(MBEDTLS_MD_SINGLE_HASH) + if( ctx->hmac_ctx == NULL ) + return( MBEDTLS_ERR_MD_BAD_INPUT_DATA ); +#endif /* !MBEDTLS_MD_SINGLE_HASH */ + md_info = mbedtls_md_get_handle( ctx ); if( md_info == MBEDTLS_MD_INVALID_HANDLE ) return( MBEDTLS_ERR_MD_BAD_INPUT_DATA ); @@ -648,9 +663,14 @@ int mbedtls_md_hmac_reset( mbedtls_md_context_t *ctx ) mbedtls_md_handle_t md_info; - if( ctx == NULL || ctx->hmac_ctx == NULL ) + if( ctx == NULL ) return( MBEDTLS_ERR_MD_BAD_INPUT_DATA ); +#if !defined(MBEDTLS_MD_SINGLE_HASH) + if( ctx->hmac_ctx == NULL ) + return( MBEDTLS_ERR_MD_BAD_INPUT_DATA ); +#endif /* !MBEDTLS_MD_SINGLE_HASH */ + md_info = mbedtls_md_get_handle( ctx ); if( md_info == MBEDTLS_MD_INVALID_HANDLE ) return( MBEDTLS_ERR_MD_BAD_INPUT_DATA );