Homomorphic Comparison for Point Numbers with User-Controllable Precision and Its Applications

: This work is mainly interested in ensuring users’ privacy in asymmetric computing, such as cloud computing. In particular, because lots of user data are expressed in non-integer data types, privacy-enhanced applications built on fully homomorphic encryption (FHE) must support real-valued comparisons due to the ubiquity of real numbers in real-world applications. However, as FHE schemes operate in speciﬁc domains, such as that of congruent integers, most FHE-based solutions focus only on homomorphic comparisons of integers. Attempts to overcome this barrier can be grouped into two classes. Given point numbers in the form of approximate real numbers, one class of solution uses a special-purpose encoding to represent the point numbers, whereas the other class constructs a dedicated FHE scheme to encrypt point numbers directly. The solutions in the former class may provide depth-efﬁcient arithmetic (i.e., logarithmic depth in the size of the data), but not depth-efﬁcient comparisons between FHE-encrypted point numbers. The second class may avoid this problem, but it requires the precision of point numbers to be determined before the FHE setup is run. Thus, the precision of the data cannot be controlled once the setup is complete. Furthermore, because the precision accuracy is closely related to the sizes of the encryption parameters, increasing the precision of point numbers results in increasing the sizes of the FHE parameters, which increases the sizes of the public keys and ciphertexts, incurring more expensive computation and storage. Unfortunately, this problem also occurs in many of the proposals that fall into the ﬁrst class. In this work, we are interested in depth-efﬁcient comparison over FHE-encrypted point numbers. In particular, we focus on enabling the precision of point numbers to be manipulated after the system parameters of the underlying FHE scheme are determined, and even after the point numbers are encrypted. To this end, we encode point numbers in continued fraction (CF) form. Therefore, our work lies in the ﬁrst class of solutions, except that our CF-based approach allows depth-efﬁcient homomorphic comparisons (more precisely, the complexity of the comparison is O ( log κ + log n ) for a number of partial quotients n and their bit length κ , which is normally small) while allowing users to determine the precision of the encrypted point numbers when running their applications. We develop several useful applications (e.g., sorting) that leverage our CF-based homomorphic comparisons.


Introduction
The success of cloud computing is primarily attributed to the fact that individuals with limited computing power cannot easily manage an exponentially increasing amount of data and knowledge in a cost-effective manner. Let us say that due to privacy concerns, a user Alice, who stores sensitive data at a remote server Bob, wishes to run some algorithms, such as sorting or classification, on the data without revealing any confidential information. In a cloud computing environment, a large variety of useful algorithms rely on secure comparisons. The secure comparison problem in this setting means that for two numbers that Alice is storing, r 0 , r 1 , Bob outputs r b such that r b ≥ r 1−b without disclosing the numbers, where b ∈ {0, 1}.
Following Yao's seminal work on garbled circuits [1], there have been several sensible solutions for cases in which the input numbers are integers. Putting such a restriction on integers seems unavoidable because their underlying cryptographic primitives are designed over integers. Since Fouque et al., in [2], developed an approach to encode rational numbers as integers and to perform computations on the encoded rational numbers, secure noninteger computations have received significant attention. Examples of prominent solutions, to the best of our knowledge, include Catrina and Saxena's solution for fixed-point numbers [3], Aliasgari et al.'s secure floating-point arithmetic [4], and Dimitrov et al.'s secure real-valued computations [5]. Secure comparison has many useful applications; for example, the evaluation of disease risk using clinical data [6] and the private analysis of satellite collisions [7].
One interesting observation is that while Fouque et al.'s solution using Paillier's cryptosystem is non-interactive, all other solutions have been studied under the multiparty computation (MPC) framework, which depends heavily on interactions between the user and the server. However, this property of the MPC can cause conflicts with the user's desire to minimize communications with the server due to limited bandwidth; consequently, existing MPC solutions may not be suitable for the cloud setting. The main advantage of the MPC-based approach can be explained by Archer et al.'s experimental study in [8], which states that the fastest alternative among solutions for secure computing is MPC based on secret sharing. This is one of the main reasons that this work considers fully homomorphic encryption (FHE), which allows anyone to evaluate arbitrary functions (more precisely, circuits representing the functions). Although FHE is notorious for being very computationally intensive, one of our main technical objectives is to devise a way to mitigate performance penalties and apply FHE for homomorphic comparisons over encrypted point numbers.

Contributions
In this work, our main contributions are twofold: 1.
Controllable precision. A key observation by Chung and Kim [9] is that when real numbers are expressed as a continued fraction (CF), partial quotients consisting of their CF representation can be taken as small integers (e.g., Z 1024 ). Thus, encoding point numbers as CFs enables depth-efficient, real-valued computation, even with a small plaintext space. Our new observation is that CF representation allows users and servers to adjust the precision of point-number computation by controlling the number of partial quotients rather than by configuring the FHE parameters. Moreover, it is well known that a CF is the best approximation of a real number among all rational numbers with the same or smaller denominators. In practice, separating precision from the parameter setup may be beneficial because it is more convenient for the user and the design is more modular. We make use of this observation in depth-efficient homomorphic comparisons, including equality and greater-than, to obtain such benefits.

2.
Depth-efficient homomorphic comparisons of point numbers. We present three homomorphic comparison protocols-equality, less-than, and greater-than-that efficiently compare the encryption of two CF-encoded point numbers reporting an encrypted result. The key idea is that if two real numbers are the same, their CF representation will be the same; in essence, the equality test for two numbers in CF form is the same as that of the numbers in decimal form.
Our equality test thus requires a multiplicative depth of O(log κ + log n), where κ is the bit length of the partial quotients and n is the number of partial quotients. Similarly, we devise less-than and greater-than algorithms by comparing two partial quotients at the same position from left to right. These algorithms also have multiplicative depths of O(log κ + log n). Our results imply that the CF encoding of point numbers is much more suitable for homomorphic comparisons than for homomorphic computations, since comparison algorithms do not require heavy computation. Indeed, CF-based homomorphic computations need to run Gosper's algorithm, which involves modular arithmetic over FHE encryptions. See ([9] §3.1) for details.)

