X-Git-Url: https://git.distorted.org.uk/u/mdw/catacomb/blobdiff_plain/b82ec4e8f22113df1ca11cdf46e8904cd0d86e7a..02dfbd5b7af7816959dbd39c1fe628451204e35f:/rsa-gen.c diff --git a/rsa-gen.c b/rsa-gen.c index 55b4ec9..d284715 100644 --- a/rsa-gen.c +++ b/rsa-gen.c @@ -1,6 +1,6 @@ /* -*-c-*- * - * $Id: rsa-gen.c,v 1.3 2000/07/01 11:22:22 mdw Exp $ + * $Id$ * * RSA parameter generation * @@ -27,35 +27,6 @@ * MA 02111-1307, USA. */ -/*----- Revision history --------------------------------------------------* - * - * $Log: rsa-gen.c,v $ - * Revision 1.3 2000/07/01 11:22:22 mdw - * Remove bad type name `rsa_param'. - * - * Revision 1.2 2000/06/17 12:05:15 mdw - * Lots of changes: - * - * * Apply limits on %$\gcd(p - 1, q - 1)$% to reduce the space of - * equivalent decryption exponents. - * - * * Force %$e = F_4 = 2^{16} + 1$% to avoid small-encryption-exponent - * attacks. - * - * * Ensure that %$p > q$% and that %$p - q$% is large to deter - * square-root-based factoring methods. - * - * * Use %$e d \equiv 1 \pmod{\lambda(n)}$%, where %$\lambda(n)$% is - * %$\lcm(p - 1, q - 1)$%, as recommended in PKCS#1, rather than the - * more usual %$\varphi(n) = (p - 1)(q - 1)$%. - * - * * Handle aborts from pgen_jump. - * - * Revision 1.1 1999/12/22 15:50:45 mdw - * Initial RSA support. - * - */ - /*----- Header files ------------------------------------------------------*/ #include @@ -151,7 +122,7 @@ again: goto again; } - if (phi->f & MP_NEG) { + if (MP_NEGP(phi)) { mp *z = rp->p; rp->p = rp->q; rp->q = z; @@ -160,7 +131,7 @@ again: /* --- Work out the modulus and the CRT coefficient --- */ rp->n = mp_mul(MP_NEW, rp->p, rp->q); - rp->q_inv = MP_NEW; mp_gcd(0, 0, &rp->q_inv, rp->p, rp->q); + rp->q_inv = mp_modinv(MP_NEW, rp->q, rp->p); /* --- Work out %$\varphi(n) = (p - 1)(q - 1)$% --- * * @@ -183,7 +154,7 @@ again: */ mp_gcd(&g.g, 0, &rp->d, phi, rp->e); - if (MP_CMP(g.g, !=, MP_ONE) && MP_LEN(rp->d) * 4 > MP_LEN(rp->n) * 3) + if (!MP_EQ(g.g, MP_ONE) && MP_LEN(rp->d) * 4 > MP_LEN(rp->n) * 3) goto fail_e; /* --- Work out exponent residues --- */