BigDigits  2.6.1
Typedefs | Functions
bigd.h File Reference

Interface to the BigDigits "bd" functions using BIGD objects with automatic memory allocation. More...

Typedefs

typedef int(* BD_RANDFUNC )(unsigned char *buf, size_t nbytes, const unsigned char *seed, size_t seedlen)
 TYPEDEF for user-defined random byte generator function. More...
 
typedef uint32_t bdigit_t
 A synonym for a single digit (DIGIT_T is not exposed) More...
 

Functions

int bdAdd (BIGD w, BIGD u, BIGD v)
 Compute sum w = u + v. More...
 
int bdAdd_s (BIGD w, BIGD u, BIGD v)
 Compute w = u + v without restrictions on overlap of bdAdd() More...
 
void bdAndBits (BIGD a, BIGD b, BIGD c)
 Computes bitwise operation a = b AND c. More...
 
size_t bdBitLength (BIGD b)
 Returns number of significant bits in b. More...
 
int bdCompare (BIGD a, BIGD b)
 Returns sign of (a-b) in {0,1,-1} More...
 
int bdCompare_ct (BIGD a, BIGD b)
 Returns sign of (a-b) as {-1,0,+1} using constant-time algorithm. More...
 
const char * bdCompileTime (void)
 Returns a pointer to a static string containing the time of compilation. More...
 
size_t bdConvFromDecimal (BIGD b, const char *s)
 Convert string of decimal characters into a BIGD object. More...
 
size_t bdConvFromHex (BIGD b, const char *s)
 Convert string of hexadecimal characters into a BIGD object. More...
 
size_t bdConvFromOctets (BIGD b, const unsigned char *octets, size_t nbytes)
 Converts a byte array into a BIGD object. More...
 
size_t bdConvToDecimal (BIGD b, char *s, size_t smax)
 Convert BIGD object into a string of decimal characters. More...
 
size_t bdConvToHex (BIGD b, char *s, size_t smax)
 Convert BIGD object into a string of hexadecimal characters. More...
 
size_t bdConvToOctets (BIGD b, unsigned char *octets, size_t nbytes)
 Converts a BIGD into an array of bytes, in big-endian order. More...
 
int bdCubeRoot (BIGD s, BIGD x)
 Computes integer cube root s = floor(cuberoot(x)) More...
 
int bdDecrement (BIGD a)
 Sets a = a - 1. More...
 
int bdDivide (BIGD q, BIGD r, BIGD u, BIGD v)
 Compute integer division of u by v such that u=qv+r. More...
 
int bdDivide_s (BIGD q, BIGD r, BIGD u, BIGD v)
 Compute u div v without restrictions on overlap of bdDivide() More...
 
void bdFree (BIGD *bd)
 Destroy BIGD object: zeroise contents and free allocated memory. More...
 
void bdFreeVars (BIGD *pb1,...)
 Destroy a set of BIGD objects. More...
 
int bdGcd (BIGD g, BIGD x, BIGD y)
 Computes g = gcd(x, y), the greatest common divisor of x and y. More...
 
int bdGeneratePrime (BIGD a, size_t nbits, size_t ntests, const unsigned char *seed, size_t seedlen, BD_RANDFUNC RandFunc)
 Generate a prime number. More...
 
int bdGetBit (BIGD a, size_t ibit)
 Returns value 1 or 0 of bit n of a (0..nbits-1) More...
 
int bdIncrement (BIGD a)
 Sets a = a + 1. More...
 
int bdIsEqual (BIGD a, BIGD b)
 Returns true (1) if a == b, else false (0) More...
 
int bdIsEqual_ct (BIGD a, BIGD b)
 Returns true if a == b, else false, using constant-time algorithm. More...
 
int bdIsEven (BIGD a)
 Returns true (1) if a is even, else false (0) More...
 
int bdIsOdd (BIGD a)
 Returns true (1) if a is odd, else false (0) More...
 
int bdIsPrime (BIGD b, size_t ntests)
 Returns true (1) if b is probably prime. More...
 
int bdIsZero (BIGD a)
 Returns true (1) if a is zero, else false (0) More...
 
int bdIsZero_ct (BIGD a)
 Returns true if a is zero, else false, using constant-time algorithm. More...
 
int bdJacobi (BIGD a, BIGD n)
 Returns the Jacobi symbol (a/n) = {-1, 0, +1}. More...
 
void bdModAdd (BIGD w, BIGD u, BIGD v, BIGD m)
 Computes w = u + v (mod m) More...
 
