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

Go to the source code of this file.

Data Structures

struct  bgv_t
 Main BGV type used to instantiate the scheme. More...
 
struct  bgv_keypair_t
 Generic key pair wraps a pair of polynomials. More...
 
struct  bgv_key_t
 BGV key pair used to encrypt, decrypt, and relinearize a ciphertext. More...
 
struct  bgv_ct_t
 BGV Ciphertext consists of $n$ polynomials over the ciphertext ring $R_q = Z_q[x]/<x^d + 1>$. More...
 

Typedefs

typedef struct bgv_t bgv_t
 Main BGV type used to instantiate the scheme.
 
typedef struct bgv_keypair_t bgv_keypair_t
 Generic key pair wraps a pair of polynomials.
 
typedef struct bgv_key_t bgv_key_t
 BGV key pair used to encrypt, decrypt, and relinearize a ciphertext.
 
typedef struct bgv_ct_t bgv_ct_t
 BGV Ciphertext consists of $n$ polynomials over the ciphertext ring $R_q = Z_q[x]/<x^d + 1>$. More...
 

Functions

int bgv_init (bgv_t *b, size_t lgd, size_t lgq, size_t lgm, size_t t)
 Initialize BGV scheme parameters. More...
 
void bgv_keygen (const bgv_t *const b, bgv_key_t *k)
 Generate a BGV key pair. More...
 
void bgv_key_serialize (unsigned char *buf, const bgv_key_t *const k)
 Serialize a BGV key pair. More...
 
void bgv_key_deserialize (const ring_t *const r, bgv_key_t *k, const unsigned char *const buf)
 Deserialize a BGV key pair. More...
 
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. More...
 
void bgv_decrypt (poly_t *m, const bgv_ct_t *const c, const poly_t *const s)
 Decrypt a BGV ciphertext. More...
 
void bgv_free (bgv_t *b)
 Destroy a BGV struct. Free any memory allocated by the context. More...
 
void bgv_key_free (bgv_key_t *k)
 Destroy a BGV key pair Free any memory allocated by the key generation process. More...
 
void bgv_key_zero (const ring_t *const r, bgv_key_t *k)
 Initialize an empty key pair. More...
 
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. More...
 
int bgv_ct_init (const ring_t *const r, bgv_ct_t *c, size_t n)
 Initialize an empty BGV ciphertext. More...
 
void bgv_ct_add (bgv_ct_t *c, const bgv_ct_t *const a, const bgv_ct_t *const b)
 Add two BGV ciphertexts. More...
 
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. More...
 
void bgv_ct_relin (bgv_ct_t *c, const bgv_keypair_t *const k)
 Relinearize a BGV ciphertext in place. More...
 
void bgv_ct_serialize (unsigned char *buf, const bgv_ct_t *const c)
 Serialize a BGV ciphertext into a byte stream. More...
 
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. More...
 
void bgv_ct_free (bgv_ct_t *c)
 Destroy a BGV ciphertext Free any memory allocated by the encryption process. More...
 

Detailed Description

This file contains the declaration of the bgv_t type, which implements the Brakerski-Gentry-Vaikuntanathan encryption scheme.

Typedef Documentation

◆ bgv_ct_t

typedef struct bgv_ct_t bgv_ct_t

BGV Ciphertext consists of $n$ polynomials over the ciphertext ring $R_q = Z_q[x]/<x^d + 1>$.

Note: The Ciphertext size $n$ increases by one after every multiplication.

Function Documentation

◆ bgv_ct_add()

void bgv_ct_add ( bgv_ct_t c,
const bgv_ct_t *const  a,
const bgv_ct_t *const  b 
)

Add two BGV ciphertexts.

Parameters
[out]cThe encryption of a + b
aBGV ciphertext addend
bBGV ciphertext addend

Note: Any of a, b, or c may overlap

◆ bgv_ct_deserialize()

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.

Parameters
rPolynomial ring
[out]cDeserialized ciphertext
bufSerialized ciphertext byte stream

◆ bgv_ct_free()

void bgv_ct_free ( bgv_ct_t c)

