BeeCrypt  4.2.1
Macros | Functions
mp.h File Reference

Multi-precision integer routines. More...

#include "beecrypt/api.h"
#include "beecrypt/mpopt.h"
Include dependency graph for mp.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define MP_HWBITS   (MP_WBITS >> 1)
 
#define MP_WBYTES   (MP_WBITS >> 3)
 
#define MP_WNIBBLES   (MP_WBITS >> 2)
 
#define MP_WORDS_TO_BITS(x)   ((x) << 6)
 
#define MP_WORDS_TO_NIBBLES(x)   ((x) << 4)
 
#define MP_WORDS_TO_BYTES(x)   ((x) << 3)
 
#define MP_BITS_TO_WORDS(x)   ((x) >> 6)
 
#define MP_NIBBLES_TO_WORDS(x)   ((x) >> 4)
 
#define MP_BYTES_TO_WORDS(x)   ((x) >> 3)
 
#define MP_MSBMASK   (((mpw) 0x1) << (MP_WBITS-1))
 
#define MP_LSBMASK   ((mpw) 0x1)
 
#define MP_ALLMASK   ~((mpw) 0x0)
 
#define mpcopy(size, dst, src)   memcpy(dst, src, MP_WORDS_TO_BYTES(size))
 
#define mpmove(size, dst, src)   memmove(dst, src, MP_WORDS_TO_BYTES(size))
 

Functions

void mpzero (size_t size, mpw *data)
 This function zeroes a multi-precision integer of a given size. More...
 
void mpfill (size_t size, mpw *data, mpw fill)
 This function fills each word of a multi-precision integer with a given value. More...
 
int mpodd (size_t size, const mpw *data)
 This functions tests if a multi-precision integer is odd. More...
 
int mpeven (size_t size, const mpw *data)
 This function tests if a multi-precision integer is even. More...
 
int mpz (size_t size, const mpw *data)
 This function tests if a multi-precision integer is zero. More...
 
int mpnz (size_t size, const mpw *data)
 This function tests if a multi-precision integer is not zero. More...
 
int mpeq (size_t size, const mpw *xdata, const mpw *ydata)
 This function tests if two multi-precision integers of the same size are equal. More...
 
int mpne (size_t size, const mpw *xdata, const mpw *ydata)
 This function tests if two multi-precision integers of the same size differ. More...
 
int mpgt (size_t size, const mpw *xdata, const mpw *ydata)
 This function tests if the first of two multi-precision integers of the same size is greater than the second. More...
 
int mplt (size_t size, const mpw *xdata, const mpw *ydata)
 This function tests if the first of two multi-precision integers of the same size is less than the second. More...
 
int mpge (size_t size, const mpw *xdata, const mpw *ydata)
 This function tests if the first of two multi-precision integers of the same size is greater than or equal to the second. More...
 
int mple (size_t size, const mpw *xdata, const mpw *ydata)
 This function tests if the first of two multi-precision integers of the same size is less than or equal to the second. More...
 
int mpcmp (size_t size, const mpw *xdata, const mpw *ydata)
 This function performs a comparison of two multi-precision integers of the same size. More...
 
int mpeqx (size_t xsize, const mpw *xdata, size_t ysize, const mpw *ydata)
 This function tests if two multi-precision integers of different size are equal. More...
 
int mpnex (size_t xsize, const mpw *xdata, size_t ysize, const mpw *ydata)
 This function tests if two multi-precision integers of different size are equal. More...
 
int mpgtx (size_t xsize, const mpw *xdata, size_t ysize, const mpw *ydata)
 This function tests if the first of two multi-precision integers of different size is greater than the second. More...
 
int mpltx (size_t xsize, const mpw *xdata, size_t ysize, const mpw *ydata)
 This function tests if the first of two multi-precision integers of different size is less than the second. More...
 
int mpgex (size_t xsize, const mpw *xdata, size_t ysize, const mpw *ydata)
 This function tests if the first of two multi-precision integers of different size is greater than or equal to the second. More...
 
