MPHELL  4.0.0
Data Structures | Typedefs | Enumerations | Functions
mphell-curve.h File Reference

Declaration of ECC functions. More...

#include "mphell-field.h"
#include "mphell-weierstrass.h"
#include "mphell-jacobi.h"
#include "mphell-edwards.h"
Include dependency graph for mphell-curve.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  ec_point
 Define an elliptic curve point. More...
 
struct  ec_curve
 Define an elliptic curve. More...
 

Typedefs

typedef enum ec_type_enum ec_type
 Define the type of curve.
 
typedef enum ec_algo_enum ec_formula
 Define the type of coordinate.
 
typedef enum ec_known_curve_enum ec_known_curve
 Define the hardcoded curves.
 
typedef struct ec_point ec_point_t
 Define an elliptic curve point.
 
typedef ec_point_t ec_point[1]
 Address of an ec_point structure.
 
typedef ec_point_tec_point_ptr
 Define ec_point_ptr, use in all functions.
 
typedef const ec_point_tec_point_srcptr
 Define ec_point_srcptr, use in all functions where the parameter is const.
 
typedef struct ec_curve ec_curve_t
 Define an elliptic curve.
 
typedef ec_curve_t ec_curve[1]
 Address of an ec_curve structure.
 
typedef ec_curve_tec_curve_ptr
 Define ec_curve_ptr, use in all functions.
 
typedef const ec_curve_tec_curve_srcptr
 Define ec_curve_srcptr, use in all functions where the parameter is const.
 

Enumerations

enum  ec_type_enum { WEIERSTRASS, EDWARDS, JACOBI_QUARTIC }
 Define the type of curve. More...
 
enum  ec_algo_enum { PROJECTIVE, JACOBIAN, EXTENDED_HOMOGENEOUS_PROJECTIVE, EXTENDED_EDWARDS }
 Define the type of coordinate. More...
 
enum  ec_known_curve_enum {
  NIST_192, NIST_224, NIST_256, NIST_384,
  NIST_521, BRAINPOOL_160, BRAINPOOL_192, BRAINPOOL_224,
  BRAINPOOL_256, BRAINPOOL_320, BRAINPOOL_384, BRAINPOOL_512,
  FR_256, JQ_256_3, ED_25519
}
 Define the hardcoded curves. More...
 

Functions

static void ec_point_get_pool_elt (ec_point_ptr P, field_ptr k, uint8_t stack)
 Get an initialised point from the pool. More...
 
static void ec_point_relax_pool_elt (ec_point_ptr P, field_ptr k, uint8_t stack)
 Relax an initialised point from the pool. More...
 
void ec_alloc (ec_curve_ptr E, field_srcptr k)
 Allocate a curve. More...
 
void ec_init (ec_curve_ptr E, field_srcptr k)
 Initialise a curve. More...
 
void ec_create (ec_curve_ptr E, const char *id_curve, field_srcptr k, fe_srcptr a, fe_srcptr b, ec_point_srcptr G, number_srcptr h, number_srcptr n, const ec_type type, const ec_formula f, uint8_t stack)
 Create an elliptic curve E, the curve must be allocated and initialised (ec_alloc & ec_init) More...
 
void ec_use_curve (ec_curve_ptr E, field_ptr k, const ec_known_curve id_curve, const ec_formula f, uint8_t stack)
 Create the elliptic curve (and the associated base field) id_curve, the curve and the field must me allocated (field_alloc & ec_alloc). More...
 
void ec_random (ec_curve_ptr E, const char *id_curve, char *seed_res, field_srcptr k, const ec_type type, const ec_formula f, uint8_t stack)
 Create a random elliptic curve E, not cryptographically secure (not tested to be). Algorithm A.3.3.2 from ANS X9.62-1998. More...
 
bool ec_verify_random_generation (ec_curve_ptr E, const char *seed, uint8_t stack)
 Test if E if generated from the seed "seed", using algorithm A.3.4.2 from ANS X9.62-1998. Only curve generated with the algorithm A.3.3.2 can be tested. More...
 
void ec_set_fast_unified_coordinates (ec_curve_ptr E)
 Set the fastest unified coordinates system. More...
 
void ec_set_fast_dedicated_coordinates (ec_curve_ptr E)
 Set the fastest dedicated coordinates system. More...
 
void ec_compute_disc (ec_curve_ptr E, uint8_t stack)
 Set the discriminant of E. More...
 
void ec_test_spec (ec_curve_ptr E, uint8_t stack)
 Set the E->ec_spec1 to true if E->a = -3 mod p, false otherwise. More...
 
void ec_copy (ec_curve_ptr E_res, ec_curve_srcptr E)
 Copy E into E_res which has been previously allocated, beware: the same field is used, do not free it 2 times. More...
 
