6 rsagen(int nlen, int elen, int rounds)
8 mpint *p, *q, *e, *d, *phi, *n, *t1, *t2, *kp, *kq, *c2;
18 // create the prime factors and euclid's function
19 genprime(p, nlen/2, rounds);
20 genprime(q, nlen - mpsignif(p) + 1, rounds);
26 // find an e relatively prime to phi
29 mprand(elen, genrandom, e);
30 if(mpcmp(e,mptwo) <= 0)
32 // See Menezes et al. p.291 "8.8 Note (selecting primes)" for discussion
33 // of the merits of various choices of primes and exponents. e=3 is a
34 // common and recommended exponent, but doesn't necessarily work here
35 // because we chose strong rather than safe primes.
37 mpextendedgcd(e, phi, t1, d, t2);
38 if(mpcmp(t1, mpone) == 0)
45 // compute chinese remainder coefficient
49 // for crt a**k mod p == (a**(k mod p-1)) mod p