BigDigits  2.6.1
Typedefs | Functions
bigdigits.h File Reference

Interface to core BigDigits "mp" functions using fixed-length arrays. More...

Typedefs

typedef uint32_t DIGIT_T
 The basic BigDigit element, an unsigned 32-bit integer. More...
 

Functions

int mpAbs (DIGIT_T x[], const DIGIT_T y[], size_t ndigits)
 Sets x = |y|, the absolute value of y. More...
 
DIGIT_T mpAdd (DIGIT_T w[], const DIGIT_T u[], const DIGIT_T v[], size_t ndigits)
 Computes w = u + v, returns carry. More...
 
void mpAndBits (DIGIT_T a[], const DIGIT_T b[], const DIGIT_T c[], size_t ndigits)
 Computes bitwise a = b AND c. More...
 
size_t mpBitLength (const DIGIT_T a[], size_t ndigits)
 Returns number of significant bits in a. More...
 
int mpChs (DIGIT_T x[], const DIGIT_T y[], size_t ndigits)
 Sets x = -y. More...
 
int mpCompare (const DIGIT_T a[], const DIGIT_T b[], size_t ndigits)
 Returns sign of (a-b) as {-1,0,+1} More...
 
int mpCompare_ct (const DIGIT_T a[], const DIGIT_T b[], size_t ndigits)
 Returns sign of (a-b) as {-1,0,+1} using constant-time algorithm. More...
 
const char * mpCompileTime (void)
 Returns a pointer to a static string containing the time of compilation. More...
 
size_t mpConvFromDecimal (DIGIT_T a[], size_t ndigits, const char *s)
 Converts a string in decimal format to a big digit. More...
 
size_t mpConvFromHex (DIGIT_T a[], size_t ndigits, const char *s)
 Converts a string in hexadecimal format to a big digit. More...
 
size_t mpConvFromOctets (DIGIT_T a[], size_t ndigits, const unsigned char *c, size_t nbytes)
 Converts nbytes octets into big digit a of max size ndigits. More...
 
size_t mpConvToDecimal (const DIGIT_T a[], size_t ndigits, char *s, size_t smax)
 Converts big digit a into a string in decimal format, where s has size smax including the terminating zero. More...
 
size_t mpConvToHex (const DIGIT_T a[], size_t ndigits, char *s, size_t smax)
 Converts big digit a into a string in hexadecimal format, where s has size smax including the terminating zero. More...
 
size_t mpConvToOctets (const DIGIT_T a[], size_t ndigits, unsigned char *c, size_t nbytes)
 Converts big digit a into string of octets, in big-endian order, padding to nbytes or truncating if necessary. More...
 
int mpCubeRoot (DIGIT_T s[], const DIGIT_T x[], size_t ndigits)
 Computes integer cube root s = floor(cuberoot(x)) More...
 
int mpDivide (DIGIT_T q[], DIGIT_T r[], const DIGIT_T u[], size_t udigits, DIGIT_T v[], size_t vdigits)
 Computes integer division of u by v such that u=qv+r. More...
 
int mpEqual (const DIGIT_T a[], const DIGIT_T b[], size_t ndigits)
 Returns true if a == b, else false. More...
 
int mpEqual_ct (const DIGIT_T a[], const DIGIT_T b[], size_t ndigits)
 Returns true if a == b, else false, using constant-time algorithm. More...
 
int mpGcd (DIGIT_T g[], const DIGIT_T x[], const DIGIT_T y[], size_t ndigits)
 Computes g = gcd(x, y), the greatest common divisor of x and y. More...
 
int mpGetBit (const DIGIT_T a[], size_t ndigits, size_t n)
 Returns value 1 or 0 of bit n (0..nbits-1) More...
 
int mpIsNegative (const DIGIT_T x[], size_t ndigits)
 Returns true (1) if x < 0, else false (0) More...
 
int mpIsPrime (DIGIT_T w[], size_t ndigits, size_t t)
 Returns true (1) if w is probably prime. More...
 
int mpIsZero (const DIGIT_T a[], size_t ndigits)
 Returns true if a is zero, else false. More...
 
int mpIsZero_ct (const DIGIT_T a[], size_t ndigits)
 Returns true if a is zero, else false, using constant-time algorithm. More...
 
