27 #include "mphell/mphell.h"
47 number_set_str(p,
"be6dc5f3bca8726edc8d23dfc89f5922e12826336befbd97ef9ad755aed3ed6f", 16);
48 #if MPHELL_USE_AMNS == 1
50 #if MPHELL_USE_AMNS_32 == 0
51 amns_alloc_init_str(&AMNS,
"[0, 5, [-6, 0, 0, 0, 0, 1], 57, 44134701894072756517992406439939382337596284345171970203125925716993129846274, [-1939549337373671, 708696650251603, 616446424117022, -270633066730404, -269473850007751], [14232251200044510573, 4260484453063696759, 4938517571905539303, 2477203899352903241, 3258824572076821322], [1880138338567364, -362418483091120, -2334430047399656, -961228302577878, -1161931871488864], [1012327336219117, -1831319554880961, -2182294994899370, -1583169082714144, -77840767700580]]", p);
53 amns_alloc_init_str(&AMNS,
"[0, 11, [-2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1], 27, 69317213738462846735478356472869330750901370837161460878148112172418640423363, [-5039301, -1520710, -682737, 4129377, -118479, 1256754, -165686, 1815325, 2205654, 691178, 3197604], [1642640743, 189102586, 3036257609, 684006625, 2212997898, 3596497786, 2141343760, 4249772178, 3100687204, 806414425, 3135734599], [9681601, 10211069, 6826356, 9674975, 8405458, 11101131, 9893709, 13350564, 5638277, 4060091, -490421], [1482320, 15811726, 4656409, 7974077, 9066791, 6298774, 9545427, 3237750, 6208594, -135406, 5934996]]", p);
55 field_set_amns(k, AMNS);
83 field_elt_set_str(a,
"49f59d6eae84c3d20838901b12eb680503e0c84c9438b2343e7cd5f750b2ccdf", 16,
false, k, STACK_1);
86 ec_point_set_str(G,
"27e09c4f00f1e6f7763e63e8cd0939c910b5cff8e9deecafe41b2933ab8adf27",
"b18a89ba34ad9fee919d49cbf816a22be34778e54ac6498ba29a17db22732673",
"78289546d596f34a9fc8e2fd46ebe745c354d1853183a42deac29ea956b114d0",
"4c075c65a97f10ff49bc6c8a223957fc99eca98df4a998165d96d31b138a5a97",
false, 16, k, STACK_1);
87 number_set_str(n,
"2f9b717cef2a1c9bb72348f7f227d648e20a240c39f62f5f1cf3643f55d42cb1", 16);
88 number_set_str(h,
"0000000000000000000000000000000000000000000000000000000000000004", 16);
90 ec_create (E,
"Jacobi_test", k, a, b, G, h, n,
JACOBI_QUARTIC,
PROJECTIVE, STACK_1);
114 ec_point_set_aff_str (x,
"38255193717143657873171169431252446125914975555408103986804661333889508186792",
"56879352098683955683913475804414516257891196368009685803867282765611829589550",
false, 10,
JACOBI_QUARTIC, k, STACK_1);
115 ec_point_set_aff_str (y,
"6481597564264008301482198835779793377095770727839417835648754067898733644793",
"72836348899108920838208922130674404413346456085043969930205677190313902908769",
false, 10,
JACOBI_QUARTIC, k, STACK_1);
120 printf(
"x+y = ");
ec_point_print(res, 16,
true, k, STACK_1); printf(
"\n");
121 printf(
"x+y belongs to E : %d\n\n",
ec_belongs(res, E, STACK_1));
126 printf(
"x-y = ");
ec_point_print(res, 16,
true, k, STACK_1); printf(
"\n");
127 printf(
"x-y belongs to E : %d\n\n",
ec_belongs(res, E, STACK_1));
132 printf(
"x*2 = ");
ec_point_print(res, 16,
true, k, STACK_1); printf(
"\n");
133 printf(
"x*2 belongs to E : %d\n\n",
ec_belongs(res, E, STACK_1));
138 printf(
"-x = ");
ec_point_print(res, 16,
true, k, STACK_1); printf(
"\n");
139 printf(
"-x belongs to E : %d\n\n",
ec_belongs(res, E, STACK_1));
145 number_set_str(n1,
"6481597564264008301482198835779793377095770727839417835648754067898733644745", 10);
147 printf(
"x*6481597564264008301482198835779793377095770727839417835648754067898733644745 = ");
ec_point_print(res, 16,
true, k, STACK_1); printf(
"\n");
148 printf(
"x*6481597564264008301482198835779793377095770727839417835648754067898733644745 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));
164 #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)
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.
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.
void field_elt_set_one(fe_ptr dst, field_srcptr k)
Set dst to one (or its Montgomery form if Montgomery arithmetic is used)
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.