int mplex (size_t xsize, const mpw *xdata, size_t ysize, const mpw *ydata)
 This function tests if the first of two multi-precision integers of different size is less than or equal to the second. More...
 
int mpcmpx (size_t xsize, const mpw *xdata, size_t ysize, const mpw *ydata)
 This function performs a comparison of two multi-precision integers of the different size. More...
 
int mpisone (size_t size, const mpw *data)
 This functions tests if the value of a multi-precision integer is equal to one. More...
 
int mpistwo (size_t size, const mpw *data)
 This function tests if the value of a multi-precision integer is equal to two. More...
 
int mpleone (size_t size, const mpw *data)
 This function tests if the value of a multi-precision integer is less than or equal to one. More...
 
int mpeqmone (size_t size, const mpw *xdata, const mpw *ydata)
 This function tests if multi-precision integer x is equal to y minus one. More...
 
int mpmsbset (size_t size, const mpw *data)
 This function tests if the most significant bit of a multi-precision integer is set. More...
 
int mplsbset (size_t size, const mpw *data)
 This function tests if the leiast significant bit of a multi-precision integer is set. More...
 
void mpsetmsb (size_t size, mpw *data)
 This function sets the most significant bit of a multi-precision integer. More...
 
void mpsetlsb (size_t size, mpw *data)
 This function sets the least significant bit of a multi-precision integer. More...
 
void mpclrmsb (size_t size, mpw *data)
 This function clears the most significant bit of a multi-precision integer. More...
 
void mpclrlsb (size_t size, mpw *data)
 This function clears the least significant bit of a multi-precision integer. More...
 
void mpand (size_t size, mpw *xdata, const mpw *ydata)
 This function computes the bit-wise AND of two multi-precision integers. Modifies xdata. More...
 
void mpor (size_t size, mpw *xdata, const mpw *ydata)
 This function computes the bit-wise OR of two multi-precision integers. Modifies xdata. More...
 
void mpxor (size_t size, mpw *xdata, const mpw *ydata)
 This function computes the bit-wise XOR of two multi-precision integers. Modifies xdata. More...
 
void mpnot (size_t size, mpw *data)
 This function flips all bits of a multi-precision integer. More...
 
void mpsetw (size_t size, mpw *xdata, mpw y)
 This function sets the value of a multi-precision integer to the given word. The given value is copied into the least significant word, while the most significant words are zeroed. More...
 
void mpsetws (size_t size, mpw *xdata, size_t y)
 This function sets the value of a multi-precision integer to the given word. The given value is copied into the least significant word(s), while the most significant words are zeroed. More...
 
void mpsetx (size_t xsize, mpw *xdata, size_t ysize, const mpw *ydata)
 This function set the value of the first multi-precision integer to the second, truncating the most significant words if ysize > xsize, or zeroing the most significant words if ysize < xsize. More...
 
int mpaddw (size_t size, mpw *xdata, mpw y)
 This function adds one word to a multi-precision integer. The performed operation is in pseudocode: x += y. More...
 
int mpadd (size_t size, mpw *xdata, const mpw *ydata)
 This function adds two multi-precision integers of equal size. The performed operation is in pseudocode: x += y. More...
 
int mpaddx (size_t xsize, mpw *xdata, size_t ysize, const mpw *ydata)
 This function adds two multi-precision integers of different size. The performed operation in pseudocode: x += y. More...
 
int mpsubw (size_t size, mpw *xdata, mpw y)
 This function subtracts one word to a multi-precision integer. The performed operation in pseudocode: x -= y. More...
 
int mpsub (size_t size, mpw *xdata, const mpw *ydata)
 This function subtracts two multi-precision integers of equal size. The performed operation in pseudocode: x -= y. More...
 
int mpsubx (size_t xsize, mpw *xdata, size_t ysize, const mpw *ydata)
 This function subtracts two multi-precision integers of different size. The performed operation in pseudocode: x -= y. More...
 
int mpmultwo (size_t size, mpw *data)
 
