MPHELL
4.0.0
|
Definition of Weierstrass ECC function. More...
#include <stdlib.h>
#include <string.h>
#include "mphell-curve.h"
#include "mphell-drbg_internal.h"
#include "mphell-sha1.h"
Go to the source code of this file.
Functions | |
void | weierstrass_compute_disc (ec_curve E, uint8_t stack) |
Set the discriminant of E: disc = -16(4a^3 + 27b^2) More... | |
bool | weierstrass_verify_random_generation (ec_curve E, const char *seed, uint8_t stack) |
Test if E if generated from the seed "seed". More... | |
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. The curve is not tested to be secure !!! More... | |
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 coordinates. More... | |
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) More... | |
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) More... | |
bool | weierstrass_belongs (ec_point_srcptr P, ec_curve_srcptr E, uint8_t stack) |
Test if P belongs to E. More... | |
void | weierstrass_point_random (ec_point_ptr P, ec_curve_srcptr E, uint8_t stack) |
Set P to a random point on E. More... | |
void | weierstrass_point_norm (ec_point_ptr P, ec_curve_srcptr E, uint8_t stack) |
Set P in affine coordinates. More... | |
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. More... | |
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. More... | |
bool | weierstrass_point_is_neutral (ec_point_srcptr P, ec_curve_srcptr E, uint8_t stack) |
Test if P is the neutral element. More... | |
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) More... | |
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 such that Z1 = Z3. More... | |
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. More... | |
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. More... | |
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 P1->z==1. More... | |
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. More... | |
void | weierstrass_point_dbl_projective_dedicated (ec_point_ptr P3, ec_point_srcptr P1, ec_curve_srcptr E, uint8_t stack) |
Set P3 to 2 P1 using projective coordinate. More... | |
void | weierstrass_point_add_projective_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 projective coordinate. More... | |
void | weierstrass_point_add_projective_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 projective coordinate. More... | |
void | weierstrass_point_dbl_jacobian_dedicated (ec_point_ptr P3, ec_point_srcptr P1, ec_curve_srcptr E, uint8_t stack) |
Set P3 to 2 P1 using jacobian coordinate with the 2007 Bernstein/Lange method. More... | |
void | weierstrass_point_add_jacobian_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 jacobian coordinate with the 2007 Bernstein/Lange method. More... | |
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. More... | |
void | setup_Kim (fe_ptr X1, fe_ptr X2, fe_ptr K, fe_ptr L, fe_ptr A, fe_ptr S, fe_ptr T, fe_srcptr x0, fe_srcptr y0, bool bit, ec_curve_srcptr E, uint8_t stack) |
void | update_Kim (fe_ptr X1, fe_ptr X2, fe_ptr K, fe_ptr L, fe_ptr A, fe_ptr S, fe_ptr T, bool prev, bool new, ec_curve_srcptr E, uint8_t stack) |
void | recovery_Kim (fe_ptr P3x, fe_ptr P3y, fe_ptr X1, fe_ptr X2, fe_ptr K, fe_ptr L, fe_ptr A, fe_ptr S, fe_ptr T, fe_srcptr x0, fe_srcptr y0, field_ptr k, bool safe, uint8_t stack) |
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 to perform an inversion at the end of the computation to have affine coordinates and its formula is not complete and does not work for n = -1 neither 0 see .c for details. More... | |
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 complete and does not work for n = -1 see .c for details. More... | |
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) More... | |
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) More... | |
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) More... | |
void | weierstrass_point_neg (ec_point_ptr P3, ec_point_srcptr P1, ec_curve_srcptr E) |
Set P3 to -P1. More... | |
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. More... | |
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 they are all equal to the unique point of order 2. More... | |
Definition of Weierstrass ECC function.
Definition in file mphell-weierstrass.c.
bool weierstrass_belongs | ( | ec_point_srcptr | P, |
ec_curve_srcptr | E, | ||
uint8_t | stack | ||
) |
Test if P belongs to E.
P | Point |
E | Elliptic curve |
stack | Temporary memory stack to use |
Definition at line 442 of file mphell-weierstrass.c.
void weierstrass_compute_disc | ( | ec_curve | E, |
uint8_t | stack | ||
) |
Set the discriminant of E: disc = -16(4a^3 + 27b^2)
E | Elliptic curve |
stack | Temporary memory stack to use |
Definition at line 70 of file mphell-weierstrass.c.
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. The curve is not tested to be secure !!!
a | Destination coefficient, generated from a random seed |
b | Destination coefficient, generated from a random seed |
seed_res | Destination seed (of 160 bits) used to generate an elliptic curve |
k | Base field, must be created by the user before use. |
stack | Temporary memory stack to use |
Definition at line 227 of file mphell-weierstrass.c.
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)
--> Interface
P3 | Destination point |
P1 | Point |
P2 | Point |
E | Elliptic curve |
stack | Temporary memory stack to use |
Definition at line 1921 of file mphell-weierstrass.c.
void weierstrass_point_add_jacobian_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 jacobian coordinate with the 2007 Bernstein/Lange method.
P3 | Resulting point |
P1 | Source point |
P2 | Source point |
E | Elliptic curve |
stack | Temporary memory stack to use |
Definition at line 1409 of file mphell-weierstrass.c.
void weierstrass_point_add_projective_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 projective coordinate.
P3 | Resulting point |
P1 | Source point |
P2 | Source point |
E | Elliptic curve |
stack | Temporary memory stack to use |
Definition at line 1121 of file mphell-weierstrass.c.
void weierstrass_point_add_projective_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 projective coordinate.
P3 | Resulting point |
P1 | Source point |
P2 | Source point |
E | Elliptic curve |
stack | Temporary memory stack to use |
Definition at line 1215 of file mphell-weierstrass.c.
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)
P3 | Destination point |
P1 | Point |
P2 | Point |
E | Elliptic curve |
stack | Temporary memory stack to use |
Definition at line 1951 of file mphell-weierstrass.c.
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.
P3 | Destination point |
P4 | Destination point |
P1 | Point (X1, Y1, Z) |
P2 | Point (X2, Y2, Z) |
E | Elliptic curve |
stack | Temporary memory stack to use |
Definition at line 815 of file mphell-weierstrass.c.
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 such that Z1 = Z3.
--> COZ
P3 | Destination point |
P1 | Point (X1, Y1, Z) |
P2 | Point (X2, Y2, Z) |
E | Elliptic curve |
stack | Temporary memory stack to use |
Definition at line 775 of file mphell-weierstrass.c.
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.
P3 | Destination point |
P1 | Point (X1, Y1, Z2) |
P2 | Point (X2, Y2, Z2) |
E | Elliptic curve |
stack | Temporary memory stack to use |
Definition at line 866 of file mphell-weierstrass.c.
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)
P1 | Point |
P2 | Point |
E | Elliptic curve |
stack | Temporary memory stack to use |
Definition at line 677 of file mphell-weierstrass.c.
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)
P3 | Destination point |
P1 | Point |
E | Elliptic curve |
stack | Temporary memory stack to use |
Definition at line 1981 of file mphell-weierstrass.c.
void weierstrass_point_dbl_jacobian_dedicated | ( | ec_point_ptr | P3, |
ec_point_srcptr | P1, | ||
ec_curve_srcptr | E, | ||
uint8_t | stack | ||
) |
Set P3 to 2 P1 using jacobian coordinate with the 2007 Bernstein/Lange method.
--> JACOBIAN
P3 | Resulting point |
P1 | Source point (to double) |
E | Elliptic curve |
stack | Temporary memory stack to use |
Definition at line 1339 of file mphell-weierstrass.c.
void weierstrass_point_dbl_projective_dedicated | ( | ec_point_ptr | P3, |
ec_point_srcptr | P1, | ||
ec_curve_srcptr | E, | ||
uint8_t | stack | ||
) |
Set P3 to 2 P1 using projective coordinate.
--> PROJECTIVE
P3 | Resulting point |
P1 | Source point (to double) |
E | Elliptic curve |
stack | Temporary memory stack to use |
Definition at line 1020 of file mphell-weierstrass.c.
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 P1->z==1.
P3 | Destination point |
P4 | Destination point |
P1 | Point with P1->z==1 |
E | Elliptic curve |
stack | Temporary memory stack to use |
Definition at line 940 of file mphell-weierstrass.c.
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.
x | P->x in affine coordinates |
P | Point |
E | Elliptic curve |
stack | Temporary memory stack to use |
Definition at line 578 of file mphell-weierstrass.c.
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.
x | P->y in affine coordinates |
P | Point |
E | Elliptic curve |
stack | Temporary memory stack to use |
Definition at line 604 of file mphell-weierstrass.c.
bool weierstrass_point_is_neutral | ( | ec_point_srcptr | P, |
ec_curve_srcptr | E, | ||
uint8_t | stack | ||
) |
Test if P is the neutral element.
P | Point to test |
E | Elliptic curve |
stack | Temporary memory stack to use |
Definition at line 633 of file mphell-weierstrass.c.
void weierstrass_point_neg | ( | ec_point_ptr | P3, |
ec_point_srcptr | P1, | ||
ec_curve_srcptr | E | ||
) |
Set P3 to -P1.
P3 | Destination point |
P1 | Point |
E | Elliptic curve |
Definition at line 2007 of file mphell-weierstrass.c.
void weierstrass_point_norm | ( | ec_point_ptr | P, |
ec_curve_srcptr | E, | ||
uint8_t | stack | ||
) |
Set P in affine coordinates.
P | Point |
E | Elliptic curve |
stack | Temporary memory stack to use |
Definition at line 537 of file mphell-weierstrass.c.
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.
--> Miscellaneaous
dst | Destination point |
E | Elliptic curve |
stack | Temporary memory stack to use |
Definition at line 2019 of file mphell-weierstrass.c.
void weierstrass_point_random | ( | ec_point_ptr | P, |
ec_curve_srcptr | E, | ||
uint8_t | stack | ||
) |
Set P to a random point on E.
P | Destination point |
E | Elliptic curve |
stack | Temporary memory stack to use |
Definition at line 511 of file mphell-weierstrass.c.
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)
P | Destination point |
x | x-coordinate of the affine point (x, y) |
y | y-coordinate of the affine point (x, y) |
k | Base field |
Definition at line 423 of file mphell-weierstrass.c.
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)
P | Destination point |
str_x | x-coordinate of the affine point (x, y) under string form |
str_y | y-coordinate of the affine point (x, y) under string form |
is_reduced | Set true if str_x and str_y are already reduced in k, false otherwise |
base | Base (either 10 or 16) used for str_x and str_y |
k | Base field |
stack | Temporary memory stack to use |
Definition at line 432 of file mphell-weierstrass.c.
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 coordinates.
dst | Destination point |
E | Elliptic curve |
stack | Temporary memory stack to use |
Definition at line 397 of file mphell-weierstrass.c.
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.
P3 | Destination point |
P4 | Destination point |
P1 | Point |
E | Elliptic curve |
stack | Temporary memory stack to use |
Definition at line 1001 of file mphell-weierstrass.c.
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 they are all equal to the unique point of order 2.
dst1 | Destination point |
dst2 | Destination point |
dst3 | Destination point |
E | Elliptic curve |
stack | Temporary memory stack to use |
Definition at line 2166 of file mphell-weierstrass.c.
bool weierstrass_verify_random_generation | ( | ec_curve | E, |
const char * | seed, | ||
uint8_t | stack | ||
) |
Test if E if generated from the seed "seed".
E | Elliptic curve to test |
seed | Seed (of 160 bits) used to generate an elliptic curve |
stack | Temporary memory stack to use |
Definition at line 100 of file mphell-weierstrass.c.
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 complete and does not work for n = -1 see .c for details.
P3 | Destination point |
P1 | Point |
E | Elliptic curve |
stack | Temporary memory stack to use |
Definition at line 1843 of file mphell-weierstrass.c.
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 to perform an inversion at the end of the computation to have affine coordinates and its formula is not complete and does not work for n = -1 neither 0 see .c for details.
P3 | Destination point |
n | Number element for the scalar multiplication (different from -1 mod #E) |
P1 | Input point |
E | Elliptic curve on which the points belong |
stack | Temporary memory stack to use |
Definition at line 1757 of file mphell-weierstrass.c.
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.
--> COZ multiplication
P3 | Destination point |
P1 | Point |
E | Elliptic curve |
stack | Temporary memory stack to use |
Definition at line 1496 of file mphell-weierstrass.c.