From 398edc729d936d6e3b7e320e06c894480c132b69 Mon Sep 17 00:00:00 2001 From: hasufell Date: Sat, 13 Sep 2014 18:26:31 +0200 Subject: [PATCH] POLY: fix substraction Interestingly, the results and tests work with both variants. However, this one is correct and matches the algorithm given in NTRU Cryptosystems Tech Report #014. --- src/ntru_poly.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ntru_poly.c b/src/ntru_poly.c index 22f0759..283d67c 100644 --- a/src/ntru_poly.c +++ b/src/ntru_poly.c @@ -509,12 +509,12 @@ poly_inverse_poly_p(fmpz_poly_t Fp, /* f = f - u * g mod p */ fmpz_poly_scalar_mul_fmpz(g_tmp, g_tmp, u); - fmpz_poly_sub(f, g_tmp, f); + fmpz_poly_sub(f, f, g_tmp); fmpz_poly_mod_unsigned(f, params->p); /* b = b - u * c mod p */ fmpz_poly_scalar_mul_fmpz(c_tmp, c_tmp, u); - fmpz_poly_sub(b, c_tmp, b); + fmpz_poly_sub(b, b, c_tmp); fmpz_poly_mod_unsigned(b, params->p); fmpz_clear(u);