Bignum mathematical accuracy regression in r31695
We have some pure Ruby code which performs a DH (Diffie Hellman) cryptographic
If I upgrade to using the Ruby 1.9.3 interpreter instead of 1.9.2, the unit
tests around the code fail, because the client and server can no longer
compute matching secret keys. I would expect they could agree on matching keys
as the DH algorithm expects. The code worked fine since May 2007 on Ruby 1.8
and 1.9 until the commit below was introduced.
Using svn-bisect, I was able to find that this commit from ruby-trunk in
between Ruby 1.9.2 (27656) and Ruby 1.9.3 (32500) causes the problem:
r31695 | mrkn | 2011-05-22 08:37:00 -0700 (Sun, 22 May 2011) | 4 lines
- bignum.c (dump_bignum, bigmul1_balance, big_split, biglsh_bang,
bigrsh_bang, big_split3, bigmul1_toom3, bigmul0): implement Toom3 (Toom-Cook)
- include/ruby/defines.h: add format prefixes for BDIGIT and BDIGIT_DBL.
Attached to this bug I have a simplified example test case which will pass
without this commit, and fail with this commit present.
Since this commit covers some relatively complex mathematical algorithms I'd
appreciate some assistance in finding the root cause from the experts on how
bignum.c works. I think the bug is relatively serious because it could cause
inaccurate output for other mathematical code using Bignums since it was
introduced in mid-2011.
This ruby -v comes from ruby trunk SVN at revision 31695, where the failure
begins to happen. I hand-re-compiled at the bisection points on trunk from
27655 through 32501 to identify the one which caused the problem.
$ ruby -v
ruby 1.9.3dev (2011-05-22 trunk 31695) [x86_64-linux]
C Compiler: gcc (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3