int mpJacobi (const DIGIT_T a[], const DIGIT_T n[], size_t ndigits)
 Returns the Jacobi symbol (a/n) in {-1, 0, +1}. More...
 
void mpModAdd (DIGIT_T w[], const DIGIT_T u[], const DIGIT_T v[], const DIGIT_T m[], size_t ndigits)
 Computes w = u + v (mod m) More...
 
int mpModExp (DIGIT_T y[], const DIGIT_T x[], const DIGIT_T e[], DIGIT_T m[], size_t ndigits)
 Computes y = x^e mod m. More...
 
int mpModExp_ct (DIGIT_T yout[], const DIGIT_T x[], const DIGIT_T e[], DIGIT_T m[], size_t ndigits)
 Computes y = x^e mod m in constant time. More...
 
void mpModHalve (DIGIT_T w[], const DIGIT_T u[], const DIGIT_T p[], size_t ndigits)
 Computes w = u/2 (mod p) for an odd prime p. More...
 
int mpModInv (DIGIT_T inv[], const DIGIT_T u[], const DIGIT_T m[], size_t ndigits)
 Computes the inverse of u modulo m, inv = u^{-1} mod m. More...
 
int mpModMult (DIGIT_T a[], const DIGIT_T x[], const DIGIT_T y[], DIGIT_T m[], size_t ndigits)
 Computes a = (x * y) mod m. More...
 
void mpModPowerOf2 (DIGIT_T a[], size_t ndigits, size_t L)
 Computes a = a mod 2^L, ie clears all bits greater than L. More...
 
void mpModSpecial (DIGIT_T u[], const DIGIT_T v[], const DIGIT_T m[], size_t ndigits)
 Computes u = v (mod m) in the special case where 0<=v<km for small k. More...
 
int mpModSqrt (DIGIT_T x[], const DIGIT_T a[], DIGIT_T p[], size_t ndigits)
 Computes x = one square root of an integer a modulo an odd prime p More...
 
int mpModSquare (DIGIT_T a[], const DIGIT_T x[], DIGIT_T m[], size_t ndigits)
 Computes a = x^2 mod m. More...
 
void mpModSub (DIGIT_T w[], const DIGIT_T u[], const DIGIT_T v[], const DIGIT_T m[], size_t ndigits)
 Computes w = u - v (mod m) More...
 
int mpModulo (DIGIT_T r[], const DIGIT_T u[], size_t udigits, DIGIT_T v[], size_t vdigits)
 Computes remainder r = u mod v. More...
 
int mpMultiply (DIGIT_T w[], const DIGIT_T u[], const DIGIT_T v[], size_t ndigits)
 Computes product w = u * v. More...
 
void mpNotBits (DIGIT_T a[], const DIGIT_T b[], size_t ndigits)
 Computes bitwise a = NOT b. More...
 
void mpOrBits (DIGIT_T a[], const DIGIT_T b[], const DIGIT_T c[], size_t ndigits)
 Computes bitwise a = b OR c. More...
 
void mpPrint (const DIGIT_T *a, size_t ndigits)
 Print all digits in hex incl leading zero digits. More...
 
void mpPrintBits (const char *prefix, DIGIT_T *a, size_t ndigits, const char *suffix)
 Print in bit (0/1) format with optional prefix and suffix strings. More...
 
void mpPrintDecimal (const char *prefix, const DIGIT_T *a, size_t ndigits, const char *suffix)
 Print in decimal format with optional prefix and suffix strings. More...
 
void mpPrintDecimalSigned (const char *prefix, DIGIT_T *a, size_t ndigits, const char *suffix)
 Print a signed integer in decimal format with optional prefix and suffix strings. More...
 
void mpPrintHex (const char *prefix, const DIGIT_T *a, size_t ndigits, const char *suffix)
 Print in hex format with optional prefix and suffix strings. More...
 
void mpPrintNL (const DIGIT_T *a, size_t ndigits)
 Print all digits in hex with newlines. More...
 
void mpPrintTrim (const DIGIT_T *a, size_t ndigits)
 Print in hex but trim leading zero digits. More...
 
void mpPrintTrimNL (const DIGIT_T *a, size_t ndigits)
 Print in hex, trim leading zeroes, add newlines. More...
 
