MD: Demonstrate config-dep'n API inlining for mbedtls_md_starts()

This commit is contained in:
Hanno Becker 2019-09-04 12:46:07 +01:00
parent 7a7b7227cb
commit 527f7c9307
2 changed files with 36 additions and 10 deletions

View file

@ -82,6 +82,8 @@ typedef enum {
#if !defined(MBEDTLS_MD_SINGLE_HASH)
#define MBEDTLS_MD_INLINABLE_API
/**
* Opaque struct defined in md.c.
*/
@ -93,6 +95,8 @@ typedef struct mbedtls_md_info_t const * mbedtls_md_handle_t;
#else /* !MBEDTLS_MD_SINGLE_HASH */
#define MBEDTLS_MD_INLINABLE_API MBEDTLS_ALWAYS_INLINE static inline
typedef int mbedtls_md_handle_t;
#define MBEDTLS_MD_INVALID_HANDLE ( (mbedtls_md_handle_t) 0 )
#define MBEDTLS_MD_UNIQUE_VALID_HANDLE ( (mbedtls_md_handle_t) 1 )
@ -308,7 +312,7 @@ const char *mbedtls_md_get_name( mbedtls_md_handle_t md_info );
* \return #MBEDTLS_ERR_MD_BAD_INPUT_DATA on parameter-verification
* failure.
*/
int mbedtls_md_starts( mbedtls_md_context_t *ctx );
MBEDTLS_MD_INLINABLE_API int mbedtls_md_starts( mbedtls_md_context_t *ctx );
/**
* \brief This function feeds an input buffer into an ongoing
@ -500,6 +504,34 @@ int mbedtls_md_hmac( mbedtls_md_handle_t md_info, const unsigned char *key, size
/* Internal use */
int mbedtls_md_process( mbedtls_md_context_t *ctx, const unsigned char *data );
/*
* Internal wrapper functions for those MD API functions which should be
* inlined in some but not all configurations. The actual MD API will be
* implemented either here or in md.c, and forward to the wrappers.
*/
MBEDTLS_ALWAYS_INLINE static inline int mbedtls_md_starts_internal(
mbedtls_md_context_t *ctx )
{
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_starts( md_info, ctx->md_ctx ) );
}
#if defined(MBEDTLS_MD_SINGLE_HASH)
MBEDTLS_MD_INLINABLE_API int mbedtls_md_starts(
mbedtls_md_context_t *ctx )
{
return( mbedtls_md_starts_internal( ctx ) );
}
#endif /* MBEDTLS_MD_SINGLE_HASH */
#ifdef __cplusplus
}
#endif

View file

@ -459,18 +459,12 @@ int mbedtls_md_setup( mbedtls_md_context_t *ctx, mbedtls_md_handle_t md_info, in
return( 0 );
}
#if !defined(MBEDTLS_MD_SINGLE_HASH)
int mbedtls_md_starts( mbedtls_md_context_t *ctx )
{
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_starts( md_info, ctx->md_ctx ) );
return( mbedtls_md_starts_internal( ctx ) );
}
#endif /* !MBEDTLS_MD_SINGLE_HASH */
int mbedtls_md_update( mbedtls_md_context_t *ctx, const unsigned char *input, size_t ilen )
{