MPHELL
4.0.0
|
Declaration of primary field functions, if Montgomery arithmetic is used, the Montgomery arithmetic will be used ! More...
#include "mphell-number.h"
Go to the source code of this file.
Typedefs | |
typedef fp_param_t * | fp_param |
Pointer on a primary field parameters structure. | |
typedef enum fp_id_e | fp_id |
Identifier for known field, use by IPPCP to accelerate the field arithmetic. | |
Enumerations | |
enum | fp_id_e { ARBITRARY, P192R1, P224R1, P256R1, P384R1, P521R1 } |
Identifier for known field, use by IPPCP to accelerate the field arithmetic. More... | |
Functions | |
void | fp_elt_print (fp_elt_srcptr src, const uint8_t base, const bool lift, const fp_param param, uint8_t stack) |
Print src in base "base". More... | |
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. More... | |
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. More... | |
void | fp_alloc (fp_param param, const uint8_t size) |
Allocate space for the prime field informations structure. More... | |
void | fp_create (fp_param param, number_srcptr p, fp_id id, uint8_t stack) |
Create a prime field of characteristic p. More... | |
void | fp_copy (fp_param param_res, const fp_param param) |
Copy the prime field structure param into param_res. More... | |
void | fp_free (fp_param param) |
Free the space of the prime field informations structure. More... | |
void | fp_get_characteristic (number_ptr c, const fp_param param) |
Get the characteristic of the prime field "param". More... | |
void | fp_elt_alloc (fp_elt *dst, const fp_param param) |
Allocate space for a primary field element. More... | |
void | fp_elt_init (fp_elt_ptr dst, const fp_param param) |
Initialise a primary field element. More... | |
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. More... | |
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) More... | |
void | fp_elt_free (fp_elt *src) |
Free space used by src. More... | |
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) More... | |
void | fp_elt_set_zero (fp_elt_ptr dst, const fp_param param) |
Set dst to zero. More... | |
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 Montgomery form. More... | |
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 Montgomery form. More... | |
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 Montgomery form. More... | |
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. More... | |
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. More... | |
void | fp_elt_get_number (number_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 number (in FP). More... | |
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. More... | |
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. More... | |
int8_t | fp_elt_cmp (fp_elt_srcptr src1, fp_elt_srcptr src2, const fp_param param) |
Compare src1 and src2 in Fp. More... | |
bool | fp_elt_isone (fp_elt_srcptr src, const fp_param param) |
Test if src is one. More... | |
static bool | fp_elt_iszero (fp_elt_srcptr src, const fp_param param) |
Test if src is zero. More... | |
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. More... | |
static void | fp_elt_inc (fp_elt_ptr dst, fp_elt_srcptr src, const fp_param param) |
Set dst <- src + 1. More... | |
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. More... | |
static void | fp_elt_dec (fp_elt_ptr dst, fp_elt_srcptr src, const fp_param param) |
Set dst <- src - 1. More... | |
static void | fp_elt_neg (fp_elt_ptr dst, fp_elt_srcptr src, const fp_param param) |
Set dst <- (-src) mod p. More... | |
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 ! More... | |
static void | fp_elt_mul2 (fp_elt_ptr dst, fp_elt_srcptr src, const fp_param param) |
Set dst <- 2 * src. More... | |
static void | fp_elt_mul4 (fp_elt_ptr dst, fp_elt_srcptr src, const fp_param param) |
Set dst <- 4 * src. More... | |
static void | fp_elt_mul8 (fp_elt_ptr dst, fp_elt_srcptr src, const fp_param param) |
Set dst <- 8 * src. More... | |
static void | fp_elt_mul3 (fp_elt_ptr dst, fp_elt_srcptr src, const fp_param param, uint8_t stack) |
Set dst <- 3 * src. More... | |
static void | fp_elt_sqr (fp_elt_ptr dst, fp_elt_srcptr src, const fp_param param, uint8_t stack) |
Set dst <- src^2. More... | |
void | fp_elt_inv_flt (fp_elt_ptr dst, fp_elt_srcptr src, const fp_param param, uint8_t stack) |
Set dst <- src^(-1) using Fermat Little Theorem. More... | |
void | fp_elt_inv (fp_elt_ptr dst, fp_elt_srcptr src, const fp_param param, uint8_t stack) |
Set dst <- src^(-1) More... | |
void | fp_elt_div (fp_elt_ptr dst, fp_elt_srcptr src1, fp_elt_srcptr src2, const fp_param param, uint8_t stack) |
Set dst <- src1 / src2. More... | |
void | fp_elt_pow_ui (fp_elt_ptr dst, fp_elt_srcptr src, const block n, const fp_param param, uint8_t stack) |
Set dst <- src^n. More... | |
void | fp_elt_pow_number (fp_elt_ptr dst, fp_elt_srcptr src, number_srcptr n, const fp_param param, uint8_t stack) |
Set dst <- src^n. More... | |
bool | fp_elt_issquare (fp_elt_srcptr src, const fp_param param, uint8_t stack) |
Test if src is a square using the Lengendre symbol. More... | |
int8_t | fp_elt_ispower_ui (fp_elt_srcptr src, const block n, const fp_param param, uint8_t stack) |
Test if src is a n-power in Fp. More... | |
int8_t | fp_elt_ispower_number (fp_elt_srcptr src, number_srcptr n, const fp_param param, uint8_t stack) |
Test if src is a n-power in Fp. More... | |
void | fp_elt_sqrt (fp_elt_ptr dst, fp_elt_srcptr src, const fp_param param, uint8_t stack) |
Set dst <- src^(1/2) mod p, using Tonelli–Shanks algorithm. More... | |
void | fp_elt_cube_root (fp_elt_ptr dst, fp_elt_srcptr src, const fp_param param, uint8_t stack) |
Set dst <- src^(1/3) mod p. More... | |
void | fp_elt_unity_nth_root (fp_elt_ptr dst, const block n, const fp_param param, uint8_t stack) |
Set dst to a non trivial n-th root of unity if it exists (ie n divides p-1), 1 otherwise. More... | |
Declaration of primary field functions, if Montgomery arithmetic is used, the Montgomery arithmetic will be used !
Definition in file mphell-fp.h.
enum fp_id_e |
Identifier for known field, use by IPPCP to accelerate the field arithmetic.
Definition at line 130 of file mphell-fp.h.
void fp_alloc | ( | fp_param | param, |
const uint8_t | size | ||
) |
Allocate space for the prime field informations structure.
param | Structure for the prime field informations to allocate |
size | Size in blocks of the prime field (ex: 4 for a 4 * 64 = 256 bits prime field on a 64 bits architecture) |
Definition at line 58 of file mphell-fp.c.
Copy the prime field structure param into param_res.
param_res | Destination prime field |
param | Source prime field |
Definition at line 266 of file mphell-fp.c.
Create a prime field of characteristic p.
param | Informations structure on prime field to fill (must be allocated) |
p | Characteristic of the prime field |
id | Name of the field, use P192R1, P224R1, P256R1, P384R1, P521R1 for the NIST curve, ARBITRARY otherwise. |
stack | Temporary memory stack to use |
Definition at line 126 of file mphell-fp.c.
|
inlinestatic |
Set dst <- src1 + src2.
dst | To store the result |
src1 | Source field element |
src2 | Source field element |
param | Information on prime field |
Definition at line 514 of file mphell-fp.h.
void fp_elt_alloc | ( | fp_elt * | dst, |
const fp_param | param | ||
) |
Allocate space for a primary field element.
dst | Primary field element to allocate |
param | Information on prime field |
Definition at line 344 of file mphell-fp.c.
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)
src | Primary field element to free |
Definition at line 377 of file mphell-fp.c.
int8_t fp_elt_cmp | ( | fp_elt_srcptr | src1, |
fp_elt_srcptr | src2, | ||
const fp_param | param | ||
) |
Compare src1 and src2 in Fp.
src1 | Source field element |
src2 | Source field element |
param | Information on prime field |
Definition at line 631 of file mphell-fp.c.
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.
dst | Destination primary field element |
src | Source primary field element |
param | Information on prime field |
Definition at line 367 of file mphell-fp.c.
void fp_elt_cube_root | ( | fp_elt_ptr | dst, |
fp_elt_srcptr | src, | ||
const fp_param | param, | ||
uint8_t | stack | ||
) |
Set dst <- src^(1/3) mod p.
dst | To store the result |
src | Source field element |
param | Information on prime field |
stack | Temporary memory stack to use |
Definition at line 1019 of file mphell-fp.c.
|
inlinestatic |
Set dst <- src - 1.
dst | To store the result |
src | Source field element |
param | Information on prime field |
Definition at line 596 of file mphell-fp.h.
void fp_elt_div | ( | fp_elt_ptr | dst, |
fp_elt_srcptr | src1, | ||
fp_elt_srcptr | src2, | ||
const fp_param | param, | ||
uint8_t | stack | ||
) |
Set dst <- src1 / src2.
dst | To store the result |
src1 | Source field element |
src2 | Source field element |
param | Information on prime field |
stack | Temporary memory stack to use |
Definition at line 740 of file mphell-fp.c.
void fp_elt_free | ( | fp_elt * | src | ) |
Free space used by src.
src | Primary field element to free |
Definition at line 385 of file mphell-fp.c.
void fp_elt_get_number | ( | number_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 number (in FP).
dst | Destination number |
src | Source field element (eventually under Montgomery form) |
param | Information on prime field |
stack | Temporary memory stack to use |
Definition at line 522 of file mphell-fp.c.
|
inlinestatic |
Get an initialised field element from the pool.
dst | Adress of the temporary element to allocate |
param | Information on prime field |
stack | Temporary memory stack to use |
Definition at line 158 of file mphell-fp.h.
|
inlinestatic |
Set dst <- src + 1.
dst | To store the result |
src | Source field element |
param | Information on prime field |
Definition at line 539 of file mphell-fp.h.
void fp_elt_init | ( | fp_elt_ptr | dst, |
const fp_param | param | ||
) |
Initialise a primary field element.
dst | Primary field element to initialise |
param | Information on prime field |
Definition at line 357 of file mphell-fp.c.
void fp_elt_inv | ( | fp_elt_ptr | dst, |
fp_elt_srcptr | src, | ||
const fp_param | param, | ||
uint8_t | stack | ||
) |
Set dst <- src^(-1)
dst | To store the result |
src | Source field element |
param | Information on prime field |
stack | Temporary memory stack to use |
Definition at line 716 of file mphell-fp.c.
void fp_elt_inv_flt | ( | fp_elt_ptr | dst, |
fp_elt_srcptr | src, | ||
const fp_param | param, | ||
uint8_t | stack | ||
) |
Set dst <- src^(-1) using Fermat Little Theorem.
dst | To store the result |
src | Source field element |
param | Information on prime field |
stack | Temporary memory stack to use |
bool fp_elt_isone | ( | fp_elt_srcptr | src, |
const fp_param | param | ||
) |
Test if src is one.
src | Source field element |
param | Information on prime field |
Definition at line 654 of file mphell-fp.c.
int8_t fp_elt_ispower_number | ( | fp_elt_srcptr | src, |
number_srcptr | n, | ||
const fp_param | param, | ||
uint8_t | stack | ||
) |
Test if src is a n-power in Fp.
src | Source field element |
n | Source number |
param | Information on prime field |
stack | Temporary memory stack to use |
Definition at line 909 of file mphell-fp.c.
int8_t fp_elt_ispower_ui | ( | fp_elt_srcptr | src, |
const block | n, | ||
const fp_param | param, | ||
uint8_t | stack | ||
) |
Test if src is a n-power in Fp.
src | Source field element |
n | Source block |
param | Information on prime field |
stack | Temporary memory stack to use |
Definition at line 865 of file mphell-fp.c.
bool fp_elt_issquare | ( | fp_elt_srcptr | src, |
const fp_param | param, | ||
uint8_t | stack | ||
) |
Test if src is a square using the Lengendre symbol.
src | Source field element |
param | Information on prime field |
stack | Temporary memory stack to use |
Definition at line 848 of file mphell-fp.c.
|
inlinestatic |
Test if src is zero.
src | Source field element |
param | Information on prime field |
Definition at line 462 of file mphell-fp.h.
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.
dst | Destination primary field element (in Fp) |
src | Source primary field element (under Montgomery form) |
param | Information on prime field |
stack | Temporary memory stack to use |
Definition at line 503 of file mphell-fp.c.
|
inlinestatic |
Set dst <- src1 * src2, if Montgomery arithmetic is used, the Montgomery multiplication will be used !
dst | To store the result |
src1 | Source field element |
src2 | Source field element |
param | Information on prime field |
stack | Temporary memory stack to use |
Definition at line 643 of file mphell-fp.h.
|
inlinestatic |
Set dst <- 2 * src.
dst | To store the result |
src | Source field element |
param | Information on prime field |
Definition at line 665 of file mphell-fp.h.
|
inlinestatic |
Set dst <- 3 * src.
dst | To store the result |
src | Source field element |
param | Information on prime field |
stack | Temporary memory stack to use |
Definition at line 768 of file mphell-fp.h.
|
inlinestatic |
Set dst <- 4 * src.
dst | To store the result |
src | Source field element |
param | Information on prime field |
Definition at line 690 of file mphell-fp.h.
|
inlinestatic |
Set dst <- 8 * src.
dst | To store the result |
src | Source field element |
param | Information on prime field |
Definition at line 728 of file mphell-fp.h.
|
inlinestatic |
Set dst <- (-src) mod p.
dst | To store the result |
src | Source field element |
param | Information on prime field |
Definition at line 613 of file mphell-fp.h.
void fp_elt_pow_number | ( | fp_elt_ptr | dst, |
fp_elt_srcptr | src, | ||
number_srcptr | n, | ||
const fp_param | param, | ||
uint8_t | stack | ||
) |
Set dst <- src^n.
dst | To store the result |
src | Source field element |
n | Source number |
param | Information on prime field |
stack | Temporary memory stack to use |
Definition at line 806 of file mphell-fp.c.
void fp_elt_pow_ui | ( | fp_elt_ptr | dst, |
fp_elt_srcptr | src, | ||
const block | n, | ||
const fp_param | param, | ||
uint8_t | stack | ||
) |
Set dst <- src^n.
dst | To store the result |
src | Source field element |
n | Source block |
param | Information on prime field |
stack | Temporary memory stack to use |
Definition at line 763 of file mphell-fp.c.
void fp_elt_print | ( | fp_elt_srcptr | src, |
const uint8_t | base, | ||
const bool | lift, | ||
const fp_param | param, | ||
uint8_t | stack | ||
) |
Print src in base "base".
src | Field element to print |
base | Base to use to write str, can be 2, 10 or 16 |
lift | If Montgomery arithmetic is used, lift == true -> lift src into Fp (or its coefficients to FP) before conversion |
param | Information on prime field |
stack | Temporary memory stack to use |
Definition at line 40 of file mphell-fp.c.
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.
dst | Destination primary field element |
param | Information on prime field |
stack | Temporary memory stack to use |
Definition at line 481 of file mphell-fp.c.
|
inlinestatic |
Relax an initialised field element from the pool.
dst | Adress of the temporary element to free |
param | Information on prime field |
stack | Temporary memory stack to use |
Definition at line 195 of file mphell-fp.h.
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 Montgomery form.
dst | Destination primary field element |
src | Source number |
isreduced | If Montgomery arithmetic is used, is_reduced == false -> transform dst into its Montgomery form, is_reduced == true -> simple copy |
param | Information on prime field |
stack | Temporary memory stack to use |
Definition at line 433 of file mphell-fp.c.
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)
dst | Destination primary field element (must be allocated) |
param | Information on prime field |
Definition at line 394 of file mphell-fp.c.
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 Montgomery form.
dst | Destination primary field element |
str | Source number under string format in base "base" |
base | Base used to write str, can be 2, 10 or 16 |
isreduced | If Montgomery arithmetic is used, is_reduced == false -> transform dst into its Montgomery form, is_reduced == true -> simple copy |
param | Information on prime field |
stack | Temporary memory stack to use |
Definition at line 455 of file mphell-fp.c.
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 Montgomery form.
dst | Destination primary field element |
src | Source block |
isreduced | If Montgomery arithmetic is used, is_reduced == false -> transform dst into its Montgomery form, is_reduced == true -> simple copy |
param | Information on prime field |
stack | Temporary memory stack to use |
Definition at line 415 of file mphell-fp.c.
void fp_elt_set_zero | ( | fp_elt_ptr | dst, |
const fp_param | param | ||
) |
Set dst to zero.
dst | Destination primary field element (must be allocated) |
param | Information on prime field |
Definition at line 404 of file mphell-fp.c.
|
inlinestatic |
Set dst <- src^2.
dst | To store the result |
src | Source field element |
param | Information on prime field |
stack | Temporary memory stack to use |
Definition at line 806 of file mphell-fp.h.
void fp_elt_sqrt | ( | fp_elt_ptr | dst, |
fp_elt_srcptr | src, | ||
const fp_param | param, | ||
uint8_t | stack | ||
) |
Set dst <- src^(1/2) mod p, using Tonelli–Shanks algorithm.
dst | To store the result |
src | Source field element |
param | Information on prime field |
stack | Temporary memory stack to use |
Definition at line 956 of file mphell-fp.c.
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.
str | Destination string, allocated by the function, must be free by the user. |
src | Source primary field element (under Montgomery form if Montgomery arithmetic is used) |
base | Base to use to write str, can be 2, 10 or 16 |
lift | If Montgomery arithmetic is used, lift == true -> lift src into Fp before conversion |
param | Information on prime field |
stack | Temporary memory stack to use |
Definition at line 600 of file mphell-fp.c.
|
inlinestatic |
Set dst <- src1 - src2.
dst | To store the result |
src1 | Source field element |
src2 | Source field element |
param | Information on prime field |
Definition at line 557 of file mphell-fp.h.
void fp_elt_unity_nth_root | ( | fp_elt_ptr | dst, |
const block | n, | ||
const fp_param | param, | ||
uint8_t | stack | ||
) |
Set dst to a non trivial n-th root of unity if it exists (ie n divides p-1), 1 otherwise.
dst | To store the result |
n | Source block |
param | Information on prime field |
stack | Temporary memory stack to use |
Definition at line 1257 of file mphell-fp.c.
void fp_free | ( | fp_param | param | ) |
Free the space of the prime field informations structure.
param | Prime field informations structure |
Definition at line 292 of file mphell-fp.c.
void fp_get_characteristic | ( | number_ptr | c, |
const fp_param | param | ||
) |
Get the characteristic of the prime field "param".
c | Destination number (to store the characteristic) |
param | Information on prime field |
Definition at line 332 of file mphell-fp.c.
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.
str | Destination string, allocated by the function, must be free by the user. |
param | Information on prime field |
base | Base to use to write str, can be 2, 10 or 16 |
stack | Temporary memory stack to use |
Definition at line 543 of file mphell-fp.c.