void ec_clear (ec_curve_ptr E)
 Clear the elliptic curve E (remove the action of ec_init, but let the one of ec_alloc) More...
 
void ec_free (ec_curve_ptr E)
 Free the elliptic curve E. More...
 
void ec_point_alloc (ec_point_ptr P, field_srcptr k)
 Allocate an elliptic curve point. More...
 
void ec_point_init (ec_point_ptr P, field_srcptr k)
 Initialise an elliptic curve point. More...
 
void ec_point_clear (ec_point_ptr P, field_srcptr k)
 Clear the point P (remove the action of ec_point_init, but let the one of ec_point_alloc) More...
 
void ec_point_free (ec_point_ptr P, field_srcptr k)
 Free the point P. More...
 
void ec_point_copy (ec_point_ptr P3, ec_point_srcptr P, field_srcptr k)
 Copy P into P3. More...
 
void ec_point_set (ec_point_ptr P, fe_srcptr x, fe_srcptr y, fe_srcptr z, fe_srcptr t, field_srcptr k)
 Set a point from its coordinates. More...
 
void ec_point_set_str (ec_point_ptr P, const char *str_x, const char *str_y, const char *str_z, const char *str_t, const bool is_reduced, const uint8_t base, field_srcptr k, uint8_t stack)
 Set a point from its coordinates under string format. More...
 
void ec_point_set_aff (ec_point_ptr P, fe_srcptr x, fe_srcptr y, const ec_type type, field_srcptr k, uint8_t stack)
 Set a point from its affine coordinates. More...
 
void ec_point_set_aff_str (ec_point_ptr P, const char *str_x, const char *str_y, const bool is_reduced, const uint8_t base, const ec_type type, field_srcptr k, uint8_t stack)
 Set a point from its affine coordinates under string format. More...
 
void ec_point_set_neutral (ec_point_ptr dst, ec_curve_srcptr E, uint8_t stack)
 Set dst to the neutral element. More...
 
void ec_point_norm (ec_point_ptr P, ec_curve_srcptr E, uint8_t stack)
 Convert a point in projective or jacobian coordinate to an affine point (x,y) More...
 
void ec_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 ec_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...
 
void ec_point_lift (ec_point_ptr P, field_srcptr k, uint8_t stack)
 Lift the coordinates from Montgomery basis to classical arithmetic. More...
 
bool ec_belongs (ec_point_srcptr P, ec_curve_srcptr E, uint8_t stack)
 Test if P belongs to E. More...
 
void ec_point_random (ec_point_ptr P, ec_curve_srcptr E, uint8_t stack)
 Create a random point P on the elliptic curve E. More...
 
void ec_curve_str (char **str, ec_curve_srcptr E, const uint8_t base, uint8_t stack)
 Allocate *str and write in it the description of E. More...
 
void ec_curve_print (ec_curve_srcptr E, const uint8_t base, uint8_t stack)
 Print a description of E. More...
 
void ec_point_str (char **str, ec_point_srcptr P, const uint8_t base, const bool lift, field_srcptr k, uint8_t stack)
 Allocate *str and write in it the description of P. More...
 
void ec_point_print (ec_point_srcptr P, const uint8_t base, const bool lift, field_srcptr k, uint8_t stack)
 Print a description of P. More...
 
bool ec_point_is_neutral (ec_point_srcptr P, ec_curve_srcptr E, uint8_t stack)
 Test if P is the neutral element. More...
 
bool ec_point_are_equal (ec_point_srcptr P1, ec_point_srcptr P2, const ec_curve_srcptr E, uint8_t stack)
 Test if P1 and P2 are equal on E. More...
 
void ec_point_neg (ec_point_ptr P3, ec_point_srcptr P1, ec_curve_srcptr E)
 Set P3 to -P1. More...
 
void ec_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 ec_point_dbl_unified (ec_point_ptr P3, ec_point_srcptr P1, ec_curve_srcptr E, uint8_t stack)
 Set P3 to 2*P1, using unified formulae (protection against SPA) More...
 
