MPHELL  5.0.0
Macros | Functions
mphell-amns.c File Reference

Definition of Adapted Modular Number System (AMNS) functions. More...

#include "mphell-amns.h"
Include dependency graph for mphell-amns.c:

Go to the source code of this file.

Macros

#define PRAGMA_UNROLL
 
#define TEMPLATE_amns_elt_add_declare(sl)    void amns_elt_add##sl (amns_elt_ptr dst, amns_elt_srcptr a, amns_elt_srcptr b, amns_srcptr AMNS); \
 
#define TEMPLATE_amns_elt_sub_declare(sl)    void amns_elt_sub##sl (amns_elt_ptr dst, amns_elt_srcptr a, amns_elt_srcptr b, amns_srcptr AMNS); \
 
#define TEMPLATE_amns_elt_neg_declare(sl)    void amns_elt_neg##sl (amns_elt_ptr dst, amns_elt_srcptr a, amns_srcptr AMNS); \
 
#define TEMPLATE_amns_elt_mul_declare(sl)    void amns_elt_mul##sl (amns_elt_ptr dst, amns_elt_srcptr a, amns_elt_srcptr b, amns_srcptr AMNS); \
 
#define TEMPLATE_amns_elt_mul_shift_p_declare(sl)    void amns_elt_mul_shift_p##sl (amns_elt_ptr dst, amns_elt_srcptr a, amns_elt_srcptr b, amns_srcptr AMNS); \
 
#define TEMPLATE_amns_elt_mul_shift_n_declare(sl)    void amns_elt_mul_shift_n##sl (amns_elt_ptr dst, amns_elt_srcptr a, amns_elt_srcptr b, amns_srcptr AMNS); \
 
#define TEMPLATE_amns_elt_sqr_declare(sl)    void amns_elt_sqr##sl (amns_elt_ptr dst, amns_elt_srcptr a, amns_srcptr AMNS); \
 
#define TEMPLATE_amns_elt_sqr_shift_p_declare(sl)    void amns_elt_sqr_shift_p##sl (amns_elt_ptr dst, amns_elt_srcptr a, amns_srcptr AMNS); \
 
#define TEMPLATE_amns_elt_sqr_shift_n_declare(sl)    void amns_elt_sqr_shift_n##sl (amns_elt_ptr dst, amns_elt_srcptr a, amns_srcptr AMNS); \
 
#define TEMPLATE_amns_internal_red_declare(sl)    void amns_internal_red##sl(amns_elt_ptr S, amns_llong * V, amns_srcptr AMNS); \
 
#define TEMPLATE_amns_elt_is_reduced_declare(sl)    static inline bool amns_elt_is_reduced##sl (amns_elt_srcptr a, amns_srcptr AMNS); \
 
#define TEMPLATE_amns_internal_red(sl)
 
#define TEMPLATE_amns_elt_is_reduced(sl)
 
#define TEMPLATE_amns_elt_add(sl)
 
#define TEMPLATE_amns_elt_neg(sl)
 
#define TEMPLATE_amns_elt_sub(sl)
 
#define TEMPLATE_amns_elt_mul(sl)
 
#define TEMPLATE_amns_elt_mul_shift_p(sl)
 
#define TEMPLATE_amns_elt_mul_shift_n(sl)
 
#define TEMPLATE_amns_elt_sqr(sl)
 
#define TEMPLATE_amns_elt_sqr_shift_p(sl)
 
#define TEMPLATE_amns_elt_sqr_shift_n(sl)
 

Functions

 TEMPLATE_amns_elt_add_declare (2)
 
void amns_free (amns_ptr *AMNS)
 Free the amns system. More...
 
void amns_elt_alloc (amns_elt *dst, amns_srcptr AMNS)
 Allocate the amns (polynomial of degree less than n) element according to the degree of E. More...
 
void amns_elt_free (amns_elt *dst)
 Free the amns element. More...
 
void amns_print_bloc (amns_block b)
 Print b. More...
 
void amns_print_bloc_ul (amns_ulong b)
 Print an amns ulong (uint64_t or uint32_t) More...
 
void amns_print_elt_raw (const amns_block *x, uint8_t size)
 Print the AMNS element x. More...
 
void amns_print_elt_raw_ul (const amns_ulong *x, uint8_t size)
 Print an amns ulong vector. More...
 
void amns_print_elt (amns_elt_srcptr x, amns_srcptr AMNS)
 Print the AMNS element x. More...
 
