Homomorphic Encryption

MP-SPDZ uses BGV encryption for triple generation in a number of protocols. This involves zero-knowledge proofs in some protocols and considerations about function privacy in all of them. The interface described below allows directly accessing the basic cryptographic operations in contexts where these considerations are not relevant. See Utils/he-example.cpp for some example code.

Reference

class FHE_Params

Cryptosystem parameters

Public Functions

FHE_Params(int n_mults = 1, int drown_sec = DEFAULT_SECURITY)

Initialization.

Parameters
  • n_mults – number of ciphertext multiplications (0/1)

  • drown_sec – parameter for function privacy (default 40)

void pack(octetStream &o) const

Append to buffer.

void unpack(octetStream &o)

Read from buffer.

void basic_generation_mod_prime(int plaintext_length)

Generate parameter for computation modulo a prime

Parameters

plaintext_length – bit length of prime

class FHE_KeyPair

BGV key pair

Public Functions

inline FHE_KeyPair(const FHE_Params &params)

Initialization.

inline void generate()

Generate fresh keys.

Public Members

FHE_PK pk

Public key.

FHE_SK sk

Secret key.

class FHE_SK

BGV secret key. The class allows addition.

Public Functions

inline void pack(octetStream &os, int = -1) const

Append to buffer.

inline void unpack(octetStream &os, int = -1)

Read from buffer. Assumes parameters are set correctly.

Plaintext_<FFT_Data> decrypt(const Ciphertext &c)

Decryption for cleartexts modulo prime.

class FHE_PK

BGV public key.

Public Functions

template<class FD>
Ciphertext encrypt(const Plaintext<typename FD::T, FD, typename FD::S> &mess) const

Encryption.

void pack(octetStream &o) const

Append to buffer.

void unpack(octetStream &o)

Read from buffer. Assumes parameters are set correctly.

template<class T, class FD, class _>
class Plaintext

BGV plaintext. Use Plaintext_mod_prime instead of filling in the templates. The plaintext is held in one of the two representations or both, polynomial and evaluation. The latter is the one allowing element-wise multiplication over a vector. Plaintexts can be added, subtracted, and multiplied via operator overloading.

Public Functions

unsigned int num_slots() const

Number of slots.

Plaintext(const FHE_Params &params)

Initialization.

inline T element(int i) const

Read slot.

Parameters

i – slot number

Returns

slot content

inline void set_element(int i, const T &e)

Write to slot

Parameters
  • i – slot number

  • e – new slot content

void pack(octetStream &o) const

Append to buffer.

void unpack(octetStream &o)

Read from buffer. Assumes parameters are set correctly.

class Ciphertext

BGV ciphertext. The class allows adding two ciphertexts as well as adding a plaintext and a ciphertext via operator overloading. The multiplication of two ciphertexts requires the public key and thus needs a separate function.

Public Functions

inline Ciphertext mul(const FHE_PK &pk, const Ciphertext &x) const

Ciphertext multiplication.

Parameters
  • pk – public key

  • x – second ciphertext

Returns

product ciphertext

void rerandomize(const FHE_PK &pk)

Re-randomize for circuit privacy.

inline void pack(octetStream &o, int = -1) const

Append to buffer.

inline void unpack(octetStream &o, int = -1)

Read from buffer. Assumes parameters are set correctly.