MD: Implement config dep'n inlining of mbedtls_md_process()

This commit is contained in:
Hanno Becker 2019-09-04 13:44:51 +01:00
parent 993691d9ba
commit 53ade9fa62
2 changed files with 25 additions and 10 deletions

View File

@ -508,7 +508,8 @@ int mbedtls_md_hmac( mbedtls_md_handle_t md_info, const unsigned char *key, size
unsigned char *output );
/* Internal use */
int mbedtls_md_process( mbedtls_md_context_t *ctx, const unsigned char *data );
MBEDTLS_MD_INLINABLE_API int mbedtls_md_process( mbedtls_md_context_t *ctx,
const unsigned char *data );
/*
* Internal wrapper functions for those MD API functions which should be
@ -575,6 +576,20 @@ MBEDTLS_ALWAYS_INLINE static inline int mbedtls_md_internal(
ilen, output) );
}
MBEDTLS_ALWAYS_INLINE static inline int mbedtls_md_process_internal(
mbedtls_md_context_t *ctx, const unsigned char *data )
{
mbedtls_md_handle_t md_info;
if( ctx == NULL )
return( MBEDTLS_ERR_MD_BAD_INPUT_DATA );
md_info = mbedtls_md_get_handle( ctx );
if( md_info == MBEDTLS_MD_INVALID_HANDLE )
return( MBEDTLS_ERR_MD_BAD_INPUT_DATA );
return( mbedtls_md_info_process( md_info, ctx->md_ctx, data ) );
}
#if defined(MBEDTLS_MD_SINGLE_HASH)
MBEDTLS_MD_INLINABLE_API int mbedtls_md_starts(
mbedtls_md_context_t *ctx )
@ -605,6 +620,12 @@ MBEDTLS_MD_INLINABLE_API int mbedtls_md(
return( mbedtls_md_internal( md_info, input, ilen, output ) );
}
MBEDTLS_MD_INLINABLE_API int mbedtls_md_process(
mbedtls_md_context_t *ctx, const unsigned char *data )
{
return( mbedtls_md_process_internal( ctx, data ) );
}
#endif /* MBEDTLS_MD_SINGLE_HASH */
#ifdef __cplusplus

View File

@ -711,18 +711,12 @@ cleanup:
return( ret );
}
#if !defined(MBEDTLS_MD_SINGLE_HASH)
int mbedtls_md_process( mbedtls_md_context_t *ctx, const unsigned char *data )
{
mbedtls_md_handle_t md_info;
if( ctx == NULL )
return( MBEDTLS_ERR_MD_BAD_INPUT_DATA );
md_info = mbedtls_md_get_handle( ctx );
if( md_info == MBEDTLS_MD_INVALID_HANDLE )
return( MBEDTLS_ERR_MD_BAD_INPUT_DATA );
return( mbedtls_md_info_process( md_info, ctx->md_ctx, data ) );
return( mbedtls_md_process_internal( ctx, data ) );
}
#endif /* !MBEDTLS_MD_SINGLE_HASH */
unsigned char mbedtls_md_get_size( mbedtls_md_handle_t md_info )
{