mirror of
https://github.com/yuzu-emu/mbedtls.git
synced 2025-02-25 01:57:00 +00:00
MD: Implement config dep'n inlining of mbedtls_md_setup()
This commit is contained in:
parent
52e36bc1a1
commit
64b0623cbb
|
@ -256,7 +256,9 @@ int mbedtls_md_init_ctx( mbedtls_md_context_t *ctx, mbedtls_md_handle_t md_info
|
||||||
* failure.
|
* failure.
|
||||||
* \return #MBEDTLS_ERR_MD_ALLOC_FAILED on memory-allocation failure.
|
* \return #MBEDTLS_ERR_MD_ALLOC_FAILED on memory-allocation failure.
|
||||||
*/
|
*/
|
||||||
int mbedtls_md_setup( mbedtls_md_context_t *ctx, mbedtls_md_handle_t md_info, int hmac );
|
MBEDTLS_MD_INLINABLE_API int mbedtls_md_setup( mbedtls_md_context_t *ctx,
|
||||||
|
mbedtls_md_handle_t md_info,
|
||||||
|
int hmac );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief This function clones the state of an message-digest
|
* \brief This function clones the state of an message-digest
|
||||||
|
@ -531,6 +533,36 @@ MBEDTLS_MD_INLINABLE_API int mbedtls_md_process( mbedtls_md_context_t *ctx,
|
||||||
* implemented either here or in md.c, and forward to the wrappers.
|
* implemented either here or in md.c, and forward to the wrappers.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
MBEDTLS_ALWAYS_INLINE static inline int mbedtls_md_setup_internal(
|
||||||
|
mbedtls_md_context_t *ctx, mbedtls_md_handle_t md_info, int hmac )
|
||||||
|
{
|
||||||
|
if( md_info == MBEDTLS_MD_INVALID_HANDLE || ctx == NULL )
|
||||||
|
return( MBEDTLS_ERR_MD_BAD_INPUT_DATA );
|
||||||
|
|
||||||
|
#if !defined(MBEDTLS_MD_SINGLE_HASH)
|
||||||
|
ctx->md_ctx = mbedtls_md_info_ctx_alloc( md_info );
|
||||||
|
if( ctx->md_ctx == NULL )
|
||||||
|
return( MBEDTLS_ERR_MD_ALLOC_FAILED );
|
||||||
|
|
||||||
|
if( hmac != 0 )
|
||||||
|
{
|
||||||
|
ctx->hmac_ctx = mbedtls_calloc( 2,
|
||||||
|
mbedtls_md_info_block_size( md_info ) );
|
||||||
|
if( ctx->hmac_ctx == NULL )
|
||||||
|
{
|
||||||
|
mbedtls_md_info_ctx_free( md_info, ctx->md_ctx);
|
||||||
|
return( MBEDTLS_ERR_MD_ALLOC_FAILED );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx->md_info = md_info;
|
||||||
|
#else
|
||||||
|
((void) hmac);
|
||||||
|
#endif /* MBEDTLS_MD_SINGLE_HASH */
|
||||||
|
|
||||||
|
return( 0 );
|
||||||
|
}
|
||||||
|
|
||||||
MBEDTLS_ALWAYS_INLINE static inline int mbedtls_md_starts_internal(
|
MBEDTLS_ALWAYS_INLINE static inline int mbedtls_md_starts_internal(
|
||||||
mbedtls_md_context_t *ctx )
|
mbedtls_md_context_t *ctx )
|
||||||
{
|
{
|
||||||
|
@ -605,6 +637,13 @@ MBEDTLS_ALWAYS_INLINE static inline int mbedtls_md_process_internal(
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(MBEDTLS_MD_SINGLE_HASH)
|
#if defined(MBEDTLS_MD_SINGLE_HASH)
|
||||||
|
|
||||||
|
MBEDTLS_MD_INLINABLE_API int mbedtls_md_setup(
|
||||||
|
mbedtls_md_context_t *ctx, mbedtls_md_handle_t md_info, int hmac )
|
||||||
|
{
|
||||||
|
return( mbedtls_md_setup_internal( ctx, md_info, hmac ) );
|
||||||
|
}
|
||||||
|
|
||||||
MBEDTLS_MD_INLINABLE_API int mbedtls_md_starts(
|
MBEDTLS_MD_INLINABLE_API int mbedtls_md_starts(
|
||||||
mbedtls_md_context_t *ctx )
|
mbedtls_md_context_t *ctx )
|
||||||
{
|
{
|
||||||
|
|
28
library/md.c
28
library/md.c
|
@ -439,36 +439,12 @@ int mbedtls_md_init_ctx( mbedtls_md_context_t *ctx, mbedtls_md_handle_t md_info
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if !defined(MBEDTLS_MD_SINGLE_HASH)
|
||||||
int mbedtls_md_setup( mbedtls_md_context_t *ctx, mbedtls_md_handle_t md_info, int hmac )
|
int mbedtls_md_setup( mbedtls_md_context_t *ctx, mbedtls_md_handle_t md_info, int hmac )
|
||||||
{
|
{
|
||||||
if( md_info == MBEDTLS_MD_INVALID_HANDLE || ctx == NULL )
|
return( mbedtls_md_setup_internal( ctx, md_info, hmac ) );
|
||||||
return( MBEDTLS_ERR_MD_BAD_INPUT_DATA );
|
|
||||||
|
|
||||||
#if !defined(MBEDTLS_MD_SINGLE_HASH)
|
|
||||||
ctx->md_ctx = mbedtls_md_info_ctx_alloc( md_info );
|
|
||||||
if( ctx->md_ctx == NULL )
|
|
||||||
return( MBEDTLS_ERR_MD_ALLOC_FAILED );
|
|
||||||
|
|
||||||
if( hmac != 0 )
|
|
||||||
{
|
|
||||||
ctx->hmac_ctx = mbedtls_calloc( 2,
|
|
||||||
mbedtls_md_info_block_size( md_info ) );
|
|
||||||
if( ctx->hmac_ctx == NULL )
|
|
||||||
{
|
|
||||||
mbedtls_md_info_ctx_free( md_info, ctx->md_ctx );
|
|
||||||
return( MBEDTLS_ERR_MD_ALLOC_FAILED );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ctx->md_info = md_info;
|
|
||||||
#else
|
|
||||||
((void) hmac);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return( 0 );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#if !defined(MBEDTLS_MD_SINGLE_HASH)
|
|
||||||
int mbedtls_md_starts( mbedtls_md_context_t *ctx )
|
int mbedtls_md_starts( mbedtls_md_context_t *ctx )
|
||||||
{
|
{
|
||||||
return( mbedtls_md_starts_internal( ctx ) );
|
return( mbedtls_md_starts_internal( ctx ) );
|
||||||
|
|
Loading…
Reference in a new issue