diff --git a/src/context.h b/src/context.h index d534431..42bba7a 100644 --- a/src/context.h +++ b/src/context.h @@ -29,6 +29,10 @@ #ifndef NTRU_CONTEXT_H #define NTRU_CONTEXT_H + +#include + + /** * NTRU cryptosystem is specified by * the following triple. @@ -38,15 +42,15 @@ typedef struct { * maximal degree N - 1 for * all polynomials */ - unsigned int N; + uint32_t N; /** * large modulus */ - unsigned int q; + uint32_t q; /** * small modulus */ - unsigned int p; + uint32_t p; } ntru_context; #endif /* NTRU_CONTEXT_H */ diff --git a/src/poly.c b/src/poly.c index be9f522..ac6b93b 100644 --- a/src/poly.c +++ b/src/poly.c @@ -34,6 +34,7 @@ #include #include +#include #include #include #include @@ -104,7 +105,7 @@ void poly_new(fmpz_poly_t new_poly, { fmpz_poly_init(new_poly); - for (unsigned int i = 0; i < len; i++) + for (uint32_t i = 0; i < len; i++) fmpz_poly_set_coeff_si(new_poly, i, c[i]); } @@ -129,7 +130,7 @@ void poly_delete(fmpz_poly_t poly) */ void poly_delete_array(fmpz_poly_t **poly_array) { - unsigned int i = 0; + uint32_t i = 0; while(poly_array[i]) { poly_delete(*(poly_array[i])); @@ -174,7 +175,7 @@ void poly_delete_all(fmpz_poly_t poly, ...) * @param mod the modulus */ void fmpz_poly_mod_unsigned(fmpz_poly_t a, - unsigned int mod) + uint32_t mod) { nmod_poly_t nmod_tmp; @@ -199,7 +200,7 @@ void fmpz_poly_mod_unsigned(fmpz_poly_t a, * @param mod the modulus */ void fmpz_poly_mod(fmpz_poly_t a, - unsigned int mod) + uint32_t mod) { nmod_poly_t nmod_tmp; @@ -237,7 +238,7 @@ void fmpz_poly_set_coeff_fmpz_n(fmpz_poly_t poly, slong n, * @param g the inverse * @param mod the modulo */ -int fmpz_invmod_ui(fmpz_t f, const fmpz_t g, unsigned int mod) +int fmpz_invmod_ui(fmpz_t f, const fmpz_t g, uint32_t mod) { fmpz_t modulus; @@ -278,7 +279,7 @@ void poly_starmultiply(fmpz_poly_t a, fmpz_poly_t b, fmpz_poly_t c, ntru_context *ctx, - unsigned int modulus) + uint32_t modulus) { fmpz_poly_t a_tmp; fmpz_t c_coeff_k; @@ -374,7 +375,7 @@ bool poly_inverse_poly_q(fmpz_poly_t a, while (1) { while (fmpz_is_zero(fmpz_poly_get_coeff_ptr(f, 0))) { - for (unsigned int i = 1; i <= ctx->N; i++) { + for (uint32_t i = 1; i <= ctx->N; i++) { fmpz *f_coeff = fmpz_poly_get_coeff_ptr(f, i); fmpz *c_coeff = fmpz_poly_get_coeff_ptr(c, ctx->N - i); @@ -497,7 +498,7 @@ bool poly_inverse_poly_p(fmpz_poly_t a, while (1) { while (fmpz_is_zero(fmpz_poly_get_coeff_ptr(f, 0))) { - for (unsigned int i = 1; i <= ctx->N; i++) { + for (uint32_t i = 1; i <= ctx->N; i++) { fmpz *f_coeff_tmp = fmpz_poly_get_coeff_ptr(f, i); fmpz *c_coeff_tmp = fmpz_poly_get_coeff_ptr(c, ctx->N - i); diff --git a/src/poly.h b/src/poly.h index 50d3600..a247179 100644 --- a/src/poly.h +++ b/src/poly.h @@ -33,6 +33,7 @@ #include #include +#include #include #include @@ -49,10 +50,10 @@ void poly_delete_array(fmpz_poly_t **poly_array); void poly_delete_all(fmpz_poly_t poly, ...); void fmpz_poly_mod_unsigned(fmpz_poly_t a, - unsigned int mod); + uint32_t mod); void fmpz_poly_mod(fmpz_poly_t a, - unsigned int mod); + uint32_t mod); void fmpz_poly_set_coeff_fmpz_n(fmpz_poly_t poly, slong n, @@ -60,7 +61,7 @@ void fmpz_poly_set_coeff_fmpz_n(fmpz_poly_t poly, int fmpz_invmod_ui(fmpz_t f, const fmpz_t g, - unsigned int mod); + uint32_t mod); void fmpz_add_n(fmpz_t f, const fmpz_t g, const fmpz_t h); @@ -68,7 +69,7 @@ void poly_starmultiply(fmpz_poly_t a, fmpz_poly_t b, fmpz_poly_t c, ntru_context *ctx, - unsigned int modulus); + uint32_t modulus); bool poly_inverse_poly_q(fmpz_poly_t a, fmpz_poly_t Fq, diff --git a/src/rand.c b/src/rand.c index 2e8f602..7e7986e 100644 --- a/src/rand.c +++ b/src/rand.c @@ -46,7 +46,7 @@ static mp_digit get_random_ternary(mp_digit random_int, int* sign); static mp_int *get_random_bigint(mp_int *upper_bound, mp_int *lower_bound, int entropy_source); -static unsigned int check_allowed_zeros(pb_poly *polynom); +static uint32_t check_allowed_zeros(pb_poly *polynom); /** * Reads a single mp_digit out of /dev/random and returns this mp_digit @@ -149,9 +149,9 @@ static mp_int *get_random_bigint(mp_int *upper_bound, * -1 if the polynom zero coefficients are over * PERCENTAGE_OF_ZERO_ALLOWED percent */ -static unsigned int check_allowed_zeros(pb_poly *polynom) +static uint32_t check_allowed_zeros(pb_poly *polynom) { - unsigned int result = -1; + uint32_t result = -1; //TODO return result; } @@ -175,7 +175,7 @@ pb_poly *ntru_get_random_poly_ternary(size_t length, int entropy_source) init_polynom_size(poly, &chara, length); mp_clear(&chara); - for (unsigned int i = 0; i < length; i++) { + for (uint32_t i = 0; i < length; i++) { int sign; if (entropy_source == GET_INT_FROM_RRAND) { coefficient = get_int_dev_random();