size_t mpQuickRandBits (DIGIT_T a[], size_t ndigits, size_t nbits)
 Generate a quick-and-dirty random mp number a of bit length at most nbits using plain-old-rand. More...
 
int mpRabinMiller (DIGIT_T w[], size_t ndigits, size_t t)
 Returns true (1) if w is probably prime using just the Rabin-Miller test. More...
 
int mpSetBit (DIGIT_T a[], size_t ndigits, size_t n, int value)
 Sets bit n of a (0..nbits-1) with value 1 or 0. More...
 
void mpSetDigit (DIGIT_T a[], DIGIT_T d, size_t ndigits)
 Sets a = d where d is a single digit. More...
 
void mpSetEqual (DIGIT_T a[], const DIGIT_T b[], size_t ndigits)
 Sets a = b. More...
 
volatile DIGIT_T mpSetZero (volatile DIGIT_T a[], size_t ndigits)
 Sets a = 0. More...
 
DIGIT_T mpShiftLeft (DIGIT_T a[], const DIGIT_T b[], size_t x, size_t ndigits)
 Computes a = b << x. More...
 
DIGIT_T mpShiftRight (DIGIT_T a[], const DIGIT_T b[], size_t x, size_t ndigits)
 Computes a = b >> x. More...
 
DIGIT_T mpShortAdd (DIGIT_T w[], const DIGIT_T u[], DIGIT_T d, size_t ndigits)
 Computes w = u + d, returns carry. More...
 
int mpShortCmp (const DIGIT_T a[], DIGIT_T d, size_t ndigits)
 Returns sign of (a - d) where d is a single digit. More...
 
DIGIT_T mpShortDiv (DIGIT_T q[], const DIGIT_T u[], DIGIT_T d, size_t ndigits)
 Computes quotient q = u div d, returns remainder. More...
 
int mpShortIsEqual (const DIGIT_T a[], DIGIT_T d, size_t ndigits)
 Returns true if a == d, else false, where d is a single digit. More...
 
DIGIT_T mpShortMod (const DIGIT_T a[], DIGIT_T d, size_t ndigits)
 Computes remainder r = a mod d. More...
 
DIGIT_T mpShortMult (DIGIT_T p[], const DIGIT_T x[], DIGIT_T d, size_t ndigits)
 Computes product p = x * d. More...
 
DIGIT_T mpShortSub (DIGIT_T w[], const DIGIT_T u[], DIGIT_T d, size_t ndigits)
 Computes w = u - d, returns borrow. More...
 
size_t mpSizeof (const DIGIT_T a[], size_t ndigits)
 Returns number of significant non-zero digits in a. More...
 
int mpSqrt (DIGIT_T s[], const DIGIT_T x[], size_t ndigits)
 Computes integer square root s = floor(sqrt(x)) More...
 
int mpSquare (DIGIT_T w[], const DIGIT_T x[], size_t ndigits)
 Computes square w = x^2. More...
 
DIGIT_T mpSubtract (DIGIT_T w[], const DIGIT_T u[], const DIGIT_T v[], size_t ndigits)
 Computes w = u - v, returns borrow. More...
 
DIGIT_T mpToShort (const DIGIT_T a[], size_t ndigits)
 Returns the least significant digit in a. More...
 
int mpVersion (void)
 Returns version number = major*1000+minor*100+release*10+PP_OPTIONS. More...
 
void mpXorBits (DIGIT_T a[], const DIGIT_T b[], const DIGIT_T c[], size_t ndigits)
 Computes bitwise a = b XOR c. More...
 
DIGIT_T spDivide (DIGIT_T *q, DIGIT_T *r, const DIGIT_T u[2], DIGIT_T v)
 Computes quotient q = u div v, remainder r = u mod v, where q, r and v are single digits. More...
 
int spMultiply (DIGIT_T p[2], DIGIT_T x, DIGIT_T y)
 Computes p = x * y, where x and y are single digits. More...
 
DIGIT_T spSimpleRand (DIGIT_T lower, DIGIT_T upper)
 Returns a simple pseudo-random digit between lower and upper. More...
 

Detailed Description

Interface to core BigDigits "mp" functions using fixed-length arrays.

Typedef Documentation

typedef uint32_t DIGIT_T

The basic BigDigit element, an unsigned 32-bit integer.