High-Level Sketch of Our Approach
The primary difference between our techniques and existing solutions lies in the way point numbers are represented. In this work, we write point numbers in CF form and then consider comparison algorithms over their FHE encryptions. Our choice leads to some technical benefits over other encoding techniques that are widely used for supporting homomorphic arithmetic over encrypted real numbers. The primary benefit is reducing the overhead of manipulating the computational precision of numeric values. Because precision-related parameters do not need to be examined when initializing the underlying FHE scheme, the proposed method may be attractive to FHE-based application developers, especially in cases wherein the precision level is not known or varies frequently. In addition to having FHE schemes take small system parameters-particularly a small plaintext space (see Theorem 3)-encryptions of CF-encoded point numbers can be used to execute homomorphic arithmetic without being switched to a different encoding.
We next describe the basic algorithms that enable two FHE-encrypted point numbers to be compared without decryption. As mentioned previously, it is straightforward to compare two point numbers written in CF form. For two X, Y ∈ R, assume that X (resp., Y) is expressed as a sequence of partial quotients; i.e., X = [x 0 ; x 1 , . . . , x n−1 ] (resp., Y = [y 0 ; y 1 , . . . , y n−1 ]), where for simplicity, all x i , y i are non-negative. Then, we only need to check the first pair of partial quotients that are different (i.e., x i and y i ). For all even-numbered indices i ∈ {0, 2, 4, . . .}, if x i < y i , then X < Y. However, if i is an odd-numbered index and x i > y i , then X < Y. See Theorem 4 for the details of performing comparisons between CF-represented real numbers. Example 1. We end this section with a toy example to show that our approach is plausible. Consider a value v = 1.2345678901. Writing v as a CF V = [1; 4, 3, 1, 3] has an error of 1 9280 < |v − V| < 1 5184 , but writing it as V * = [1; 4, 3, 1, 3, 1] has only an error of 1 89812152 < |v − V * | < 1 89805591 .

Applications
Our choice of encoding and basic comparison algorithms have readily usable applications in a variety of areas. We provide a list of some interesting applications for which they are appropriate in scenarios involving sensitive numerical data, particularly real numbers, which are encrypted and stored on a remote untrusted server and require a large number of comparisons without user intervention.
Sorting. Sorting is one of the most frequently used basic data manipulations. Well-known applications of sorting include conducting private auctions [10] and comparing genetic sequences [11], and more generic primitives, such as top-k queries [12] and (weighted) set intersection [13,14]. In [15], Chatterjee et al. studied a way to accelerate an FHE-based sorting algorithm. Unfortunately, their proposed approach requires 235 s to perform a bubble sort on five FHE ciphertexts whose underlying messages are 32-bit integers. In [16], Cetin et al. introduced a new sorting algorithm to optimize a multiplicative depth for efficient homomorphic sorting. The merge sort, which is known as the most efficient sorting algorithm, requires a depth of O(N log 2 N) for data of size N, but the algorithm of Cetin et al. requires a multiplicative depth of O(log N + log ), where is the size of the data.
Machine learning. Millions of people are generating tremendous amounts of data through the increased use of various electronic devices that are normally resource-constrained. Considering the continuously increasing power of modern computers, it is not probable that individuals will be able to keep up with this pace. Thus, one cost-effective approach to handle this asymmetry in computational resources is to rely on cloud computing. A natural solution to prevent privacy breaches of personal data stored in the cloud is to encrypt the data and delegate computations on encrypted data to the cloud.
In this context, homomorphic comparisons over encrypted real numbers are required for basic machine learning (ML) functions, such as classification [17] and the evaluation of decision trees [18]. Then, one can apply these basic ML operations to design a variety of applications, including clinical decision-making aids [19], disease risk estimators [6], and recommendation systems [20].
Private database queries. Other useful applications of homomorphic comparisons include range queries over encrypted databases [21], algorithms for optimization problems in supply chain management [22,23], and privacy-preserving signal processing [24,25]. Note that these examples are a nonexhaustive list of promising applications of secure comparisons using FHE.

