27 #include "mphell/mphell.h" 41 number_set_str(p,
"fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffeffffffff0000000000000000ffffffff", 16);
69 field_elt_set_str(x,
"25888030203341481017599806294711784662368639501836779649649722493704107869971378062561359493103614745148646490006495,30818930178847386173826179517114528511268570512817196018110767526684990909388933012679657889738193796300356614506500", 10,
false, k2, STACK_1);
70 field_elt_set_str(y,
"13513975993052998194679233805431829142711099768628667018298570910541613901525492266485906595155323256712960483105824,8583076017547093038452860583029085293811168757648250649837525877560730862107937316367608198520744205561250358605819", 10,
false, k2, 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");
99 printf(
"x/y = ");
field_elt_print(res, 16,
true, k, STACK_1); printf(
"\n");
104 printf(
"x^3 = ");
field_elt_print(res, 16,
true, k, STACK_1); printf(
"\n");
109 printf(
"x^n = ");
field_elt_print(res, 16,
true, k, STACK_1); printf(
"\n");
116 printf(
"x^(-1) = ");
field_elt_print(res, 16,
true, k, STACK_1); printf(
"\n");
121 printf(
"x = ");
field_elt_print(x, 16,
true, k, STACK_1); printf(
"\n");
124 printf(
"x^(1/2) = ");
field_elt_print(res, 16,
true, k, STACK_1); printf(
"\n");
127 printf(
"x = ");
field_elt_print(x, 16,
true, k, STACK_1); printf(
"\n");
130 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.
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_find_nonsquare(fe_ptr dst, field_ptr k, uint8_t stack)
Look for a random non square element in 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...
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.