diff --git a/sexp2rsa.c b/sexp2rsa.c
index 1027765a4363152bb131f852e803313b85b83d50..940296c2445b8475aa227713b9d689759de4497b 100644
--- a/sexp2rsa.c
+++ b/sexp2rsa.c
@@ -102,12 +102,18 @@ rsa_keypair_from_sexp(struct rsa_public_key *pub,
       GET(priv->a, &values[5]);
       GET(priv->b, &values[6]);
       GET(priv->c, &values[7]);
+
+      if (!rsa_prepare_private_key(priv))
+	return 0;
     }
 
   if (pub)
     {
       GET(pub->n, &values[0]);
       GET(pub->e, &values[1]);
+
+      if (!rsa_prepare_public_key(pub))
+	return 0;
     }
     
   return 1;