mirror of
https://github.com/yuzu-emu/mbedtls.git
synced 2025-03-24 22:25:11 +00:00
Add int return values to MD2 function calls
The following function calls are being deprecated to introduce int return values. * mbedtls_md2() * mbedtls_md2_starts() * mbedtls_md2_update() * mbedtls_md2_finish() * mbedtls_md2_process() The return codes can be used to return error values. This is important when using hardware accelerators.
This commit is contained in:
parent
034ea7e754
commit
1d85213602
|
@ -31,6 +31,11 @@
|
||||||
|
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
|
||||||
|
#if ( defined(__ARMCC_VERSION) || defined(_MSC_VER) ) && \
|
||||||
|
!defined(inline) && !defined(__cplusplus)
|
||||||
|
#define inline __inline
|
||||||
|
#endif
|
||||||
|
|
||||||
#if !defined(MBEDTLS_MD2_ALT)
|
#if !defined(MBEDTLS_MD2_ALT)
|
||||||
// Regular implementation
|
// Regular implementation
|
||||||
//
|
//
|
||||||
|
@ -78,8 +83,10 @@ void mbedtls_md2_clone( mbedtls_md2_context *dst,
|
||||||
* \brief MD2 context setup
|
* \brief MD2 context setup
|
||||||
*
|
*
|
||||||
* \param ctx context to be initialized
|
* \param ctx context to be initialized
|
||||||
|
*
|
||||||
|
* \return 0 if successful
|
||||||
*/
|
*/
|
||||||
void mbedtls_md2_starts( mbedtls_md2_context *ctx );
|
int mbedtls_md2_starts_ext( mbedtls_md2_context *ctx );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief MD2 process buffer
|
* \brief MD2 process buffer
|
||||||
|
@ -87,16 +94,99 @@ void mbedtls_md2_starts( mbedtls_md2_context *ctx );
|
||||||
* \param ctx MD2 context
|
* \param ctx MD2 context
|
||||||
* \param input buffer holding the data
|
* \param input buffer holding the data
|
||||||
* \param ilen length of the input data
|
* \param ilen length of the input data
|
||||||
|
*
|
||||||
|
* \return 0 if successful
|
||||||
*/
|
*/
|
||||||
void mbedtls_md2_update( mbedtls_md2_context *ctx, const unsigned char *input, size_t ilen );
|
int mbedtls_md2_update_ext( mbedtls_md2_context *ctx,
|
||||||
|
const unsigned char *input,
|
||||||
|
size_t ilen );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief MD2 final digest
|
* \brief MD2 final digest
|
||||||
*
|
*
|
||||||
* \param ctx MD2 context
|
* \param ctx MD2 context
|
||||||
* \param output MD2 checksum result
|
* \param output MD2 checksum result
|
||||||
|
*
|
||||||
|
* \return 0 if successful
|
||||||
*/
|
*/
|
||||||
void mbedtls_md2_finish( mbedtls_md2_context *ctx, unsigned char output[16] );
|
int mbedtls_md2_finish_ext( mbedtls_md2_context *ctx,
|
||||||
|
unsigned char output[16] );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief MD2 process data block (internal use only)
|
||||||
|
*
|
||||||
|
* \param ctx MD2 context
|
||||||
|
*
|
||||||
|
* \return 0 if successful
|
||||||
|
*/
|
||||||
|
int mbedtls_md2_process_ext( mbedtls_md2_context *ctx );
|
||||||
|
|
||||||
|
#if !defined(MBEDTLS_DEPRECATED_REMOVED)
|
||||||
|
#if defined(MBEDTLS_DEPRECATED_WARNING)
|
||||||
|
#define MBEDTLS_DEPRECATED __attribute__((deprecated))
|
||||||
|
#else
|
||||||
|
#define MBEDTLS_DEPRECATED
|
||||||
|
#endif
|
||||||
|
/**
|
||||||
|
* \brief MD2 context setup
|
||||||
|
*
|
||||||
|
* \deprecated Superseded by mbedtls_md2_starts_ext() in 2.5.0
|
||||||
|
*
|
||||||
|
* \param ctx context to be initialized
|
||||||
|
*/
|
||||||
|
MBEDTLS_DEPRECATED static inline void mbedtls_md2_starts(
|
||||||
|
mbedtls_md2_context *ctx )
|
||||||
|
{
|
||||||
|
mbedtls_md2_starts_ext( ctx );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief MD2 process buffer
|
||||||
|
*
|
||||||
|
* \deprecated Superseded by mbedtls_md2_update_ext() in 2.5.0
|
||||||
|
*
|
||||||
|
* \param ctx MD2 context
|
||||||
|
* \param input buffer holding the data
|
||||||
|
* \param ilen length of the input data
|
||||||
|
*/
|
||||||
|
MBEDTLS_DEPRECATED static inline void mbedtls_md2_update(
|
||||||
|
mbedtls_md2_context *ctx,
|
||||||
|
const unsigned char *input,
|
||||||
|
size_t ilen )
|
||||||
|
{
|
||||||
|
mbedtls_md2_update_ext( ctx, input, ilen );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief MD2 final digest
|
||||||
|
*
|
||||||
|
* \deprecated Superseded by mbedtls_md2_finish_ext() in 2.5.0
|
||||||
|
*
|
||||||
|
* \param ctx MD2 context
|
||||||
|
* \param output MD2 checksum result
|
||||||
|
*/
|
||||||
|
MBEDTLS_DEPRECATED static inline void mbedtls_md2_finish(
|
||||||
|
mbedtls_md2_context *ctx,
|
||||||
|
unsigned char output[16] )
|
||||||
|
{
|
||||||
|
mbedtls_md2_finish_ext( ctx, output );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief MD2 process data block (internal use only)
|
||||||
|
*
|
||||||
|
* \deprecated Superseded by mbedtls_md2_process_ext() in 2.5.0
|
||||||
|
*
|
||||||
|
* \param ctx MD2 context
|
||||||
|
*/
|
||||||
|
MBEDTLS_DEPRECATED static inline void mbedtls_md2_process(
|
||||||
|
mbedtls_md2_context *ctx )
|
||||||
|
{
|
||||||
|
mbedtls_md2_process_ext( ctx );
|
||||||
|
}
|
||||||
|
|
||||||
|
#undef MBEDTLS_DEPRECATED
|
||||||
|
#endif /* !MBEDTLS_DEPRECATED_REMOVED */
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
@ -117,7 +207,36 @@ extern "C" {
|
||||||
* \param ilen length of the input data
|
* \param ilen length of the input data
|
||||||
* \param output MD2 checksum result
|
* \param output MD2 checksum result
|
||||||
*/
|
*/
|
||||||
void mbedtls_md2( const unsigned char *input, size_t ilen, unsigned char output[16] );
|
int mbedtls_md2_ext( const unsigned char *input,
|
||||||
|
size_t ilen,
|
||||||
|
unsigned char output[16] );
|
||||||
|
|
||||||
|
#if !defined(MBEDTLS_DEPRECATED_REMOVED)
|
||||||
|
#if defined(MBEDTLS_DEPRECATED_WARNING)
|
||||||
|
#define MBEDTLS_DEPRECATED __attribute__((deprecated))
|
||||||
|
#else
|
||||||
|
#define MBEDTLS_DEPRECATED
|
||||||
|
#endif
|
||||||
|
/**
|
||||||
|
* \brief Output = MD2( input buffer )
|
||||||
|
*
|
||||||
|
* \deprecated Superseded by mbedtls_md2() in 2.5.0
|
||||||
|
*
|
||||||
|
* \param input buffer holding the data
|
||||||
|
* \param ilen length of the input data
|
||||||
|
* \param output MD2 checksum result
|
||||||
|
*
|
||||||
|
* \return 0 if successful
|
||||||
|
*/
|
||||||
|
MBEDTLS_DEPRECATED static inline void mbedtls_md2( const unsigned char *input,
|
||||||
|
size_t ilen,
|
||||||
|
unsigned char output[16] )
|
||||||
|
{
|
||||||
|
mbedtls_md2_ext( input, ilen, output );
|
||||||
|
}
|
||||||
|
|
||||||
|
#undef MBEDTLS_DEPRECATED
|
||||||
|
#endif /* !MBEDTLS_DEPRECATED_REMOVED */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Checkup routine
|
* \brief Checkup routine
|
||||||
|
@ -126,9 +245,6 @@ void mbedtls_md2( const unsigned char *input, size_t ilen, unsigned char output[
|
||||||
*/
|
*/
|
||||||
int mbedtls_md2_self_test( int verbose );
|
int mbedtls_md2_self_test( int verbose );
|
||||||
|
|
||||||
/* Internal use */
|
|
||||||
void mbedtls_md2_process( mbedtls_md2_context *ctx );
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -105,16 +105,18 @@ void mbedtls_md2_clone( mbedtls_md2_context *dst,
|
||||||
/*
|
/*
|
||||||
* MD2 context setup
|
* MD2 context setup
|
||||||
*/
|
*/
|
||||||
void mbedtls_md2_starts( mbedtls_md2_context *ctx )
|
int mbedtls_md2_starts_ext( mbedtls_md2_context *ctx )
|
||||||
{
|
{
|
||||||
memset( ctx->cksum, 0, 16 );
|
memset( ctx->cksum, 0, 16 );
|
||||||
memset( ctx->state, 0, 46 );
|
memset( ctx->state, 0, 46 );
|
||||||
memset( ctx->buffer, 0, 16 );
|
memset( ctx->buffer, 0, 16 );
|
||||||
ctx->left = 0;
|
ctx->left = 0;
|
||||||
|
|
||||||
|
return( 0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
#if !defined(MBEDTLS_MD2_PROCESS_ALT)
|
#if !defined(MBEDTLS_MD2_PROCESS_ALT)
|
||||||
void mbedtls_md2_process( mbedtls_md2_context *ctx )
|
int mbedtls_md2_process_ext( mbedtls_md2_context *ctx )
|
||||||
{
|
{
|
||||||
int i, j;
|
int i, j;
|
||||||
unsigned char t = 0;
|
unsigned char t = 0;
|
||||||
|
@ -146,14 +148,19 @@ void mbedtls_md2_process( mbedtls_md2_context *ctx )
|
||||||
( ctx->cksum[i] ^ PI_SUBST[ctx->buffer[i] ^ t] );
|
( ctx->cksum[i] ^ PI_SUBST[ctx->buffer[i] ^ t] );
|
||||||
t = ctx->cksum[i];
|
t = ctx->cksum[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return( 0 );
|
||||||
}
|
}
|
||||||
#endif /* !MBEDTLS_MD2_PROCESS_ALT */
|
#endif /* !MBEDTLS_MD2_PROCESS_ALT */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* MD2 process buffer
|
* MD2 process buffer
|
||||||
*/
|
*/
|
||||||
void mbedtls_md2_update( mbedtls_md2_context *ctx, const unsigned char *input, size_t ilen )
|
int mbedtls_md2_update_ext( mbedtls_md2_context *ctx,
|
||||||
|
const unsigned char *input,
|
||||||
|
size_t ilen )
|
||||||
{
|
{
|
||||||
|
int ret;
|
||||||
size_t fill;
|
size_t fill;
|
||||||
|
|
||||||
while( ilen > 0 )
|
while( ilen > 0 )
|
||||||
|
@ -172,16 +179,21 @@ void mbedtls_md2_update( mbedtls_md2_context *ctx, const unsigned char *input, s
|
||||||
if( ctx->left == 16 )
|
if( ctx->left == 16 )
|
||||||
{
|
{
|
||||||
ctx->left = 0;
|
ctx->left = 0;
|
||||||
mbedtls_md2_process( ctx );
|
if( ( ret = mbedtls_md2_process_ext( ctx ) ) != 0 )
|
||||||
|
return( ret );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return( 0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* MD2 final digest
|
* MD2 final digest
|
||||||
*/
|
*/
|
||||||
void mbedtls_md2_finish( mbedtls_md2_context *ctx, unsigned char output[16] )
|
int mbedtls_md2_finish_ext( mbedtls_md2_context *ctx,
|
||||||
|
unsigned char output[16] )
|
||||||
{
|
{
|
||||||
|
int ret;
|
||||||
size_t i;
|
size_t i;
|
||||||
unsigned char x;
|
unsigned char x;
|
||||||
|
|
||||||
|
@ -190,12 +202,16 @@ void mbedtls_md2_finish( mbedtls_md2_context *ctx, unsigned char output[16] )
|
||||||
for( i = ctx->left; i < 16; i++ )
|
for( i = ctx->left; i < 16; i++ )
|
||||||
ctx->buffer[i] = x;
|
ctx->buffer[i] = x;
|
||||||
|
|
||||||
mbedtls_md2_process( ctx );
|
if( ( ret = mbedtls_md2_process_ext( ctx ) ) != 0 )
|
||||||
|
return( ret );
|
||||||
|
|
||||||
memcpy( ctx->buffer, ctx->cksum, 16 );
|
memcpy( ctx->buffer, ctx->cksum, 16 );
|
||||||
mbedtls_md2_process( ctx );
|
if( ( ret = mbedtls_md2_process_ext( ctx ) ) != 0 )
|
||||||
|
return( ret );
|
||||||
|
|
||||||
memcpy( output, ctx->state, 16 );
|
memcpy( output, ctx->state, 16 );
|
||||||
|
|
||||||
|
return( 0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* !MBEDTLS_MD2_ALT */
|
#endif /* !MBEDTLS_MD2_ALT */
|
||||||
|
@ -203,15 +219,28 @@ void mbedtls_md2_finish( mbedtls_md2_context *ctx, unsigned char output[16] )
|
||||||
/*
|
/*
|
||||||
* output = MD2( input buffer )
|
* output = MD2( input buffer )
|
||||||
*/
|
*/
|
||||||
void mbedtls_md2( const unsigned char *input, size_t ilen, unsigned char output[16] )
|
int mbedtls_md2_ext( const unsigned char *input,
|
||||||
|
size_t ilen,
|
||||||
|
unsigned char output[16] )
|
||||||
{
|
{
|
||||||
|
int ret;
|
||||||
mbedtls_md2_context ctx;
|
mbedtls_md2_context ctx;
|
||||||
|
|
||||||
mbedtls_md2_init( &ctx );
|
mbedtls_md2_init( &ctx );
|
||||||
mbedtls_md2_starts( &ctx );
|
|
||||||
mbedtls_md2_update( &ctx, input, ilen );
|
if( ( ret = mbedtls_md2_starts_ext( &ctx ) ) != 0 )
|
||||||
mbedtls_md2_finish( &ctx, output );
|
return( ret );
|
||||||
|
|
||||||
|
if( ( ret = mbedtls_md2_update_ext( &ctx, input, ilen ) ) != 0 )
|
||||||
|
return( ret );
|
||||||
|
|
||||||
|
if( ( ret = mbedtls_md2_finish_ext( &ctx, output ) ) != 0 )
|
||||||
|
return( ret );
|
||||||
|
|
||||||
|
|
||||||
mbedtls_md2_free( &ctx );
|
mbedtls_md2_free( &ctx );
|
||||||
|
|
||||||
|
return( 0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(MBEDTLS_SELF_TEST)
|
#if defined(MBEDTLS_SELF_TEST)
|
||||||
|
@ -262,16 +291,12 @@ int mbedtls_md2_self_test( int verbose )
|
||||||
if( verbose != 0 )
|
if( verbose != 0 )
|
||||||
mbedtls_printf( " MD2 test #%d: ", i + 1 );
|
mbedtls_printf( " MD2 test #%d: ", i + 1 );
|
||||||
|
|
||||||
mbedtls_md2( (unsigned char *) md2_test_str[i],
|
if( mbedtls_md2_ext( (unsigned char *)md2_test_str[i],
|
||||||
strlen( md2_test_str[i] ), md2sum );
|
strlen( md2_test_str[i] ), md2sum ) != 0 )
|
||||||
|
goto fail;
|
||||||
|
|
||||||
if( memcmp( md2sum, md2_test_sum[i], 16 ) != 0 )
|
if( memcmp( md2sum, md2_test_sum[i], 16 ) != 0 )
|
||||||
{
|
goto fail;
|
||||||
if( verbose != 0 )
|
|
||||||
mbedtls_printf( "failed\n" );
|
|
||||||
|
|
||||||
return( 1 );
|
|
||||||
}
|
|
||||||
|
|
||||||
if( verbose != 0 )
|
if( verbose != 0 )
|
||||||
mbedtls_printf( "passed\n" );
|
mbedtls_printf( "passed\n" );
|
||||||
|
@ -281,6 +306,12 @@ int mbedtls_md2_self_test( int verbose )
|
||||||
mbedtls_printf( "\n" );
|
mbedtls_printf( "\n" );
|
||||||
|
|
||||||
return( 0 );
|
return( 0 );
|
||||||
|
|
||||||
|
fail:
|
||||||
|
if( verbose != 0 )
|
||||||
|
mbedtls_printf( "failed\n" );
|
||||||
|
|
||||||
|
return( 1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* MBEDTLS_SELF_TEST */
|
#endif /* MBEDTLS_SELF_TEST */
|
||||||
|
|
Loading…
Reference in a new issue