Closely Related Work
This subsection reviews existing work that is closely related to making secure comparisons using homomorphic encryption. The majority of existing solutions focus on securely performing homomorphic computations of point numbers. Despite the wide range of applications, few studies have considered how to securely compare two real numbers.
Given a rational number q = t/s, where gcd(s, t) = 1, Fouque et al., in [2], wrote q as q = ts −1 (mod N) for an RSA modulus N where gcd(s, N) = 1, and encrypted q with Paillier's cryptosystem [26]. After decryption, (t, s) can be recovered from q by using the Gauss algorithm, which enables a basis to be found in a 2-dimensional lattice. Since Paillier encryption is additively homomorphic, one can perform addition multiple times over encrypted rational numbers; however, a comparison of two encrypted rational numbers cannot be performed.
To our knowledge, there are a few works that attempt to handle point numbers in the FHE framework. In [27], Jäschke and Armknecht proposed a special-purpose encoding algorithm for rational numbers in the FHE context. However, due to the specificity of their proposed encoding, Boolean comparisons on encrypted data of bit length are not performed efficiently, since O( ) multiplicative depth is required rather than a shallower depth of only O(log ). Recently, Costache et al.'s scheme in [28] investigated fixed-point arithmetic in somewhat homomorphic encryption. However, they focused only on basic arithmetic operations. Chung and Kim proposed a CF representation [9], but their protocol does not support homomorphic computations between FHE encryptions (i.e., one input must be given in the clear). In [29,30], an encoding method for fixed-point numbers was presented that was tailored for homomorphic function evaluation and had the advantage of allowing a smaller plaintext coefficient modulus to be chosen. However, even when the coefficients of a polynomial are small, the degree of the polynomial doubles when multiplication is performed in order to preserve correctness. For this reason, when two real numbers are compared with high precision, several multiplications are required and the polynomial degree becomes large, which may not lead to efficient implementation.
In a new line of research, Cheon et al.'s approximate FHE scheme, called homomorphic encryption for arithmetics of approximate numbers (HEAAN) [31], allowed point numbers to be encrypted directly. More recently, a method for depth-efficient comparison of two point numbers encrypted under HEAAN has been suggested by Cheon et al. in [32]. However, for high precision, HEAAN requires a large scale factor ∆ (for example, 40-50 bits), since multiplying by a larger scale factor enables higher precision. Another drawback of high-precision settings is the consumption of a higher modulus number Q during the rescaling process. Consequently, HEAAN needs to configure precision-related parameters during its setup algorithm and may suffer from performance degradation by customizing the parameters for high precision. Moreover, existing efficient implementations of HEAAN use residue-number-system variants of the scheme that set Q as a product of coprime moduli [33]. In these implementations, precision is limited to the size of these primes for maximum accuracy and efficiency. This can limit the choices of the user in setting the computational precision. Table 1 gives a brief summary of what we have reviewed above and the gap we are trying to fill. Structure of the paper. In Section 2, we introduce definitions, cryptographic tools, and key building blocks for our construction along with a precise description of the system model and security goal. Section 3 provides a brief review of CFs. We then describe our proposed secure comparison algorithms in Section 4. Useful applications and results of our solutions are discussed in Section 5. Finally, Section 6 concludes the work.

Definitions and Cryptographic Tools
We begin by introducing some notation and terminology that will be used in the remainder of the paper. We denote that x is encrypted by writingx. To distinguish integers and real numbers, a small letter indicates an integer (e.g., x), whereas a capital letter indicates a real number (e.g., X). Since real numbers are replaced with approximate point numbers in computing, the term "point numbers" is used throughout the paper. We refer to α ← A(a, b) as an algorithm that takes two inputs a and b and outputs α. The base-2 logarithm is denoted as log.

System Model
We precisely describe the system model on which our possible applications are designed. There are two entities in the system model, i.e., the user and server, and each entity is a protocol participant. A user holding data wishes to store her data on a cloud that is controlled by the server. We focus on the case in which the data are numerical, specifically real numbers, and are meant to be protected from the server.
Our primary goal is to privately compare real numbers with full delegation of the computation to the server. Therefore, when a user submits a request for comparison as a service, she needs to provide a specification of the comparison to the server. The server is then expected to run a set of algorithms to perform the designated computation without interacting with the user. After completing the computation, the server returns an encrypted result to the user. Because the user has a pair of encryption and decryption keys, she can decrypt the results. We assume that the user is honest; however, the server does not need to be honest. A semi-honest server can be assumed. For high privacy, one may require security in the presence of a malicious server. However, due to our performance requirement for a reasonable response time, we only consider a semi-honest server.

Fully Homomorphic Encryption
An FHE scheme, denoted by FHE = (Kg, En, De, Ev), is a quadruple of probabilistic polynomial-time (PPT) algorithms, as follows: Key generation. This algorithm takes the security parameter λ and outputs a public encryption key pk, a public evaluation key ek, and a secret decryption key sk. We write the algorithm as (pk, ek, sk) ← Kg(1 λ ) and assume that the public key specifies the plaintext space P and the ciphertext space C. Encryption. The algorithmx ← En pk (x) takes the public key pk and a message x ∈ P and outputs a ciphertextx ∈ C. Decryption. The algorithm x * ← De sk (x) takes the secret key sk and a ciphertext c and outputs a message x * ∈ P. Homomorphic evaluation. This algorithm takes the evaluation key ek, a function f : ({0, 1} * ) n → {0, 1} * , and a set of n ciphertextsx 1 , . . . ,x n , and outputs a ciphertextx f , denoted byx f ← Ev ek ( f ,x 1 , . . . ,x n ).
Since Gentry's first secure FHE scheme was introduced in [35], lots of studies (e.g., [36][37][38]) have focused on constructing efficient FHE schemes. To tackle their poor performance, Brakerski and Vaikuntanathan [39] newly introduced the notion of leveled FHE, which allows one to evaluate functions of at most a prefixed multiplicative depth rather than arbitrary functions. For a while, Brakerski, Gentry, and Vaikuntanathan [40] developed a leveled FHE scheme over polynomial rings so that their scheme significantly improved performance over the previous schemes. More recently, Cheon et al. suggested a new FHE scheme [31] that supports an approximate computation over ciphertexts. Therefore, there are good solutions for instantiating leveled FHE (e.g., [40,41]). Unless otherwise stated explicitly, hereafter, FHE refers to leveled FHE.
Formally, an FHE scheme is semantically secure if it achieves indistinguishability against chosen-plaintext attackers. We follow a standard definition of semantic security given in [42].

Definition 1 (Semantic Security). An FHE scheme is semantically secure if for any polynomial-time adversary
is negligible in the security parameter λ, where (pk, ek, sk) ← Kg(1 λ ) and m 0 , m 1 ∈ P are chosen by the adversary A.

