MPHELL  5.0.0
Data Structures | Typedefs | Enumerations | Functions
mphell-field.h File Reference

Declaration of field functions. More...

#include "mphell-fp.h"
#include "mphell-fp2.h"
#include "mphell-fp3.h"
Include dependency graph for mphell-field.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  field_t
 Define a field. More...
 

Typedefs

typedef fp_elt * field_elt
 Generic field element.
 
typedef fp_elt * fe_ptr
 Pointer on a field element.
 
typedef const fp_elt * fe_srcptr
 Pointer on a field element, the field element cannot be modified through this pointer.
 
typedef field_t field[1]
 Address of a field structure.
 
typedef field_tfield_ptr
 Address of a field structure, use in all functions.
 
typedef const field_tfield_srcptr
 Address of a field structure, use in all functions where the parameter is const.
 

Enumerations

enum  field_type { FP , FP2 , FP3 }
 Define the field type. More...
 

Functions

static void field_elt_get_pool_elt (field_elt *dst, field_ptr k, uint8_t stack)
 Get an initialised field element from the pool. More...
 
static void field_elt_relax_pool_elt (field_elt *dst, field_ptr k, uint8_t stack)
 Relax an initialised field element from the pool. More...
 
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. More...
 
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. More...
 
void field_copy (field_ptr k_res, field_srcptr k)
 Copy the field structure param into param_res. More...
 
void field_free (field_ptr k)
 Free the space of the field informations structure. More...
 
void field_get_size (number_ptr c, field_srcptr k)
 Get the size of the field "k". More...
 
void field_get_characteristic (number_ptr c, field_srcptr k)
 Get the charactristic of the field "k". More...
 
void field_elt_alloc (fe_ptr *dst, field_srcptr k)
 Allocate space for a field element. More...
 
void field_elt_init (fe_ptr dst, field_srcptr k)
 Initialise the field element. More...
 
void field_elt_copy (fe_ptr dst, fe_srcptr src, field_srcptr k)
 Copy src into dst, src and dst must belong to the same field. More...
 
void field_elt_clear (fe_ptr *src, field_srcptr k)
 Clear space used by src (remove the action of field_elt_init but let the one of field_elt_alloc) More...
 
void field_elt_free (fe_ptr *src, field_srcptr k)
 Free space used by src. More...
 
void field_elt_set_one (fe_ptr dst, field_srcptr k)
 Set dst to one (or its Montgomery form if Montgomery arithmetic is used) More...
 
void field_elt_set_zero (fe_ptr dst, field_srcptr k)
 Set dst to zero. More...
 
void field_elt_set_ui (fe_ptr dst, const block src, const bool isreduced, field_srcptr k, uint8_t stack)
 Set dst to src, if Montgomery arithmetic is used, is_reduced == false -> transform dst into its Montgomery form. More...
 
void field_elt_set_number (fe_ptr dst, const bool isreduced, field_srcptr k, uint8_t stack, const uint32_t n,...)
 Set dst to src, if Montgomery arithmetic is used, is_reduced == false -> transform dst into its Montgomery form. More...
 
void field_elt_set_fp_elts (fe_ptr dst, field_srcptr k, const uint32_t n,...)
 Set dst to src(s) More...
 
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 Montgomery form. More...
 
void field_elt_random (fe_ptr dst, field_srcptr k, uint8_t stack)
 Set dst to a random element of k, the random process is chosen at the MHELL initialisation. More...
 
void field_elt_lift (fe_ptr dst, fe_srcptr src, field_srcptr k, uint8_t stack)
 If Montgomery arithmetic is used, lift src (which is into Montgomery form) to classical fp (or its coefficients). More...
 
void field_elt_get_number (number_ptr dst, fe_srcptr src, uint8_t pos, field_srcptr k, uint8_t stack)
 If Montgomery arithmetic is used, lift src (which is into Montgomery form) to classical fp (or its coefficients). More...
 
void field_elt_get_fp_elt (fe_ptr dst, fe_srcptr src, uint8_t pos, field_srcptr k)
 Get the field_elt in position 1, 2 or 3 of the src element. Rmq: if src element is in FP, it is just a copy. More...
 
