# Classical Fully Homomorphic Encryption for Quantum Circuits

The example protocol achieves the functionality of Delegated Quantum Computation by a method which involves fully classical offline and no quantum communication. It uses only classical Homomorphic Encryption (HE) scheme to evaluate quantum circuits for classical input/output. It allows a fully classical Client to hide her data such that Server can carry out any arbitrary quantum computation on the encrypted data without having any knowledge about Client’s inputs. It hides the output and input of the computation while Server is allowed to choose the unitary operation (any quantum gate) for required computation. Quantum offline communication would be required if Client’s input and output is quantum.

Tags: Two Party, Quantum Functionality, Universal Task, Secure Client- Server Delegated Quantum Computation, Prepare and Send Quantum FHE, Classical Offline Communication, Superposition, Trapdoor Claw-Free Functions, Learning With Errors, Encrypted CNOT Operation.

## Assumptions

• This protocol is secure against honest but curious adversary setting.
• HE is a classical leveled fully homomorphic encryption scheme which is quantum capable for given depth of one layer of circuit, ${\displaystyle L_{c}}$ (See Notations below).
• A BQP Server (a quantum computer) can generate a superposition of inputs for the encryption function over some distribution given the public key used for encryption. The protocol takes learning with errors assumption.

## Outline

FHE presents a classical protocol with the help of which a completely classical Client could assign Server a quantum computation for her encrypted (hidden) input/output. Similar to any classical HE this scheme is divided into four steps: Key Generation generates keys for encryption, decryption and evaluation of the circuit; Encryption encodes the input into a secret text using the encryption key generated during Key Generation; Evaluation performs operations (implements the circuit) on the encrypted input using evaluation key generated and Decryption transforms result of the evaluation step hidden in the secret text, to outcome of the circuit for Client's input using decryption key. Following the stages of Secure Delegated Quantum Computation, in preparation stage, Client encrypts her input by performing one time pad to hide it from the Server, who, in the computation stage, performs quantum computation by a completely classical evaluation step. There are two kinds of gates in Quantum Computation (See Glossary) Clifford Gates, which consists of Hadamard gate, CNOT and Pauli gates (X, Y, Z) and Toffoli gates (any single qubit phase/rotation gate). A universal scheme can perform both these types of gates implying that it can perform any quantum operation. Now, applying Clifford gates remains a simple step as it leaves the state with only Pauli corrections (X, Z) which are easy to handle as these gates commute with every quantum gate and hence can be shifted and cancelled out by applying corresponding inverse gate later by the Client, but when applying Toffoli Gates, it leaves the state with some Pauli corrections and Clifford gate corrections depending on the one pad key used for encryption key used by Client. Decryption key cannot deal with Clifford gate errors as they do not commute with all quantum operations and hence it needs to be corrected by applying corresponding inverse gate before the operation of next gate for computation by the Server. These Clifford gate corrections are a combination of CNOT corrections dependent on encryption key and a Hadamard correction independent of encryption key. Thus, applying Hadamard requires no extra information but CNOT gate errors require revelation of the encryption key. FHE deals with this problem via Encrypted CNOT operation using Trapdoor Claw-Free Function (TCF) without revelation of encryption key to the Server. Finally, in the Output Correction stage, Client gets her inputs and updated encryption keys to get the correct final outcome from the secret text using her decryption key. Following is an outline of the steps to illustrate the above mentioned scheme, assuming depth of circuit (see notations used) equal to L.
The preparation stage incorporates,

• Key Generation: Client generates ${\displaystyle L+1}$ classical homomorphic key sets consisting of public key, evaluation key, secret key, trapdoor information (a piece of information required to invert the function used for encrypted CNOT operation, as explained in Circuit Evaluation) using HE.KeyGen() (classical HE step). Evaluation key consists of first L pairs of secret key-trapdoor information encrypted with last L public keys such that secret key-trapdoor key pair and public key do not belong to the same key set. Evaluation key also contains this public key used to encrypt the pair.
• Encryption: Client uses classical one time pad to hide her input and encrypts the pad key with the first public key (not used to encrypt any trapdoor-secret key pair) using HE.Enc() (classical HE step). She then sends the hidden classical input with encrypted pad key and classical evaluation key to the Server over classical channel. This step marks the end of preparation stage.

Further, the computation stage incorporates,

