ALL: improve readability

This commit is contained in:
hasufell 2014-05-28 01:17:19 +02:00
parent d8f95240c0
commit 2ec61bc87e
No known key found for this signature in database
GPG Key ID: 220CD1C5BDEED020
8 changed files with 88 additions and 0 deletions

View File

@ -76,6 +76,8 @@ static char *
get_bin_arr_to_ascii(char *binary_rep); get_bin_arr_to_ascii(char *binary_rep);
/*------------------------------------------------------------------------*/
static char * static char *
get_int_to_bin_str(uint8_t value) get_int_to_bin_str(uint8_t value)
{ {
@ -93,6 +95,8 @@ get_int_to_bin_str(uint8_t value)
return bin_string; return bin_string;
} }
/*------------------------------------------------------------------------*/
static char * static char *
get_bin_arr_to_ascii(char *binary_rep) get_bin_arr_to_ascii(char *binary_rep)
{ {
@ -121,6 +125,8 @@ get_bin_arr_to_ascii(char *binary_rep)
return int_string; return int_string;
} }
/*------------------------------------------------------------------------*/
fmpz_poly_t * fmpz_poly_t *
ascii_bin_to_bin_poly(char *to_poly, ntru_context *ctx) ascii_bin_to_bin_poly(char *to_poly, ntru_context *ctx)
{ {
@ -148,6 +154,8 @@ ascii_bin_to_bin_poly(char *to_poly, ntru_context *ctx)
return new_poly; return new_poly;
} }
/*------------------------------------------------------------------------*/
fmpz_poly_t ** fmpz_poly_t **
ascii_to_bin_poly_arr(char *to_poly, ntru_context *ctx) ascii_to_bin_poly_arr(char *to_poly, ntru_context *ctx)
{ {
@ -190,6 +198,8 @@ ascii_to_bin_poly_arr(char *to_poly, ntru_context *ctx)
return poly_array; return poly_array;
} }
/*------------------------------------------------------------------------*/
string * string *
bin_poly_to_ascii(fmpz_poly_t poly, bin_poly_to_ascii(fmpz_poly_t poly,
ntru_context *ctx) ntru_context *ctx)
@ -218,6 +228,8 @@ bin_poly_to_ascii(fmpz_poly_t poly,
return result_string; return result_string;
} }
/*------------------------------------------------------------------------*/
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, ntru_context *ctx)
{ {
@ -266,6 +278,8 @@ bin_poly_arr_to_ascii(fmpz_poly_t **bin_poly_arr, ntru_context *ctx)
return result_string; return result_string;
} }
/*------------------------------------------------------------------------*/
fmpz_poly_t ** fmpz_poly_t **
base64_to_poly_arr(string *to_poly, ntru_context *ctx) base64_to_poly_arr(string *to_poly, ntru_context *ctx)
{ {
@ -321,6 +335,8 @@ base64_to_poly_arr(string *to_poly, ntru_context *ctx)
return poly_array; return poly_array;
} }
/*------------------------------------------------------------------------*/
string * string *
poly_to_base64(fmpz_poly_t poly, poly_to_base64(fmpz_poly_t poly,
ntru_context *ctx) ntru_context *ctx)
@ -349,6 +365,8 @@ poly_to_base64(fmpz_poly_t poly,
return result_string; return result_string;
} }
/*------------------------------------------------------------------------*/
string * string *
poly_arr_to_base64(fmpz_poly_t **poly_array, poly_arr_to_base64(fmpz_poly_t **poly_array,
ntru_context *ctx) ntru_context *ctx)
@ -388,3 +406,5 @@ poly_arr_to_base64(fmpz_poly_t **poly_array,
return result_string; return result_string;
} }
/*------------------------------------------------------------------------*/

View File

