>Not sure if you've seen it, but Hanno had some very interesting results with
>fuzzing crypto-relevant bignum implementations.
You don't know the half of it :-). Even without fuzzing, considerable bugs
have been discovered in bignum libraries. Not naming names, but look at the
code for the modmult and modexp routines used by certain libraries and see if
you'd want to feed attacker-controlled data to that stuff.
>His basic approach, I think, is to calculate the same value using two
>"competing" libraries or two algorithms that should give the same result, and
>then assert() if the output doesn't match.
This is, unfortunately, something that requires quite a bit of effort to do
(and I don't envy Hanno the amount of work he's probably had to put in). I
played with using PARI/GP (my go-to gold standard) for this, but you need to
write a pile of support code to do the A/B testing, eventually I shelved it
because there was more... outside incentivisation to re-paint the deck than to
fuzz bignum code :-).
Peter.
>What I thought of doing and haven't done yet: Creating a collection of test
>inputs that have triggered bugs in bignum libs in the past. That could be
>used as a test suite to see whether the same bug may be present in another
>library.
I'm not sure if that would be overly useful because a lot of the stuff would
be code-path-dependent. That is, it can't hurt, but being able to pass fixed
test vectors isn't a guarantee that the code is OK. AFL's ability to generate
inputs as required that exercise all the code paths is quite valuable here.
Another thing that's useful is generating vectors yourself based on what you
know the code is meant to do. For my own test vectors I used awkward corner
cases like all-one or all-zero bits with a one or zero in appropriate
locations, things I knew would cause issues with carries, funny shift
quantities, that sort of thing. To take the recent non-prime prime issue in
socat as an example, the chances of randomly hitting a prime when fuzzing are
pretty low so you need to help the fuzzer along a bit in some cases.
Peter.
>Another thing that's useful is generating vectors yourself based on what you
>know the code is meant to do.
Case in point:
In case of the BN_sqr() bug a possibility is simply to compare the result of
the squaring with a multiplication of a number by itself.
So the problem with this is that if your BN_mult() routine calls BN_sqr() if
the two input values are the same then you're really fuzzing BN_sqr() against
itself.
It's tricky to get right :-).
Peter.
What I thought of doing and haven't done yet: Creating a collection of
test inputs that have triggered bugs in bignum libs in the past. That
could be used as a test suite to see whether the same bug may be
present in another library.