ALL: use const modifiers on parameters where possible

Esse commit está contido em:
hasufell 2014-06-01 20:41:29 +02:00
commit a265a89a0d
Nenhuma chave conhecida encontrada para esta assinatura no banco de dados
ID da chave GPG: 220CD1C5BDEED020
10 arquivos alterados com 89 adições e 87 exclusões

Ver arquivo

@ -75,7 +75,7 @@ get_int_to_bin_str(uint8_t value);
* newly allocated * newly allocated
*/ */
static string * static string *
get_bin_arr_to_ascii(char *binary_rep); get_bin_arr_to_ascii(const char *binary_rep);
/*------------------------------------------------------------------------*/ /*------------------------------------------------------------------------*/
@ -100,7 +100,7 @@ get_int_to_bin_str(uint8_t value)
/*------------------------------------------------------------------------*/ /*------------------------------------------------------------------------*/
static string * static string *
get_bin_arr_to_ascii(char *binary_rep) get_bin_arr_to_ascii(const char *binary_rep)
{ {
size_t int_arr_size = 0; size_t int_arr_size = 0;
uint8_t *int_arr = NULL; uint8_t *int_arr = NULL;
@ -145,7 +145,7 @@ get_bin_arr_to_ascii(char *binary_rep)
/*------------------------------------------------------------------------*/ /*------------------------------------------------------------------------*/
fmpz_poly_t * fmpz_poly_t *
ascii_bin_to_bin_poly(char *to_poly, ntru_context *ctx) ascii_bin_to_bin_poly(const char *to_poly, const ntru_context *ctx)
{ {
uint32_t i = 0; uint32_t i = 0;
fmpz_poly_t *new_poly = ntru_malloc(sizeof(*new_poly)); fmpz_poly_t *new_poly = ntru_malloc(sizeof(*new_poly));
@ -165,7 +165,7 @@ ascii_bin_to_bin_poly(char *to_poly, ntru_context *ctx)
/*------------------------------------------------------------------------*/ /*------------------------------------------------------------------------*/
fmpz_poly_t ** fmpz_poly_t **
ascii_to_bin_poly_arr(string *to_poly, ntru_context *ctx) ascii_to_bin_poly_arr(const string *to_poly, const ntru_context *ctx)
{ {
char *cur = to_poly->ptr; char *cur = to_poly->ptr;
char *out = ntru_malloc(CHAR_SIZE * (to_poly->len * ASCII_BITS + 1)); char *out = ntru_malloc(CHAR_SIZE * (to_poly->len * ASCII_BITS + 1));
@ -209,8 +209,8 @@ ascii_to_bin_poly_arr(string *to_poly, ntru_context *ctx)
/*------------------------------------------------------------------------*/ /*------------------------------------------------------------------------*/
string * string *
bin_poly_to_ascii(fmpz_poly_t poly, bin_poly_to_ascii(const fmpz_poly_t poly,
ntru_context *ctx) const ntru_context *ctx)
{ {
string *result_string = ntru_malloc(sizeof(*result_string)); string *result_string = ntru_malloc(sizeof(*result_string));
char *binary_rep = ntru_malloc(CHAR_SIZE * (ctx->N)); char *binary_rep = ntru_malloc(CHAR_SIZE * (ctx->N));
@ -240,7 +240,8 @@ bin_poly_to_ascii(fmpz_poly_t poly,
/*------------------------------------------------------------------------*/ /*------------------------------------------------------------------------*/
string * string *
bin_poly_arr_to_ascii(fmpz_poly_t **bin_poly_arr, ntru_context *ctx) bin_poly_arr_to_ascii(fmpz_poly_t **bin_poly_arr,
const ntru_context *ctx)
{ {
fmpz_poly_t *ascii_poly; fmpz_poly_t *ascii_poly;
char *binary_rep = NULL; char *binary_rep = NULL;
@ -253,7 +254,7 @@ bin_poly_arr_to_ascii(fmpz_poly_t **bin_poly_arr, ntru_context *ctx)
* parse the polynomial coefficients into a string * parse the polynomial coefficients into a string
*/ */
binary_rep = ntru_calloc(1, CHAR_SIZE * (ctx->N + 1)); binary_rep = ntru_calloc(1, CHAR_SIZE * (ctx->N + 1));
while ((ascii_poly = *bin_poly_arr++)) { while ((ascii_poly = (fmpz_poly_t *)*bin_poly_arr++)) {
string *single_poly_string = NULL; string *single_poly_string = NULL;
new_length = CHAR_SIZE * (ctx->N); new_length = CHAR_SIZE * (ctx->N);
@ -287,8 +288,8 @@ bin_poly_arr_to_ascii(fmpz_poly_t **bin_poly_arr, ntru_context *ctx)
/*------------------------------------------------------------------------*/ /*------------------------------------------------------------------------*/
string * string *
poly_to_ascii(fmpz_poly_t poly, poly_to_ascii(const fmpz_poly_t poly,
ntru_context *ctx) const ntru_context *ctx)
{ {
string *result_string = ntru_malloc(sizeof(*result_string)); string *result_string = ntru_malloc(sizeof(*result_string));
char *string_rep = ntru_malloc(CHAR_SIZE * (ctx->N)); char *string_rep = ntru_malloc(CHAR_SIZE * (ctx->N));
@ -310,7 +311,7 @@ poly_to_ascii(fmpz_poly_t poly,
/*------------------------------------------------------------------------*/ /*------------------------------------------------------------------------*/
fmpz_poly_t ** fmpz_poly_t **
base64_to_poly_arr(string *to_poly, ntru_context *ctx) base64_to_poly_arr(const string *to_poly, const ntru_context *ctx)
{ {
uint32_t i = 0, uint32_t i = 0,
polyc = 0; polyc = 0;
@ -378,8 +379,8 @@ base64_to_poly_arr(string *to_poly, ntru_context *ctx)
/*------------------------------------------------------------------------*/ /*------------------------------------------------------------------------*/
string * string *
poly_to_base64(fmpz_poly_t poly, poly_to_base64(const fmpz_poly_t poly,
ntru_context *ctx) const ntru_context *ctx)
{ {
string *result_string = ntru_malloc(sizeof(*result_string)); string *result_string = ntru_malloc(sizeof(*result_string));
string *string_rep = NULL; string *string_rep = NULL;
@ -407,7 +408,7 @@ poly_to_base64(fmpz_poly_t poly,
string * string *
poly_arr_to_base64(fmpz_poly_t **poly_array, poly_arr_to_base64(fmpz_poly_t **poly_array,
ntru_context *ctx) const ntru_context *ctx)
{ {
fmpz_poly_t *ascii_poly; fmpz_poly_t *ascii_poly;
char *string_rep = NULL; char *string_rep = NULL;

Ver arquivo

@ -54,7 +54,7 @@
* @return newly allocated array of binary polynomials * @return newly allocated array of binary polynomials
*/ */
fmpz_poly_t * fmpz_poly_t *
ascii_bin_to_bin_poly(char *to_poly, ntru_context *ctx); ascii_bin_to_bin_poly(const char *to_poly, const ntru_context *ctx);
/** /**
* Convert an ascii string to an array of binary polyomials. * Convert an ascii string to an array of binary polyomials.
@ -73,7 +73,7 @@ ascii_bin_to_bin_poly(char *to_poly, ntru_context *ctx);
* @return newly allocated array of binary polynomials * @return newly allocated array of binary polynomials
*/ */
fmpz_poly_t ** fmpz_poly_t **
ascii_to_bin_poly_arr(string *to_poly, ntru_context *ctx); ascii_to_bin_poly_arr(const string *to_poly, const ntru_context *ctx);
/** /**
* Convert a single binary polynomial back to a real string. * Convert a single binary polynomial back to a real string.
@ -95,8 +95,8 @@ ascii_to_bin_poly_arr(string *to_poly, ntru_context *ctx);
* @return the real string, newly allocated * @return the real string, newly allocated
*/ */
string * string *
bin_poly_to_ascii(fmpz_poly_t poly, bin_poly_to_ascii(const fmpz_poly_t poly,
ntru_context *ctx); const ntru_context *ctx);
/** /**
* Convert an array of binary polynomials back to a real string. * Convert an array of binary polynomials back to a real string.
@ -118,7 +118,8 @@ bin_poly_to_ascii(fmpz_poly_t poly,
* @return the real string, newly allocated * @return the real string, newly allocated
*/ */
string * string *
bin_poly_arr_to_ascii(fmpz_poly_t **bin_poly_arr, ntru_context *ctx); bin_poly_arr_to_ascii(fmpz_poly_t **bin_poly_arr,
const ntru_context *ctx);
/** /**
* Convert a single polynom back to a real string which is * Convert a single polynom back to a real string which is
@ -134,8 +135,8 @@ bin_poly_arr_to_ascii(fmpz_poly_t **bin_poly_arr, ntru_context *ctx);
* @return the real string, newly allocated * @return the real string, newly allocated
*/ */
string * string *
poly_to_ascii(fmpz_poly_t poly, poly_to_ascii(const fmpz_poly_t poly,
ntru_context *ctx); const ntru_context *ctx);
/** /**
* Convert an base64 encoded string to an array of polyomials with * Convert an base64 encoded string to an array of polyomials with
@ -153,7 +154,7 @@ poly_to_ascii(fmpz_poly_t poly,
* @return newly allocated array of polynomials * @return newly allocated array of polynomials
*/ */
fmpz_poly_t ** fmpz_poly_t **
base64_to_poly_arr(string *to_poly, ntru_context *ctx); base64_to_poly_arr(const string *to_poly, const ntru_context *ctx);
/** /**
* Convert a single polynom back to a real string which is * Convert a single polynom back to a real string which is
@ -169,8 +170,8 @@ base64_to_poly_arr(string *to_poly, ntru_context *ctx);
* @return the real string, newly allocated * @return the real string, newly allocated
*/ */
string * string *
poly_to_base64(fmpz_poly_t poly, poly_to_base64(const fmpz_poly_t poly,
ntru_context *ctx); const ntru_context *ctx);
/** /**
* Convert an array of polynomials back to a real string which * Convert an array of polynomials back to a real string which
@ -186,7 +187,7 @@ poly_to_base64(fmpz_poly_t poly,
* @return the real string, newly allocated * @return the real string, newly allocated
*/ */
string * string *
poly_arr_to_base64(fmpz_poly_t **poly_arr, ntru_context *ctx); poly_arr_to_base64(fmpz_poly_t **poly_arr, const ntru_context *ctx);
#endif /* NTRU_ASCII_POLY_H_ */ #endif /* NTRU_ASCII_POLY_H_ */

Ver arquivo

@ -41,11 +41,11 @@
bool bool
ntru_decrypt_poly( ntru_decrypt_poly(
fmpz_poly_t encr_msg, const fmpz_poly_t encr_msg,
fmpz_poly_t priv_key, const fmpz_poly_t priv_key,
fmpz_poly_t priv_key_inv, const fmpz_poly_t priv_key_inv,
fmpz_poly_t out_bin, fmpz_poly_t out_bin,
ntru_context *ctx) const ntru_context *ctx)
{ {
fmpz_poly_t a, fmpz_poly_t a,
priv_key_tmp, priv_key_tmp,
@ -89,10 +89,10 @@ ntru_decrypt_poly(
string * string *
ntru_decrypt_string( ntru_decrypt_string(
string *encr_msg, const string *encr_msg,
fmpz_poly_t priv_key, const fmpz_poly_t priv_key,
fmpz_poly_t priv_key_inv, const fmpz_poly_t priv_key_inv,
ntru_context *ctx) const ntru_context *ctx)
{ {
uint32_t i = 0; uint32_t i = 0;
string *decr_msg; string *decr_msg;

Ver arquivo

@ -53,11 +53,11 @@
*/ */
bool bool
ntru_decrypt_poly( ntru_decrypt_poly(
fmpz_poly_t encr_msg, const fmpz_poly_t encr_msg,
fmpz_poly_t priv_key, const fmpz_poly_t priv_key,
fmpz_poly_t priv_key_inv, const fmpz_poly_t priv_key_inv,
fmpz_poly_t out_tern, fmpz_poly_t out_tern,
ntru_context *ctx); const ntru_context *ctx);
/** /**
* Decryption of a given encrypted string. * Decryption of a given encrypted string.
@ -71,10 +71,10 @@ ntru_decrypt_poly(
*/ */
string * string *
ntru_decrypt_string( ntru_decrypt_string(
string *encr_msg, const string *encr_msg,
fmpz_poly_t priv_key, const fmpz_poly_t priv_key,
fmpz_poly_t priv_key_inv, const fmpz_poly_t priv_key_inv,
ntru_context *ctx); const ntru_context *ctx);
#endif /* NTRU_DECRYPT */ #endif /* NTRU_DECRYPT */

Ver arquivo

@ -41,11 +41,11 @@
bool bool
ntru_encrypt_poly( ntru_encrypt_poly(
fmpz_poly_t msg_bin, const fmpz_poly_t msg_bin,
fmpz_poly_t pub_key, const fmpz_poly_t pub_key,
fmpz_poly_t rnd, const fmpz_poly_t rnd,
fmpz_poly_t out, fmpz_poly_t out,
ntru_context *ctx) const ntru_context *ctx)
{ {
fmpz_poly_t tmp_poly_msg; fmpz_poly_t tmp_poly_msg;
@ -73,10 +73,10 @@ ntru_encrypt_poly(
string * string *
ntru_encrypt_string( ntru_encrypt_string(
string *msg, const string *msg,
fmpz_poly_t pub_key, const fmpz_poly_t pub_key,
fmpz_poly_t rnd, const fmpz_poly_t rnd,
ntru_context *ctx) const ntru_context *ctx)
{ {
uint32_t i = 0; uint32_t i = 0;
string *enc_msg; string *enc_msg;

Ver arquivo

@ -64,11 +64,11 @@
*/ */
bool bool
ntru_encrypt_poly( ntru_encrypt_poly(
fmpz_poly_t msg_tern, const fmpz_poly_t msg_tern,
fmpz_poly_t pub_key, const fmpz_poly_t pub_key,
fmpz_poly_t rnd, const fmpz_poly_t rnd,
fmpz_poly_t out, fmpz_poly_t out,
ntru_context *ctx); const ntru_context *ctx);
/** /**
* Encrypt a message in the form of a null-terminated char array and * Encrypt a message in the form of a null-terminated char array and
@ -83,10 +83,10 @@ ntru_encrypt_poly(
*/ */
string * string *
ntru_encrypt_string( ntru_encrypt_string(
string *msg, const string *msg,
fmpz_poly_t pub_key, const fmpz_poly_t pub_key,
fmpz_poly_t rnd, const fmpz_poly_t rnd,
ntru_context *ctx); const ntru_context *ctx);
#endif /* PQC_ENCRYPT_H */ #endif /* PQC_ENCRYPT_H */

Ver arquivo

@ -34,7 +34,7 @@
/*------------------------------------------------------------------------*/ /*------------------------------------------------------------------------*/
void void
prints(string *print_string) prints(const string *print_string)
{ {
for (size_t i = 0; i < print_string->len; i++) for (size_t i = 0; i < print_string->len; i++)
printf("%c", print_string->ptr[i]); printf("%c", print_string->ptr[i]);

Ver arquivo

@ -55,7 +55,7 @@ struct string {
void void
prints(string *print_string); prints(const string *print_string);
/** /**
* Delete the inner structure * Delete the inner structure

Ver arquivo

@ -52,17 +52,17 @@
* @param ctx NTRU context * @param ctx NTRU context
*/ */
static static
void poly_mod2_to_modq(fmpz_poly_t a, void poly_mod2_to_modq(const fmpz_poly_t a,
fmpz_poly_t Fq, fmpz_poly_t Fq,
ntru_context *ctx); const ntru_context *ctx);
/*------------------------------------------------------------------------*/ /*------------------------------------------------------------------------*/
static void static void
poly_mod2_to_modq(fmpz_poly_t a, poly_mod2_to_modq(const fmpz_poly_t a,
fmpz_poly_t Fq, fmpz_poly_t Fq,
ntru_context *ctx) const ntru_context *ctx)
{ {
int v = 2; int v = 2;
fmpz_poly_t poly_tmp, two; fmpz_poly_t poly_tmp, two;
@ -147,7 +147,7 @@ poly_delete_all(fmpz_poly_t poly, ...)
void void
fmpz_poly_mod_unsigned(fmpz_poly_t a, fmpz_poly_mod_unsigned(fmpz_poly_t a,
uint32_t mod) const uint32_t mod)
{ {
nmod_poly_t nmod_tmp; nmod_poly_t nmod_tmp;
@ -163,7 +163,7 @@ fmpz_poly_mod_unsigned(fmpz_poly_t a,
void void
fmpz_poly_mod(fmpz_poly_t a, fmpz_poly_mod(fmpz_poly_t a,
uint32_t mod) const uint32_t mod)
{ {
nmod_poly_t nmod_tmp; nmod_poly_t nmod_tmp;
@ -190,7 +190,7 @@ fmpz_poly_set_coeff_fmpz_n(fmpz_poly_t poly, slong n,
/*------------------------------------------------------------------------*/ /*------------------------------------------------------------------------*/
int int
fmpz_invmod_ui(fmpz_t f, const fmpz_t g, uint32_t mod) fmpz_invmod_ui(fmpz_t f, const fmpz_t g, const uint32_t mod)
{ {
fmpz_t modulus; fmpz_t modulus;
@ -219,10 +219,10 @@ fmpz_add_n(fmpz_t f, const fmpz_t g, const fmpz_t h)
/*------------------------------------------------------------------------*/ /*------------------------------------------------------------------------*/
void void
poly_starmultiply(fmpz_poly_t a, poly_starmultiply(const fmpz_poly_t a,
fmpz_poly_t b, const fmpz_poly_t b,
fmpz_poly_t c, fmpz_poly_t c,
ntru_context *ctx, const ntru_context *ctx,
uint32_t modulus) uint32_t modulus)
{ {
fmpz_poly_t a_tmp; fmpz_poly_t a_tmp;
@ -277,9 +277,9 @@ poly_starmultiply(fmpz_poly_t a,
/*------------------------------------------------------------------------*/ /*------------------------------------------------------------------------*/
bool bool
poly_inverse_poly_q(fmpz_poly_t a, poly_inverse_poly_q(const fmpz_poly_t a,
fmpz_poly_t Fq, fmpz_poly_t Fq,
ntru_context *ctx) const ntru_context *ctx)
{ {
bool retval = false; bool retval = false;
int k = 0, int k = 0,
@ -389,9 +389,9 @@ _cleanup:
/*------------------------------------------------------------------------*/ /*------------------------------------------------------------------------*/
bool bool
poly_inverse_poly_p(fmpz_poly_t a, poly_inverse_poly_p(const fmpz_poly_t a,
fmpz_poly_t Fp, fmpz_poly_t Fp,
ntru_context *ctx) const ntru_context *ctx)
{ {
bool retval = false; bool retval = false;
int k = 0, int k = 0,
@ -554,7 +554,7 @@ cleanup:
/*------------------------------------------------------------------------*/ /*------------------------------------------------------------------------*/
void void
poly_draw(fmpz_poly_t poly) poly_draw(const fmpz_poly_t poly)
{ {
fmpz_poly_print(poly); fmpz_poly_print(poly);
flint_printf("\n"); flint_printf("\n");
@ -563,7 +563,7 @@ poly_draw(fmpz_poly_t poly)
/*------------------------------------------------------------------------*/ /*------------------------------------------------------------------------*/
void void
poly_draw_pretty(fmpz_poly_t poly) poly_draw_pretty(const fmpz_poly_t poly)
{ {
fmpz_poly_print_pretty(poly, "x"); fmpz_poly_print_pretty(poly, "x");
flint_printf("\n"); flint_printf("\n");

Ver arquivo

@ -102,7 +102,7 @@ poly_delete_all(fmpz_poly_t poly, ...);
*/ */
void void
fmpz_poly_mod_unsigned(fmpz_poly_t a, fmpz_poly_mod_unsigned(fmpz_poly_t a,
uint32_t mod); const uint32_t mod);
/** /**
* Calls fmpz_poly_get_nmod_poly() and * Calls fmpz_poly_get_nmod_poly() and
@ -118,7 +118,7 @@ fmpz_poly_mod_unsigned(fmpz_poly_t a,
*/ */
void void
fmpz_poly_mod(fmpz_poly_t a, fmpz_poly_mod(fmpz_poly_t a,
uint32_t mod); const uint32_t mod);
/** /**
* The same as fmpz_poly_set_coeff_fmpz() except that it * The same as fmpz_poly_set_coeff_fmpz() except that it
@ -145,7 +145,7 @@ fmpz_poly_set_coeff_fmpz_n(fmpz_poly_t poly,
int int
fmpz_invmod_ui(fmpz_t f, fmpz_invmod_ui(fmpz_t f,
const fmpz_t g, const fmpz_t g,
uint32_t mod); const uint32_t mod);
/** /**
* The same as fmpz_add() except that it handles NULL * The same as fmpz_add() except that it handles NULL
@ -165,10 +165,10 @@ fmpz_add_n(fmpz_t f, const fmpz_t g, const fmpz_t h);
* @param modulus whether we use p or q * @param modulus whether we use p or q
*/ */
void void
poly_starmultiply(fmpz_poly_t a, poly_starmultiply(const fmpz_poly_t a,
fmpz_poly_t b, const fmpz_poly_t b,
fmpz_poly_t c, fmpz_poly_t c,
ntru_context *ctx, const ntru_context *ctx,
uint32_t modulus); uint32_t modulus);
/** /**
@ -184,9 +184,9 @@ poly_starmultiply(fmpz_poly_t a,
* @return true if invertible, false if not * @return true if invertible, false if not
*/ */
bool bool
poly_inverse_poly_q(fmpz_poly_t a, poly_inverse_poly_q(const fmpz_poly_t a,
fmpz_poly_t Fq, fmpz_poly_t Fq,
ntru_context *ctx); const ntru_context *ctx);
/** /**
* Compute the inverse of a polynomial in (Z/pZ)[X]/(X^N - 1). * Compute the inverse of a polynomial in (Z/pZ)[X]/(X^N - 1).
@ -198,9 +198,9 @@ poly_inverse_poly_q(fmpz_poly_t a,
* @param ctx NTRU context * @param ctx NTRU context
*/ */
bool bool
poly_inverse_poly_p(fmpz_poly_t a, poly_inverse_poly_p(const fmpz_poly_t a,
fmpz_poly_t Fp, fmpz_poly_t Fp,
ntru_context *ctx); const ntru_context *ctx);
/** /**
* Draws a polynomial to stdout. * Draws a polynomial to stdout.
@ -208,7 +208,7 @@ poly_inverse_poly_p(fmpz_poly_t a,
* @param poly draw this * @param poly draw this
*/ */
void void
poly_draw(fmpz_poly_t poly); poly_draw(const fmpz_poly_t poly);
/** /**
* Draws a polynomial to stdout, * Draws a polynomial to stdout,
@ -217,7 +217,7 @@ poly_draw(fmpz_poly_t poly);
* @param poly draw this * @param poly draw this
*/ */
void void
poly_draw_pretty(fmpz_poly_t poly); poly_draw_pretty(const fmpz_poly_t poly);
#endif /* NTRU_POLY_H */ #endif /* NTRU_POLY_H */