void field_str (char **str, field_srcptr k, const uint8_t base, uint8_t stack)
 Converts k to string format in base specified by base. More...
 
void field_print (field_srcptr k, const uint8_t base, uint8_t stack)
 Print the different fields of the structure pointed by k. More...
 
void field_elt_str (char **str, fe_srcptr src, const uint8_t base, const bool lift, field_srcptr k, uint8_t stack)
 Converts src to string format in base specified by base. More...
 
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. More...
 
bool field_isequal (field_srcptr k1, field_srcptr k2)
 Test if k1 and k2 are equals. More...
 
int8_t field_elt_cmp (fe_srcptr src1, fe_srcptr src2, field_srcptr k)
 Compare src1 and src2. More...
 
int8_t field_elt_cmp_fp_elt (fe_srcptr src1, fe_srcptr src2, field_srcptr k)
 Compare src1 and src2. More...
 
bool field_elt_isone (fe_srcptr src, field_srcptr k)
 Test if src is one. More...
 
static bool field_elt_iszero (fe_srcptr src, field_srcptr k)
 Test if src is zero. More...
 
static void field_elt_inc (fe_ptr dst, fe_srcptr src, field_srcptr k)
 Set dst <- src + 1. More...
 
static void field_elt_add (fe_ptr dst, fe_srcptr src1, fe_srcptr src2, field_srcptr k)
 Set dst <- src1 + src2. More...
 
static void field_elt_add_fp_elt (fe_ptr dst, fe_srcptr src1, fe_srcptr src2, field_srcptr k)
 Set dst <- src1 + src2. More...
 
static void field_elt_dec (fe_ptr dst, fe_srcptr src, field_srcptr k)
 Set dst <- src - 1. More...
 
static void field_elt_sub (fe_ptr dst, fe_srcptr src1, fe_srcptr src2, field_srcptr k)
 Set dst <- src1 - src2. More...
 
static void field_elt_sub_fp_elt (fe_ptr dst, fe_srcptr src1, fe_srcptr src2, field_srcptr k)
 Set dst <- src1 - src2. More...
 
static void field_elt_neg (fe_ptr dst, fe_srcptr src, field_srcptr k)
 Set dst <- (-src) More...
 
static void field_elt_neg_fp_elt (fe_ptr dst, fe_srcptr src, field_srcptr k)
 Set dst <- (-src) More...
 
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 ! More...
 