Security Model
For two given point numbers X 0 and X 1 , the functionality that our protocol realizes, outputs the larger number X b such that X b ≥ X 1−b for b ∈ {0, 1}. To show that our protocol is a secure instantiation of this functionality, we consider a simple form of the standard definition of security in the static, semi-honest model proposed by Goldreich [43]. Generally, all players in the semi-honest model are assumed to follow the instructions prescribed in the protocol. Thus, security in our setting is more straightforward, since we only need to consider the case where the server acts semi-honestly. In other words, no PPT server obtains information about the user's private inputs other than what can be deduced from the result of the protocol. We argue for the protocol's security in the semi-honest model by comparing an ideal-world model, in which a trusted third party (TTP) receives the inputs of the user and outputs the result of the protocol, to a real-world model of the protocol without a TTP.
We use F op to denote the real-number comparison functionality and use π op to denote a comparison protocol over real numbers, where the comparison operator op ∈ {>, <, =}. Let x and y be the inputs from the user and server, respectively. We define the user's view of the protocol as (x, r c , m c 1 , . . . , m c k ) and the server's view as (y, r s , m s 1 , . . . , m s k ), where r c and r s are the user's and server's respective internal coin tosses and m c i and m s i are the user's and server's respective i-th messages during the execution of the protocol. For compatibility with existing notation, we will write the server's view as view(x, y).

Definition 2.
Protocol π op is a secure comparison protocol for a comparison operator op ∈ {>, <, =} in the presence of a semi-honest server if a PPT simulator S exists such that where c ≡ denotes computational indistinguishability by any polynomial-time algorithm.
Note that in our setting, it is not necessary for a server to provide a private input, and thus, y does not have a value.

Homomorphic Comparison of Integers
As mentioned previously, our solution can be built on top of the homomorphic comparison of two FHE-encrypted integers. Hence, the goal of this subsection is to review homomorphic comparison algorithms of encrypted integers. Recall thatx denotes an encryption of an integer x.
For simplicity, we follow the convention used in [44] for constructing an integer-valued comparison whose native plaintext space is Z 2 . However, it is straightforward to extend this convention to a larger plaintext space such as Z 2 t for a moderately-sized integer t (e.g., 64) while preserving the same multiplicative depths as those of [44] (see [45,46] for the detailed theories).

Equality
The homomorphic equality algorithm for two integers x and y outputs1 if x = y; otherwise, it outputs0. To compare two integers, bits at the same position are considered. Adding two bits to 1 allows the coincidence of two bits to be checked, since for a, b ∈ Z 2 , a + b + 1 outputs 1 in Z 2 if a = b; otherwise, it outputs 0 in Z 2 . Using this equation, we define an equality test over the integers, denoted by EQ Z , as follows: forx =x n−1 · · ·x 0 andȳ =ȳ n−1 · · ·ȳ 0 , where x i , y i ∈ Z 2 , It is clear that the circuit requires log n multiplicative depths.

Greater-Than and Less-Than
We have two types of inequality test circuits: less-than and greater-than algorithms. The less-than algorithm compares two integers and outputs1 if x < y and0 if x > y. Similarly, the greater-than algorithm compares two integers and outputs1 if x > y and0 if x < y. Indeed, the principle of these two algorithms is the same; hence, the greater-than algorithm can easily be obtained from the less-than circuit by adding 1 to the output, and vice versa. If an integer x = x n−1 · · · x 0 is less than (resp., greater than) an integer y = y n−1 · · · y 0 , then there exists i ∈ {0, 1, . . . , n − 1} such that and outputs 0 otherwise, we define the less-than circuit, denoted by LT Z (resp., greater-than circuit, denoted by GT Z ) over the integers: and We note that a naive implementation of these circuits incurs O(n 2 ) homomorphic multiplications; however, by rewriting each expression in closed form and applying the single-instruction, multiple-data (SIMD) technique [47,48] to the rewritten expressions, we can have these circuits incur 2(n − 1) multiplications so that they have a multiplicative depth of only (1 + log n) (see [44]).

Rationale of CF Encoding
The goal of this section is to explain why writing numbers in CF form enables us to design depth-efficient homomorphic comparisons such that users can control the precision accuracy independently. For this purpose, we briefly review the basic facts about CFs and their properties. Thus, readers who are familiar with this topic may move on to the next section.

Definitions
There are some methods that represent point numbers as integers (e.g., decimal expansion and CFs). However, there are reasons why CFs are a more mathematically natural representation than other representations of point numbers. First, the CF representation for a rational number is finite, but the decimal representation for the same number may be infinite. Moreover, every rational number has a unique CF representation, under some restrictions. The successive approximations generated in finding the CF representation of a number by truncating the CF representation are in a certain sense (described below) the best possible option for representing the number. Therefore, the CF representation has been considered to be a great tool in mathematics; however, here we only discuss topics related to our work.
A CF can be obtained by running an iterative process of expressing a number as the sum of its integer part and the reciprocal of the remaining part, and then writing the remaining part as the sum of its integer part and remaining part, and so on. Namely, given a number X ∈ R and r i > 1, for all i, we have and we use X = [x 0 ; x 1 , x 2 , . . .] to denote this. It is clear that x 0 can be any integer, but some definitions and theorems [49] are needed to show that for i ∈ N, x i is positive, and that with this restriction, the CF of X is unique.
• x i is called a partial quotient of X for each i.

•
A CF X is finite if the number of partial quotients of some X is finite.
All the partial quotients are closely related to each other in the sense that each partial quotient can be written in the previous quotient. Moreover, when a rational number is represented as a CF, its denominator and numerator can be seen as a multivariate polynomial in terms of the partial quotients.

Definition 4 (Convergent)
. Let X = [a 0 ; a 1 , . . . , a n−1 ], where X ∈ Q and a i ∈ Z. The convergents of X are defined as where C i represents a rational number; it is denoted by C i = p i /q i , where p i /q i is in reduced form.