void amns_print_elt_ul (const amns_ulong *x, amns_srcptr AMNS)
 Print an amns ulong vector. More...
 
void amns_print_AMNS (amns_srcptr AMNS)
 Print the AMNS system. More...
 
void amns_print_stat (amns_srcptr AMNS)
 Print the AMNS system statistic. More...
 
uint8_t amns_calculate_max_coeff_size (amns_elt_srcptr a, amns_srcptr AMNS)
 Calculate log2(||a||_infty) More...
 
amns_block amns_calculate_max_coeff (amns_elt_srcptr a, amns_srcptr AMNS)
 Calculate (||a||_infty) More...
 
void amns_internal_red_generic (amns_elt_ptr S, amns_llong *V, amns_srcptr AMNS)
 Internal reduction using Montgomery method, not optimised because the compiler cannot guess the loop size. More...
 
void amns_internal_red (amns_elt_ptr S, amns_llong *V, amns_srcptr AMNS)
 Internal reduction using Montgomery method, optimised with templates to allow the compiler to guess the loop size. More...
 
 TEMPLATE_amns_internal_red (2)
 
void set_fast_internal_reduction_nist521 (amns_ptr AMNS)
 Set up a dedicated AMNS internal reduction for NIST 521 (Mersenne prime), the AMNS must be exactly the one defined in mphell-curve.c. More...
 
void amns_internal_red_exact (amns_elt_ptr dst, amns_srcptr AMNS)
 Set dst such that dst(gamma) == R(gamma) et |coeffs(dst)| < 2^rho, use after addition when the coefficients become greater than max_digit_delta. More...
 
void amns_calcule_Ti (amns_ptr AMNS, const amns_block *P0, const amns_block *P1)
 Compute the polynomials (amns elements) Ti such that Ti(gamma) = 2^(rho.i) * phi^2. Used for binary to AMNS conversion. More...
 
void amns_calcule_gi (amns_ptr AMNS)
 Compute the number gi such that gi = gamma^i mod p. Used for AMNS to binary conversion. More...
 
void amns_calcule_Mi (amns_ptr AMNS, const amns_block *M)
 Compute the Mti used by the internal reduction. More...
 
void amns_calcule_Miprime (amns_ptr AMNS, const amns_block *Mprime)
 Compute the Mtiprime used by the internal reduction. More...
 
static bool amns_elt_is_reduced_generic (amns_elt_srcptr a, amns_srcptr AMNS)
 Test if the coefficient a_i of a are all such that |a_i|<2^rho. More...
 
 TEMPLATE_amns_elt_is_reduced (2)
 
void amns_elt_copy_ul_2_amns (amns_elt dst, const amns_ulong *a, amns_srcptr AMNS)
 Copy a unsigned vector into a signed vector modulo phi, the modulo is applied through the cast. More...
 
void amns_elt_read_sep (amns_block *x, char *str)
 Parser to read a signed AMNS vector. More...
 
void amns_elt_read_sep_ul (amns_ulong *x, char *str)
 Parser to read a unsigned AMNS vector. More...
 
void amns_alloc_init_str (amns_ptr *AMNS, char *str, number p)
 Allocate and initialise the amns system from the string generated by the Sage AMNS generator from https://github.com/arithPMNS/generalisation_amns. More...
 
uint8_t previous_power_2 (uint8_t x)
 Round to the previous power of 2. More...
 
void amns_init (amns_ptr AMNS, const amns_block *E, const amns_block *P0, const amns_block *P1, const amns_block *M, const amns_ulong *Mprime, number_srcptr p, number gamma, uint8_t rho, uint8_t nb_add_max)
 Initialise the amns system. More...
 
void amns_init_stat (amns_ptr AMNS)
 Initialise again the AMNS statistics. More...
 
void amns_elt_write (amns_block *x, uint8_t size, char *str)
 Write a amns element into a string. More...
 
void amns_elt_read (amns_block *x, char *str)
 Read a AMNS element from a string. More...
 
void amns_elt_read_ul (amns_ulong *x, char *str)
 Read a ulong polynomial from a string. More...
 
void amns_elt_set_zero (amns_elt_ptr dst, amns_srcptr AMNS)
 Set dst to 0. More...
 
void amns_mul_scalar_llong (amns_llong *dst, amns_elt_srcptr a, amns_ulong b, amns_srcptr AMNS)
 Multiply the llong polynomial a by the scalar b. More...
 