int bdModExp (BIGD y, BIGD x, BIGD e, BIGD m)
 Computes y = x^e mod m. More...
 
int bdModExp_ct (BIGD y, BIGD x, BIGD e, BIGD m)
 Computes y = x^e mod m in constant time. More...
 
void bdModHalve (BIGD w, const BIGD u, const BIGD p)
 Computes w = u/2 (mod p) for an odd prime p. More...
 
int bdModInv (BIGD x, BIGD a, BIGD m)
 Computes the inverse of a modulo m, x = a^{-1} mod m More...
 
int bdModMult (BIGD a, BIGD x, BIGD y, BIGD m)
 Computes a = (x * y) mod m. More...
 
void bdModPowerOf2 (BIGD a, size_t L)
 Computes a = a mod 2^L, ie clears all bits greater than L. More...
 
int bdModSqrt (BIGD x, BIGD a, BIGD p)
 Computes x = one square root of an integer a modulo an odd prime p More...
 
int bdModSquare (BIGD a, BIGD x, BIGD m)
 Computes a = x^2 mod m. More...
 
void bdModSub (BIGD w, BIGD u, BIGD v, BIGD m)
 Computes w = u - v (mod m) More...
 
int bdModulo (BIGD r, BIGD u, BIGD v)
 Compute remainder r = u mod v. More...
 
int bdModulo_s (BIGD r, BIGD u, BIGD v)
 Compute u mod v without restrictions on overlap of bdModulo() More...
 
int bdMultiply (BIGD w, BIGD u, BIGD v)
 Compute product w = u * v. More...
 
int bdMultiply_s (BIGD w, BIGD u, BIGD v)
 Compute w = u * v without restrictions on overlap of bdMultiply() More...
 
BIGD bdNew (void)
 Create new BIGD object. More...
 
void bdNewVars (BIGD *pb1,...)
 Create a set of BIGD objects. More...
 
void bdNotBits (BIGD a, BIGD b)
 Computes bitwise a = NOT b. More...
 
void bdOrBits (BIGD a, BIGD b, BIGD c)
 Computes bitwise operation a = b OR c. More...
 
int bdPower (BIGD y, BIGD g, unsigned short int n)
 Computes y = g^n (up to available memory!) More...
 
void bdPrint (BIGD b, size_t flags)
 Print b in hex format to stdout. More...
 
void bdPrintBits (const char *prefix, BIGD b, const char *suffix)
 Print b in bit (0/1) format with optional prefix and suffix strings. More...
 
void bdPrintDecimal (const char *prefix, BIGD b, const char *suffix)
 Print b in decimal format with optional prefix and suffix strings. More...
 
void bdPrintHex (const char *prefix, BIGD b, const char *suffix)
 Print b in hex format with optional prefix and suffix strings. More...
 
size_t bdQuickRandBits (BIGD a, size_t nbits)
 Generate a quick-and-dirty random number a of bit length at most nbits using plain-old-rand. More...
 
int bdRabinMiller (BIGD b, size_t ntests)
 Returns true (1) if b is probably prime using just the Rabin-Miller test. More...
 
int bdRandomSeeded (BIGD a, size_t nbits, const unsigned char *seed, size_t seedlen, BD_RANDFUNC RandFunc)
 Generate a random number nbits long using RandFunc. More...
 
int bdSetBit (BIGD a, size_t n, int value)
 Set bit n of a (0..nbits-1) with value 1 or 0. More...
 
int bdSetEqual (BIGD a, BIGD b)
 Sets a = b. More...
 
size_t bdSetRandTest (BIGD a, size_t ndigits)
 Set a with a "random" value of random length up to ndigits long suitable for quick tests. More...
 
int bdSetShort (BIGD b, bdigit_t d)
 Converts a single digit into a BIGD. More...
 
int bdSetZero (BIGD a)
 Sets a = 0. More...
 
void bdShiftLeft (BIGD a, BIGD b, size_t n)
 Computes a = b << n. More...
 
void bdShiftRight (BIGD a, BIGD b, size_t n)
 Computes a = b >> n. More...
 
int bdShortAdd (BIGD w, BIGD u, bdigit_t d)
 Computes w = u + d where d is a single digit. More...
 
int bdShortCmp (BIGD a, bdigit_t d)
 Returns sign of (a-d) where d is a single digit. More...
 
int bdShortDiv (BIGD q, BIGD r, BIGD u, bdigit_t d)
 Computes integer division of u by single digit d. More...
 
