1 #include "os.h" 2 #include <mp.h> 3 #include <libsec.h> 4 5 EGpriv* eggen(int nlen,int rounds)6eggen(int nlen, int rounds) 7 { 8 EGpub *pub; 9 EGpriv *priv; 10 11 priv = egprivalloc(); 12 pub = &priv->pub; 13 pub->p = mpnew(0); 14 pub->alpha = mpnew(0); 15 pub->key = mpnew(0); 16 priv->secret = mpnew(0); 17 gensafeprime(pub->p, pub->alpha, nlen, rounds); 18 mprand(nlen-1, genrandom, priv->secret); 19 mpexp(pub->alpha, priv->secret, pub->p, pub->key); 20 return priv; 21 } 22