void amns_add_llong (amns_llong *dst, amns_llong *a, amns_llong *b, amns_srcptr AMNS)
 Add the llong polynomials a and b. More...
 
void binary_to_amns (number_srcptr a, amns_elt_ptr dst, amns_srcptr AMNS)
 Convert a number into its AMNS representation. More...
 
void binary_ui_to_amns (block a, amns_elt_ptr dst, amns_srcptr AMNS)
 Convert a small number into its AMNS representation. More...
 
void amns_to_binary (const amns_elt_srcptr a, number_ptr dst, amns_srcptr AMNS)
 Convert AMNS representation into a number. More...
 
bool amns_elt_is_zero (amns_elt_srcptr src, amns_srcptr AMNS)
 Test if src is zero. More...
 
bool amns_elt_isequal (amns_elt_srcptr src1, amns_elt_srcptr src2, amns_srcptr AMNS)
 Test if src1 == src2, if true OK, if false, must be tested on binary !!! More...
 
int8_t amns_elt_cmp (amns_elt_srcptr src1, amns_elt_srcptr src2, amns_srcptr AMNS)
 Compare src1 and src2. More...
 
int8_t amns_elt_cmp_ui (amns_elt_srcptr src1, block src2, amns_srcptr AMNS)
 Compare src1 and src2. More...
 
void amns_elt_copy (amns_elt_ptr dst, amns_elt_srcptr a, amns_srcptr AMNS)
 Copy a into dst. More...
 
void amns_elt_add_generic (amns_elt_ptr dst, amns_elt_srcptr a, amns_elt_srcptr b, amns_srcptr AMNS)
 Set dst to a + b, using a generic code not optimised. More...
 
void amns_elt_add (amns_elt_ptr dst, amns_elt_srcptr a, amns_elt_srcptr b, amns_srcptr AMNS)
 Set dst to a + b. More...
 
void amns_elt_neg (amns_elt_ptr dst, amns_elt_srcptr a, amns_srcptr AMNS)
 Set dst to -a. More...
 
void amns_elt_sub (amns_elt_ptr dst, amns_elt_srcptr a, amns_elt_srcptr b, amns_srcptr AMNS)
 Set dst to a - b. More...
 
 TEMPLATE_amns_elt_mul (2)
 
void amns_elt_sqr_generic (amns_elt_ptr dst, amns_elt_srcptr a, amns_srcptr AMNS)
 Set dst to a^2, using a generic code not optimised. More...
 
 TEMPLATE_amns_elt_sqr (2)
 

Detailed Description

Definition of Adapted Modular Number System (AMNS) functions.

Definition in file mphell-amns.c.

Macro Definition Documentation

◆ TEMPLATE_amns_elt_add

#define TEMPLATE_amns_elt_add (   sl)
Value:
void \
amns_elt_add##sl(amns_elt_ptr dst, amns_elt_srcptr a, amns_elt_srcptr b, amns_srcptr AMNS) \
{ \
/* Polynomial Addition */ \
const uint8_t n = sl; \
uint8_t i; \
\
PRAGMA_UNROLL \
for(i=0; i<n; i++) \
{ \
dst[i]=a[i]+b[i]; \
} \
\
/* Internal reduction (coeffs) */ \
\
if(!amns_elt_is_reduced(dst, AMNS)) \
{ \
amns_internal_red_exact(dst, AMNS); \
} \
} \
const amns_block * amns_elt_srcptr
Define amns_elt_srcptr, use in all functions where the parameter is const.
Definition: mphell-amns.h:73
amns_block * amns_elt_ptr
Define amns_elt_ptr, use in all functions.
Definition: mphell-amns.h:67
Define a AMNS.
Definition: mphell-amns.h:81

Definition at line 2359 of file mphell-amns.c.

◆ TEMPLATE_amns_elt_is_reduced

#define TEMPLATE_amns_elt_is_reduced (   sl)
Value:
static inline bool \
amns_elt_is_reduced##sl(amns_elt_srcptr a, amns_srcptr AMNS) \
{ \
const uint8_t n = sl; \
uint8_t i; \
\
for(i=0; i<n; i++) \
{ \
if((a[i] >= AMNS->max_digit_delta) || (a[i] <= AMNS->min_digit_delta)) \
{ \
return false; \
} \
} \
return true; \
} \

Definition at line 1127 of file mphell-amns.c.

