MPHELL  4.0.0
mphell-weierstrass.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_WEIERSTRASS_H
27 #define MPHELL_WEIERSTRASS_H
28 
29 /* E: y^2 = x^3 + ax + b */
30 /* Projective coordinates represent an affine point (x,y) on a Weierstrass-form elliptic curve y^2 = x^3 + ax + b as (X:Y:Z) satisfying Y^2 Z = X^3 + aXZ^2 + bZ^3. Here (X:Y:Z) = (sX:sY:sZ) for all nonzero s. */
31 /* The triple (X, Y, Z) represents the affine point (X / Z, Y / Z) */
32 
33 /* Jacobian coordinates represent an affine point (x,y) on a Weierstrass-form elliptic curve y^2 = x^3 + ax + b as (X:Y:Z) satisfying Y^2 = X^3 + aXZ^4 + bZ^6. Here (X:Y:Z) = (s^2 X:s^3 Y:sZ) for all nonzero s.*/
34 /* The triple (X, Y, Z) represents the affine point (X / Z^2, Y / Z^3). */
35 
36 
37 /************************************SETTERS**********************************/
38 
45 void
46 weierstrass_compute_disc(ec_curve E, uint8_t stack);
47 
57 bool
58 weierstrass_verify_random_generation(ec_curve E, const char * seed, uint8_t stack);
59 
69 void
70 weierstrass_curve_random_generation(fe_ptr a, fe_ptr b, char * seed_res, field_srcptr k, uint8_t stack);
71 
79 void
81 
90 void
92 
104 void
105 weierstrass_point_set_aff_str (ec_point_ptr P, const char *str_x, const char *str_y,
106  const bool is_reduced, const uint8_t base, field_srcptr k, uint8_t stack);
107 
117 bool
119 
127 void
129 
137 void
139 
148 void
150 
159 void
161 
162 
163 /*******************************COMPARISON************************************/
164 
173 bool
175 
185 bool
187  ec_curve_srcptr E, uint8_t stack);
188 
189 
190 /*******************************OPERATIONS************************************/
191 
199 void
201 
202 /* UNIFIED => Resistant to SPA */
203 
213 void
215  ec_curve_srcptr E, uint8_t stack);
216 
227 void
229  ec_point_srcptr P2, ec_curve_srcptr E, uint8_t stack);
230 
240 void
242  ec_curve_srcptr E, uint8_t stack);
243 
253 void
255  ec_curve_srcptr E, uint8_t stack);
256 
266 void
268  ec_curve_srcptr E, uint8_t stack);
269 
282 void
284  ec_curve_srcptr E, uint8_t stack);
285 
294 void
296  ec_curve_srcptr E, uint8_t stack);
297 
308 void
309 weierstrass_Zjoye_mul(ec_point_ptr P3, number_srcptr n, ec_point_srcptr P1,
310  ec_curve_srcptr E, uint8_t stack);
311 
321 void
323  ec_curve_srcptr E, uint8_t stack);
324 
325 /* DEDICATED => Not resistant to SPA */
326 
336 void
338  ec_curve_srcptr E, uint8_t stack);
339 
348 void
350 
351 
352 /* Miscellaneaous */
353 
361 void
363 
373 void
375 
376 #endif
377 
378 
fp_elt * field_elt
Generic field element.
Definition: mphell-field.h:39
bool weierstrass_verify_random_generation(ec_curve E, const char *seed, uint8_t stack)
Test if E if generated from the seed "seed".
void weierstrass_curve_random_generation(fe_ptr a, fe_ptr b, 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 weierstrass_point_DBLU(ec_point_ptr P3, ec_point_ptr P4, ec_point_srcptr P1, ec_curve_srcptr E, uint8_t stack)
Co-Z point doubling with update: Set P3 to 2*P1 and P4 such that P1 = P4 and Z4 = Z3 and assume that ...
Define a field.
Definition: mphell-field.h:90
Define an elliptic curve point.
Definition: mphell-curve.h:103
void weierstrass_point_norm(ec_point_ptr P, ec_curve_srcptr E, uint8_t stack)
Set P in affine coordinates.
bool weierstrass_point_is_neutral(ec_point_srcptr P, ec_curve_srcptr E, uint8_t stack)
Test if P is the neutral element.
void weierstrass_point_set_neutral(ec_point_ptr dst, ec_curve_srcptr E, uint8_t stack)
Set dst to the neutral element: (0,1,0) for projective coordinates and (1,1,0) for jacobian coordinat...
void weierstrass_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 weierstrass_point_add_ZDAU(ec_point_ptr P3, ec_point_srcptr P1, ec_point_ptr P2, ec_curve_srcptr E, uint8_t stack)
Co-Z point doubling-addition with update: Set P3 to 2*P1 + P2 and update P2 such that Z2 = Z3.
bool weierstrass_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 they belong to the curve)
void weierstrass_compute_disc(ec_curve E, uint8_t stack)
Set the discriminant of E: disc = -16(4a^3 + 27b^2)
void weierstrass_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 weierstrass_Zjoye_mul(ec_point_ptr P3, number_srcptr n, ec_point_srcptr P1, ec_curve_srcptr E, uint8_t stack)
Set P3 to n * P1 using Joye’s double-add algorithm with Co-Z addition formula.The formulae are not co...
void weierstrass_point_add_unified(ec_point_ptr P3, ec_point_srcptr P1, ec_point_srcptr P2, ec_curve_srcptr E, uint8_t stack)
Set P3 to P1 + P2, using unified formulae (protection against SPA)
void weierstrass_point_set_aff(ec_point_ptr P, fe_srcptr x, fe_srcptr y, field_srcptr k)
Set dest to the affine point (x, y)
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 weierstrass_point_dbl_dedicated(ec_point_ptr P3, ec_point_srcptr P1, ec_curve_srcptr E, uint8_t stack)
Set P3 to 2 * P1, using dedicated formulae (not protected against SPA, but faster)
fp_elt * fe_ptr
Pointer on a field element.
Definition: mphell-field.h:45
void weierstrass_point_of_order_2(ec_point_ptr dst, ec_curve_srcptr E, uint8_t stack)
Set dst to one of the point of order 2 of the curve E assuming that at least one exist.
void weierstrass_point_add_dedicated(ec_point_ptr P3, ec_point_srcptr P1, ec_point_srcptr P2, ec_curve_srcptr E, uint8_t stack)
Set P3 to P1 + P2, using dedicated formulae (not protected against SPA, but faster)
void weierstrass_point_TPLU(ec_point_ptr P3, ec_point_ptr P4, ec_point_srcptr P1, ec_curve_srcptr E, uint8_t stack)
Co-Z point tripling with update: Set P3 to 3*P1 and P4 such that P4 = P1 and Z4 = Z3.
void weierstrass_point_add_ZADDU(ec_point_ptr P3, ec_point_ptr P1, ec_point_srcptr P2, ec_curve_srcptr E, uint8_t stack)
Co-Z point addition with update: Set P3 = (X3,Y3,Z3) to P1 + P2 using Co-Z addition and update P1 suc...
Define an elliptic curve.
Definition: mphell-curve.h:139
void weierstrass_point_random(ec_point_ptr P, ec_curve_srcptr E, uint8_t stack)
Set P to a random point on E.
void weierstrass_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 (str_x,str_y)
void weierstrass_point_add_ZADDC(ec_point_ptr P3, ec_point_ptr P4, ec_point_srcptr P1, ec_point_srcptr P2, ec_curve_srcptr E, uint8_t stack)
Conjugate Co-Z point addition: Set P3 to P1 + P2 and P4 to P1 - P2 such that Z3=Z4.
void weierstrass_point_neg(ec_point_ptr P3, ec_point_srcptr P1, ec_curve_srcptr E)
Set P3 to -P1.
void weierstrass_points_of_order_2(ec_point_ptr dst1, ec_point_ptr dst2, ec_point_ptr dst3, ec_curve_srcptr E, uint8_t stack)
Set dst1, dst2, dst3 to the points of order 2 of the curve E assuming they are different otherwise th...
void weierstrass_Zmontgomery_Kim(ec_point_ptr P3, number_srcptr n, ec_point_srcptr P1, ec_curve_srcptr E, uint8_t stack)
Perform the Montgomery ladder, taken from Kim et al's 2017 work, compute P3=[n]P1 it has the drawback...
bool weierstrass_belongs(ec_point_srcptr P, ec_curve_srcptr E, uint8_t stack)
Test if P belongs to E.
void weierstrass_Zmontgomery_ladder(ec_point_ptr P3, number_srcptr n, ec_point_srcptr P1, ec_curve_srcptr E, uint8_t stack)
Set P3 to n * P1 using Montgomery ladder with Co-Z addition formula.