27 #include "mphell/mphell.h"
51 number_set_str(p,
"7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed", 16);
52 #if MPHELL_USE_AMNS == 1
54 #if MPHELL_USE_AMNS_32 == 0
55 amns_alloc_init_str(&AMNS,
"[7, 5, [-2, 0, 0, 0, 0, 1], 54, 18452995865838783329900129877370266585014740033535441780974987498391596057242, [961252216531765, -808644316442835, 1045474214679914, 876400205157459, 80702276750246], [215521628593942615, 6036461283567564605, 7224436840646086003, 10819948880990321094, 2770174224844310327], [1261219955914665, 2245748633013857, 1942034862299073, 1713436964429893, 1484033610923007], [982299117090493, 2384806805124374, 473263249613373, 1302309306467128, 767899215173126]]", p);
57 amns_alloc_init_str(&AMNS,
"[1, 13, [-2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1], 24, 27348853913383126840958695328985844583331474485808319900533972989426705703935, [295765, -240077, -384002, 86822, 427979, -178061, 355024, 35335, -47509, 293623, -162279, 239276, -54823], [304002351, 603274027, 987322065, 611192953, 899268748, 456421020, 1804479788, 151565031, 3376928416, 3404037305, 3106617823, 3555398377, 1245081753], [420571, 1005149, 1316639, 803101, 880079, 1425571, 78727, 673803, 292695, 429454, 603140, -81310, 484327], [-78425, 649592, 1210799, 537480, 931731, 330032, 587956, 604351, 932082, 256513, 633201, 50270, 916590]]", p);
59 field_set_amns(k, AMNS);
79 field_elt_set_str(a,
"178bccfe3009fb7a6adc25a5981cc87fcb86f5d89097a446249d137d8676d379", 16,
false, k, STACK_1);
80 field_elt_set_str(b,
"55f4c3f0ed6ed8e9501feca7866d4e8d70d9960f148207bf7d618f19d7fe4169", 16,
false, k, STACK_1);
81 ec_point_set_aff_str(G,
"460ed8dffbd2fc64813be575cc7034ba059bfb51e03357653b07c4f6b00f8859",
"361e0dc66944371de8e1860980b5c14414d5bf32c315a5a5374e38f87126c0c1",
false, 16,
WEIERSTRASS, k, STACK_1);
95 ec_create (E_ed,
"RandP25519_rank2_Edwards", k, a, b, G, h, n,
EDWARDS,
EXTENDED_EDWARDS, STACK_1);
97 printf(
"The edwards departing curve \nE_ed: \n");
ec_curve_print(E_ed, 16, STACK_1); printf(
"\n");
102 printf(
"random point, res_ed = ");
ec_point_print(res_ed, 16,
true, k, STACK_1); printf(
"\n");
103 printf(
"res_ed belongs to E_ed : %d\n\n",
edwards_belongs(res_ed, E_ed, STACK_1));
109 printf(
"The Weierstrass curve isomorphic to E_ed calculated \n");
115 printf(
"Weierstrass random point, res = ");
ec_point_print(res, 16,
true, k, STACK_1); printf(
"\n");
129 #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 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.
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_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_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 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 p...
void edwards_point_random(ec_point_ptr P, ec_curve_srcptr E, uint8_t stack)
Set P to a random point on E.
bool edwards_belongs(ec_point_srcptr P, ec_curve_srcptr E, uint8_t stack)
Test if P belongs to E.
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.
bool weierstrass_belongs(ec_point_srcptr P, ec_curve_srcptr E, uint8_t stack)
Test if P belongs to E.
Define an elliptic curve.
Define an elliptic curve point.