mirror of
https://github.com/yuzu-emu/mbedtls.git
synced 2024-11-29 08:04:24 +01:00
RSA blinding threading support
This commit is contained in:
parent
1337affc91
commit
c9965dca27
@ -32,6 +32,10 @@
|
|||||||
#include "bignum.h"
|
#include "bignum.h"
|
||||||
#include "md.h"
|
#include "md.h"
|
||||||
|
|
||||||
|
#if defined(POLARSSL_THREADING_C)
|
||||||
|
#include "threading.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* RSA Error codes
|
* RSA Error codes
|
||||||
*/
|
*/
|
||||||
@ -100,6 +104,9 @@ typedef struct
|
|||||||
specified in the md.h header file
|
specified in the md.h header file
|
||||||
for the EME-OAEP and EMSA-PSS
|
for the EME-OAEP and EMSA-PSS
|
||||||
encoding */
|
encoding */
|
||||||
|
#if defined(POLARSSL_THREADING_C)
|
||||||
|
threading_mutex_t mutex; /*!< Thread-safety mutex */
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
rsa_context;
|
rsa_context;
|
||||||
|
|
||||||
|
@ -54,6 +54,10 @@ void rsa_init( rsa_context *ctx,
|
|||||||
|
|
||||||
ctx->padding = padding;
|
ctx->padding = padding;
|
||||||
ctx->hash_id = hash_id;
|
ctx->hash_id = hash_id;
|
||||||
|
|
||||||
|
#if defined(POLARSSL_THREADING_C)
|
||||||
|
polarssl_mutex_init( &ctx->mutex );
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(POLARSSL_GENPRIME)
|
#if defined(POLARSSL_GENPRIME)
|
||||||
@ -298,6 +302,9 @@ int rsa_private( rsa_context *ctx,
|
|||||||
unsigned char *output )
|
unsigned char *output )
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
|
#if defined(POLARSSL_THREADING_C)
|
||||||
|
int locked = 0;
|
||||||
|
#endif
|
||||||
size_t olen;
|
size_t olen;
|
||||||
mpi T, T1, T2;
|
mpi T, T1, T2;
|
||||||
|
|
||||||
@ -315,6 +322,10 @@ int rsa_private( rsa_context *ctx,
|
|||||||
#else
|
#else
|
||||||
if( f_rng != NULL )
|
if( f_rng != NULL )
|
||||||
{
|
{
|
||||||
|
#if defined(POLARSSL_THREADING_C)
|
||||||
|
polarssl_mutex_lock( &ctx->mutex );
|
||||||
|
locked = 1;
|
||||||
|
#endif
|
||||||
/*
|
/*
|
||||||
* Blinding
|
* Blinding
|
||||||
* T = T * Vi mod N
|
* T = T * Vi mod N
|
||||||
@ -361,7 +372,10 @@ int rsa_private( rsa_context *ctx,
|
|||||||
MPI_CHK( mpi_write_binary( &T, output, olen ) );
|
MPI_CHK( mpi_write_binary( &T, output, olen ) );
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
|
#if defined(POLARSSL_THREADING_C)
|
||||||
|
if( locked )
|
||||||
|
polarssl_mutex_unlock( &ctx->mutex );
|
||||||
|
#endif
|
||||||
mpi_free( &T ); mpi_free( &T1 ); mpi_free( &T2 );
|
mpi_free( &T ); mpi_free( &T1 ); mpi_free( &T2 );
|
||||||
|
|
||||||
if( ret != 0 )
|
if( ret != 0 )
|
||||||
@ -1330,6 +1344,10 @@ void rsa_free( rsa_context *ctx )
|
|||||||
mpi_free( &ctx->QP ); mpi_free( &ctx->DQ ); mpi_free( &ctx->DP );
|
mpi_free( &ctx->QP ); mpi_free( &ctx->DQ ); mpi_free( &ctx->DP );
|
||||||
mpi_free( &ctx->Q ); mpi_free( &ctx->P ); mpi_free( &ctx->D );
|
mpi_free( &ctx->Q ); mpi_free( &ctx->P ); mpi_free( &ctx->D );
|
||||||
mpi_free( &ctx->E ); mpi_free( &ctx->N );
|
mpi_free( &ctx->E ); mpi_free( &ctx->N );
|
||||||
|
|
||||||
|
#if defined(POLARSSL_THREADING_C)
|
||||||
|
polarssl_mutex_free( &ctx->mutex );
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(POLARSSL_SELF_TEST)
|
#if defined(POLARSSL_SELF_TEST)
|
||||||
|
Loading…
Reference in New Issue
Block a user