27 #include "mphell/mphell.h"
47 number_set_str(p,
"fffffffffffffffffffffffffffffffeffffffffffffffff", 16);
48 #if MPHELL_USE_AMNS == 1
50 #if MPHELL_USE_AMNS_32 == 0
51 amns_alloc_init_str(&AMNS,
"[16, 4, [-2, 0, 0, 0, 1], 52, 6172336866035235830030737468594796900503843124202341567269, [276558595304361, 45414025950417, -34859774231597, -43697934106541], [15163021665183677629, 10328824020132901291, 3520630562803742874, 2017188797426544734], [175018852767439, 167878561785955, 39999505818260, -16528460836324], [197873551048475, 174802838528544, 29957080636796, 208984152402038]]", p);
53 amns_alloc_init_str(&AMNS,
"[1, 9, [-2, 0, 0, 0, 0, 0, 0, 0, 0, 1], 25, 778621639070749301272595529543640079614006395911121441202, [701093, -169839, 992868, -808873, -49859, -1298542, 346565, 1453220, 10927], [3371333987, 1139504849, 3063325107, 1068215102, 2225669310, 3489025068, 823765184, 3434826107, 24083075], [2398376, 1499579, -352758, -1034120, -179340, 1441412, 1982754, 1026111, 990222], [1506274, 1189710, -669416, 2638499, 1835063, 598693, 1905562, -10756, 308592]]", p);
55 field_set_amns(k, AMNS);
83 field_elt_set_str(a,
"fffffffffffffffffffffffffffffffefffffffffffffffc", 16,
false, k, STACK_1);
84 field_elt_set_str(b,
"64210519e59c80e70fa7e9ab72243049feb8deecc146b9b1", 16,
false, k, STACK_1);
85 ec_point_set_aff_str(G,
"188da80eb03090f67cbf20eb43a18800f4ff0afd82ff1012",
"07192b95ffc8da78631011ed6b24cdd573f977a11e794811",
false, 16,
WEIERSTRASS, k, STACK_1);
86 number_set_str(h,
"000000000000000000000000000000000000000000000001", 16);
87 number_set_str(n,
"ffffffffffffffffffffffff99def836146bc9b1b4d22831", 16);
89 ec_create(E,
"Weierstrass_test", k, a, b, G, h, n,
WEIERSTRASS,
PROJECTIVE, STACK_1);
113 ec_point_set_aff_str(x,
"3a6e0e0135079698f34344bb2261a5fa0730419b639b45ca",
"52c86dc001c77804f6a1e9ab8e5ac4627727919a68993692",
false, 16,
WEIERSTRASS, k, STACK_1);
114 ec_point_set_aff_str(y,
"8cf9058484386d660331a5ef852002360c00d5c940010c33",
"2ec3235f6b5eeec13bc3c206b47e60cf715966c67c6e292a",
false, 16,
WEIERSTRASS, k, STACK_1);
119 printf(
"x+y = ");
ec_point_print(res, 16,
true, k, STACK_1); printf(
"\n");
120 printf(
"x+y belongs to E : %d\n\n",
ec_belongs(res, E, STACK_1));
125 printf(
"x-y = ");
ec_point_print(res, 16,
true, k, STACK_1); printf(
"\n");
126 printf(
"x-y belongs to E : %d\n\n",
ec_belongs(res, E, STACK_1));
131 printf(
"x*2 = ");
ec_point_print(res, 16,
true, k, STACK_1); printf(
"\n");
132 printf(
"x*2 belongs to E : %d\n\n",
ec_belongs(res, E, STACK_1));
137 printf(
"-x = ");
ec_point_print(res, 16,
true, k, STACK_1); printf(
"\n");
138 printf(
"-x belongs to E : %d\n\n",
ec_belongs(res, E, STACK_1));
144 number_set_str(m,
"3a6e0e0135079698f34344bb2261a5fa0730419b639b45ca", 16);
146 printf(
"x*3a6e0e0135079698f34344bb2261a5fa0730419b639b45ca = ");
ec_point_print(res, 16,
true, k, STACK_1); printf(
"\n");
147 printf(
"x*3a6e0e0135079698f34344bb2261a5fa0730419b639b45ca belongs to E : %d\n\n",
ec_belongs(res, E, STACK_1));
154 printf(
"random point, res = ");
ec_point_print(res, 16,
true, k, STACK_1); printf(
"\n");
155 printf(
"res belongs to E : %d\n\n",
ec_belongs(res, E, STACK_1));
162 #if MPHELL_USE_AMNS == 1
void amns_free(amns_ptr *AMNS)
Free the amns system.
void amns_alloc_init_str(amns_ptr *AMNS, char *str, number p)
Allocate and initialise the amns system from the string generated by the Sage AMNS generator from htt...
void ec_curve_print(ec_curve_srcptr E, const uint8_t base, uint8_t stack)
Print a description of E.
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.
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)
bool ec_belongs(ec_point_srcptr P, ec_curve_srcptr E, uint8_t stack)
Test if P belongs to E.
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...
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.
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)
void ec_free(ec_curve_ptr E)
Free the elliptic curve E.
void ec_init(ec_curve_ptr E, field_srcptr k)
Initialise a curve.
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)
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.
void ec_point_neg(ec_point_ptr P3, ec_point_srcptr P1, ec_curve_srcptr E)
Set P3 to -P1.
void ec_point_init(ec_point_ptr P, field_srcptr k)
Initialise an elliptic curve point.
void ec_point_free(ec_point_ptr P, field_srcptr k)
Free the point P.
void ec_point_alloc(ec_point_ptr P, field_srcptr k)
Allocate an elliptic curve point.
void ec_alloc(ec_curve_ptr E, field_srcptr k)
Allocate a curve.
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)
void field_elt_free(fe_ptr *src, field_srcptr k)
Free space used by src.
void field_alloc(field_ptr k, const field_type type, const uint8_t size, field_ptr base)
Allocates space for the different fields of the structure pointed by k.
void field_elt_set_str(fe_ptr dst, const char *str, const uint8_t base, const bool isreduced, field_srcptr k, uint8_t stack)
Set dst to str, if Montgomery arithmetic is used, is_reduced == false -> transform dst into its Montg...
void field_elt_init(fe_ptr dst, field_srcptr k)
Initialise the field element.
void field_elt_alloc(fe_ptr *dst, field_srcptr k)
Allocate space for a field element.
void field_free(field_ptr k)
Free the space of the field informations structure.
void field_create(field_ptr k, const char *id, uint8_t stack, const uint32_t n,...)
Initialize the different fields of the structure pointed by k.
field_t field[1]
Address of a field structure.
fp_elt * field_elt
Generic field element.
void free_mphell()
Free MPHELL memory, especially the big amount of temporary memory.
void init_mphell(const uint16_t security_strength, const random_type type, const entropy_type entropy)
Initialise MPHELL with security_strength bits of security (for random number only).
void number_free(number *dst)
Free a number_ptr allocated on the RAM memory (malloc)
void number_set_str(number_ptr dst, const char *str, const uint8_t base)
Set dst to str.
void number_init(number *dst, const uint8_t n)
Allocate a number_ptr on the RAM memory (malloc)
uint8_t bits_to_nblock(const uint16_t nbits)
Return the number of blocks required to store a nbits number.
Define an elliptic curve.
Define an elliptic curve point.