]> git.lizzy.rs Git - plan9front.git/blob - sys/src/libsec/port/eggen.c
libsec: fix probably_prime() endless loop for n == 3
[plan9front.git] / sys / src / libsec / port / eggen.c
1 #include "os.h"
2 #include <mp.h>
3 #include <libsec.h>
4
5 EGpriv*
6 eggen(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 }