◆ TEMPLATE_amns_elt_neg

#define TEMPLATE_amns_elt_neg (   sl)
Value:
void \
amns_elt_neg##sl(amns_elt_ptr dst, amns_elt_srcptr a, amns_srcptr AMNS) \
{ \
/* Polynomial Negation */ \
const uint8_t n = sl; \
uint8_t i; \
\
PRAGMA_UNROLL \
for(i=0; i<n; i++) \
{ \
dst[i]=-a[i]; \
} \
} \

Definition at line 2432 of file mphell-amns.c.

◆ TEMPLATE_amns_elt_sub

#define TEMPLATE_amns_elt_sub (   sl)
Value:
void \
amns_elt_sub##sl(amns_elt_ptr dst, amns_elt_srcptr a, amns_elt_srcptr b, amns_srcptr AMNS) \
{ \
/* Polynomial Substraction */ \
const uint8_t n = sl; \
uint8_t i; \
\
PRAGMA_UNROLL \
for(i=0; i<n; i++) \
{ \
dst[i]=a[i]-b[i]; \
} \
\
/* Internal reduction (coeffs) */ \
\
if(!amns_elt_is_reduced(dst, AMNS)) \
{ \
amns_internal_red_exact(dst, AMNS); \
} \
} \

Definition at line 2512 of file mphell-amns.c.

Function Documentation

◆ amns_add_llong()

void amns_add_llong ( amns_llong *  dst,
amns_llong *  a,
amns_llong *  b,
amns_srcptr  AMNS 
)

Add the llong polynomials a and b.

Parameters
dstDestination polynomial
aSource polynomial
bSource polynomial
AMNSAMNS system

Definition at line 2143 of file mphell-amns.c.

◆ amns_alloc_init_str()

void amns_alloc_init_str ( amns_ptr AMNS,
char *  str,
number  p 
)

Allocate and initialise the amns system from the string generated by the Sage AMNS generator from https://github.com/arithPMNS/generalisation_amns.

Parameters
AMNSAMNS to initialise
strString generated by the sage AMNS generator
pPrime number

Definition at line 1242 of file mphell-amns.c.

◆ amns_calculate_max_coeff()

amns_block amns_calculate_max_coeff ( amns_elt_srcptr  a,
amns_srcptr  AMNS 
)

Calculate (||a||_infty)

Parameters
Sourceamns element
AMNSAMNS system
Returns
||a||_infty

Definition at line 671 of file mphell-amns.c.

◆ amns_calculate_max_coeff_size()

uint8_t amns_calculate_max_coeff_size ( amns_elt_srcptr  a,
amns_srcptr  AMNS 
)

Calculate log2(||a||_infty)

Parameters
Sourceamns element
AMNSAMNS system
Returns
log2(||a||_infty)+1

Definition at line 645 of file mphell-amns.c.

◆ amns_calcule_gi()

void amns_calcule_gi ( amns_ptr  AMNS)

Compute the number gi such that gi = gamma^i mod p. Used for AMNS to binary conversion.

Parameters
AMNSAMNS system

Definition at line 1020 of file mphell-amns.c.

◆ amns_calcule_Mi()

void amns_calcule_Mi ( amns_ptr  AMNS,
const amns_block M 
)

Compute the Mti used by the internal reduction.

Parameters
MInternal reduction polynomial
AMNSAMNS system

Definition at line 1040 of file mphell-amns.c.

◆ amns_calcule_Miprime()

void amns_calcule_Miprime ( amns_ptr  AMNS,
const amns_block Mprime 
)

Compute the Mtiprime used by the internal reduction.

Parameters
Mprime-M^(-1) mod(E, phi)
AMNSAMNS system

Definition at line 1075 of file mphell-amns.c.

◆ amns_calcule_Ti()

void amns_calcule_Ti ( amns_ptr  AMNS,
const amns_block P0,
const amns_block P1 
)

Compute the polynomials (amns elements) Ti such that Ti(gamma) = 2^(rho.i) * phi^2. Used for binary to AMNS conversion.

Parameters
P0AMNS representation of phi^2
P1AMNS representation of rho * phi^2
AMNSAMNS system

Definition at line 983 of file mphell-amns.c.

◆ amns_elt_add()

void amns_elt_add ( amns_elt_ptr  dst,
amns_elt_srcptr  a,
amns_elt_srcptr  b,
amns_srcptr  AMNS 
)

Set dst to a + b.

