/* RSA decryption with the private key */ public static void DECRYPT(rsa_private_key PRIV, sbyte[] G, sbyte[] F) { int n = PRIV.p.getlen(); FF g = new FF(2 * n); FF.fromBytes(g, G); FF jp = g.dmod(PRIV.p); FF jq = g.dmod(PRIV.q); jp.skpow(PRIV.dp, PRIV.p); jq.skpow(PRIV.dq, PRIV.q); g.zero(); g.dscopy(jp); jp.mod(PRIV.q); if (FF.comp(jp, jq) > 0) { jq.add(PRIV.q); } jq.sub(jp); jq.norm(); FF t = FF.mul(PRIV.c, jq); jq = t.dmod(PRIV.q); t = FF.mul(jq, PRIV.p); g.add(t); g.norm(); g.toBytes(F); }
/* Set r=this mod b */ /* this is of length - 2*n */ /* r,b is of length - n */ public FF dmod(FF b) { int k, n = b.length; FF m = new FF(2 * n); FF x = new FF(2 * n); FF r = new FF(n); x.copy(this); x.norm(); m.dsucopy(b); k = 256 * n; while (k > 0) { m.shr(); if (comp(x, m) >= 0) { x.sub(m); x.norm(); } k--; } r.copy(x); r.mod(b); return(r); }