int bdShortIsEqual (BIGD a, bdigit_t d)
 Returns true if a == d, else false, where d is a single digit. More...
 
bdigit_t bdShortMod (BIGD r, BIGD u, bdigit_t d)
 Computes r = u mod d where d is a single digit. More...
 
int bdShortMult (BIGD w, BIGD u, bdigit_t d)
 Computes w = u * d where d is a single digit. More...
 
int bdShortSub (BIGD w, BIGD u, bdigit_t d)
 Computes w = u - d where d is a single digit. More...
 
size_t bdSizeof (BIGD b)
 Returns number of significant digits in b. More...
 
int bdSqrt (BIGD s, BIGD x)
 Computes integer square root s = floor(sqrt(x)) More...
 
int bdSquare (BIGD w, BIGD x)
 Compute square w = x^2. More...
 
int bdSquare_s (BIGD s, BIGD x)
 Compute s = x * x without restrictions on overlap of bdSquare() More...
 
int bdSubtract (BIGD w, BIGD u, BIGD v)
 Compute difference w = u - v. More...
 
int bdSubtract_s (BIGD w, BIGD u, BIGD v)
 Compute w = u - v without restrictions on overlap of bdSubtract() More...
 
bdigit_t bdToShort (BIGD b)
 Returns the least significant digit in b. More...
 
int bdVersion (void)
 Returns version number = major*1000+minor*100+release*10+PP_OPTIONS. More...
 
void bdXorBits (BIGD a, BIGD b, BIGD c)
 Computes bitwise operation a = b XOR c. More...
 

Detailed Description

Interface to the BigDigits "bd" functions using BIGD objects with automatic memory allocation.

PROGRAMMER'S NOTES
Where the function computes a new BIGD value, the result is returned in the first argument. Some functions do not allow variables to overlap. Functions of type int generally return 0 to denote success but some return True/False (1/0) or borrow (+1) or error (-1). Functions of type size_t (an unsigned int) return a length.
Memory allocation
Memory for each variable is allocated as required and is increased automatically if needed. However, memory for a variable is only released when freed with bdFree(). The standard code for a variable b should be as follows:
BIGD b;
b = bdNew();
// operations using b...
bdFree(&b);

Typedef Documentation

typedef int(* BD_RANDFUNC)(unsigned char *buf, size_t nbytes, const unsigned char *seed, size_t seedlen)

TYPEDEF for user-defined random byte generator function.

typedef uint32_t bdigit_t

A synonym for a single digit (DIGIT_T is not exposed)

Function Documentation

int bdAdd ( BIGD  w,
BIGD  u,
BIGD  v 
)

Compute sum w = u + v.

Returns
carry
Remarks
w and v must be separate variables. Use bdAdd_s() to avoid overlap restriction.
int bdAdd_s ( BIGD  w,
BIGD  u,
BIGD  v 
)

Compute w = u + v without restrictions on overlap of bdAdd()

void bdAndBits ( BIGD  a,
BIGD  b,
BIGD  c 
)

Computes bitwise operation a = b AND c.

size_t bdBitLength ( BIGD  b)

Returns number of significant bits in b.

int bdCompare ( BIGD  a,
BIGD  b 
)

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

Remarks
Not constant-time
int bdCompare_ct ( BIGD  a,
BIGD  b 
)

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

const char* bdCompileTime ( void  )

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

size_t bdConvFromDecimal ( BIGD  b,
const char *  s 
)

Convert string of decimal characters into a BIGD object.

Parameters
[out]bTo receive the result
[in]sNull-terminated string of decimal digits [0-9]
Returns
Number of significant digits actually set, which could be 0.
size_t bdConvFromHex ( BIGD  b,
const char *  s 
)

Convert string of hexadecimal characters into a BIGD object.

Parameters
[out]bTo receive the result
[in]sNull-terminated string of hex digits [0-9A-Fa-f]
Returns
Number of significant digits actually set, which could be 0.
size_t bdConvFromOctets ( BIGD  b,
const unsigned char *  octets,
size_t  nbytes 
)

Converts a byte array into a BIGD object.

Parameters
[out]bTo receive the result
[in]octetsPointer to array of bytes (octets)
[in]nbytesNumber of bytes in sequence
Returns
Number of digits actually set, which may be larger than bdSizeof(BIGD b).
size_t bdConvToDecimal ( BIGD  b,
char *  s,
size_t  smax 
)

Convert BIGD object into a string of decimal characters.

