pub/bbs-gen.c, pub/rsa-gen.c: Fail if the generated key is the wrong length.
[catacomb] / pub / rsa-gen.c
index c12be18..de97644 100644 (file)
@@ -158,6 +158,8 @@ int rsa_gen(rsa_priv *rp, unsigned nbits, grand *r, unsigned n,
   mp_gcd(&g.g, 0, &rp->d, phi, rp->e);
   if (!MP_EQ(g.g, MP_ONE) && MP_LEN(rp->d) * 4 > MP_LEN(rp->n) * 3)
     goto fail_e;
+  if (mp_bits(rp->n) != nbits)
+    goto fail_e;
 
   /* --- Work out exponent residues --- */