void mpneg (size_t size, mpw *data)
 This function negates a multi-precision integer. More...
 
size_t mpsize (size_t size, const mpw *data)
 This function returns the true size of a multi-precision integer, after stripping leading zero words. More...
 
size_t mpbits (size_t size, const mpw *data)
 This function returns the number of significant bits in a multi-precision integer. More...
 
size_t mpmszcnt (size_t size, const mpw *data)
 
size_t mplszcnt (size_t size, const mpw *data)
 
void mplshift (size_t size, mpw *data, size_t count)
 
void mprshift (size_t size, mpw *data, size_t count)
 
size_t mprshiftlsz (size_t size, mpw *data)
 
size_t mpnorm (size_t size, mpw *data)
 
void mpdivtwo (size_t size, mpw *data)
 
void mpsdivtwo (size_t size, mpw *data)
 
mpw mpsetmul (size_t size, mpw *result, const mpw *data, mpw y)
 This function performs a multi-precision multiply-setup. More...
 
mpw mpaddmul (size_t size, mpw *result, const mpw *data, mpw y)
 This function performs a mult-precision multiply-accumulate. More...
 
void mpaddsqrtrc (size_t size, mpw *result, const mpw *data)
 This function is used in the calculation of a multi-precision squaring. More...
 
void mpmul (mpw *result, size_t xsize, const mpw *xdata, size_t ysize, const mpw *ydata)
 This function computes a full multi-precision product. More...
 
void mpsqr (mpw *result, size_t size, const mpw *data)
 This function computes a full multi-precision square. More...
 
void mpgcd_w (size_t size, const mpw *xdata, const mpw *ydata, mpw *result, mpw *wksp)
 
int mpextgcd_w (size_t size, const mpw *xdata, const mpw *ydata, mpw *result, mpw *wksp)
 
mpw mppndiv (mpw xhi, mpw xlo, mpw y)
 
void mpmod (mpw *result, size_t xsize, const mpw *xdata, size_t ysize, const mpw *ydata, mpw *wksp)
 
void mpndivmod (mpw *result, size_t xsize, const mpw *xdata, size_t ysize, const mpw *ydata, mpw *wksp)
 
void mpprint (size_t size, const mpw *data)
 
void mpprintln (size_t size, const mpw *data)
 
void mpfprint (FILE *f, size_t size, const mpw *data)
 
void mpfprintln (FILE *f, size_t size, const mpw *data)
 
int i2osp (byte *osdata, size_t ossize, const mpw *idata, size_t isize)
 
int os2ip (mpw *idata, size_t isize, const byte *osdata, size_t ossize)
 
int hs2ip (mpw *idata, size_t isize, const char *hsdata, size_t hssize)
 

Detailed Description

Multi-precision integer routines.

The routines declared here are all low-level operations, most of them suitable to be implemented in assembler. Prime candidates are in order of importance (according to gprof):

With some smart use of available assembler instructions, it's possible to speed these routines up by a factor of 2 to 4.

Author
Bob Deblier bob.d.nosp@m.ebli.nosp@m.er@te.nosp@m.lene.nosp@m.t.be

Macro Definition Documentation

◆ MP_ALLMASK

#define MP_ALLMASK   ~((mpw) 0x0)

◆ MP_BITS_TO_WORDS

#define MP_BITS_TO_WORDS (   x)    ((x) >> 6)

◆ MP_BYTES_TO_WORDS

#define MP_BYTES_TO_WORDS (   x)    ((x) >> 3)

◆ MP_HWBITS

#define MP_HWBITS   (MP_WBITS >> 1)

◆ MP_LSBMASK

#define MP_LSBMASK   ((mpw) 0x1)

◆ MP_MSBMASK

#define MP_MSBMASK   (((mpw) 0x1) << (MP_WBITS-1))

◆ MP_NIBBLES_TO_WORDS

#define MP_NIBBLES_TO_WORDS (   x)    ((x) >> 4)

◆ MP_WBYTES

#define MP_WBYTES   (MP_WBITS >> 3)

◆ MP_WNIBBLES