• Circuit Evaluation: Server starts with the classical one time padded states from the Client and generates the required quantum states. For each gate of the circuit that Server applies, he updates the encrypted Pauli encryption according to rules given in Pseudo code below. In case of Toffoli gate operation, an additional step is incorporated where he corrects the extra Clifford gate error performing encrypted CNOT operation and then Hadamard operation on the target qubit. This step uses evaluation key and can be explained as follows.

Encrypted CNOT operation All errors imposed by Toffoli gates can be represented using encrypted CNOT operation, a Hadamard operation and a set of Pauli gates (X, Z). All errors imposed by Clifford gates can be represented by a combination of Pauli gates. A mathematical representation of this step can be found in the Pseudo Code below.

1. TCF: This operation uses Trapdoor Claw Free function pairs which have the same image (output) for different pre-images(inputs) called 'random claw pair'. Given the image, it is rendered a hard problem to find this corresponding random claw without its trapdoor information (example, a piece of information required to invert the function). For this protocol, the HE Encryption function (HE.Enc()) is taken as one of the functions. A second function whose distribution is shifted from the previous function by a natural (homomorphic) XOR operation (a requirement for the classical HE scheme used) of encrypted key bit used for that encryption function. This means, the functions have a common range such that for every image (output), the pre-images (input) for each of the functions stated above would also differ by a XOR operation of actual (not encrypted) key bit. Thus, any element in the said range set would have one pre-image in the domain set of each function, together called random claw pair. If one performs a XOR operation on the pair, the result is pad key bit. This is implied from the properties of homomorphic XOR. In simple words, the above paragraph implies that if two functions are separated by encrypted pad key via a homomorphic XOR operation, their inputs for a common output (random claw pair) would be separated by the (not encrypted) pad key bit. Thus, any pre-image pair (random claw) thus, obtained, hides the pad key (to be used later for Encrypted CNOT operation).
2. Server's preparation Thus, Server creates a superposition of inputs for the functions over some distribution. Next, he creates a superposition of quantum states generated from Client's input. After applying the gates on qubits, for correction of CNOT errors, Server creates three registers. First has the superposition of quantum states generated from Client's input, second has the superposition on a distribution chosen for inputs of the function while third register has the output of one of the two functions illustrated above, where the function (one of the two) is chosen according to the first qubit of the first register and its quantum input is taken from the second register. Hence, these registers are entangled. Server, now measures the third register which reduces second register to a random claw pair as discussed before, hiding the pad key. It is still hidden from the Server as he does not know trapdoor information to be able to know the random claw pair and he cannot compute it from the measured output as it is a hard problem.
3. Server's Toffoli gate operation After some calculations it can be shown that if Server performs Hadamard operation on the second register and then measures it, the first register is reduced to corrected quantum state with some extra Pauli corrections. These final Pauli corrections require trapdoor information and measurement outcome of the second register. To perform the above operation one needs the secret text to be same throughtout the protocol and existence of a natural XOR operation. This is not known to have been achieved by a single HE together. Hence, this protocol uses AltHE (an alternate HE) which can operate XOR for encrypted CNOT operation while he uses HE for updation of Pauli keys. In order to do this, HE provides a conversion of secret text under HE to secret text under AltHE and vice versa. Thus, after encrypted CNOT operation, encrypted pad key bit and other measurement outcomes are recrypted using public key provided in the evaluation key for that step, under HE. Thus, the trapdoor information and pad key bit are encrypted under same public key. Now, using the measurement outcome and the encrypted trapdoor information with recrypted pad key, Server obtains Pauli corrections. The Server encrypts Pauli corrections under public key for corresponding layer and hence updates the recrypted pad key
4. Server's Clifford gate operation Server obtains with Pauli corrections according to rules described in the Pseudo code and updates the recrypted pad key as before.
• Decryption Server repeats the same procedure for each layer and at the end of last layer, sends the updated recryption of pad key and classical measurement output of the first register (containing the corrected quantum state encrypted by pad key) to Client. Client converts the pad key to another secret text using AltHE. The sent pad key is recrypted with public key of the last (${\displaystyle L_{th}}$) evaluation key used. This is the ${\displaystyle (L+1)_{th}}$ public key. Hence, Client uses ${\displaystyle (L+1)_{th}}$ secret key (which was not included in the evaluation keys) to decrypt the updated encryption of pad key sent by the Server. She (Client) uses the resulting pad key to undo the one time pad on the sent output.