Parameters
dstAMNS representation of a + b
aSource AMNS element
bSource AMNS element
AMNSAMNS system

Definition at line 2354 of file mphell-amns.c.

◆ amns_elt_add_generic()

void amns_elt_add_generic ( amns_elt_ptr  dst,
amns_elt_srcptr  a,
amns_elt_srcptr  b,
amns_srcptr  AMNS 
)

Set dst to a + b, using a generic code not optimised.

Parameters
dstAMNS representation of a + b
aSource AMNS element
bSource AMNS element
AMNSAMNS system

Definition at line 2329 of file mphell-amns.c.

◆ amns_elt_alloc()

void amns_elt_alloc ( amns_elt dst,
amns_srcptr  AMNS 
)

Allocate the amns (polynomial of degree less than n) element according to the degree of E.

Parameters
dstAMNS element to allocate
AMNSAMNS system

Definition at line 496 of file mphell-amns.c.

◆ amns_elt_cmp()

int8_t amns_elt_cmp ( amns_elt_srcptr  src1,
amns_elt_srcptr  src2,
amns_srcptr  AMNS 
)

Compare src1 and src2.

Parameters
src1AMNS representation of a integer
src2AMNS representation of a integer
AMNSAMNS system
Returns
-1 if src1 < src2
0 if src1 == src2
1 if src1 > src2

Definition at line 2284 of file mphell-amns.c.

◆ amns_elt_cmp_ui()

int8_t amns_elt_cmp_ui ( amns_elt_srcptr  src1,
block  src2,
amns_srcptr  AMNS 
)

Compare src1 and src2.

Parameters
src1AMNS representation of a integer
src2Unsigned integer
AMNSAMNS system
Returns
-1 if src1 < src2
0 if src1 == src2
1 if src1 > src2

Definition at line 2297 of file mphell-amns.c.

◆ amns_elt_copy()

void amns_elt_copy ( amns_elt_ptr  dst,
amns_elt_srcptr  a,
amns_srcptr  AMNS 
)

Copy a into dst.

Parameters
dstDestination AMNS element
aSource AMNS element
AMNSAMNS system

Definition at line 2310 of file mphell-amns.c.

◆ amns_elt_copy_ul_2_amns()

void amns_elt_copy_ul_2_amns ( amns_elt  dst,
const amns_ulong *  a,
amns_srcptr  AMNS 
)

Copy a unsigned vector into a signed vector modulo phi, the modulo is applied through the cast.

Parameters
dstAMNS signed vector
aUnsigned vector
AMNSAMNS system

Definition at line 1183 of file mphell-amns.c.

◆ amns_elt_free()

void amns_elt_free ( amns_elt dst)

Free the amns element.

Parameters
dstAMNS element to free

Definition at line 501 of file mphell-amns.c.

◆ amns_elt_is_reduced_generic()

static inline bool amns_elt_is_reduced_generic ( amns_elt_srcptr  a,
amns_srcptr  AMNS 
)
inlinestatic

Test if the coefficient a_i of a are all such that |a_i|<2^rho.

Parameters
aAMNS element to test
AMNSAMNS system
Returns
true if a is reduced (internal reduction)
false otherwise

Definition at line 1112 of file mphell-amns.c.

◆ amns_elt_is_zero()

bool amns_elt_is_zero ( amns_elt_srcptr  src,
amns_srcptr  AMNS 
)

Test if src is zero.

Parameters
srcAMNS representation of a integer
AMNSAMNS system
Returns
true if src is zero
false otherwise

Definition at line 2261 of file mphell-amns.c.

◆ amns_elt_isequal()

bool amns_elt_isequal ( amns_elt_srcptr  src1,
amns_elt_srcptr  src2,
amns_srcptr  AMNS 
)

Test if src1 == src2, if true OK, if false, must be tested on binary !!!

Parameters
src1AMNS representation of a integer
src2AMNS representation of a integer
AMNSAMNS system (bases, ...)
Returns
true if src1 == src2
false, can be still equal, AMNS allows multiplie representation

Definition at line 2271 of file mphell-amns.c.

◆ amns_elt_neg()

void amns_elt_neg ( amns_elt_ptr  dst,
amns_elt_srcptr  a,
amns_srcptr  AMNS 
)

Set dst to -a.

Parameters
dstAMNS representation of -a
aSource AMNS element
AMNSAMNS system

Definition at line 2427 of file mphell-amns.c.

◆ amns_elt_read()

