42 #include <fmpz_poly.h>
66 char *bin_string =
ntru_malloc(
sizeof(*bin_string) *
70 bin_string[bin_string_size - 1] =
'\0';
72 for (i =
ASCII_BITS - 1; i >= 0; --i, value >>= 1)
73 bin_string[i] = (value & 1) +
'0';
84 fmpz_poly_t *new_poly =
ntru_malloc(
sizeof(*new_poly));
86 fmpz_poly_init(*new_poly);
88 while (to_poly[i] && i < params->N) {
89 fmpz_poly_set_coeff_si(*new_poly,
91 (to_poly[i] ==
'0') ? -1 : 1);
103 char *cur = to_poly->
ptr;
107 fmpz_poly_t **poly_array;
109 for (uint32_t i = 0; i < to_poly->
len; i++) {
111 memcpy(out + out_len, tmp_string,
ASCII_BITS);
119 (strlen(out) / params->
N + 1));
121 for (uint32_t i = 0; i < out_len; i += params->
N) {
122 char chunk[params->
N + 1];
123 size_t real_chunk_size;
126 (out_len - i > params->
N) ? params->
N : out_len - i;
128 memcpy(chunk, out + i, real_chunk_size);
129 chunk[real_chunk_size] =
'\0';
138 poly_array[polyc] = NULL;
151 guchar *base64_decoded = NULL,
153 string *new_string =
ntru_malloc(
sizeof(*new_string));
154 fmpz_poly_t **poly_array;
158 memcpy(tmp, to_poly->
ptr, to_poly->
len);
159 tmp[to_poly->
len] =
'\0';
161 base_tmp = g_base64_decode((
const gchar *)tmp, &out_len);
164 REALLOC(tmp,
sizeof(
char) * (out_len + 1));
165 memcpy(tmp, base_tmp, out_len);
168 base64_decoded = g_base64_decode((
const gchar *)tmp, &out_len);
170 new_string->
ptr = (
char *)base64_decoded;
171 new_string->
len = (
unsigned long)(out_len);
174 (new_string->
len / params->
N));
176 while (i < new_string->len) {
178 fmpz_poly_t *new_poly =
ntru_malloc(
sizeof(*new_poly));
180 fmpz_poly_init(*new_poly);
182 while (j < params->N) {
183 fmpz_poly_set_coeff_si(*new_poly,
185 (uint8_t)(base64_decoded[i]));
192 for (uint32_t k = j; k < params->
N; k++) {
193 fmpz_poly_set_coeff_si(*new_poly,
198 poly_array[polyc] = new_poly;
202 poly_array[polyc] = NULL;
fmpz_poly_t ** ascii_to_bin_poly_arr(const string *to_poly, const ntru_params *params)
void string_delete(string *del_string)
fmpz_poly_t ** base64_to_poly_arr(const string *to_poly, const ntru_params *params)
#define REALLOC(ptr, size)
static char * get_int_to_bin_str(uint8_t value)
void * ntru_malloc(size_t size)
fmpz_poly_t * ascii_bin_to_bin_poly(const char *to_poly, const ntru_params *params)
header for ntru_ascii_poly.c