Some Properties
We begin by confirming that every rational number has a unique, finite, simple CF representation. Theorem 1 implies that the correspondence between rational numbers and finite CFs [x 0 ; x 1 , . . . , x n ] with an integer x 0 and positive integer x i for i > 0 and x n > 1 is one-to-one. Theorem 1 ([49]). Any rational number can be represented as a finite CF, and the CF representation is unique when the last partial quotient is larger than 1.
Next, we argue that a CF is the best tool for approximating real numbers as point numbers. Indeed, Theorem 2 indicates that p i /q i is the best possible approximation of X among all rational numbers while having the same or smaller denominator.  .
We now show that each partial quotient is much smaller than the denominator and numerator. Because any real number can be approximated as a rational number, and by Theorem 1, any rational number can be written as a finite CF, we only consider finite CFs henceforth. Nevertheless, we can consider infinite CFs simply as X = lim i→∞ C i , where X ∈ R.
Using the property of convergents, we claim that the size of a partial quotient is much smaller in bit length than those of the denominator and numerator. Theorem 3. Let X = [x 0 ; x 1 , . . . , x n−1 ] be a CF of p/q, where X ∈ Q and x i , p, q ∈ Z. Then, and log x 0 + log x 1 + · · · + log x n−1 < log q.
Proof. Let X = [x 0 ; x 1 , . . . , x n−1 ], where X ∈ Q, x i ∈ Z, and its convergents C i = [x 0 ; x 1 , . . . , x i ] = p i /q i . By mathematical induction on i, we can easily show that the numbers p i and q i can be obtained by the recurrence with initial conditions p 0 = x 0 , p −1 = 1, q 0 = 1, and q −1 = 0. We can rewrite Equations (3) and (4) with a matrix as follows: Therefore, all i, p i , and q i contain x 0 x 1 · · · x i , and there is no negative term, which implies that Taking the logarithm with base 2 for both inequalities completes the proof.

Homomorphic Comparison between FHE-Encrypted Point Numbers
For a better understanding, we first present comparison algorithms of two CFs in the clear, and then we describe our homomorphic comparison algorithms over their FHE encryptions. Our constructions rely on the integer-valued comparisons discussed in Section 2.4.

Comparisons of Two CF-Encoded Point Numbers in the Clear
Consider representation in terms of decimal expansion. One of its greatest advantages is that it makes it easy to compare two point numbers. However, even for a low precision accuracy, a relatively large plaintext space should be configured, so large parameters will be bound to the underlying FHE scheme. This might, in turn, cause the inherent noise to grow very rapidly in homomorphic multiplications. For example, consider a point number r with precision 6; i.e., r = n 0 .n 1 · · · n 6 . In decimal form, an appropriate plaintext space should be larger than 20 bits simply because r is represented as (n 0 .n 1 · · · n 6 ) · 10 6 and 10 6 ≈ 2 20 . Furthermore, users cannot control the precision of their data after completing the underlying FHE scheme. As observed in Section 3, introducing CF encoding helps us address these problems.
For simplicity, we write two CF representations as X = [x 0 ; x 1 , . . . , x n−1 ] and Y = [y 0 ; y 1 , . . . , y m−1 ], where n, m refer to the numbers of partial quotients in each CF representation. To demonstrate our idea effectively, we show a sequence of examples and then prove Theorem 4, on which we base the comparison algorithm between CF-encoded point numbers. Depending on n and m, we have two cases; we discuss each case in turn.

When n = m
We divide this case into three subcases in which the partial quotients at specific positions are different from each other.
From the definition of a CF (see Equation (2)), we find that the partial quotients x 0 and y 0 dominate all other partial quotients x i and y i for i > 0. Therefore, X is greater than (resp., less than) Y if x 0 is greater than (resp., less than) y 0 . Case 2. If x 0 = y 0 and x 1 ≥ y 1 , then X ≤ Y.
Suppose that x 0 = y 0 . Then, X and Y from Equation (2) can be written as follows: We then rewrite these as 1 X−x 0 = [x 1 ; x 2 , . . . , x n−1 ] and 1 Y−y 0 = [y 1 ; y 2 , . . . , y n−1 ]. We can see that the result of the comparison between 1 X−x 0 and 1 Y−y 0 fully depends on x 1 and y 1 . The only difference from Case 1 is that if x 1 is greater than (resp., less than) y 1 , then X is less than (resp., greater than) Y, Case 3. If x 0 = y 0 , x 1 = y 1 , and x 2 ≥ y 2 , then X ≥ Y.
We can continue this process to an arbitrary n(= m), but it is not difficult to infer a relationship between the sizes of the point numbers and the indices of their partial quotients.

When n = m
This case is much simpler than the case above, because the comparison result is totally determined by n and m. Without loss of generality, we assume that n < m. For i ∈ {0, 1, . . . , n − 1}, it is trivial to compare two CFs by applying the same rule as above. However, it is unclear how to compare two CFs, because x i = y i for all i ∈ {0, 1, . . . , n − 1}, but there is no partial quotient of X corresponding to y i for some i ≥ n. To tackle this problem, we make two point numbers in CF form have the same number of partial quotients using the simple trick below.
Our key idea is that because 0 = 1 ∞ , adding ∞ to the end of partial quotients on the X side has no side effects. Specifically, since 1 Consequently, we can always write two point numbers as two CFs with the same numbers of partial quotients. Thus, it is possible to compare two real numbers in terms of CFs when they have different numbers of partial quotients. Our argument can be formally stated by Theorem 4. Because the proof of the theorem is clear by mathematical induction on k, we omit the details of the proof.
and X > Y otherwise. If there is no k that implies that x i = y i for all i < n and n < m, then X < Y if n is odd and X > Y if n is even. If there is no such k and n = m, then clearly X = Y.
This section ends with Algorithm 1, which provides a concrete algorithm for comparing two CFs in the clear.

Algorithm 1 Comparing two continued fractions in the clear
Input. X = [x 0 ; x 1 , . . . , x n−1 ] and Y = [y 0 ; y 1 , . . . , y m−1 ] Output. The result of the comparison of X and Y 1: Find k such that k is the smallest index for which x k = y k 2: if ∃k then 3: if c < 0 then 5: return X < Y 6: else 7: return X > Y 8: else 9: if n = m then 10: return X = Y 11: else if n < m then 12: if n is odd then 13: return X < Y 14: else n is even 15: return X > Y 16: else 17: if m is odd then 18: return X < Y 19: else m is even 20: return X > Y

