Skip to content

Commit 8c2631b

Browse files
committed
Address review comments
1 parent 80cc811 commit 8c2631b

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

library/pkparse.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -769,6 +769,17 @@ static int pk_parse_key_pkcs1_der( mbedtls_rsa_context *rsa,
769769
goto cleanup;
770770
p += len;
771771

772+
/*
773+
* The RSA CRT parameters DP, DQ and QP are nominally redundant, in
774+
* that they can be easily recomputed from D, P and Q. However by
775+
* parsing them from the PKCS1 structure it is possible to avoid
776+
* recalculating them which both reduces the overhead of loading
777+
* RSA private keys into memory and also avoids side channels which
778+
* can arise when computing those values, since all of D, P, and Q
779+
* are secret. See https://eprint.iacr.org/2020/055 for a
780+
* description of one such attack.
781+
*/
782+
772783
/* Import DP */
773784
if( ( ret = mbedtls_asn1_get_tag( &p, end, &len,
774785
MBEDTLS_ASN1_INTEGER ) ) != 0 ||

library/rsa.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,10 @@ static int rsa_check_context( mbedtls_rsa_context const *ctx, int is_priv,
249249
int mbedtls_rsa_complete( mbedtls_rsa_context *ctx )
250250
{
251251
int ret = 0;
252-
int have_N, have_P, have_Q, have_D, have_E, have_DP, have_DQ, have_QP;
252+
int have_N, have_P, have_Q, have_D, have_E;
253+
#if !defined(MBEDTLS_RSA_NO_CRT)
254+
int have_DP, have_DQ, have_QP;
255+
#endif
253256
int n_missing, pq_missing, d_missing, is_pub, is_priv;
254257

255258
RSA_VALIDATE_RET( ctx != NULL );
@@ -259,10 +262,12 @@ int mbedtls_rsa_complete( mbedtls_rsa_context *ctx )
259262
have_Q = ( mbedtls_mpi_cmp_int( &ctx->Q, 0 ) != 0 );
260263
have_D = ( mbedtls_mpi_cmp_int( &ctx->D, 0 ) != 0 );
261264
have_E = ( mbedtls_mpi_cmp_int( &ctx->E, 0 ) != 0 );
265+
266+
#if !defined(MBEDTLS_RSA_NO_CRT)
262267
have_DP = ( mbedtls_mpi_cmp_int( &ctx->DP, 0 ) != 0 );
263268
have_DQ = ( mbedtls_mpi_cmp_int( &ctx->DQ, 0 ) != 0 );
264269
have_QP = ( mbedtls_mpi_cmp_int( &ctx->QP, 0 ) != 0 );
265-
270+
#endif
266271

267272
/*
268273
* Check whether provided parameters are enough

0 commit comments

Comments
 (0)