Function Documentation

int mpAbs ( DIGIT_T  x[],
const DIGIT_T  y[],
size_t  ndigits 
)

Sets x = |y|, the absolute value of y.

Remarks
Expects a negative number to be stored in two's-complement representation.
DIGIT_T mpAdd ( DIGIT_T  w[],
const DIGIT_T  u[],
const DIGIT_T  v[],
size_t  ndigits 
)

Computes w = u + v, returns carry.

Precondition
w and v must not overlap.
void mpAndBits ( DIGIT_T  a[],
const DIGIT_T  b[],
const DIGIT_T  c[],
size_t  ndigits 
)

Computes bitwise a = b AND c.

size_t mpBitLength ( const DIGIT_T  a[],
size_t  ndigits 
)

Returns number of significant bits in a.

int mpChs ( DIGIT_T  x[],
const DIGIT_T  y[],
size_t  ndigits 
)

Sets x = -y.

Remarks
Expects a negative number to be stored in two's-complement representation.
int mpCompare ( const DIGIT_T  a[],
const DIGIT_T  b[],
size_t  ndigits 
)

Returns sign of (a-b) as {-1,0,+1}

Remarks
Not constant-time.
int mpCompare_ct ( const DIGIT_T  a[],
const DIGIT_T  b[],
size_t  ndigits 
)

Returns sign of (a-b) as {-1,0,+1} using constant-time algorithm.

const char* mpCompileTime ( void  )

Returns a pointer to a static string containing the time of compilation.

size_t mpConvFromDecimal ( DIGIT_T  a[],
size_t  ndigits,
const char *  s 
)

Converts a string in decimal format to a big digit.

Returns
actual number of (possibly zero) digits set.
size_t mpConvFromHex ( DIGIT_T  a[],
size_t  ndigits,
const char *  s 
)

Converts a string in hexadecimal format to a big digit.

Returns
actual number of (possibly zero) digits set.
size_t mpConvFromOctets ( DIGIT_T  a[],
size_t  ndigits,
const unsigned char *  c,
size_t  nbytes 
)

Converts nbytes octets into big digit a of max size ndigits.

Returns
actual number of digits set
size_t mpConvToDecimal ( const DIGIT_T  a[],
size_t  ndigits,
char *  s,
size_t  smax 
)

Converts big digit a into a string in decimal format, where s has size smax including the terminating zero.

Returns
number of chars required excluding leading zeroes.
size_t mpConvToHex ( const DIGIT_T  a[],
size_t  ndigits,
char *  s,
size_t  smax 
)

Converts big digit a into a string in hexadecimal format, where s has size smax including the terminating zero.

Returns
number of chars required excluding leading zeroes.
size_t mpConvToOctets ( const DIGIT_T  a[],
size_t  ndigits,
unsigned char *  c,
size_t  nbytes 
)

Converts big digit a into string of octets, in big-endian order, padding to nbytes or truncating if necessary.

Returns
number of non-zero octets required.
int mpCubeRoot ( DIGIT_T  s[],
const DIGIT_T  x[],
size_t  ndigits 
)

Computes integer cube root s = floor(cuberoot(x))

int mpDivide ( DIGIT_T  q[],
DIGIT_T  r[],
const DIGIT_T  u[],
size_t  udigits,
DIGIT_T  v[],
size_t  vdigits 
)

Computes integer division of u by v such that u=qv+r.

Parameters
[out]qto receive quotient = u div v, an array of size udigits
[out]rto receive divisor = u mod v, an array of size udigits
[in]udividend of size udigits
[in]udigitssize of arrays q r and u
[in]vdivisor of size vdigits
[in]vdigitssize of array v
Precondition
q and r must be independent of u and v.
Warning
Trashes q and r first
int mpEqual ( const DIGIT_T  a[],
const DIGIT_T  b[],
size_t  ndigits 
)

Returns true if a == b, else false.

Remarks
Not constant-time.
int mpEqual_ct ( const DIGIT_T  a[],
const DIGIT_T  b[],
size_t  ndigits 
)

Returns true if a == b, else false, using constant-time algorithm.

int mpGcd ( DIGIT_T  g[],
const DIGIT_T  x[],
const DIGIT_T  y[],
size_t  ndigits 
)

