From bdc3aad651f977986ead8eb3c8587f1cfe3a1ba5 Mon Sep 17 00:00:00 2001 From: hasufell Date: Thu, 29 May 2014 16:46:35 +0200 Subject: [PATCH] ENC: fix encryption It was actually broken, since we did overwrite the out-coefficients instead of adding to them. Fixing this again causes the same problems as described in the inline comment, no matter which implementation we use. --- src/encrypt.c | 21 ++++----------------- 1 file changed, 4 insertions(+), 17 deletions(-) diff --git a/src/encrypt.c b/src/encrypt.c index 2d01881..541ac6c 100644 --- a/src/encrypt.c +++ b/src/encrypt.c @@ -59,23 +59,10 @@ ntru_encrypt_poly( fmpz_poly_zero(out); poly_starmultiply(pub_key, rnd, out, ctx, ctx->q); - /* - * using the flint functions - * fmpz_poly_add(out, out, tmp_poly_msg); - * fmpz_poly_mod_unsigned(out, ctx->q); - * here instead caused very rare glitches in some cases, - * TODO: investigate - */ - for (uint32_t i = 0; i < ctx->N; i++) { - fmpz_t e_coeff_i; - fmpz *m_coeff_i = fmpz_poly_get_coeff_ptr(tmp_poly_msg, i); - fmpz_init(e_coeff_i); - - fmpz_add_n(e_coeff_i, e_coeff_i, m_coeff_i); - fmpz_mod_ui(e_coeff_i, e_coeff_i, ctx->q); - - fmpz_poly_set_coeff_fmpz_n(out, i, e_coeff_i); - } + /* FIXME: causes rare junk chars in some cases, + * which is perfectly reproducible, so this is not UB */ + fmpz_poly_add(out, out, tmp_poly_msg); + fmpz_poly_mod_unsigned(out, ctx->q); fmpz_poly_clear(tmp_poly_msg);