@@ -769,14 +769,40 @@ static int pk_parse_key_pkcs1_der( mbedtls_rsa_context *rsa,
769
769
goto cleanup ;
770
770
p += len ;
771
771
772
- /* Complete the RSA private key */
773
- if ( ( ret = mbedtls_rsa_complete ( rsa ) ) != 0 )
774
- goto cleanup ;
772
+ #if !defined(MBEDTLS_RSA_NO_CRT )
773
+ /*
774
+ * The RSA CRT parameters DP, DQ and QP are nominally redundant, in
775
+ * that they can be easily recomputed from D, P and Q. However by
776
+ * parsing them from the PKCS1 structure it is possible to avoid
777
+ * recalculating them which both reduces the overhead of loading
778
+ * RSA private keys into memory and also avoids side channels which
779
+ * can arise when computing those values, since all of D, P, and Q
780
+ * are secret. See https://eprint.iacr.org/2020/055 for a
781
+ * description of one such attack.
782
+ */
783
+
784
+ /* Import DP */
785
+ if ( ( ret = mbedtls_asn1_get_mpi ( & p , end , & rsa -> DP ) ) != 0 )
786
+ goto cleanup ;
787
+
788
+ /* Import DQ */
789
+ if ( ( ret = mbedtls_asn1_get_mpi ( & p , end , & rsa -> DQ ) ) != 0 )
790
+ goto cleanup ;
791
+
792
+ /* Import QP */
793
+ if ( ( ret = mbedtls_asn1_get_mpi ( & p , end , & rsa -> QP ) ) != 0 )
794
+ goto cleanup ;
775
795
776
- /* Check optional parameters */
796
+ #else
797
+ /* Verify existance of the CRT params */
777
798
if ( ( ret = mbedtls_asn1_get_mpi ( & p , end , & T ) ) != 0 ||
778
799
( ret = mbedtls_asn1_get_mpi ( & p , end , & T ) ) != 0 ||
779
800
( ret = mbedtls_asn1_get_mpi ( & p , end , & T ) ) != 0 )
801
+ goto cleanup ;
802
+ #endif
803
+
804
+ /* Complete the RSA private key */
805
+ if ( ( ret = mbedtls_rsa_complete ( rsa ) ) != 0 )
780
806
goto cleanup ;
781
807
782
808
if ( p != end )
0 commit comments