27 #include "mphell/mphell.h" 41 number_set_str(p,
"8CB91E82A3386D280F5D6F7E50E641DF152F7109ED5456B412B1DA197FB71123ACD3A729901D1A71874700133107EC53", 16);
69 field_elt_set_str(x,
"17533160620960747720658538821194093754122675622398475560762133052267072585559185687559064016240090086860997857609409,6500634679458907167017356094867727707826954836406037804481994709882642877127237360869164454175728327118666667333650,11742847707788052444522195706157812780258053127409735266675287415078850342578399252850159043780127493098080513256739", 10,
false, k3, STACK_1);
70 field_elt_set_str(y,
"4126110149158568452410698021138511225673440764619173039319485451554017348466776134677497966604444001579710560363922,15158636090660409006051880747464877271969161550611610795599623793938447056898724461367397528668805761322041750639681,9916423062331263728547041136174792199538063259607913333406331088742239591447562569386402939064406595342627904716592", 10,
false, k3, STACK_1);
75 printf(
"x+1 = ");
field_elt_print(res, 16,
true, k, STACK_1); printf(
"\n");
78 printf(
"x+y = ");
field_elt_print(res, 16,
true, k, STACK_1); printf(
"\n");
83 printf(
"x-1 = ");
field_elt_print(res, 16,
true, k, STACK_1); printf(
"\n");
86 printf(
"x-y = ");
field_elt_print(res, 16,
true, k, STACK_1); printf(
"\n");
91 printf(
"x*y = ");
field_elt_print(res, 16,
true, k, STACK_1); printf(
"\n");
94 printf(
"x^2 = ");
field_elt_print(res, 16,
true, k, STACK_1); printf(
"\n");
100 printf(
"x/y = ");
field_elt_print(res, 16,
true, k, STACK_1); printf(
"\n");
105 printf(
"x^3 = ");
field_elt_print(res, 16,
true, k, STACK_1); printf(
"\n");
110 printf(
"x^n = ");
field_elt_print(res, 16,
true, k, STACK_1); printf(
"\n");
117 printf(
"x^(-1) = ");
field_elt_print(res, 16,
true, k, STACK_1); printf(
"\n");
122 printf(
"x = ");
field_elt_print(x, 16,
true, k, STACK_1); printf(
"\n");
125 printf(
"x^(1/2) = ");
field_elt_print(res, 16,
true, k, STACK_1); printf(
"\n");
128 printf(
"x = ");
field_elt_print(x, 16,
true, k, STACK_1); printf(
"\n");
131 printf(
"x^(1/3) = ");
field_elt_print(res, 16,
true, k, STACK_1); printf(
"\n");
fp_elt * field_elt
Generic field element.
void free_mphell()
Free MPHELL memory, especially the big amount of temporary memory.
void field_elt_free(fe_ptr *src, field_srcptr k)
Free space used by src.
static void field_elt_mul(fe_ptr dst, fe_srcptr src1, fe_srcptr src2, field_srcptr k, uint8_t stack)
Set dst <- src1 * src2, if Montgomery arithmetic is used, the Montgomery multiplication will be used ...
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).
static void field_elt_inc(fe_ptr dst, fe_srcptr src, field_srcptr k)
Set dst <- src + 1.
uint8_t bits_to_nblock(const uint16_t nbits)
Return the number of blocks required to store a nbits number.
void field_elt_sqrt(fe_ptr dst, fe_srcptr src, field_srcptr k, uint8_t stack)
Set dst <- src^(1/2)
void field_elt_alloc(fe_ptr *dst, field_srcptr k)
Allocate space for a field element.
field_t field[1]
Address of a field structure.
void field_elt_div(fe_ptr dst, fe_srcptr src1, fe_srcptr src2, field_srcptr k, uint8_t stack)
Set dst <- src1 / src2.
void field_elt_cube_root(fe_ptr dst, fe_srcptr src, field_srcptr k, uint8_t stack)
Set dst <- src^(1/3)
void number_free(number *dst)
Free a number_ptr allocated on the RAM memory (malloc)
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.
bool field_elt_issquare(fe_srcptr src, field_srcptr k, uint8_t stack)
Test if src is a square using the Lengendre symbol.
int8_t field_elt_ispower_ui(fe_srcptr src, const block n, field_srcptr k, uint8_t stack)
Test if src is a n-power in src->k.
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.
bool field_find_nonpower_ui(fe_ptr dst, const block n, field_ptr k, uint8_t stack)
Look for a random non n-power element in k.
void field_elt_inv(fe_ptr dst, fe_srcptr src, field_srcptr k, uint8_t stack)
Set dst <- src^(-1)
void field_elt_init(fe_ptr dst, field_srcptr k)
Initialise the field element.
void field_elt_pow_number(fe_ptr dst, fe_srcptr src, number_srcptr n, field_srcptr k, uint8_t stack)
Set dst <- src^n.
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)
void field_elt_print(fe_srcptr src, const uint8_t base, const bool lift, field_srcptr k, uint8_t stack)
Print src in base specified by base.
void field_elt_pow_ui(fe_ptr dst, fe_srcptr src, const block n, field_srcptr k, uint8_t stack)
Set dst <- src^n.
void field_free(field_ptr k)
Free the space of the field informations structure.
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...
static void field_elt_sqr(fe_ptr dst, fe_srcptr src, field_srcptr k, uint8_t stack)
Set dst <- src^2.
static void field_elt_sub(fe_ptr dst, fe_srcptr src1, fe_srcptr src2, field_srcptr k)
Set dst <- src1 - src2.
static void field_elt_dec(fe_ptr dst, fe_srcptr src, field_srcptr k)
Set dst <- src - 1.
static void field_elt_add(fe_ptr dst, fe_srcptr src1, fe_srcptr src2, field_srcptr k)
Set dst <- src1 + src2.
int8_t field_elt_ispower_number(fe_srcptr src, number_srcptr n, field_srcptr k, uint8_t stack)
Test if src is a n-power in src->k.