Our Homomorphic Comparisons over FHE Encryptions
We are ready to provide our depth-efficient homomorphic comparison algorithms over FHE encryptions. To this end, we revise Algorithm 1 so that it operates correctly on FHE ciphertexts, whose original numbers have been written in CF form. We note that an FHE scheme with a larger plaintext space than Z 2 can be set up without additional costs in terms of multiplicative depth.

Equality Tests
We define an equality circuit, denoted by EQ R , which takes as input two encrypted CFs, as follows: The correctness of the algorithm is formally proven by Lemma 1.

Lemma 1.
LetX andȲ be encrypted CFs for real numbers X and Y, respectively. The equality circuit EQ R in Equation (5) correctly computes an encryption of the equality test result between the two encrypted real numbers as CFs.
Proof. LetX = [x 0 ;x 1 , . . . ,x n−1 ] andȲ = [ȳ 0 ;ȳ 1 , . . . ,ȳ m−1 ] be two encrypted CFs. Only if n = m and x i = y i for all 0 ≤ i ≤ n − 1 are the two CFs equal. We can easily check the first condition by the number of their ciphertexts, and the second condition by comparing two encrypted partial quotients at the same position; i.e., by invoking then all outputs of EQ Z are1 so that the product of all of these outputs is1. However, if there is at least one pair of different partial quotients, then because the output of the corresponding EQ Z is0, the product of the outputs is0.
We then construct a comparison protocol, denoted by Π = , by extending the equality algorithm. The protocol Π = consists of the following two rounds: • (The first round.) A user sends two FHE encryptions (X,Ȳ) to a server. • (The second round.) The server responds to the user by sending the result of homomorphically evaluating EQ R at the two FHE encryptionsX andȲ.

Greater-Than and Less-Than Tests
Using integer-based circuits, we define two comparison circuits, denoted by GT R and LT R , taking as input two encrypted CFs, as follows: Lemma 2. LetX andȲ be encrypted CFs for real numbers X and Y, respectively. The comparison circuit GT R (resp., LT R ) correctly computes an encryption of the greater-than (resp., less-than) comparison result between two encrypted real numbers in CF form.
Proof. Let x, Y ∈ R, and letX andȲ be their respective encrypted CFs. The comparison test between CFs proceeds in a left-to-right direction, like comparing two integers. For two integers given in binary, when the first difference occurs at an index i in their binary expansions, the integer of the i-th bit of being 1 is greater than the other integer. Additionally, as proven in Theorem 4, when the first difference occurs at the index i in the two CF expansions, the comparison between the two CFs needs to consider the index i itself along with the i-th partial quotients. Specifically, if the index i is odd, then the direction of the inequality of the two i-th partial quotients is the same as the direction of the inequality of the two real numbers; but if the index i is even, then the direction of the inequality of the two i-th partial quotients is the opposite of that of the two real numbers.
On the other hand, we need to carefully deal with the case that n = m, when comparing the two encrypted CFs. As many dummy partial quotients ∞ as the difference between n and m are added, such that both CFs have the same number of partial quotients. For efficiency reasons, we do not encrypt the dummy partial quotients. Instead we just have to check if the index at which the first partial quotient appears is even or odd, as ∞ is larger than any integer.
Similarly, we can design a comparison protocol for the greater-than (resp., less-than) test, denoted by Π > (resp., Π < ), as follows: • A user sends two FHE encryptions (X,Ȳ) to a server.

•
The server responds to the user by sending the result of homomorphically evaluating GT R (reps. LT R ) for the two FHE encryptionsX andȲ.

Efficiency
We evaluate the performance of the algorithms by finding the multiplicative depth. Note that for two -bit integers, the best-known equality test algorithm has a multiplicative depth of log and the best-known comparison test algorithm has a multiplicative depth of log + 1.
Given a real number X, we write it as X = [x 0 ; x 1 , . . . , x n−1 ] in CF form but as X = x · 10 k in decimal form with precision k. Graepel et al. take a systematic approach to encoding real numbers as elements of polynomial rings [50]. However, in essence, their approach is the same as decimal representation, because the polynomial of a real number X with precision k has a degree of log x · 10 k . As studied in [9], our algorithms use a plaintext space of κ = /n bits on average, where we set to = log X = log x · 10 k . However, as a trade-off, it seems that the number of ciphertexts must be equal to the number of partial quotients; i.e., there are n ciphertexts for κ-bit messages. Fortunately, we can fix this problem by using FHE schemes (e.g., [31,40]) that support ciphertext packing [47,48]. The ciphertext packing technique allows us to evaluate a function homomorphically, in parallel, on n blocks of encrypted data. Essentially, it works by packing multiple plaintexts into one ciphertext. More specifically, when we use a variety of parameters with a fixed plaintext space p = 2, key-switching digit parameter c = 3 and cyclotomic polynomial Φ 19811 (z), yielding a plaintext space of 50 , we are able to pack 360 48-bit partial quotients into one FHE ciphertext.
Note that packing allows SIMD-like computation on the vectors of encrypted data simultaneously without additional cost. Multiplying each result of the comparison between encrypted partial quotients requires that the equality test should have a multiplicative depth of log n . Similarly, the comparison test icurs an additional 2 log n homomorphic multiplications and log n homomorphic additions. Table 2 reports on measurements with respect to the plaintext space, the number of ciphertexts, and the multiplicative depth. Table 2. Summary of efficiency.

