From bb0207ba039f4c14562d44ccbddc1e087fad8a1c Mon Sep 17 00:00:00 2001 From: hasufell Date: Wed, 28 May 2014 23:11:52 +0200 Subject: [PATCH] KEYGEN: improve error handling --- src/keypair.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/src/keypair.c b/src/keypair.c index 44abbd0..5aa81c0 100644 --- a/src/keypair.c +++ b/src/keypair.c @@ -45,25 +45,23 @@ ntru_create_keypair( keypair *pair, ntru_context *ctx) { - bool retval = true; + bool retval = false; fmpz_poly_t Fq, Fp, pub; + if (!f || !g || !ctx) + goto _return; + fmpz_poly_init(Fq); fmpz_poly_init(Fp); fmpz_poly_init(pub); + if (!poly_inverse_poly_q(f, Fq, ctx)) + goto _cleanup; - if (!poly_inverse_poly_q(f, Fq, ctx)) { - retval = false; - goto cleanup; - } - - if (!poly_inverse_poly_p(f, Fp, ctx)) { - retval = false; - goto cleanup; - } + if (!poly_inverse_poly_p(f, Fp, ctx)) + goto _cleanup; poly_starmultiply(Fq, g, pub, ctx, ctx->q); fmpz_poly_scalar_mul_ui(pub, pub, ctx->p); @@ -77,10 +75,13 @@ ntru_create_keypair( fmpz_poly_set(pair->priv_inv, Fp); fmpz_poly_set(pair->pub, pub); -cleanup: + retval = true; + +_cleanup: fmpz_poly_clear(Fq); fmpz_poly_clear(Fp); fmpz_poly_clear(pub); +_return: return retval; }