BigDigits  2.7.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 mpConvFromStr (DIGIT_T a[], size_t ndigits, const char *s, char **endptr, int base)
 Converts a string of digits in the specified radix base to a big digit array. 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

◆ DIGIT_T

typedef uint32_t DIGIT_T

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

Function Documentation

◆ mpAbs()

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.

◆ mpAdd()

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.

◆ mpAndBits()

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

Computes bitwise a = b AND c.

◆ mpBitLength()

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

Returns number of significant bits in a.

◆ mpChs()

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.

◆ mpCompare()

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.

◆ mpCompare_ct()

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.

◆ mpCompileTime()

const char* mpCompileTime ( void  )

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

◆ mpConvFromDecimal()

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.

◆ mpConvFromHex()

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.

◆ mpConvFromOctets()

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

◆ mpConvFromStr()

size_t mpConvFromStr ( DIGIT_T  a[],
size_t  ndigits,
const char *  s,
char **  endptr,
int  base 
)

Converts a string of digits in the specified radix base to a big digit array.

Supported bases are 10 (decimal), 16 (hexadecimal), and 2 (binary). The conversion stops at the first invalid character or end of string. Sets endptr to point to the first character that could not be converted, similar to ANSI strtoul. If base is 0 then base 10 is assumed unless the prefix 0x or 0b is present, denoting base 16 or base 2 respectively.

◆ mpConvToDecimal()

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.

◆ mpConvToHex()

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.

◆ mpConvToOctets()

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.

◆ mpCubeRoot()

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

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

◆ mpDivide()

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

◆ mpEqual()

int mpEqual ( const DIGIT_T  a[],
const DIGIT_T  b[],
size_t  ndigits 
)

Returns true if a == b, else false.

Remarks
Not constant-time.

◆ mpEqual_ct()

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.

◆ mpGcd()

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.

◆ mpGetBit()

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

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

◆ mpIsNegative()

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.

◆ mpIsPrime()

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().

◆ mpIsZero()

int mpIsZero ( const DIGIT_T  a[],
size_t  ndigits 
)

Returns true if a is zero, else false.

Remarks
Not constant-time.

◆ mpIsZero_ct()

int mpIsZero_ct ( const DIGIT_T  a[],
size_t  ndigits 
)

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

◆ mpJacobi()

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

◆ mpModAdd()

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()

◆ mpModExp()

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.

◆ mpModExp_ct()

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().

◆ mpModHalve()

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]

◆ mpModInv()

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.

◆ mpModMult()

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.

◆ mpModPowerOf2()

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

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

◆ mpModSpecial()

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.

◆ mpModSqrt()

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.

◆ mpModSquare()

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

Computes a = x^2 mod m.

◆ mpModSub()

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()

◆ 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().

◆ mpMultiply()

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

◆ mpNotBits()

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

Computes bitwise a = NOT b.

◆ mpOrBits()

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

Computes bitwise a = b OR c.

◆ mpPrint()

void mpPrint ( const DIGIT_T a,
size_t  ndigits 
)

Print all digits in hex incl leading zero digits.

◆ mpPrintBits()

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.

◆ mpPrintDecimal()

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.

◆ mpPrintDecimalSigned()

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.

◆ mpPrintHex()

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.

◆ mpPrintNL()

void mpPrintNL ( const DIGIT_T a,
size_t  ndigits 
)

Print all digits in hex with newlines.

◆ mpPrintTrim()

void mpPrintTrim ( const DIGIT_T a,
size_t  ndigits 
)

Print in hex but trim leading zero digits.

Deprecated:
Use mpPrintHex()

◆ mpPrintTrimNL()

void mpPrintTrimNL ( const DIGIT_T a,
size_t  ndigits 
)

Print in hex, trim leading zeroes, add newlines.

Deprecated:
Use mpPrintHex()

◆ mpQuickRandBits()

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()

◆ mpRabinMiller()

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.

◆ mpSetBit()

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.

◆ mpSetDigit()

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

Sets a = d where d is a single digit.

◆ mpSetEqual()

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

Sets a = b.

◆ mpSetZero()

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

Sets a = 0.

◆ mpShiftLeft()

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

Computes a = b << x.

◆ mpShiftRight()

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

Computes a = b >> x.

◆ mpShortAdd()

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

Computes w = u + d, returns carry.

◆ mpShortCmp()

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

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

◆ mpShortDiv()

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

Computes quotient q = u div d, returns remainder.

◆ mpShortIsEqual()

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.

◆ mpShortMod()

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

Computes remainder r = a mod d.

◆ mpShortMult()

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

Computes product p = x * d.

◆ mpShortSub()

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

Computes w = u - d, returns borrow.

◆ mpSizeof()

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

Returns number of significant non-zero digits in a.

◆ mpSqrt()

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

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

◆ mpSquare()

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

◆ mpSubtract()

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.

◆ mpToShort()

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

Returns the least significant digit in a.

◆ mpVersion()

int mpVersion ( void  )

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

◆ mpXorBits()

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

Computes bitwise a = b XOR c.

◆ spDivide()

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.

◆ spMultiply()

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

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

◆ spSimpleRand()

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-26 D.I. Management Services Pty Limited ABN 78 083 210 584 Australia. All rights reserved. <https://di-mgt.com.au/bigdigits.html> Generated on Sat Apr 4 2026 19:52:36 by Doxygen 1.9.1.