Algorithms
Measures Values # of Ciphertexts n Multiplicative depth log κ + log n + 2 Remark 1. In this work, we do not consider arithmetic on encrypted point numbers. However, a beneficial aspect of homomorphic encryption compared to other cryptosystems is that anyone can add and multiply the underlying messages that are being encrypted. Because homomorphic evaluation results can also be represented as CFs of small terms, our argument holds for arithmetic operations on encrypted real numbers. Additionally, for decimal or polynomial representation cases, their evaluation results should not overflow beyond the underlying message space. Therefore, an FHE scheme is not easy to set up, even for a small number of homomorphic multiplications.

Experimental setup.
Our experiments use a variant of the BGV FHE scheme [40] to implement the equality and comparison circuits on real numbers. A complete C++ implementation of the underlying FHE scheme is provided by Halevi and Shoup based on the number theoretic library NTL [51] (version 10.3.0), named HElib [52]. We also utilize Open Multi-Processing (OpenMP) [53] to take advantage of available processing cores to run code concurrently and efficiently. While HElib supports bootstrapping, we use a leveled variant of the BGV-type scheme that supports homomorphic evaluations up to a predefined level.

Microbechmarks.
In the following, we demonstrates simple experiments for comparing the run times in the same setting. For this purpose, we select several random CFs by varying the number of partial quotients and express these numbers in decimal form with various degrees of precision. Then, we encrypt each encoding to generate two ciphertexts for these numbers. During setting up an instance of the FHE scheme, we chose the minimum FHE parameters that may guarantee correct evaluations. In Table 3, we compare the average run times with each encoding with various degrees of precision.

Security
The underlying FHE scheme we use is semantically secure; that is, no polynomial-time servers can distinguish betweenm 0 andm 1 for arbitrary messages m 0 , m 1 ∈ P. Because all comparisons are performed by the server without decryption, it is obvious that no semi-honest server can learn any information about the encrypted numbers. For completeness, we begin by arguing for the correctness of our protocols. The completeness property is trivial from Lemmas 1 and 2.
Theorem 5 (Correctness). LetX andȲ be encrypted CFs for real numbers X and Y, respectively. The comparison protocols Π op correctly compute an encryption of the comparison result between the two encrypted point numbers in CF form, where op ∈ {>, <, =}.
Next, we will check whether our protocol securely performs real-number comparison. Theorem 6. Assume that the FHE scheme used in the comparison protocols is semantically secure. Then, in our comparison protocols Π op of point numbers, a polynomial-time semi-honest server can learn nothing about the information other than what could be revealed in the ideal model using the same private inputs with a TTP.
Proof. Because of the semantic security of the underlying FHE scheme, no PPT semi-honest servers can distinguishm 0 andm 1 for two same-length plaintexts m 0 , m 1 . Thus, nothing is revealed to the server before decryption by the user, since all user inputs are encrypted by the FHE scheme but the server has no input. Note that a description of the comparison circuit is known to the server before running the comparison protocol.
Specifically, for two inputsX andȲ, all partial quotientsx i andȳ i are encrypted by the semantically secure FHE scheme and provided to the server. Thus, the server cannot learn information aboutX andȲ except for the numbers of partial quotients (i.e., n and m). However, these numbers should also be known to an ideal adversary when the decimal precision for representing point numbers is fixed. Furthermore, while computing the intermediate values, the server evaluates the comparison circuit using only encrypted summands and learns nothing about the final result of the circuit. Consequently, no information of the honest user concerning X and Y is revealed to the semi-honest server other than the decimal precision, as implied by the encrypted comparison result of the protocol at the end of execution.
There are a variety of privacy-enhanced applications that can employ our FHE-based point number comparison solution. We present two such useful applications: sorting a list of FHE-encrypted point numbers and processing retrieval queries on FHE-encrypted databases.

Sorting on Encrypted Databases
Sorting is one of the most fundamental operations undertaken in computers, and it has been studied for a long time. Furthermore, with the advent of cloud services and cloud computing, sorting on encrypted databases has also been getting a lot of attention. Order-preserving encryption [54] and order-revealing encryption [55][56][57] are two appealing solutions for sorting encrypted data for efficiency on the server side. However, these encryption schemes can leak information on the relative distance between the underlying messages. In particular, they can leak more information in specific settings; for example, a set of non-uniform data [58].
On the other hand, because FHE schemes leak no information about the underlying messages, FHE-based sorting does not leak any information to a semi-honest server beyond that revealed by its output (e.g., the size of the list). Several solutions have been suggested for sorting FHE-encrypted lists (see, e.g., [15,16]). However, to the best of our knowledge, there have been known no solutions working for a list of point numbers.
The construction. Two fundamental operations of classical sorting algorithms are comparisons and swaps. Thus, the main goal of our construction is to use our comparison algorithms GT R and LT R to construct a swapping algorithm for two encrypted values. A swap operation takes a sequence of point numbers and outputs an ordered sequence. Without loss of generality, we consider only ascending order, but descending order can be easily obtained with small changes. For two encrypted point numbersX andȲ, swapping in ascending order is defined as where by [X,Ȳ] we mean thatX andȲ are stored in order.
Efficiency. We focus on Gizem et al.'s two sorting algorithms, called direct sort and greedy sort [16]. The reason for considering the scheme is that different from existing algorithms with O(N log 2 N) multiplicative depth, their scheme incurs merely O(log N + log ) multiplicative depth for the size of the input list N and the bit size of the elements . More specifically, to sort N values, a 0 , . . . , a N−1 , the protocol first builds an N × N matrix whose components (i, j) are GT Z (a i , a j ) for i, j ∈ {0, 1, N − 1}. Because the sum of the i-th row of the matrix means the number of elements greater than a i , it can sort all values according to this sum. Moreover, combining their algorithms with merge sort can provide better performance.
We can apply their technique to our scenario using the comparison algorithms for point numbers. Specifically, we construct a comparison matrix whose components (i, j) are GT R (a i , a j ) for 0 ≤ i, j < N rather than GT Z (a i , a j ), and we can sort an encrypted list of point numbers with the same multiplicative depth.

