POLY: add null-ptr tolerant fmpz_cmp_si_n() function
This commit is contained in:
parent
6199ab2505
commit
2eb7af07dc
25
src/poly.c
25
src/poly.c
@ -89,6 +89,23 @@ poly_mod2_to_modq(const fmpz_poly_t a,
|
|||||||
|
|
||||||
/*------------------------------------------------------------------------*/
|
/*------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
int
|
||||||
|
fmpz_cmp_si_n(const fmpz_t f, slong g)
|
||||||
|
{
|
||||||
|
fmpz_t f_cmp;
|
||||||
|
|
||||||
|
fmpz_init(f_cmp);
|
||||||
|
|
||||||
|
if (f)
|
||||||
|
fmpz_set(f_cmp, f);
|
||||||
|
else
|
||||||
|
fmpz_set_si(f_cmp, 0);
|
||||||
|
|
||||||
|
return fmpz_cmp_si(f_cmp, g);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*------------------------------------------------------------------------*/
|
||||||
|
|
||||||
void
|
void
|
||||||
poly_new(fmpz_poly_t new_poly,
|
poly_new(fmpz_poly_t new_poly,
|
||||||
int const * const c,
|
int const * const c,
|
||||||
@ -252,8 +269,8 @@ poly_starmultiply(const fmpz_poly_t a,
|
|||||||
a_tmp_coeff_i = fmpz_poly_get_coeff_ptr(a_tmp, i);
|
a_tmp_coeff_i = fmpz_poly_get_coeff_ptr(a_tmp, i);
|
||||||
b_coeff_j = fmpz_poly_get_coeff_ptr(b, j);
|
b_coeff_j = fmpz_poly_get_coeff_ptr(b, j);
|
||||||
|
|
||||||
if (a_tmp_coeff_i && fmpz_cmp_si(a_tmp_coeff_i, 0) &&
|
if (fmpz_cmp_si_n(a_tmp_coeff_i, 0) &&
|
||||||
b_coeff_j && fmpz_cmp_si(b_coeff_j, 0)) {
|
fmpz_cmp_si_n(b_coeff_j, 0)) {
|
||||||
fmpz_t fmpz_tmp;
|
fmpz_t fmpz_tmp;
|
||||||
|
|
||||||
fmpz_init(fmpz_tmp);
|
fmpz_init(fmpz_tmp);
|
||||||
@ -350,7 +367,7 @@ poly_inverse_poly_q(const 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 (fmpz_cmp_si_n(b_last, 0))
|
||||||
goto _cleanup;
|
goto _cleanup;
|
||||||
|
|
||||||
/* Fq(x) = x^(N-k) * b(x) */
|
/* Fq(x) = x^(N-k) * b(x) */
|
||||||
@ -498,7 +515,7 @@ poly_inverse_poly_p(const 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 (fmpz_cmp_si_n(b_last, 0))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
/* Fp(x) = x^(N-k) * b(x) */
|
/* Fp(x) = x^(N-k) * b(x) */
|
||||||
|
11
src/poly.h
11
src/poly.h
@ -39,6 +39,17 @@
|
|||||||
#include <fmpz_poly.h>
|
#include <fmpz_poly.h>
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The same as fmpz_cmp_si except that it
|
||||||
|
* will interpret f as a 0-coefficient if it is a NULL pointer.
|
||||||
|
*
|
||||||
|
* @param poly the polynom we want to compare
|
||||||
|
* @param n the coefficient we want to compare
|
||||||
|
* @return negative value if f < g, positiv evalue if g < f, otherwise 0
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
fmpz_cmp_si_n(const fmpz_t f, slong g);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initializes and builds a polynomial with the
|
* Initializes and builds a polynomial with the
|
||||||
* coefficient values of c[] of size len within NTRU
|
* coefficient values of c[] of size len within NTRU
|
||||||
|
Loading…
Reference in New Issue
Block a user