#define MP_WNIBBLES   (MP_WBITS >> 2)

◆ MP_WORDS_TO_BITS

#define MP_WORDS_TO_BITS (   x)    ((x) << 6)

◆ MP_WORDS_TO_BYTES

#define MP_WORDS_TO_BYTES (   x)    ((x) << 3)

◆ MP_WORDS_TO_NIBBLES

#define MP_WORDS_TO_NIBBLES (   x)    ((x) << 4)

◆ mpcopy

#define mpcopy (   size,
  dst,
  src 
)    memcpy(dst, src, MP_WORDS_TO_BYTES(size))

◆ mpmove

#define mpmove (   size,
  dst,
  src 
)    memmove(dst, src, MP_WORDS_TO_BYTES(size))

Function Documentation

◆ hs2ip()

int hs2ip ( mpw idata,
size_t  isize,
const char *  hsdata,
size_t  hssize 
)

◆ i2osp()

int i2osp ( byte osdata,
size_t  ossize,
const mpw idata,
size_t  isize 
)

◆ mpadd()

int mpadd ( size_t  size,
mpw xdata,
const mpw ydata 
)

This function adds two multi-precision integers of equal size. The performed operation is in pseudocode: x += y.

Parameters
sizeThe size of the multi-precision integers.
xdataThe first multi-precision integer.
ydataThe second multi-precision integer.
Returns
The carry-over value of the operation; this value is either 0 or 1.

◆ mpaddmul()

mpw mpaddmul ( size_t  size,
mpw result,
const mpw data,
mpw  y 
)

This function performs a mult-precision multiply-accumulate.

This function is used in the computation of a full multi-precision multiplication. It computes the product-by-one-word and accumulates it with the previous result.

Parameters
sizeThe size of multi-precision integer multiplier.
resultThe place where result will be accumulated.
dataThe multi-precision integer multiplier.
yThe multiplicand.
Return values
Thecarry-over multi-precision word.

◆ mpaddsqrtrc()

void mpaddsqrtrc ( size_t  size,
mpw result,
const mpw data 
)

This function is used in the calculation of a multi-precision squaring.

◆ mpaddw()

int mpaddw ( size_t  size,
mpw xdata,
mpw  y 
)

This function adds one word to a multi-precision integer. The performed operation is in pseudocode: x += y.

Parameters
sizeThe size of the multi-precision integer.
xdataThe first multi-precision integer.
yThe multi-precision word.
Returns
The carry-over value of the operation; this value is either 0 or 1.

◆ mpaddx()

int mpaddx ( size_t  xsize,
mpw xdata,
size_t  ysize,
const mpw ydata 
)

This function adds two multi-precision integers of different size. The performed operation in pseudocode: x += y.

Parameters
xsizeThe size of the first multi-precision integer.
xdataThe first multi-precision integer.
ysizeThe size of the second multi-precision integer.
ydataThe second multi-precision integer.
Returns
The carry-over value of the operation; this value is either 0 or 1.

◆ mpand()

mpand ( size_t  size,
mpw xdata,
const mpw ydata 
)

This function computes the bit-wise AND of two multi-precision integers. Modifies xdata.

Parameters
sizeThe size of the multi-precision integers.
xdataThe multi-precision integer data.
ydataThe multi-precision integer data.

◆ mpbits()

size_t mpbits ( size_t  size,
const mpw data 
)

This function returns the number of significant bits in a multi-precision integer.

Parameters
sizeThe size of the multi-precision integer.
dataThe multi-precision integer data.

◆ mpclrlsb()

void mpclrlsb ( size_t  size,
mpw data 
)

This function clears the least significant bit of a multi-precision integer.

Parameters
sizeThe size of the multi-precision integer.
dataThe multi-precision integer data.

◆ mpclrmsb()

void mpclrmsb ( size_t  size,
mpw data 
)

This function clears the most significant bit of a multi-precision integer.

Parameters
sizeThe size of the multi-precision integer.
dataThe multi-precision integer data.

◆ mpcmp()