Computes g = gcd(x, y), the greatest common divisor of x and y.

int mpGetBit ( const DIGIT_T  a[],
size_t  ndigits,
size_t  n 
)

Returns value 1 or 0 of bit n (0..nbits-1)

int mpIsNegative ( const DIGIT_T  x[],
size_t  ndigits 
)

Returns true (1) if x < 0, else false (0)

Remarks
Expects a negative number to be stored in two's-complement representation.
int mpIsPrime ( DIGIT_T  w[],
size_t  ndigits,
size_t  t 
)

Returns true (1) if w is probably prime.

Parameters
[in]wNumber to test
[in]ndigitssize of array w
[in]tThe count of Rabin-Miller primality tests to carry out (recommended at least 80)
Returns
true (1) if w is probably prime otherwise false (0)
Remarks
Uses FIPS-186-2/Rabin-Miller with trial division by small primes, which is faster in most cases than mpRabinMiller().
See Also
mpRabinMiller().
int mpIsZero ( const DIGIT_T  a[],
size_t  ndigits 
)

Returns true if a is zero, else false.

Remarks
Not constant-time.
int mpIsZero_ct ( const DIGIT_T  a[],
size_t  ndigits 
)

Returns true if a is zero, else false, using constant-time algorithm.

int mpJacobi ( const DIGIT_T  a[],
const DIGIT_T  n[],
size_t  ndigits 
)

Returns the Jacobi symbol (a/n) in {-1, 0, +1}.

Remarks
If n is prime then the Jacobi symbol becomes the Legendre symbol (a/p) defined to be
  • (a/p) = +1 if a is a quadratic residue modulo p
  • (a/p) = -1 if a is a quadratic non-residue modulo p
  • (a/p) = 0 if a is divisible by p
void mpModAdd ( DIGIT_T  w[],
const DIGIT_T  u[],
const DIGIT_T  v[],
const DIGIT_T  m[],
size_t  ndigits 
)

Computes w = u + v (mod m)

Precondition
Require u and v to be in the range [0, m-1]. The variables w and v must not overlap.
Remarks
Quicker than adding then using mpModulo()
int mpModExp ( DIGIT_T  y[],
const DIGIT_T  x[],
const DIGIT_T  e[],
DIGIT_T  m[],
size_t  ndigits 
)

Computes y = x^e mod m.

int mpModExp_ct ( DIGIT_T  yout[],
const DIGIT_T  x[],
const DIGIT_T  e[],
DIGIT_T  m[],
size_t  ndigits 
)

Computes y = x^e mod m in constant time.

Remarks
Resistant to simple power analysis attack on private exponent. Slower than mpModExp().
void mpModHalve ( DIGIT_T  w[],
const DIGIT_T  u[],
const DIGIT_T  p[],
size_t  ndigits 
)

Computes w = u/2 (mod p) for an odd prime p.

Precondition
Require u to be in the range [0,p-1]
int mpModInv ( DIGIT_T  inv[],
const DIGIT_T  u[],
const DIGIT_T  m[],
size_t  ndigits 
)

Computes the inverse of u modulo m, inv = u^{-1} mod m.

int mpModMult ( DIGIT_T  a[],
const DIGIT_T  x[],
const DIGIT_T  y[],
DIGIT_T  m[],
size_t  ndigits 
)

Computes a = (x * y) mod m.

void mpModPowerOf2 ( DIGIT_T  a[],
size_t  ndigits,
size_t  L 
)

Computes a = a mod 2^L, ie clears all bits greater than L.

void mpModSpecial ( DIGIT_T  u[],
const DIGIT_T  v[],
const DIGIT_T  m[],
size_t  ndigits 
)

Computes u = v (mod m) in the special case where 0<=v<km for small k.

Remarks
Uses subtraction instead of division, so is much faster than mpModulo() in this case.
Precondition
v is in the range [0,km] where k is a small integer
Warning
Use only if you know k is small, say < 3.
int mpModSqrt ( DIGIT_T  x[],
const DIGIT_T  a[],
DIGIT_T  p[],
size_t  ndigits 
)

Computes x = one square root of an integer a modulo an odd prime p

