mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-03-26 11:37:09 +00:00
RSA: remove unneeded temporaries
Signed-off-by: Janos Follath <janos.follath@arm.com>
This commit is contained in:
parent
e6750b2a0b
commit
47ee770812
@ -1056,18 +1056,9 @@ int mbedtls_rsa_private(mbedtls_rsa_context *ctx,
|
|||||||
/* Temporaries holding the blinded exponents for
|
/* Temporaries holding the blinded exponents for
|
||||||
* the mod p resp. mod q computation (if used). */
|
* the mod p resp. mod q computation (if used). */
|
||||||
mbedtls_mpi DP_blind, DQ_blind;
|
mbedtls_mpi DP_blind, DQ_blind;
|
||||||
|
|
||||||
/* Pointers to actual exponents to be used - either the unblinded
|
|
||||||
* or the blinded ones, depending on the presence of a PRNG. */
|
|
||||||
mbedtls_mpi *DP = &ctx->DP;
|
|
||||||
mbedtls_mpi *DQ = &ctx->DQ;
|
|
||||||
#else
|
#else
|
||||||
/* Temporary holding the blinded exponent (if used). */
|
/* Temporary holding the blinded exponent (if used). */
|
||||||
mbedtls_mpi D_blind;
|
mbedtls_mpi D_blind;
|
||||||
|
|
||||||
/* Pointer to actual exponent to be used - either the unblinded
|
|
||||||
* or the blinded one, depending on the presence of a PRNG. */
|
|
||||||
mbedtls_mpi *D = &ctx->D;
|
|
||||||
#endif /* MBEDTLS_RSA_NO_CRT */
|
#endif /* MBEDTLS_RSA_NO_CRT */
|
||||||
|
|
||||||
/* Temporaries holding the initial input and the double
|
/* Temporaries holding the initial input and the double
|
||||||
@ -1143,8 +1134,6 @@ int mbedtls_rsa_private(mbedtls_rsa_context *ctx,
|
|||||||
MBEDTLS_MPI_CHK(mbedtls_mpi_mul_mpi(&D_blind, &P1, &Q1));
|
MBEDTLS_MPI_CHK(mbedtls_mpi_mul_mpi(&D_blind, &P1, &Q1));
|
||||||
MBEDTLS_MPI_CHK(mbedtls_mpi_mul_mpi(&D_blind, &D_blind, &R));
|
MBEDTLS_MPI_CHK(mbedtls_mpi_mul_mpi(&D_blind, &D_blind, &R));
|
||||||
MBEDTLS_MPI_CHK(mbedtls_mpi_add_mpi(&D_blind, &D_blind, &ctx->D));
|
MBEDTLS_MPI_CHK(mbedtls_mpi_add_mpi(&D_blind, &D_blind, &ctx->D));
|
||||||
|
|
||||||
D = &D_blind;
|
|
||||||
#else
|
#else
|
||||||
/*
|
/*
|
||||||
* DP_blind = ( P - 1 ) * R + DP
|
* DP_blind = ( P - 1 ) * R + DP
|
||||||
@ -1155,8 +1144,6 @@ int mbedtls_rsa_private(mbedtls_rsa_context *ctx,
|
|||||||
MBEDTLS_MPI_CHK(mbedtls_mpi_add_mpi(&DP_blind, &DP_blind,
|
MBEDTLS_MPI_CHK(mbedtls_mpi_add_mpi(&DP_blind, &DP_blind,
|
||||||
&ctx->DP));
|
&ctx->DP));
|
||||||
|
|
||||||
DP = &DP_blind;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* DQ_blind = ( Q - 1 ) * R + DQ
|
* DQ_blind = ( Q - 1 ) * R + DQ
|
||||||
*/
|
*/
|
||||||
@ -1165,12 +1152,10 @@ int mbedtls_rsa_private(mbedtls_rsa_context *ctx,
|
|||||||
MBEDTLS_MPI_CHK(mbedtls_mpi_mul_mpi(&DQ_blind, &Q1, &R));
|
MBEDTLS_MPI_CHK(mbedtls_mpi_mul_mpi(&DQ_blind, &Q1, &R));
|
||||||
MBEDTLS_MPI_CHK(mbedtls_mpi_add_mpi(&DQ_blind, &DQ_blind,
|
MBEDTLS_MPI_CHK(mbedtls_mpi_add_mpi(&DQ_blind, &DQ_blind,
|
||||||
&ctx->DQ));
|
&ctx->DQ));
|
||||||
|
|
||||||
DQ = &DQ_blind;
|
|
||||||
#endif /* MBEDTLS_RSA_NO_CRT */
|
#endif /* MBEDTLS_RSA_NO_CRT */
|
||||||
|
|
||||||
#if defined(MBEDTLS_RSA_NO_CRT)
|
#if defined(MBEDTLS_RSA_NO_CRT)
|
||||||
MBEDTLS_MPI_CHK(mbedtls_mpi_exp_mod(&T, &T, D, &ctx->N, &ctx->RN));
|
MBEDTLS_MPI_CHK(mbedtls_mpi_exp_mod(&T, &T, &D_blind, &ctx->N, &ctx->RN));
|
||||||
#else
|
#else
|
||||||
/*
|
/*
|
||||||
* Faster decryption using the CRT
|
* Faster decryption using the CRT
|
||||||
@ -1179,8 +1164,8 @@ int mbedtls_rsa_private(mbedtls_rsa_context *ctx,
|
|||||||
* TQ = input ^ dQ mod Q
|
* TQ = input ^ dQ mod Q
|
||||||
*/
|
*/
|
||||||
|
|
||||||
MBEDTLS_MPI_CHK(mbedtls_mpi_exp_mod(&TP, &T, DP, &ctx->P, &ctx->RP));
|
MBEDTLS_MPI_CHK(mbedtls_mpi_exp_mod(&TP, &T, &DP_blind, &ctx->P, &ctx->RP));
|
||||||
MBEDTLS_MPI_CHK(mbedtls_mpi_exp_mod(&TQ, &T, DQ, &ctx->Q, &ctx->RQ));
|
MBEDTLS_MPI_CHK(mbedtls_mpi_exp_mod(&TQ, &T, &DQ_blind, &ctx->Q, &ctx->RQ));
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* T = (TP - TQ) * (Q^-1 mod P) mod P
|
* T = (TP - TQ) * (Q^-1 mod P) mod P
|
||||||
|
Loading…
x
Reference in New Issue
Block a user