## Properties

• Quantum Capable A classical HE is quantum capable i.e. can perform quantum computation efficiently if there exists AltHE which can execute natural XOR operations.
• Indistinguishability under Chosen Plaintext Attacks by adversary(IND-CPA) The presented classical FHE scheme is CPA secure i.e. it is not possible for any polynomial time adversary to distinguish between the encrypted classical message bits 0 and 1, by learning with errors.
• Compactness This protocol is compact i.e. decryption does not depend on the complexity of the quantum circuit.
• Correctness Correctness is implied from the correctness of encrypted CNOT operation.
• Circuit Privacy This protocol is not circuit private as both Client and Server know the quantum circuit used for performing the computation.
• Full Homomorphism This protocol is fully homomorphic i.e. Server can operate any quantum circuit using this protocol.
• Circular Security This protocol has a stronger notion of circular security where not only the secret key but also the trapdoor functions are encrypted when provided to the Server.

## Notation

• ${\displaystyle m}$: classical data of client's required quantum input states
• ${\displaystyle \lambda }$: security parameter
• ${\displaystyle k}$: security parameter
• ${\displaystyle {\tilde {x}}}$: encrypted pad key
• ${\displaystyle s}$: concatenated pad key elements
• ${\displaystyle c=HE.Enc_{pk}(s)}$ Encryption of s using public key ${\displaystyle pk}$ via classical HE encryption step.
• ${\displaystyle {\hat {c}}}$: converted c using classical HE in order to use it with ${\displaystyle AltHE}$
• ${\displaystyle {\tilde {x}}^{[l]}}$: ${\displaystyle l^{th}}$ bit of encrypted pad key
• ${\displaystyle L_{c}}$: depth of a layer of circuit where each layer contains Clifford gates and Toffoli gates
• ${\displaystyle L}$: depth of the circuit (no. of layers in the circuit)
• ${\displaystyle \{pk_{i},sk_{i},evk_{i},t_{sk_{i}}\}}$: ${\displaystyle i_{th}}$ homomorphic key set generated from HE.KeyGen(). Public key for encryption, secret key for decryption, evaluation function key, trapdoor information required for randomness recovery from secret texts.
• ${\displaystyle y}$: measurement outcome of third register
• ${\displaystyle (\mu _{0},r_{0})(\mu _{1},r_{1})}$: random claw for pair, for given y
• ${\displaystyle d}$: measurement outcome of the second register

## Requirements

• Network Stage: Quantum Memory
• Required Network Parameters:
• ${\displaystyle \epsilon _{j}}$, which measures the error due to noisy operations.
• Number of communication rounds
• Circuit depth
• Number of physical qubits used
• The concerned protocol requires classical HE scheme.
• Communication can be performed over a classical network with only one quantum node (in case of classical input and output).
• The functions ${\displaystyle f_{0},f_{1}}$ used must be trapdoor claw-free(TCF) such that one it is not possible to find a triple ${\displaystyle (\mu _{0},\mu _{1},y)}$ such that ${\displaystyle f_{0}(\mu _{0})=f_{1}(\mu _{1})=y}$

## Protocol Description

• Boxed texts are not part of the code but contain proofs used in various steps, illustrated for a better understanding of the protocol.

### Stage 1 Client’s Preparation

