69 param->
size = base->size;
140 param->
size = (uint8_t)0;
228 const bool isreduced,
const fp2_param param, uint8_t stack)
243 const bool isreduced,
const fp2_param param, uint8_t stack)
245 char *s = (
char*) malloc(
sizeof(
char)*strlen(str)+10);
249 char *str1, *str2 = NULL;
250 str1 = strsep(&s,
",");
251 str2 = strsep(&s,
",");
252 MPHELL_ASSERT_ALWAYS((str1!= NULL) && (str2 != NULL),
253 "fp2_elt_set_str : invalid string");
276 char *base_str, *non_residue_str, *q_str;
282 *str = (
char*)malloc(100 + strlen(base_str) + strlen(q_str) +
283 strlen(non_residue_str));
285 sprintf(s,
"base parameter \n%s\nnon residue quadratic = %s\norder = %s",
286 base_str, non_residue_str, q_str);
290 free(non_residue_str);
295 const bool lift,
const fp2_param param, uint8_t stack)
300 *str = malloc(strlen(str1) + strlen(str2) + 4);
301 sprintf(*str,
"%s,%s", str1, str2);
564 while (m != (block)0)
583 #if MPHELL_USE_GMP == 1 585 #elif MPHELL_USE_IPP == 1 587 ippsRef_BN(NULL, &size, NULL, n);
589 #elif MPHELL_USE_MBEDTLS == 1 606 #if MPHELL_USE_GMP == 1 608 #elif MPHELL_USE_IPP == 1 610 #elif MPHELL_USE_MBEDTLS == 1 699 #if MPHELL_USE_GMP == 1 701 #elif MPHELL_USE_IPP == 1 703 ippsRef_BN(NULL, &size, NULL, n);
705 #elif MPHELL_USE_MBEDTLS == 1 716 #if MPHELL_USE_GMP == 1 718 #elif MPHELL_USE_IPP == 1 720 #elif MPHELL_USE_MBEDTLS == 1 730 #if MPHELL_USE_GMP == 1 732 #elif MPHELL_USE_IPP == 1 734 #elif MPHELL_USE_MBEDTLS == 1 755 #if MPHELL_USE_GMP == 1 757 #elif MPHELL_USE_IPP == 1 759 ippsRef_BN(NULL, &size, NULL, param->
p_odd);
761 #elif MPHELL_USE_MBEDTLS == 1 780 #if MPHELL_USE_GMP == 1 782 #elif MPHELL_USE_IPP == 1 784 #elif MPHELL_USE_MBEDTLS == 1 794 MPHELL_ASSERT_ALWAYS(m <= param->p_even,
"fp_elt_sqrt : \ 798 while (m < param->p_even - 1)
808 #if MPHELL_USE_GMP == 1 810 #elif MPHELL_USE_IPP == 1 812 #elif MPHELL_USE_MBEDTLS == 1 827 block pow = (block)1;
831 fp2_elt b, c1, c2, h, r, d, tmp1;
886 for(i=1; i<= (s-1); i++)
967 block prime[20]={2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71};
996 while(test ==
false);
bool number_isdiff_ui(number_srcptr src1, const block src2)
Test if src1 != src2.
bool number_iszero(number_srcptr src)
Test if src is zero.
void fp2_elt_set_one(fp2_elt_ptr dst, const fp2_param param)
Set dst to one (or its Montgomery form if Montgomery arithmetic is used)
void fp2_elt_alloc(fp2_elt *dst, const fp2_param param)
Allocate space for a quadratic extension field element.
int8_t fp_elt_cmp(fp_elt_srcptr src1, fp_elt_srcptr src2, const fp_param param)
Compare src1 and src2 in Fp.
static void fp_elt_add(fp_elt_ptr dst, fp_elt_srcptr src1, fp_elt_srcptr src2, const fp_param param)
Set dst <- src1 + src2.
void fp2_elt_primitive_elt(fp2_elt_ptr dst, const fp2_param param, uint8_t stack)
Find a possible primitive element in the field defined by param.
void fp2_alloc(fp2_param param, const fp_param base)
Allocate space for the quadratic extension field informations structure.
void fp2_elt_sqrt(fp2_elt_ptr dst, fp2_elt_srcptr src, const fp2_param param, uint8_t stack)
Set dst <- src^(1/2), using Tonelli–Shanks algorithm.
void fp2_elt_clear(fp2_elt *src)
Clear space used by src (remove the action of fp2_elt_init but less the one of fp2_elt_alloc)
void fp2_elt_copy(fp2_elt_ptr dst, fp2_elt_srcptr src, const fp2_param param)
Copy src into dst, src and dst must belong to the same FP2.
void fp2_elt_mul(fp2_elt_ptr dst, fp2_elt_srcptr src1, fp2_elt_srcptr src2, const fp2_param param, uint8_t stack)
Set dst <- src1 * src2, if Montgomery arithmetic is used, the Montgomery multiplication will be used ...
void fp2_elt_mul2(fp2_elt_ptr dst, fp2_elt_srcptr src, const fp2_param param)
Set dst <- 2 * src.
void number_mod_ui(block *dst, number_srcptr src1, const block src2)
Compute dst such that src1 = q * src2 + dst ; dst < src2.
void number_div_ui(number_ptr dst, number_srcptr src1, const block src2)
Compute dst such that src1 = dst * src2 + r ; r < src2.
void fp2_elt_lift(fp2_elt_ptr dst, fp2_elt_srcptr src, const fp2_param param, uint8_t stack)
If Montgomery arithmetic is used, lift src (which is into Montgomery form) to classical FP2.
void fp_elt_set_ui(fp_elt_ptr dst, const block src, const bool isreduced, const fp_param param, uint8_t stack)
Set dst to src, if Montgomery arithmetic is used, is_reduced == false -> transform dst into its Montg...
void fp2_elt_unity_nth_root(fp2_elt_ptr dst, const block n, const fp2_param param, uint8_t stack)
Set dst to a non trivial n-th root of unity if it exists (ie n divides q-1), 1 otherwise.
void fp_elt_free(fp_elt *src)
Free space used by src.
void fp2_elt_pow_ui(fp2_elt_ptr dst, fp2_elt_srcptr src, const block n, const fp2_param param, uint8_t stack)
Set dst <- src^n.
void fp2_create(fp2_param param, const fp_param base, fp_elt_srcptr non_residue, uint8_t stack)
Create a quadratic extension of the field base.
void fp2_free(fp2_param param)
Free the space of the quadratic extension field informations structure.
void fp_elt_clear(fp_elt *src)
Clear space used by src (remove the action of fp_elt_init but let the one of fp_elt_alloc)
static void fp_elt_mul8(fp_elt_ptr dst, fp_elt_srcptr src, const fp_param param)
Set dst <- 8 * src.
void number_set_ui(number_ptr dst, const block src)
Set dst to src.
bool number_iseven(number_srcptr src)
Test if src is even.
void fp2_elt_sqr(fp2_elt_ptr dst, fp2_elt_srcptr src, const fp2_param param, uint8_t stack)
Set dst <- src^2.
void fp2_elt_mul3(fp2_elt_ptr dst, fp2_elt_srcptr src, const fp2_param param, uint8_t stack)
Set dst <- 3 * src.
void fp2_elt_set_ui(fp2_elt_ptr dst, const uint64_t src, const bool isreduced, const fp2_param param, uint8_t stack)
Set dst to src, if Montgomery arithmetic is used, is_reduced == false -> transform dst into its Montg...
void fp2_elt_mul8(fp2_elt_ptr dst, fp2_elt_srcptr src, const fp2_param param)
Set dst <- 8 * src.
static void fp_elt_sqr(fp_elt_ptr dst, fp_elt_srcptr src, const fp_param param, uint8_t stack)
Set dst <- src^2.
void fp2_elt_set(fp2_elt_ptr dst, number_srcptr src1, number_srcptr src2, const bool isreduced, const fp2_param param, uint8_t stack)
Set dst to src1 + src2*x, if Montgomery arithmetic is used, is_reduced == false -> transform dst into...
void fp2_elt_neg(fp2_elt_ptr dst, fp2_elt_srcptr src, const fp2_param param)
Set dst <- (-src)
static void fp_elt_relax_pool_elt(fp_elt *dst, const fp_param param, uint8_t stack)
Relax an initialised field element from the pool.
void number_free(number *dst)
Free a number_ptr allocated on the RAM memory (malloc)
void fp2_elt_str(char **str, fp2_elt_srcptr src, const uint8_t base, const bool lift, const fp2_param param, uint8_t stack)
Converts src to string format in base specified by base.
void fp2_elt_sub_fp_elt(fp2_elt_ptr dst, fp2_elt_srcptr src1, fp_elt_srcptr src2, const fp2_param param)
Set dst <- src1 - src2.
void fp2_elt_inc(fp2_elt_ptr dst, fp2_elt_srcptr src, const fp2_param param)
Set dst <- src + 1.
void number_divmod_ui(number_ptr q, block *r, number_srcptr src1, const block src2)
Compute (q, r) such that src1 = q * src2 + r ; r < src2.
int8_t fp2_elt_ispower_ui(fp2_elt_srcptr src, const block n, const fp2_param param, uint8_t stack)
Test if src is a n-power in FP2, using A NOTE ON POWERS IN FINITE FIELDS from ANDREAS AABRANDT AND VA...
void fp2_elt_mul4(fp2_elt_ptr dst, fp2_elt_srcptr src, const fp2_param param)
Set dst <- 4 * src.
void fp2_copy(fp2_param param_res, const fp2_param param)
Copy the quadratic extension field structure param into param_res.
void fp2_elt_random(fp2_elt_ptr dst, const fp2_param param, uint8_t stack)
Set dst to a random element of FP2, the random process is chosen at the MHELL initialisation.
void fp2_elt_cube_root(fp2_elt_ptr dst, fp2_elt_srcptr src, const fp2_param param, uint8_t stack)
Set dst <- src^(1/3)
void fp_elt_copy(fp_elt_ptr dst, fp_elt_srcptr src, const fp_param param)
Copy src into dst, src and dst must belong to the same Fp.
void fp_get_characteristic(number_ptr c, const fp_param param)
Get the characteristic of the prime field "param".
bool fp2_elt_isone(fp2_elt_srcptr src, const fp2_param param)
Test if src is one.
void fp2_elt_inv(fp2_elt_ptr dst, fp2_elt_srcptr src, const fp2_param param, uint8_t stack)
Set dst <- src^(-1)
void fp_str(char **str, const fp_param param, const uint8_t base, uint8_t stack)
Converts fp_param param to string format in base specified by base.
void fp_elt_set_number(fp_elt_ptr dst, number_srcptr src, const bool isreduced, const fp_param param, uint8_t stack)
Set dst to src, if Montgomery arithmetic is used, is_reduced == false -> transform dst into its Montg...
bool fp_elt_isone(fp_elt_srcptr src, const fp_param param)
Test if src is one.
void number_gcd_ui(block *dst, number_srcptr src1, const block src2)
Set dst to GCD(src1, src2)
static void fp_elt_mul(fp_elt_ptr dst, fp_elt_srcptr src1, fp_elt_srcptr src2, const fp_param param, uint8_t stack)
Set dst <- src1 * src2, if Montgomery arithmetic is used, the Montgomery multiplication will be used ...
static void fp_elt_inc(fp_elt_ptr dst, fp_elt_srcptr src, const fp_param param)
Set dst <- src + 1.
static bool fp_elt_iszero(fp_elt_srcptr src, const fp_param param)
Test if src is zero.
block number_and_ui(number_srcptr src1, const block src2, uint8_t stack)
Apply logical bitwise AND operator between src1 and src2.
static void fp_elt_get_pool_elt(fp_elt *dst, const fp_param param, uint8_t stack)
Get an initialised field element from the pool.
static void fp_elt_mul3(fp_elt_ptr dst, fp_elt_srcptr src, const fp_param param, uint8_t stack)
Set dst <- 3 * src.
static void fp_elt_mul2(fp_elt_ptr dst, fp_elt_srcptr src, const fp_param param)
Set dst <- 2 * src.
void number_copy(number_ptr dst, number_srcptr src)
Copy src into dst.
Declaration of binary field (finite field constructed with an irreducible polynomial of degree 2) fun...
void fp2_elt_div(fp2_elt_ptr dst, fp2_elt_srcptr src1, fp2_elt_srcptr src2, const fp2_param param, uint8_t stack)
Set dst <- src1 / src2.
void number_sqr(number_ptr dst, number_srcptr src)
Set dst to src1^2.
bool fp2_elt_issquare(fp2_elt_srcptr src, const fp2_param param, uint8_t stack)
Test if src is a square, using A NOTE ON POWERS IN FINITE FIELDS from ANDREAS AABRANDT AND VAGN LUNDS...
void fp_elt_alloc(fp_elt *dst, const fp_param param)
Allocate space for a primary field element.
void fp_elt_inv(fp_elt_ptr dst, fp_elt_srcptr src, const fp_param param, uint8_t stack)
Set dst <- src^(-1)
void fp2_str(char **str, const fp2_param param, const uint8_t base, uint8_t stack)
Converts fp2_param param to string format in base specified by base.
static void fp_elt_neg(fp_elt_ptr dst, fp_elt_srcptr src, const fp_param param)
Set dst <- (-src) mod p.
void fp2_prepare_sqrt(fp2_param param, uint8_t stack)
Find a non square residue in FP2, factor out q-1 by powers of 2, find Q and S such that q − 1 = Q....
void fp2_elt_print(fp2_elt_srcptr src, const uint8_t base, const bool lift, const fp2_param param, uint8_t stack)
Print src in base "base".
void fp2_elt_relax_pool_elt(fp2_elt *dst, const fp2_param param, uint8_t stack)
Free space of a temporary quadratic extension field element.
void fp_elt_set_zero(fp_elt_ptr dst, const fp_param param)
Set dst to zero.
void fp2_elt_sqr_fp_elt(fp2_elt_ptr dst, fp_elt_srcptr src, const fp2_param param, uint8_t stack)
Set dst <- src^2.
static void fp_elt_mul4(fp_elt_ptr dst, fp_elt_srcptr src, const fp_param param)
Set dst <- 4 * src.
void fp2_elt_div_fp_elt(fp2_elt_ptr dst, fp2_elt_srcptr src1, fp_elt_srcptr src2, const fp2_param param, uint8_t stack)
Set dst <- src1 / src2.
void fp2_elt_mul_fp_elt(fp2_elt_ptr dst, fp2_elt_srcptr src1, fp_elt_srcptr src2, const fp2_param param, uint8_t stack)
Set dst <- src1 * src2, if Montgomery arithmetic is used, the Montgomery multiplication will be used ...
void number_tmp_free(number *t, const uint8_t size, uint8_t stack)
Free a temporary number.
void fp2_elt_init(fp2_elt_ptr dst, const fp2_param param)
Initialise a quadratic extension field element.
void number_dec(number_ptr dst, number_srcptr src)
Set dst to src - 1 if src - 1 fit in dst.
void number_inc(number_ptr dst, number_srcptr src)
Set dst to src + 1 if src + 1 fit in dst.
Quadratic extension field element structure.
int8_t fp2_elt_cmp_fp_elt(fp2_elt_srcptr src1, fp_elt_srcptr src2, const fp2_param param)
Compare src1 and src2 in FP2.
void fp_elt_set_str(fp_elt_ptr dst, const char *str, const uint8_t base, const bool isreduced, const fp_param param, uint8_t stack)
Set dst to str, if Montgomery arithmetic is used, is_reduced == false -> transform dst into its Montg...
void fp2_elt_set_number(fp2_elt_ptr dst, number_srcptr src, const bool isreduced, const fp2_param param, uint8_t stack)
Set dst to src, if Montgomery arithmetic is used, is_reduced == false -> transform dst into its Montg...
void number_tmp_alloc(number *t, const uint8_t size, uint8_t stack)
Allocate a temporary number.
void number_init(number *dst, const uint8_t n)
Allocate a number_ptr on the RAM memory (malloc)
void fp2_elt_pow_number(fp2_elt_ptr dst, fp2_elt_srcptr src, number_srcptr n, const fp2_param param, uint8_t stack)
Set dst <- src^n.
void fp2_elt_add_fp_elt(fp2_elt_ptr dst, fp2_elt_srcptr src1, fp_elt_srcptr src2, const fp2_param param)
Set dst <- src1 + src2.
static void fp_elt_dec(fp_elt_ptr dst, fp_elt_srcptr src, const fp_param param)
Set dst <- src - 1.
void fp2_elt_sub(fp2_elt_ptr dst, fp2_elt_srcptr src1, fp2_elt_srcptr src2, const fp2_param param)
Set dst <- src1 - src2.
int8_t fp2_elt_ispower_number(fp2_elt_srcptr src, number_srcptr n, const fp2_param param, uint8_t stack)
Test if src is a n-power in FP2, using A NOTE ON POWERS IN FINITE FIELDS from ANDREAS AABRANDT AND VA...
void fp2_elt_inv_fp_elt(fp2_elt_ptr dst, fp_elt_srcptr src, const fp2_param param, uint8_t stack)
Set dst <- src^(-1)
void fp_elt_lift(fp_elt_ptr dst, fp_elt_srcptr src, const fp_param param, uint8_t stack)
If Montgomery arithmetic is used, lift src (which is into Montgomery form) to classical fp.
void fp2_elt_neg_fp_elt(fp2_elt_ptr dst, fp_elt_srcptr src, const fp2_param param)
Set dst <- (-src)
void number_rshift(number_ptr dst, number_srcptr src, const uint16_t shift)
Set dst to src >> shift.
Primary field parameters.
static void fp_elt_sub(fp_elt_ptr dst, fp_elt_srcptr src1, fp_elt_srcptr src2, const fp_param param)
Set dst <- src1 - src2.
void fp2_elt_dec(fp2_elt_ptr dst, fp2_elt_srcptr src, const fp2_param param)
Set dst <- src - 1.
void fp2_elt_set_str(fp2_elt_ptr dst, const char *str, const uint8_t base, const bool isreduced, const fp2_param param, uint8_t stack)
Set dst to str, if Montgomery arithmetic is used, is_reduced == false -> transform dst into its Montg...
bool fp2_elt_iszero(fp2_elt_srcptr src, const fp2_param param)
Test if src is zero.
void fp2_elt_set_fp_elts(fp2_elt_ptr dst, fp_elt_srcptr src1, fp_elt_srcptr src2, const fp2_param param)
Set dst to src1 + src2*x.
void fp_elt_random(fp_elt_ptr dst, const fp_param param, uint8_t stack)
Set dst to a random element of Fp, the random process is chosen at the MHELL initialisation.
int8_t number_cmp_ui(number_srcptr src1, const block src2)
Compare src1 and src2.
void number_divmod(number_ptr q, number_ptr r, number_srcptr src1, number_srcptr src2)
Compute (q, r) such that src1 = q * src2 + r ; r < src2.
void fp2_elt_add(fp2_elt_ptr dst, fp2_elt_srcptr src1, fp2_elt_srcptr src2, const fp2_param param)
Set dst <- src1 + src2.
void fp2_get_characteristic(number_ptr c, const fp2_param param)
Get the characteristic of the quadratic extension field "param".
int8_t fp2_elt_cmp(fp2_elt_srcptr src1, fp2_elt_srcptr src2, const fp2_param param)
Compare src1 and src2 in FP2.
void fp_elt_set_one(fp_elt_ptr dst, const fp_param param)
Set dst to one (or its Montgomery form if Montgomery arithmetic is used)
void fp2_get_size(number_ptr c, const fp2_param param)
Get the size of the quadratic extension field "param".
void fp2_elt_get_pool_elt(fp2_elt *dst, const fp2_param param, uint8_t stack)
Allocate and initialise space for a temporary quadratic extension field element.
void fp_elt_str(char **str, fp_elt_srcptr src, const uint8_t base, const bool lift, const fp_param param, uint8_t stack)
Converts src to string format in base specified by base.
Quadratic extension field structure.
void number_str(char **str, number_srcptr src, const uint8_t base)
Converts src to string format in base specified by base.
void fp2_elt_set_fp_elt(fp2_elt_ptr dst, fp_elt_srcptr src, const fp2_param param)
Set dst to src.
void fp_elt_init(fp_elt_ptr dst, const fp_param param)
Initialise a primary field element.
void fp2_elt_free(fp2_elt *src)
Free space used by src.