Destroy a BGV ciphertext Free any memory allocated by the encryption process.

Parameters
cBGV ciphertext

◆ bgv_ct_init()

int bgv_ct_init ( const ring_t *const  r,
bgv_ct_t c,
size_t  n 
)

Initialize an empty BGV ciphertext.

Parameters
rPolynomial ring
[out]cInitialized ciphertext
nThe ciphertext length (number of underlying polynomials)

◆ bgv_ct_mul()

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.

Parameters
[out]cThe encryption of a * b
eBGV evaluation key used for auto-relinearization
aBGV ciphertext addend
bBGV ciphertext addend

Note: c will be overwritten by this function and SHOULD NOT overlap with neither the multiplier nor the multiplicand.

◆ bgv_ct_relin()

void bgv_ct_relin ( bgv_ct_t c,
const bgv_keypair_t *const  k 
)

Relinearize a BGV ciphertext in place.

Parameters
[out]cThe relinearized ciphertext
kThe relinierization key

Note: c will be overwritten by this function.

◆ bgv_ct_serialize()

void bgv_ct_serialize ( unsigned char *  buf,
const bgv_ct_t *const  c 
)

Serialize a BGV ciphertext into a byte stream.

Parameters
[out]bufSerialized ciphertext byte stream
cCiphertext to be serialized

◆ bgv_decrypt()

void bgv_decrypt ( poly_t m,
const bgv_ct_t *const  c,
const poly_t *const  s 
)

Decrypt a BGV ciphertext.

Parameters
[out]mResulting plaintext
cBGV ciphertext to be decrypted
sBGV secret key with which to decrypt

◆ bgv_encrypt()

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.

  1. Sample random secret key $s \in R_2$ (ternary distribution)
  2. Sample random $a \in R_q$ (uniform distribution)
  3. Sample random $e \in R_q$ (error distribution)
Parameters
bBGV context
[out]cResulting ciphertext
kBGV public key used for encryption
mPlaintext message used for encryption

◆ bgv_free()

void bgv_free ( bgv_t b)

Destroy a BGV struct. Free any memory allocated by the context.

Parameters
bBGV context

◆ bgv_init()

int bgv_init ( bgv_t b,
size_t  lgd,
size_t  lgq,
size_t  lgm,
size_t  t 
)

Initialize BGV scheme parameters.

Parameters
bBGV context
lgdwhere d is the polynomial ring degree (power of 2)
lgqthe bitlength of the ciphertext modulus q
lgmthe bitlength of the residues in the CRT representation of q
tthe plaintext modulus
Returns
0 on success, nonzero otherwise.

◆ bgv_key_cmp()

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.

Parameters
aBGV Key
bBGV Key

◆ bgv_key_deserialize()

void bgv_key_deserialize ( const ring_t *const  r,
bgv_key_t k,
const unsigned char *const  buf 
)

Deserialize a BGV key pair.

Parameters
rPolynomial ring
[out]kDeserialized key pair
bufSerialized key pair

◆ bgv_key_free()

void bgv_key_free ( bgv_key_t k)

Destroy a BGV key pair Free any memory allocated by the key generation process.

Parameters
kBGV key

◆ bgv_key_serialize()

void bgv_key_serialize ( unsigned char *  buf,
const bgv_key_t *const  k 
)

Serialize a BGV key pair.

Parameters
[out]bufSerialized key pair byte stream
kKey pair to be serialized

◆ bgv_key_zero()

void bgv_key_zero ( const ring_t *const  r,
bgv_key_t k 
)

Initialize an empty key pair.

Parameters
rPolynomial ring
[out]kEmpty key pair

◆ bgv_keygen()

void bgv_keygen ( const bgv_t *const  b,
bgv_key_t k 
)

Generate a BGV key pair.

  1. Sample random secret key $s \in R_2$ (ternary distribution)
  2. Sample random $a \in R_q$ (uniform distribution)
  3. Sample random $e \in R_q$ (error distribution)
Parameters
bBGV context
[out]kgenerated key $ = (s, (e - as, a))$