Back when it was still SSLeay, I got into a longish discussion with Eric about 
changes to the bignum code for the next release after 0.9.1.  I don't know how 
much of this stuff (if any) got into OpenSSL, but if anyone's working on 
maintaining the code I can dig up the feedback.  There were some bugfixes and 
speedups, but also general discussion on algorithms and whatnot, and I've got 
what I think is a slightly faster RSA keygen than SSLeay used (mind you the 
code was pretty incomprehensible in places, they might be the same thing).  
Some of the bugs:
 
-- Snip --
 
bn_fix_top is redefined in bn_lcl.h after being defined in bn.h.
 
In bn_blind.c, BN_BLINDING_new() will die if the first malloc fails, and at 
the end you're returning an invalid pointer instead of NULL.  Also you're not 
checking the return value elsewhere.
 
Calling abort() in bn_lib.c and bn_mulw.c is rather unfriendly (I've changed 
it to 'return( -1 )' and 'return( NULL )' as appropriate).
 
In bn_lib.c, BN_num_bits_word() shifts 'l', a 32-bit value, right.  This 
results in a flurry of warnings about loss of precision from Borland 
compilers, to get rid of this change the end of the function to:
 
                {
#if defined(THIRTY_TWO_BIT) || defined(SIXTY_FOUR_BIT) || defined(SIXTY_FOUR_BIT_LONG)
                if (l & 0xffff0000L)
                        {
                        if (l & 0xff000000L)
                                return(bits[(int)(l>>24)]+24);
                        else    return(bits[(int)(l>>16)]+16);
                        }
                else
#endif
                        {
#if defined(SIXTEEN_BIT) || defined(THIRTY_TWO_BIT) || defined(SIXTY_FOUR_BIT) || 
defined(SIXTY_FOUR_BIT_LONG)
                        if (l & 0xff00L)
                                return(bits[(int)(l>>8)]+8);
                        else
#endif
                                return(bits[(int)l   ]  );
                        }
                }
 
(ie add (int) casts when you shift the value).
 
In bn_mont.c, BN_from_montgomery, the value t1 is never used.
 
-- Snip --
 
There were a number of other bugs I found as well, if the above aren't already 
in the OpenSSL version I can try and dig up the notes I made.  There was also 
a discussion on memory usage, by changing the way the bignums are allocated 
it's possible to get a speedup of several percent (at least under VC++, which 
has a somewhat lethargic allocator) purely from the savings in allocation 
overhead.  I've got a whole lot of notes lying around (somewhere, I hope) on 
this and other issues if there's anyone who's maintaining the bignum code 
who's interested in them.
 
Peter.

______________________________________________________________________
OpenSSL Project                                 http://www.openssl.org
Development Mailing List                       [EMAIL PROTECTED]
Automated List Manager                           [EMAIL PROTECTED]

Reply via email to