15 priv = dsaprivalloc();
19 pub->p = mpcopy(opub->p);
20 pub->q = mpcopy(opub->q);
24 DSAprimes(pub->q, pub->p, nil);
26 bits = Dbits*pub->p->top;
28 pub->alpha = mpnew(0);
30 priv->secret = mpnew(0);
32 // find a generator alpha of the multiplicative
33 // group Z*p, i.e., of order n = p-1. We use the
34 // fact that q divides p-1 to reduce the exponent.
38 mpsub(pub->p, mpone, exp);
39 mpdiv(exp, pub->q, exp, r);
40 if(mpcmp(r, mpzero) != 0)
41 sysfatal("dsagen foul up");
43 mprand(bits, genrandom, g);
45 mpexp(g, exp, pub->p, pub->alpha);
46 if(mpcmp(pub->alpha, mpone) != 0)
52 // create the secret key
53 mprand(bits, genrandom, priv->secret);
54 mpmod(priv->secret, pub->p, priv->secret);
55 mpexp(pub->alpha, priv->secret, pub->p, pub->key);