Fix for RSA private key encryption if p < q. This took ***ages*** to track down.

This commit is contained in:
Dr. Stephen Henson
1999-03-11 02:42:13 +00:00
parent 47c389e7cc
commit abd4c91527
2 changed files with 14 additions and 0 deletions

View File

@@ -473,6 +473,15 @@ RSA *rsa;
if (!BN_mul(&r1,r0,rsa->iqmp,ctx)) goto err;
if (!BN_mod(r0,&r1,rsa->p,ctx)) goto err;
/* If p < q it is occasionally possible for the correction of
* adding 'p' if r0 is negative above to leave the result still
* negative. This can break the private key operations: the following
* second correction should *always* correct this rare occurrence.
* This will *never* happen with OpenSSL generated keys because
* they ensure p > q [steve]
*/
if (r0->neg)
if (!BN_add(r0,r0,rsa->p)) goto err;
if (!BN_mul(&r1,r0,rsa->q,ctx)) goto err;
if (!BN_add(r0,&r1,&m1)) goto err;