mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-02-06 12:40:02 +00:00
Extend blinding to RSA result check
Signed-off-by: Janos Follath <janos.follath@arm.com>
This commit is contained in:
parent
d6b096532c
commit
6bcbc925bf
@ -1113,8 +1113,6 @@ int mbedtls_rsa_private(mbedtls_rsa_context *ctx,
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
MBEDTLS_MPI_CHK(mbedtls_mpi_copy(&I, &T));
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Blinding
|
* Blinding
|
||||||
* T = T * Vi mod N
|
* T = T * Vi mod N
|
||||||
@ -1123,6 +1121,8 @@ int mbedtls_rsa_private(mbedtls_rsa_context *ctx,
|
|||||||
MBEDTLS_MPI_CHK(mbedtls_mpi_mul_mpi(&T, &T, &ctx->Vi));
|
MBEDTLS_MPI_CHK(mbedtls_mpi_mul_mpi(&T, &T, &ctx->Vi));
|
||||||
MBEDTLS_MPI_CHK(mbedtls_mpi_mod_mpi(&T, &T, &ctx->N));
|
MBEDTLS_MPI_CHK(mbedtls_mpi_mod_mpi(&T, &T, &ctx->N));
|
||||||
|
|
||||||
|
MBEDTLS_MPI_CHK(mbedtls_mpi_copy(&I, &T));
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Exponent blinding
|
* Exponent blinding
|
||||||
*/
|
*/
|
||||||
@ -1191,12 +1191,6 @@ int mbedtls_rsa_private(mbedtls_rsa_context *ctx,
|
|||||||
MBEDTLS_MPI_CHK(mbedtls_mpi_add_mpi(&T, &TQ, &TP));
|
MBEDTLS_MPI_CHK(mbedtls_mpi_add_mpi(&T, &TQ, &TP));
|
||||||
#endif /* MBEDTLS_RSA_NO_CRT */
|
#endif /* MBEDTLS_RSA_NO_CRT */
|
||||||
|
|
||||||
/*
|
|
||||||
* Unblind
|
|
||||||
* T = T * Vf mod N
|
|
||||||
*/
|
|
||||||
MBEDTLS_MPI_CHK(rsa_unblind(&T, &ctx->Vf, &ctx->N));
|
|
||||||
|
|
||||||
/* Verify the result to prevent glitching attacks. */
|
/* Verify the result to prevent glitching attacks. */
|
||||||
MBEDTLS_MPI_CHK(mbedtls_mpi_exp_mod(&C, &T, &ctx->E,
|
MBEDTLS_MPI_CHK(mbedtls_mpi_exp_mod(&C, &T, &ctx->E,
|
||||||
&ctx->N, &ctx->RN));
|
&ctx->N, &ctx->RN));
|
||||||
@ -1205,6 +1199,12 @@ int mbedtls_rsa_private(mbedtls_rsa_context *ctx,
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Unblind
|
||||||
|
* T = T * Vf mod N
|
||||||
|
*/
|
||||||
|
MBEDTLS_MPI_CHK(rsa_unblind(&T, &ctx->Vf, &ctx->N));
|
||||||
|
|
||||||
olen = ctx->len;
|
olen = ctx->len;
|
||||||
MBEDTLS_MPI_CHK(mbedtls_mpi_write_binary(&T, output, olen));
|
MBEDTLS_MPI_CHK(mbedtls_mpi_write_binary(&T, output, olen));
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user