void ec_point_sub_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 ec_point_mul_unified (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 for Weierstrass elliptic curve, and naive method for other elliptic curve type, using unified formulae (protection against SPA) More...
 
void ec_point_add (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 ec_point_dbl (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 ec_point_sub (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 ec_point_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 Montgomery for Weierstrass elliptic curve, and naive method for other elliptic curve type, using dedicated formulae (not protected against SPA execpt in WEIESTRASS / JACOBIAN case, but faster) More...
 
void ec_point_mul_with_precomp (ec_point_ptr P3, number_srcptr n, ec_point *tab_P1, int16_t window_size, ec_curve_srcptr E, uint8_t stack)
 Set P3 to n * P1 using naive double and add method, Montgomery and Joye multiplication are also available for Weierstrass elliptic curve, using dedicated formulae (not protected against SPA, but faster) More...
 
void ec_point_2mul_with_precomp (ec_point_ptr P3, number_srcptr n1, ec_point *tab_P1, number_srcptr n2, ec_point *tab_P2, int16_t win_size, ec_curve_srcptr E, uint8_t stack)
 Set P3 to n1 * P1 + n2 * P2 using 2 precomputated array. More...
 
void jacobi_quartic_to_weierstrass (ec_curve_ptr E_res, ec_curve_srcptr E, uint8_t stack)
 Convert a jacobi quartic elliptic curve into a Weierstrass elliptic curve. More...
 
void jacobi_quartic_point_to_weierstrass_point (ec_point_ptr dst, ec_point_srcptr P, ec_curve_srcptr E, uint8_t stack)
 Convert a point on a jacobi quartic elliptic curve to a point on a weierstrass elliptic curve. More...
 
void weierstrass_to_jacobi_quartic (ec_curve_ptr E_res, ec_curve_srcptr E, const bool determined, fe_ptr teta, uint8_t stack)
 Convert a Weierstrass elliptic curve into a jacobi quartic elliptic curve. More...
 
void weierstrass_point_to_jacobi_quartic_point (ec_point_ptr dst, ec_point_srcptr P, ec_curve_srcptr E, uint8_t stack)
 Convert a point on a weierstrass elliptic curve to a point on a jacobi quartic elliptic curve. More...
 
void edwards_to_weierstrass (ec_curve_ptr E_res, ec_curve_srcptr E, uint8_t stack)
 Convert the Edwards elliptic curve E to the corresponding Weierstrass elliptic curve E_res. More...
 
void edwards_point_to_weierstrass_point (ec_point_ptr dst, ec_point_srcptr P, ec_curve_srcptr E, uint8_t stack)
 Convert the Edwards point P of the elliptic curve E to the corresponding Weierstrass elliptic curve point dst. More...
 
void weierstrass_to_edwards (ec_curve_ptr E_res, ec_curve_srcptr E, const uint8_t n, fe_ptr alpha, fe_ptr beta, uint8_t stack)
 Convert the Weierstrass elliptic curve E to the one of the corresponding Edwards elliptic curve according to the choice (or not) of alpha and/or beta. More...
 
void weierstrass_point_to_edwards_point (ec_point_ptr dst, ec_point_srcptr P, ec_curve_srcptr E, const uint8_t n, fe_ptr alpha, fe_ptr beta, uint8_t stack)
 Convert the point of the Weierstrass elliptic curve E to the elliptic curve of one of the corresponding Edwards elliptic curve according to the choice (or not) of alpha and/or beta. More...
 

Detailed Description

Declaration of ECC functions.

Definition in file mphell-curve.h.

Enumeration Type Documentation

◆ ec_algo_enum

Define the type of coordinate.

Enumerator
PROJECTIVE 

(X,Y,Z) matching the affine point (x,y) where x=X/Z, y=Y/Z, the point at infinity is (0,1,0)

JACOBIAN 

(X,Y,Z) matching the affine point (x,y) where x=X/Z^2, y=Y/Z^3, the point at infinity is (a^2,a^3,0) with a!=0

EXTENDED_HOMOGENEOUS_PROJECTIVE 

(X,Y,T,Z) satisfying Y^2 = Z^2 + 2aX^2 + T^2; X^2 = ZT; a != 1 Here (X:Y:T:Z) = (sX:sY:T:sZ) for all nonzero s

EXTENDED_EDWARDS 

(X,Y,T,Z) matching the affine point (x,y) where x=X/Z, y=Y/Z, and T=XY/Z the point at infinity is (0,1,0,1)

Definition at line 56 of file mphell-curve.h.

◆ ec_known_curve_enum

Define the hardcoded curves.

Enumerator
NIST_192 

NIST 192 bits

NIST_224 

NIST 224 bits

NIST_256 

NIST 256 bits

NIST_384 

NIST 384 bits

NIST_521 

NIST 521 bits

BRAINPOOL_160 

BRAINPOOL 160 bits

BRAINPOOL_192 

BRAINPOOL 192 bits

BRAINPOOL_224 

BRAINPOOL 224 bits

BRAINPOOL_256 

BRAINPOOL 256 bits

BRAINPOOL_320 

BRAINPOOL 320 bits

BRAINPOOL_384 

BRAINPOOL 384 bits

BRAINPOOL_512 

BRAINPOOL 521 bits

FR_256 

ANSI 256 bits

JQ_256_3 

JACOBI QUARTIC 256 bits

ED_25519 

EDWARDS 25519

Definition at line 74 of file mphell-curve.h.

◆ ec_type_enum

Define the type of curve.

Enumerator
WEIERSTRASS 

Weierstrass curve, E: y^2 = x^3 + ax + b, 4a^3 +27b^2 != 0

EDWARDS 

Edwards curve, E: x^2 + y^2 = 1 + d x^2 y^2; d(1-d)!=0

JACOBI_QUARTIC 

Jacobi quartic curve, E: y^2 = z^2 + 2ax^2 + t^2; x^2 = zt; a != 1

Definition at line 39 of file mphell-curve.h.

Function Documentation

◆ ec_alloc()

void ec_alloc ( ec_curve_ptr  E,
field_srcptr  k 
)

Allocate a curve.

Parameters
EElliptic curve to allocate
kBase field

Definition at line 37 of file mphell-curve.c.

◆ ec_belongs()

bool ec_belongs ( ec_point_srcptr  P,
ec_curve_srcptr  E,
uint8_t  stack 
)

Test if P belongs to E.

Parameters
PPoint
EElliptic curve
stackTemporary memory stack to use
Returns
True if P belongs to E, false otherwise

Definition at line 865 of file mphell-curve.c.

◆ ec_clear()

void ec_clear ( ec_curve_ptr  E)

Clear the elliptic curve E (remove the action of ec_init, but let the one of ec_alloc)

Parameters
EElliptic curve

Definition at line 643 of file mphell-curve.c.

◆ ec_compute_disc()

void ec_compute_disc ( ec_curve_ptr  E,
uint8_t  stack 
)

Set the discriminant of E.

Parameters
EElliptic curve
stackTemporary memory stack to use

Definition at line 580 of file mphell-curve.c.

◆ ec_copy()

void ec_copy ( ec_curve_ptr  E_res,
ec_curve_srcptr  E 
)

Copy E into E_res which has been previously allocated, beware: the same field is used, do not free it 2 times.

Parameters
E_resResulting elliptic curve
EElliptic curve

Definition at line 618 of file mphell-curve.c.

◆ ec_create()

void ec_create ( ec_curve_ptr  E,
const char *  id_curve,
field_srcptr  k,
fe_srcptr  a,
fe_srcptr  b,
ec_point_srcptr  G,
number_srcptr  h,
number_srcptr  n,
const ec_type  type,
const ec_formula  f,
uint8_t  stack 
)

Create an elliptic curve E, the curve must be allocated and initialised (ec_alloc & ec_init)

Parameters
EElliptic curve, previously allocated
id_curveName of the curve
kBase field
aa coefficient for short Weierstrass and Jacobi Quartic elliptic curve
bb coefficient for short Weierstrass elliptic curve
GBase point
hCofactor of the order of G
nOrder of G
typeType of elliptic curve
fType of coordinate system
stackTemporary memory stack to use

Definition at line 62 of file mphell-curve.c.

◆ ec_curve_print()

void ec_curve_print ( ec_curve_srcptr  E,
const uint8_t  base,
uint8_t  stack 
)

Print a description of E.

Parameters
EElliptic curve
baseBase used to print the parameters (either 10 or 16)
stackTemporary memory stack to use

Definition at line 1036 of file mphell-curve.c.

◆ ec_curve_str()

void ec_curve_str ( char **  str,
ec_curve_srcptr  E,
const uint8_t  base,
uint8_t  stack 
)

Allocate *str and write in it the description of E.

Parameters
strPointer to a string, allocated by the function.
EElliptic curve
baseBase used to write the parameters (either 10 or 16)
stackTemporary memory stack to use

Definition at line 932 of file mphell-curve.c.

◆ ec_free()

void ec_free ( ec_curve_ptr  E)

Free the elliptic curve E.

Parameters
EElliptic curve

Definition at line 655 of file mphell-curve.c.

◆ ec_init()

void ec_init ( ec_curve_ptr  E,
field_srcptr  k 
)

Initialise a curve.

Parameters
EElliptic curve to initialise
kBase field

Definition at line 52 of file mphell-curve.c.

◆ ec_point_2mul_with_precomp()

void ec_point_2mul_with_precomp ( ec_point_ptr  P3,
number_srcptr  n1,
ec_point tab_P1,
number_srcptr  n2,
ec_point tab_P2,
int16_t  win_size,
ec_curve_srcptr  E,
uint8_t  stack 
)

Set P3 to n1 * P1 + n2 * P2 using 2 precomputated array.

Parameters
P3Destination point
n1Scalar to multiply P1 with
tab_P1Array of precomputed [P1, 2P1, 3P1, ..., (2^e - 1)P1]
n2Scalar to multiply P2 with
tab_P2Array of precomputed [P2, 2P2, 3P2, ..., (2^e - 1)P2]
win_sizeSize of the windows
EElliptic curve
stackTemporary memory stack to use

Definition at line 1611 of file mphell-curve.c.

◆ ec_point_add()

void ec_point_add ( 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)

Parameters
P3Resulting point
P1Source point
P2Source point
EElliptic curve
stackTemporary memory stack to use

Definition at line 1291 of file mphell-curve.c.

◆ ec_point_add_unified()

void ec_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)

Parameters
P3Resulting point
P1Source point
P2Source point
EElliptic curve
stackTemporary memory stack to use

Definition at line 1138 of file mphell-curve.c.

◆ ec_point_alloc()

void ec_point_alloc ( ec_point_ptr  P,
field_srcptr  k 
)

Allocate an elliptic curve point.

Parameters
PPoint to allocate
kBase field

Definition at line 673 of file mphell-curve.c.

◆ ec_point_are_equal()

bool ec_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.

Parameters
P1Point
P2Point
EElliptic curve
stackTemporary memory stack to use
Returns
True if P1 == P2, False otherwise

Definition at line 1095 of file mphell-curve.c.

◆ ec_point_clear()

void ec_point_clear ( ec_point_ptr  P,
field_srcptr  k 
)

Clear the point P (remove the action of ec_point_init, but let the one of ec_point_alloc)

Parameters
PPoint to clear
kBase field

Definition at line 691 of file mphell-curve.c.

◆ ec_point_copy()

void ec_point_copy ( ec_point_ptr  P3,
ec_point_srcptr  P,
field_srcptr  k 
)

Copy P into P3.

Parameters
P3Destination point
PPoint
kBase field

Definition at line 709 of file mphell-curve.c.

◆ ec_point_dbl()

void ec_point_dbl ( 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)

Parameters
P3Resulting point
P1Source point
EElliptic curve
stackTemporary memory stack to use

Definition at line 1312 of file mphell-curve.c.

◆ ec_point_dbl_unified()

void ec_point_dbl_unified ( ec_point_ptr  P3,
ec_point_srcptr  P1,
ec_curve_srcptr  E,
uint8_t  stack 
)

Set P3 to 2*P1, using unified formulae (protection against SPA)

Parameters
P3Resulting point
P1Source point
EElliptic curve
stackTemporary memory stack to use

Definition at line 1162 of file mphell-curve.c.

◆ ec_point_free()

void ec_point_free ( ec_point_ptr  P,
field_srcptr  k 
)

Free the point P.

Parameters
PPoint to free
kBase field

Definition at line 700 of file mphell-curve.c.

◆ ec_point_get_pool_elt()

void ec_point_get_pool_elt ( ec_point_ptr  P,
field_ptr  k,
uint8_t  stack 
)
inlinestatic

Get an initialised point from the pool.

Parameters
PPoint
kBase field
stackTemporary memory stack to use

Definition at line 202 of file mphell-curve.h.

◆ ec_point_get_x_affine()

void ec_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.

Parameters
xP->x in affine coordinates
PPoint
EElliptic curve
stackTemporary memory stack to use

Definition at line 818 of file mphell-curve.c.

◆ ec_point_get_y_affine()

void ec_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.

Parameters
yP->y in affine coordinates
PPoint
EElliptic curve
stackTemporary memory stack to use

Definition at line 837 of file mphell-curve.c.

◆ ec_point_init()

void ec_point_init ( ec_point_ptr  P,
field_srcptr  k 
)

Initialise an elliptic curve point.

Parameters
PPoint to allocate
kBase field

Definition at line 682 of file mphell-curve.c.

◆ ec_point_is_neutral()

bool ec_point_is_neutral ( ec_point_srcptr  P,
ec_curve_srcptr  E,
uint8_t  stack 
)

Test if P is the neutral element.

Parameters
PPoint to test
EElliptic curve
stackTemporary memory stack to use
Returns
True if P is neutral, False otherwise

Definition at line 1075 of file mphell-curve.c.

◆ ec_point_lift()

void ec_point_lift ( ec_point_ptr  P,
field_srcptr  k,
uint8_t  stack 
)

Lift the coordinates from Montgomery basis to classical arithmetic.

Parameters
PPoint
kBase field
stackTemporary memory stack to use

Definition at line 856 of file mphell-curve.c.

◆ ec_point_mul()

void ec_point_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 Montgomery for Weierstrass elliptic curve, and naive method for other elliptic curve type, using dedicated formulae (not protected against SPA execpt in WEIESTRASS / JACOBIAN case, but faster)

Parameters
P3Destination point
nScalar to multiply P1 with
P1Point
EElliptic curve
stackTemporary memory stack to use

Definition at line 1779 of file mphell-curve.c.

◆ ec_point_mul_unified()

void ec_point_mul_unified ( 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 for Weierstrass elliptic curve, and naive method for other elliptic curve type, using unified formulae (protection against SPA)

Parameters
P3Destination point
nScalar to multiply P1 with
P1Point
EElliptic curve
stackTemporary memory stack to use

Definition at line 1242 of file mphell-curve.c.

◆ ec_point_mul_with_precomp()

void ec_point_mul_with_precomp ( ec_point_ptr  P3,
number_srcptr  n,
ec_point tab_P1,
int16_t  win_size,
ec_curve_srcptr  E,
uint8_t  stack 
)

Set P3 to n * P1 using naive double and add method, Montgomery and Joye multiplication are also available for Weierstrass elliptic curve, using dedicated formulae (not protected against SPA, but faster)

Parameters
P3Destination point
nScalar to multiply P1 with
tab_P1Array of precomputed [P1, 3P1, 5P1, ..., (2^e - 1)P1]
win_sizeSize of the windows
EElliptic curve
stackTemporary memory stack to use

Definition at line 1559 of file mphell-curve.c.

◆ ec_point_neg()

void ec_point_neg ( ec_point_ptr  P3,
ec_point_srcptr  P1,
ec_curve_srcptr  E 
)

Set P3 to -P1.

Parameters
P3Resulting point
P1Source point
EElliptic curve

Definition at line 1117 of file mphell-curve.c.

◆ ec_point_norm()

void ec_point_norm ( ec_point_ptr  P,
ec_curve_srcptr  E,
uint8_t  stack 
)

Convert a point in projective or jacobian coordinate to an affine point (x,y)

Parameters
PPoint
EElliptic curve
stackTemporary memory stack to use

Definition at line 799 of file mphell-curve.c.

◆ ec_point_print()

void ec_point_print ( ec_point_srcptr  P,
const uint8_t  base,
const bool  lift,
field_srcptr  k,
uint8_t  stack 
)

Print a description of P.

Parameters
PPoint
baseBase used to print the coordinates (either 10 or 16)
liftIf Montgomery is used, lift P coordinates to classical fp.
kBase field
stackTemporary memory stack to use

Definition at line 1064 of file mphell-curve.c.

◆ ec_point_random()

void ec_point_random ( ec_point_ptr  P,
ec_curve_srcptr  E,
uint8_t  stack 
)

Create a random point P on the elliptic curve E.

Parameters
PDestination point
EElliptic curve
stackTemporary memory stack to use

Definition at line 885 of file mphell-curve.c.

◆ ec_point_relax_pool_elt()

void ec_point_relax_pool_elt ( ec_point_ptr  P,
field_ptr  k,
uint8_t  stack 
)
inlinestatic

Relax an initialised point from the pool.

Parameters
PPoint
kBase field
stackTemporary memory stack to use

Definition at line 218 of file mphell-curve.h.

◆ ec_point_set()

void ec_point_set ( ec_point_ptr  P,
fe_srcptr  x,
fe_srcptr  y,
fe_srcptr  z,
fe_srcptr  t,
field_srcptr  k 
)

Set a point from its coordinates.

Parameters
PDestination point
xx-coordinate of P
yy-coordinate of P
zz-coordinate of P
tt-coordinate of P
kBase field

Definition at line 718 of file mphell-curve.c.

◆ ec_point_set_aff()

void ec_point_set_aff ( ec_point_ptr  P,
fe_srcptr  x,
fe_srcptr  y,
const ec_type  type,
field_srcptr  k,
uint8_t  stack 
)

Set a point from its affine coordinates.

Parameters
PDestination point
xx-coordinate of P
yy-coordinate of P
typeType of elliptic curve
stackTemporary memory stack to use

Definition at line 739 of file mphell-curve.c.

◆ ec_point_set_aff_str()

void ec_point_set_aff_str ( ec_point_ptr  P,
const char *  str_x,
const char *  str_y,
const bool  is_reduced,
const uint8_t  base,
const ec_type  type,
field_srcptr  k,
uint8_t  stack 
)

Set a point from its affine coordinates under string format.

Parameters
PDestination point
xx-coordinate of P under string form
yy-coordinate of P under string form
is_reducedTrue if the coordinates are already reduced in k, false otherwise
baseBase used to read the coordinate (either 10 or 16)
typeType of elliptic curve
kBase field
stackTemporary memory stack to use

Definition at line 759 of file mphell-curve.c.

◆ ec_point_set_neutral()

void ec_point_set_neutral ( ec_point_ptr  dst,
ec_curve_srcptr  E,
uint8_t  stack 
)

Set dst to the neutral element.

Parameters
dstDestination point
EElliptic curve
stackTemporary memory stack to use

Definition at line 780 of file mphell-curve.c.

◆ ec_point_set_str()

void ec_point_set_str ( ec_point_ptr  P,
const char *  str_x,
const char *  str_y,
const char *  str_z,
const char *  str_t,
const bool  is_reduced,
const uint8_t  base,
field_srcptr  k,
uint8_t  stack 
)

Set a point from its coordinates under string format.

Parameters
PDestination point
xx-coordinate of P under string form
yy-coordinate of P under string form
zz-coordinate of P under string form
tt-coordinate of P under string form
is_reducedTrue if the coordinates are already in Montgomery form, false otherwise
baseBase used to read the coordinate (either 10 or 16)
kBase field
stackTemporary memory stack to use

Definition at line 728 of file mphell-curve.c.

◆ ec_point_str()

void ec_point_str ( char **  str,
ec_point_srcptr  P,
const uint8_t  base,
const bool  lift,
field_srcptr  k,
uint8_t  stack 
)

Allocate *str and write in it the description of P.

Parameters
strPointer to a string, allocated by the function.
PPoint
baseBase used to write the coordinates (either 10 or 16)
liftIf Montgomery is used, lift P coordinates to classical fp.
kBase field
stackTemporary memory stack to use

Definition at line 1045 of file mphell-curve.c.

◆ ec_point_sub()

void ec_point_sub ( 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)

Parameters
P3Resulting point
P1Source point
P2Source point
EElliptic curve
stackTemporary memory stack to use

Definition at line 1332 of file mphell-curve.c.

◆ ec_point_sub_unified()

void ec_point_sub_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)

Parameters
P3Resulting point
P1Source point
P2Source point
EElliptic curve
stackTemporary memory stack to use

Definition at line 1185 of file mphell-curve.c.

◆ ec_random()

void ec_random ( ec_curve_ptr  E,
const char *  id_curve,
char *  seed_res,
field_srcptr  k,
const ec_type  type,
const ec_formula  f,
uint8_t  stack 
)

Create a random elliptic curve E, not cryptographically secure (not tested to be). Algorithm A.3.3.2 from ANS X9.62-1998.

Parameters
EElliptic curve, previously allocated
id_curveName of the curve
seed_resRandom seed use to generate the curve, 160 bits under hexadecimal form. Use a string of length 41 to store it.
typeType of elliptic curve
fType of coordinate system
stackTemporary memory stack to use

Definition at line 495 of file mphell-curve.c.

◆ ec_set_fast_dedicated_coordinates()

void ec_set_fast_dedicated_coordinates ( ec_curve_ptr  E)

Set the fastest dedicated coordinates system.

Parameters
EElliptic curve

Definition at line 562 of file mphell-curve.c.

◆ ec_set_fast_unified_coordinates()

void ec_set_fast_unified_coordinates ( ec_curve_ptr  E)

Set the fastest unified coordinates system.

Parameters
EElliptic curve

Definition at line 544 of file mphell-curve.c.

◆ ec_test_spec()

void ec_test_spec ( ec_curve_ptr  E,
uint8_t  stack 
)

Set the E->ec_spec1 to true if E->a = -3 mod p, false otherwise.

Parameters
EElliptic curve
stackTemporary memory stack to use

Definition at line 599 of file mphell-curve.c.

◆ ec_use_curve()

void ec_use_curve ( ec_curve_ptr  E,
field_ptr  k,
const ec_known_curve  id_curve,
const ec_formula  f,
uint8_t  stack 
)

Create the elliptic curve (and the associated base field) id_curve, the curve and the field must me allocated (field_alloc & ec_alloc).

Parameters
EElliptic curve, previously allocated
kBase field, previously allocated
id_curveName of the curve, see ec_known_curve_enum
fType of coordinate system
stackTemporary memory stack to use

Definition at line 114 of file mphell-curve.c.

◆ ec_verify_random_generation()

bool ec_verify_random_generation ( ec_curve_ptr  E,
const char *  seed,
uint8_t  stack 
)

Test if E if generated from the seed "seed", using algorithm A.3.4.2 from ANS X9.62-1998. Only curve generated with the algorithm A.3.3.2 can be tested.

Parameters
EElliptic curve to test
seedSeed (of 160 bits) used to generate an elliptic curve, under hexadecimal form.
stackTemporary memory stack to use
Returns
true if E is generated from seed
false otherwise

Definition at line 523 of file mphell-curve.c.

◆ edwards_point_to_weierstrass_point()

void edwards_point_to_weierstrass_point ( ec_point_ptr  dst,
ec_point_srcptr  P,
ec_curve_srcptr  E,
uint8_t  stack 
)

Convert the Edwards point P of the elliptic curve E to the corresponding Weierstrass elliptic curve point dst.

Parameters
dstElliptic curve destination point
PElliptic curve point
EEdwards Elliptic curve
stackTemporary memory stack to use

Definition at line 2247 of file mphell-curve.c.

◆ edwards_to_weierstrass()

void edwards_to_weierstrass ( ec_curve_ptr  E_res,
ec_curve_srcptr  E,
uint8_t  stack 
)

Convert the Edwards elliptic curve E to the corresponding Weierstrass elliptic curve E_res.

Parameters
E_resWeierstrass Elliptic curve
EEdwards Elliptic curve
stackTemporary memory stack to use

Definition at line 2144 of file mphell-curve.c.

◆ jacobi_quartic_point_to_weierstrass_point()

void jacobi_quartic_point_to_weierstrass_point ( ec_point_ptr  dst,
ec_point_srcptr  P1,
ec_curve_srcptr  E,
uint8_t  stack 
)

Convert a point on a jacobi quartic elliptic curve to a point on a weierstrass elliptic curve.

Parameters
dstResulting point (weierstrass point)
PSource point (jacobi quartic point)
EElliptic curve (Jacobi quartic)
stackTemporary memory stack to use

Definition at line 1816 of file mphell-curve.c.

◆ jacobi_quartic_to_weierstrass()

void jacobi_quartic_to_weierstrass ( ec_curve_ptr  E_res,
ec_curve_srcptr  E,
uint8_t  stack 
)

Convert a jacobi quartic elliptic curve into a Weierstrass elliptic curve.

Parameters
E_resResulting elliptic curve (Weierstrass)
ESource elliptic curve (Jacobi quartic)
stackTemporary memory stack to use

Definition at line 1888 of file mphell-curve.c.

◆ weierstrass_point_to_edwards_point()

void weierstrass_point_to_edwards_point ( ec_point_ptr  dst,
ec_point_srcptr  P,
ec_curve_srcptr  E,
const uint8_t  n,
fe_ptr  alpha,
fe_ptr  beta,
uint8_t  stack 
)

Convert the point of the Weierstrass elliptic curve E to the elliptic curve of one of the corresponding Edwards elliptic curve according to the choice (or not) of alpha and/or beta.

Parameters
dstEdwards Elliptic curve destination point
PWeierstrass Elliptic curve point
EEdwards Elliptic curve
nInteger indicating the number of variables between alpha and beta fixed by the user 2 if the both are fixed 1 if only alpha is fixed and 0 if the choice is let to the program
alphaField element
betaField element
stackTemporary memory stack to use

Definition at line 2430 of file mphell-curve.c.

◆ weierstrass_point_to_jacobi_quartic_point()

void weierstrass_point_to_jacobi_quartic_point ( ec_point_ptr  dst,
ec_point_srcptr  P1,
ec_curve_srcptr  E,
uint8_t  stack 
)

Convert a point on a weierstrass elliptic curve to a point on a jacobi quartic elliptic curve.

Parameters
dstResulting point (jacobi quartic point)
PSource point (Weierstrass point)
EElliptic curve (Jacobi quartic)
stackTemporary memory stack to use

Definition at line 1949 of file mphell-curve.c.

◆ weierstrass_to_edwards()

void weierstrass_to_edwards ( ec_curve_ptr  E_res,
ec_curve_srcptr  E,
const uint8_t  n,
fe_ptr  alpha,
fe_ptr  beta,
uint8_t  stack 
)

Convert the Weierstrass elliptic curve E to the one of the corresponding Edwards elliptic curve according to the choice (or not) of alpha and/or beta.

Parameters
E_resEdwards Elliptic curve
EWeierstrass Elliptic curve
nInteger indicating the number of variables between alpha and beta fixed by the user 2 if the both are fixed 1 if only alpha is fixed and 0 if the choice is let to the program
alphaField element
betaField element
stackTemporary memory stack to use

Definition at line 2308 of file mphell-curve.c.

◆ weierstrass_to_jacobi_quartic()

void weierstrass_to_jacobi_quartic ( ec_curve_ptr  E_res,
ec_curve_srcptr  E,
const bool  determined,
fe_ptr  teta,
uint8_t  stack 
)

Convert a Weierstrass elliptic curve into a jacobi quartic elliptic curve.

Parameters
E_resResulting elliptic curve (Jacobi quartic)
ESource elliptic curve (Weierstrass)
determinedBoolean equals to false if theta is not specified then we make the assumption that b_j=1 otherwise theta is specified
tetaField element such as (teta, 0) is a 2-torsion point on E
stackTemporary memory stack to use

Definition at line 2028 of file mphell-curve.c.