# BFV

Around 2012 Brakerski [1] proposed a new efficient FHE scheme whose security is based on the LWE problem. Later on, this scheme was ported to the ring-LWE setting by Fan and Vercauteren. [2] The various optimisations achieved by the last two authors made the scheme suitable for implementation. One such implementation is available in Microsoft SEAL [3] is an actively maintained library which makes homomorphic encryption available in an easy-to-use form both to experts and to non-experts.

## Overview of the BFV scheme

In BFV the plaintext space consists of polynomials of degree less than ${\displaystyle n}$ with coefficients modulo ${\displaystyle t}$, more precisely ${\displaystyle {\mathcal {R}}_{t}=\mathbb {Z} _{t}[x]/(x^{n}+1)}$. This is a ring, where addition is just the usual addition of polynomials. Multiplication is also quite intuitive, in the sense that multiplication of two elements is just multiplication of the underlying polynomials with ${\displaystyle x^{n}}$ being converted to ${\displaystyle -1}$. In this way, the result of ring operations on ${\displaystyle {\mathcal {R}}_{t}}$ is always a polynomial of degree strictly less than ${\displaystyle n}$.

The homomorphic operations on ciphertext, that will be described later, will carry through encryption to addition and multiplication operations in the plaintext ${\displaystyle {\mathcal {R}}_{t}}$.

If we wish to encrypt an integer or a rational number, then we need to encode it first into a plaintext polynomial in ${\displaystyle {\mathcal {R}}_{t}}$ and the result can be encrypted only after that. We mention that distinction should be made between encoding and encrypting data. The first one is a public operation, i.e. anybody can reverse it by decoding , whereas the latter can be reverse just by someone who knows the (secret) encryption key. In order to be able to compute additions and multiplications on, for example, integers in encrypted form, the encoding must be such that addition and multiplication of encoded polynomials in ${\displaystyle {\mathcal {R}}_{t}}$ carry over correctly to the integers when the result is decoded. The aforementioned library Microsoft SEAL provides a few different standard encoders that users can use at their convenience.

The ciphertext space in this scheme consists of arrays of polynomials in ${\displaystyle {\mathcal {R}}_{q}}$, for some different (much larger than ${\displaystyle t}$) integer ${\displaystyle q}$. These arrays contain at least two polynomials. Their length grows with each homomorphic multiplication, unless an operation called reliniarization is performed. The latter is a procedure which takes a ciphertext consisting of more than ${\displaystyle 2}$ polynomials in ${\displaystyle {\mathcal {R}}_{q}}$ back to a ciphertext with ${\displaystyle 2}$ polynomials encrypting the same message ${\displaystyle m\in {\mathcal {R}}_{t}}$.

## Description of the scheme

Let ${\displaystyle \lambda }$ be the security parameter. Let ${\displaystyle w}$ be a base (one can think of ${\displaystyle w=2}$ for the sake of presentation) and let ${\displaystyle l+1=\lfloor \log _{w}q\rfloor +1}$ denote the number of terms in the decomposition into base ${\displaystyle q}$. Polynomials in ${\displaystyle {\mathcal {R}}_{q}}$ will also be decomposed into base ${\displaystyle w}$ components coefficient-wise, resulting in ${\displaystyle l+1}$ polynomials. When ${\displaystyle S}$ is a set, we denote ${\displaystyle a\leftarrow S}$ we denote the fact that ${\displaystyle a}$ is sampled uniformly from the set ${\displaystyle S}$.

The BFV scheme has the algorithms ${\displaystyle SecretKeyGen,PublicKeyGen,EvaluationKeyGen,Encrypt,Decrypt,Add}$ and ${\displaystyle Multiply}$. We describe these below.