void amns_elt_read ( amns_block x,
char *  str 
)

Read a AMNS element from a string.

Parameters
xDestination AMNS element
strSource string to read

Definition at line 2069 of file mphell-amns.c.

◆ amns_elt_read_sep()

void amns_elt_read_sep ( amns_block x,
char *  str 
)

Parser to read a signed AMNS vector.

Parameters
xDestination AMNS vector
strString to parse

Definition at line 1202 of file mphell-amns.c.

◆ amns_elt_read_sep_ul()

void amns_elt_read_sep_ul ( amns_ulong *  x,
char *  str 
)

Parser to read a unsigned AMNS vector.

Parameters
xDestination unsigned vector
strString to parse

Definition at line 1227 of file mphell-amns.c.

◆ amns_elt_read_ul()

void amns_elt_read_ul ( amns_ulong *  x,
char *  str 
)

Read a ulong polynomial from a string.

Parameters
xDestination polynomial
strSource string to read

Definition at line 2088 of file mphell-amns.c.

◆ amns_elt_set_zero()

void amns_elt_set_zero ( amns_elt_ptr  dst,
amns_srcptr  AMNS 
)

Set dst to 0.

Parameters
dstAMNS element
AMNSAMNS system

Definition at line 2103 of file mphell-amns.c.

◆ amns_elt_sqr_generic()

void amns_elt_sqr_generic ( amns_elt_ptr  dst,
amns_elt_srcptr  a,
amns_srcptr  AMNS 
)

Set dst to a^2, using a generic code not optimised.

Parameters
dstAMNS representation of a^2
aSource AMNS element
AMNSAMNS system

Definition at line 2852 of file mphell-amns.c.

◆ amns_elt_sub()

void amns_elt_sub ( amns_elt_ptr  dst,
amns_elt_srcptr  a,
amns_elt_srcptr  b,
amns_srcptr  AMNS 
)

Set dst to a - b.

Parameters
dstAMNS representation of a - b
aSource AMNS element
bSource AMNS element
AMNSAMNS system

Definition at line 2507 of file mphell-amns.c.

◆ amns_elt_write()

void amns_elt_write ( amns_block x,
uint8_t  size,
char *  str 
)

Write a amns element into a string.

Parameters
xAMNS element to write
sizeSize of x
strDestination string, must be large enough

Definition at line 2053 of file mphell-amns.c.

◆ amns_free()

void amns_free ( amns_ptr AMNS)

Free the amns system.

Parameters
AMNSAMNS system to free

Definition at line 444 of file mphell-amns.c.

◆ amns_init()

void amns_init ( amns_ptr  AMNS,
const amns_block E,
const amns_block P0,
const amns_block P1,
const amns_block M,
const amns_ulong *  Mprime,
number_srcptr  p,
number  gamma,
uint8_t  rho,
uint8_t  nb_add_max 
)

Initialise the amns system.

Parameters
AMNSAMNS to initialise
EExternal reduction polynomial
P0AMNS representation of phi^2
P1AMNS representation of rho * phi^2
MInternal reduction polynomial
Mprime-M^(-1) mod(E, phi)
pPrime number
gammaRoot of E mod p : E(gammma)=0 mod p
rhoReduced coefficient of the AMNS are < 2^rho
nb_add_maxMaximum number of consecutive addition / substraction that can be done without to call a costly internal reduction.

Definition at line 1324 of file mphell-amns.c.

◆ amns_init_stat()

void amns_init_stat ( amns_ptr  AMNS)

Initialise again the AMNS statistics.

Parameters
AMNSAMNS in use

Definition at line 2039 of file mphell-amns.c.

◆ amns_internal_red()

void amns_internal_red ( amns_elt_ptr  S,
amns_llong *  V,
amns_srcptr  AMNS 
)

Internal reduction using Montgomery method, optimised with templates to allow the compiler to guess the loop size.

Parameters
SResulting reduced vector
VVector to reduce
AMNSsystem

Definition at line 740 of file mphell-amns.c.

◆ amns_internal_red_exact()

void amns_internal_red_exact ( amns_elt_ptr  dst,
amns_srcptr  AMNS 
)

Set dst such that dst(gamma) == R(gamma) et |coeffs(dst)| < 2^rho, use after addition when the coefficients become greater than max_digit_delta.

Parameters
dstDestination and source amns element
AMNSAMNS system

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

◆ amns_internal_red_generic()