int mpcmp ( size_t  size,
const mpw xdata,
const mpw ydata 
)

This function performs a comparison of two multi-precision integers of the same size.

Note
The comparison treats the arguments as unsigned.
Return values
-1if x < y
0if x == y
1if x > y

◆ mpcmpx()

int mpcmpx ( size_t  xsize,
const mpw xdata,
size_t  ysize,
const mpw ydata 
)

This function performs a comparison of two multi-precision integers of the different size.

Note
The comparison treats the arguments as unsigned.
Return values
-1if x < y
0if x == y
1if x > y

◆ mpdivtwo()

void mpdivtwo ( size_t  size,
mpw data 
)

◆ mpeq()

int mpeq ( size_t  size,
const mpw xdata,
const mpw ydata 
)

This function tests if two multi-precision integers of the same size are equal.

Parameters
sizeThe size of the multi-precision integers.
xdataThe first multi-precision integer.
ydataThe second multi-precision integer.
Return values
1if equal
0if not equal

◆ mpeqmone()

int mpeqmone ( size_t  size,
const mpw xdata,
const mpw ydata 
)

This function tests if multi-precision integer x is equal to y minus one.

Parameters
sizeThe size of the multi-precision integers.
xdataThe first multi-precision integer.
ydataThe second multi-precision integer.
Return values
1if less than or equal to one.
0if greater than one.

◆ mpeqx()

int mpeqx ( size_t  xsize,
const mpw xdata,
size_t  ysize,
const mpw ydata 
)

This function tests if two multi-precision integers of different size are equal.

Parameters
xsizeThe size of the first multi-precision integer.
xdataThe first multi-precision integer.
ysizeThe size of the first multi-precision integer.
ydataThe second multi-precision integer.
Return values
1if equal
0if not equal

◆ mpeven()

int mpeven ( size_t  size,
const mpw data 
)

This function tests if a multi-precision integer is even.

Parameters
sizeThe size of the multi-precision integer.
dataThe multi-precision integer data.
Return values
1if even
0if odd

◆ mpextgcd_w()

int mpextgcd_w ( size_t  size,
const mpw xdata,
const mpw ydata,
mpw result,
mpw wksp 
)

◆ mpfill()

void mpfill ( size_t  size,
mpw data,
mpw  fill 
)

This function fills each word of a multi-precision integer with a given value.

Parameters
sizeThe size of the multi-precision integer.
dataThe multi-precision integer data.
fillThe value fill the data with.

◆ mpfprint()

void mpfprint ( FILE *  f,
size_t  size,
const mpw data 
)

◆ mpfprintln()

void mpfprintln ( FILE *  f,
size_t  size,
const mpw data 
)

◆ mpgcd_w()

void mpgcd_w ( size_t  size,
const mpw xdata,
const mpw ydata,
mpw result,
mpw wksp 
)

◆ mpge()

int mpge ( size_t  size,
const mpw xdata,
const mpw ydata 
)

This function tests if the first of two multi-precision integers of the same size is greater than or equal to the second.

Note
The comparison treats the arguments as unsigned.
Parameters
sizeThe size of the multi-precision integers.
xdataThe first multi-precision integer.
ydataThe second multi-precision integer.
Return values
1if greater or equal
0if less

◆ mpgex()

int mpgex ( size_t  xsize,
const mpw xdata,
size_t  ysize,
const mpw ydata 
)

This function tests if the first of two multi-precision integers of different size is greater than or equal to the second.

Note
The comparison treats the arguments as unsigned.
Parameters
xsizeThe size of the first multi-precision integer.
xdataThe first multi-precision integer.
ysizeThe size of the second multi-precision integer.
ydataThe second multi-precision integer.
Return values
1if greater or equal
0if less

◆ mpgt()

int mpgt ( size_t  size,
const mpw xdata,
const mpw ydata 
)

This function tests if the first of two multi-precision integers of the same size is greater than the second.