• ${\displaystyle SecretKeyGen(\lambda )}$: This just samples ${\displaystyle s\leftarrow {\mathcal {R}}_{2}}$ and outputs the secre key ${\displaystyle sk=s}$.
• ${\displaystyle PublicKeyGen(sk)}$: Set ${\displaystyle s=sk}$, sample ${\displaystyle a\leftarrow {\mathcal {R}}_{q}}$ uniformly and ${\displaystyle e\leftarrow \chi }$ from an error distribution. Output the public key ${\displaystyle pk=([-(as+e)]_{q},a)}$.
• ${\displaystyle EvaluationKeyGen(sk,w)}$: for ${\displaystyle i\in \{0,\dots ,l\}}$, sample ${\displaystyle a_{i}\leftarrow {\mathcal {R}}_{q}}$ and ${\displaystyle e_{i}\leftarrow \chi }$. Output
${\displaystyle evk=([-(a_{i}s+e_{i})+w^{i}s^{2}]_{q},a_{i})}$.

The autors note that one can think of the evaluation key essentially as a masking of the secret key raised to the power 2 (or, more generally, to some higher power). Unfortunately, it is not possible to argue the uniformity of the evaluation key based on the decision-RLWE assumption. Instead, one can think of it as an encryption of (some power of) the secret key under the secret key itself, and to argue security one needs to make the extra assumption that the encryption scheme is secure even when the adversary has access to all of the evaluation keys which may exist. This point is also explained in the SEAL manual [4].

• ${\displaystyle Encrypt(pk,m):}$ For ${\displaystyle m\in {\mathcal {R}}_{t}}$, let ${\displaystyle p_{k}=(p_{0},p_{1})}$. Sample ${\displaystyle u\leftarrow {\mathcal {R}}_{2}}$ uniformly and ${\displaystyle e_{1},e_{2}\leftarrow \chi }$. Compute and output
${\displaystyle ct=([{\frac {q}{t}}\cdot m+p_{0}u+e_{1}]_{q},[p_{q}u+e_{2}]_{q})}$ .
• ${\displaystyle Decrypt(sk,ct)}$: Set ${\displaystyle s=sk,c_{0}=ct[0]}$ and ${\displaystyle c_{1}=ct[1]}$. Output
${\displaystyle \left[\left\lfloor {\frac {t}{q}}\cdot [c_{0}+c_{1}s]_{q}\right\rfloor \right]_{t}}$.

The homomorphic operations on ciphertext are as follows

• ${\displaystyle Add(ct_{0},ct_{1}):}$ Output ${\displaystyle (ct_{0}[0]+ct_{1}[0],ct_{0}[1]+ct_{1}[1]).}$

As one can see addition is done in the most natural way, component-wise. Multiplication is a little bit more tricky.

• ${\displaystyle Multiply(ct_{0},ct_{1}):}$ Compute
${\displaystyle c_{0}=\left[\left\lfloor {\frac {t}{q}}ct_{0}[0]ct_{1}[0]\right\rceil \right]_{q}}$,
${\displaystyle c_{1}=\left[\left\lfloor {\frac {t}{q}}(ct_{0}[0]ct_{1}[1]+ct_{0}[1]ct_{1}[0])\right\rceil \right]_{q}}$ ,

and ${\displaystyle c_{2}=\left[\left\lfloor {\frac {t}{q}}(ct_{0}[1]ct_{1}[1])\right\rceil \right]_{q}}$.

This first step is quite easy. One can think of ${\displaystyle ct_{i}}$ as a polynomial ${\displaystyle ct_{i}(x)=ct_{i}[0]+x\cdot ct_{i}[1]}$ with coefficients in ${\displaystyle {\mathcal {R}}_{q}}$. What we did so far corresponds to computing the product of the polynomials ${\displaystyle ct_{1}(x)}$ and ${\displaystyle ct_{2}(x)}$, resulting in a (quadratic in ${\displaystyle x}$) polynomial ${\displaystyle c_{0}+c_{1}x+c_{2}x^{2}}$. This corresponds to a length ${\displaystyle 3}$ array ${\displaystyle (c_{0},c_{1},c_{2})}$. To keep the size of the ciphertext small, we now apply a reliniarization step. The latter consists in computing

