Hybrid Position-Residues Number System Karim Bigou, Arnaud Tisserand
Total Page:16
File Type:pdf, Size:1020Kb
Hybrid Position-Residues Number System Karim Bigou, Arnaud Tisserand To cite this version: Karim Bigou, Arnaud Tisserand. Hybrid Position-Residues Number System. ARITH: 23rd Sympo- sium on Computer Arithmetic, Jul 2016, Santa Clara, CA, United States. hal-01314232 HAL Id: hal-01314232 https://hal.inria.fr/hal-01314232 Submitted on 18 Jul 2016 HAL is a multi-disciplinary open access L’archive ouverte pluridisciplinaire HAL, est archive for the deposit and dissemination of sci- destinée au dépôt et à la diffusion de documents entific research documents, whether they are pub- scientifiques de niveau recherche, publiés ou non, lished or not. The documents may come from émanant des établissements d’enseignement et de teaching and research institutions in France or recherche français ou étrangers, des laboratoires abroad, or from public or private research centers. publics ou privés. Copyright Hybrid Position-Residues Number System Karim Bigou 3;1 and Arnaud Tisserand 2;1 1IRISA, 2CNRS, 3University Rennes 1, INRIA Centre Rennes - Bretagne Atlantique 6 rue Kerampont, CS 80518, 22305 Lannion cedex, FRANCE f karim.bigou ; arnaud.tisserand [email protected] Abstract—We propose an hybrid representation of large in- cryptography are presented in Sections V and VI respectively. tegers, or prime field elements, combining both positional and Finally, Section VII concludes the paper. residue number systems (RNS). Our hybrid position-residues (HPR) number system mixes a high-radix positional represen- II. NOTATIONS AND DEFINITIONS tation and digits represented in RNS. RNS offers an important source of parallelism for addition, subtraction and multiplication The definitions and notations used in the paper are: operations. But, due to its non-positional property, it makes • Capital letters, e.g. X, denote large integers or field comparisons and modular reductions more costly than in a positional number system. HPR offers various trade-offs between elements of ` bits (in our applications ` > 100) internal parallelism and the efficiency of operations requiring po- • jXjP is X mod P sition information. Our current application domain is asymmetric • B = (m1; : : : ; mn) is an RNS base composed of n cryptography where HPR significantly reduces the cost of some moduli where all mi are pairwise co-primes of w bits modular operations compared to state-of-the-art RNS solutions. • hXi represents X in the RNS base B and defined by: Index Terms—number representation; large integer; finite field; modular arithmetic; residue number system. hXi = (x1; : : : ; xn) where xi = jXjmi (1) Qn M • M = i=1 mi and Mi = m I. INTRODUCTION i • EMM a w-bit elementary modular multiplication jxi ·yijmi In computer arithmetic, representations of numbers strongly used as complexity unit for cost analysis as in all works impact algorithms and implementations performances for basic of the literature operations. Redundant number systems (see for instance [1]) • n = d`=we, i.e. the minimal number of moduli to allow limited carry propagations during additions, and then represent an `-bit value fully parallel addition. Logarithmic number system (LNS, • the word “base” is used in the RNS context see for instance [2]) swaps the cost of addition/subtraction • the word “radix” is used in the positional context by the cost of multiplication/division, but it still leads to • LSD/MSD denote least/most significant digit a large cost difference between these two operations cate- We will use two or three small RNS bases denoted gories. Furthermore LNS is difficult to use in asymmetric Ba; Bb; etc. In Ba, composed of na < n moduli (w-bit cryptography applications with large numbers. Residue num- integers), X is represented by hXia. Same notations apply ber system internal (RNS, see for instance [3], [4]) allows for the other bases. The base concatenation is denoted Bajb parallelism for both addition/subtraction and multiplication. and hXiajb is the RNS representation of X using na + nb Then RNS is commonly used in asymmetric cryptography moduli. (see for instance [5], [6], [7], [8], [9], [10]). But RNS is a non-positional representation with reduced efficiency for III. STATE-OF-THE-ART comparisons, modular reductions and modular multiplications. A. Residue Number System (RNS) We propose a new number system, denoted hybrid position- residues (HPR) number system for large integers and prime The RNS representation, proposed in the late 50s in [3], [4], is increasingly used for large modular arithmetic compu- field elements (Fp). HPR “mixes” a high-radix positional representation of numbers and RNS digits. It can be seen tations and asymmetric cryptography implementations, see for as a sort of compromise between a positional representation instance [11], [12], [13], [9], [14], [10], [8]. and RNS. Our hybrid number system offers a good level of The integers X and Y are represented in the RNS base B by internal parallelism for addition, subtraction and multiplication hXi and hY i. Multiplications, additions and subtractions are operations (even if it is slightly reduced compared to standard very efficient and natural in RNS. If one wants to perform the RNS). But it also allows much more efficient comparisons, operation in RNS, with 2 f+; −; ×}, one just computes modular reductions and modular multiplications due to the in parallel over the moduli: available position information in the representation. hXi hY i = jx1 y1jm ;:::; jxn ynjm : (2) After the presentation of notations and definitions in Sec- 1 n tion II, Section III briefly presents the state-of-the-art. Our Computations are performed independently on each modulo HPR number system is detailed in Section IV. Applications mi without carry propagation. RNS multiplication requires n to modular multiplication and exponentiation for asymmetric independent EMMs. Moreover, if Z is an integer coprime with all mi, then exact division by Z is computed by multiplying Using the optimization from [10], the RNS-MR total cost is −1 −1 −1 2 by hZ i = jZ jm1 ;:::; jZ jmn . 2 na nb + na + nb = 2 n + 2 n EMMs. We assume 0 6 X < M to be able to convert back using In RNS, the modular multiplication (RNS-MM) is com- the CRT (Chinese remainder theorem) formula: posed of a simple RNS multiplication, on both bases, followed 2 n by a RNS-MR and costs 2 n + 4 n EMMs. X −1 X = jXjM = xi · M × Mi : i mi D. Close and Related Representations i=1 M The mixed-radix system (MRS [4]) uses, as RNS, a base of An important consequence of the CRT is that each RNS moduli to represent integers but is a positional representation operation performed in base B is automatically reduced mod- with very limited internal parallelism compared to RNS. ulo M. As described in Sec. III-C, it is used to compute The polynomial RNS (PRNS [20]) uses small polynomials modular reduction in state-of-the-art. for the moduli instead of integers, and as RNS is a non- However, RNS is a non-positional representation: com- positional representation. parisons, general divisions and modular reductions are much In the standard radix-2 positional representation, the use of harder than multiplications in RNS (for instance see [15]). Mersenne and pseudo-Mersenne primes significantly reduces B. RNS Base Extension the cost of modular reductions. The representation proposed In order to compute more complex operations like RNS in [21] generalizes the idea of pseudo-Mersenne primes for modular reduction, the base extension (BE) has been pro- any radix but not in the RNS context. Recently, [13] proposes an equivalent to pseudo-Mersenne primes in RNS where the posed in [15]. BE converts hXia into hXib, avoiding costly conversions to the classical representation. In this paper, we RNS-MR cost is more or less divided by 2. consider only the BE algorithm from [6], which is used IV. PRESENTATION OF THE HPR NUMBER SYSTEM in state-of-the-art implementations due to its high level of A. Definition and Properties parallelism. Nonetheless, our propositions are independent of the choice of the BE algorithm, one can choose an- In this section, we define our hybrid position-residues other algorithm such as [16], [17]. The principle of the BE (HPR) representation and describe its properties. The main proposed in [6] is to approximate q in the CRT formula, idea is to define a representation which makes a link between Pna −1 RNS and the standard positional representation. On the one X = i=1 xa;i · Ma;i Ma;i − q Ma where the com- ma;i hand RNS representation is very efficient for some operations, putations are performed modulo each m . The result of this b;i as multiplications, but is not for some others as comparisons. approximated conversion is either hXi or hX + M i but b a b On the other hand, a positional number system allows cheaper this is easily managed in state-of-the-art implementations (see comparisons but more costly multiplications than RNS. details in [6]). This algorithm requires (n n + n ) EMMs. a b a Definition 1 (Hybrid Position-Residues Number System C. RNS Modular Reduction and Multiplication (HPR)): Let us assume two coprime RNS bases Ba and Qna−1 ∗ The state-of-the-art RNS modular reduction (RNS-MR) for Bb with Ma = i=0 ma;i, the degree d 2 N , a generic modulus, proposed in [18] (and optimized in [5], βmin and βmax 2 R such that βmax − βmin > 1 and [6], [10]), is based on the Montgomery modular reduction [19] βmax + βmin > 0. The integer X is represented in HPR, (initially proposed for radix-2). with parameters (Ba; Bb; βmin; βmax), in a high-radix Ma To perform all required operations in the Montgomery positional representation by reduction, one needs two bases: Ba for computing modulo X = hX i ;:::; hX i HPR d−1 ajb 0 ajb HPR Ma; and Bb for dividing by Ma (which is not possible in Ba).