• Input: ${\displaystyle k,L,L_{c}}$, classical message ${\displaystyle m}$
• Output: Homomorphic key sets ${\displaystyle (pk_{i},evk_{i},sk_{i},t_{sk_{i}})}$, encrypted pad key ${\displaystyle {\tilde {z}},{\tilde {x}}}$, One time Padded message (${\displaystyle l}$)
• Key Generation (FHE.KeyGen(${\displaystyle 1^{\lambda },1^{L}}$))
1. For ${\displaystyle 1\leq i\leq L+1}$,
2. Client generates homomorphic key set, ${\displaystyle (pk_{i},evk_{i},sk_{i},t_{sk_{i}})=}$HE.Keygen(${\displaystyle 1^{\lambda },1^{L_{c}}}$).
The public key ${\displaystyle pk}$ is ${\displaystyle pk_{1}}$ and the secret key ${\displaystyle sk}$ is ${\displaystyle sk_{L+1}}$.
The evaluation key ${\displaystyle evk_{i}}$ consists of ${\displaystyle (pk_{i+1},}$HE.Enc${\displaystyle _{pk_{i+1}}(sk_{i})}$, HE.Enc${\displaystyle _{pk_{i+1}}(t_{sk_{i}})}$) for ${\displaystyle 1\leq i\leq L}$.
• Encryption (FHE.Enc${\displaystyle _{pk}(m)}$))
1. Client chooses pad key for each message bit ${\displaystyle z,x\in \{0,1\}^{\lambda }}$.
2. She one time pads the message m, ${\displaystyle l=x\oplus m}$
//z is used for quantum input ${\displaystyle Z^{z}X^{x}|\psi \rangle }$ where ${\displaystyle |\psi \rangle }$ is quantum input.
3. She then encrypts the pad key. HE.Enc${\displaystyle _{pk_{1}}(z,x)}$
4. She sends the encrypted message and pad key to the Server with the evaluation keys.

### Stage 2 Server’s Computation

• Input: ${\displaystyle \mathrm {evk} _{i}}$, pad key elements concatenation (${\displaystyle s}$), encryption of s under HE (${\displaystyle c=\mathrm {HE.Enc} _{pk}(s)}$), one time padded message (${\displaystyle l}$)
• Output: Updated encryption of pad key ${\displaystyle {\tilde {z}},{\tilde {x}}}$ and final classical outcome after performing the circuit.
• Circuit Evaluation (FHE.Eval())
1. Server creates a quantum superposition state for encrypted input ${\displaystyle l}$: ${\displaystyle Z^{z}X^{x}|\psi \rangle }$, where
${\displaystyle |\psi \rangle =\sum _{a,b\epsilon \{0,1\}}\alpha _{ab}|a,b\rangle }$ represents the two qubits superposition state for classical message m,
${\displaystyle Z^{z}X^{x}}$ represents quantum one time pad.
2. For all i, Server applies gate ${\displaystyle c_{i}}$ on qubit l and the ${\displaystyle l_{th}}$ bits of pad key ${\displaystyle ({\tilde {x}}^{[l]},{\tilde {z}}^{[l]})}$ are updated to ${\displaystyle ({\tilde {x}}'^{[l]},{\tilde {z}}'^{[l]})}$ as follows.
1. If ${\displaystyle c_{i}=\{P,H,CNOT\}}$, a Clifford gate then
//(${\displaystyle c_{i}Z^{z^{[l]}}X^{x^{[l]}}|\psi \rangle =Z^{z'^{[l]}}X^{x'^{[l]}}c_{i}|\psi \rangle }$)
1. if ${\displaystyle c_{i}=}$H then

${\displaystyle ({\tilde {x}}^{[l]},{\tilde {z}}^{[l]})\rightarrow ({\tilde {z}}^{[l]},{\tilde {x}}^{[l]})}$
//Hadamard tranforms X gate into Z and Z into X
2. if ${\displaystyle c_{i}=}$P then
//Pauli Gate

${\displaystyle ({\tilde {x}}^{[l]},{\tilde {z}}^{[l]})\rightarrow ({\tilde {x}}^{[l]},{\tilde {x}}^{[l]}\oplus {\tilde {z}}^{[l]})}$
3. if ${\displaystyle c_{i}=CNOT_{l,n}}$ with m as target bit and n as control bit then
//CNOT