Note
The comparison treats the arguments as unsigned.
Parameters
sizeThe size of the multi-precision integers.
xdataThe first multi-precision integer.
ydataThe second multi-precision integer.
Return values
1if greater
0if less or equal

◆ mpgtx()

int mpgtx ( size_t  xsize,
const mpw xdata,
size_t  ysize,
const mpw ydata 
)

This function tests if the first of two multi-precision integers of different size is greater than the second.

Note
The comparison treats the arguments as unsigned.
Parameters
xsizeThe size of the first multi-precision integer.
xdataThe first multi-precision integer.
ysizeThe size of the second multi-precision integer.
ydataThe second multi-precision integer.
Return values
1if greater
0if less or equal

◆ mpisone()

int mpisone ( size_t  size,
const mpw data 
)

This functions tests if the value of a multi-precision integer is equal to one.

Parameters
sizeThe size of the multi-precision integer.
dataThe multi-precision integer data.
Return values
1if one
0if not one

◆ mpistwo()

int mpistwo ( size_t  size,
const mpw data 
)

This function tests if the value of a multi-precision integer is equal to two.

Parameters
sizeThe size of the multi-precision integer.
dataThe multi-precision integer data.
Return values
1if two
0if not two

◆ mple()

int mple ( size_t  size,
const mpw xdata,
const mpw ydata 
)

This function tests if the first of two multi-precision integers of the same size is less than or equal to the second.

Note
The comparison treats the arguments as unsigned.
Parameters
sizeThe size of the multi-precision integers.
xdataThe first multi-precision integer.
ydataThe second multi-precision integer.
Return values
1if less or equal
0if greater

◆ mpleone()

int mpleone ( size_t  size,
const mpw data 
)

This function tests if the value of a multi-precision integer is less than or equal to one.

Parameters
sizeThe size of the multi-precision integer.
dataThe multi-precision integer data.
Return values
1if less than or equal to one.
0if greater than one.

◆ mplex()

int mplex ( size_t  xsize,
const mpw xdata,
size_t  ysize,
const mpw ydata 
)

This function tests if the first of two multi-precision integers of different size is less than or equal to the second.

Note
The comparison treats the arguments as unsigned.
Parameters
xsizeThe size of the first multi-precision integer.
xdataThe first multi-precision integer.
ysizeThe size of the second multi-precision integer.
ydataThe second multi-precision integer.
Return values
1if less or equal
0if greater

◆ mplsbset()

int mplsbset ( size_t  size,
const mpw data 
)

This function tests if the leiast significant bit of a multi-precision integer is set.

Parameters
sizeThe size of the multi-precision integer.
dataThe multi-precision integer data.
Return values
1if set
0if not set

◆ mplshift()

void mplshift ( size_t  size,
mpw data,
size_t  count 
)

◆ mplszcnt()

size_t mplszcnt ( size_t  size,
const mpw data 
)

◆ mplt()

int mplt ( size_t  size,
const mpw xdata,
const mpw ydata 
)

This function tests if the first of two multi-precision integers of the same size is less than the second.

Note
The comparison treats the arguments as unsigned.
Parameters
sizeThe size of the multi-precision integers.
xdataThe first multi-precision integer.
ydataThe second multi-precision integer.
Return values
1if less
0if greater or equal

◆ mpltx()

int mpltx ( size_t  xsize,
const mpw xdata,
size_t  ysize,
const mpw ydata 
)

This function tests if the first of two multi-precision integers of different size is less than the second.

Note
The comparison treats the arguments as unsigned.
Parameters
xsizeThe size of the first multi-precision integer.
xdataThe first multi-precision integer.
ysizeThe size of the second multi-precision integer.
ydataThe second multi-precision integer.
Return values
1if less
0if greater or equal

◆ mpmod()

void mpmod ( mpw result,
size_t  xsize,
const mpw xdata,
size_t  ysize,
const mpw ydata,
mpw wksp 
)

◆ mpmsbset()

int mpmsbset ( size_t  size,
const mpw data 
)

This function tests if the most significant bit of a multi-precision integer is set.