Parameters
[in]bBIGD object to be converted
[out]sString buffer to receive output
[in]smaxSize of buffer including the terminating zero
Returns
Exact number of characters required excluding the terminating zero. If s is NULL or smax is zero then just returns required number.
char *s;
size_t nchars = bdConvToDecimal(b, NULL, 0);
s = malloc(nchars+1); // NB add one extra
nchars = bdConvToDecimal(b, s, nchars+1);
Remarks
Always returns the length of the string it tried to create, even if the actual output was truncated, so remember to check.
size_t bdConvToHex ( BIGD  b,
char *  s,
size_t  smax 
)

Convert BIGD object into a string of hexadecimal characters.

Parameters
[in]bBIGD object to be converted
[out]sString buffer to receive output
[in]smaxSize of buffer including the terminating zero
Returns
Exact number of characters required excluding the terminating zero. If s is NULL or smax is zero then just returns required number.
char *s;
size_t nchars = bdConvToHex(b, NULL, 0);
s = malloc(nchars+1); // NB add one extra
nchars = bdConvToHex(b, s, nchars+1);
Remarks
Always returns the length of the string it tried to create, even if the actual output was truncated, so remember to check.
size_t bdConvToOctets ( BIGD  b,
unsigned char *  octets,
size_t  nbytes 
)

Converts a BIGD into an array of bytes, in big-endian order.

Parameters
[in]bBIGD object to be converted
[out]octetsArray of bytes (octets) to receive output
[in]nbytesLength of array to receive output
Returns
Exact number of significant bytes in the result. If octets is NULL or nbytes is zero then just returns required size (nsig).
Remarks
Will pad on the left with zeros if nbytes is larger than required, or will truncate from the left if it is too short.
  • if nbytes = nsig, octets <– mmmnnn;
  • if nbytes > nsig, octets <– 000mmmnnn;
  • if nbytes < nsig, octets <– nnn.
int bdCubeRoot ( BIGD  s,
BIGD  x 
)

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

int bdDecrement ( BIGD  a)

Sets a = a - 1.

Returns
borrow
Warning
Behaviour is undefined if a becomes negative.
int bdDivide ( BIGD  q,
BIGD  r,
BIGD  u,
BIGD  v 
)

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

Parameters
[out]qTo receive quotient = u div v
[out]rTo receive remainder = u mod v
[in]uDividend
[in]vDivisor
Remarks
Trashes q and r first: q and r must be independent of u and v. Use bdDivide_s() to avoid overlap restriction.
int bdDivide_s ( BIGD  q,
BIGD  r,
BIGD  u,
BIGD  v 
)

Compute u div v without restrictions on overlap of bdDivide()

void bdFree ( BIGD *  bd)

Destroy BIGD object: zeroise contents and free allocated memory.

Remarks
Pass a pointer to the handle
void bdFreeVars ( BIGD *  pb1,
  ... 
)

Destroy a set of BIGD objects.

BIGD a, b, c;
bdNewVars(&a, &b, &c, NULL);
// do stuff with variables a, b, c...
bdFreeVars(&a, &b, &c, NULL);

The bdFreeVars function call above is equivalent to

bdFree(&a);
bdFree(&b);
bdFree(&c);
Warning
The list must finish with NULL
int bdGcd ( BIGD  g,
BIGD  x,
BIGD  y 
)

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

int bdGeneratePrime ( BIGD  a,
size_t  nbits,
size_t  ntests,
const unsigned char *  seed,
size_t  seedlen,
BD_RANDFUNC  RandFunc 
)

Generate a prime number.

Parameters
[out]aTo receive the result
[in]nbitsMaximum number of bits in number
[in]ntestsNumber of primality tests to carry out (recommended at least 80)
[in]seedOptional seed to add extra entropy
[in]seedlenNumber of bytes in seed
[in]RandFuncUser function to generate random bytes
int bdGetBit ( BIGD  a,
size_t  ibit 
)

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

int bdIncrement ( BIGD  a)

Sets a = a + 1.

Returns
carry
int bdIsEqual ( BIGD  a,
BIGD  b 
)

Returns true (1) if a == b, else false (0)

Remarks
Not constant-time
int bdIsEqual_ct ( BIGD  a,
BIGD  b 
)

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

int bdIsEven ( BIGD  a)

Returns true (1) if a is even, else false (0)

int bdIsOdd ( BIGD  a)

Returns true (1) if a is odd, else false (0)

int bdIsPrime ( BIGD  b,
size_t  ntests 
)

Returns true (1) if b is probably prime.