(${\displaystyle {\tilde {x}}^{[l]},{\tilde {z}}^{[l]};{\tilde {x}}^{[n]},{\tilde {z}}^{[n]})\rightarrow ({\tilde {x}}^{[l]},{\tilde {z}}^{[l]}\oplus {\tilde {z}}^{[n]};{\tilde {x}}^{[l]}\oplus {\tilde {x}}^{[n]},{\tilde {z}}^{[n]})}$
2. If ${\displaystyle c_{i}=T}$ gate then
//Toffoli Gate on ${\displaystyle l_{th},n_{th},o_{th}}$ key bits
The Toffoli gate application can be deduced as follows:
${\displaystyle TZ^{z^{[l]}}X^{x^{[l]}}Z^{z^{[n]}}X^{x^{[n]}}Z^{z^{[o]}}X^{x^{[o]}}|\psi \rangle }$
${\displaystyle =TZ^{z^{[l]}}X^{x^{[l]}}Z^{z^{[n]}}X^{x^{[n]}}Z^{z^{[o]}}X^{x^{[o]}}T\dagger T|\psi \rangle }$
${\displaystyle =CNOT_{l,o}^{x^{[n]}}CNOT_{n,o}^{x^{[l]}}CZ_{l,n}^{z^{[o]}}Z^{z^{[l]}}X^{x^{[l]}}T|\psi \rangle }$
${\displaystyle =CNOT_{l,o}^{x^{[n]}}CNOT_{n,o}^{x^{[l]}}H_{n}CNOT_{l,n}^{z^{[o]}}H_{n}Z^{z^{[l]}}X^{x^{[l]}}T|\psi \rangle }$
${\displaystyle =C_{zx}P_{zx}T|\psi \rangle }$, where ${\displaystyle C\epsilon \{{\text{CNOT,H}}\}}$ and ${\displaystyle P\epsilon \{X,Z\}}$
1. The Pauli key encryptions are homomorphically updated according to ${\displaystyle P_{zx}}$.
(${\displaystyle {\tilde {x}}^{[l]},{\tilde {z}}^{[l]};{\tilde {x}}^{[n]},{\tilde {z}}^{[n]};{\tilde {x}}^{[o]},{\tilde {z}}^{[o]})\rightarrow ({\tilde {x}}^{[l]},{\tilde {z}}^{[l]};0,0;0,0)}$
2. Three encrypted CNOTs are used to correct ${\displaystyle C^{zx}}$ as follows under ${\displaystyle \mathrm {AltHE} }$.

