POLY: fix pb_inverse_poly_p and convert to pb_mp_mul()
Was still using the old build_polynom() API.
This commit is contained in:
parent
8fbcbe4144
commit
e29064a666
21
src/poly.c
21
src/poly.c
@ -511,11 +511,10 @@ bool pb_inverse_poly_p(pb_poly *a,
|
|||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
pb_poly *u, *c_tmp, *g_tmp;
|
pb_poly *c_tmp, *g_tmp;
|
||||||
mp_int mp_tmp;
|
mp_int u, mp_tmp;
|
||||||
|
|
||||||
init_integer(&mp_tmp);
|
init_integers(&u, &mp_tmp, NULL);
|
||||||
u = build_polynom(NULL, ctx->N, ctx);
|
|
||||||
g_tmp = build_polynom(NULL, ctx->N + 1);
|
g_tmp = build_polynom(NULL, ctx->N + 1);
|
||||||
PB_COPY(g, g_tmp);
|
PB_COPY(g, g_tmp);
|
||||||
c_tmp = build_polynom(NULL, ctx->N + 1);
|
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
|
/* u = f[0] * g[0]^(-1) mod p
|
||||||
* = (f[0] mod p) * (g[0] inverse mod p) 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_COPY(&(f->terms[0]), &mp_tmp);
|
||||||
MP_INVMOD(&(g->terms[0]), &mp_modulus, &(u->terms[0]));
|
MP_INVMOD(&(g->terms[0]), &mp_modulus, &u);
|
||||||
MP_MOD(&mp_tmp, &mp_modulus, &mp_tmp);
|
MP_MOD(&mp_tmp, &mp_modulus, &mp_tmp);
|
||||||
MP_MUL(&(u->terms[0]), &mp_tmp, &(u->terms[0]));
|
MP_MUL(&u, &mp_tmp, &u);
|
||||||
MP_MOD(&(u->terms[0]), &mp_modulus, &(u->terms[0]));
|
MP_MOD(&u, &mp_modulus, &u);
|
||||||
|
|
||||||
/* f = f - u * g mod p */
|
/* 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_SUB(f, g_tmp, f);
|
||||||
PB_MOD(f, &mp_modulus, f, ctx->N + 1);
|
PB_MOD(f, &mp_modulus, f, ctx->N + 1);
|
||||||
|
|
||||||
/* b = b - u * c mod p */
|
/* 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_SUB(b, c_tmp, b);
|
||||||
PB_MOD(b, &mp_modulus, b, ctx->N + 1);
|
PB_MOD(b, &mp_modulus, b, ctx->N + 1);
|
||||||
|
|
||||||
mp_clear(&mp_tmp);
|
mp_clear(&mp_tmp);
|
||||||
delete_polynom_multi(u, c_tmp, g_tmp, NULL);
|
delete_polynom_multi(c_tmp, g_tmp, NULL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user