5 // decrypt rsa using garner's algorithm for the chinese remainder theorem
6 // seminumerical algorithms, knuth, pp 253-254
7 // applied cryptography, menezes et al, pg 612
9 rsadecrypt(RSApriv *rsa, mpint *in, mpint *out)
16 // convert in to modular representation
18 mpmod(in, rsa->p, v1);
20 mpmod(in, rsa->q, v2);
22 // exponentiate the modular rep
23 mpexp(v1, rsa->kp, rsa->p, v1);
24 mpexp(v2, rsa->kq, rsa->q, v2);
26 // out = v1 + p*((v2-v1)*c2 mod q)
28 mpmul(v2, rsa->c2, v2);
29 mpmod(v2, rsa->q, v2);
30 mpmul(v2, rsa->p, out);