• Server's Preparation:
1. Server converts ${\displaystyle {\hat {c}}=\mathrm {HE.Convert(c)} }$.
2. Server generates superposition on distribution D: ${\displaystyle \sum _{\mu \in \{0,1\},r}{\sqrt {D(\mu ,r)}}|\mu ,r\rangle }$
3. Server entangles above superposition and ${\displaystyle |\psi \rangle }$ with a third register:${\displaystyle \sum _{a,b,\mu \in \{0,1\},r}\alpha _{ab}{\sqrt {D(\mu ,r)}}|a,b\rangle |\mu ,r\rangle |f_{a}(r)\rangle }$, such that
${\displaystyle f_{0}=\mathrm {AltHE.Enc} _{pk}()}$;
${\displaystyle f_{1}(\mu _{1},r_{1})=f_{0}(\mu _{0},r_{0})\oplus _{H}{\hat {c}}=\mathrm {AltHE.Enc} _{pk}(\mu _{0},r_{0})\oplus _{H}\mathrm {AltHE.Enc} _{pk}(s)}$
${\displaystyle \therefore \mu _{0}\oplus \mu _{1}=s}$
4. Server measures the last register to get ${\displaystyle y=\mathrm {AltHE.Enc} (\mu _{0},r_{0})=\mathrm {AltHE.Enc} _{pk}(\mu _{1},r_{1})\oplus _{H}AltHE.Enc_{pk}(s)}$.
The resulting superposition state is:${\displaystyle \sum _{a,b\in \{0,1\}}\alpha _{ab}{\sqrt {D(\mu _{0},r_{0})}}|a,b\rangle |\mu _{a},r_{a}\rangle |\mathrm {AltHE.Enc} (\mu _{0},r_{0})\rangle =\sum _{a,b\in \{0,1\}}\alpha _{ab}{\sqrt {D(\mu _{0},r_{0})}}|a,b\rangle |\mu _{a},r_{a}\rangle |y\rangle }$
• Encrypted CNOT operation:
${\displaystyle \sum _{a,b\in \{0,1\}}\alpha _{ab}CNOT_{a,b}^{s}|a,b\rangle }$
${\displaystyle =\sum _{a,b\in \{0,1\}}\alpha _{ab}|a,b\oplus a\cdot s\rangle }$
${\displaystyle =\sum _{a,b\in \{0,1\}}\alpha _{ab}|a,b\oplus a\cdot (\mu _{0}\oplus \mu _{1})\rangle }$
${\displaystyle =\sum _{b\in \{0,1\}}\alpha _{0b}|0,b\oplus \mu _{0}\oplus \mu _{0}\rangle +\alpha _{1b}|1,b\oplus \mu _{0}\oplus \mu _{1}\rangle }$, ${\displaystyle \because q\oplus q=0}$
${\displaystyle =\sum _{b\in \{0,1\}}\alpha _{0b}|0\rangle \otimes X^{\mu _{0}}|b\oplus \mu _{0}\rangle +\alpha _{1b}|1\rangle \otimes X^{\mu _{0}}|b\oplus \mu _{1}\rangle }$, ${\displaystyle \because |q\oplus y\rangle =X^{y}|q\rangle }$
${\displaystyle =\sum _{a,b\in \{0,1\}}\alpha _{ab}|a\rangle \otimes X^{\mu _{0}}|b\oplus \mu _{a}\rangle }$
${\displaystyle =\sum _{a,b\in \{0,1\}}\alpha _{ab}(I\otimes X^{\mu _{0}})|a,b\oplus \mu _{a}\rangle }$
1. Server XORs the second qubit of first register with ${\displaystyle \mu _{a}}$ to get:
${\displaystyle \sum _{a,b\in \{0,1\}}\alpha _{ab}{\sqrt {D(\mu _{0},r_{0})}}(I\otimes X^{\mu _{0}})CNOT_{a,b}^{s}|a,b\rangle \otimes |\mu _{a},r_{a}\rangle |y\rangle }$
2. Server performs Hadamard on second register. The resulting superposition state is:
${\displaystyle \sum _{a,b\in \{0,1\}}\alpha _{ab}{\sqrt {D(\mu _{0},r_{0})}}(I\otimes X^{\mu _{0}})CNOT_{ab}^{s}|a,b\rangle \otimes H^{k}|\mu _{a},r_{a}\rangle |y\rangle }$
${\displaystyle =\sum _{a,b\in \{0,1\}}\alpha _{ab}{\sqrt {D(\mu _{0},r_{0})}}(I\otimes X^{\mu _{0}})CNOT_{ab}^{s}|a,b\rangle \otimes {\bigg (}\sum _{e\in \{0,1\}^{k}}(-1)^{e\cdot (\mu _{a},r_{a})}|e\rangle {\bigg )}|y\rangle }$, ${\displaystyle \because H^{k}|q\rangle =\sum _{e\in \{0,1\}^{k}}(-1)^{e\cdot q}|e\rangle }$, where q has k qubits
3. Server measures the second register to get d. The resulting superposition is:
${\displaystyle =\sum _{a,b\in \{0,1\}}\alpha _{ab}{\sqrt {D(\mu _{0},r_{0})}}(I\otimes X^{\mu _{0}})CNOT_{ab}^{s}|a,b\rangle \otimes (-1)^{d\cdot (\mu _{a},r_{a})}|d\rangle |y\rangle }$

