vli.h File Reference

Definition of Large Integer math. More...

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

Functions

uint32_t VliAdd (VeryLargeInt *result, VeryLargeInt const *left, VeryLargeInt const *right)
 Add two large integers. More...
 
void VliMul (VeryLargeIntProduct *result, VeryLargeInt const *left, VeryLargeInt const *right)
 Multiply two large integers. More...
 
void VliRShift (VeryLargeInt *result, VeryLargeInt const *in, uint32_t shift)
 Right shift a large integers. More...
 
uint32_t VliSub (VeryLargeInt *result, VeryLargeInt const *left, VeryLargeInt const *right)
 Subtract two large integers. More...
 
void VliSet (VeryLargeInt *result, VeryLargeInt const *in)
 Set a large integer's value. More...
 
void VliClear (VeryLargeInt *result)
 Clear a large integer's value. More...
 
int VliIsZero (VeryLargeInt const *in)
 Test if a large integer is zero. More...
 
void VliCondSet (VeryLargeInt *result, VeryLargeInt const *true_val, VeryLargeInt const *false_val, int truth_val)
 Conditionally Set a large inter's value to one of two values. More...
 
uint32_t VliTestBit (VeryLargeInt const *in, uint32_t bit)
 Test the value of a bit in a large integer. More...
 
int VliRand (VeryLargeInt *result, BitSupplier rnd_func, void *rnd_param)
 Generate a random large integer. More...
 
int VliCmp (VeryLargeInt const *left, VeryLargeInt const *right)
 compare two large integers. More...
 
void VliModAdd (VeryLargeInt *result, VeryLargeInt const *left, VeryLargeInt const *right, VeryLargeInt const *mod)
 Add two large integers modulo a value. More...
 
void VliModSub (VeryLargeInt *result, VeryLargeInt const *left, VeryLargeInt const *right, VeryLargeInt const *mod)
 Subtract two large integers modulo a value. More...
 
void VliModMul (VeryLargeInt *result, VeryLargeInt const *left, VeryLargeInt const *right, VeryLargeInt const *mod)
 Multiply two large integers modulo a value. More...
 
void VliModExp (VeryLargeInt *result, VeryLargeInt const *base, VeryLargeInt const *exp, VeryLargeInt const *mod)
 Exponentiate a large integer modulo a value. More...
 
void VliModInv (VeryLargeInt *result, VeryLargeInt const *input, VeryLargeInt const *mod)
 Invert a large integer modulo a value. More...
 
void VliModSquare (VeryLargeInt *result, VeryLargeInt const *input, VeryLargeInt const *mod)
 Square a large integer modulo a value. More...
 
void VliModBarrett (VeryLargeInt *result, VeryLargeIntProduct const *input, VeryLargeInt const *mod)
 Reduce a value to a modulo. More...
 

Detailed Description

Definition of Large Integer math.

Function Documentation

◆ VliAdd()

uint32_t VliAdd ( VeryLargeInt result,
VeryLargeInt const *  left,
VeryLargeInt const *  right 
)

Add two large integers.

Parameters
[out]resulttarget.
[in]leftThe first operand to be added.
[in]rightThe second operand to be added.
Returns
the carry portion of the addition.

◆ VliClear()

void VliClear ( VeryLargeInt result)

Clear a large integer's value.

Parameters
[out]resultvalue to clear.

◆ VliCmp()

int VliCmp ( VeryLargeInt const *  left,
VeryLargeInt const *  right 
)

compare two large integers.

Parameters
[in]leftthe left hand value.
[in]rightthe right hand value.
Returns
the sign of left - right

◆ VliCondSet()

void VliCondSet ( VeryLargeInt result,
VeryLargeInt const *  true_val,
VeryLargeInt const *  false_val,
int  truth_val 
)

Conditionally Set a large inter's value to one of two values.

