mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-07-09 07:13:43 -05:00
Rewrite invent_firstbits().
Instead of repeatedly looping on the random number generator until it comes up with two values that have a large enough product, the new version guarantees only one use of random numbers, by first counting up all the possible pairs of values that would work, and then inventing a single random number that's used as an index into that list. I've done the selection from the list using constant-time techniques, not particularly because I think key generation can be made CT in general, but out of sheer habit after the last few months, and who knows, it _might_ be useful. While I'm at it, I've also added an option to make sure the two firstbits values differ by at least a given value. For RSA, I set that value to 2, guaranteeing that even if the smaller prime has a very long string of 1 bits after the firstbits value and the larger has a long string of 0, they'll still have a relative difference of at least 2^{-12}. Not that there was any serious chance of the primes having randomly ended up so close together as to make the key in danger of factoring, but it seems like a silly thing to leave out if I'm rewriting the function anyway.
This commit is contained in:
Reference in New Issue
Block a user