mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-07-18 19:41:01 -05:00
New API for primegen(), using PrimeCandidateSource.
The more features and options I add to PrimeCandidateSource, the more cumbersome it will be to replicate each one in a command-line option to the ultimate primegen() function. So I'm moving to an API in which the client of primegen() constructs a PrimeCandidateSource themself, and passes it in to primegen(). Also, changed the API for pcs_new() so that you don't have to pass 'firstbits' unless you really want to. The net effect is that even though we've added flexibility, we've also simplified the call sites of primegen() in the simple case: if you want a 1234-bit prime, you just need to pass pcs_new(1234) as the argument to primegen, and you're done. The new declaration of primegen() lives in ssh_keygen.h, along with all the types it depends on. So I've had to #include that header in a few new files.
This commit is contained in:
11
sshdssg.c
11
sshdssg.c
@ -4,6 +4,7 @@
|
||||
|
||||
#include "misc.h"
|
||||
#include "ssh.h"
|
||||
#include "sshkeygen.h"
|
||||
#include "mpint.h"
|
||||
|
||||
int dsa_generate(struct dss_key *key, int bits, progfn_t pfn,
|
||||
@ -56,15 +57,21 @@ int dsa_generate(struct dss_key *key, int bits, progfn_t pfn,
|
||||
|
||||
pfn(pfnparam, PROGFN_READY, 0, 0);
|
||||
|
||||
PrimeCandidateSource *pcs;
|
||||
|
||||
/*
|
||||
* Generate q: a prime of length 160.
|
||||
*/
|
||||
mp_int *q = primegen(160, 0, 0, NULL, 1, pfn, pfnparam, 1);
|
||||
pcs = pcs_new(160);
|
||||
mp_int *q = primegen(pcs, 1, pfn, pfnparam);
|
||||
|
||||
/*
|
||||
* Now generate p: a prime of length `bits', such that p-1 is
|
||||
* divisible by q.
|
||||
*/
|
||||
mp_int *p = primegen(bits, 0, 0, q, 2, pfn, pfnparam, 1);
|
||||
pcs = pcs_new(bits);
|
||||
pcs_require_residue_1(pcs, q);
|
||||
mp_int *p = primegen(pcs, 2, pfn, pfnparam);
|
||||
|
||||
/*
|
||||
* Next we need g. Raise 2 to the power (p-1)/q modulo p, and
|
||||
|
Reference in New Issue
Block a user