${\displaystyle c_{0}'=c_{0}+\sum _{i=0}^{l}evk[i][0]c_{2}^{(i)}}$,
${\displaystyle c_{1}'=c_{1}+\sum _{i=0}^{l}evk[i][1]c_{2}^{(i)}}$ ,

and return as output the ciphertext ${\displaystyle (c_{0}',c_{1}')}$.

We remark that the last step is the only place where one has to use the evaluation key, therefore having to rely on the extra circular security assumption. In practice, if one does not need to perform bootstrapping for obtaining a fully homomorphic encryption scheme, the reliniarization step can be avoided. For example, in the SEAL library, the function Evaluator::multiply(ct_0, ct_1) performs only the first step in the multiplication and outputs ${\displaystyle (c_{0},c_{1},c_{2})}$, a ciphertext of size ${\displaystyle 3}$. Homomorphic operations are defined naturally on ciphertexts of arbitrary size and the decryption algorithm works well without reliniarization. The only problem with this approach is that the ciphertexts will grow with the number of homomorphic multiplications we perform, so one has to know a priori an upper bound on this number in order to choose parameters correctly. The problem of choosing parameters is also a delicate one. Increasing ${\displaystyle q}$ while keeping ${\displaystyle n}$ constant, one obtains more room for homomorphic multiplications (good), but the security of the scheme decreases (bad). This problem can be mitigated by increasing ${\displaystyle n}$ as well.

## Making the scheme fully homomorphic

What is described above is a somewhat homomorphic encryption scheme. As all existing schemes that are based on LWE or ring-LWE, a small “noise” component is added to the message during encryption (the vectors ${\displaystyle e_{1},e_{2}}$ sampled from the distribution ${\displaystyle \chi }$ above). Computing homomorphically on ciphertexts will cause these noise to grow up to the point when it becomes so large (in practice, this happens when a certain norm of the vectors ${\displaystyle e_{1},e_{2}}$ is larger than ${\displaystyle 1/2\cdot \lfloor q/t\rceil }$ ) that decryption fails. The bootstrapping approach by Gentry can then be used to lower the noise in a ciphertext to a fixed level determined by the complexity of the decryption circuit. Gentry’s idea of bootstrapping is really simple, namely run the decryption of the somewhat homomorphic scheme above in the encrypted domain, i.e. homomorphically. The result of this operation is an encryption of the same message, but with noise of a fixed size. If the decryption circuit can be evaluated in depth D, then the noise after bootstrapping equals the noise one would obtain by evaluating a depth D circuit, which is clearly independent of the starting noise present in the ciphertext. Therefore, if the scheme can handle circuits of depth ${\displaystyle D+1}$ , we can still handle one multiplication after bootstrapping and thus obtain a fully homomorphic scheme. The BFV scheme is designed such that it handles its own decryption circuit, therefore it can be turned into a fully homomorphic scheme via bootstrapping.

Unfortunately this is slow, and requires the encryption parameters ${\displaystyle (n,q)}$ to be large enough to support bootstrapping (not currently implemented in SEAL for the BFV scheme).

## Applications

• CryptoNets: Applying Neural Networks to Encrypted Data

## References

1. Z. Brakerski. Fully Homomorphic Encryption without Modulus Switching from Classical GapSVP. CRYPTO 2012. http://eprint.iacr.org/2012/078.pdf
2. J. Fan and F. Vercauteren. Somewhat practical fully homomorphic encryption. Cryptology ePrint Archive, Report 2012/144, Mar. 2012. https://eprint.iacr.org/2012/144.pdf
3. Microsoft Research. Microsoft SEAL (release 3.5). 2020. https://github.com/Microsoft/SEAL
4. K. Lane. Simple Encrypted Arithmetic Library. Microsoft Research. https://www.microsoft.com/en-us/research/uploads/prod/2017/11/sealmanual-2-3-1.pdf