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