static void field_elt_mul_fp_elt (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 ! More...
 
static void field_elt_mul2 (fe_ptr dst, fe_srcptr src, field_srcptr k)
 Set dst <- 2 * src. More...
 
static void field_elt_mul4 (fe_ptr dst, fe_srcptr src, field_srcptr k)
 Set dst <- 4 * src. More...
 
static void field_elt_mul8 (fe_ptr dst, fe_srcptr src, field_srcptr k)
 Set dst <- 8 * src. More...
 
static void field_elt_mul3 (fe_ptr dst, fe_srcptr src, field_srcptr k, uint8_t stack)
 Set dst <- 3 * src. More...
 
static void field_elt_sqr (fe_ptr dst, fe_srcptr src, field_srcptr k, uint8_t stack)
 Set dst <- src^2. More...
 
static void field_elt_sqr_fp_elt (fe_ptr dst, fe_srcptr src, field_srcptr k, uint8_t stack)
 Set dst <- src^2. More...
 
void field_elt_pow_ui (fe_ptr dst, fe_srcptr src, const block n, field_srcptr k, uint8_t stack)
 Set dst <- src^n. More...
 
void field_elt_pow_number (fe_ptr dst, fe_srcptr src, number_srcptr n, field_srcptr k, uint8_t stack)
 Set dst <- src^n. More...
 
bool field_elt_issquare (fe_srcptr src, field_srcptr k, uint8_t stack)
 Test if src is a square using the Lengendre symbol. More...
 
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. More...
 
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. More...
 
void field_find_nonsquare (fe_ptr dst, field_ptr k, uint8_t stack)
 Look for a random non square element in k. More...
 
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. More...
 
bool field_find_nonpower_number (fe_ptr dst, number_srcptr n, field_ptr k, uint8_t stack)
 Look for a random non n-power element in k. More...
 
void field_elt_sqrt (fe_ptr dst, fe_srcptr src, field_srcptr k, uint8_t stack)
 Set dst <- src^(1/2) More...
 
void field_elt_cube_root (fe_ptr dst, fe_srcptr src, field_srcptr k, uint8_t stack)
 Set dst <- src^(1/3) More...
 
void field_elt_unity_nth_root (fe_ptr dst, const block n, field_ptr k, uint8_t stack)
 Set dst to a non trivial n-th root of unity if it exists (ie n divides order(k)-1), 1 otherwise. More...
 
void field_elt_inv (fe_ptr dst, fe_srcptr src, field_srcptr k, uint8_t stack)
 Set dst <- src^(-1) More...
 
void field_elt_inv_fp_elt (fe_ptr dst, fe_srcptr src, field_srcptr k, uint8_t stack)
 Set dst <- src^(-1) More...
 
void field_elt_div (fe_ptr dst, fe_srcptr src1, fe_srcptr src2, field_srcptr k, uint8_t stack)
 Set dst <- src1 / src2. More...
 
void field_elt_div_fp_elt (fe_ptr dst, fe_srcptr src1, fe_srcptr src2, field_srcptr k, uint8_t stack)
 Set dst <- src1 / src2. More...
 

Detailed Description

Declaration of field functions.

Definition in file mphell-field.h.

Enumeration Type Documentation

◆ field_type

enum field_type

Define the field type.

Enumerator
FP 

Prime field

FP2 

Finite field of p^2 element

FP3 

Finite field of p^3 element

Definition at line 55 of file mphell-field.h.

Function Documentation

◆ field_alloc()

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.

Parameters
kStructure for the field informations to allocate
typeType of field, available fields are FP, FP2 and FP3
sizeSize in blocks of the field (ex: 4 for a 4 * 64 = 256 bits prime field on a 64 bits architecture)
baseBase prime field or NULL if k is already a prime field

Definition at line 37 of file mphell-field.c.

◆ field_copy()

void field_copy ( field_ptr  k_res,
field_srcptr  k 
)

Copy the field structure param into param_res.

Parameters
k_resDestination field
kSource field

Definition at line 175 of file mphell-field.c.

◆ field_create()

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.

Parameters
kInformations structure on the field to fill (must be allocated)
idName of the field
stackTemporary memory stack to use
nNumber of arguments that follow (use 1 for FP and 2 for FP2 and FP3)
...Characteristic (number) for FP and base field (prime field) and non_residu (field_elt) for FP2 and FP3

Definition at line 87 of file mphell-field.c.

◆ field_elt_add()

void field_elt_add ( fe_ptr  dst,
fe_srcptr  src1,
fe_srcptr  src2,
field_srcptr  k 
)
inlinestatic

Set dst <- src1 + src2.

Parameters
dstTo store the result
src1Source field element
src2Source field element
kField

Definition at line 558 of file mphell-field.h.

◆ field_elt_add_fp_elt()

void field_elt_add_fp_elt ( fe_ptr  dst,
fe_srcptr  src1,
fe_srcptr  src2,
field_srcptr  k 
)
inlinestatic

Set dst <- src1 + src2.

Parameters
dstTo store the result
src1Source field element
src2Source field element in FP
kField

Definition at line 585 of file mphell-field.h.

◆ field_elt_alloc()

void field_elt_alloc ( fe_ptr dst,
field_srcptr  k 
)

Allocate space for a field element.

Parameters
dstField element to allocate
kField

Definition at line 269 of file mphell-field.c.

◆ field_elt_clear()

void field_elt_clear ( fe_ptr src,
field_srcptr  k 
)

Clear space used by src (remove the action of field_elt_init but let the one of field_elt_alloc)

Parameters
srcField element to clear
kField

Definition at line 329 of file mphell-field.c.

◆ field_elt_cmp()

int8_t field_elt_cmp ( fe_srcptr  src1,
fe_srcptr  src2,
field_srcptr  k 
)

Compare src1 and src2.

Parameters
src1Source field element
src2Source field element
kField
Returns
-1 if src1 < src2
0 if src1 == src2
1 if src1 > src2

Definition at line 743 of file mphell-field.c.

◆ field_elt_cmp_fp_elt()

int8_t field_elt_cmp_fp_elt ( fe_srcptr  src1,
fe_srcptr  src2,
field_srcptr  k 
)

Compare src1 and src2.

Parameters
src1Source field element
src2Source field element in FP
kField
Returns
-1 if src1 < src2
0 if src1 == src2
1 if src1 > src2

Definition at line 764 of file mphell-field.c.

◆ field_elt_copy()

void field_elt_copy ( fe_ptr  dst,
fe_srcptr  src,
field_srcptr  k 
)

Copy src into dst, src and dst must belong to the same field.

Parameters
dstDestination field element
srcSource field element
kField

Definition at line 310 of file mphell-field.c.

◆ field_elt_cube_root()

void field_elt_cube_root ( fe_ptr  dst,
fe_srcptr  src,
field_srcptr  k,
uint8_t  stack 
)

Set dst <- src^(1/3)

Parameters
dstTo store the result
srcSource field element
kField
stackTemporary memory stack to use

Definition at line 1057 of file mphell-field.c.

◆ field_elt_dec()

void field_elt_dec ( fe_ptr  dst,
fe_srcptr  src,
field_srcptr  k 
)
inlinestatic

Set dst <- src - 1.

Parameters
dstTo store the result
srcSource field element
kField

Definition at line 611 of file mphell-field.h.

◆ field_elt_div()

void field_elt_div ( fe_ptr  dst,
fe_srcptr  src1,
fe_srcptr  src2,
field_srcptr  k,
uint8_t  stack 
)

Set dst <- src1 / src2.

Parameters
dstTo store the result
src1Source field element
src2Source field element
kField
stackTemporary memory stack to use

Definition at line 1137 of file mphell-field.c.

◆ field_elt_div_fp_elt()

void field_elt_div_fp_elt ( fe_ptr  dst,
fe_srcptr  src1,
fe_srcptr  src2,
field_srcptr  k,
uint8_t  stack 
)

Set dst <- src1 / src2.

Parameters
dstTo store the result
src1Source field element
src2Source field element in FP
kField
stackTemporary memory stack to use

Definition at line 1156 of file mphell-field.c.

◆ field_elt_free()

void field_elt_free ( fe_ptr src,
field_srcptr  k 
)

Free space used by src.

Parameters
srcField element to free
kField

Definition at line 348 of file mphell-field.c.

◆ field_elt_get_fp_elt()

void field_elt_get_fp_elt ( fe_ptr  dst,
fe_srcptr  src,
uint8_t  pos,
field_srcptr  k 
)

Get the field_elt in position 1, 2 or 3 of the src element. Rmq: if src element is in FP, it is just a copy.

Parameters
dstDestination field element in FP
srcSource field element
pos1 for FP, 1 or 2 for FP2, 1 or 2 or 3 for FP3 to get the wanted part of the field element.
kField from src

Definition at line 618 of file mphell-field.c.

◆ field_elt_get_number()

void field_elt_get_number ( number_ptr  dst,
fe_srcptr  src,
uint8_t  pos,
field_srcptr  k,
uint8_t  stack 
)

If Montgomery arithmetic is used, lift src (which is into Montgomery form) to classical fp (or its coefficients).

Parameters
dstDestination number
srcSource field element (eventually under Montgomery form)
pos1 for FP, 1 or 2 for FP2, 1 or 2 or 3 for FP3 to get the wanted part of the field element.
kField
stackTemporary memory stack to use

Definition at line 574 of file mphell-field.c.

◆ field_elt_get_pool_elt()

void field_elt_get_pool_elt ( field_elt dst,
field_ptr  k,
uint8_t  stack 
)
inlinestatic

Get an initialised field element from the pool.

Parameters
dstAddress of a field element
kInformation on the field, k must have been created with field_create.
stackTemporary memory stack to use

Definition at line 110 of file mphell-field.h.

◆ field_elt_inc()

void field_elt_inc ( fe_ptr  dst,
fe_srcptr  src,
field_srcptr  k 
)
inlinestatic

Set dst <- src + 1.

Parameters
dstTo store the result
srcSource field element
kField

Definition at line 531 of file mphell-field.h.

◆ field_elt_init()

void field_elt_init ( fe_ptr  dst,
field_srcptr  k 
)

Initialise the field element.

Parameters
dstField element to initialise
kField

Definition at line 291 of file mphell-field.c.

◆ field_elt_inv()

void field_elt_inv ( fe_ptr  dst,
fe_srcptr  src,
field_srcptr  k,
uint8_t  stack 
)

Set dst <- src^(-1)

Parameters
dstTo store the result
srcSource field element
kField
stackTemporary memory stack to use

Definition at line 1099 of file mphell-field.c.

◆ field_elt_inv_fp_elt()

void field_elt_inv_fp_elt ( fe_ptr  dst,
fe_srcptr  src,
field_srcptr  k,
uint8_t  stack 
)

Set dst <- src^(-1)

Parameters
dstTo store the result
srcSource field element in FP
kField
stackTemporary memory stack to use

Definition at line 1118 of file mphell-field.c.

◆ field_elt_isone()

bool field_elt_isone ( fe_srcptr  src,
field_srcptr  k 
)

Test if src is one.

Parameters
srcSource field element
kField
Returns
true if scr is one, false otherwise

Definition at line 785 of file mphell-field.c.

◆ field_elt_ispower_number()

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.

Parameters
srcSource field element
nSource number
kField
stackTemporary memory stack to use
Returns
2 if all element in src->k are some n-power
1 if src is a n-power in src->k
false otherwise

Definition at line 972 of file mphell-field.c.

◆ field_elt_ispower_ui()

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.

Parameters
srcSource field element
nSource block
kField
stackTemporary memory stack to use
Returns
2 if all element in src->k are some n-power
1 if src is a n-power in src->k
false otherwise

Definition at line 951 of file mphell-field.c.

◆ field_elt_issquare()

bool field_elt_issquare ( fe_srcptr  src,
field_srcptr  k,
uint8_t  stack 
)

Test if src is a square using the Lengendre symbol.

Parameters
srcSource field element
kField
stackTemporary memory stack to use
Returns
true if src is a square in src->k, false otherwise

Definition at line 932 of file mphell-field.c.

◆ field_elt_iszero()

bool field_elt_iszero ( fe_srcptr  src,
field_srcptr  k 
)
inlinestatic

Test if src is zero.

Parameters
srcSource field element
kField
Returns
true if scr is zero, false otherwise

Definition at line 500 of file mphell-field.h.

◆ field_elt_lift()

void field_elt_lift ( fe_ptr  dst,
fe_srcptr  src,
field_srcptr  k,
uint8_t  stack 
)

If Montgomery arithmetic is used, lift src (which is into Montgomery form) to classical fp (or its coefficients).

Parameters
dstDestination field element (in FP or with coefficients in Fp for FP2 and FP3)
srcSource field element (eventually under Montgomery form)
kField
stackTemporary memory stack to use

Definition at line 555 of file mphell-field.c.

◆ field_elt_mul()

void field_elt_mul ( fe_ptr  dst,
fe_srcptr  src1,
fe_srcptr  src2,
field_srcptr  k,
uint8_t  stack 
)
inlinestatic

Set dst <- src1 * src2, if Montgomery arithmetic is used, the Montgomery multiplication will be used !

Parameters
dstTo store the result
src1Source field element, must be of the same type than dst (FP, FP2 or FP3)
src2Source field element, can be of the same type than dst (FP, FP2, FP3) or FP.
kField
stackTemporary memory stack to use

Definition at line 749 of file mphell-field.h.

◆ field_elt_mul2()

void field_elt_mul2 ( fe_ptr  dst,
fe_srcptr  src,
field_srcptr  k 
)
inlinestatic

Set dst <- 2 * src.

Parameters
dstTo store the result
srcSource field element, must be of the same type than dst (FP, FP2 or FP3)
kField

Definition at line 803 of file mphell-field.h.

◆ field_elt_mul3()

void field_elt_mul3 ( fe_ptr  dst,
fe_srcptr  src,
field_srcptr  k,
uint8_t  stack 
)
inlinestatic

Set dst <- 3 * src.

Parameters
dstTo store the result
srcSource field element, must be of the same type than dst (FP, FP2 or FP3)
kField
stackTemporary memory stack to use

Definition at line 882 of file mphell-field.h.

◆ field_elt_mul4()

void field_elt_mul4 ( fe_ptr  dst,
fe_srcptr  src,
field_srcptr  k 
)
inlinestatic

Set dst <- 4 * src.

Parameters
dstTo store the result
srcSource field element, must be of the same type than dst (FP, FP2 or FP3)
kField

Definition at line 829 of file mphell-field.h.

◆ field_elt_mul8()

void field_elt_mul8 ( fe_ptr  dst,
fe_srcptr  src,
field_srcptr  k 
)
inlinestatic

Set dst <- 8 * src.

Parameters
dstTo store the result
srcSource field element, must be of the same type than dst (FP, FP2 or FP3)
kField

Definition at line 855 of file mphell-field.h.

◆ field_elt_mul_fp_elt()

void field_elt_mul_fp_elt ( fe_ptr  dst,
fe_srcptr  src1,
fe_srcptr  src2,
field_srcptr  k,
uint8_t  stack 
)
inlinestatic

Set dst <- src1 * src2, if Montgomery arithmetic is used, the Montgomery multiplication will be used !

Parameters
dstTo store the result
src1Source field element, must be of the same type than dst (FP, FP2 or FP3)
src2Source field element in FP.
kField
stackTemporary memory stack to use

Definition at line 777 of file mphell-field.h.

◆ field_elt_neg()

void field_elt_neg ( fe_ptr  dst,
fe_srcptr  src,
field_srcptr  k 
)
inlinestatic

Set dst <- (-src)

Parameters
dstTo store the result
srcSource field element
kField

Definition at line 691 of file mphell-field.h.

◆ field_elt_neg_fp_elt()

void field_elt_neg_fp_elt ( fe_ptr  dst,
fe_srcptr  src,
field_srcptr  k 
)
inlinestatic

Set dst <- (-src)

Parameters
dstTo store the result
srcSource field element in FP
kField

Definition at line 717 of file mphell-field.h.

◆ field_elt_pow_number()

void field_elt_pow_number ( fe_ptr  dst,
fe_srcptr  src,
number_srcptr  n,
field_srcptr  k,
uint8_t  stack 
)

Set dst <- src^n.

Parameters
dstTo store the result
srcSource field element
nSource number
kField
stackTemporary memory stack to use

Definition at line 913 of file mphell-field.c.

◆ field_elt_pow_ui()

void field_elt_pow_ui ( fe_ptr  dst,
fe_srcptr  src,
const block  n,
field_srcptr  k,
uint8_t  stack 
)

Set dst <- src^n.

Parameters
dstTo store the result
srcSource field element
nSource block
kField
stackTemporary memory stack to use

Definition at line 894 of file mphell-field.c.

◆ field_elt_print()

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.

Parameters
srcSource field element (under Montgomery form if Montgomery arithmetic is used)
baseBase to use to write str, can be 2, 10 or 16
liftIf Montgomery arithmetic is used, lift == true -> lift src into Fp (or its coefficients to FP) before conversion
kField
stackTemporary memory stack to use

Definition at line 732 of file mphell-field.c.

◆ field_elt_random()

void field_elt_random ( fe_ptr  dst,
field_srcptr  k,
uint8_t  stack 
)

Set dst to a random element of k, the random process is chosen at the MHELL initialisation.

Parameters
dstDestination field element
kField
stackTemporary memory stack to use

Definition at line 536 of file mphell-field.c.

◆ field_elt_relax_pool_elt()

void field_elt_relax_pool_elt ( field_elt dst,
field_ptr  k,
uint8_t  stack 
)
inlinestatic

Relax an initialised field element from the pool.

Parameters
dstAddress of a field element
kInformation on the field, k must have been created with field_create.
stackTemporary memory stack to use

Definition at line 143 of file mphell-field.h.

◆ field_elt_set_fp_elts()

void field_elt_set_fp_elts ( fe_ptr  dst,
field_srcptr  k,
const uint32_t  n,
  ... 
)

Set dst to src(s)

Parameters
dstDestination field element
kField
nNumber of arguments that follow (use 1 for FP, 1 or 2 for FP2 and 1 or 3 FP3)
...fp_elt for FP, coefficients of the polynomial for FP2 and FP3

Definition at line 471 of file mphell-field.c.

◆ field_elt_set_number()

void field_elt_set_number ( fe_ptr  dst,
const bool  isreduced,
field_srcptr  k,
uint8_t  stack,
const uint32_t  n,
  ... 
)

Set dst to src, if Montgomery arithmetic is used, is_reduced == false -> transform dst into its Montgomery form.

Parameters
dstDestination field element
isreducedIf Montgomery arithmetic is used, is_reduced == false -> transform dst into its Montgomery form, is_reduced == true -> simple copy
kField
stackTemporary memory stack to use
nNumber of arguments that follow (use 1 for FP, 1 or 2 for FP2 and 1 or 3 FP3)
...Number for FP, coefficients of the polynomial for FP2 and FP3

Definition at line 426 of file mphell-field.c.

◆ field_elt_set_one()

void field_elt_set_one ( fe_ptr  dst,
field_srcptr  k 
)

Set dst to one (or its Montgomery form if Montgomery arithmetic is used)

Parameters
dstDestination field element (must be allocated)
kField

Definition at line 368 of file mphell-field.c.

◆ field_elt_set_str()

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 Montgomery form.

Parameters
dstDestination field element
strSource number under string format in base "base". If FP2 or FP3 is use the polynomials coefficients are given separated by a "," without space.
baseBase used to write str, can be 2, 10 or 16
isreducedIf Montgomery arithmetic is used, is_reduced == false -> transform dst into its Montgomery form, is_reduced == true -> simple copy
kField
stackTemporary memory stack to use

Definition at line 516 of file mphell-field.c.

◆ field_elt_set_ui()

void field_elt_set_ui ( fe_ptr  dst,
const block  src,
const bool  isreduced,
field_srcptr  k,
uint8_t  stack 
)

Set dst to src, if Montgomery arithmetic is used, is_reduced == false -> transform dst into its Montgomery form.

Parameters
dstDestination field element
srcSource block
isreducedIf Montgomery arithmetic is used, is_reduced == false -> transform dst into its Montgomery form, is_reduced == true -> simple copy
kField
stackTemporary memory stack to use

Definition at line 406 of file mphell-field.c.

◆ field_elt_set_zero()

void field_elt_set_zero ( fe_ptr  dst,
field_srcptr  k 
)

Set dst to zero.

Parameters
dstDestination field element (must be allocated)
kField

Definition at line 387 of file mphell-field.c.

◆ field_elt_sqr()

void field_elt_sqr ( fe_ptr  dst,
fe_srcptr  src,
field_srcptr  k,
uint8_t  stack 
)
inlinestatic

Set dst <- src^2.

Parameters
dstTo store the result
srcSource field element
kField
stackTemporary memory stack to use

Definition at line 909 of file mphell-field.h.

◆ field_elt_sqr_fp_elt()

void field_elt_sqr_fp_elt ( fe_ptr  dst,
fe_srcptr  src,
field_srcptr  k,
uint8_t  stack 
)
inlinestatic

Set dst <- src^2.

Parameters
dstTo store the result
srcSource field element in FP
kField
stackTemporary memory stack to use

Definition at line 936 of file mphell-field.h.

◆ field_elt_sqrt()

void field_elt_sqrt ( fe_ptr  dst,
fe_srcptr  src,
field_srcptr  k,
uint8_t  stack 
)

Set dst <- src^(1/2)

Parameters
dstTo store the result
srcSource field element
kField
stackTemporary memory stack to use

Definition at line 1036 of file mphell-field.c.

◆ field_elt_str()

void field_elt_str ( char **  str,
fe_srcptr  src,
const uint8_t  base,
const bool  lift,
field_srcptr  k,
uint8_t  stack 
)

Converts src to string format in base specified by base.

Parameters
strDestination string, allocated by the function, must be free by the user.
srcSource field element (under Montgomery form if Montgomery arithmetic is used)
baseBase to use to write str, can be 2, 10 or 16
liftIf Montgomery arithmetic is used, lift == true -> lift src into Fp (or its coefficients to FP) before conversion
kField
stackTemporary memory stack to use

Definition at line 702 of file mphell-field.c.

◆ field_elt_sub()

void field_elt_sub ( fe_ptr  dst,
fe_srcptr  src1,
fe_srcptr  src2,
field_srcptr  k 
)
inlinestatic

Set dst <- src1 - src2.

Parameters
dstTo store the result
src1Source field element
src2Source field element
kField

Definition at line 638 of file mphell-field.h.

◆ field_elt_sub_fp_elt()

void field_elt_sub_fp_elt ( fe_ptr  dst,
fe_srcptr  src1,
fe_srcptr  src2,
field_srcptr  k 
)
inlinestatic

Set dst <- src1 - src2.

Parameters
dstTo store the result
src1Source field element
src2Source field element in FP
kField

Definition at line 665 of file mphell-field.h.

◆ field_elt_unity_nth_root()

void field_elt_unity_nth_root ( fe_ptr  dst,
const block  n,
field_ptr  k,
uint8_t  stack 
)

Set dst to a non trivial n-th root of unity if it exists (ie n divides order(k)-1), 1 otherwise.

Parameters
dstTo store the result
nSource block
paramField
stackTemporary memory stack to use

Definition at line 1078 of file mphell-field.c.

◆ field_find_nonpower_number()

bool field_find_nonpower_number ( fe_ptr  dst,
number_srcptr  n,
field_ptr  k,
uint8_t  stack 
)

Look for a random non n-power element in k.

Parameters
dstDestination field element
nSource number
kField
stackTemporary memory stack to use
Returns
true if a n-power is found in k
false if k does not have any n-power

Definition at line 1019 of file mphell-field.c.

◆ field_find_nonpower_ui()

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.

Parameters
dstDestination field element
nSource block
kField
stackTemporary memory stack to use
Returns
true if a n-power is found in k
false if k does not have any n-power

Definition at line 1002 of file mphell-field.c.

◆ field_find_nonsquare()

void field_find_nonsquare ( fe_ptr  dst,
field_ptr  k,
uint8_t  stack 
)

Look for a random non square element in k.

Parameters
dstDestination field element
kField
stackTemporary memory stack to use

Definition at line 993 of file mphell-field.c.

◆ field_free()

void field_free ( field_ptr  k)

Free the space of the field informations structure.

Parameters
kField informations structure

Definition at line 194 of file mphell-field.c.

◆ field_get_characteristic()

void field_get_characteristic ( number_ptr  c,
field_srcptr  k 
)

Get the charactristic of the field "k".

Parameters
cDestination number (to store the characteristic)
kField

Definition at line 250 of file mphell-field.c.

◆ field_get_size()

void field_get_size ( number_ptr  c,
field_srcptr  k 
)

Get the size of the field "k".

Parameters
cDestination number (to store the characteristic)
kField

Definition at line 231 of file mphell-field.c.

◆ field_isequal()

bool field_isequal ( field_srcptr  k1,
field_srcptr  k2 
)

Test if k1 and k2 are equals.

Parameters
k1Field
k2Field
Returns
true if k1 == k2
false if k1 != k2

Definition at line 808 of file mphell-field.c.

◆ field_print()

void field_print ( field_srcptr  k,
const uint8_t  base,
uint8_t  stack 
)

Print the different fields of the structure pointed by k.

Parameters
kField
baseBase to use to print k, can be 2, 10 or 16
stackTemporary memory stack to use

Definition at line 693 of file mphell-field.c.

◆ field_str()

void field_str ( char **  str,
field_srcptr  k,
const uint8_t  base,
uint8_t  stack 
)

Converts k to string format in base specified by base.

Parameters
strDestination string, allocated by the function, must be free by the user.
kField
baseBase to use to write str, can be 2, 10 or 16
stackTemporary memory stack to use

Definition at line 662 of file mphell-field.c.