libfhe
fhe_poly.h
Go to the documentation of this file.
1// libfhe
2//
3// This program is free software: you can redistribute it and/or modify
4// it under the terms of the GNU General Public License as published by
5// the Free Software Foundation, either version 3 of the License, or
6// (at your option) any later version.
7//
8// This program is distributed in the hope that it will be useful,
9// but WITHOUT ANY WARRANTY; without even the implied warranty of
10// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11// GNU General Public License for more details.
12//
13// You should have received a copy of the GNU General Public License
14// along with this program. If not, see <http://www.gnu.org/licenses/>.
15//
16//===----------------------------------------------------------------------===//
23//===----------------------------------------------------------------------===//
24
25#ifndef FHE_POLY_H
26#define FHE_POLY_H
27
28#include "fhe_ring.h"
29
45typedef struct poly_t {
48 char is_ntt;
51
58int poly_zero(const ring_t *const r, poly_t *p);
59
67void poly_encode(const ring_t *const r, const uint_t *const u, poly_t *p);
68
76void poly_decode(uint_t *out, const poly_t *const p, uint_t t);
77
84
91
98void poly_clone(poly_t *dst, const poly_t *const src);
99
107void poly_cmul(poly_t *out, const poly_t *const in, int_t c);
108
116void poly_rand(const ring_t *const r, poly_t *out, DISTRIBUTION d);
117
124
132void poly_add(poly_t *c, const poly_t *const a, const poly_t *const b);
140void poly_sub(poly_t *c, const poly_t *const a, const poly_t *const b);
141
149void poly_mul(poly_t *c, const poly_t *const a, const poly_t *const b);
150
157void poly_serialize(unsigned char *buf, const poly_t *const p);
158
165void poly_deserialize(poly_t *p, const unsigned char *const buf);
166
174int poly_cmp(const poly_t *const a, const poly_t *const b);
175
183
184#endif /* FHE_POLY_H */
uint64_t uint_t
Default unsigned integer width is 64 bits.
Definition: fhe_config.h:49
int64_t int_t
Default integer width is 64 bits.
Definition: fhe_config.h:44
DISTRIBUTION
Enum determines sampling distribution.
Definition: fhe_config.h:64
void poly_clone(poly_t *dst, const poly_t *const src)
Clone a polynomial.
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.
void poly_rand(const ring_t *const r, poly_t *out, DISTRIBUTION d)
Sample a random polynomial.
void poly_sub(poly_t *c, const poly_t *const a, const poly_t *const b)
Polynomial subtraction.
void poly_serialize(unsigned char *buf, const poly_t *const p)
Serialize a polynomial into a byte stream.
void poly_neg(poly_t *p)
Negate a polynomial.
void poly_cmul(poly_t *out, const poly_t *const in, int_t c)
Constant multiplication.
void poly_intt(poly_t *p)
Convert back from NTT form.
struct poly_t poly_t
Main Polynomial type used to represent polynomials over for a generic modulus .
void poly_mul(poly_t *c, const poly_t *const a, const poly_t *const b)
Polynomial multiplication.
void poly_add(poly_t *c, const poly_t *const a, const poly_t *const b)
Polynomial addition.
void poly_free(poly_t *p)
Destroy a Polynomial Free any memory allocated by the polynomial.
int poly_zero(const ring_t *const r, poly_t *p)
Initialize the zero polynomial.
void poly_deserialize(poly_t *p, const unsigned char *const buf)
Deserialize a polynomial from a byte stream.
void poly_decode(uint_t *out, const poly_t *const p, uint_t t)
Decode a polynomial into its original form.
void poly_ntt(poly_t *p)
Convert to NTT form.
void poly_encode(const ring_t *const r, const uint_t *const u, poly_t *p)
Encode a polynomial into its CRT representation.
Main Polynomial type used to represent polynomials over for a generic modulus .
Definition: fhe_poly.h:45
ring_t * r
Reference to the base ring.
Definition: fhe_poly.h:46
uint_t * b
Polynomial coefficients.
Definition: fhe_poly.h:47
char is_ntt
Definition: fhe_poly.h:48
Main Ring type used to define a polynomial ring.
Definition: fhe_ring.h:34