libfhe
Data Structures | Typedefs | Functions
fhe_poly.h File Reference
#include "fhe_ring.h"

Go to the source code of this file.

Data Structures

struct  poly_t
 Main Polynomial type used to represent polynomials over $R = Z_M[X] / <x^d + 1>$ for a generic modulus $M$. More...
 

Typedefs

typedef struct poly_t poly_t
 Main Polynomial type used to represent polynomials over $R = Z_M[X] / <x^d + 1>$ for a generic modulus $M$. More...
 

Functions

int poly_zero (const ring_t *const r, poly_t *p)
 Initialize the zero polynomial. More...
 
void poly_encode (const ring_t *const r, const uint_t *const u, poly_t *p)
 Encode a polynomial into its CRT representation. More...
 
void poly_decode (uint_t *out, const poly_t *const p, uint_t t)
 Decode a polynomial into its original form. More...
 
void poly_ntt (poly_t *p)
 Convert to NTT form. More...
 
void poly_intt (poly_t *p)
 Convert back from NTT form. More...
 
void poly_clone (poly_t *dst, const poly_t *const src)
 Clone a polynomial. More...
 
void poly_cmul (poly_t *out, const poly_t *const in, int_t c)
 Constant multiplication. More...
 
void poly_rand (const ring_t *const r, poly_t *out, DISTRIBUTION d)
 Sample a random polynomial. More...
 
void poly_neg (poly_t *p)
 Negate a polynomial. More...
 
void poly_add (poly_t *c, const poly_t *const a, const poly_t *const b)
 Polynomial addition. More...
 
void poly_sub (poly_t *c, const poly_t *const a, const poly_t *const b)
 Polynomial subtraction. More...
 
void poly_mul (poly_t *c, const poly_t *const a, const poly_t *const b)
 Polynomial multiplication. More...
 
void poly_serialize (unsigned char *buf, const poly_t *const p)
 Serialize a polynomial into a byte stream. More...
 
void poly_deserialize (poly_t *p, const unsigned char *const buf)
 Deserialize a polynomial from a byte stream. More...
 
int poly_cmp (const poly_t *const a, const poly_t *const b)
 Test two polynomials for equality Returns 1 if polynomials are equal, 0 otherwise. More...
 
void poly_free (poly_t *p)
 Destroy a Polynomial Free any memory allocated by the polynomial. More...
 

Detailed Description

This file contains the declaration of the poly_t type, which implements arithmetic over the cyclotomic polynomial ring $R = Z_M[X] / <x^d + 1>$ for a generic modulus $M$.

Typedef Documentation

◆ poly_t

typedef struct poly_t poly_t

Main Polynomial type used to represent polynomials over $R = Z_M[X] / <x^d + 1>$ for a generic modulus $M$.

Polynomials are represented using the ring isomorphism provided by the Chinese Remainder Theorem.

Namely, a polynomial with coefficients mod $M$ is decomposed into $n$ polynomials with coefficients mod $m_i$ of degree $d$ where $ M = \prod_i m_i $.

Residues $m_i$ are pairwise coprime word-sized integers (typically between 32-60 bits)

Function Documentation

◆ poly_add()

void poly_add ( poly_t c,
const poly_t *const  a,
const poly_t *const  b 
)

Polynomial addition.

Parameters
[out]cResulting sum
aAddend
bAddend

◆ poly_clone()

void poly_clone ( poly_t dst,
const poly_t *const  src 
)

Clone a polynomial.

Parameters
[out]dstDestination polynomial
srcSource polynomial

◆ poly_cmp()

int poly_cmp ( const poly_t *const  a,
const poly_t *const  b 
)

Test two polynomials for equality Returns 1 if polynomials are equal, 0 otherwise.

Parameters
aPolynomial
bPolynomial

◆ poly_cmul()

void poly_cmul ( poly_t out,
const poly_t *const  in,
int_t  c 
)

Constant multiplication.

Parameters
[out]outResulting polynomial
inInput polynomial
cConstant multiplier

◆ poly_decode()

void poly_decode ( uint_t out,
const poly_t *const  p,
uint_t  t 
)

Decode a polynomial into its original form.

Parameters
[out]outdecoded polynomial
pencoded polynomial
tmodulus

◆ poly_deserialize()

void poly_deserialize ( poly_t p,
const unsigned char *const  buf 
)

Deserialize a polynomial from a byte stream.

Parameters
[out]pDeserialized polynomial
bufSerialized polynomial

◆ poly_encode()

void poly_encode ( const ring_t *const  r,
const uint_t *const  u,
poly_t p 
)

Encode a polynomial into its CRT representation.

Parameters
rUnderlying ring
uPolynomial coefficients
[out]pEncoded polynomial

◆ poly_free()

void poly_free ( poly_t p)

Destroy a Polynomial Free any memory allocated by the polynomial.

Parameters
pPolynomial

◆ poly_intt()

void poly_intt ( poly_t p)

Convert back from NTT form.

Parameters
pPolynomial

◆ poly_mul()

void poly_mul ( poly_t c,
const poly_t *const  a,
const poly_t *const  b 
)

Polynomial multiplication.

Parameters
[out]cResulting product
amultiplicand
bmultiplier

◆ poly_neg()

void poly_neg ( poly_t p)

Negate a polynomial.

Parameters
pPolynomial

◆ poly_ntt()

void poly_ntt ( poly_t p)

Convert to NTT form.

Parameters
pPolynomial

◆ poly_rand()

void poly_rand ( const ring_t *const  r,
poly_t out,
DISTRIBUTION  d 
)

Sample a random polynomial.

Parameters
rBase ring
[out]outRandom polynomial
dSampling distribution

◆ poly_serialize()

void poly_serialize ( unsigned char *  buf,
const poly_t *const  p 
)

Serialize a polynomial into a byte stream.

Parameters
[out]bufSerialized polynomial
pPolynomial to be serialized

◆ poly_sub()

void poly_sub ( poly_t c,
const poly_t *const  a,
const poly_t *const  b 
)

Polynomial subtraction.

Parameters
[out]cResulting difference
aMinuend
bSubtrahend

◆ poly_zero()

int poly_zero ( const ring_t *const  r,
poly_t p 
)

Initialize the zero polynomial.

Parameters
rUnderlying ring
[out]pZero polynomial