27 #include "mphell/mphell.h"
52 number_set_str(p,
"fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffeffffffff0000000000000000ffffffff", 16);
53 #if MPHELL_USE_AMNS == 1
55 #if MPHELL_USE_AMNS_32 == 0
56 amns_alloc_init_str(&AMNS,
"[0, 7, [-2, 0, 0, 0, 0, 0, 0, 1], 59, 8010427042960414838884725536003025378504357914088932113335334539926383793809451548018236227209625700052722361381087, [-8576931003528147, 12963241998501462, -11685779024318585, 12198217901242760, 5469056521909520, -16952339206744690, -7801587214757611], [936600828956320511, 17864700281010200544, 7457034104920941375, 4906978974859566336, 1521310033682434027, 11977106235113612084, 6613199331606154624], [-48661600919137196, -16406260014740521, -9043881017757559, -15840327204754192, -4503903233538141, -10931797952018020, 3933578076642458], [-10700965224081570, -31747207631521220, -21134995866173053, -3985617456248275, -932744058138743, -25427794319760237, -2489368063126092]]", p);
58 amns_alloc_init_str(&AMNS,
"[0, 18, [-2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1], 26, 28816340648335589686749390875939188706868735452517709312097740458242732054770156839198296353641579295263032233716200, [-51353, 1463368, 1158979, 544183, -726450, 976213, 144497, -886193, -264198, 688818, 1070182, -170086, 864472, -144241, -360825, -510521, 1017098, -59072], [3993315613, 3730700630, 867896355, 1312786307, 471958917, 4205419201, 2925107995, 1257333470, 1009072108, 3882493844, 334530385, 923966745, 2062755457, 1054721524, 1062123069, 2491481070, 813468425, 1351925765], [1499105, 1805368, 3513276, 2380622, 4551927, 3187369, 3810913, 2129326, 3493684, 1909307, 1981401, 2013148, 1633911, 2996996, 2975679, 3661385, 2455278, 1909836], [5854047, 6627253, 2246346, 3861327, 2251173, 2334257, 1163302, 3551220, 4498564, 4312125, 4221299, 3184071, 2952719, 307544, 1633107, 2468475, 2132615, 2940733]]", p);
60 field_set_amns(k, AMNS);
83 field_elt_set_str(a,
"e6d121fc8cfc85448e51524d40b0a3f6146006a7e2001270385be91a918ba0c2066c8ae2615a9bf927b73c9756bce6b2", 16,
false, k, STACK_1);
84 field_elt_set_str(b,
"a36e0555338282573d94a77351044dfad63d30aac6505bcd470ad021e3a4b057d81fc21d6c92ef0190798b386c38f9ba", 16,
false, k, STACK_1);
85 ec_point_set_aff_str(G,
"a3f0d2b9cbda17b9201391877f744cbc69f7efe29f56e2552439582e70238edbdb70193133bae1d9a8b659d2d7692931",
"c467049b488e283fdf78669237ca9387b347f63d17ce4fac5e6bbe737b4d8e306dfcb80eee28477ab6a0e06f262e47d2",
false, 16,
WEIERSTRASS, k, STACK_1);
86 number_set_str(h,
"15ad3c423d6df1572016199efaeee94ca5242a87a4", 16);
87 number_set_str(n,
"bcf569c46c00fa8b5f4c7d41b55e14295468dac4097918b25e24499", 16);
99 ec_create(E,
"RandP384", k, a, b, G, h, n,
WEIERSTRASS,
PROJECTIVE, STACK_1);
101 printf(
"The weierstrass departing curve \nE: \n");
ec_curve_print(E, 16, STACK_1); printf(
"\n");
106 printf(
"random point, res = ");
ec_point_print(res, 16,
true, k, STACK_1); printf(
"\n");
114 printf(
"The Jacobi Quartic curve isomorphic to E calculated with teta not specified \n");
115 printf(
"E_jq: \n");
ec_curve_print(E_jq, 16, STACK_1); printf(
"\n");
120 printf(
"The Jacobi Quartic curve calculated with teta specified \n");
121 printf(
"E_jq: \n");
ec_curve_print(E_jq, 16, STACK_1); printf(
"\n");
126 printf(
"Jacobi Quartic random point, res_jq = ");
ec_point_print(res_jq, 16,
true, k, STACK_1); printf(
"\n");
143 #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 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.
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 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.
void ec_alloc(ec_curve_ptr E, field_srcptr k)
Allocate a curve.
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).
bool jacobi_quartic_belongs(ec_point_srcptr P, ec_curve_srcptr E, uint8_t stack)
Test if P belongs to E.
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.
void weierstrass_point_random(ec_point_ptr P, ec_curve_srcptr E, uint8_t stack)
Set P to a random point on E.
Define an elliptic curve.
Define an elliptic curve point.