@@ -420,6 +420,7 @@ Please use `private_from_ec_scalar_with_rng` instead."
420420 let ctx = ret. inner . pk_ctx as * mut rsa_context ;
421421 rsa_import ( ctx, to_ptr ( n) , to_ptr ( p) , to_ptr ( q) , to_ptr ( d) , to_ptr ( e) ) . into_result ( ) ?;
422422 rsa_complete ( ctx) . into_result ( ) ?;
423+ rsa_check_privkey ( ctx) . into_result ( ) ?;
423424 }
424425 Ok ( ret)
425426 }
@@ -1657,6 +1658,21 @@ iy6KC991zzvaWY/Ys+q/84Afqa+0qJKQnPuy/7F5GkVdQA/lfbhi
16571658 assert_rsa_private_key_eq ( & pk, & pk3) ;
16581659 }
16591660
1661+ #[ test]
1662+ fn private_from_rsa_components_wrong_params ( ) {
1663+ let pk = Pk :: generate_rsa ( & mut crate :: test_support:: rand:: test_rng ( ) , 2048 , 0x10001 ) . unwrap ( ) ;
1664+ let components = RsaPrivateComponents :: WithPrimes {
1665+ p : & pk. rsa_private_prime1 ( ) . unwrap ( ) ,
1666+ q : & pk. rsa_private_prime2 ( ) . unwrap ( ) ,
1667+ e : & pk. rsa_public_modulus ( ) . unwrap ( ) , // incorrect
1668+ } ;
1669+ let err = match Pk :: private_from_rsa_components ( components) {
1670+ Ok ( _) => panic ! ( "expected an error, got a Pk" ) ,
1671+ Err ( e) => e,
1672+ } ;
1673+ assert_eq ! ( err, Error :: RsaKeyCheckFailed ) ;
1674+ }
1675+
16601676 #[ test]
16611677 fn public_from_rsa_components_sanity ( ) {
16621678 let mut pk = Pk :: generate_rsa ( & mut crate :: test_support:: rand:: test_rng ( ) , 2048 , 0x10001 ) . unwrap ( ) ;
0 commit comments