Parameters
[out]resulttarget.
[in]true_valvalue to set if condition is true.
[in]false_valvalue to set if condition is false.
[in]truth_valvalue of condition.

◆ VliIsZero()

int VliIsZero ( VeryLargeInt const *  in)

Test if a large integer is zero.

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

◆ VliModAdd()

void VliModAdd ( VeryLargeInt result,
VeryLargeInt const *  left,
VeryLargeInt const *  right,
VeryLargeInt const *  mod 
)

Add two large integers modulo a value.

Parameters
[out]resulttarget.
[in]leftThe first operand to be added.
[in]rightThe second operand to be added.
[in]modThe modulo.

◆ VliModBarrett()

void VliModBarrett ( VeryLargeInt result,
VeryLargeIntProduct const *  input,
VeryLargeInt const *  mod 
)

Reduce a value to a modulo.

Parameters
[out]resulttarget.
[in]inputthe base.
[in]modThe modulo.
Warning
This function makes significant assumptions about the range of values input

◆ VliModExp()

void VliModExp ( VeryLargeInt result,
VeryLargeInt const *  base,
VeryLargeInt const *  exp,
VeryLargeInt const *  mod 
)

Exponentiate a large integer modulo a value.

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

◆ VliModInv()

void VliModInv ( VeryLargeInt result,
VeryLargeInt const *  input,
VeryLargeInt const *  mod 
)

Invert a large integer modulo a value.

Parameters
[out]resulttarget.
[in]inputthe value to invert.
[in]modThe modulo.

◆ VliModMul()

void VliModMul ( VeryLargeInt result,
VeryLargeInt const *  left,
VeryLargeInt const *  right,
VeryLargeInt const *  mod 
)

Multiply two large integers modulo a value.

Parameters
[out]resulttarget.
[in]leftThe first operand to be multiplied.
[in]rightThe second operand to be multiplied.
[in]modThe modulo.

◆ VliModSquare()

void VliModSquare ( VeryLargeInt result,
VeryLargeInt const *  input,
VeryLargeInt const *  mod 
)

Square a large integer modulo a value.

Parameters
[out]resulttarget.
[in]inputthe base.
[in]modThe modulo.

◆ VliModSub()

void VliModSub ( VeryLargeInt result,
VeryLargeInt const *  left,
VeryLargeInt const *  right,
VeryLargeInt const *  mod 
)

Subtract two large integers modulo a value.

Parameters
[out]resulttarget.
[in]leftThe operand to be subtracted from.
[in]rightThe operand to subtract.
[in]modThe modulo.

◆ VliMul()

void VliMul ( VeryLargeIntProduct result,
VeryLargeInt const *  left,
VeryLargeInt const *  right 
)

Multiply two large integers.

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

◆ VliRand()

int VliRand ( VeryLargeInt result,
BitSupplier  rnd_func,
void *  rnd_param 
)

Generate a random large integer.

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.

◆ VliRShift()

void VliRShift ( VeryLargeInt result,
VeryLargeInt const *  in,
uint32_t  shift 
)

Right shift a large integers.

Parameters
[out]resulttarget.
[in]inThe value to be shifted.
[in]shiftThe number of bits to shift.

◆ VliSet()

void VliSet ( VeryLargeInt result,
VeryLargeInt const *  in 
)

Set a large integer's value.

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

◆ VliSub()

uint32_t VliSub ( VeryLargeInt result,
VeryLargeInt const *  left,
VeryLargeInt const *  right 
)

Subtract two large integers.

Parameters
[out]resulttarget.
[in]leftThe operand to be subtracted from.
[in]rightThe operand to subtract.
Returns
1 on success, 0 on failure

◆ VliTestBit()

uint32_t VliTestBit ( VeryLargeInt const *  in,
uint32_t  bit 
)

Test the value of a bit in a large integer.

Parameters
[in]inthe value to test.
[in]bitthe bit index.
Returns
value of the bit (1 or 0).