Parameters
sizeThe size of the multi-precision integer.
dataThe multi-precision integer data.
Return values
1if set
0if not set

◆ mpmszcnt()

size_t mpmszcnt ( size_t  size,
const mpw data 
)

◆ mpmul()

void mpmul ( mpw result,
size_t  xsize,
const mpw xdata,
size_t  ysize,
const mpw ydata 
)

This function computes a full multi-precision product.

◆ mpmultwo()

int mpmultwo ( size_t  size,
mpw data 
)

◆ mpndivmod()

void mpndivmod ( mpw result,
size_t  xsize,
const mpw xdata,
size_t  ysize,
const mpw ydata,
mpw wksp 
)

◆ mpne()

int mpne ( size_t  size,
const mpw xdata,
const mpw ydata 
)

This function tests if two multi-precision integers of the same size differ.

Parameters
sizeThe size of the multi-precision integers.
xdataThe first multi-precision integer.
ydataThe second multi-precision integer.
Return values
1if not equal
0if equal

◆ mpneg()

void mpneg ( size_t  size,
mpw data 
)

This function negates a multi-precision integer.

Parameters
sizeThe size of the multi-precision integer.
dataThe multi-precision integer data.

◆ mpnex()

int mpnex ( size_t  xsize,
const mpw xdata,
size_t  ysize,
const mpw ydata 
)

This function tests if two multi-precision integers of different size are equal.

Parameters
xsizeThe size of the first multi-precision integer.
xdataThe first multi-precision integer.
ysizeThe size of the first multi-precision integer.
ydataThe second multi-precision integer.
Return values
1if equal
0if not equal

◆ mpnorm()

size_t mpnorm ( size_t  size,
mpw data 
)

◆ mpnot()

mpnot ( size_t  size,
mpw data 
)

This function flips all bits of a multi-precision integer.

Parameters
sizeThe size of the multi-precision integer.
dataThe multi-precision integer data.

◆ mpnz()

int mpnz ( size_t  size,
const mpw data 
)

This function tests if a multi-precision integer is not zero.

Parameters
sizeThe size of the multi-precision integer.
dataThe multi-precision integer data.
Return values
1if not zero
0if zero

◆ mpodd()

int mpodd ( size_t  size,
const mpw data 
)

This functions tests if a multi-precision integer is odd.

Parameters
sizeThe size of the multi-precision integer.
dataThe multi-precision integer data.
Return values
1if odd
0if even

◆ mpor()

void mpor ( size_t  size,
mpw xdata,
const mpw ydata 
)

This function computes the bit-wise OR of two multi-precision integers. Modifies xdata.

Parameters
sizeThe size of the multi-precision integer.
xdataThe multi-precision integer data.
ydataThe multi-precision integer data.

◆ mppndiv()

mpw mppndiv ( mpw  xhi,
mpw  xlo,
mpw  y 
)

◆ mpprint()

void mpprint ( size_t  size,
const mpw data 
)

◆ mpprintln()

void mpprintln ( size_t  size,
const mpw data 
)

◆ mprshift()

void mprshift ( size_t  size,
mpw data,
size_t  count 
)

◆ mprshiftlsz()

size_t mprshiftlsz ( size_t  size,
mpw data 
)

◆ mpsdivtwo()

void mpsdivtwo ( size_t  size,
mpw data 
)

◆ mpsetlsb()

void mpsetlsb ( size_t  size,
mpw data 
)

This function sets the least significant bit of a multi-precision integer.

Parameters
sizeThe size of the multi-precision integer.
dataThe multi-precision integer data.

◆ mpsetmsb()

void mpsetmsb ( size_t  size,
mpw data 
)

This function sets the most significant bit of a multi-precision integer.

Parameters
sizeThe size of the multi-precision integer.
dataThe multi-precision integer data.

◆ mpsetmul()

mpw mpsetmul ( size_t  size,
mpw result,
const mpw data,
mpw  y 
)

This function performs a multi-precision multiply-setup.

