Generation of Twisted Edwards Elliptic Curves for Circuit Use
Total Page:16
File Type:pdf, Size:1020Kb
Community Standard Proposal Generation of twisted Edwards elliptic curves for circuit use Barry WhiteHat1, Jordi Baylina2, and Marta Bell´es2,3 1Ethereum foundation, 2iden3, 3Universitat Pompeu Fabra May 16, 2019 Contents 1 Scope 2 2 Motivation 2 3 Background and Terminology 2 3.1 Montgomery form.................................................2 3.2 Twisted Edwards form...............................................3 4 Generation of twisted Edwards and Montgomery elliptic curves3 4.1 Choice of Montgomery equation..........................................4 4.2 Choice of generator and base points.......................................4 4.3 Transformation to twisted Edwards........................................4 4.4 Optimisation of parameters............................................5 5 Safety criteria 5 6 Implementations 6 7 Example: Baby Jubjub 6 7.1 Arithmetic In Baby Jubjub............................................6 7.1.1 Addition Of Points.............................................7 7.1.2 Multiplication Of A Point Of E By A Scalar..............................7 8 Intellectual Property 8 References 8 A Generation of curves 10 B Safety criteria 11 C Generation of Baby Jubjub 19 1 1 Scope algorithm for checking its security. The algorithms have already been implemented and tested: in ZCash, the new This proposal defines a deterministic algorithm for gener- curve derived from the order of BLS12-381, is called Jub- ating twisted Edwards elliptic curves defined over a given jub [10], and in Ethereum, the adopted curve is called prime field. It also provides an algorithm for checking the Baby Jubjub [19]. safety of the curve against best known security attacks. Although the generation of other types of curves, such Additionally, we present an example that puts theory as pairing-friendly and prime order curves, is out of scope into practice: we detail the generation of the twisted Ed- of this proposal, we hope the procedures of generating wards curve Baby Jubjub and explain how the arithmetic them get standardised and available to the community of the curve can be efficiently implemented inside a circuit. soon. 2 Motivation 3 Background and Terminology The study of pairing-friendly elliptic curves and the effi- In this section we present the main definitions needed cient implementation of cryptographic functions inside cir- to understand the document. We restrict the concepts cuits has reached a lot of popularity since the appearance and results to elliptic curves defined over a prime finite of zero-knowledge protocols such as zkSNARKs [15,7]. In field. For general results about elliptic curves see [17] and blockchain community these protocols have become a cru- [16] (this second book requires high mathematical back- cial ingredient, not only in privacy aspects but also as a ground). The following table contains the notation used solution to scalability problems. across the document. Inside a SNARK circuit one deals with elements of a certain finite field Fp where p is determined by the order of certain pairing-friendly elliptic curve used to generate the zero-knowledge proof. If one wants to implement func- tions involving elliptic curves inside a SNARK, such as the Pedersen hash function [10, Sec. 5.4.1.7] or EdDSA [11], a new curve defined over Fp is needed. Choosing this new curve in twisted Edwards [2] or Montgomery form [14] seems the optimal choice for cir- cuit use, as addition in the first case has a single complete formula and in the second, operating is very efficient. As we will see later, twisted Edwards and Montgomery curves are birationally equivalent, which allows as to easily com- bine both forms inside a circuit. It is important that the generation of this new curve is done in a transparent and deterministic way, so that it is clear no external considerations are taken for defining it. This is paramount as it significantly reduces the possi- bility of a backdoor being present, thus leading to better security. Moreover, it is crucial that the new curve is also safe against best known attacks [6]. In this proposal we cover both aspects. We provide 3.1 Montgomery form and algorithm that given a prime number p, determinis- tically generates a Montgomery and a birationally equiv- In this part we define and describe elliptic curves in Mont- alent twisted Edwards curve defined over Fp and also an gomery form. We follow [14] and [2]. 2 Definition 3.1 (Montgomery curve). Let p ≥ 3 be a Theorem 3.5. Let P1 = (x1; y1) and P2 = (x2; y2) be prime and Fp the finite field of order p. For A 2 Fp\{−2; 2g points a twisted Edwards elliptic curve E. The sum P1+P2 and B 2 Fpnf0g, an elliptic curve defined by is a third point P3 = (x3; y3) with M 2 3 2 E : By = x + Ax + x λ = dx1x2y1y2; x3 = (x1y2 + y1x2)=(1 + λ); is called a Montgomery (elliptic) curve. y3 = (y1y2 − x1x2)=(1 − λ): The following theorem presents the addition formulas in Montgomery curves. Note that the neutral element is the point O = (0; 1) and the inverse of a point (x; y) is (−x; y). Theorem 3.2. Let P1 = (x1; y1) 6= O and P2 = (x2; y2) 6= O be two points of the Baby-JubJub elliptic curve EM in Proof. [4, Sec. 3]. Montgomery form. If P1 6= P2, then the sum P1 + P2 is a third point As the following theorem states, Montgomery and P3 = (x3; y3) with coordinates twisted Edwards curves are birationally equivalent. The theorem also gives the birational map that allows the Λ = (y2 − y1)=(x2 − x1); transformation from one form to the other. 2 x3 = BΛ − A − x1 − x2; (1) Theorem 3.6. Every twisted Edwards curve E over Fp y3 = Λ(x1 − x3) − y1: is birationally equivalent over Fp to a Montgomery curve EM with parameters If P1 = P2, then 2 · P1 is a point P3 = (x3; y3) with coor- dinates a + d 4 A = 2 and B = : 2 a − d a − d Λ = (3x1 + 2Ax1 + 1)=(2By1); 2 M x3 = BΛ − A − 2x1; (2) The birational equivalence form E to E is the map y3 = Λ(x1 − x3) − y1: 1 + y 1 + y (x; y) ! (u; v) = ; 1 − y (1 − y)x Proof. See [12]. with inverse Theorem 3.3. The order of a Montgomery curve is a multiple of 4. u u − 1 (u; v) ! (x; y) = ; : (3) v u + 1 Proof. See [14, Sec. 10.3.2]. Conversely, every Montgomery curve over Fp is bira- 3.2 Twisted Edwards form tionally equivalent over Fp to a twisted Edwards curve with In this section we describe twisted Edwards curves follow- parameters ing the definition and results from [2]. A + 2 A − 2 a = and d = : Definition 3.4 (Twisted Edwards curve). Let p ≥ 3 be B B a prime and Fp the finite field of order p. For distinct Proof. See [2, Thm. 3.2]. a; b 2 Fpnf0g, an elliptic curve defined by E : ax2 + y2 = 1 + dx2y2 4 Generation of twisted Edwards is called a twisted Edwards (elliptic) curve. and Montgomery elliptic curves As next theorem shows, twisted Edwards curves have We present a method that, given a prime number p, we complete addition formulas. This makes these curves very get a twisted Edwards curve defined over Fp. The specific efficient inside circuits. outputs of the algorithm are: 3 • The prime order of the finite field the curve is defined a prime congruent to 3 mod 4, both the curve and twist over (which is the input p). cofactors can be 4, and this is minimal. • Parameters a and d of the equation that defines the Algorithm 1: Generation of EM curve. Input: p Output: A, B, n, h, l • Order of the curve and its decomposition into the 1 Fix B = 1. product of a cofactor and a large prime. 2 Start with A = 3. • Generator and base points. 3 Check that (A − 2) 6= 0 mod 4. Otherwise, increment A by 1 and check this condition again. 2 3 2 As the finite field is defined by the input p, no spec- 4 Check that the equation y = x + Ax + x ification of this parameter is required. In the same way, defines an elliptic curve over Fp. Otherwise, the order of the curve and its decomposition is determined increment A by 1 and go back to step 3. once the parameters of the equation describing the curve 5 Compute the group order n. are fixed. Hence, the only remaining specifications are pa- 6 If p = 1 mod 4 : Check that the cofactor is 8 rameters a and d and the choice of a generator and a base and the cofactor of the twist is 4. Otherwise, point. increment A by 1 and go back to step 3. We have divided the procedure in four steps. We 7 If p = 3 mod 4 : Check that the cofactor of the start by deterministically generating a Montgomery ellip- curve and its twist is 4. Otherwise, increment A M tic curve E over Fp and then setting the generator and by 1 and go back to step 3. base points. Afterwards, we convert the curve and the 8 Compute l. points to twisted Edwards using theorem 3.6. Last step 9 Return A, B, n, h and l. consists on rescaling all parameters so that less operations are required when doing arithmetic in the curve [8]. All 4.2 Choice of generator and base points algorithms are implemented in appendixA. To pick a generator G0 of the curve, we choose the small- 4.1 Choice of Montgomery equation est element of Fp that corresponds to an x-coordinate of a point in the curve of order n. Then as a base point, we We start by finding a Montgomery curve defined over Fp define G1 = 8 · G0, which has order l.