1 #include "os.h"
2 #include <mp.h>
3 #include <libsec.h>
4 
5 mpint*
egdecrypt(EGpriv * priv,mpint * in,mpint * out)6 egdecrypt(EGpriv *priv, mpint *in, mpint *out)
7 {
8 	EGpub *pub = &priv->pub;
9 	mpint *gamma, *delta;
10 	mpint *p = pub->p;
11 	int plen = mpsignif(p)+1;
12 	int shift = ((plen+Dbits-1)/Dbits)*Dbits;
13 
14 	if(out == nil)
15 		out = mpnew(0);
16 	gamma = mpnew(0);
17 	delta = mpnew(0);
18 	mpright(in, shift, gamma);
19 	mpleft(gamma, shift, delta);
20 	mpsub(in, delta, delta);
21 	mpexp(gamma, priv->secret, p, out);
22 	mpinvert(out, p, gamma);
23 	mpmul(gamma, delta, out);
24 	mpmod(out, p, out);
25 	mpfree(gamma);
26 	mpfree(delta);
27 	return out;
28 }
29