Parameters
xTo receive the result
aAn integer expected to be a quadratic residue modulo p
pAn odd prime
ndigitsThe number of digits in each of the parameters
Returns
0 if successful, or -1 if square root does not exist
Remarks
More precisely, find an integer x such that x^2 mod p = a. Uses the Tonelli-Shanks algorithm. The other square root is p - x.
Warning
Check the return value before using the result x.
int mpModSquare ( DIGIT_T  a[],
const DIGIT_T  x[],
DIGIT_T  m[],
size_t  ndigits 
)

Computes a = x^2 mod m.

void mpModSub ( DIGIT_T  w[],
const DIGIT_T  u[],
const DIGIT_T  v[],
const DIGIT_T  m[],
size_t  ndigits 
)

Computes w = u - v (mod m)

Precondition
Require u and v to be in the range [0, m-1]. The variables w and v must not overlap.
Remarks
Quicker than subtracting then using mpModulo()
int mpModulo ( DIGIT_T  r[],
const DIGIT_T  u[],
size_t  udigits,
DIGIT_T  v[],
size_t  vdigits 
)

Computes remainder r = u mod v.

Parameters
[out]rto receive divisor = u mod v, an array of size vdigits
[in]udividend of size udigits
[in]udigitssize of arrays r and u
[in]vdivisor of size vdigits
[in]vdigitssize of array v
Precondition
r and u must not overlap.
Remarks
Note that r is vdigits long here, but is udigits long in mpDivide().
int mpMultiply ( DIGIT_T  w[],
const DIGIT_T  u[],
const DIGIT_T  v[],
size_t  ndigits 
)

Computes product w = u * v.

Parameters
[out]wTo receive the product, an array of size 2 x ndigits
[in]uAn array of size ndigits
[in]vAn array of size ndigits
[in]ndigitssize of arrays u and v
Precondition
w and u must not overlap.
Warning
The product must be of size 2 x ndigits
void mpNotBits ( DIGIT_T  a[],
const DIGIT_T  b[],
size_t  ndigits 
)

Computes bitwise a = NOT b.

void mpOrBits ( DIGIT_T  a[],
const DIGIT_T  b[],
const DIGIT_T  c[],
size_t  ndigits 
)

Computes bitwise a = b OR c.

void mpPrint ( const DIGIT_T a,
size_t  ndigits 
)

Print all digits in hex incl leading zero digits.

void mpPrintBits ( const char *  prefix,
DIGIT_T a,
size_t  ndigits,
const char *  suffix 
)

Print in bit (0/1) format with optional prefix and suffix strings.

void mpPrintDecimal ( const char *  prefix,
const DIGIT_T a,
size_t  ndigits,
const char *  suffix 
)

Print in decimal format with optional prefix and suffix strings.

void mpPrintDecimalSigned ( const char *  prefix,
DIGIT_T a,
size_t  ndigits,
const char *  suffix 
)

Print a signed integer in decimal format with optional prefix and suffix strings.

Remarks
Expects a negative number to be stored in two's-complement representation.
void mpPrintHex ( const char *  prefix,
const DIGIT_T a,
size_t  ndigits,
const char *  suffix 
)

Print in hex format with optional prefix and suffix strings.

void mpPrintNL ( const DIGIT_T a,
size_t  ndigits 
)

Print all digits in hex with newlines.

void mpPrintTrim ( const DIGIT_T a,
size_t  ndigits 
)

Print in hex but trim leading zero digits.

Deprecated:
Use mpPrintHex()
void mpPrintTrimNL ( const DIGIT_T a,
size_t  ndigits 
)

Print in hex, trim leading zeroes, add newlines.

Deprecated:
Use mpPrintHex()
size_t mpQuickRandBits ( DIGIT_T  a[],
size_t  ndigits,
size_t  nbits 
)

Generate a quick-and-dirty random mp number a of bit length at most nbits using plain-old-rand.

Remarks
Not crypto secure.
See Also
mpRandomBits()
int mpRabinMiller ( DIGIT_T  w[],
size_t  ndigits,
size_t  t 
)

Returns true (1) if w is probably prime using just the Rabin-Miller test.

See Also
mpIsPrime() is preferred.
int mpSetBit ( DIGIT_T  a[],
size_t  ndigits,
size_t  n,
int  value 
)

Sets bit n of a (0..nbits-1) with value 1 or 0.

