libfhe
fhe_bgv.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//===----------------------------------------------------------------------===//
22//===----------------------------------------------------------------------===//
23
24#ifndef FHE_BGV_H
25#define FHE_BGV_H
26
27#include "fhe_poly.h"
28#include "fhe_ring.h"
29
33typedef struct bgv_t {
34 size_t t;
37
41typedef struct bgv_keypair_t {
45
49typedef struct bgv_key_t {
54
58//
62typedef struct bgv_ct_t {
63 size_t n;
66
78int bgv_init(bgv_t *b, size_t lgd, size_t lgq, size_t lgm, size_t t);
79
90void bgv_keygen(const bgv_t *const b, bgv_key_t *k);
91
98void bgv_key_serialize(unsigned char *buf, const bgv_key_t *const k);
99
107void bgv_key_deserialize(const ring_t *const r, bgv_key_t *k,
108 const unsigned char *const buf);
109
121void bgv_encrypt(const bgv_t *const b, bgv_ct_t *c,
122 const bgv_keypair_t *const k, const poly_t *const m);
123
131void bgv_decrypt(poly_t *m, const bgv_ct_t *const c, const poly_t *const s);
132
140
148
155void bgv_key_zero(const ring_t *const r, bgv_key_t *k);
156
164int bgv_key_cmp(const bgv_key_t *const a, const bgv_key_t* const b);
165
173int bgv_ct_init(const ring_t *const r, bgv_ct_t *c, size_t n);
174
184void bgv_ct_add(bgv_ct_t *c, const bgv_ct_t *const a, const bgv_ct_t *const b);
185
197void bgv_ct_mul(bgv_ct_t *c, const bgv_keypair_t *e, const bgv_ct_t *const a,
198 const bgv_ct_t *const b);
199
208void bgv_ct_relin(bgv_ct_t *c, const bgv_keypair_t *const k);
209
216void bgv_ct_serialize(unsigned char *buf, const bgv_ct_t *const c);
217
225void bgv_ct_deserialize(const ring_t *const r, bgv_ct_t *c,
226 const unsigned char *buf);
227
235
236#endif /* FHE_BGV_H */
void bgv_key_serialize(unsigned char *buf, const bgv_key_t *const k)
Serialize a BGV key pair.
struct bgv_key_t bgv_key_t
BGV key pair used to encrypt, decrypt, and relinearize a ciphertext.
struct bgv_keypair_t bgv_keypair_t
Generic key pair wraps a pair of polynomials.
int bgv_init(bgv_t *b, size_t lgd, size_t lgq, size_t lgm, size_t t)
Initialize BGV scheme parameters.
void bgv_ct_add(bgv_ct_t *c, const bgv_ct_t *const a, const bgv_ct_t *const b)
Add two BGV ciphertexts.
int bgv_key_cmp(const bgv_key_t *const a, const bgv_key_t *const b)
Test two keys for equality. Returns 1 if keys are equal, 0 otherwise.
struct bgv_t bgv_t
Main BGV type used to instantiate the scheme.
void bgv_encrypt(const bgv_t *const b, bgv_ct_t *c, const bgv_keypair_t *const k, const poly_t *const m)
Encrypt a polynomial using the BGV scheme.
void bgv_key_zero(const ring_t *const r, bgv_key_t *k)
Initialize an empty key pair.
void bgv_key_free(bgv_key_t *k)
Destroy a BGV key pair Free any memory allocated by the key generation process.
void bgv_ct_deserialize(const ring_t *const r, bgv_ct_t *c, const unsigned char *buf)
Deserialize a BGV ciphertext from a byte stream.
void bgv_decrypt(poly_t *m, const bgv_ct_t *const c, const poly_t *const s)
Decrypt a BGV ciphertext.
int bgv_ct_init(const ring_t *const r, bgv_ct_t *c, size_t n)
Initialize an empty BGV ciphertext.
void bgv_ct_serialize(unsigned char *buf, const bgv_ct_t *const c)
Serialize a BGV ciphertext into a byte stream.
void bgv_key_deserialize(const ring_t *const r, bgv_key_t *k, const unsigned char *const buf)
Deserialize a BGV key pair.
void bgv_ct_mul(bgv_ct_t *c, const bgv_keypair_t *e, const bgv_ct_t *const a, const bgv_ct_t *const b)
Multiply two BGV ciphertexts.
void bgv_free(bgv_t *b)
Destroy a BGV struct. Free any memory allocated by the context.
void bgv_ct_free(bgv_ct_t *c)
Destroy a BGV ciphertext Free any memory allocated by the encryption process.
struct bgv_ct_t bgv_ct_t
BGV Ciphertext consists of polynomials over the ciphertext ring .
void bgv_keygen(const bgv_t *const b, bgv_key_t *k)
Generate a BGV key pair.
void bgv_ct_relin(bgv_ct_t *c, const bgv_keypair_t *const k)
Relinearize a BGV ciphertext in place.
BGV Ciphertext consists of polynomials over the ciphertext ring .
Definition: fhe_bgv.h:62
poly_t * c
Ciphertext polynomials
Definition: fhe_bgv.h:64
size_t n
Number of polynomials.
Definition: fhe_bgv.h:63
BGV key pair used to encrypt, decrypt, and relinearize a ciphertext.
Definition: fhe_bgv.h:49
bgv_keypair_t pub
Public key pair .
Definition: fhe_bgv.h:51
poly_t s
Secret key .
Definition: fhe_bgv.h:50
bgv_keypair_t eval
Evaluation key pair .
Definition: fhe_bgv.h:52
Generic key pair wraps a pair of polynomials.
Definition: fhe_bgv.h:41
poly_t b
Polynomial b.
Definition: fhe_bgv.h:43
poly_t a
Polynomial a.
Definition: fhe_bgv.h:42
Main BGV type used to instantiate the scheme.
Definition: fhe_bgv.h:33
size_t t
Plaintext modulus .
Definition: fhe_bgv.h:34
ring_t r
Polynomial ring .
Definition: fhe_bgv.h:35
Main Polynomial type used to represent polynomials over for a generic modulus .
Definition: fhe_poly.h:45
Main Ring type used to define a polynomial ring.
Definition: fhe_ring.h:34