Database Queries on Encrypted Databases
Informally, by a retrieval database query or database query for short we mean the process of retrieving the data that satisfy a set of predicates from a database. Database queries are one of the the most important and basic operations that make databases useful. However, if users' data are sensitive (e.g., medical or financial information), part (occasionally all) of the database involving these sensitive attributes should be protected from unauthorized access. For this reason, lots of studies have paid great attention to providing privacy-preserving query services for outsourced data, called private database queries (PDQs).
PDQ solutions enable users to learn desired information from encrypted databases without revealing information to the server. Searchable encryption [59] can be used to retrieve information as a result of queries; however, it can leak information about plaintext messages. In particular, it does not allow the evaluation of encrypted functions.
In this work, we take into account two simple types of PDQs, called retrieval queries and aggregate queries. For example, consider two queries over a medical database: • What are the names of all patients whose preprandial plasma glucose levels were above 11.3450098875 mmol/L? • What is the average age of female patients whose postprandial plasma glucose is below 13.10134111097 mmol/L?
To respond to these queries, database systems have to identify tuples satisfying a given search condition and sometimes perform computations on the set of results. Because of this need, FHE-based PDQ protocols (e.g., [60,61]) have been developed to support various queries.
Search queries. Search queries (a.k.a., retrieval queries) consist of a list of attributes, their owner table names, and a search condition. One way to offer reasonable performance is to encrypt only the private constant values in the search condition statement. Then, on receiving such a such query, the cloud database server can identify which attributes in a given table are compared to the encryptions of constants. In principle, search queries can be grouped into conjunctive queries and disjunctive queries. Conjunctive queries require that all predicates in a search condition should be satisfied, whereas disjunctive queries require that at least one predicate in a search condition only have to be satisfied.
Suppose that a database R has a schema R(A 1 , A 2 , . . . , A τ ), where R is a relation name and each A i is an attribute name, and that it has N encrypted tuples. Note that all tuples in the relation do not need to be encrypted; for performance reasons, some of sensitive attribute values have to be encrypted. For simplicity, we use Cmp(A i [j],X i ) to denote the i-th predicate to compare an encrypted constantX i to an encrypted attribute valueȲ i,j of the attribute A i in the j-th tuple where j ∈ {1, 2, . . . , N}. Recall that the comparison predicate Cmp performs one of comparison operations in {<, =, >}. Then, we can describe search queries over the encrypted database R as Conj(X i 1 , . . . ,X i η )[j] := Cmp(A i 1 [j],X i 1 ) ∧ · · · ∧ Cmp(A i η [j],X i η ) and Disj(X i 1 , . . . ,X i η )[j] := Cmp(A i 1 [j],X i 1 ) ∨ · · · ∨ Cmp(A i η [j],X i η ).
If A k is a target attribute, at the end of the protocol the server produces as a resulting set {Ȳ k,j · Conj(X i 1 , . . . ,X i η )[j]} 1≤j≤N . In the same way, we can figure out the output of disjunctive queries.
Aggregate queries. Aggregate functions return a single resulting value based on a group of data that is formed by applying search queries; Examples include sum, avg, and count. For the purpose of arithmetic with CFs, we can use Gosper's arithmetic algorithm in [62] between CFs. The algorithm allows arithmetic operations to be performed not only between two CFs but also between a CF and a rational number. More concretely, the algorithm receives two numbers X, Y ∈ R in CF form and outputs F(X, Y) := (α + βX + cY + δXY)/( + f X + ζY + ηXY), where α, β, c, δ, , f , ζ, η ∈ Z. For example, setting β = 1, c = −1, = 1 indicates F(X, Y) = X − Y, setting δ = −1, = 1 indicates F(X, Y) = −X · Y, and setting α = 2, β = 1, ζ = 3 indicates F(X, Y) = (2 + X)/3Y. This implies that F(X, Y) can express every primitive arithmetic operation, Therefore, we can evaluate every primitive arithmetic operation along with a two-variable linear fractional transformation.
In [9], the authors first investigate the possibility of employing FHE with the Gosper algorithm to allow anyone to evaluate two encrypted CFs. In principle, with the Gosper algorithm, we can evaluate arbitrary polynomials utilizing the same approach as discussed above. However, because this approach becomes fairly impractical when the polynomial has the degree of greater than 2, the algorithm is not suitable for aggregate queries for performance reasons. More specifically, in the Gosper algorithm, the process of expressing rational numbers Z = F(X, Y) using the partial quotients of X and Y requires quite high computational costs. Indeed, each reconstruct of the numerator and denominator for each partial quotient requires on homomorphic multiplication. For this reason, separately stroing both numerators and denominators with their CFs enables to reduce the computational overhead. Then, executing arithmetic operations with numerators and denominators becomes much more efficient than directly applying the Gosper algorithm, as this can significantly relieve the cost of reconstructing rational numbers.

Summary of Results
In this work, we addressed the goal of allowing users to manipulate the computational precision of encrypted numerical data, namely, point numbers, that are to be stored at a remote server. In most existing schemes, the precision must be configured when setting up the underlying FHE scheme, so users have no control over the precision accuracy of the FHE-encrypted point numbers.
To solve this problem, we encoded point numbers as continued fractions and suggested a set of efficient homomorphic comparison algorithms over their FHE encryptions. We then showed that depth-efficient homomorphic comparison algorithms can be obtained by only using efficient homomorphic comparisons over FHE-encrypted integers. In particular, we argued that our comparison algorithms require only logarithmic multiplicative depth. Our technique may incur the costs of the overhead to store every partial quotient of the point numbers; however, using an FHE scheme that allows for the SIMD technique, we can reduce this overhead. Thus, our solutions have a wide range of applications in cloud-based tasks.