This function is used in the computation of a full multi-precision multiplication. By using it we can shave off a few cycles; otherwise we'd have to zero the least significant half of the result first and use another call to the slightly slower mpaddmul function.

Parameters
sizeThe size of multi-precision integer multiplier.
resultThe place where result will be accumulated.
dataThe multi-precision integer multiplier.
yThe multiplicand.
Returns
The carry-over multi-precision word.

◆ mpsetw()

void mpsetw ( size_t  size,
mpw xdata,
mpw  y 
)

This function sets the value of a multi-precision integer to the given word. The given value is copied into the least significant word, while the most significant words are zeroed.

Parameters
sizeThe size of the multi-precision integer.
xdataThe multi-precision integer data.
yThe value to be assigned.

◆ mpsetws()

void mpsetws ( size_t  size,
mpw xdata,
size_t  y 
)

This function sets the value of a multi-precision integer to the given word. The given value is copied into the least significant word(s), while the most significant words are zeroed.

Parameters
sizeThe size of the multi-precision integer.
xdataThe multi-precision integer data.
yThe value.

◆ mpsetx()

void mpsetx ( size_t  xsize,
mpw xdata,
size_t  ysize,
const mpw ydata 
)

This function set the value of the first multi-precision integer to the second, truncating the most significant words if ysize > xsize, or zeroing the most significant words if ysize < xsize.

Parameters
xsizeThe size of the first multi-precision integer.
xdataThe first multi-precision integer.
ysizeThe size of the second multi-precision integer.
ydataThe second multi-precision integer.

◆ mpsize()

size_t mpsize ( size_t  size,
const mpw data 
)

This function returns the true size of a multi-precision integer, after stripping leading zero words.

Parameters
sizeThe size of the multi-precision integer.
dataThe multi-precision integer data.

◆ mpsqr()

void mpsqr ( mpw result,
size_t  size,
const mpw data 
)

This function computes a full multi-precision square.

◆ mpsub()

int mpsub ( size_t  size,
mpw xdata,
const mpw ydata 
)

This function subtracts two multi-precision integers of equal size. The performed operation in pseudocode: x -= y.

Parameters
sizeThe size of the multi-precision integers.
xdataThe first multi-precision integer.
ydataThe second multi-precision integer.
Returns
The carry-over value of the operation; this value is either 0 or 1.

◆ mpsubw()

int mpsubw ( size_t  size,
mpw xdata,
mpw  y 
)

This function subtracts one word to a multi-precision integer. The performed operation in pseudocode: x -= y.

Parameters
sizeThe size of the multi-precision integers.
xdataThe first multi-precision integer.
yThe multi-precision word.
Returns
The carry-over value of the operation; this value is either 0 or 1.

◆ mpsubx()

int mpsubx ( size_t  xsize,
mpw xdata,
size_t  ysize,
const mpw ydata 
)

This function subtracts two multi-precision integers of different size. The performed operation in pseudocode: x -= y.

Parameters
xsizeThe size of the first multi-precision integer.
xdataThe first multi-precision integer.
ysizeThe size of the second multi-precision integer.
ydataThe second multi-precision integer.
Returns
The carry-over value of the operation; this value is either 0 or 1.

◆ mpxor()

void mpxor ( size_t  size,
mpw xdata,
const mpw ydata 
)

This function computes the bit-wise XOR of two multi-precision integers. Modifies xdata.

Parameters
sizeThe size of the multi-precision integer.
xdataThe multi-precision integer data.
ydataThe multi-precision integer data.

◆ mpz()

int mpz ( size_t  size,
const mpw data 
)

This function tests if a multi-precision integer is zero.

Parameters
sizeThe size of the multi-precision integer.
dataThe multi-precision integer data.
Return values
1if zero
0if not zero

◆ mpzero()

void mpzero ( size_t  size,
mpw data 
)

This function zeroes a multi-precision integer of a given size.

Parameters
sizeThe size of the multi-precision integer.
dataThe multi-precision integer data.

◆ os2ip()

int os2ip ( mpw idata,
size_t  isize,
const byte osdata,
size_t  ossize 
)