mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-07-05 21:42:47 -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:
2
ssh.h
2
ssh.h
@ -1172,7 +1172,7 @@ int eddsa_generate(struct eddsa_key *key, int bits, progfn_t pfn,
|
||||
mp_int *primegen(
|
||||
int bits, int modulus, int residue, mp_int *factor,
|
||||
int phase, progfn_t pfn, void *pfnparam, unsigned firstbits);
|
||||
void invent_firstbits(unsigned *one, unsigned *two);
|
||||
void invent_firstbits(unsigned *one, unsigned *two, unsigned min_separation);
|
||||
|
||||
/*
|
||||
* Connection-sharing API provided by platforms. This function must
|
||||
|
Reference in New Issue
Block a user