chiark / gitweb /
pub/bbs-gen.c, pub/rsa-gen.c: Fail if the generated key is the wrong length.
authorMark Wooding <mdw@distorted.org.uk>
Thu, 26 May 2016 08:26:09 +0000 (09:26 +0100)
committerMark Wooding <mdw@distorted.org.uk>
Sun, 26 Jun 2016 10:44:36 +0000 (11:44 +0100)
pub/bbs-gen.c
pub/rsa-gen.c

index 4796cf5c719942c0bb65f95133a1aa8a05249b48..fcba8288965555a716e8ed3a055ce51989f7fffd 100644 (file)
@@ -102,11 +102,14 @@ int bbs_gen(bbs_priv *bp, unsigned nbits, grand *r, unsigned n,
   /* --- Compute @n@ --- */
 
   bp->n = mp_mul(MP_NEW, bp->p, bp->q);
+  if (mp_bits(bp->n) != nbits) goto fail_n;
   mp_drop(x);
   return (PGEN_DONE);
 
   /* --- Tidy up if things went wrong --- */
 
+fail_n:
+  mp_drop(bp->n);
 fail_q:
   mp_drop(bp->p);
 fail_p:
index c12be18ae3a02d5282a01ccecf7adca217163c27..de97644c4d73708080a3f65ccb41c3501a6a2897 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 --- */