From e29064a666914ea9fa69ccbd13d3fce22991ce22 Mon Sep 17 00:00:00 2001 From: hasufell Date: Wed, 30 Apr 2014 17:29:16 +0200 Subject: [PATCH] POLY: fix pb_inverse_poly_p and convert to pb_mp_mul() Was still using the old build_polynom() API. --- src/poly.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/src/poly.c b/src/poly.c index a13b481..5dd64c8 100644 --- a/src/poly.c +++ b/src/poly.c @@ -511,11 +511,10 @@ bool pb_inverse_poly_p(pb_poly *a, } { - pb_poly *u, *c_tmp, *g_tmp; - mp_int mp_tmp; + pb_poly *c_tmp, *g_tmp; + mp_int u, mp_tmp; - init_integer(&mp_tmp); - u = build_polynom(NULL, ctx->N, ctx); + init_integers(&u, &mp_tmp, NULL); g_tmp = build_polynom(NULL, ctx->N + 1); PB_COPY(g, g_tmp); c_tmp = build_polynom(NULL, ctx->N + 1); @@ -523,24 +522,24 @@ bool pb_inverse_poly_p(pb_poly *a, /* u = f[0] * g[0]^(-1) mod p * = (f[0] mod p) * (g[0] inverse mod p) mod p */ - MP_COPY(&(f->terms[0]), &mp_tmp); /* don't change f[0] */ - MP_INVMOD(&(g->terms[0]), &mp_modulus, &(u->terms[0])); + MP_COPY(&(f->terms[0]), &mp_tmp); + MP_INVMOD(&(g->terms[0]), &mp_modulus, &u); MP_MOD(&mp_tmp, &mp_modulus, &mp_tmp); - MP_MUL(&(u->terms[0]), &mp_tmp, &(u->terms[0])); - MP_MOD(&(u->terms[0]), &mp_modulus, &(u->terms[0])); + MP_MUL(&u, &mp_tmp, &u); + MP_MOD(&u, &mp_modulus, &u); /* f = f - u * g mod p */ - PB_MUL(g_tmp, u, g_tmp); + PB_MP_MUL(g_tmp, &u, g_tmp); PB_SUB(f, g_tmp, f); PB_MOD(f, &mp_modulus, f, ctx->N + 1); /* b = b - u * c mod p */ - PB_MUL(c_tmp, u, c_tmp); + PB_MP_MUL(c_tmp, &u, c_tmp); PB_SUB(b, c_tmp, b); PB_MOD(b, &mp_modulus, b, ctx->N + 1); mp_clear(&mp_tmp); - delete_polynom_multi(u, c_tmp, g_tmp, NULL); + delete_polynom_multi(c_tmp, g_tmp, NULL); } }