]> granicus.if.org Git - openssl/commitdiff
Fix a bug which caused BN_div to produce the
authorDr. Stephen Henson <steve@openssl.org>
Wed, 28 Feb 2001 00:51:48 +0000 (00:51 +0000)
committerDr. Stephen Henson <steve@openssl.org>
Wed, 28 Feb 2001 00:51:48 +0000 (00:51 +0000)
wrong result if rm==num and num < 0.

CHANGES
crypto/bn/bn_div.c

diff --git a/CHANGES b/CHANGES
index 6a2480b24cbfe2d34bb644e52c4513542d901c38..753853c8fa869803b5eef4fab78e2ff20028bae3 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -3,6 +3,12 @@
 
  Changes between 0.9.6 and 0.9.7  [xx XXX 2000]
 
+  *) In BN_div() keep a copy of the sign of 'num' before writing the
+     result to 'rm' because if rm==num the value will be overwritten
+     and produce the wrong result if 'num' is negative: this caused
+     problems with BN_mod() and BN_nnmod().
+     [Steve Henson]
+
   *) Function OCSP_request_verify(). This checks the signature on an
      OCSP request and verifies the signer certificate. The signer
      certificate is just checked for a generic purpose and OCSP request
index 7bee1dcc724efa8dc91034d7adc4c39053c258f2..bbd09940089cf38cabc3f014f04682c083413dca 100644 (file)
@@ -342,9 +342,13 @@ int BN_div(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num, const BIGNUM *divisor,
                }
        if (rm != NULL)
                {
+               /* Keep a copy of the neg flag in num because if rm==num
+                * BN_rshift() will overwrite it.
+                */
+               int neg = num->neg;
                BN_rshift(rm,snum,norm_shift);
                if (!BN_is_zero(rm))
-                       rm->neg = num->neg;
+                       rm->neg = neg;
                }
        BN_CTX_end(ctx);
        return(1);