void amns_internal_red_generic ( amns_elt_ptr  S,
amns_llong *  V,
amns_srcptr  AMNS 
)

Internal reduction using Montgomery method, not optimised because the compiler cannot guess the loop size.

Parameters
SResulting reduced vector
VVector to reduce
AMNSsystem

Definition at line 697 of file mphell-amns.c.

◆ amns_mul_scalar_llong()

void amns_mul_scalar_llong ( amns_llong *  dst,
amns_elt_srcptr  a,
amns_ulong  b,
amns_srcptr  AMNS 
)

Multiply the llong polynomial a by the scalar b.

Parameters
dstDestination polynomial
aSource polynomial
bScalar (integer)
AMNSAMNS system

Definition at line 2124 of file mphell-amns.c.

◆ amns_print_AMNS()

void amns_print_AMNS ( amns_srcptr  AMNS)

Print the AMNS system.

Parameters
AMNSAMNS system

Definition at line 577 of file mphell-amns.c.

◆ amns_print_bloc()

void amns_print_bloc ( amns_block  b)

Print b.

Parameters
bAMNS block

Definition at line 510 of file mphell-amns.c.

◆ amns_print_bloc_ul()

void amns_print_bloc_ul ( amns_ulong  b)

Print an amns ulong (uint64_t or uint32_t)

Parameters
bUnsigned integer to print

Definition at line 524 of file mphell-amns.c.

◆ amns_print_elt()

void amns_print_elt ( amns_elt_srcptr  x,
amns_srcptr  AMNS 
)

Print the AMNS element x.

Parameters
xAMNS representation of X
AMNSAMNS system (bases, ...)

Definition at line 561 of file mphell-amns.c.

◆ amns_print_elt_raw()

void amns_print_elt_raw ( const amns_block x,
uint8_t  size 
)

Print the AMNS element x.

Parameters
xAMNS representation of X
sizeSize of x (in number of amns_block element)

Definition at line 533 of file mphell-amns.c.

◆ amns_print_elt_raw_ul()

void amns_print_elt_raw_ul ( const amns_ulong *  x,
uint8_t  size 
)

Print an amns ulong vector.

Parameters
xUnsigned integer vector to print
sizeSize of the vector

Definition at line 550 of file mphell-amns.c.

◆ amns_print_elt_ul()

void amns_print_elt_ul ( const amns_ulong *  x,
amns_srcptr  AMNS 
)

Print an amns ulong vector.

Parameters
xUnsigned integer vector to print
AMNSAMNS system

Definition at line 572 of file mphell-amns.c.

◆ amns_print_stat()

void amns_print_stat ( amns_srcptr  AMNS)

Print the AMNS system statistic.

Parameters
AMNSAMNS system

Definition at line 622 of file mphell-amns.c.

◆ amns_to_binary()

void amns_to_binary ( const amns_elt_srcptr  a,
number_ptr  dst,
amns_srcptr  AMNS 
)

Convert AMNS representation into a number.

Parameters
aAMNS representation of a
dstDestination number (binary representation of a)
AMNSAMNS system

Definition at line 2223 of file mphell-amns.c.

◆ binary_to_amns()

void binary_to_amns ( number_srcptr  a,
amns_elt_ptr  dst,
amns_srcptr  AMNS 
)

Convert a number into its AMNS representation.

Parameters
aSource number (binary representation)
dstAMNS representation of a
AMNSAMNS system

Definition at line 2154 of file mphell-amns.c.

◆ binary_ui_to_amns()

void binary_ui_to_amns ( block  a,
amns_elt_ptr  dst,
amns_srcptr  AMNS 
)

Convert a small number into its AMNS representation.

Parameters
aSource number (binary representation)
dstAMNS representation of a
AMNSAMNS system

Definition at line 2189 of file mphell-amns.c.

◆ previous_power_2()

uint8_t previous_power_2 ( uint8_t  x)

Round to the previous power of 2.

Parameters
x8 bits unsigned integer to round
Returns
Previous power of 2 before x

Definition at line 1316 of file mphell-amns.c.

◆ set_fast_internal_reduction_nist521()

void set_fast_internal_reduction_nist521 ( amns_ptr  AMNS)

Set up a dedicated AMNS internal reduction for NIST 521 (Mersenne prime), the AMNS must be exactly the one defined in mphell-curve.c.

Parameters
AMNSAMNS to modify

Definition at line 935 of file mphell-amns.c.