ALL: use uint32_t instead of unsigned int

This commit is contained in:
hasufell 2014-05-25 22:47:54 +02:00
parent 58e6a90881
commit 4a07ceadcd
No known key found for this signature in database
GPG Key ID: 220CD1C5BDEED020
4 changed files with 25 additions and 19 deletions

View File

@ -29,6 +29,10 @@
#ifndef NTRU_CONTEXT_H #ifndef NTRU_CONTEXT_H
#define NTRU_CONTEXT_H #define NTRU_CONTEXT_H
#include <stdint.h>
/** /**
* NTRU cryptosystem is specified by * NTRU cryptosystem is specified by
* the following triple. * the following triple.
@ -38,15 +42,15 @@ typedef struct {
* maximal degree N - 1 for * maximal degree N - 1 for
* all polynomials * all polynomials
*/ */
unsigned int N; uint32_t N;
/** /**
* large modulus * large modulus
*/ */
unsigned int q; uint32_t q;
/** /**
* small modulus * small modulus
*/ */
unsigned int p; uint32_t p;
} ntru_context; } ntru_context;
#endif /* NTRU_CONTEXT_H */ #endif /* NTRU_CONTEXT_H */

View File

@ -34,6 +34,7 @@
#include <stdarg.h> #include <stdarg.h>
#include <stdbool.h> #include <stdbool.h>
#include <stdint.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <sys/types.h> #include <sys/types.h>
@ -104,7 +105,7 @@ void poly_new(fmpz_poly_t new_poly,
{ {
fmpz_poly_init(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]); 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) void poly_delete_array(fmpz_poly_t **poly_array)
{ {
unsigned int i = 0; uint32_t i = 0;
while(poly_array[i]) { while(poly_array[i]) {
poly_delete(*(poly_array[i])); poly_delete(*(poly_array[i]));
@ -174,7 +175,7 @@ void poly_delete_all(fmpz_poly_t poly, ...)
* @param mod the modulus * @param mod the modulus
*/ */
void fmpz_poly_mod_unsigned(fmpz_poly_t a, void fmpz_poly_mod_unsigned(fmpz_poly_t a,
unsigned int mod) uint32_t mod)
{ {
nmod_poly_t nmod_tmp; nmod_poly_t nmod_tmp;
@ -199,7 +200,7 @@ void fmpz_poly_mod_unsigned(fmpz_poly_t a,
* @param mod the modulus * @param mod the modulus
*/ */
void fmpz_poly_mod(fmpz_poly_t a, void fmpz_poly_mod(fmpz_poly_t a,
unsigned int mod) uint32_t mod)
{ {
nmod_poly_t nmod_tmp; 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 g the inverse
* @param mod the modulo * @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; fmpz_t modulus;
@ -278,7 +279,7 @@ void poly_starmultiply(fmpz_poly_t a,
fmpz_poly_t b, fmpz_poly_t b,
fmpz_poly_t c, fmpz_poly_t c,
ntru_context *ctx, ntru_context *ctx,
unsigned int modulus) uint32_t modulus)
{ {
fmpz_poly_t a_tmp; fmpz_poly_t a_tmp;
fmpz_t c_coeff_k; fmpz_t c_coeff_k;
@ -374,7 +375,7 @@ bool poly_inverse_poly_q(fmpz_poly_t a,
while (1) { while (1) {
while (fmpz_is_zero(fmpz_poly_get_coeff_ptr(f, 0))) { 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 *f_coeff = fmpz_poly_get_coeff_ptr(f, i);
fmpz *c_coeff = fmpz_poly_get_coeff_ptr(c, ctx->N - 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 (1) {
while (fmpz_is_zero(fmpz_poly_get_coeff_ptr(f, 0))) { 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 *f_coeff_tmp = fmpz_poly_get_coeff_ptr(f, i);
fmpz *c_coeff_tmp = fmpz_poly_get_coeff_ptr(c, ctx->N - i); fmpz *c_coeff_tmp = fmpz_poly_get_coeff_ptr(c, ctx->N - i);

View File

@ -33,6 +33,7 @@
#include <stdarg.h> #include <stdarg.h>
#include <stdbool.h> #include <stdbool.h>
#include <stdint.h>
#include <stdlib.h> #include <stdlib.h>
#include <fmpz_poly.h> #include <fmpz_poly.h>
@ -49,10 +50,10 @@ void poly_delete_array(fmpz_poly_t **poly_array);
void poly_delete_all(fmpz_poly_t poly, ...); void poly_delete_all(fmpz_poly_t poly, ...);
void fmpz_poly_mod_unsigned(fmpz_poly_t a, void fmpz_poly_mod_unsigned(fmpz_poly_t a,
unsigned int mod); uint32_t mod);
void fmpz_poly_mod(fmpz_poly_t a, 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, void fmpz_poly_set_coeff_fmpz_n(fmpz_poly_t poly,
slong n, slong n,
@ -60,7 +61,7 @@ void fmpz_poly_set_coeff_fmpz_n(fmpz_poly_t poly,
int fmpz_invmod_ui(fmpz_t f, int fmpz_invmod_ui(fmpz_t f,
const fmpz_t g, 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); 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 b,
fmpz_poly_t c, fmpz_poly_t c,
ntru_context *ctx, ntru_context *ctx,
unsigned int modulus); uint32_t modulus);
bool poly_inverse_poly_q(fmpz_poly_t a, bool poly_inverse_poly_q(fmpz_poly_t a,
fmpz_poly_t Fq, fmpz_poly_t Fq,

View File

@ -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, static mp_int *get_random_bigint(mp_int *upper_bound,
mp_int *lower_bound, mp_int *lower_bound,
int entropy_source); 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 * 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 * -1 if the polynom zero coefficients are over
* PERCENTAGE_OF_ZERO_ALLOWED percent * 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 //TODO
return result; 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); init_polynom_size(poly, &chara, length);
mp_clear(&chara); mp_clear(&chara);
for (unsigned int i = 0; i < length; i++) { for (uint32_t i = 0; i < length; i++) {
int sign; int sign;
if (entropy_source == GET_INT_FROM_RRAND) { if (entropy_source == GET_INT_FROM_RRAND) {
coefficient = get_int_dev_random(); coefficient = get_int_dev_random();