fp.h File Reference

Definition of Fp math. More...

#include <stddef.h>
#include <stdint.h>
#include "epid/common/bitsupplier.h"

Functions

int FpInField (FpElem const *in)
 Test if an element is in Fp. More...
 
void FpAdd (FpElem *result, FpElem const *left, FpElem const *right)
 Add two elements of Fp. More...
 
void FpMul (FpElem *result, FpElem const *left, FpElem const *right)
 Multiply two elements of Fp. More...
 
void FpSub (FpElem *result, FpElem const *left, FpElem const *right)
 Subtract two elements of Fp. More...
 
void FpExp (FpElem *result, FpElem const *base, VeryLargeInt const *exp)
 Exponentiate an element of Fp by a large integer. More...
 
void FpNeg (FpElem *result, FpElem const *in)
 Negate an element of Fp. More...
 
int FpEq (FpElem const *left, FpElem const *right)
 Test if two elements in Fp are equal. More...
 
void FpInv (FpElem *result, FpElem const *in)
 Invert an element of Fp. More...
 
int FpRand (FpElem *result, BitSupplier rnd_func, void *rnd_param)
 Generate a random element of Fp. More...
 
int FpRandNonzero (FpElem *result, BitSupplier rnd_func, void *rnd_param)
 Generate a non-zero random element of Fp. More...
 
void FpClear (FpElem *result)
 Clear an element of Fp. More...
 
void FpSet (FpElem *result, uint32_t in)
 Set a element of Fp's value. More...
 
void FpFromHash (FpElem *result, unsigned char const *hash, size_t len)
 Reinterpret a buffer as an element of Fp. More...
 

Detailed Description

Definition of Fp math.

Function Documentation

◆ FpAdd()

void FpAdd ( FpElem result,
FpElem const *  left,
FpElem const *  right 
)

Add two elements of Fp.

Parameters
[out]resultof adding left and right.
[in]leftThe first operand to be added.
[in]rightThe second operand to be added.

◆ FpClear()

void FpClear ( FpElem result)

Clear an element of Fp.

Parameters
[out]resultvalue to clear.

◆ FpEq()

int FpEq ( FpElem const *  left,
FpElem const *  right 
)

Test if two elements in Fp are equal.

Parameters
[in]leftThe first operand to be tested.
[in]rightThe second operand to be tested.
Returns
A value different from zero (i.e., true) if indeed the values are equal. Zero (i.e., false) otherwise.

◆ FpExp()

void FpExp ( FpElem result,
FpElem const *  base,
VeryLargeInt const *  exp 
)

Exponentiate an element of Fp by a large integer.

Parameters
[out]resulttarget.
[in]basethe base.
[in]expthe exponent.

◆ FpFromHash()

void FpFromHash ( FpElem result,
unsigned char const *  hash,
size_t  len 
)

Reinterpret a buffer as an element of Fp.

Parameters
[out]resulttarget.
[in]hashbuffer to reinterpret.
[in]lenlength of hash in bytes.

◆ FpInField()

int FpInField ( FpElem const *  in)

Test if an element is in Fp.

Parameters
[in]inthe element to test
Returns
A value different from zero (i.e., true) indeed the value is in the field. Zero (i.e., false) otherwise.

◆ FpInv()

void FpInv ( FpElem result,
FpElem const *  in 
)

Invert an element of Fp.

Parameters
[out]resulttarget.
[in]inthe value to invert.

◆ FpMul()

void FpMul ( FpElem result,
FpElem const *  left,
FpElem const *  right 
)

Multiply two elements of Fp.

Parameters
[out]resultof multiplying left and right.
[in]leftThe first operand to be multiplied.
[in]rightThe second operand to be multiplied.

◆ FpNeg()

void FpNeg ( FpElem result,
FpElem const *  in 
)

Negate an element of Fp.

Parameters
[out]resulttarget.
[in]inthe value to negate.

◆ FpRand()

int FpRand ( FpElem result,
BitSupplier  rnd_func,
void *  rnd_param 
)

Generate a random element of Fp.

Parameters
[in]resultthe random value.
[in]rnd_funcRandom number generator.
[in]rnd_paramPass through context data for rnd_func.
Returns
A value different from zero (i.e., true) if on success. Zero (i.e., false) otherwise.

◆ FpRandNonzero()

int FpRandNonzero ( FpElem result,
BitSupplier  rnd_func,
void *  rnd_param 
)

Generate a non-zero random element of Fp.

Parameters
[in]resultthe random value.
[in]rnd_funcRandom number generator.
[in]rnd_paramPass through context data for rnd_func.
Returns
A value different from zero (i.e., true) if on success. Zero (i.e., false) otherwise.

◆ FpSet()

void FpSet ( FpElem result,
uint32_t  in 
)

Set a element of Fp's value.

Parameters
[out]resulttarget.
[in]invalue to set.

◆ FpSub()

void FpSub ( FpElem result,
FpElem const *  left,
FpElem const *  right 
)

Subtract two elements of Fp.

Parameters
[out]resultof subtracting left from right.
[in]leftThe operand to be subtracted from.
[in]rightThe operand to subtract.