mirror of
https://github.com/yuzu-emu/mbedtls
synced 2024-11-25 20:48:13 +00:00
Faster mbedtls_zeroize for MPI
Writes in `sizeof(mbedtls_mpi_uint)` units perform faster than plain chars, also eliminates multiplication by `ciL`
This commit is contained in:
parent
8a3170571e
commit
3d53f41638
1 changed files with 5 additions and 5 deletions
|
@ -59,8 +59,8 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Implementation that should never be optimized out by the compiler */
|
/* Implementation that should never be optimized out by the compiler */
|
||||||
static void mbedtls_zeroize( void *v, size_t n ) {
|
static void mbedtls_zeroize( mbedtls_mpi_uint *v, size_t n ) {
|
||||||
volatile unsigned char *p = v; while( n-- ) *p++ = 0;
|
volatile mbedtls_mpi_uint *p = v; while( n-- ) *p++ = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define ciL (sizeof(mbedtls_mpi_uint)) /* chars in limb */
|
#define ciL (sizeof(mbedtls_mpi_uint)) /* chars in limb */
|
||||||
|
@ -99,7 +99,7 @@ void mbedtls_mpi_free( mbedtls_mpi *X )
|
||||||
|
|
||||||
if( X->p != NULL )
|
if( X->p != NULL )
|
||||||
{
|
{
|
||||||
mbedtls_zeroize( X->p, X->n * ciL );
|
mbedtls_zeroize( X->p, X->n );
|
||||||
mbedtls_free( X->p );
|
mbedtls_free( X->p );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -126,7 +126,7 @@ int mbedtls_mpi_grow( mbedtls_mpi *X, size_t nblimbs )
|
||||||
if( X->p != NULL )
|
if( X->p != NULL )
|
||||||
{
|
{
|
||||||
memcpy( p, X->p, X->n * ciL );
|
memcpy( p, X->p, X->n * ciL );
|
||||||
mbedtls_zeroize( X->p, X->n * ciL );
|
mbedtls_zeroize( X->p, X->n );
|
||||||
mbedtls_free( X->p );
|
mbedtls_free( X->p );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -164,7 +164,7 @@ int mbedtls_mpi_shrink( mbedtls_mpi *X, size_t nblimbs )
|
||||||
if( X->p != NULL )
|
if( X->p != NULL )
|
||||||
{
|
{
|
||||||
memcpy( p, X->p, i * ciL );
|
memcpy( p, X->p, i * ciL );
|
||||||
mbedtls_zeroize( X->p, X->n * ciL );
|
mbedtls_zeroize( X->p, X->n );
|
||||||
mbedtls_free( X->p );
|
mbedtls_free( X->p );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue