From f15aefe4e0bb264fc1ceac17c7bbe1a534d190c9 Mon Sep 17 00:00:00 2001 From: Mark Wooding Date: Thu, 25 Jul 2013 18:30:46 +0100 Subject: [PATCH 1/1] rsa.c: Check public key length. The private key is checked quite carefully -- even to a fault -- for being sensibly sized, but the corresponding function for public keys appears to have no checking at all. This is a shame since message- representative construction assumes that the message representative will fit in a fixed-size buffer. Fix this situation by checking public key sizes in `rsapub_apply'. Signed-off-by: Mark Wooding Signed-off-by: Ian Jackson --- rsa.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/rsa.c b/rsa.c index 2db03c9..f7dd69d 100644 --- a/rsa.c +++ b/rsa.c @@ -199,6 +199,9 @@ static list_t *rsapub_apply(closure_t *self, struct cloc loc, dict_t *context, } else { cfgfatal(loc,"rsa-public","you must provide an encryption key\n"); } + if (mpz_sizeinbase(&st->e, 256) > RSA_MAX_MODBYTES) { + cfgfatal(loc, "rsa-public", "implausibly large public exponent\n"); + } i=list_elem(args,1); if (i) { @@ -213,6 +216,9 @@ static list_t *rsapub_apply(closure_t *self, struct cloc loc, dict_t *context, } else { cfgfatal(loc,"rsa-public","you must provide a modulus\n"); } + if (mpz_sizeinbase(&st->n, 256) > RSA_MAX_MODBYTES) { + cfgfatal(loc, "rsa-public", "implausibly large modulus\n"); + } return new_closure(&st->cl); } -- 2.30.2