71 param->
size = base->size;
148 param->
size = (uint8_t)0;
152 param->
p_even = (uint32_t)0;
249 number_srcptr src3,
const bool isreduced,
const fp3_param param, uint8_t stack)
266 const bool isreduced,
const fp3_param param, uint8_t stack)
268 char *s = (
char*) malloc(
sizeof(
char)*strlen(str)+10);
272 char *str1, *str2, *str3 = NULL;
273 str1 = strsep(&s,
",");
274 str2 = strsep(&s,
",");
275 str3 = strsep(&s,
",");
276 MPHELL_ASSERT_ALWAYS((str1!= NULL) && (str2 != NULL) && (str3 != NULL),
277 "fp3_elt_set_str : invalid string");
303 char *base_str, *non_residue_str, *q_str;
309 *str = (
char*)malloc(100 + strlen(base_str) + strlen(q_str) +
310 strlen(non_residue_str));
312 sprintf(s,
"base parameter \n%s\nnon residue quadratic = %s\norder = %s",
313 base_str, non_residue_str, q_str);
317 free(non_residue_str);
322 const bool lift,
const fp3_param param, uint8_t stack)
324 char *str1, *str2, *str3;
328 *str = malloc(strlen(str1) + strlen(str2) + strlen(str3) + 10);
329 sprintf(*str,
"%s,%s,%s", str1, str2, str3);
509 fp_elt res0, res1, v0, v1, v2, t1, t2;
584 fp_elt tmp, tmp1, tmp2;
656 while (m != (block)0)
675 #if MPHELL_USE_GMP == 1 677 #elif MPHELL_USE_IPP == 1 679 ippsRef_BN(NULL, &size, NULL, n);
681 #elif MPHELL_USE_MBEDTLS == 1 698 #if MPHELL_USE_GMP == 1 700 #elif MPHELL_USE_IPP == 1 702 #elif MPHELL_USE_MBEDTLS == 1 791 #if MPHELL_USE_GMP == 1 793 #elif MPHELL_USE_IPP == 1 795 ippsRef_BN(NULL, &size, NULL, n);
797 #elif MPHELL_USE_MBEDTLS == 1 808 #if MPHELL_USE_GMP == 1 810 #elif MPHELL_USE_IPP == 1 812 #elif MPHELL_USE_MBEDTLS == 1 822 #if MPHELL_USE_GMP == 1 824 #elif MPHELL_USE_IPP == 1 826 #elif MPHELL_USE_MBEDTLS == 1 846 #if MPHELL_USE_GMP == 1 848 #elif MPHELL_USE_IPP == 1 850 ippsRef_BN(NULL, &size, NULL, param->
p_odd);
852 #elif MPHELL_USE_MBEDTLS == 1 870 #if MPHELL_USE_GMP == 1 872 #elif MPHELL_USE_IPP == 1 874 #elif MPHELL_USE_MBEDTLS == 1 884 MPHELL_ASSERT_ALWAYS(m <= param->p_even,
"fp_elt_sqrt : \ 889 while (m < param->p_even - 1)
899 #if MPHELL_USE_GMP == 1 901 #elif MPHELL_USE_IPP == 1 903 #elif MPHELL_USE_MBEDTLS == 1 918 block pow = (block)1;
922 fp3_elt b, c1, c2, h, r, d, tmp1;
977 for(i=1; i<= (s-1); i++)
1059 block prime[20]={2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71};
1088 while(test ==
false);
void fp3_get_characteristic(number_ptr c, const fp3_param param)
Get the characteristic of the cubic extension field "param".
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.
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 fp3_elt_alloc(fp3_elt *dst, const fp3_param param)
Allocate space for a cubic extension field element.
void fp3_elt_mul(fp3_elt_ptr dst, fp3_elt_srcptr src1, fp3_elt_srcptr src2, const fp3_param param, uint8_t stack)
Set dst <- src1 * src2, if Montgomery arithmetic is used, the Montgomery multiplication will be used ...
void fp3_elt_neg(fp3_elt_ptr dst, fp3_elt_srcptr src, const fp3_param param)
Set dst <- (-src)
void fp3_elt_pow_number(fp3_elt_ptr dst, fp3_elt_srcptr src, number_srcptr n, const fp3_param param, uint8_t stack)
Set dst <- src^n.
void fp3_elt_relax_pool_elt(fp3_elt *dst, const fp3_param param, uint8_t stack)
Free space of a temporary cubic extension field element.
void fp3_elt_add_fp_elt(fp3_elt_ptr dst, fp3_elt_srcptr src1, fp_elt_srcptr src2, const fp3_param param)
Set dst <- src1 + src2.
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 fp3_elt_random(fp3_elt_ptr dst, const fp3_param param, uint8_t stack)
Set dst to a random element of FP3, the random process is chosen at the MHELL initialisation.
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 fp3_elt_init(fp3_elt_ptr dst, const fp3_param param)
Initialise a cubic extension field element.
void fp_elt_free(fp_elt *src)
Free space used by src.
void fp3_elt_set_one(fp3_elt_ptr dst, const fp3_param param)
Set dst to one (or its Montgomery form if Montgomery arithmetic is used)
int8_t fp3_elt_cmp_fp_elt(fp3_elt_srcptr src1, fp_elt_srcptr src2, const fp3_param param)
Compare src1 and src2 in FP3.
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 fp3_elt_pow_ui(fp3_elt_ptr dst, fp3_elt_srcptr src, const block n, const fp3_param param, uint8_t stack)
Set dst <- src^n.
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.
bool fp3_elt_isone(fp3_elt_srcptr src, const fp3_param param)
Test if src is one.
void fp3_elt_set(fp3_elt_ptr dst, number_srcptr src1, number_srcptr src2, number_srcptr src3, const bool isreduced, const fp3_param param, uint8_t stack)
Set dst to src1 + src2*x + src3*x^2, if Montgomery arithmetic is used, is_reduced == false -> transfo...
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 fp3_elt_inv_fp_elt(fp3_elt_ptr dst, fp_elt_srcptr src, const fp3_param param, uint8_t stack)
Set dst <- src^(-1)
void fp3_elt_div(fp3_elt_ptr dst, fp3_elt_srcptr src1, fp3_elt_srcptr src2, const fp3_param param, uint8_t stack)
Set dst <- src1 / src2.
void fp3_elt_dec(fp3_elt_ptr dst, fp3_elt_srcptr src, const fp3_param param)
Set dst <- src - 1.
int8_t fp3_elt_ispower_number(fp3_elt_srcptr src, number_srcptr n, const fp3_param param, uint8_t stack)
Test if src is a n-power in FP3, using A NOTE ON POWERS IN FINITE FIELDS from ANDREAS AABRANDT AND VA...
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 fp3_get_size(number_ptr c, const fp3_param param)
Get the size of the cubic extension field "param".
void fp3_elt_sqr(fp3_elt_ptr dst, fp3_elt_srcptr src, const fp3_param param, uint8_t stack)
Set dst <- src^2.
void fp3_elt_str(char **str, fp3_elt_srcptr src, const uint8_t base, const bool lift, const fp3_param param, uint8_t stack)
Converts src to string format in base specified by base.
void number_free(number *dst)
Free a number_ptr allocated on the RAM memory (malloc)
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.
void fp3_elt_print(fp3_elt_srcptr src, const uint8_t base, const bool lift, const fp3_param param, uint8_t stack)
Print src in base "base".
void fp3_elt_add(fp3_elt_ptr dst, fp3_elt_srcptr src1, fp3_elt_srcptr src2, const fp3_param param)
Set dst <- src1 + src2.
void fp3_elt_mul4(fp3_elt_ptr dst, fp3_elt_srcptr src, const fp3_param param)
Set dst <- 4 * src.
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 fp3_elt_neg_fp_elt(fp3_elt_ptr dst, fp_elt_srcptr src, const fp3_param param)
Set dst <- (-src)
void fp3_elt_sub(fp3_elt_ptr dst, fp3_elt_srcptr src1, fp3_elt_srcptr src2, const fp3_param param)
Set dst <- src1 - src2.
void fp_get_characteristic(number_ptr c, const fp_param param)
Get the characteristic of the prime field "param".
void fp3_free(fp3_param param)
Free the space of the cubic extension field informations structure.
void fp3_elt_unity_nth_root(fp3_elt_ptr dst, const block n, const fp3_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 fp3_str(char **str, const fp3_param param, const uint8_t base, uint8_t stack)
Converts fp2_param param to string format in base specified by base.
void fp3_elt_sqrt(fp3_elt_ptr dst, fp3_elt_srcptr src, const fp3_param param, uint8_t stack)
Set dst <- src^(1/2), using Tonelli–Shanks algorithm.
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...
void fp3_elt_mul_fp_elt(fp3_elt_ptr dst, fp3_elt_srcptr src1, fp_elt_srcptr src2, const fp3_param param, uint8_t stack)
Set dst <- src1 * src2, if Montgomery arithmetic is used, the Montgomery multiplication will be used ...
void number_mul(number_ptr dst, number_srcptr src1, number_srcptr src2)
Set dst to src1 * src2.
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.
void fp3_elt_copy(fp3_elt_ptr dst, fp3_elt_srcptr src, const fp3_param param)
Copy src into dst, src and dst must belong to the same FP3.
void fp3_alloc(fp3_param param, const fp_param base)
Allocate space for the cubic extension field informations structure.
void number_sqr(number_ptr dst, number_srcptr src)
Set dst to src1^2.
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 fp3_elt_get_pool_elt(fp3_elt *dst, const fp3_param param, uint8_t stack)
Allocate and initialise space for a temporary cubic extension field element.
static void fp_elt_neg(fp_elt_ptr dst, fp_elt_srcptr src, const fp_param param)
Set dst <- (-src) mod p.
void fp3_elt_mul3(fp3_elt_ptr dst, fp3_elt_srcptr src, const fp3_param param, uint8_t stack)
Set dst <- 3 * src.
void fp_elt_set_zero(fp_elt_ptr dst, const fp_param param)
Set dst to zero.
void fp3_elt_set_number(fp3_elt_ptr dst, number_srcptr src, const bool isreduced, const fp3_param param, uint8_t stack)
Set dst to src, if Montgomery arithmetic is used, is_reduced == false -> transform dst into its Montg...
static void fp_elt_mul4(fp_elt_ptr dst, fp_elt_srcptr src, const fp_param param)
Set dst <- 4 * src.
void fp3_copy(fp3_param param_res, const fp3_param param)
Copy the cubic extension field structure param into param_res.
void fp3_elt_mul2(fp3_elt_ptr dst, fp3_elt_srcptr src, const fp3_param param)
Set dst <- 2 * src.
void number_tmp_free(number *t, const uint8_t size, uint8_t stack)
Free a temporary number.
Cubic extension field element structure.
void fp3_elt_clear(fp3_elt *src)
Clear space used by src (remove the action of fp3_elt_init but let the one of fp3_elt_alloc)
void fp3_elt_sqr_fp_elt(fp3_elt_ptr dst, fp_elt_srcptr src, const fp3_param param, uint8_t stack)
Set dst <- src^2.
void fp3_elt_set_fp_elt(fp3_elt_ptr dst, fp_elt_srcptr src, const fp3_param param)
Set dst to src.
void fp3_elt_inc(fp3_elt_ptr dst, fp3_elt_srcptr src, const fp3_param param)
Set dst <- src + 1.
bool fp3_elt_issquare(fp3_elt_srcptr src, const fp3_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 fp3_elt_set_str(fp3_elt_ptr dst, const char *str, const uint8_t base, const bool isreduced, const fp3_param param, uint8_t stack)
Set dst to str, if Montgomery arithmetic is used, is_reduced == false -> transform dst into its Montg...
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.
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 number_tmp_alloc(number *t, const uint8_t size, uint8_t stack)
Allocate a temporary number.
Cubic extension field structure.
void number_init(number *dst, const uint8_t n)
Allocate a number_ptr on the RAM memory (malloc)
Declaration of cubic field (finite field constructed with an irreducible polynomial of degree 3) func...
void fp3_create(fp3_param param, const fp_param base, fp_elt_srcptr non_residue, uint8_t stack)
Create a cubic extension of the field base.
static void fp_elt_dec(fp_elt_ptr dst, fp_elt_srcptr src, const fp_param param)
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 number_rshift(number_ptr dst, number_srcptr src, const uint16_t shift)
Set dst to src >> shift.
Primary field parameters.
void fp3_elt_free(fp3_elt *src)
Free space used by src.
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 fp3_elt_set_fp_elts(fp3_elt_ptr dst, fp_elt_srcptr src1, fp_elt_srcptr src2, fp_elt_srcptr src3, const fp3_param param)
Set dst to src1 + src2*x + src3*x^2.
void fp3_elt_set_ui(fp3_elt_ptr dst, const uint64_t src, const bool isreduced, const fp3_param param, uint8_t stack)
Set dst to src, if Montgomery arithmetic is used, is_reduced == false -> transform dst into its Montg...
void fp3_prepare_sqrt(fp3_param param, uint8_t stack)
Find a non square residue in FP3, factor out q-1 by powers of 2, find Q and S such that q − 1 = Q....
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 fp3_elt_inv(fp3_elt_ptr dst, fp3_elt_srcptr src, const fp3_param param, uint8_t stack)
Set dst <- src^(-1)
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 fp3_elt_div_fp_elt(fp3_elt_ptr dst, fp3_elt_srcptr src1, fp_elt_srcptr src2, const fp3_param param, uint8_t stack)
Set dst <- src1 / src2.
bool fp3_elt_iszero(fp3_elt_srcptr src, const fp3_param param)
Test if src is zero.
void fp3_elt_sub_fp_elt(fp3_elt_ptr dst, fp3_elt_srcptr src1, fp_elt_srcptr src2, const fp3_param param)
Set dst <- src1 - src2.
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.
void number_str(char **str, number_srcptr src, const uint8_t base)
Converts src to string format in base specified by base.
void fp3_elt_lift(fp3_elt_ptr dst, fp3_elt_srcptr src, const fp3_param param, uint8_t stack)
If Montgomery arithmetic is used, lift src (which is into Montgomery form) to classical FP3.
int8_t fp3_elt_cmp(fp3_elt_srcptr src1, fp3_elt_srcptr src2, const fp3_param param)
Compare src1 and src2 in FP3.
void fp3_elt_mul8(fp3_elt_ptr dst, fp3_elt_srcptr src, const fp3_param param)
Set dst <- 8 * src.
void fp_elt_init(fp_elt_ptr dst, const fp_param param)
Initialise a primary field element.
void fp3_elt_primitive_elt(fp3_elt_ptr dst, const fp3_param param, uint8_t stack)
Find a possible primitive element in the field defined by param.
void fp3_elt_cube_root(fp3_elt_ptr dst, fp3_elt_srcptr src, const fp3_param param, uint8_t stack)
Set dst <- src^(1/3)
int8_t fp3_elt_ispower_ui(fp3_elt_srcptr src, const block n, const fp3_param param, uint8_t stack)
Test if src is a n-power in FP3, using A NOTE ON POWERS IN FINITE FIELDS from ANDREAS AABRANDT AND VA...