The first register could be equivalently written as:
${\displaystyle (-1)^{d\cdot (\mu _{0},r_{0})}|0,b\rangle +(-1)^{d\cdot (\mu _{1},r_{1})}|1,b\rangle }$
${\displaystyle =(-1)^{d\cdot (\mu _{0},r_{0})}((-1)^{d\cdot ((\mu _{0},r_{0})\oplus (\mu _{0},r_{0}))}|0,b\rangle +(-1)^{d\cdot ((\mu _{0},r_{0})\oplus (\mu _{1},r_{1}))}|1,b\rangle )}$
${\displaystyle =(-1)^{d\cdot (\mu _{0},r_{0})}((-1)^{0\cdot (d\cdot ((\mu _{0},r_{0})\oplus (\mu _{1},r_{1}))})|0,b\rangle +(-1)^{1\cdot (d\cdot ((\mu _{0},r_{0})\oplus (\mu _{1},r_{1})))}|1,b\rangle )}$
${\displaystyle =(-1)^{d\cdot (\mu _{0},r_{0})}((-1)^{a\cdot (d\cdot ((\mu _{0},r_{0})\oplus (\mu _{1},r_{1}))})|a,b\rangle }$
${\displaystyle =(-1)^{d\cdot (\mu _{0},r_{0})}(Z^{d\cdot ((\mu _{0},r_{0})\oplus (\mu _{1},r_{1}))}|a,b\rangle )}$, ${\displaystyle \because Z|q\rangle =(-1)^{q}|q\rangle }$
Thus, the resulting state (upto a global phase) is:
${\displaystyle \approx (Z^{d\cdot ((\mu _{0},r_{0})\oplus (\mu _{1},r_{1}))}\otimes X^{\mu _{0}})CNOT_{12}^{s}\sum _{a,b\in \{0,1\}}\alpha _{ab}|a,b\rangle }$
Final superposition at the end of encrypted CNOT operation is:
${\displaystyle (Z^{d\cdot ((\mu _{0},r_{0})\oplus (\mu _{1},r_{1}))}\otimes X^{\mu _{0}})\mathrm {CNOT} _{1,2}^{s}|\psi _{12}\rangle }$
where ${\displaystyle (\mu _{0},r_{0})=(\mu _{1},r_{1})\oplus _{H}s}$, as ${\displaystyle \oplus _{H}}$ is the homomorphic XOR operation.

1. The server uses ${\displaystyle pk_{i+1}}$ to recrypt 'c' (previously encrypted using ${\displaystyle pk_{i}}$) and encrypt other variables under HE: ${\displaystyle \mathrm {HE.Enc} _{pk_{i+1}}(c)}$, ${\displaystyle \mathrm {HE.Enc} _{pk_{i+1}}({\hat {c}},y,d)}$.
2. The server computes the encryption of ${\displaystyle z,x}$ (stored in ${\displaystyle {\tilde {z}},{\tilde {x}}}$) under ${\displaystyle pk_{i+1}}$ by performing decryption circuit on ${\displaystyle \mathrm {HE.Enc} _{pk_{i+1}}(c)}$ using ${\displaystyle \mathrm {HE.Enc} _{pk_{i+1}}(sk_{i})}$ (provided by the evaluation key). Here, c, as stated before is the concatenation of encryption of x, z under ${\displaystyle pk_{i}}$, provided by the Client.
3. The server (homomorphically) computes ${\displaystyle (\mu _{0},r_{0})}$ and ${\displaystyle (\mu _{1},r_{1})}$, using ${\displaystyle \mathrm {HE.Enc} _{pk_{i+1}}(t_{sk_{i}},sk_{i})}$, provided by the evaluation key ${\displaystyle \mathrm {evk} _{i}}$ encrypted under ${\displaystyle pk_{i+1}}$, and ${\displaystyle \mathrm {HE.Enc} _{pk_{i+1}}({\hat {c}},y,d)}$, from the previous step.
4. The server then uses this results of the last three steps, to (homomorphically) update Pauli encryptions for encrypted ${\displaystyle CNOT_{l,n}^{s}}$:
(${\displaystyle {\tilde {x}}^{[l]},{\tilde {z}}^{[l]};{\tilde {x}}^{[n]},{\tilde {z}}^{[n]})\rightarrow ({\tilde {x}}^{[l]},{\tilde {z}}^{[l]}+d\cdot ((\mu _{0},r_{0})\oplus (\mu _{1},r_{1});{\tilde {x}}^{[n]}+\mu _{0},{\tilde {z}}^{[n]})}$

3. Server sends updated encryptions of Pauli corrections ${\displaystyle {\tilde {x}},{\tilde {z}}}$ and the classical outcome after measurement of the output state to Client.

### Stage 3 Client’s Output Correction

• Input: Classical output state (${\displaystyle l\in \{0,1\}^{\lambda }}$), encrypted Pauli corrections (${\displaystyle {\tilde {z}},{\tilde {x}}}$)
• Output: Decrypted classical message (${\displaystyle l\oplus x}$)
• Decryption (FHE.Dec${\displaystyle _{sk}}$)
1. Client decrypts ${\displaystyle {\tilde {z}},{\tilde {x}}}$ using ${\displaystyle sk_{L+1}}$ to obtain ${\displaystyle z,x}$.
2. She then uses the decrypted Pauli corrections to get the correct output ${\displaystyle l\oplus x}$.

## Further Information

In case of Quantum Input, the client additionally sends quantum one tie padded input state. In case of quantum output the Server instead of classical outcome sends the final quantum one time padded output state (operated by the required circuit). Client gets the output by using the updated encryption sent by the server to perform Pauli corrections on the output state. This protocol is first and only protocol currently, to use a classical functionality to solve a quantum task. It provides computationally security. Verification of this protocol is still an open question.