MPHELL  4.0.0
mphell-edwards.h
Go to the documentation of this file.
1 /*
2  MPHELL-4.0
3  Author(s): The MPHELL team
4 
5  (C) Copyright 2015-2018 - Institut Fourier / Univ. Grenoble Alpes (France)
6 
7  This file is part of the MPHELL Library.
8  MPHELL is free software: you can redistribute it and/or modify
9  it under the terms of the GNU Lesser General Public License as published by
10  the Free Software Foundation, version 3 of the License.
11 
12  MPHELL is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU Lesser General Public License for more details.
16 
17  You should have received a copy of the GNU Lesser General Public License
18  along with MPHELL. If not, see <http://www.gnu.org/licenses/>.
19 */
20 
26 #ifndef MPHELL_EDWARDS_H
27 #define MPHELL_EDWARDS_H
28 
29 /* E: x^2 + y^2 = 1 + d x^2 y^2 */
30 /* Edwards form */
31 /* Projective coordinates represent an affine point (x,y) on a Edwards-form elliptic curve x^2 + y^2 = 1 + d x^2 y^2 as (X:Y:Z) satisfying (X^2 + Y^2) Z^2 = Z^4 + d X^2 Y^2. Here (X:Y:Z) = (sX:sY:sZ) for all nonzero s. */
32 /* The triple (X, Y, Z) represents the affine point (X / Z, Y / Z) */
33 
34 /* Jacobian coordinates represent an affine point (x,y) on a Edwards-form elliptic curve x^2 + y^2 = 1 + d x^2 y^2 as (X:Y:Z) satisfying (X^2 Z^6 + Y^2 Z^4) = Z^10 + d X^2 Y^2. Here (X:Y:Z) = (s^2 X:s^3 Y:sZ) for all nonzero s.*/
35 /* The triple (X, Y, Z) represents the affine point (X / Z^2, Y / Z^3). */
36 
37 /* Extended twisted Edwards coordinates represent an affine point (x,y) on a Edwards-form elliptic curve x^2 + y^2 = 1 + d x^2 y^2 as (X:Y:Z) satisfying ( X^2 + Y^2) Z^2 = Z^4 + d X^2 Y^2. Here (X:Y:T:Z) = (sX:sY:sT:sZ) for all nonzero s. The auxiliary coordinate T has the property T=XY/Z. */
38 
39 /* E: a x^2 + y^2 = 1 + d x^2 y^2 */
40 /* Twisted Edwards form */
41 /* Projective coordinates represent an affine point (x,y) on a Edwards-form elliptic curve a x^2 + y^2 = 1 + d x^2 y^2 as (X:Y:Z) satisfying (X^2 + Y^2) Z^2 = Z^4 + d X^2 Y^2. Here (X:Y:Z) = (sX:sY:sZ) for all nonzero s. */
42 /* The triple (X, Y, Z) represents the affine point (X / Z, Y / Z) */
43 
44 /* Jacobian coordinates represent an affine point (x,y) on a Weierstrass-form elliptic curve a x^2 + y^2 = 1 + d x^2 y^2 as (X:Y:Z) satisfying (a X^2 Z^6 + Y^2 Z^4) = Z^10 + d X^2 Y^2. Here (X:Y:Z) = (s^2 X:s^3 Y:sZ) for all nonzero s.*/
45 /* The triple (X, Y, Z) represents the affine point (X / Z^2, Y / Z^3). */
46 
47 /* Extended twisted Edwards coordinates represent an affine point (x,y) on a Edwards-form elliptic curve a x^2 + y^2 = 1 + d x^2 y^2 as (X:Y:Z) satisfying (a X^2 + Y^2) Z^2 = Z^4 + d X^2 Y^2. Here (X:Y:T:Z) = (sX:sY:sT:sZ) for all nonzero s. The auxiliary coordinate T has the property T=XY/Z. */
48 
49 /* In this software the coefficients a and d that represent a(n) (Twisted) Edwards Curve are stored in E->a for a and E->b for d.*/
50 
51 /* More details can be found for example in Twisted Edwards curves by Daniel J. Bernstein, Peter Birkner, Marc Joye, Tanja Lange, and Christiane Peters
52  published in International Conference on Cryptology in Africa. Springer, Berlin, Heidelberg, 2008. p. 389-405. */
53 
54 /************************************SETTERS**********************************/
55 
62 void
63 edwards_compute_disc(ec_curve E, uint8_t stack);
64 
74 bool
75 edwards_verify_random_generation(ec_curve E, const char * seed, uint8_t stack);
76 
85 void
86 edwards_curve_random_generation(fe_ptr d, char * seed_res, field_srcptr k, uint8_t stack);
87 
95 void
97 
107 void
109 
121 void
122 edwards_point_set_aff_str (ec_point_ptr P, const char *str_x, const char *str_y,
123  const bool is_reduced, const uint8_t base, field_srcptr k, uint8_t stack);
124 
133 bool
134 edwards_belongs (ec_point_srcptr P, ec_curve_srcptr E, uint8_t stack);
135 
143 void
145 
153 void
154 edwards_point_norm (ec_point_ptr P, ec_curve_srcptr E, uint8_t stack);
155 
164 void
166 
175 void
177 
178 /*******************************COMPARISON************************************/
179 
187 bool
189 
199 bool
201  ec_curve_srcptr E, uint8_t stack);
202 
203 /*******************************OPERATIONS************************************/
204 
212 void
214 
215 /* UNIFIED => Resistant to SPA */
216 
226 void
228  ec_curve_srcptr E, uint8_t stack);
229 
230 /* DEDICATED => Not resistant to SPA, but faster */
231 
241 void
243  ec_curve_srcptr E, uint8_t stack);
244 
253 void
255 
256 #endif
257 
void edwards_point_set_aff(ec_point_ptr P, fe_srcptr x, fe_srcptr y, field_srcptr k, uint8_t stack)
Set dest to the extended twisted Edwards coordinates point (x,y,1,xy)
bool edwards_point_are_equal(ec_point_srcptr P1, ec_point_srcptr P2, ec_curve_srcptr E, uint8_t stack)
Test if P1 and P2 are equal on E (BUT do not test if the points belongs to the curve )
fp_elt * field_elt
Generic field element.
Definition: mphell-field.h:39
void edwards_point_neg(ec_point_ptr P3, ec_point_srcptr P1, ec_curve_srcptr E)
Compute the opposite of a point of the the Edwards elliptic curve E.
void edwards_point_get_y_affine(field_elt y, ec_point_ptr P, ec_curve_srcptr E, uint8_t stack)
Convert P->y to its affine representation.
void edwards_curve_random_generation(fe_ptr d, char *seed_res, field_srcptr k, uint8_t stack)
Generate a 160 bits seed and coefficients a and b defining a Weiestrass elliptic curve....
void edwards_compute_disc(ec_curve E, uint8_t stack)
Set the discriminant of E: disc = a.d.(a-d)^4.
Define a field.
Definition: mphell-field.h:90
Define an elliptic curve point.
Definition: mphell-curve.h:103
void edwards_point_set_neutral(ec_point_ptr dst, ec_curve_srcptr E, uint8_t stack)
Set dst to the neutral element: (0,1,0,1) for extended twisted Edwards coordinates.
void edwards_point_dbl_dedicated(ec_point_ptr P3, ec_point_srcptr P1, ec_curve_srcptr E, uint8_t stack)
Compute the double of a point of the Edwards elliptic curve E (not protected against SPA,...
bool edwards_verify_random_generation(ec_curve E, const char *seed, uint8_t stack)
Test if E if generated from the seed "seed".
void edwards_point_add_unified(ec_point_ptr P3, ec_point_srcptr P1, ec_point_srcptr P2, ec_curve_srcptr E, uint8_t stack)
Compute the unified addition of 2 points P1 and P2 of the Edwards elliptic curve E,...
bool edwards_belongs(ec_point_srcptr P, ec_curve_srcptr E, uint8_t stack)
Test if P belongs to E.
void edwards_point_norm(ec_point_ptr P, ec_curve_srcptr E, uint8_t stack)
Set P in affine coordinates.
void edwards_point_get_x_affine(field_elt x, ec_point_ptr P, ec_curve_srcptr E, uint8_t stack)
Convert P->x to its affine representation.
void edwards_point_random(ec_point_ptr P, ec_curve_srcptr E, uint8_t stack)
Set P to a random point on E.
const fp_elt * fe_srcptr
Pointer on a field element, the field element cannot be modified through this pointer.
Definition: mphell-field.h:51
void edwards_point_set_aff_str(ec_point_ptr P, const char *str_x, const char *str_y, const bool is_reduced, const uint8_t base, field_srcptr k, uint8_t stack)
Set dest to the affine point twisted Edwards coordinates point (str_x,str_y,1,str_x str_y)
fp_elt * fe_ptr
Pointer on a field element.
Definition: mphell-field.h:45
Define an elliptic curve.
Definition: mphell-curve.h:139
void edwards_point_add_dedicated(ec_point_ptr P3, ec_point_srcptr P1, ec_point_srcptr P2, ec_curve_srcptr E, uint8_t stack)
Compute the addition of 2 points P1 and P2 of the Edwards elliptic curve E (not protected against SPA...
bool edwards_point_is_neutral(ec_point_srcptr P, ec_curve_srcptr E)
Test if P is the neutral element.