[openssl-dev] [openssl.org #4485] big number tests and Math::BigInt changes

Richard Levitte via RT rt at openssl.org
Fri Mar 25 21:29:51 UTC 2016

Vid Fre, 25 Mar 2016 kl. 20.51.10, skrev craigberry at mac.com:
> I reported this to the Math::BigInt maintainer, who explains that the
> change fixes a bug in which, "The code did truncated division whereas
> the documentation said that floored division was used" and he changed
> the code to match the documentation. See:

BN_div does truncated division, which is expressed in other terms in
the comment in crypto/bn/bn_div.c:

/*- * BN_div computes dv := num / divisor, rounding towards * zero, and sets up
rm such that dv*divisor + rm = num holds. * Thus: * dv->neg == num->neg ^
divisor->neg (unless the result is zero) * rm->neg == num->neg (unless the
remainder is zero) * If 'dv' or 'rm' is NULL, the respective value is not
returned. */
keywords being "rounding towards zero".
> Or is truncated division intentional and we now have a problem using
> Math::BigInt as a reference since that’s not what it does anymore?

I wouldn't dare change BN_div's behaviour in this regard. It might not be
as mathematically correct, but there's too much else possibly relying on
the current behaviour.

However, if you have a look at test/recipes/bc.pl, you'll see that there's
a "fix" of modulo because there's already a difference between what
OpenSSL's modulo does and what Math::BigInt's modulo does. I don't
think it would be too hard to do something similar for division.

> but I have also reproduced the test failures on OS X by just doing:
> $ sudo cpan -i Math::BigInt


Richard Levitte
levitte at openssl.org

Ticket here: http://rt.openssl.org/Ticket/Display.html?id=4485
Please log in as guest with password guest if prompted

More information about the openssl-dev mailing list