Subject: | Better primality testing in CryptX (libtomcrypt/libtommath) |
This RT is based on Dana Jacobsen's comment in another RT:
Show quoted text
> There are two issues. One is doing only 8 tests, which doesn't bother
> me quite so much as the next. At 160 bits, 8 tests should give us a
> better than 1e-15 chance of failure on random inputs (using
> Damgård/Landrock/Pomerance calculations, which based on their table 1
> are conservative). If the input is chosen by an adversary, then only
> 1.5e-5. That seems high to me. But this is just being lax with the
> probability, which I wouldn't claim is "broken".
>
> My main issue is that it uses the first k prime bases for its tests.
> If I have a random number from 1 to 1M and ask you to guess it, your
> chances are 1 in 1 million. But if I never change my number, and
> you're allowed to keep guessing and talk to everyone else who's
> played, then the chances are no longer 1 in 1M, and once you know my
> number then you can guess it every time. That's essentially what
> using a fixed set of bases is doing. There are known numbers that
> pass the first 168 prime bases. Arnault in 1994 wrote a paper showing
> how to construct numbers that pass many given bases.
>
> This is a big issue if you're exposing the is-prime function to
> anything that can select its number (e.g. a user like Perl 6 does).
> For DSA use it doesn't seem obviously as bad since the input numbers
> are not user-chosen, but cryptography is a bad place to say "I can't
> think of how the known weakness can be exploited, so I guess it's ok."
>
> We could:
>
> - prove the primality. Fantastic for security, but requires a non-
> trivial implementation (For Crypt::DSA::GMP I'm using
> Math::Prime::Util::GMP) and is always going to be a performance
> concern. With MPU:GMP, it's almost free for < 256-bit, but gets quite
> noticeable after 1024 or so bits, and probably too slow for this
> application once in the 4096-bit range. WraithX has a nice APRCL
> implementation that looks promising also. Both are in GMP however,
> and would be quite a bit of work to put in libtommath.
>
> - BPSW + optional number of random [2, n-2] M-R bases. In my opinion
> the best solution, meets FIPS requirements, and good performance.
> This is what I'm doing in Crypt::DSA::GMP when not proving primality.
> See next item.
>
> - BPSW. Requires adding a Lucas test to libtommath, which isn't too
> hard (~40-100 lines of code), but you have to get it integrated into
> libtommath. ltm is kind of built around the idea of multiple M-R
> tests, which is a very 1980's way to do things. By itself BPSW isn't
> FIPS compliant, though it is what almost all math packages use now.
> FIPS wants some extra M-R tests.
>
> - M-R with random (in range [2,n-2]) bases. FIPS compliant, though
> they want a huge number of bases if you're not using a Lucas test.
>
>
> While random bases prevent a lot of crytographic attacks, it makes
> debugging more of a problem since you can't reproduce any failure.
> Since the BPSW test has no known counterexamples, it's unlikely to
> ever come up if you do that first.