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
2 changed files with 173 additions and 26 deletions
library
|
@ -105,16 +105,18 @@ void mbedtls_md2_clone( mbedtls_md2_context *dst,
|
|||
/*
|
||||
* 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->state, 0, 46 );
|
||||
memset( ctx->buffer, 0, 16 );
|
||||
ctx->left = 0;
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
#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;
|
||||
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] );
|
||||
t = ctx->cksum[i];
|
||||
}
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
#endif /* !MBEDTLS_MD2_PROCESS_ALT */
|
||||
|
||||
/*
|
||||
* 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;
|
||||
|
||||
while( ilen > 0 )
|
||||
|
@ -172,16 +179,21 @@ void mbedtls_md2_update( mbedtls_md2_context *ctx, const unsigned char *input, s
|
|||
if( ctx->left == 16 )
|
||||
{
|
||||
ctx->left = 0;
|
||||
mbedtls_md2_process( ctx );
|
||||
if( ( ret = mbedtls_md2_process_ext( ctx ) ) != 0 )
|
||||
return( ret );
|
||||
}
|
||||
}
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
/*
|
||||
* 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;
|
||||
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++ )
|
||||
ctx->buffer[i] = x;
|
||||
|
||||
mbedtls_md2_process( ctx );
|
||||
if( ( ret = mbedtls_md2_process_ext( ctx ) ) != 0 )
|
||||
return( ret );
|
||||
|
||||
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 );
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
#endif /* !MBEDTLS_MD2_ALT */
|
||||
|
@ -203,15 +219,28 @@ void mbedtls_md2_finish( mbedtls_md2_context *ctx, unsigned char output[16] )
|
|||
/*
|
||||
* 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_init( &ctx );
|
||||
mbedtls_md2_starts( &ctx );
|
||||
mbedtls_md2_update( &ctx, input, ilen );
|
||||
mbedtls_md2_finish( &ctx, output );
|
||||
|
||||
if( ( ret = mbedtls_md2_starts_ext( &ctx ) ) != 0 )
|
||||
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 );
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
#if defined(MBEDTLS_SELF_TEST)
|
||||
|
@ -262,16 +291,12 @@ int mbedtls_md2_self_test( int verbose )
|
|||
if( verbose != 0 )
|
||||
mbedtls_printf( " MD2 test #%d: ", i + 1 );
|
||||
|
||||
mbedtls_md2( (unsigned char *) md2_test_str[i],
|
||||
strlen( md2_test_str[i] ), md2sum );
|
||||
if( mbedtls_md2_ext( (unsigned char *)md2_test_str[i],
|
||||
strlen( md2_test_str[i] ), md2sum ) != 0 )
|
||||
goto fail;
|
||||
|
||||
if( memcmp( md2sum, md2_test_sum[i], 16 ) != 0 )
|
||||
{
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "failed\n" );
|
||||
|
||||
return( 1 );
|
||||
}
|
||||
goto fail;
|
||||
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "passed\n" );
|
||||
|
@ -281,6 +306,12 @@ int mbedtls_md2_self_test( int verbose )
|
|||
mbedtls_printf( "\n" );
|
||||
|
||||
return( 0 );
|
||||
|
||||
fail:
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "failed\n" );
|
||||
|
||||
return( 1 );
|
||||
}
|
||||
|
||||
#endif /* MBEDTLS_SELF_TEST */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue