mirror of
https://github.com/yuzu-emu/mbedtls.git
synced 2024-11-26 19:25:42 +01:00
Improve speed of PBKDF2 by caching the digest state of the passphrase
This commit is contained in:
parent
3f20efc030
commit
71657493f1
@ -243,13 +243,12 @@ int mbedtls_pkcs5_pbkdf2_hmac( mbedtls_md_context_t *ctx,
|
|||||||
return( MBEDTLS_ERR_PKCS5_BAD_INPUT_DATA );
|
return( MBEDTLS_ERR_PKCS5_BAD_INPUT_DATA );
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
if( ( ret = mbedtls_md_hmac_starts( ctx, password, plen ) ) != 0 )
|
||||||
|
return( ret );
|
||||||
while( key_length )
|
while( key_length )
|
||||||
{
|
{
|
||||||
// U1 ends up in work
|
// U1 ends up in work
|
||||||
//
|
//
|
||||||
if( ( ret = mbedtls_md_hmac_starts( ctx, password, plen ) ) != 0 )
|
|
||||||
return( ret );
|
|
||||||
|
|
||||||
if( ( ret = mbedtls_md_hmac_update( ctx, salt, slen ) ) != 0 )
|
if( ( ret = mbedtls_md_hmac_update( ctx, salt, slen ) ) != 0 )
|
||||||
return( ret );
|
return( ret );
|
||||||
|
|
||||||
@ -259,21 +258,24 @@ int mbedtls_pkcs5_pbkdf2_hmac( mbedtls_md_context_t *ctx,
|
|||||||
if( ( ret = mbedtls_md_hmac_finish( ctx, work ) ) != 0 )
|
if( ( ret = mbedtls_md_hmac_finish( ctx, work ) ) != 0 )
|
||||||
return( ret );
|
return( ret );
|
||||||
|
|
||||||
|
if( ( ret = mbedtls_md_hmac_reset( ctx ) ) != 0 )
|
||||||
|
return( ret );
|
||||||
|
|
||||||
memcpy( md1, work, md_size );
|
memcpy( md1, work, md_size );
|
||||||
|
|
||||||
for( i = 1; i < iteration_count; i++ )
|
for( i = 1; i < iteration_count; i++ )
|
||||||
{
|
{
|
||||||
// U2 ends up in md1
|
// U2 ends up in md1
|
||||||
//
|
//
|
||||||
if( ( ret = mbedtls_md_hmac_starts( ctx, password, plen ) ) != 0 )
|
|
||||||
return( ret );
|
|
||||||
|
|
||||||
if( ( ret = mbedtls_md_hmac_update( ctx, md1, md_size ) ) != 0 )
|
if( ( ret = mbedtls_md_hmac_update( ctx, md1, md_size ) ) != 0 )
|
||||||
return( ret );
|
return( ret );
|
||||||
|
|
||||||
if( ( ret = mbedtls_md_hmac_finish( ctx, md1 ) ) != 0 )
|
if( ( ret = mbedtls_md_hmac_finish( ctx, md1 ) ) != 0 )
|
||||||
return( ret );
|
return( ret );
|
||||||
|
|
||||||
|
if( ( ret = mbedtls_md_hmac_reset( ctx ) ) != 0 )
|
||||||
|
return( ret );
|
||||||
|
|
||||||
// U1 xor U2
|
// U1 xor U2
|
||||||
//
|
//
|
||||||
for( j = 0; j < md_size; j++ )
|
for( j = 0; j < md_size; j++ )
|
||||||
|
Loading…
Reference in New Issue
Block a user