Research Article: An Efficient Encrypted Floating-Point Representation Using Heaan and Tfhe
Research Article: An Efficient Encrypted Floating-Point Representation Using Heaan and Tfhe
Research Article
An Efficient Encrypted Floating-Point Representation Using
HEAAN and TFHE
1
Department of Software Analysis and Design, SeoulTech, Seoul 18011, Republic of Korea
2
ITM Division, Department of Industrial Engineering, SeoulTech, Seoul 18011, Republic of Korea
Received 30 October 2019; Revised 17 January 2020; Accepted 3 February 2020; Published 2 March 2020
Copyright © 2020 Subin Moon and Younho Lee. This is an open access article distributed under the Creative Commons
Attribution License, which permits unrestricted use, distribution, and reproduction in any medium, provided the original work is
properly cited.
As a method of privacy-preserving data analysis (PPDA), a fully homomorphic encryption (FHE) has been in the spotlight
recently. Unfortunately, because many data analysis methods assume that the type of data is of real type, the FHE-based PPDA
methods could not support the enough level of accuracy due to the nature of FHE that fixed-point real-number representation is
supported easily. In this paper, we propose a new method to represent encrypted floating-point real numbers on top of FHE. The
proposed method is designed to have analogous range and accuracy to 32-bit floating-point number in IEEE 754 representation.
We propose a method to perform arithmetic operations and size comparison operations. The proposed method is designed using
two different FHEs, HEAAN and TFHE. As a result, HEAAN is proven to be very efficient for arithmetic operations and TFHE is
efficient in size comparison. This study is expected to contribute to practical use of FHE-based PPDA.
Unfortunately, there have been only few attempts to point representation to support the arithmetic and relational
represent floating-point numbers with FHE. A representa- operations efficiently with the underlying FHE schemes.
tive study is the HEAAN method [14]. In HEAAN, floating Therefore, to understand the proposed representation easily,
point numbers can be thought of because they have the we first briefly overview it. In IEEE 754, two types of floating-
advantage of keeping the same significant digits regardless of point representation are defined, single-precision and
the size of the computed result. However, HEAAN has a few double-precision, depending on the number of bits assigned
drawbacks. First, it does not provide comparison operations for a representation. In this work, we only focus on the
on given numbers. This is a big problem when implementing single-precision representation as this is only applied for the
various applications using HEAAN. Second, HEAAN pro- proposed one.
vides the division operation only within a limited range of Figure 1 shows the IEEE 754 single-precision repre-
realizations. That is, if “a” is the real number contained in a sentation. It is composed of three parts: 1-bit sign, 8-bit
cipher text, then |1− a| ≤ 1/2 should be held. Therefore, in exponent, and 23-bit mantissa. The sign bits represent if the
order to use HEAAN for applications, it is necessary to value is positive (0) or negative (1). The exponent bits
scaling the values. represent the exponent which is in the range between − 127
Apart from HEAAN, TFHE was proposed in 2017, which and 127. The “fraction” bits contain the significant bits of the
supports very fast bootstrapping [7]. Sadly, because it does value. In normal mode, Figure 1 represents a real number
not provide floating-point operations, a new method is (− 1) (sign) ∗ 1. (FRACTION) (2) ∗ 2(EXPONENT(2)− 127), where
needed to support the encrypted floating-point represen- binary values represent unsigned positive integers.
tation over TFHE and the operations that can work on top of The arithmetic and relational operations between the
the representation. numbers expressed in this way can be carried out as follows.
Therefore, we propose an encrypted floating-point In the case of addition and subtraction, the exponents of two
representation on which it is provided efficient floating- operands are made equal. The mantissas of them are ad-
point operations over the encrypted values by the above FHE justed following the changed exponents, respectively. After
schemes. In the proposed method, real numbers are that, the operation is performed with the adjusted mantissas.
expressed with sign, exponent, and mantissa similarly to the In the case of multiplication and division, operations are
conventional IEEE 754 expression. However, it is designed performed on exponents and mantissas of two operands,
to achieve the efficiency of the entire operations by utilizing respectively. After processing, adjustment is performed on
the characteristics of each FHE method. Supporting the the resultant exponent and mantissa in order to match the
efficient floating-point operations over the proposed expression rules. Please refer to [15] for details.
encrypted representation is not an easy task because we have
to consider all possible values that ciphertexts of the pro-
posed representation must have when we design the com- 2.2. Fully Homomorphic Encryption (FHE). FHE is a special
putation circuits to implement the operations. cryptosystem that can process encrypted data without
In this paper, we compare the performance of two decrypting them. This is useful for data delegation or pri-
representations each of which is implemented on top of vacy-preserving data processing. Figure 2 shows the dif-
HEAAN and FHE, respectively. As a result of performance ference between FHE and a conventional encryption scheme
comparison, HEAAN has a computation speed of several when addition of two encrypted numbers is performed.
tens to hundreds of times faster than that of TFHE-based With the ciphertexts by FHE, addition of their hidden
implementation. In the comparison operation, TFHE has plaintext values is possible without decryption.
tens to hundreds of times higher performance than HEAAN. An FHE scheme is defined with the following algorithms:
In the case of the equality checking operation, we could ParamGen (1λ, N, L) ⟶ param: this generates a pa-
observe that TFHE case is about 5 times faster than HEAAN. rameter for key generation. It takes the security pa-
The proposed method is expected to be used for the rameter λ, the number of slots in a ciphertext N, and the
implementation of the algorithms in privacy-preserving possible multiplicative depth of a fresh ciphertext
machine learning. In particular, it tells you what type of FHE without bootstrapping L.
schemes to use depending on the type of operation being
KeyGen (param) ⟶ sk, pk, evk: this is a key generation
used. Based on this, we hope that it could be widely used in
algorithm, which takes the parameter from the pa-
encrypted data processing and analysis applications.
rameter generation algorithm and outputs sk, a secret
This paper is organized as follows. Section 2 describes the
key for decryption, pk, a public key for encryption, and
preliminary to help understanding this study. Section 3
evk, a set of the evaluation keys with which some
introduces the research motivation and related work. In
computation over the ciphertexts can be done if the
Section 4, the proposed method is given, which is followed
ciphertexts are generated with the matched pk.
by the performance evaluation of implementation results in →
Section 5. Section 6 concludes the paper. Enc (m , pk) ⟶ C: an encryption algorithm which
→
takes a vector of plaintext message m of dimension N
and a public key and outputs a ciphertext that contains
2. Preliminary →
m.
→
2.1. IEEE 754 Floating-Point Representation. The proposed Dec (C, sk) ⟶ m (or ⊥): it takes a ciphertext c and a
→
representation is a variant of IEEE 754 standard floating- secret key sk, and outputs a plaintext m if C is the result
Security and Communication Networks 3
the operations supported on it. In HEAAN, as shown in the Zhu et al. [23] proposed a method to represent floating-
figure below, a limited number of real numbers can be stored point numbers as Double List Tree format and provide the
in one ciphertext. Arithmetic operations can be performed encryption function for them with Paillier cryptosystem
between those in the same slot as shown in Figure 3(B). In [24]. Their work utilizes hashtag (#) to represent the location
addition to this, as shown in Figure 3(C), it is possible to of the decimal points of encrypted numbers. However, in
move the embedded plaintexts between slots. Finally, if there this method, the digits of the real number can be inferred
are two ciphertexts where only 0 or 1 are encrypted in each through the position of the hashtag used for performing the
slot, then logical AND/XOR operations between the operation of each digit. Furthermore, their arithmetic op-
encrypted values are possible in the same slot position of erations use the size comparison operation. However, they
both ciphertexts. These logical operations can be imple- did not show how to implement the size comparison
mented by arithmetic subtraction, addition, and multipli- operation.
cation using the equations described in Figure 3(D). In the method of Jaschke and Armknecht [25], when an
Unfortunately, there is a disadvantage that a slot can only operation is performed on encrypted rational numbers, they
store a fixed-point real-number plaintext. Also, a certain are multiplied by an exponent of 2 to move the decimal place
operation can work only when the stored plaintext value is values to an integer position. After this, rounding is per-
within a limited range. TFHE has similar ciphertext struc- formed to remove the decimal point value, and the main
ture as HEAAN, but each slot can contain only 0 or 1 (1 bit operation is performed with only the integer parts of two
value). Also, slot-shift operation is not supported. operands. After that, the desired result is obtained by
adjusting the digits. This process has the disadvantage that
3. Related Work and System Model the precision of the operation is reduced because the cal-
culation is performed after some bit values of input rational
3.1. Related Work. There have been some attempts to rep- numbers are removed.
resent encrypted floating-point real numbers before this There are other methods such as those of Seiko and
study. Arita and Nakasato [21] proposed the FHE4FX Nakasato [26] and Dowlin et al. [27]. However, they require
method that can perform addition and multiplication be- a very large computation for floating-point operations. Also,
tween encrypted floating-point numbers without decryption as we mentioned in the previous section, HEAAN [14, 16]
based on the FV FHE method [22]. It generates an encrypted has some limitation on representing encrypted floating-
floating-point representation by encrypting each sign, ex- point numbers. Also, there has been no approach to rep-
ponent, and mantissa part of a real number in separate resent encrypted floating-point numbers on top of TFHE
ciphertexts. For the multiplication and addition operations [9, 19].
between encrypted values, it first determines the type of FHE In conclusion, there is no way to represent encrypted
operations to be performed on the sign, exponent, and floating-point real numbers with similar level of accuracy
mantissa parts based on the comparison result of values of and efficiency to the floating-point representation used in
each part of the ciphertext. Unfortunately, there is some common computing environment, even if there are so many
limitation in this approach that it is necessary to use the methods using existing FHE methods. In this paper, we aim
decryption key for computation and it does not support to solve this problem and make it possible to represent
operations other than addition and multiplication. encrypted floating-point numbers and to perform
Security and Communication Networks 5
computation with them efficiently. In other words, this result. For example, if there are two ciphers C1 and C2, and
research is the first study to propose and implement a size each represents a binary number using the bit values of all of
comparison operation and arithmetic operations over its slots, this module returns a ciphertext of 1 when C1 > C2
encrypted floating-point real-number representation effi- and returns 0 otherwise (if the resultant ciphertext has many
ciently using FHE. slots, it outputs the ciphertext containing 1 in every slot; this
also holds in the case where the resultant ciphertext contains
0). It can be implemented as shown in Figure 5(B) using
3.2. System Model. The system model assumed in this study
E-KSA module. The reason why this works is illustrated in
is as follows. The client translates the plaintext represen-
Figure 5(C). For example, if C1 contains an encryption of
tation of the floating-point real numbers into the encrypted
1100(2) (4 bits) and C2 contains 1010(2), we can see that a
one using the proposed method and delivers it to the central
carry is generated as a result of adding the 1’s complements
server. The central server then performs an algorithm that
of C1 and C2. Based on this, we can confirm that C1 > C2.
can be performed on the encrypted input and returns the
When using such a COMP circuit, if two ciphertexts C1
results back to the client. The client can decode the result to
and C2 are input, we can make a circuit that outputs a ci-
get the result. In this model, the client and server shares their
phertext CB containing the larger plaintext and another
public keys with each other.
ciphertext CS which contains the smaller plaintext among
The security model we assume is the general Honest-But-
the plaintexts encrypted in C1 and C2, respectively. If we
Curious (HBC) model. The central server performs pre-
assume the result of executing the COMP module with input
defined protocols, but it tries to obtain useful information of
C1 and C2 as COMP (C1, C2), CB can be derived by cal-
the clients while running the protocol. The clients are those
culating C1 ∗ COMP(C1, C2) + C2 ∗ (1c—COMP (C1, C2)).
who own their data, including both input and result of the
Similarly, CS ⟵ C1 ∗ (1c—COMP (C1, C2)) + C2 ∗ COMP
protocol, and want it to be protected from the central server.
(C1, C2). 1c means an encoding of 1 where calculation is
Please check Figure 4 above for the detailed description of
possible with other ciphertexts. If the ciphertext has many
the system and security model.
slots, 1c is an encoding of 1 in every slot. One caveat is that
you cannot know whether CB and CS come from either C1 or
4. Proposed Approach C2, respectively, because the above formulas’ calculation
In this section, we propose a new scheme to represent results depend on the results of COMP() circuit whose
encrypted floating-point numbers using two methods, output is encrypted; thus, it cannot be known without de-
HEAAN and TFHE, respectively. Our proposal includes the cryption. We can define the above two circuits as MinMax()
methods to support the arithmetic and the relation opera- as follows:
tions over the encrypted numbers represented by the pro- Cb , Cs ⟵ MinMax C1 , C2 . (1)
posed methods. Before explaining each method, we first
introduce the tools used to implement the proposed
methods and then proceed to the description of the pro-
posed one. We omit showing the evaluation key (evk) when 4.2. HEAAN-Based Method. The HEAAN-based method
we present the proposed methods because any calculation uses three ciphertexts to represent a single real number. The
involving the proposed encrypted representation needs evk. first ciphertext represents the sign of the real number, the
second ciphertext stores the exponent value, and the last
ciphertext stores the mantissa. The sign and exponent are
4.1. Building Blocks expressed as bit values like IEEE 754 standard. However,
4.1.1. Kogge–Stone Adder (KSA). The authors in [28] when expressing a mantissa, the corresponding number is
implemented the Kogge–Stone Adder [29], which performs not stored as a multibit value. Instead, it is encrypted to a
addition on two input numbers, using FHE to have it work HEAAN ciphertext directly. One significant difference of
on encrypted input numbers. In [28], it is assumed that each this approach from IEEE 754 is that the value of the mantissa
slot of a ciphertext stores only one bit value, and all the slots is assumed to be in the range [0, 1). This is because the
are used to represent one number. Therefore, we can use [28] HEAAN operation works better when the hidden plaintext
to implement the Kogge–Stone Adder over encrypted inputs in the ciphertext in [0, 1) than [1, 2).
using either TFHE or HEAAN, if we put only one-bit Figure 6 shows the procedure on how a single floating-
plaintext in each slot of ciphertext. Using this, it is possible to point number is encrypted using three ciphertexts. cresult []
implement the adder using a circuit with log n multiplication is an array containing ciphertexts. It is assumed that the
depth when inputs are of n bits. Figure 5(A) shows the value assigned to the ciphertext cresult [] is encrypted and
encrypted KSA (E-KSA) in [12]. Two ciphertexts are output stored in the corresponding ciphertext. Figure 7 shows an
of the adder where the first has the sum where all n slots are example of converting a real number into the proposed
filled with outputs, whereas only one slot is used in the other encrypted representation.
ciphertext to represent the carry of the addition.
4.2.1. Addition/Subtraction. The HEAAN-based addition
4.1.2. Comparator (COMP) Module. It compares the size of method is implemented as shown in Figure 8. In this
two ciphertexts and returns a ciphertext containing the method, two operands are classified to a smaller number and
6 Security and Communication Networks
Bob (client)
the other bigger number first. Then, the exponent value of We suppose the result of Rearrange (C1, C2, EXPO) is CS
the smaller number is increased to be matched to that of the and CB. We run the following addition code with CS and CB
bigger number. The increase of the value of the smaller in Figure 10. The output of the code is Cout. We discuss how
number, which results from the increasing the exponent, is the following code works. Because CS[EXPO] < CB[EXPO]
cancelled by dividing the mantissa part. After that, two and CS[FRAC], CB[EXPO] in [0, 1), the sign of the addition
mantissa parts are added to complete the addition. result is CB[SIGN]. Also, to perform calculation, the code
The details of addition operation is as follows. We increases CS[EXPO] to make it the same as CB[EXPO]. To
suppose two operands to be added as C1 � (C1[SIGN], keep the original value of CS after increasing CS[EXPO], the
C1[EXPO], C1[FRAC]), C2 � (C2[SIGN], C2[EXPO], code decreases CS[FRAC] accordingly. After that, it returns
C2[FRAC]). The function ReArrange (), which returns a the result of CB[FRAC] + CS[FRAC] when both CB and CS
larger value in cB and a small value in cS among the input C1 have the same sign or CB[FRAC] − CS[FRAC] if the signs are
and C2, can be implemented as shown in Figure 9. C1 and C2 different. To keep the result’s fraction is in [0, 1), the ex-
are compared based on their exponent values. ponent is increased by 1 and the fraction is divided by 2.
Security and Communication Networks 7
START : Encryption
float2cipher
(cresult[], num)
expo = 0
False True
Num > 0
cresult[SIGN] = 1 cresult[SIGN] = 0
False True
fabs (num) < 1.0
RETURN cresult[]
Figure 7: An example of representing 30.3 with the HEAAN-based proposed scheme. The exponent is converted to binary representation.
Then, it is encrypted to C[expo]. Each encrypted bit is stored in each slot. On the other hand, the fraction is stored as it is in a HEAAN
ciphertext.
Because the maximum binary string that CB[EXPO] and 4.2.2. Multiplication. Multiplication is easier to implement
CS[EXPO] can have is 11111111(2), Ceqcc is an encryption of than addition. First, the sign of the result value is equal to the
1 only once in the loop. In this case, value obtained by XORing the sign of two input numbers,
CB[FRAC] + CS[FRAC] ∗ (1 − 2 ∗ Csign) is given to Cout[- and the result of the exponent part can be obtained by
FRAC], where Csign is the result of checking if CB[SIGN] and adding the exponents of the two inputs. E-KSA can be used
CS[SIGN] are the same: if so, it has the encryption of 0, and 1 to calculate it. Also, the mantissa can be obtained by
otherwise. In Step 3, EQCC (CB[EXPO], CS[EXPO]) exe- multiplying the mantissas of two input numbers. In this case,
cutes HEAAN_XNOR(CB[EXPO], CS[EXPO]) from inside the result of multiplying mantissa is still in [0, 1). Thus, we
to perform XNOR operation between the bit values in the have nothing to do further. Figure 11 shows the process of
same slot of CB[EXPO] and CS[EXPO], respectively. After multiplying two encrypted floating-point real numbers C1
that, we multiply all the bit values in each slot of XNOR and C2 in the proposed method.
result to create Ccomp. Ccomp becomes 1 if CB[EXPO] and
CS[EXPO] have exactly the same bit value in all of their slots;
otherwise, it becomes 0. 4.2.3. Comparison. In the HEAAN-based approach,
To perform subtraction, the sign of the number to be COMPHEAAN() function is used as a tool to perform the size
subtracted is inverted using HEAAN_XNOR, and then the comparison operation of the encrypted floating-point
addition operation is performed instead. values. COMPHEAAN () takes two HEAAN ciphertexts and
8 Security and Communication Networks
Cout
C1.0
Equal comparison module
with exponent value C1.1
C1.2
..
CS S0 S1.0 S1.1 S1.02 ... S1.7 S2 .
C1.7
the computation key evk of the ciphertext and performs the C1[EXPO], C1[FRAC]) and C2 � (C2[SIGN], C2[EXPO],
following operation [30]: C2[FRAC]) using the code written in Figure 12. If the code
outputs an encryption of 1, it says C1’s absolute value is
COMPHEAAN C1(HEAAN) , C2(HEAAN) , evk ⟶ 1 if
(2) greater than C2’s and it returns an encryption of 0 otherwise.
· C1(HEAAN) > C2(HEAAN) else 0. Step 2 in Figure 12 is described in Figure 13 in detail.
A circuit for determining if two encrypted representa-
Using the above circuit, we can compare the size of two tions are equal can be implemented similar to addition/
encrypted floating-point numbers C1 � (C1[SIGN], subtraction circuit: it can be easily obtained by calculating
Security and Communication Networks 9
Cout
HEAAN_XOR ()
C1[EXPO] C1[FRAC] C0
C2
Cout[FRAC]
whether the FRAC part and the SIGN part of both floating- is greater if the mantissa of the dividend is doubled. The
point numbers to be compared are the same using COM- process can be described as follows.
PHEAAN() after equalizing their EXPO parts. Step 1 in Figure 14 can be specified in detail as follows in
Figure 15.
4.2.4. Division. The division operation is similar to the
multiplication operation except that the exponent part of the 4.3. TFHE-Based Method. The TFHE-based expression
divisor is subtracted from the exponent of the dividend, and follows the standard IEEE 754 exactly. For example, to
the inverse of the mantissa of the divisor is calculated using represent 30.3 with the TFHE-based representation, we first
the inverse function and then it is multiplied by the mantissa translate this as 1.1110010011001100110 × 23(2). Then we add
of the dividend. In this case, if we do nothing further, the 127 to the exponent to represent the exponent bits. The
mantissa of the resultant value may be greater than 1. To deal fraction part stores all the fraction bits except the first “1” at
with this, before performing the multiplication operations in the left of the decimal point. In this approach, sign, expo-
the fraction part, the mantissa of the dividend is corrected so nents, and mantissa are encrypted by separate ciphertexts.
that it is smaller than the mantissa of the divisor. However, it The number of ciphertexts in C[SIGN] is 1, C[EXPO] is 8,
10 Security and Communication Networks
Input: C1[SIGN], C2[SIGN], C1[EXPO], C2[EXPO], C1[FRAC], C2[FRAC] (C1: Dividend, C2: Divisor)
1. Adjust C1 to make C1[FRAC] < C2[FRAC] < 2 ∗ C1[FRAC]
2. Cexpo ← HEAAN_XOR (C2[EXPO], 1c) + 1 // 2′s complement of C2[EXPO]
3. Cout[EXPO] ← E-KSA (C1[EXPO], Cexpo) // Cout[EXPO] = C1[EXPO] – C2[EXPO]
4. Cinv ← 1/C2[FRAC]
5. Cout[FRAC] ← C1[FRAC] ∗ Cinv
6. Cout[SIGN] ← HEAAN_XOR (C1[SIGN], C2[SIGN])
7. Output Cout = (Cout[SIGN], Cout[EXPO], Cout[SIGN])
and C[FRAC] is 23 when the encrypted floating-point Step 1. Convert the plaintext number to IEEE 754 representation
number is represented as C � (C [SIGN], C [EXPO], C Sign 2exponent Fraction
[FRAC]). Also, for ease of expression, TFHE_XOR () op-
30.3 0 10000011 11100100110011001100110
eration is written as ⊕, and TFHE_AND () operation is
indicated by. Figure 16 explains the procedure of making a
Step 2. Encrypt each part separately with TFHE
TFHE-based encrypted floating-point number representa-
tion with an example of 30.3. Sign 2exponent Fraction
To explain the methods clearly, we are going to use the 0 10000011 11100100110011001100110 Ciphertext
following notations. An array of ciphertexts C[] � c0||c1||. . .||
Figure 16: Creating a ciphertext of a floating-point number with
cn− 1 can be described as C[0] � c0, C[1] � c1,. . . , C[n− 1] � cn− 1,
TFHE.
where ci (i ∈ [0, n− 1]) refers to an encryption of a single bit
value. If we describe C[] � (cn− 1 cn− 2 . . . c2c1c0) (2), as a binary
integer representation, then C[0] � c0, C[1] � c1,. . . , building block for addition operation. We also introduce the
C[n− 1] � cn− 1, too. If there are two array of ciphertexs A[] and negate function (Negate()) which flips the bits in the input
C[], where both are represented as binary integers and they set of ciphertexts in Figure 19.
are added using E-KSA circuit, then the result CR[] is 2n− 1 Figure 20 shows the procedure of addition operation
(cn− 1 + an− 1) + 2n− 2 (cn− 2 + an− 2)+ . . . + 21(c1 + a1) + c0+a0. with TFHE-based representation. For subtraction, the ad-
Also, you have to keep in mind that c ⊕ (c0||c1||. . .|| dition operation can be used after modifying the sign of the
cn− 1) � (c ⊕ c0||c ⊕ c1. . .||c ⊕ cn-1) and (ca0||ca1||. . .||can) ⊕ value to be subtracted.
(cb0||cb1||. . .||cbn) � (ca0 ⊕ cb0||ca1 ⊕ cb1||. . .||can ⊕ cbn). The
concatenation of two ciphertext arrays A[] and B[] can be
described as A[]||B[], and it generates a new array of ci- 4.3.2. Multiplication. The multiplication operation proceeds
phertexts. Finally, C[] � C[] >> 1 means C[i + 1] � C[i] for all as follows. First, a basic operation is performed in which an
i � 0, . . ., len(C[])− 2 and C[0] � 0. XOR operation is performed on sign portions and the addition
is performed on exponent portions. Then, the result of the
multiplication operation of the fraction parts is applied. When
4.3.1. Addition/Subtraction. The addition algorithm is adding the exponent parts, 127 is subtracted from the addition
constructed in a manner as similar as the HEAAN-based result to get the correct result. This is because the exponent
method. However, in this TFHE based method, arrays of part is basically expressed by adding 127 so that a negative
ciphertexts are used to represent the components of the number can be expressed with unsigned bit-strings. The
representation and each ciphertext has one bit value, which overall multiplication process is shown in Figure 21 below.
complicates the process as shown in Figure 17. We use Among the three operations in Figure 21, (1) and (2) are
E-KSA as building block. The input of E-KSA, however, is easy to implement, so we focus on (3). To perform (3), the
arrays of ciphertexts instead of ciphertexts of multiple slots. numbers actually represented by C1[FRAC] and C2[FRAC]
Our implementation of E-KSA considered that. Figure 18 must be restored. The bits in C1[FRAC] and C2[FRAC] mean
shows an implementation of Equality Comparison Circuit the values to the right of the decimal point in the two
(TFHE_EQCC()) for TFHE representation, which is also a numbers’ fraction parts, and the leading “1” to the left of the
Security and Communication Networks 11
Fraction
Comparison addition
CB[FRAC] CS[FRAC] KSA result result result
KSA7 KSA7
B8 Z KSA8 KSA78
S8 S8 KSA9 KSA9
S9 S9 KSA10 Ccomp KSA10
⊕
S11 S10 KSA KSA11 KSA11
.. .. .. ..
. . . .
S31 S30 KSA31 KSA31
SHIFT (>>)
Figure 17: Overview of addition operation in TFHE-based method.
Input: CA[], CB[] // Arrays of encrypted bits, assumes length of CA[] and CB[] are same.
1. cout ← 1
2. For i = 0 to len (CA[]) – 1
2.1 c ← CA[i] ⊕ CB[i]
2.2 c ← c ⊕ 1 // negate c
2.3 cout ← cout∙c
3. Output cout
Input: C[] // Arrays of encrypted bits, assumes length of CA[] and CB[] are same.
1. cout ← 1
2. For i = 0 to len (C[]) – 1
2.1 C[i] ← C[i] ⊕ 1
3.C[] ← E-KSA (C[], 1) // 1 should be contained an array of ciphertext C’[] where the first is 1
// and the others set to zero.
4. Output C[]
decimal point is omitted as specified by the standard. the multiplication result is Cm [1] ∼ Cm [22], and the ex-
Therefore, the multiplication calculation should be per- ponent value should be incremented by one. If Cm[0] is 0,
formed after recovering the “1”. Therefore, the multiplica- that means Cm [1] is 1, so the exponent does not increase and
tion is performed by attaching an encoding of “1” to the the fraction part of the result is Cm [2]∼Cm [24]. The method
most significant digit, which is just left to the decimal point. that reflects this is shown in Figure 22 below.
In this case, the multiplication result cannot exceed 4, so the
result is a 46-bit value with two bits to the left of the decimal
point and the remaining 44 bits to the right. 4.3.3. Division. The division operation is similar to the
After calculating Cm[], the final step is to check whether multiplication operation. That is, to calculate the exponent
the value in the ciphertext Cm[0], which represents the most part, the exponent value of the denominator is subtracted
significant bit of the multiplication result and 1 bit left away from the numerator, and division operation is performed
from the decimal point, is 1. If Cm[0] is 1, the fraction part of between the fraction parts of them. Since the exponent
12 Security and Communication Networks
Figure 20: The addition algorithm for the TFHE-based representation. It takes CB, CS and outputs Cout.
Figure 22: Details of calculating the exponent and fraction in multiplication in TFHE-based representation.
should be added to 127 (�2((length of exponent bits)− 1) − 1) to operations to be performed for division. Cout[EXPO] and
represent the negative exponent, 127 should be added to the Cout[FRAC] are the result values, C1 � (C1[SIGN],
resultant exponent after the subtraction. An overview of C1[EXPO], C1[FRAC]) is the numerator, and
division operation to calculate the resultant exponent and C2 � (C2[SIGN], C2[EXPO], C2[FRAC]) is the denominator.
fraction is shown in Figures 23 and 24, respectively. As with multiplication, the most important and difficult
After calculating the exponent and the fraction, we need process is (3). We use the nonrestoring division [31] method,
to correct them because the range of the result of calculating which uses the divide-and-conquer to implement (3). This is
the fraction part is (0.5, 2). Thus, if the fraction part’s result is known to be more efficient than the well-known methods
less than 1, 1 must be subtracted from the exponent and the such as those of Newton-Rapth [32] and Burnikel and
bit position of the resultant fraction must be shifted to left by Ziegler [33]. Figure 26 shows the result of implementing the
1 bit. The sign is determined by XORing the signs of the nonrestoring division algorithm [15] to make it work on
numerator and denominator. Figure 25 shows the ciphertext input. This algorithm assumes that the highest-
Security and Communication Networks 13
Sub1 Z C1
B1 S1
Sub2 Z C2
B2 S2
Sub3 One C3
B3 S3
Binary Sub4 One KSA
.. .. ..
. . subtraction .. .. .
. .
B8 S8 Sub8 One C8
Figure 23: Exponent calculation module in the division operation of TFHE-based method.
Divisor
M0 M1 M2 ... M22
3. Divisor
copy M0 M1 M2 ... M22
Figure 24: Fraction calculation module in the division operation of TFHE-based method.
order bits are stored in index 0 of each input array, and the 2). Therefore, the subsequent 23 bits are stored in the fraction
lower-order bits are stored as the index becomes larger. The part. If so, the value of exponent must be decreased by one.
bit length of both dividend and divisor is 24 bits each. Figure 27 shows an example of the case where the left part of
We deal with how to calculate (3) specifically. Since the the decimal point becomes zero in the fraction part of the
mantissa is represented by omitting 1 immediately to the left of division result. The steps to be performed is shown in the figure.
the decimal point which is the largest digit, in order to perform The details of (3) is shown in Figure 28.
division correctly, the omitted bits should be restored before
starting the division operation. To do this, the size of the ci-
phertext arrays indicating both the dividend and divisor is 4.3.4. Comparison and Equality Check. The comparison
increased by one each, and we place an encoding of 1 to the operation can be done using the COMP() circuit described in
highest position (i.e., the zeroth index). Then, division is Figure 5(B), using the bitwise concatenation results of all of the
performed through R_DIV (). The result is a 25-bit quotient. In sign, exponent, and fraction ciphertext arrays in both values to be
this case, if the bit value of the highest position is 1, the next 23 compared as inputs. IEEE 754 standard exactly uses the same
bits are stored in the resultant fraction. Otherwise, the value of approach to compare the floating-point numbers. The process of
the second digit is 1 because the division quotient range is (0.5, comparing two numbers can be expressed as shown in Figure 29.
14 Security and Communication Networks
Figure 27: An example of normalizing the fraction part in the division result.
Figure 28: Procedure for calculating Cout[FRAC] with updating Cout[EXPO] in division.
The equality can be easily checked as they are repre- SIMD operation, but the TFHE-based method must perform
sented using bits. Two values are treated the same only if operations in bit units, which requires large number of
they have the same bits. TFHE operations.
Second, the HEAAN-based implementation can im-
plement the operations for dealing with the mantissa part
4.4. Discussion on the Differences between the Implementation with a small number of HEAAN operations using arith-
of Two Methods. The differences between the implementa- metic operation provided by HEAAN, but in TFHE-based
tion of the two methods can be summarized as follows. First, method, the operation must be processed for each bit of
in the operation with exponent values, the HEAAN-based mantissa, which also requires a large number of TFHE
method can reduce the number of operations by using the operations.
Security and Communication Networks 15
In the above two cases, the HEAAN-based method seems Table 1: Computational complexity analysis on the operations in
to be dominant, but HEAAN requires bootstrapping when it terms of the number of FHE multiplication operations required.
needs complex arithmetic with their floating point repre- Operations TFHE HEAAN
sentations: especially when it needs calculation of more than Addition O(2e (m + e)log(m + e)) O(2e log(e))
a predetermined multiplication depth. In this case, HEAAN Multiplication O(m2 + e log(e)) O(2e e)
needs a lot of computation resources. Thus, it will be much O(m log(e)) + 2
slower than the TFHE-based method. Division O(m2 + me + e log(e))
bootstraps
Comparison O((m + e)log(m + e)) O(log(e))
5. Performance Evaluation m: bit length of mantissa, e: bit length of exponent.
54895
15363
54887
15284
2298.8
7204.3
7213.8
100000
1116.2
3761.5
3763.1
7236
2294.4
1129.7
10000
931.9
928.7
1152
Second (s)
1000
94.5
95.2
39.93
34.2
39.3
31.3
20.2
22.1
100
10
1
2 4 8 2 4 8
TFHE HEAAN
Exponent bitlength
Addition Multiplication
Subtraction Division
Figure 31: Performance on arithmetic operations.
Table 4: Experiment results on various mantissa bit lengths when the bit length of exponent is fixed to four (in seconds).
TFHE HEAAN
Fraction bit length Log p (p-bit)
ADD MULT DIV COMP ADD MULT DIV COMP
23 489.613 162.195 686.513 5.70388 185.735 10.735 417.938 171.706 28
33 1351.28 446.062 2275.67 12.0943 166.174 10.783 716.644 152.721 38
43 1167.55 571.274 2950.23 12.6297 583.492 10.659 1066.72 531.607 48
52 1207.52 686.463 3559.19 13.0962 1110.84 10.449 2162.76 941.9 57
Table 5: Relative errors between the multiplication result with ciphertexts and that with plaintexts.
Multiplication round 1 2 3 4 5 6 7 8 9 10
Relative error 1.21E − 7 6.92E − 8 7.91E − 8 9.04E − 8 1.03E − 7 0 6.75E − 8 1.54E − 7 0 0
Proceedings of the 2018 Annual International Conference on [31] S. Kaur, M. Singh, and R. Agarwal, “Vhdl implementation of
the Theory and Applications of Cryptographic Techniques non-restoring division algorithm using high speed adder/
(EUROCRYPT’18), pp. 306–384, Aarhus, Denmark, May subtractor,” International Journal of Advanced Research in
2018. Electrical, Electronics and Instrumentation Engineering, vol. 2,
[17] J. H. Cheon, K. Han, S.-M. Hong et al., “Toward a secure pp. 3317–3324, 2013, https://www.researchgate.net/
drone system: flying with real-time homomorphic authenti- publication/250612202_VHDL_Implementation_of_Non_
cated encryption,” IEEE Access, vol. 6, pp. 24325–24339, 2018. Restoring_Division_Algorithm_Using_High_Speed_
[18] K. Han, S. Hong, J. Cheon, and D. Park, “Logistic regression AdderSubtractor.
on homomorphic encrypted data at scale,” in Proceedings of [32] M. J. Flynn, “On division by functional iteration,” IEEE
the 31st Annual Conference on Innovative Applications of Transactions on Computers, vol. C-19, no. 8, pp. 702–706,
Artificial Intelligence (IAAI-19), Anaheim, CA, USA, July 1970.
2019, https://aaai.org/Conferences/AAAI-19/iaai-19/. [33] C. Burnikel and J. Ziegler, “Fast recursive division,” Research
[19] I. Chillotti, N. Gama, M. Georgieva, and M. Izabachène, Report Max-Planck-Institut fuer Informatik Research Report
“Faster packed homomorphic operations and efficient circuit MPI-I-98-1-022, Max–Planck–Institut für Informatik,
bootstrapping for TFHE,” in Advances in Cryptology- Saarbrücken, Germany, 1998.
—ASIACRYPT 2017, vol. 10624, pp. 377–408, Springer,
Heidelberg, Germany, 2017.
[20] C. Gentry, A. Sahai, and B. Waters, “Homomorphic en-
cryption from learning with errors: conceptually-simpler,
asymptotically-faster, attribute-based,” in CRYPTO’13,
vol. 8042, pp. 75–92, Springer, Heidelberg, Germany, 2013.
[21] S. Arita and S. Nakasato, “Fully homomorphic encryption for
point numbers,” in Proceedings of the 12th International
Conference, Information Security Practice and Experience
(ISPEC) 2016, vol. 10143, pp. 253–270, Zhangjiajie, China,
November 2016.
[22] J. Fan and F. Vercauteren, “Somewhat practical fully ho-
momorphic encryption,” IACR Cryptology ePrint Archive,
vol. 2012, p. 144, 2012, https://eprint.iacr.org/2012/144.
[23] T. Zhu, X. Zou, and J. Pan, “Query with SUM aggregate
function on encrypted floating-point numbers in cloud,”
Journal of Information Processing Systems (JIPS), vol. 13, no. 3,
pp. 573–589, 2017.
[24] P. Paillier, “Public-key cryptosystems based on composite
degree residuosity classes,” in Proceedings of the 18th Annual
International Conference on the Theory and Applications of
Cryptographic Techniques (EUROCRYPT) 1999, pp. 223–238,
Prague, Czech Republic, May 1999.
[25] A. Jaschke and F. Armknecht, “Accelerating homomorphic
computations on rational numbers,” in Proceedings of the
Applied Cryptography and Network Security (ACNS) 14th
International Conference, pp. 19–22, Guildford, UK, June
2016.
[26] S. Arita and S. Nakasato, “Fully homomorphic encryption for
point numbers,” in Proceedings of the International Confer-
ence on Information Security and Cryptology, pp. 253–270,
Springer, Seoul, Korea, December 2016.
[27] N. Dowlin, R. Gilad-Bachrach, K. Laine, K. Lauter,
M. Naehrig, and J. Wernsing, “Manual for using homo-
morphic encryption for bioinformatics,” Proceedings of the
IEEE, vol. 105, no. 3, 2017.
[28] K. Seo, P. Kim, and Y. Lee, “Implementation and performance
enhancement of arithmetic adder for fully homomorphic
encrypted data,” Journal of the Korea Institute of Information
Security & Cryptography, vol. 27, no. 3, pp. 413–426, 2017.
[29] P. M. Kogge and H. S. Stone, “A parallel algorithm for the
efficient solution of a general class of recurrence equations,”
IEEE Transactions on Computers, vol. C-22, no. 8, pp. 786–
793, 1973.
[30] J. Cheon, D. Kim, D. Kim, H. H. Lee, and K. Lee, “Numerical
method for comparison on homomorphically encrypted
numbers,” in IACR Eprint Archive, Springer, Heidelberg,
Germany, 2019, https://eprint.iacr.org/2019/417.