POLY: readability
This commit is contained in:
parent
9039e47eb4
commit
67ec5615c7
19
src/poly.c
19
src/poly.c
@ -390,7 +390,7 @@ poly_inverse_poly_p(fmpz_poly_t a,
|
|||||||
fmpz_poly_t Fp,
|
fmpz_poly_t Fp,
|
||||||
ntru_context *ctx)
|
ntru_context *ctx)
|
||||||
{
|
{
|
||||||
bool retval = true;
|
bool retval = false;
|
||||||
int k = 0,
|
int k = 0,
|
||||||
j = 0;
|
j = 0;
|
||||||
fmpz *b_last;
|
fmpz *b_last;
|
||||||
@ -437,10 +437,8 @@ poly_inverse_poly_p(fmpz_poly_t a,
|
|||||||
|
|
||||||
k++;
|
k++;
|
||||||
|
|
||||||
if (fmpz_poly_degree(f) == -1) {
|
if (fmpz_poly_degree(f) == -1)
|
||||||
retval = false;
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fmpz_poly_degree(f) == 0)
|
if (fmpz_poly_degree(f) == 0)
|
||||||
@ -497,10 +495,8 @@ poly_inverse_poly_p(fmpz_poly_t a,
|
|||||||
k = k % ctx->N;
|
k = k % ctx->N;
|
||||||
|
|
||||||
b_last = fmpz_poly_get_coeff_ptr(b, ctx->N);
|
b_last = fmpz_poly_get_coeff_ptr(b, ctx->N);
|
||||||
if (b_last && fmpz_cmp_si(b_last, 0)) {
|
if (b_last && fmpz_cmp_si(b_last, 0))
|
||||||
retval = false;
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
|
||||||
|
|
||||||
/* Fp(x) = x^(N-k) * b(x) */
|
/* Fp(x) = x^(N-k) * b(x) */
|
||||||
for (int i = ctx->N - 1; i >= 0; i--) {
|
for (int i = ctx->N - 1; i >= 0; i--) {
|
||||||
@ -537,8 +533,10 @@ poly_inverse_poly_p(fmpz_poly_t a,
|
|||||||
/* check if the f * Fp = 1 (mod p) condition holds true */
|
/* check if the f * Fp = 1 (mod p) condition holds true */
|
||||||
fmpz_poly_set(a_tmp, a);
|
fmpz_poly_set(a_tmp, a);
|
||||||
poly_starmultiply(a_tmp, Fp, a_tmp, ctx, ctx->p);
|
poly_starmultiply(a_tmp, Fp, a_tmp, ctx, ctx->p);
|
||||||
if (!fmpz_poly_is_one(a_tmp))
|
if (fmpz_poly_is_one(a_tmp))
|
||||||
retval = false;
|
retval = true;
|
||||||
|
else
|
||||||
|
fmpz_poly_zero(Fp);
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
fmpz_poly_clear(a_tmp);
|
fmpz_poly_clear(a_tmp);
|
||||||
@ -547,9 +545,6 @@ cleanup:
|
|||||||
fmpz_poly_clear(f);
|
fmpz_poly_clear(f);
|
||||||
fmpz_poly_clear(g);
|
fmpz_poly_clear(g);
|
||||||
|
|
||||||
if (!retval)
|
|
||||||
fmpz_poly_zero(Fp);
|
|
||||||
|
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user