POLY: simplify pb_inverse_poly_q() a bit

This commit is contained in:
hasufell 2014-04-30 17:23:24 +02:00
parent 8817cd79b2
commit f6b5c8de19
No known key found for this signature in database
GPG Key ID: 220CD1C5BDEED020
1 changed files with 6 additions and 7 deletions

View File

@ -377,8 +377,11 @@ bool pb_inverse_poly_q(pb_poly * const a,
int k = 0,
j = 0;
pb_poly *a_tmp, *b, *c, *f, *g;
mp_int mp_modulus;
/* general initialization of temp variables */
init_integer(&mp_modulus);
MP_SET_INT(&mp_modulus, (unsigned long)(ctx->q));
b = build_polynom(NULL, ctx->N + 1);
MP_SET(&(b->terms[0]), 1);
c = build_polynom(NULL, ctx->N + 1);
@ -435,15 +438,11 @@ bool pb_inverse_poly_q(pb_poly * const a,
/* pull into positive space */
for (int i = ctx->N - 1; i >= 0; i--)
if (mp_cmp_d(&(Fq->terms[i]), 0) == MP_LT) {
mp_int mp_tmp;
init_integer(&mp_tmp);
MP_SET_INT(&mp_tmp, ctx->q);
MP_ADD(&(Fq->terms[i]), &mp_tmp, &(Fq->terms[i]));
mp_clear(&mp_tmp);
}
if (mp_cmp_d(&(Fq->terms[i]), 0) == MP_LT)
MP_ADD(&(Fq->terms[i]), &mp_modulus, &(Fq->terms[i]));
delete_polynom_multi(a_tmp, b, c, f, g, NULL);
mp_clear(&mp_modulus);
/* TODO: check if the f * Fq = 1 (mod p) condition holds true */