Parameters
[in]bNumber to test
[in]ntestsThe count of Rabin-Miller primality tests to carry out (recommended at least 80)
Returns
true (1) if b 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 bdRabinMiller().
See Also
bdRabinMiller().
int bdIsZero ( BIGD  a)

Returns true (1) if a is zero, else false (0)

Remarks
Not constant-time
int bdIsZero_ct ( BIGD  a)

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

int bdJacobi ( BIGD  a,
BIGD  n 
)

Returns the Jacobi symbol (a/n) = {-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 bdModAdd ( BIGD  w,
BIGD  u,
BIGD  v,
BIGD  m 
)

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 bdModExp ( BIGD  y,
BIGD  x,
BIGD  e,
BIGD  m 
)

Computes y = x^e mod m.

int bdModExp_ct ( BIGD  y,
BIGD  x,
BIGD  e,
BIGD  m 
)

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

Remarks
Resistant to simple power analysis attack on private exponent. Slower than bdModExp().
void bdModHalve ( BIGD  w,
const BIGD  u,
const BIGD  p 
)

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

Precondition
Require u to be in the range [0,p-1]
int bdModInv ( BIGD  x,
BIGD  a,
BIGD  m 
)

Computes the inverse of a modulo m, x = a^{-1} mod m

int bdModMult ( BIGD  a,
BIGD  x,
BIGD  y,
BIGD  m 
)

Computes a = (x * y) mod m.

void bdModPowerOf2 ( BIGD  a,
size_t  L 
)

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

int bdModSqrt ( BIGD  x,
BIGD  a,
BIGD  p 
)

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
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 bdModSquare ( BIGD  a,
BIGD  x,
BIGD  m 
)

Computes a = x^2 mod m.

void bdModSub ( BIGD  w,
BIGD  u,
BIGD  v,
BIGD  m 
)

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 bdModulo ( BIGD  r,
BIGD  u,
BIGD  v 
)

Compute remainder r = u mod v.

Remarks
r and u must be separate variables. Use bdModulo_s() to avoid overlap restriction.
int bdModulo_s ( BIGD  r,
BIGD  u,
BIGD  v 
)

Compute u mod v without restrictions on overlap of bdModulo()

int bdMultiply ( BIGD  w,
BIGD  u,
BIGD  v 
)

Compute product w = u * v.

Remarks
w and u must be separate variables. Use bdMultiply_s() to avoid overlap restriction.
int bdMultiply_s ( BIGD  w,
BIGD  u,
BIGD  v 
)

Compute w = u * v without restrictions on overlap of bdMultiply()

BIGD bdNew ( void  )

Create new BIGD object.

Returns
Handle to new object
void bdNewVars ( BIGD *  pb1,
  ... 
)

Create a set of BIGD objects.

BIGD a, b, c;
bdNewVars(&a, &b, &c, NULL);
// do stuff with variables a, b, c...
bdFreeVars(&a, &b, &c, NULL);

The bdNewVars function call above is equivalent to

a = bdNew();
b = bdNew();
c = bdNew();
Warning
The list must finish with NULL
void bdNotBits ( BIGD  a,
BIGD  b 
)

Computes bitwise a = NOT b.

Remarks
This flips all the bits up to the most significant digit, which may not be exactly what you want.
void bdOrBits ( BIGD  a,
BIGD  b,
BIGD  c 
)

Computes bitwise operation a = b OR c.

int bdPower ( BIGD  y,
BIGD  g,
unsigned short int  n 
)

Computes y = g^n (up to available memory!)

Remarks
Be very careful that n is not too large
void bdPrint ( BIGD  b,
size_t  flags 
)

Print b in hex format to stdout.

Parameters
[in]bNumber to print
[in]flags(see below)
Remarks
Flags are
  • 0 default display leading zeros but no newline
  • BD_PRINT_NL 0x1 append a newline after printing
  • BD_PRINT_TRIM 0x2 trim leading zero digits
Deprecated:
Use bdPrintHex() or bdPrintDecimal().
void bdPrintBits ( const char *  prefix,
BIGD  b,
const char *  suffix 
)

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

void bdPrintDecimal ( const char *  prefix,
BIGD  b,
const char *  suffix 
)

Print b in decimal format with optional prefix and suffix strings.

void bdPrintHex ( const char *  prefix,
BIGD  b,
const char *  suffix 
)

Print b in hex format with optional prefix and suffix strings.

size_t bdQuickRandBits ( BIGD  a,
size_t  nbits 
)

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

Returns
Number of digits actually set
Remarks
Not crypto secure. May give same value on repeated calls.
See Also
bdRandomBits() or bdRandomSeeded().
int bdRabinMiller ( BIGD  b,
size_t  ntests 
)

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

Parameters
[in]bNumber to test (b > 2)
[in]ntestsThe count of Rabin-Miller primality tests to carry out (recommended at least 80)
Returns
true (1) if b is probably prime otherwise false (0)
Remarks
bdIsPrime() is the recommended function to test for primality. Use this variant if, for some reason, you do not want to do the quicker trial division tests first.
See Also
bdIsPrime()
int bdRandomSeeded ( BIGD  a,
size_t  nbits,
const unsigned char *  seed,
size_t  seedlen,
BD_RANDFUNC  RandFunc 
)

Generate a random number nbits long using RandFunc.

Parameters
[out]aTo receive the result
[in]nbitsMaximum number of bits in number
[in]seedOptional seed to add extra entropy
[in]seedlenNumber of bytes in seed
[in]RandFuncUser function to generate random bytes
int bdSetBit ( BIGD  a,
size_t  n,
int  value 
)

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

int bdSetEqual ( BIGD  a,
BIGD  b 
)

Sets a = b.

size_t bdSetRandTest ( BIGD  a,
size_t  ndigits 
)

Set a with a "random" value of random length up to ndigits long suitable for quick tests.

Returns
Number of digits actually set
Remarks
For testing purposes only. Not crypto secure. Not thread safe.
int bdSetShort ( BIGD  b,
bdigit_t  d 
)

Converts a single digit into a BIGD.

Parameters
[out]bTo receive the result
[in]dA single digit
Remarks
Use this to set a BIGD variable to a small integer.
int bdSetZero ( BIGD  a)

Sets a = 0.

void bdShiftLeft ( BIGD  a,
BIGD  b,
size_t  n 
)

Computes a = b << n.

void bdShiftRight ( BIGD  a,
BIGD  b,
size_t  n 
)

Computes a = b >> n.

int bdShortAdd ( BIGD  w,
BIGD  u,
bdigit_t  d 
)

Computes w = u + d where d is a single digit.

Returns
carry
int bdShortCmp ( BIGD  a,
bdigit_t  d 
)

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

int bdShortDiv ( BIGD  q,
BIGD  r,
BIGD  u,
bdigit_t  d 
)

Computes integer division of u by single digit d.

Parameters
[out]qTo receive quotient = u div d
[out]rTo receive remainder = u mod d
[in]uDividend, a BIGD object
[in]dDivisor, a single digit
Remarks
A separate BIGD object r must be provided to receive the remainder.
int bdShortIsEqual ( BIGD  a,
bdigit_t  d 
)

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

bdigit_t bdShortMod ( BIGD  r,
BIGD  u,
bdigit_t  d 
)

Computes r = u mod d where d is a single digit.

int bdShortMult ( BIGD  w,
BIGD  u,
bdigit_t  d 
)

Computes w = u * d where d is a single digit.

int bdShortSub ( BIGD  w,
BIGD  u,
bdigit_t  d 
)

Computes w = u - d where d is a single digit.

Returns
borrow
size_t bdSizeof ( BIGD  b)

Returns number of significant digits in b.

int bdSqrt ( BIGD  s,
BIGD  x 
)

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

int bdSquare ( BIGD  w,
BIGD  x 
)

Compute square w = x^2.

Remarks
w and x must be separate variables. Use bdSquare_s() to avoid overlap restriction.
int bdSquare_s ( BIGD  s,
BIGD  x 
)

Compute s = x * x without restrictions on overlap of bdSquare()

int bdSubtract ( BIGD  w,
BIGD  u,
BIGD  v 
)

Compute difference w = u - v.

Returns
borrow
Remarks
w and v must be separate variables. Use bdSubtract_s() to avoid overlap restriction.
Warning
Behaviour is undefined for negative numbers.
int bdSubtract_s ( BIGD  w,
BIGD  u,
BIGD  v 
)

Compute w = u - v without restrictions on overlap of bdSubtract()

bdigit_t bdToShort ( BIGD  b)

Returns the least significant digit in b.

Returns
A single digit equal to the least significant digit in b
Remarks
Use this to convert (truncate) a BIGD object into a short integer
int bdVersion ( void  )

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

void bdXorBits ( BIGD  a,
BIGD  b,
BIGD  c 
)

Computes bitwise operation a = b XOR c.

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.