post quantum cryptography
Highly optimized implementation of the NTRUEncrypt algorithm
Functions
/home/travis/build/hasufell/pqc/src/ntru_poly_ascii.c File Reference

polynomials to acii More...

#include "ntru_poly_ascii.h"
#include "ntru_common.h"
#include "ntru_mem.h"
#include "ntru_params.h"
#include "ntru_poly.h"
#include "ntru_string.h"
#include <glib.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <fmpz_poly.h>
#include <fmpz.h>
Include dependency graph for ntru_poly_ascii.c:

Go to the source code of this file.

Functions

static stringget_bin_arr_to_ascii (const char *binary_rep)
stringbin_poly_to_ascii (const fmpz_poly_t poly, const ntru_params *params)
stringbin_poly_arr_to_ascii (const fmpz_poly_t **bin_poly_arr, const uint32_t poly_c, const ntru_params *params)
stringpoly_to_ascii (const fmpz_poly_t poly, const ntru_params *params)
stringpoly_arr_to_ascii (const fmpz_poly_t **poly_array, const uint32_t poly_c, const ntru_params *params)
stringpoly_to_base64 (const fmpz_poly_t poly, const ntru_params *params)
stringpoly_arr_to_base64 (const fmpz_poly_t **poly_array, const uint32_t poly_c, const ntru_params *params)

Detailed Description

polynomials to acii

This file allows to convert polynomials to ascii strings, including base64 encoded.

Definition in file ntru_poly_ascii.c.


Function Documentation

string* bin_poly_arr_to_ascii ( const fmpz_poly_t **  bin_poly_arr,
const uint32_t  poly_c,
const ntru_params params 
)

Convert an array of binary polynomials back to a real string. The polynomial coefficients represent a binary format of the ascii string with the following mapping:

1 => 1

-1 => 0

2 => 0

The 2's are only used for filling up the last polynomial, so they will just end up as '\0's at the end of the string and will not confuse the result.

Parameters:
bin_poly_arrthe array of polynomials
poly_cthe amount of polynomials in bin_poly_arr
paramsthe NTRU parameters
Returns:
the real string, newly allocated

Definition at line 143 of file ntru_poly_ascii.c.

string* bin_poly_to_ascii ( const fmpz_poly_t  poly,
const ntru_params params 
)

Convert a single binary polynomial back to a real string. The polynomial coefficients represent a binary format of the ascii string with the following mapping:

1 => 1

-1 => 0

2 => 0

The 2's are only used for filling up the rest of the polynomial, so they will just end up as '\0's at the end of the string and will not confuse the result.

Parameters:
polythe binary polynomial to convert
paramsthe NTRU parameters
Returns:
the real string, newly allocated

Definition at line 114 of file ntru_poly_ascii.c.

static string * get_bin_arr_to_ascii ( const char *  binary_rep) [static]

Converts a binary representation of multiple concatenated integers to the corresponding array of ascii chars, which is NULL-terminated.

It reads in 8bit chunks, as in:

10110101|00111100|01011001 => 90|60|89 => "Z<Y"

Chunks that are 00000000 are stripped from the result.

Parameters:
binary_repthe binary representation of multiple integers concatenated
Returns:
string of corresponding ascii-chars, newly allocated

Definition at line 69 of file ntru_poly_ascii.c.

string* poly_arr_to_ascii ( const fmpz_poly_t **  poly_array,
const uint32_t  poly_c,
const ntru_params params 
)

Convert an array of polynomials back to a real string. The polynomial coefficients are expected to be in the range [0, q-1] and will be casted back to chars without any mapping.

Trailing q coefficients are only used for filling up the rest of a polynomial with '\0', so they will not confuse the result.

Parameters:
poly_arraythe array of polynomials
poly_cthe amount of polynomials in poly_arr
paramsthe NTRU parameters
Returns:
the real string, newly allocated

Definition at line 203 of file ntru_poly_ascii.c.

string* poly_arr_to_base64 ( const fmpz_poly_t **  poly_arr,
const uint32_t  poly_c,
const ntru_params params 
)

Convert an array of polynomials back to a real string which is base64 encoded. The polynomial coefficients are expected to be in the range [0, q-1] and will be casted back to chars without any mapping.

Trailing q coefficients are only used for filling up the rest of a polynomial with '\0', so they will not confuse the result.

Parameters:
poly_arrthe array of polynomials
poly_cthe amount of polynomials in poly_arr
paramsthe NTRU parameters
Returns:
the real string, newly allocated

Definition at line 264 of file ntru_poly_ascii.c.

string* poly_to_ascii ( const fmpz_poly_t  poly,
const ntru_params params 
)

Convert a single polynom back to a real string which is ascii encoded (full 256 C char spectrum). The polynomial coefficients are expected to be in the range [0, q-1] and will be casted back to chars without any mapping.

Trailing q coefficients are only used for filling up the rest of a polynomial with '\0', so they will not confuse the result.

Parameters:
polythe polynomial to convert
paramsthe NTRU parameters
Returns:
the real string, newly allocated

Definition at line 180 of file ntru_poly_ascii.c.

string* poly_to_base64 ( const fmpz_poly_t  poly,
const ntru_params params 
)

Convert a single polynom back to a real string which is base64 encoded. The polynomial coefficients are expected to be in the range [0, q-1] and will be casted back to chars without any mapping.

Trailing q coefficients are only used for filling up the rest of a polynomial with '\0', so they will not confuse the result.

Parameters:
polythe polynomial to convert
paramsthe NTRU parameters
Returns:
the real string, newly allocated

Definition at line 237 of file ntru_poly_ascii.c.

 All Data Structures Files Functions Variables Typedefs Defines