@ -36,6 +36,8 @@
#include <fmpz.h> #include <fmpz.h>
/*------------------------------------------------------------------------*/
void void
ntru_decrypt_poly( ntru_decrypt_poly(
fmpz_poly_t encr_msg, fmpz_poly_t encr_msg,
@ -57,6 +59,8 @@ ntru_decrypt_poly(
fmpz_poly_clear(a); fmpz_poly_clear(a);
} }
/*------------------------------------------------------------------------*/
string * string *
ntru_decrypt_string( ntru_decrypt_string(
string *encr_msg, string *encr_msg,
@ -82,3 +86,5 @@ ntru_decrypt_string(
return decr_msg; return decr_msg;
} }
/*------------------------------------------------------------------------*/

View File

@ -37,6 +37,8 @@
#include <fmpz.h> #include <fmpz.h>
/*------------------------------------------------------------------------*/
void void
ntru_encrypt_poly( ntru_encrypt_poly(
fmpz_poly_t msg_bin, fmpz_poly_t msg_bin,
@ -58,6 +60,8 @@ ntru_encrypt_poly(
fmpz_poly_clear(tmp_poly_msg); fmpz_poly_clear(tmp_poly_msg);
} }
/*------------------------------------------------------------------------*/
string * string *
ntru_encrypt_string( ntru_encrypt_string(
char *msg, char *msg,
@ -82,3 +86,5 @@ ntru_encrypt_string(
return enc_msg; return enc_msg;
} }
/*------------------------------------------------------------------------*/

View File

@ -44,6 +44,8 @@
#define STD_FILE_BUF 4096 #define STD_FILE_BUF 4096
/*------------------------------------------------------------------------*/
string * string *
read_file(char const * const filename) read_file(char const * const filename)
{ {
@ -90,6 +92,8 @@ read_file(char const * const filename)
} }
} }
/*------------------------------------------------------------------------*/
void void
write_file(string const *wstring, char const * const filename) write_file(string const *wstring, char const * const filename)
{ {
@ -105,3 +109,5 @@ write_file(string const *wstring, char const * const filename)
fclose(fp); fclose(fp);
} }
/*------------------------------------------------------------------------*/

View File

@ -36,6 +36,8 @@
#include <stdbool.h> #include <stdbool.h>
/*------------------------------------------------------------------------*/
bool bool
ntru_create_keypair( ntru_create_keypair(
fmpz_poly_t f, fmpz_poly_t f,
@ -82,6 +84,8 @@ cleanup:
return retval; return retval;
} }
/*------------------------------------------------------------------------*/
void void
ntru_delete_keypair(keypair *pair) ntru_delete_keypair(keypair *pair)
{ {
@ -89,3 +93,5 @@ ntru_delete_keypair(keypair *pair)
fmpz_poly_clear(pair->priv); fmpz_poly_clear(pair->priv);
fmpz_poly_clear(pair->pub); fmpz_poly_clear(pair->pub);
} }
/*------------------------------------------------------------------------*/

View File

@ -32,6 +32,8 @@
#include <stdlib.h> #include <stdlib.h>
/*------------------------------------------------------------------------*/
void * void *
ntru_malloc(size_t size) ntru_malloc(size_t size)
{ {
@ -48,6 +50,8 @@ ntru_malloc(size_t size)
return ptr; return ptr;
} }
/*------------------------------------------------------------------------*/
void * void *
ntru_calloc(size_t nmemb, size_t size) ntru_calloc(size_t nmemb, size_t size)
{ {
@ -63,3 +67,5 @@ ntru_calloc(size_t nmemb, size_t size)
return ptr; return ptr;
} }
/*------------------------------------------------------------------------*/

View File

@ -31,6 +31,8 @@
#include <stdio.h> #include <stdio.h>
/*------------------------------------------------------------------------*/
void void
prints(string *print_string) prints(string *print_string)
{ {
@ -39,9 +41,13 @@ prints(string *print_string)
} }
/*------------------------------------------------------------------------*/
void void
string_delete(string *del_string) string_delete(string *del_string)
{ {
free(del_string->ptr); free(del_string->ptr);
free(del_string); free(del_string);
} }
/*------------------------------------------------------------------------*/

View File

@ -57,6 +57,8 @@ void poly_mod2_to_modq(fmpz_poly_t a,
ntru_context *ctx); ntru_context *ctx);
/*------------------------------------------------------------------------*/
static void static void
poly_mod2_to_modq(fmpz_poly_t a, poly_mod2_to_modq(fmpz_poly_t a,
fmpz_poly_t Fq, fmpz_poly_t Fq,
@ -85,6 +87,8 @@ poly_mod2_to_modq(fmpz_poly_t a,
} }
/*------------------------------------------------------------------------*/
void void
poly_new(fmpz_poly_t new_poly, poly_new(fmpz_poly_t new_poly,
int const * const c, int const * const c,
@ -96,12 +100,16 @@ poly_new(fmpz_poly_t new_poly,
fmpz_poly_set_coeff_si(new_poly, i, c[i]); fmpz_poly_set_coeff_si(new_poly, i, c[i]);
} }
/*------------------------------------------------------------------------*/
void void
poly_delete(fmpz_poly_t poly) poly_delete(fmpz_poly_t poly)
{ {
fmpz_poly_clear(poly); fmpz_poly_clear(poly);
} }
/*------------------------------------------------------------------------*/
void void
poly_delete_array(fmpz_poly_t **poly_array) poly_delete_array(fmpz_poly_t **poly_array)
{ {
@ -115,6 +123,8 @@ poly_delete_array(fmpz_poly_t **poly_array)
free(poly_array); free(poly_array);
} }
/*------------------------------------------------------------------------*/
void void
poly_delete_all(fmpz_poly_t poly, ...) poly_delete_all(fmpz_poly_t poly, ...)
{ {
@ -130,6 +140,8 @@ poly_delete_all(fmpz_poly_t poly, ...)
va_end(args); va_end(args);
} }
/*------------------------------------------------------------------------*/
void void
fmpz_poly_mod_unsigned(fmpz_poly_t a, fmpz_poly_mod_unsigned(fmpz_poly_t a,
uint32_t mod) uint32_t mod)
@ -144,6 +156,8 @@ fmpz_poly_mod_unsigned(fmpz_poly_t a,
nmod_poly_clear(nmod_tmp); nmod_poly_clear(nmod_tmp);
} }
/*------------------------------------------------------------------------*/
void void
fmpz_poly_mod(fmpz_poly_t a, fmpz_poly_mod(fmpz_poly_t a,
uint32_t mod) uint32_t mod)
@ -158,6 +172,8 @@ fmpz_poly_mod(fmpz_poly_t a,
nmod_poly_clear(nmod_tmp); nmod_poly_clear(nmod_tmp);
} }
/*------------------------------------------------------------------------*/
void void
fmpz_poly_set_coeff_fmpz_n(fmpz_poly_t poly, slong n, fmpz_poly_set_coeff_fmpz_n(fmpz_poly_t poly, slong n,
const fmpz_t x) const fmpz_t x)
@ -168,6 +184,8 @@ fmpz_poly_set_coeff_fmpz_n(fmpz_poly_t poly, slong n,
fmpz_poly_set_coeff_si(poly, n, 0); fmpz_poly_set_coeff_si(poly, n, 0);
} }
/*------------------------------------------------------------------------*/
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, uint32_t mod)
{ {
@ -178,6 +196,8 @@ fmpz_invmod_ui(fmpz_t f, const fmpz_t g, uint32_t mod)
return fmpz_invmod(f, g, modulus); return fmpz_invmod(f, g, modulus);
} }
/*------------------------------------------------------------------------*/
void void
fmpz_add_n(fmpz_t f, const fmpz_t g, const fmpz_t h) fmpz_add_n(fmpz_t f, const fmpz_t g, const fmpz_t h)
{ {
@ -193,6 +213,8 @@ fmpz_add_n(fmpz_t f, const fmpz_t g, const fmpz_t h)
} }
} }
/*------------------------------------------------------------------------*/
void void
poly_starmultiply(fmpz_poly_t a, poly_starmultiply(fmpz_poly_t a,
fmpz_poly_t b, fmpz_poly_t b,
@ -249,6 +271,8 @@ poly_starmultiply(fmpz_poly_t a,
fmpz_poly_clear(a_tmp); fmpz_poly_clear(a_tmp);
} }
/*------------------------------------------------------------------------*/
bool bool
poly_inverse_poly_q(fmpz_poly_t a, poly_inverse_poly_q(fmpz_poly_t a,
fmpz_poly_t Fq, fmpz_poly_t Fq,
@ -364,6 +388,8 @@ cleanup:
return retval; return retval;
} }
/*------------------------------------------------------------------------*/
bool bool
poly_inverse_poly_p(fmpz_poly_t a, poly_inverse_poly_p(fmpz_poly_t a,
fmpz_poly_t Fp, fmpz_poly_t Fp,
@ -532,6 +558,8 @@ cleanup:
return retval; return retval;
} }
/*------------------------------------------------------------------------*/
void void
poly_draw(fmpz_poly_t poly) poly_draw(fmpz_poly_t poly)
{ {
@ -539,9 +567,13 @@ poly_draw(fmpz_poly_t poly)
flint_printf("\n"); flint_printf("\n");
} }
/*------------------------------------------------------------------------*/
void void
poly_draw_pretty(fmpz_poly_t poly) poly_draw_pretty(fmpz_poly_t poly)
{ {
fmpz_poly_print_pretty(poly, "x"); fmpz_poly_print_pretty(poly, "x");
flint_printf("\n"); flint_printf("\n");
} }
/*------------------------------------------------------------------------*/