void mpSetDigit ( DIGIT_T  a[],
DIGIT_T  d,
size_t  ndigits 
)

Sets a = d where d is a single digit.

void mpSetEqual ( DIGIT_T  a[],
const DIGIT_T  b[],
size_t  ndigits 
)

Sets a = b.

volatile DIGIT_T mpSetZero ( volatile DIGIT_T  a[],
size_t  ndigits 
)

Sets a = 0.

DIGIT_T mpShiftLeft ( DIGIT_T  a[],
const DIGIT_T  b[],
size_t  x,
size_t  ndigits 
)

Computes a = b << x.

DIGIT_T mpShiftRight ( DIGIT_T  a[],
const DIGIT_T  b[],
size_t  x,
size_t  ndigits 
)

Computes a = b >> x.

DIGIT_T mpShortAdd ( DIGIT_T  w[],
const DIGIT_T  u[],
DIGIT_T  d,
size_t  ndigits 
)

Computes w = u + d, returns carry.

int mpShortCmp ( const DIGIT_T  a[],
DIGIT_T  d,
size_t  ndigits 
)

Returns sign of (a - d) where d is a single digit.

DIGIT_T mpShortDiv ( DIGIT_T  q[],
const DIGIT_T  u[],
DIGIT_T  d,
size_t  ndigits 
)

Computes quotient q = u div d, returns remainder.

int mpShortIsEqual ( const DIGIT_T  a[],
DIGIT_T  d,
size_t  ndigits 
)

Returns true if a == d, else false, where d is a single digit.

DIGIT_T mpShortMod ( const DIGIT_T  a[],
DIGIT_T  d,
size_t  ndigits 
)

Computes remainder r = a mod d.

DIGIT_T mpShortMult ( DIGIT_T  p[],
const DIGIT_T  x[],
DIGIT_T  d,
size_t  ndigits 
)

Computes product p = x * d.

DIGIT_T mpShortSub ( DIGIT_T  w[],
const DIGIT_T  u[],
DIGIT_T  d,
size_t  ndigits 
)

Computes w = u - d, returns borrow.

size_t mpSizeof ( const DIGIT_T  a[],
size_t  ndigits 
)

Returns number of significant non-zero digits in a.

int mpSqrt ( DIGIT_T  s[],
const DIGIT_T  x[],
size_t  ndigits 
)

Computes integer square root s = floor(sqrt(x))

int mpSquare ( DIGIT_T  w[],
const DIGIT_T  x[],
size_t  ndigits 
)

Computes square w = x^2.

Parameters
[out]warray of size 2 x ndigits to receive square
[in]xarray of size ndigits
[in]ndigitssize of array x
Precondition
w and x must not overlap.
Warning
The product w must be of size 2 x ndigits
DIGIT_T mpSubtract ( DIGIT_T  w[],
const DIGIT_T  u[],
const DIGIT_T  v[],
size_t  ndigits 
)

Computes w = u - v, returns borrow.

Precondition
w and v must not overlap.
DIGIT_T mpToShort ( const DIGIT_T  a[],
size_t  ndigits 
)

Returns the least significant digit in a.

int mpVersion ( void  )

Returns version number = major*1000+minor*100+release*10+PP_OPTIONS.

void mpXorBits ( DIGIT_T  a[],
const DIGIT_T  b[],
const DIGIT_T  c[],
size_t  ndigits 
)

Computes bitwise a = b XOR c.

DIGIT_T spDivide ( DIGIT_T q,
DIGIT_T r,
const DIGIT_T  u[2],
DIGIT_T  v 
)

Computes quotient q = u div v, remainder r = u mod v, where q, r and v are single digits.

int spMultiply ( DIGIT_T  p[2],
DIGIT_T  x,
DIGIT_T  y 
)

Computes p = x * y, where x and y are single digits.

DIGIT_T spSimpleRand ( DIGIT_T  lower,
DIGIT_T  upper 
)

Returns a simple pseudo-random digit between lower and upper.

Remarks
Not crypto secure.
See Also
spBetterRand()
Copyright © 2001-16 D.I. Management Services Pty Limited ABN 78 083 210 584 Australia. All rights reserved. <www.di-mgt.com.au/bigdigits.html> Generated on Thu Mar 31 2016 10:28:02 by Doxygen 1.8.3.1.